From 1e81fc6a02465deaa351f5105b41a88ba5369e65 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 4 Feb 2023 14:16:58 +0200 Subject: [PATCH] Improve typing notification handling --- portal.go | 18 ++++++++++++++++++ user.go | 6 +----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/portal.go b/portal.go index 1821856..162c9e9 100644 --- a/portal.go +++ b/portal.go @@ -1282,6 +1282,24 @@ func (portal *Portal) handleDiscordMessageDelete(user *User, msg *discordgo.Mess } } +func (portal *Portal) handleDiscordTyping(evt *discordgo.TypingStart) { + puppet := portal.bridge.GetPuppetByID(evt.UserID) + if puppet.Name == "" { + // Puppet hasn't been synced yet + return + } + intent := puppet.IntentFor(portal) + err := intent.EnsureJoined(portal.MXID) + if err != nil { + portal.log.Warnfln("Failed to ensure %s is joined for typing notification: %v", puppet.MXID, portal.MXID, err) + return + } + _, err = intent.UserTyping(portal.MXID, true, 12*time.Second) + if err != nil { + portal.log.Warnfln("Failed to mark %s as typing: %v", puppet.MXID, portal.MXID, err) + } +} + func (portal *Portal) syncParticipants(source *User, participants []*discordgo.User) { for _, participant := range participants { puppet := portal.bridge.GetPuppetByID(participant.ID) diff --git a/user.go b/user.go index ac30554..a4edcc7 100644 --- a/user.go +++ b/user.go @@ -995,11 +995,7 @@ func (user *User) typingStartHandler(_ *discordgo.Session, t *discordgo.TypingSt if portal == nil || portal.MXID == "" { return } - puppet := user.bridge.GetPuppetByID(t.UserID) - _, err := puppet.IntentFor(portal).UserTyping(portal.MXID, true, 12*time.Second) - if err != nil { - user.log.Warnfln("Failed to mark %s as typing in %s: %v", puppet.MXID, portal.MXID, err) - } + portal.handleDiscordTyping(t) } func (user *User) interactionSuccessHandler(_ *discordgo.Session, s *discordgo.InteractionSuccess) {