fix(forward): one forbidden target no longer fails the whole multi-room forward (#194 P6-3)
All targets were sent concurrently through matrix-js-sdk's message queue; when the send to a room you cannot post to failed with 403 the scheduler clearQueue()'d every send still waiting, so 'Send to 3 rooms' with one read-only room reported 'Failed to forward' for all three and left a half-sent comment in the first. Rooms are now sent one at a time. Verified: 'Forwarded to 2/3. Failed: Read Only Room.' and both good rooms receive comment + forwarded message. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -338,35 +338,43 @@ export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const commentBody = comment.trim();
|
const commentBody = comment.trim();
|
||||||
const results = await Promise.allSettled(
|
// Rooms are sent ONE AT A TIME. matrix-js-sdk queues message sends, and
|
||||||
ids.map((id) => {
|
// when one queued send fails permanently (e.g. 403 in a room you cannot
|
||||||
const destEncrypted = !!mx.getRoom(id)?.hasEncryptionStateEvent();
|
// post to) the scheduler rejects every send still waiting in the queue —
|
||||||
// Encrypted destinations keep the original (possibly encrypted-attachment)
|
// so firing all rooms concurrently turned one forbidden target into
|
||||||
// content; unencrypted ones get the plaintext version, or fail outright if
|
// "Failed to forward" for all of them, with half-sent comments (Gitea #194).
|
||||||
// that couldn't be built — never fall back to sending the encrypted `file`.
|
const sendToRoom = (id: string): Promise<unknown> => {
|
||||||
const contentToSend = fwdContent.file && !destEncrypted ? plaintextContent : fwdContent;
|
const destEncrypted = !!mx.getRoom(id)?.hasEncryptionStateEvent();
|
||||||
if (fwdContent.file && !destEncrypted && !contentToSend) {
|
// Encrypted destinations keep the original (possibly encrypted-attachment)
|
||||||
return Promise.reject(new Error(plaintextContentError));
|
// content; unencrypted ones get the plaintext version, or fail outright if
|
||||||
}
|
// that couldn't be built — never fall back to sending the encrypted `file`.
|
||||||
// threadId-aware overload (P3-8): explicit null = send to the main timeline.
|
const contentToSend = fwdContent.file && !destEncrypted ? plaintextContent : fwdContent;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
if (fwdContent.file && !destEncrypted && !contentToSend) {
|
||||||
const sendForward = () => mx.sendEvent(id, null, mEvent.getType() as any, contentToSend);
|
return Promise.reject(new Error(plaintextContentError));
|
||||||
// Send the optional comment first so it reads as a note above the
|
}
|
||||||
// forwarded content. The room counts as failed if either send rejects.
|
// threadId-aware overload (P3-8): explicit null = send to the main timeline.
|
||||||
// Track rooms whose comment already landed so a retry (after the FORWARD
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
// failed) doesn't post the comment twice — only the missing forward.
|
const sendForward = () => mx.sendEvent(id, null, mEvent.getType() as any, contentToSend);
|
||||||
const needsComment = commentBody && !commentSentRef.current.has(id);
|
// Send the optional comment first so it reads as a note above the
|
||||||
const step = needsComment
|
// forwarded content. The room counts as failed if either send rejects.
|
||||||
? mx
|
// Track rooms whose comment already landed so a retry (after the FORWARD
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// failed) doesn't post the comment twice — only the missing forward.
|
||||||
.sendMessage(id, null, { msgtype: MsgType.Text, body: commentBody } as any)
|
const needsComment = commentBody && !commentSentRef.current.has(id);
|
||||||
.then(() => {
|
const step = needsComment
|
||||||
commentSentRef.current.add(id);
|
? mx
|
||||||
})
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
: Promise.resolve();
|
.sendMessage(id, null, { msgtype: MsgType.Text, body: commentBody } as any)
|
||||||
return step.then(sendForward);
|
.then(() => {
|
||||||
}),
|
commentSentRef.current.add(id);
|
||||||
);
|
})
|
||||||
|
: Promise.resolve();
|
||||||
|
return step.then(sendForward);
|
||||||
|
};
|
||||||
|
const results: PromiseSettledResult<unknown>[] = [];
|
||||||
|
for (const id of ids) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
results.push(...(await Promise.allSettled([sendToRoom(id)])));
|
||||||
|
}
|
||||||
|
|
||||||
const failedIds: string[] = [];
|
const failedIds: string[] = [];
|
||||||
const failedNames: string[] = [];
|
const failedNames: string[] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user