Skip to content

Commit e383012

Browse files
committed
fix: keep chats the user asked for out of the unanswered list
A chat the user asked for (backfill --chat, watch) is no longer asked about, so its old answer stayed in doctor and unwatch --missing turned it off. Both now leave such chats alone.
1 parent 2acc15d commit e383012

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎core/operations.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ async function channelShow(ctx, args = {}) {
290290
};
291291
}
292292

293-
// args: { chat, enable }. Toggle the per-chat archive flag; enabling also makes sure
294-
// a job fetches what arrived while the chat was off. Returns the new sync state plus
295-
// job info.
296293
// The chats doctor lists as missing from the dialog list with no answer from Telegram.
297294
async function channelsUnwatchMissing(ctx) {
298295
return { channelIds: ctx.messageSyncService.unwatchUnansweredChats() };
299296
}
300297

298+
// args: { chat, enable }. Toggle the per-chat archive flag; enabling also makes sure
299+
// a job fetches what arrived while the chat was off. Returns the new sync state plus
300+
// job info.
301301
async function channelSetSync(ctx, args = {}) {
302302
const chatId = await ctx.messageSyncService.resolveChatKey(args.chat);
303303
const result = ctx.messageSyncService.setChannelSync(chatId, Boolean(args.enable));

‎message-sync-service.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ export default class MessageSyncService {
33033303
listUnansweredChats() {
33043304
return this.db.prepare(`
33053305
SELECT channel_id, peer_title, membership_checked_at FROM channels
3306-
WHERE sync_enabled = 1 AND in_dialogs = 0 AND membership = 'unknown'
3306+
WHERE sync_enabled = 1 AND in_dialogs = 0 AND membership = 'unknown' AND COALESCE(sync_by_user, 0) = 0
33073307
ORDER BY channel_id
33083308
`).all();
33093309
}
@@ -3313,7 +3313,7 @@ export default class MessageSyncService {
33133313
UPDATE channels
33143314
SET sync_enabled = 0, sync_by_user = 0, sync_off_reason = NULL, membership = NULL,
33153315
membership_checked_at = NULL, updated_at = CURRENT_TIMESTAMP
3316-
WHERE sync_enabled = 1 AND in_dialogs = 0 AND membership = 'unknown'
3316+
WHERE sync_enabled = 1 AND in_dialogs = 0 AND membership = 'unknown' AND COALESCE(sync_by_user, 0) = 0
33173317
RETURNING channel_id
33183318
`).all().map((row) => row.channel_id).sort();
33193319
}

‎tests/doctor-unanswered.test.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,19 @@ describe('doctor unanswered chats', () => {
9999
});
100100

101101
describe('turning off the unanswered chats', () => {
102-
it('turns off only those, as if the user had, and leaves them off when they come back', async () => {
102+
it('turns off only those, as if the user had', async () => {
103103
const service = new MessageSyncService(null, { dbPath: path.join(storeDir, 'messages.db') });
104104
for (const [sql, ...params] of [
105105
chat('-1000000000820'),
106106
chat('-1000000000821'),
107107
chat('-1000000000822', { membership: 'member' }),
108-
chat('-1000000000823', { inDialogs: 1, membership: null }),
108+
chat('-1000000000823', { inDialogs: 1 }),
109+
chat('-1000000000824'),
109110
]) {
110111
service.db.prepare(sql).run(...params);
111112
}
113+
// One the user asked for stays theirs.
114+
service.db.prepare('UPDATE channels SET sync_by_user = 1 WHERE channel_id = ?').run('-1000000000824');
112115

113116
expect(service.unwatchUnansweredChats()).toEqual(['-1000000000820', '-1000000000821']);
114117
const rows = Object.fromEntries(service.db.prepare('SELECT channel_id, sync_enabled, sync_off_reason FROM channels').all()
@@ -118,6 +121,7 @@ describe('turning off the unanswered chats', () => {
118121
'-1000000000821': [0, null],
119122
'-1000000000822': [1, null],
120123
'-1000000000823': [1, null],
124+
'-1000000000824': [1, null],
121125
});
122126
expect(service.listUnansweredChats()).toEqual([]);
123127
service.close();

0 commit comments

Comments
 (0)