Improve typing notification handling

This commit is contained in:
Tulir Asokan
2023-02-04 14:16:58 +02:00
parent 80f8bed9b9
commit 1e81fc6a02
2 changed files with 19 additions and 5 deletions

View File

@@ -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)

View File

@@ -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) {