Restore user query buffer unread status

This commit is contained in:
Simon Ser 2021-08-23 12:25:43 +02:00
parent 016ca27f2d
commit c47af780f6
2 changed files with 30 additions and 2 deletions

View File

@ -272,7 +272,11 @@ export default class App extends Component {
[id, updated] = State.createBuffer(state, name, serverID, client); [id, updated] = State.createBuffer(state, name, serverID, client);
return updated; return updated;
}); });
this.bufferStore.put({ name, server: client.params }); this.bufferStore.put({
name,
server: client.params,
unread: Unread.NONE,
});
return id; return id;
} }
@ -305,6 +309,13 @@ export default class App extends Component {
} }
let lastMsg = buf.messages[buf.messages.length - 1]; let lastMsg = buf.messages[buf.messages.length - 1];
this.setReceipt(buf.name, ReceiptType.READ, lastMsg); this.setReceipt(buf.name, ReceiptType.READ, lastMsg);
let client = this.clients.get(buf.server);
this.bufferStore.put({
name: buf.name,
server: client.params,
unread: Unread.NONE,
});
}); });
} }
@ -442,12 +453,17 @@ export default class App extends Component {
// TODO: set unread if scrolled up // TODO: set unread if scrolled up
let unread = buf.unread; let unread = buf.unread;
let lastReadReceipt = buf.lastReadReceipt; let lastReadReceipt = buf.lastReadReceipt;
if (this.state.activeBuffer != buf.id) { if (this.state.activeBuffer !== buf.id) {
unread = Unread.union(unread, msgUnread); unread = Unread.union(unread, msgUnread);
} else { } else {
this.setReceipt(bufName, ReceiptType.READ, msg); this.setReceipt(bufName, ReceiptType.READ, msg);
lastReadReceipt = this.getReceipt(bufName, ReceiptType.READ); lastReadReceipt = this.getReceipt(bufName, ReceiptType.READ);
} }
this.bufferStore.put({
name: buf.name,
server: client.params,
unread,
});
return { unread, lastReadReceipt }; return { unread, lastReadReceipt };
}); });
} }
@ -548,6 +564,9 @@ export default class App extends Component {
continue; continue;
} }
this.createBuffer(serverID, buf.name); this.createBuffer(serverID, buf.name);
if (client.enabledCaps["draft/chathistory"]) {
this.setBufferState({ server: serverID, name: buf.name }, { unread: buf.unread });
}
client.who(buf.name); client.who(buf.name);
} }

View File

@ -65,14 +65,23 @@ export class Buffer {
} }
put(buf) { put(buf) {
let key = this.key(buf);
let prev = this.m.get(key);
if (prev && prev.unread === buf.unread) {
return;
}
this.m.set(this.key(buf), { this.m.set(this.key(buf), {
name: buf.name, name: buf.name,
unread: buf.unread,
server: { server: {
url: buf.server.url, url: buf.server.url,
nick: buf.server.nick, nick: buf.server.nick,
bouncerNetwork: buf.server.bouncerNetwork, bouncerNetwork: buf.server.bouncerNetwork,
}, },
}); });
this.save(); this.save();
} }