Album: Attach caption to the last file on send (#4766)
This commit is contained in:
parent
145c603afc
commit
43459b8ea9
@ -363,30 +363,55 @@ addActionHandler('sendMessage', (global, actions, payload): ActionReturnType =>
|
|||||||
} = params;
|
} = params;
|
||||||
const byType = splitAttachmentsByType(attachments!);
|
const byType = splitAttachmentsByType(attachments!);
|
||||||
|
|
||||||
|
let hasSentCaption = false;
|
||||||
byType.forEach((group, groupIndex) => {
|
byType.forEach((group, groupIndex) => {
|
||||||
const groupedAttachments = split(group as ApiAttachment[], MAX_MEDIA_FILES_FOR_ALBUM);
|
const groupedAttachments = split(group as ApiAttachment[], MAX_MEDIA_FILES_FOR_ALBUM);
|
||||||
for (let i = 0; i < groupedAttachments.length; i++) {
|
for (let i = 0; i < groupedAttachments.length; i++) {
|
||||||
const [firstAttachment, ...restAttachments] = groupedAttachments[i];
|
|
||||||
const groupedId = `${Date.now()}${groupIndex}${i}`;
|
const groupedId = `${Date.now()}${groupIndex}${i}`;
|
||||||
|
|
||||||
const isFirst = i === 0 && groupIndex === 0;
|
const isFirst = i === 0 && groupIndex === 0;
|
||||||
|
const isLast = i === groupedAttachments.length - 1 && groupIndex === byType.length - 1;
|
||||||
|
|
||||||
sendMessage(global, {
|
if (group[0].quick && !group[0].shouldSendAsFile) {
|
||||||
...commonParams,
|
const [firstAttachment, ...restAttachments] = groupedAttachments[i];
|
||||||
text: isFirst ? text : undefined,
|
|
||||||
entities: isFirst ? entities : undefined,
|
|
||||||
attachment: firstAttachment,
|
|
||||||
groupedId: restAttachments.length > 0 ? groupedId : undefined,
|
|
||||||
wasDrafted: Boolean(draft),
|
|
||||||
});
|
|
||||||
|
|
||||||
restAttachments.forEach((attachment: ApiAttachment) => {
|
|
||||||
sendMessage(global, {
|
sendMessage(global, {
|
||||||
...commonParams,
|
...commonParams,
|
||||||
attachment,
|
text: isFirst && !hasSentCaption ? text : undefined,
|
||||||
groupedId,
|
entities: isFirst && !hasSentCaption ? entities : undefined,
|
||||||
|
attachment: firstAttachment,
|
||||||
|
groupedId: restAttachments.length > 0 ? groupedId : undefined,
|
||||||
|
wasDrafted: Boolean(draft),
|
||||||
});
|
});
|
||||||
});
|
hasSentCaption = true;
|
||||||
|
|
||||||
|
restAttachments.forEach((attachment: ApiAttachment) => {
|
||||||
|
sendMessage(global, {
|
||||||
|
...commonParams,
|
||||||
|
attachment,
|
||||||
|
groupedId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const firstAttachments = groupedAttachments[i].slice(0, -1);
|
||||||
|
const lastAttachment = groupedAttachments[i][groupedAttachments[i].length - 1];
|
||||||
|
firstAttachments.forEach((attachment: ApiAttachment) => {
|
||||||
|
sendMessage(global, {
|
||||||
|
...commonParams,
|
||||||
|
attachment,
|
||||||
|
groupedId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sendMessage(global, {
|
||||||
|
...commonParams,
|
||||||
|
text: isLast && !hasSentCaption ? text : undefined,
|
||||||
|
entities: isLast && !hasSentCaption ? entities : undefined,
|
||||||
|
attachment: lastAttachment,
|
||||||
|
groupedId: firstAttachments.length > 0 ? groupedId : undefined,
|
||||||
|
wasDrafted: Boolean(draft),
|
||||||
|
});
|
||||||
|
hasSentCaption = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user