gotd: ensure user is member of channels before starting getDifference loop
This commit is contained in:
@@ -226,6 +226,7 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
dispatcher.OnPhoneCall(client.onPhoneCall)
|
||||
|
||||
client.updatesManager = updates.New(updates.Config{
|
||||
OnNotChannelMember: client.onNotChannelMember,
|
||||
OnChannelTooLong: func(channelID int64) error {
|
||||
// TODO resync topics?
|
||||
res := tc.Bridge.QueueRemoteEvent(login, &simplevent.ChatResync{
|
||||
|
||||
@@ -107,6 +107,10 @@ func (t *TelegramClient) selfLeaveChat(ctx context.Context, portalKey networkid.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TelegramClient) onNotChannelMember(ctx context.Context, channelID int64) error {
|
||||
return t.selfLeaveChat(ctx, t.makePortalKeyFromID(ids.PeerTypeChannel, channelID, 0), fmt.Errorf("startup channel member check failed"))
|
||||
}
|
||||
|
||||
func (t *TelegramClient) onUpdateChannel(ctx context.Context, e tg.Entities, update *tg.UpdateChannel) error {
|
||||
log := zerolog.Ctx(ctx).With().
|
||||
Str("handler", "on_update_channel").
|
||||
|
||||
@@ -74,19 +74,26 @@ const (
|
||||
|
||||
var _ updates.StateStorage = (*ScopedStore)(nil)
|
||||
|
||||
type channelIDPtsTuple struct {
|
||||
ChannelID int64
|
||||
Pts int
|
||||
}
|
||||
|
||||
var ciptScanner = dbutil.ConvertRowFn[channelIDPtsTuple](func(row dbutil.Scannable) (cipt channelIDPtsTuple, err error) {
|
||||
err = row.Scan(&cipt.ChannelID, &cipt.Pts)
|
||||
return
|
||||
})
|
||||
|
||||
func (s *ScopedStore) ForEachChannels(ctx context.Context, userID int64, f func(ctx context.Context, channelID int64, pts int) error) error {
|
||||
s.assertUserIDMatches(userID)
|
||||
rows, err := s.db.Query(ctx, allChannelsQuery, userID)
|
||||
items, err := ciptScanner.NewRowIter(s.db.Query(ctx, allChannelsQuery, userID)).AsList()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var channelID int64
|
||||
var pts int
|
||||
for rows.Next() {
|
||||
if err = rows.Scan(&channelID, &pts); err != nil {
|
||||
return err
|
||||
} else if err = f(ctx, channelID, pts); err != nil {
|
||||
return err
|
||||
for _, item := range items {
|
||||
err = f(ctx, item.ChannelID, item.Pts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("iteration error for channel %d: %w", item.ChannelID, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user