add mailbox
This commit is contained in:
Vendored
+32
-2
@@ -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
@@ -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": {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user