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)
|
return client.onMessageEdit(ctx, update)
|
||||||
})
|
})
|
||||||
dispatcher.OnUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateUserTyping) error {
|
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 {
|
dispatcher.OnChatUserTyping(func(ctx context.Context, e tg.Entities, update *tg.UpdateChatUserTyping) error {
|
||||||
if update.FromID.TypeID() != tg.PeerUserTypeID {
|
if update.FromID.TypeID() != tg.PeerUserTypeID {
|
||||||
log.Warn().Str("from_id_type", update.FromID.TypeName()).Msg("unsupported from_id type")
|
log.Warn().Str("from_id_type", update.FromID.TypeName()).Msg("unsupported from_id type")
|
||||||
return nil
|
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 {
|
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 {
|
dispatcher.OnReadHistoryOutbox(func(ctx context.Context, e tg.Entities, update *tg.UpdateReadHistoryOutbox) error {
|
||||||
return client.updateReadReceipt(update)
|
return client.updateReadReceipt(update)
|
||||||
|
|||||||
@@ -333,6 +333,10 @@ func (t *TelegramClient) getEventSender(msg interface {
|
|||||||
if !ok {
|
if !ok {
|
||||||
peer = msg.GetPeerID()
|
peer = msg.GetPeerID()
|
||||||
}
|
}
|
||||||
|
return t.getPeerSender(peer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TelegramClient) getPeerSender(peer tg.PeerClass) bridgev2.EventSender {
|
||||||
switch from := peer.(type) {
|
switch from := peer.(type) {
|
||||||
case *tg.PeerUser:
|
case *tg.PeerUser:
|
||||||
return bridgev2.EventSender{
|
return bridgev2.EventSender{
|
||||||
@@ -344,8 +348,7 @@ func (t *TelegramClient) getEventSender(msg interface {
|
|||||||
Sender: ids.MakeChannelUserID(from.ChannelID),
|
Sender: ids.MakeChannelUserID(from.ChannelID),
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fromID, _ := msg.GetFromID()
|
panic(fmt.Sprintf("couldn't determine sender (peer: %+v)", peer))
|
||||||
panic(fmt.Sprintf("couldn't determine sender (from: %+v) (peer: %+v)", fromID, msg.GetPeerID()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,8 +591,8 @@ func (t *TelegramClient) onMessageEdit(ctx context.Context, update IGetMessage)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) handleTyping(portal networkid.PortalKey, userID int64, action tg.SendMessageActionClass) error {
|
func (t *TelegramClient) handleTyping(portal networkid.PortalKey, sender bridgev2.EventSender, action tg.SendMessageActionClass) error {
|
||||||
if userID == t.telegramUserID {
|
if sender.IsFromMe || (sender.Sender == t.userID && sender.SenderLogin == t.userLogin.ID) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
timeout := time.Duration(6) * time.Second
|
timeout := time.Duration(6) * time.Second
|
||||||
@@ -601,10 +604,7 @@ func (t *TelegramClient) handleTyping(portal networkid.PortalKey, userID int64,
|
|||||||
EventMeta: simplevent.EventMeta{
|
EventMeta: simplevent.EventMeta{
|
||||||
Type: bridgev2.RemoteEventTyping,
|
Type: bridgev2.RemoteEventTyping,
|
||||||
PortalKey: portal,
|
PortalKey: portal,
|
||||||
Sender: bridgev2.EventSender{
|
Sender: sender,
|
||||||
SenderLogin: ids.MakeUserLoginID(userID),
|
|
||||||
Sender: ids.MakeUserID(userID),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user