handletelegram,gotd: stop get difference polling after leaving channel

This commit is contained in:
Tulir Asokan
2025-12-11 13:56:48 +02:00
parent 390f9f422e
commit 581ba79c84
3 changed files with 31 additions and 7 deletions
+7
View File
@@ -161,6 +161,13 @@ func (m *Manager) Run(ctx context.Context, api API, userID int64, opt AuthOption
return wg.Wait()
}
func (m *Manager) RemoveChannel(channelID int64, reason error) {
if m == nil {
return
}
m.state.RemoveChannel(channelID, reason)
}
func (m *Manager) loadState(ctx context.Context, api API, userID int64, forget bool) (State, error) {
onNotFound:
var state State
+13
View File
@@ -383,6 +383,19 @@ func (s *internalState) handleChannel(ctx context.Context, channelID int64, date
return state.Push(ctx, cu)
}
func (s *internalState) RemoveChannel(channelID int64, reason error) {
if s == nil {
return
}
s.channelsLock.Lock()
state, ok := s.channels[channelID]
s.channelsLock.Unlock()
if !ok {
return
}
state.stop(fmt.Errorf("%w: %w", ErrRemoveChannelState, reason))
}
func (s *internalState) createAndRunChannelState(ctx context.Context, channelID, accessHash int64, initialPts int) (state *channelState) {
state = s.newChannelState(channelID, accessHash, initialPts)
s.channelsLock.Lock()