mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Restore opened user query buffers
Closes: https://todo.sr.ht/~emersion/gamja/93
This commit is contained in:
parent
4dd1fac002
commit
016ca27f2d
2 changed files with 86 additions and 2 deletions
|
@ -170,6 +170,7 @@ export default class App extends Component {
|
|||
this.saveReceipts = debounce(this.saveReceipts.bind(this), 500);
|
||||
|
||||
this.receipts = store.receipts.load();
|
||||
this.bufferStore = new store.Buffer();
|
||||
|
||||
configPromise.then((config) => {
|
||||
this.handleConfig(config);
|
||||
|
@ -264,13 +265,14 @@ export default class App extends Component {
|
|||
}
|
||||
|
||||
createBuffer(serverID, name) {
|
||||
let client = this.clients.get(serverID);
|
||||
let id = null;
|
||||
this.setState((state) => {
|
||||
let client = this.clients.get(serverID);
|
||||
let updated;
|
||||
[id, updated] = State.createBuffer(state, name, serverID, client);
|
||||
return updated;
|
||||
});
|
||||
this.bufferStore.put({ name, server: client.params });
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -540,6 +542,15 @@ export default class App extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
// Restore opened user query buffers
|
||||
for (let buf of this.bufferStore.load(client.params)) {
|
||||
if (buf.name === "*" || client.isChannel(buf.name)) {
|
||||
continue;
|
||||
}
|
||||
this.createBuffer(serverID, buf.name);
|
||||
client.who(buf.name);
|
||||
}
|
||||
|
||||
let lastReceipt = this.latestReceipt(ReceiptType.READ);
|
||||
if (lastReceipt && lastReceipt.time && client.enabledCaps["draft/chathistory"] && (!client.enabledCaps["soju.im/bouncer-networks"] || client.params.bouncerNetwork)) {
|
||||
let now = irc.formatDate(new Date());
|
||||
|
@ -869,9 +880,12 @@ export default class App extends Component {
|
|||
for (let serverID of this.clients.keys()) {
|
||||
this.close({ server: serverID, name: SERVER_BUFFER });
|
||||
}
|
||||
this.bufferStore.clear();
|
||||
} else {
|
||||
this.bufferStore.clear(client.params);
|
||||
}
|
||||
|
||||
// TODO: only clear local storage if this server is stored there
|
||||
// TODO: only clear autoconnect if this server is stored there
|
||||
if (buf.server == 1) {
|
||||
store.autoconnect.put(null);
|
||||
}
|
||||
|
@ -889,6 +903,8 @@ export default class App extends Component {
|
|||
|
||||
this.receipts.delete(buf.name);
|
||||
this.saveReceipts();
|
||||
|
||||
this.bufferStore.delete({ name: buf.name, server: client.params });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
68
store.js
68
store.js
|
@ -35,3 +35,71 @@ export const receipts = {
|
|||
rawReceipts.put(Object.fromEntries(m));
|
||||
},
|
||||
};
|
||||
|
||||
export class Buffer {
|
||||
raw = new Item("buffers");
|
||||
m = null;
|
||||
|
||||
constructor() {
|
||||
var obj = this.raw.load();
|
||||
this.m = new Map(Object.entries(obj || {}));
|
||||
}
|
||||
|
||||
key(buf) {
|
||||
return JSON.stringify({
|
||||
name: buf.name,
|
||||
server: {
|
||||
url: buf.server.url,
|
||||
nick: buf.server.nick,
|
||||
bouncerNetwork: buf.server.bouncerNetwork,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
save() {
|
||||
if (this.m.size > 0) {
|
||||
this.raw.put(Object.fromEntries(this.m));
|
||||
} else {
|
||||
this.raw.put(null);
|
||||
}
|
||||
}
|
||||
|
||||
put(buf) {
|
||||
this.m.set(this.key(buf), {
|
||||
name: buf.name,
|
||||
server: {
|
||||
url: buf.server.url,
|
||||
nick: buf.server.nick,
|
||||
bouncerNetwork: buf.server.bouncerNetwork,
|
||||
},
|
||||
});
|
||||
this.save();
|
||||
}
|
||||
|
||||
delete(buf) {
|
||||
this.m.delete(this.key(buf));
|
||||
this.save();
|
||||
}
|
||||
|
||||
load(server) {
|
||||
let buffers = [];
|
||||
for (const buf of this.m.values()) {
|
||||
if (buf.server.url !== server.url || buf.server.nick !== server.nick || buf.server.bouncerNetwork !== server.bouncerNetwork) {
|
||||
continue;
|
||||
}
|
||||
buffers.push(buf);
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
|
||||
clear(server) {
|
||||
if (server) {
|
||||
for (const buf of this.load(server)) {
|
||||
this.m.delete(this.key(buf));
|
||||
}
|
||||
} else {
|
||||
this.m = new Map();
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue