mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-28 18:45:51 -05:00
Restore channel unread status from local storage
Closes: https://todo.sr.ht/~emersion/gamja/75 Closes: https://todo.sr.ht/~emersion/gamja/89
This commit is contained in:
parent
c470c9f2c0
commit
aa9ce73d5a
2 changed files with 28 additions and 16 deletions
|
@ -264,6 +264,22 @@ export default class App extends Component {
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncBufferUnread(serverID, name) {
|
||||||
|
let client = this.clients.get(serverID);
|
||||||
|
|
||||||
|
let stored = this.bufferStore.get({ name, server: client.params });
|
||||||
|
if (client.enabledCaps["draft/chathistory"] && stored) {
|
||||||
|
this.setBufferState({ server: serverID, name }, { unread: stored.unread });
|
||||||
|
}
|
||||||
|
if (!stored) {
|
||||||
|
this.bufferStore.put({
|
||||||
|
name,
|
||||||
|
server: client.params,
|
||||||
|
unread: Unread.NONE,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createBuffer(serverID, name) {
|
createBuffer(serverID, name) {
|
||||||
let client = this.clients.get(serverID);
|
let client = this.clients.get(serverID);
|
||||||
let id = null;
|
let id = null;
|
||||||
|
@ -272,11 +288,7 @@ 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({
|
this.syncBufferUnread(serverID, name);
|
||||||
name,
|
|
||||||
server: client.params,
|
|
||||||
unread: Unread.NONE,
|
|
||||||
});
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +365,7 @@ export default class App extends Component {
|
||||||
let last = null;
|
let last = null;
|
||||||
this.receipts.forEach((receipts, target) => {
|
this.receipts.forEach((receipts, target) => {
|
||||||
let delivery = receipts[type];
|
let delivery = receipts[type];
|
||||||
if (target == "*" || !delivery || !delivery.time) {
|
if (!delivery || !delivery.time) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!last || delivery.time > last.time) {
|
if (!last || delivery.time > last.time) {
|
||||||
|
@ -559,26 +571,20 @@ export default class App extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore opened user query buffers
|
// Restore opened user query buffers
|
||||||
for (let buf of this.bufferStore.load(client.params)) {
|
for (let buf of this.bufferStore.list(client.params)) {
|
||||||
if (buf.name === "*" || client.isChannel(buf.name)) {
|
if (buf.name === "*" || client.isChannel(buf.name)) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastReceipt = this.latestReceipt(ReceiptType.READ);
|
let lastReceipt = this.latestReceipt(ReceiptType.DELIVERED);
|
||||||
if (lastReceipt && lastReceipt.time && client.enabledCaps["draft/chathistory"] && (!client.enabledCaps["soju.im/bouncer-networks"] || client.params.bouncerNetwork)) {
|
if (lastReceipt && lastReceipt.time && client.enabledCaps["draft/chathistory"] && (!client.enabledCaps["soju.im/bouncer-networks"] || client.params.bouncerNetwork)) {
|
||||||
let now = irc.formatDate(new Date());
|
let now = irc.formatDate(new Date());
|
||||||
client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => {
|
client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => {
|
||||||
targets.forEach((target) => {
|
targets.forEach((target) => {
|
||||||
let from = this.getReceipt(target, ReceiptType.READ);
|
let from = lastReceipt;
|
||||||
if (!from) {
|
|
||||||
from = lastReceipt;
|
|
||||||
}
|
|
||||||
let to = { time: msg.tags.time || irc.formatDate(new Date()) };
|
let to = { time: msg.tags.time || irc.formatDate(new Date()) };
|
||||||
this.fetchBacklog(client, target.name, from, to);
|
this.fetchBacklog(client, target.name, from, to);
|
||||||
});
|
});
|
||||||
|
@ -619,6 +625,8 @@ export default class App extends Component {
|
||||||
case "JOIN":
|
case "JOIN":
|
||||||
channel = msg.params[0];
|
channel = msg.params[0];
|
||||||
|
|
||||||
|
this.syncBufferUnread(serverID, channel);
|
||||||
|
|
||||||
if (!client.isMyNick(msg.prefix.name)) {
|
if (!client.isMyNick(msg.prefix.name)) {
|
||||||
this.addMessage(serverID, channel, msg);
|
this.addMessage(serverID, channel, msg);
|
||||||
}
|
}
|
||||||
|
|
6
store.js
6
store.js
|
@ -64,6 +64,10 @@ export class Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get(buf) {
|
||||||
|
return this.m.get(this.key(buf));
|
||||||
|
}
|
||||||
|
|
||||||
put(buf) {
|
put(buf) {
|
||||||
let key = this.key(buf);
|
let key = this.key(buf);
|
||||||
|
|
||||||
|
@ -90,7 +94,7 @@ export class Buffer {
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
load(server) {
|
list(server) {
|
||||||
let buffers = [];
|
let buffers = [];
|
||||||
for (const buf of this.m.values()) {
|
for (const buf of this.m.values()) {
|
||||||
if (buf.server.url !== server.url || buf.server.nick !== server.nick || buf.server.bouncerNetwork !== server.bouncerNetwork) {
|
if (buf.server.url !== server.url || buf.server.nick !== server.nick || buf.server.bouncerNetwork !== server.bouncerNetwork) {
|
||||||
|
|
Loading…
Reference in a new issue