fix(channels): sync stop replaying clear-history updates
This commit is contained in:
parent
73cf6a8184
commit
5e1f867b2d
4 changed files with 22 additions and 51 deletions
|
|
@ -2302,14 +2302,6 @@ func (s *Service) GetDifference(ctx context.Context, userID int64, req domain.Ch
|
||||||
return domain.ChannelDifference{}, err
|
return domain.ChannelDifference{}, err
|
||||||
}
|
}
|
||||||
diff = s.filterBotChannelDifference(ctx, userID, diff)
|
diff = s.filterBotChannelDifference(ctx, userID, diff)
|
||||||
if diff.Self.HistoryClearAnchorID > 0 &&
|
|
||||||
diff.Self.HistoryClearAnchorID == diff.Self.AvailableMinID &&
|
|
||||||
!diff.TooLong {
|
|
||||||
// updateChannelAvailableMessages is an absolute no-PTS update. Keep it
|
|
||||||
// outside ChannelUpdateEvent so channel difference continuity remains
|
|
||||||
// defined solely by real channel events.
|
|
||||||
diff.AvailableMinID = diff.Self.AvailableMinID
|
|
||||||
}
|
|
||||||
return diff, nil
|
return diff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1335,10 +1335,6 @@ type ChannelDifference struct {
|
||||||
Events []ChannelUpdateEvent
|
Events []ChannelUpdateEvent
|
||||||
NewMessages []ChannelMessage
|
NewMessages []ChannelMessage
|
||||||
OtherUpdates []ChannelUpdateEvent
|
OtherUpdates []ChannelUpdateEvent
|
||||||
// AvailableMinID is an owner-local, absolute no-PTS boundary appended to a
|
|
||||||
// normal channel difference. It must never be represented as a synthetic
|
|
||||||
// ChannelUpdateEvent because updateChannelAvailableMessages has no pts.
|
|
||||||
AvailableMinID int
|
|
||||||
Users []User
|
Users []User
|
||||||
Channels []Channel
|
Channels []Channel
|
||||||
Pts int
|
Pts int
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,7 @@ func TestChannelsDeleteHistoryLocalClearEmitsAvailableMessagesUpdate(t *testing.
|
||||||
t.Fatalf("offline account state = %+v, want unchanged pts=%d and non-regressing date", offlineDiff.State, stateBefore.Pts)
|
t.Fatalf("offline account state = %+v, want unchanged pts=%d and non-regressing date", offlineDiff.State, stateBefore.Pts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for attempt := 1; attempt <= 2; attempt++ {
|
||||||
channelOffline, err := r.onUpdatesGetChannelDifference(WithUserID(ctx, owner.ID), &tg.UpdatesGetChannelDifferenceRequest{
|
channelOffline, err := r.onUpdatesGetChannelDifference(WithUserID(ctx, owner.ID), &tg.UpdatesGetChannelDifferenceRequest{
|
||||||
Channel: &tg.InputChannel{ChannelID: channel.ID, AccessHash: channel.AccessHash},
|
Channel: &tg.InputChannel{ChannelID: channel.ID, AccessHash: channel.AccessHash},
|
||||||
Filter: &tg.ChannelMessagesFilterEmpty{},
|
Filter: &tg.ChannelMessagesFilterEmpty{},
|
||||||
|
|
@ -280,25 +281,13 @@ func TestChannelsDeleteHistoryLocalClearEmitsAvailableMessagesUpdate(t *testing.
|
||||||
Limit: 100,
|
Limit: 100,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("channel difference after offline local clear: %v", err)
|
t.Fatalf("channel difference attempt %d after offline local clear: %v", attempt, err)
|
||||||
}
|
}
|
||||||
channelDiff, ok := channelOffline.(*tg.UpdatesChannelDifference)
|
channelDiff, ok := channelOffline.(*tg.UpdatesChannelDifferenceEmpty)
|
||||||
if !ok {
|
if !ok || channelDiff.Pts != newChannelUpdate.Pts {
|
||||||
t.Fatalf("offline channel difference = %T %+v, want non-empty difference with absolute update", channelOffline, channelOffline)
|
t.Fatalf("channel difference attempt %d = %T %+v, want empty with unchanged channel pts=%d",
|
||||||
|
attempt, channelOffline, channelOffline, newChannelUpdate.Pts)
|
||||||
}
|
}
|
||||||
var channelAvailable *tg.UpdateChannelAvailableMessages
|
|
||||||
for _, update := range channelDiff.OtherUpdates {
|
|
||||||
if value, ok := update.(*tg.UpdateChannelAvailableMessages); ok {
|
|
||||||
channelAvailable = value
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if channelAvailable == nil ||
|
|
||||||
channelAvailable.ChannelID != channel.ID ||
|
|
||||||
channelAvailable.AvailableMinID != msg.ID ||
|
|
||||||
channelDiff.Pts != newChannelUpdate.Pts {
|
|
||||||
t.Fatalf("offline channel updates = %+v pts=%d, want available boundary %d with unchanged channel pts=%d",
|
|
||||||
channelDiff.OtherUpdates, channelDiff.Pts, msg.ID, newChannelUpdate.Pts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &tg.MessagesGetDialogsRequest{OffsetPeer: &tg.InputPeerEmpty{}, Limit: 20}
|
req := &tg.MessagesGetDialogsRequest{OffsetPeer: &tg.InputPeerEmpty{}, Limit: 20}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ func tgChannelDifference(viewerUserID int64, diff domain.ChannelDifference) tg.U
|
||||||
Users: tgUsersForViewer(viewerUserID, diff.Users),
|
Users: tgUsersForViewer(viewerUserID, diff.Users),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(diff.Events) == 0 && len(diff.NewMessages) == 0 && len(diff.OtherUpdates) == 0 && diff.AvailableMinID == 0 {
|
if len(diff.Events) == 0 && len(diff.NewMessages) == 0 && len(diff.OtherUpdates) == 0 {
|
||||||
return &tg.UpdatesChannelDifferenceEmpty{
|
return &tg.UpdatesChannelDifferenceEmpty{
|
||||||
Final: diff.Final,
|
Final: diff.Final,
|
||||||
Pts: diff.Pts,
|
Pts: diff.Pts,
|
||||||
|
|
@ -148,12 +148,6 @@ func tgChannelDifference(viewerUserID int64, diff domain.ChannelDifference) tg.U
|
||||||
updates = append(updates, update)
|
updates = append(updates, update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if diff.AvailableMinID > 0 {
|
|
||||||
updates = append(updates, &tg.UpdateChannelAvailableMessages{
|
|
||||||
ChannelID: diff.Channel.ID,
|
|
||||||
AvailableMinID: diff.AvailableMinID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
chats := tgChannelDifferenceChats(viewerUserID, diff)
|
chats := tgChannelDifferenceChats(viewerUserID, diff)
|
||||||
users := tgUsersForViewer(viewerUserID, diff.Users)
|
users := tgUsersForViewer(viewerUserID, diff.Users)
|
||||||
return &tg.UpdatesChannelDifference{
|
return &tg.UpdatesChannelDifference{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue