client: ignore messages in left channels
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -135,13 +135,13 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
EntityHandler: client.onEntityUpdate,
|
||||
}
|
||||
dispatcher.OnNewMessage(func(ctx context.Context, e tg.Entities, update *tg.UpdateNewMessage) error {
|
||||
return client.onUpdateNewMessage(ctx, update)
|
||||
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, update)
|
||||
return client.onUpdateNewMessage(ctx, e.Channels, update)
|
||||
})
|
||||
dispatcher.OnUserName(client.onUserName)
|
||||
dispatcher.OnDeleteMessages(func(ctx context.Context, e tg.Entities, update *tg.UpdateDeleteMessages) error {
|
||||
@@ -446,6 +446,7 @@ func (t *TelegramClient) getSingleUser(ctx context.Context, id int64) (tg.UserCl
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make work for channel peers (necessary for forward backfill)
|
||||
func (t *TelegramClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error) {
|
||||
if peerType, id, err := ids.ParseUserID(ghost.ID); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -83,12 +83,21 @@ func (t *TelegramClient) onUpdateChannel(ctx context.Context, update *tg.UpdateC
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, update IGetMessage) error {
|
||||
func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, channels map[int64]*tg.Channel, update IGetMessage) error {
|
||||
log := zerolog.Ctx(ctx)
|
||||
switch msg := update.GetMessage().(type) {
|
||||
case *tg.Message:
|
||||
sender := t.getEventSender(msg)
|
||||
|
||||
if channel, ok := msg.PeerID.(*tg.PeerChannel); ok {
|
||||
if c, ok := channels[channel.ChannelID]; ok && c.Left {
|
||||
log.Debug().
|
||||
Int64("channel_id", channel.ChannelID).
|
||||
Msg("Received message in left channel, ignoring")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
go t.handleTelegramReactions(ctx, msg)
|
||||
|
||||
if media, ok := msg.GetMedia(); ok && media.TypeID() == tg.MessageMediaContactTypeID {
|
||||
|
||||
Reference in New Issue
Block a user