generated from exteraGramPlugins/pluginBase
Two bugs visible in a device log. "injector: anchor 0 not loaded, skipping insert" was a regression from the previous commit. _newest_visible_message_id returns 0 when the offset reaches past the loaded window, and the strict anchor check then refused to place the card, so pressing Summarize appeared to do nothing at all. Before that commit anchor 0 silently matched a date separator, which is why it went unnoticed. A live card is the user's only feedback that the press registered, so it must always appear: try the exact anchor, then id ordering, then the bottom of the chat, and let reanchor() move it once the analyzed range is known. Restoring saved summaries stays strict, since nothing corrects their position later. _newest_visible_message_id also falls back to the oldest loaded message rather than returning 0. The unread button prefilled a smaller range on each press -- 1000, then 15, then 75, with ~1100 unread. Viewing a chat calls MessagesController.markDialogAsRead, so dialog.unread_count decays while the chat is open and no longer describes the backlog the user wants summarized. Resolve the count from the unread divider instead, which is what the app's own button uses (onPageDownClicked branches on createUnreadMessageAfterId) and which does not decay while the chat stays open, and keep the largest value seen per chat so a later press never prefills less than an earlier one. Both are covered by tests that fail against the previous behaviour: the strict anchor path reports inserted=True while leaving no card in the list, and the unread resolver reproduces exactly 1100, 15, 75.