Make scheduled message ids determenistic.

Fixes #6686.
This commit is contained in:
John Preston 2022-03-11 11:04:46 +04:00
parent 1bc438ed01
commit 1833fac094
6 changed files with 10 additions and 7 deletions

View File

@ -113,12 +113,9 @@ HistoryItemsList::const_iterator Groups::findPositionForItem(
const HistoryItemsList &group,
not_null<HistoryItem*> item) {
const auto last = end(group);
if (!item->isRegular()) {
return last;
}
const auto itemId = item->id;
for (auto result = begin(group); result != last; ++result) {
if ((*result)->isRegular() && (*result)->id > itemId) {
if ((*result)->id > itemId) {
return result;
}
}

View File

@ -76,6 +76,7 @@ Q_DECLARE_METATYPE(MsgId);
constexpr auto StartClientMsgId = MsgId(0x01 - (1LL << 58));
constexpr auto EndClientMsgId = MsgId(-(1LL << 57));
constexpr auto ServerMaxMsgId = MsgId(1LL << 56);
constexpr auto ScheduledMsgIdsRange = (1LL << 32);
constexpr auto ShowAtUnreadMsgId = MsgId(0);
constexpr auto SpecialMsgIdShift = EndClientMsgId.bare;

View File

@ -319,7 +319,7 @@ void ScheduledMessages::apply(
} else {
Assert(!list.itemById.contains(local->id));
Assert(!list.idByItem.contains(local));
local->setRealId(local->history()->nextNonHistoryEntryId());
local->setRealId(local->history()->scheduledMessageId(id));
list.idByItem.emplace(local, id);
list.itemById.emplace(id, local);
}
@ -467,7 +467,7 @@ HistoryItem *ScheduledMessages::append(
}
const auto item = _session->data().addNewMessage(
history->nextNonHistoryEntryId(),
history->scheduledMessageId(id),
PrepareMessage(message),
MessageFlags(), // localFlags
NewMessageType::Existing);

View File

@ -993,7 +993,7 @@ private:
std::unique_ptr<SponsoredMessages> _sponsoredMessages;
const std::unique_ptr<Reactions> _reactions;
MsgId _nonHistoryEntryId = ServerMaxMsgId;
MsgId _nonHistoryEntryId = ServerMaxMsgId.bare + ScheduledMsgIdsRange;
rpl::lifetime _lifetime;

View File

@ -1760,6 +1760,10 @@ MsgId History::nextNonHistoryEntryId() {
return owner().nextNonHistoryEntryId();
}
MsgId History::scheduledMessageId(MsgId remoteScheduledMsgId) const {
return ServerMaxMsgId + remoteScheduledMsgId + 1;
}
bool History::folderKnown() const {
return _folder.has_value();
}

View File

@ -439,6 +439,7 @@ public:
[[nodiscard]] std::pair<Element*, int> findItemAndOffset(int top) const;
[[nodiscard]] MsgId nextNonHistoryEntryId();
[[nodiscard]] MsgId scheduledMessageId(MsgId remoteScheduledMsgId) const;
bool folderKnown() const override;
Data::Folder *folder() const override;