feat(shared): sendEncryptedMessage inserts mention rows after the message row
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
type OwnUserCtx,
|
||||
tryGetConvKey,
|
||||
} from './convKeys';
|
||||
import { insertMentions, makeMentionResolver, parseMentionUsernames } from './mentions';
|
||||
import type { ChatMessage, DecryptedMessage } from './types';
|
||||
|
||||
const MESSAGE_COLS =
|
||||
@@ -146,6 +147,28 @@ export async function sendEncryptedMessage(params: SendMessageParams): Promise<C
|
||||
.select(MESSAGE_COLS)
|
||||
.single();
|
||||
if (insertErr) throw insertErr;
|
||||
|
||||
// Mention rows are inserted on a best-effort basis after the message itself
|
||||
// lands. If parsing or resolution fails the message still goes through —
|
||||
// worst case the mentioned user doesn't get a notification.
|
||||
const usernames = parseMentionUsernames(params.plaintext);
|
||||
if (usernames.length > 0) {
|
||||
try {
|
||||
const resolver = makeMentionResolver(params.client);
|
||||
const resolved = await resolver.resolveUsernames(params.conversationId, usernames);
|
||||
if (resolved.size > 0) {
|
||||
await insertMentions(
|
||||
params.client,
|
||||
(messageRow as unknown as { id: string }).id,
|
||||
params.conversationId,
|
||||
[...resolved.values()],
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('mention insert failed', err);
|
||||
}
|
||||
}
|
||||
|
||||
return mapMessage(messageRow as unknown as MessageRow);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user