connector: simplify some of the dispatcher handlers

Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
Sumner Evans
2024-12-02 15:53:43 -07:00
parent 124f0967ed
commit bf3e0ec8ab
2 changed files with 11 additions and 23 deletions
+6 -18
View File
@@ -152,12 +152,10 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
dispatcher.OnNewMessage(func(ctx context.Context, e tg.Entities, update *tg.UpdateNewMessage) error {
return client.onUpdateNewMessage(ctx, e.Channels, update)
})
dispatcher.OnChannel(func(ctx context.Context, e tg.Entities, update *tg.UpdateChannel) error {
return client.onUpdateChannel(ctx, update)
})
dispatcher.OnNewChannelMessage(func(ctx context.Context, e tg.Entities, update *tg.UpdateNewChannelMessage) error {
return client.onUpdateNewMessage(ctx, e.Channels, update)
})
dispatcher.OnChannel(client.onUpdateChannel)
dispatcher.OnUserName(client.onUserName)
dispatcher.OnDeleteMessages(func(ctx context.Context, e tg.Entities, update *tg.UpdateDeleteMessages) error {
return client.onDeleteMessages(ctx, 0, update)
@@ -184,27 +182,17 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
dispatcher.OnChannelUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateChannelUserTyping) error {
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeChannel, update.ChannelID), client.getPeerSender(update.FromID), update.Action)
})
dispatcher.OnReadHistoryOutbox(func(ctx context.Context, e tg.Entities, update *tg.UpdateReadHistoryOutbox) error {
return client.updateReadReceipt(update)
})
dispatcher.OnReadHistoryOutbox(client.updateReadReceipt)
dispatcher.OnReadHistoryInbox(func(ctx context.Context, e tg.Entities, update *tg.UpdateReadHistoryInbox) error {
return client.onOwnReadReceipt(client.makePortalKeyFromPeer(update.Peer), update.MaxID)
})
dispatcher.OnReadChannelInbox(func(ctx context.Context, e tg.Entities, update *tg.UpdateReadChannelInbox) error {
return client.onOwnReadReceipt(client.makePortalKeyFromID(ids.PeerTypeChannel, update.ChannelID), update.MaxID)
})
dispatcher.OnNotifySettings(func(ctx context.Context, e tg.Entities, update *tg.UpdateNotifySettings) error {
return client.onNotifySettings(ctx, update)
})
dispatcher.OnPinnedDialogs(func(ctx context.Context, e tg.Entities, update *tg.UpdatePinnedDialogs) error {
return client.onPinnedDialogs(ctx, update)
})
dispatcher.OnChatDefaultBannedRights(func(ctx context.Context, e tg.Entities, update *tg.UpdateChatDefaultBannedRights) error {
return client.onChatDefaultBannedRights(ctx, e, update)
})
dispatcher.OnPeerBlocked(func(ctx context.Context, e tg.Entities, update *tg.UpdatePeerBlocked) error {
return client.onPeerBlocked(ctx, update)
})
dispatcher.OnNotifySettings(client.onNotifySettings)
dispatcher.OnPinnedDialogs(client.onPinnedDialogs)
dispatcher.OnChatDefaultBannedRights(client.onChatDefaultBannedRights)
dispatcher.OnPeerBlocked(client.onPeerBlocked)
dispatcher.OnChat(client.onChat)
dispatcher.OnPhoneCall(client.onPhoneCall)
+5 -5
View File
@@ -50,7 +50,7 @@ func (t *TelegramClient) selfLeaveChat(portalKey networkid.PortalKey) {
})
}
func (t *TelegramClient) onUpdateChannel(ctx context.Context, update *tg.UpdateChannel) error {
func (t *TelegramClient) onUpdateChannel(ctx context.Context, e tg.Entities, update *tg.UpdateChannel) error {
log := zerolog.Ctx(ctx).With().
Str("handler", "on_update_channel").
Int64("channel_id", update.ChannelID).
@@ -779,7 +779,7 @@ func (t *TelegramClient) handleTyping(portal networkid.PortalKey, sender bridgev
return nil
}
func (t *TelegramClient) updateReadReceipt(update *tg.UpdateReadHistoryOutbox) error {
func (t *TelegramClient) updateReadReceipt(ctx context.Context, e tg.Entities, update *tg.UpdateReadHistoryOutbox) error {
user, ok := update.Peer.(*tg.PeerUser)
if !ok {
// Read receipts from other users are meaningless in chats/channels
@@ -927,7 +927,7 @@ func (t *TelegramClient) transferEmojisToMatrix(ctx context.Context, customEmoji
return
}
func (t *TelegramClient) onNotifySettings(ctx context.Context, update *tg.UpdateNotifySettings) error {
func (t *TelegramClient) onNotifySettings(ctx context.Context, e tg.Entities, update *tg.UpdateNotifySettings) error {
if update.Peer.TypeID() != tg.NotifyPeerTypeID {
return fmt.Errorf("unsupported peer type %s", update.Peer.TypeName())
}
@@ -968,7 +968,7 @@ func (t *TelegramClient) HandleMute(ctx context.Context, msg *bridgev2.MatrixMut
return err
}
func (t *TelegramClient) onPinnedDialogs(ctx context.Context, msg *tg.UpdatePinnedDialogs) error {
func (t *TelegramClient) onPinnedDialogs(ctx context.Context, e tg.Entities, msg *tg.UpdatePinnedDialogs) error {
needsUnpinning := map[networkid.PortalKey]struct{}{}
for _, portalID := range t.userLogin.Metadata.(*UserLoginMetadata).PinnedDialogs {
pt, id, err := ids.ParsePortalID(portalID)
@@ -1050,7 +1050,7 @@ func (t *TelegramClient) onChatDefaultBannedRights(ctx context.Context, entities
return nil
}
func (t *TelegramClient) onPeerBlocked(ctx context.Context, update *tg.UpdatePeerBlocked) error {
func (t *TelegramClient) onPeerBlocked(ctx context.Context, e tg.Entities, update *tg.UpdatePeerBlocked) error {
var userID networkid.UserID
if peer, ok := update.PeerID.(*tg.PeerUser); ok {
userID = ids.MakeUserID(peer.UserID)