gotd: fix channel membership check not doing anything
This commit is contained in:
@@ -81,7 +81,7 @@ type PtsAccessHashTuple struct {
|
|||||||
AccessHash int64
|
AccessHash int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) checkParticipant(ctx context.Context, api API, userID, channelID, hash int64) error {
|
func (m *Manager) checkParticipant(ctx context.Context, api API, userID, channelID, hash int64) (isMember bool, err error) {
|
||||||
lg := m.lg.With(zap.Int64("channel_id", channelID))
|
lg := m.lg.With(zap.Int64("channel_id", channelID))
|
||||||
lg.Info("Ensuring user is still in channel")
|
lg.Info("Ensuring user is still in channel")
|
||||||
pcp, err := api.ChannelsGetParticipant(ctx, &tg.ChannelsGetParticipantRequest{
|
pcp, err := api.ChannelsGetParticipant(ctx, &tg.ChannelsGetParticipantRequest{
|
||||||
@@ -97,7 +97,7 @@ func (m *Manager) checkParticipant(ctx context.Context, api API, userID, channel
|
|||||||
} else {
|
} else {
|
||||||
lg.Error("channels.getParticipant failed", zap.Error(err))
|
lg.Error("channels.getParticipant failed", zap.Error(err))
|
||||||
// TODO fatal error?
|
// TODO fatal error?
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch pcp.Participant.(type) {
|
switch pcp.Participant.(type) {
|
||||||
@@ -105,16 +105,16 @@ func (m *Manager) checkParticipant(ctx context.Context, api API, userID, channel
|
|||||||
lg.Warn("Removing update state for channel as user is left or banned")
|
lg.Warn("Removing update state for channel as user is left or banned")
|
||||||
default:
|
default:
|
||||||
lg.Debug("Membership confirmed", zap.Any("participant", pcp.Participant))
|
lg.Debug("Membership confirmed", zap.Any("participant", pcp.Participant))
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.cfg.Storage.SetChannelPts(ctx, userID, channelID, -1); err != nil {
|
if err := m.cfg.Storage.SetChannelPts(ctx, userID, channelID, -1); err != nil {
|
||||||
return fmt.Errorf("failed to clear pts: %w", err)
|
return false, fmt.Errorf("failed to clear pts: %w", err)
|
||||||
} else if err = m.cfg.OnNotChannelMember(ctx, channelID); err != nil {
|
} else if err = m.cfg.OnNotChannelMember(ctx, channelID); err != nil {
|
||||||
return fmt.Errorf("OnNotChannelMember callback failed: %w", err)
|
return false, fmt.Errorf("OnNotChannelMember callback failed: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run notifies manager about user authentication on the telegram server.
|
// Run notifies manager about user authentication on the telegram server.
|
||||||
@@ -154,8 +154,10 @@ func (m *Manager) Run(ctx context.Context, api API, userID int64, opt AuthOption
|
|||||||
return errors.Wrap(err, "get channel access hash")
|
return errors.Wrap(err, "get channel access hash")
|
||||||
} else if !found {
|
} else if !found {
|
||||||
return nil
|
return nil
|
||||||
} else if err = m.checkParticipant(ctx, api, userID, channelID, hash); err != nil {
|
} else if isMember, err := m.checkParticipant(ctx, api, userID, channelID, hash); err != nil {
|
||||||
return fmt.Errorf("failed to check if user is participant of channel %d: %w", channelID, err)
|
return fmt.Errorf("failed to check if user is participant of channel %d: %w", channelID, err)
|
||||||
|
} else if !isMember {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
channels[channelID] = PtsAccessHashTuple{Pts: pts, AccessHash: hash}
|
channels[channelID] = PtsAccessHashTuple{Pts: pts, AccessHash: hash}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user