forked from CringeStudios/gamja
Restore opened user query buffers
Closes: https://todo.sr.ht/~emersion/gamja/93
This commit is contained in:
parent
4dd1fac002
commit
016ca27f2d
@ -170,6 +170,7 @@ export default class App extends Component {
|
|||||||
this.saveReceipts = debounce(this.saveReceipts.bind(this), 500);
|
this.saveReceipts = debounce(this.saveReceipts.bind(this), 500);
|
||||||
|
|
||||||
this.receipts = store.receipts.load();
|
this.receipts = store.receipts.load();
|
||||||
|
this.bufferStore = new store.Buffer();
|
||||||
|
|
||||||
configPromise.then((config) => {
|
configPromise.then((config) => {
|
||||||
this.handleConfig(config);
|
this.handleConfig(config);
|
||||||
@ -264,13 +265,14 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createBuffer(serverID, name) {
|
createBuffer(serverID, name) {
|
||||||
|
let client = this.clients.get(serverID);
|
||||||
let id = null;
|
let id = null;
|
||||||
this.setState((state) => {
|
this.setState((state) => {
|
||||||
let client = this.clients.get(serverID);
|
|
||||||
let updated;
|
let updated;
|
||||||
[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 });
|
||||||
return id;
|
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);
|
let lastReceipt = this.latestReceipt(ReceiptType.READ);
|
||||||
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());
|
||||||
@ -869,9 +880,12 @@ export default class App extends Component {
|
|||||||
for (let serverID of this.clients.keys()) {
|
for (let serverID of this.clients.keys()) {
|
||||||
this.close({ server: serverID, name: SERVER_BUFFER });
|
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) {
|
if (buf.server == 1) {
|
||||||
store.autoconnect.put(null);
|
store.autoconnect.put(null);
|
||||||
}
|
}
|
||||||
@ -889,6 +903,8 @@ export default class App extends Component {
|
|||||||
|
|
||||||
this.receipts.delete(buf.name);
|
this.receipts.delete(buf.name);
|
||||||
this.saveReceipts();
|
this.saveReceipts();
|
||||||
|
|
||||||
|
this.bufferStore.delete({ name: buf.name, server: client.params });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
68
store.js
68
store.js
@ -35,3 +35,71 @@ export const receipts = {
|
|||||||
rawReceipts.put(Object.fromEntries(m));
|
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…
x
Reference in New Issue
Block a user