add mailbox

This commit is contained in:
marlon-erler
2024-07-21 15:15:24 +02:00
parent a7a416ba30
commit fd52b7af03
5 changed files with 73 additions and 5 deletions
+32 -2
View File
@@ -393,6 +393,7 @@
socketAddress: [DATA_VERSION, "connection", "socket-address"],
reconnectAddress: [DATA_VERSION, "connection", "reconnect-address"],
outbox: [DATA_VERSION, "connection", "outbox"],
mailboxes: [DATA_VERSION, "connection", "mailboxes"],
// settings
username: [DATA_VERSION, "settings", "user-name"],
firstDayOfWeek: [DATA_VERSION, "settings", "first-day-of-week"],
@@ -1657,7 +1658,6 @@
connect = (address) => {
this.udn.connect(address);
};
a;
disconnect = () => {
this.udn.disconnect();
const reconnectAddressPath = storageKeys.reconnectAddress;
@@ -1671,10 +1671,29 @@
this.connectionChangeHandler();
if (this.isConnected == false) return;
if (!this.address) return;
this.connectMailbox();
this.storeAddress(this.address);
this.sendSubscriptionRequest();
this.sendMessagesInOutbox();
};
// mailbox
requestNewMailbox = () => {
console.trace("requesting mailbox");
this.udn.requestMailbox();
};
connectMailbox = () => {
if (this.address == void 0) return;
const path = [...storageKeys.mailboxes, this.address];
const mailboxId = this.storageModel.restore(path);
console.log("connecting mailbox", mailboxId);
if (mailboxId == null) return this.requestNewMailbox();
this.udn.connectMailbox(mailboxId);
};
storeMailbox = (mailboxId) => {
if (this.address == void 0) return;
const path = [...storageKeys.mailboxes, this.address];
this.storageModel.store(path, mailboxId);
};
// subscription
addChannel = (channel) => {
this.channelsToSubscribe.add(channel);
@@ -1685,6 +1704,7 @@
for (const channel of this.channelsToSubscribe) {
this.udn.subscribe(channel);
}
this.connectMailbox();
};
// outbox
getOutboxMessags = () => {
@@ -1743,7 +1763,6 @@
this.storageModel.store(addressPath, "");
const reconnectAddressPath = storageKeys.reconnectAddress;
this.storageModel.store(reconnectAddressPath, address);
this.storageModel.print();
};
removeAddress = (address) => {
const addressPath = this.getAddressPath(address);
@@ -1776,6 +1795,17 @@
this.udn.ondisconnect = () => {
this.handleConnectionChange();
};
this.udn.onmailboxcreate = (mailboxId) => {
console.log("Created mailbox", mailboxId);
this.storeMailbox(mailboxId);
this.connectMailbox();
};
this.udn.onmailboxdelete = () => {
this.requestNewMailbox();
};
this.udn.onmailboxconnect = (mailboxId) => {
console.log(`Using mailbox ${mailboxId}`);
};
const reconnectAddressPath = storageKeys.reconnectAddress;
const reconnectAddress = storageModel2.restore(reconnectAddressPath);
if (reconnectAddress != null) {