feat: add dm_typing_stop event to clear typing indicator on message send
Broadcasts dm_typing_stop to DM members before dm_message_created, so the typing indicator clears immediately when a message arrives instead of lingering for up to 3 seconds after delivery.
This commit is contained in:
@@ -180,6 +180,17 @@ export function broadcastDmMessage(dmChannelId: string, message: DmMessageWithUs
|
||||
.where(eq(schema.dmMembers.dmChannelId, dmChannelId))
|
||||
.all();
|
||||
|
||||
// Clear typing indicator for the message author — the message itself proves they stopped
|
||||
for (const member of dmMembers) {
|
||||
if (member.userId !== message.userId) {
|
||||
connectionManager.sendToUser(member.userId, {
|
||||
type: 'dm_typing_stop',
|
||||
dmChannelId,
|
||||
userId: message.userId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const member of dmMembers) {
|
||||
// If this member had closed the DM, resurface it first
|
||||
if (member.closed === 1) {
|
||||
|
||||
@@ -893,6 +893,14 @@ function handleDmMessageCreate(event: Record<string, unknown>, userId: string):
|
||||
// Federation: queue for relay
|
||||
queueDmRelay(dmMessage, dmChannelId, 'create');
|
||||
|
||||
// Clear any pending typing timeout for this user+channel
|
||||
const typingKey = `dm:${userId}:${dmChannelId}`;
|
||||
const existingTimeout = typingTimeouts.get(typingKey);
|
||||
if (existingTimeout) {
|
||||
clearTimeout(existingTimeout);
|
||||
typingTimeouts.delete(typingKey);
|
||||
}
|
||||
|
||||
// Resolve embeds asynchronously
|
||||
setImmediate(() => {
|
||||
resolveEmbeds(messageId, hasContent ? content!.trim() : null, dmChannelId, true, null).catch(() => {});
|
||||
|
||||
Reference in New Issue
Block a user