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
BIN
View File
Binary file not shown.
+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) {
+2 -2
View File
@@ -1,9 +1,9 @@
{
"dependencies": {
"@types/uuid": "^10.0.0",
"bloatless-react": "^1.3.8",
"bloatless-react": "^1.3.9",
"esbuild": "^0.23.0",
"udn-frontend": "^1.0.7-beta1",
"udn-frontend": "^1.0.8",
"uuid": "^10.0.0"
},
"scripts": {
+38 -1
View File
@@ -50,11 +50,34 @@ export default class ConnectionModel {
if (this.isConnected == false) return;
if (!this.address) return;
this.connectMailbox();
this.storeAddress(this.address);
this.sendSubscriptionRequest();
this.sendMessagesInOutbox();
};
// mailbox
requestNewMailbox = (): void => {
console.trace("requesting mailbox");
this.udn.requestMailbox();
};
connectMailbox = (): void => {
if (this.address == undefined) 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: string): void => {
if (this.address == undefined) return;
const path = [...storageKeys.mailboxes, this.address];
this.storageModel.store(path, mailboxId);
};
// subscription
addChannel = (channel: string): void => {
this.channelsToSubscribe.add(channel);
@@ -67,6 +90,8 @@ export default class ConnectionModel {
for (const channel of this.channelsToSubscribe) {
this.udn.subscribe(channel);
}
// update mailbox
this.connectMailbox();
};
// outbox
@@ -142,7 +167,6 @@ export default class ConnectionModel {
// reconnect
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
this.storageModel.store(reconnectAddressPath, address);
this.storageModel.print();
};
removeAddress = (address: string): void => {
@@ -187,6 +211,19 @@ export default class ConnectionModel {
this.handleConnectionChange();
};
this.udn.onmailboxcreate = (mailboxId: string) => {
console.log("created mailbox", mailboxId);
this.storeMailbox(mailboxId);
this.connectMailbox();
};
this.udn.onmailboxdelete = (mailboxId: string) => {
console.log(`mailbox ${mailboxId} deleted`);
this.requestNewMailbox();
};
this.udn.onmailboxconnect = (mailboxId: string) => {
console.log(`using mailbox ${mailboxId}`);
};
// reconnect
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
const reconnectAddress: string | null =
+1
View File
@@ -133,6 +133,7 @@ export const storageKeys = {
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"],