typing: support typing as a channel user
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -161,17 +161,17 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
return client.onMessageEdit(ctx, update)
|
||||
})
|
||||
dispatcher.OnUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateUserTyping) error {
|
||||
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeUser, update.UserID), update.UserID, update.Action)
|
||||
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeUser, update.UserID), client.senderForUserID(update.UserID), update.Action)
|
||||
})
|
||||
dispatcher.OnChatUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateChatUserTyping) error {
|
||||
if update.FromID.TypeID() != tg.PeerUserTypeID {
|
||||
log.Warn().Str("from_id_type", update.FromID.TypeName()).Msg("unsupported from_id type")
|
||||
return nil
|
||||
}
|
||||
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeChat, update.ChatID), update.FromID.(*tg.PeerUser).UserID, update.Action)
|
||||
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeChat, update.ChatID), client.getPeerSender(update.FromID), update.Action)
|
||||
})
|
||||
dispatcher.OnChannelUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateChannelUserTyping) error {
|
||||
return client.handleTyping(client.makePortalKeyFromID(ids.PeerTypeChannel, update.ChannelID), update.FromID.(*tg.PeerUser).UserID, update.Action)
|
||||
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)
|
||||
|
||||
@@ -333,6 +333,10 @@ func (t *TelegramClient) getEventSender(msg interface {
|
||||
if !ok {
|
||||
peer = msg.GetPeerID()
|
||||
}
|
||||
return t.getPeerSender(peer)
|
||||
}
|
||||
|
||||
func (t *TelegramClient) getPeerSender(peer tg.PeerClass) bridgev2.EventSender {
|
||||
switch from := peer.(type) {
|
||||
case *tg.PeerUser:
|
||||
return bridgev2.EventSender{
|
||||
@@ -344,8 +348,7 @@ func (t *TelegramClient) getEventSender(msg interface {
|
||||
Sender: ids.MakeChannelUserID(from.ChannelID),
|
||||
}
|
||||
default:
|
||||
fromID, _ := msg.GetFromID()
|
||||
panic(fmt.Sprintf("couldn't determine sender (from: %+v) (peer: %+v)", fromID, msg.GetPeerID()))
|
||||
panic(fmt.Sprintf("couldn't determine sender (peer: %+v)", peer))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,8 +591,8 @@ func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TelegramClient) handleTyping(portal networkid.PortalKey, userID int64, action tg.SendMessageActionClass) error {
|
||||
if userID == t.telegramUserID {
|
||||
func (t *TelegramClient) handleTyping(portal networkid.PortalKey, sender bridgev2.EventSender, action tg.SendMessageActionClass) error {
|
||||
if sender.IsFromMe || (sender.Sender == t.userID && sender.SenderLogin == t.userLogin.ID) {
|
||||
return nil
|
||||
}
|
||||
timeout := time.Duration(6) * time.Second
|
||||
@@ -601,10 +604,7 @@ func (t *TelegramClient) handleTyping(portal networkid.PortalKey, userID int64,
|
||||
EventMeta: simplevent.EventMeta{
|
||||
Type: bridgev2.RemoteEventTyping,
|
||||
PortalKey: portal,
|
||||
Sender: bridgev2.EventSender{
|
||||
SenderLogin: ids.MakeUserLoginID(userID),
|
||||
Sender: ids.MakeUserID(userID),
|
||||
},
|
||||
Sender: sender,
|
||||
},
|
||||
Timeout: timeout,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user