add mailbox
This commit is contained in:
Vendored
+32
-2
@@ -393,6 +393,7 @@
|
|||||||
socketAddress: [DATA_VERSION, "connection", "socket-address"],
|
socketAddress: [DATA_VERSION, "connection", "socket-address"],
|
||||||
reconnectAddress: [DATA_VERSION, "connection", "reconnect-address"],
|
reconnectAddress: [DATA_VERSION, "connection", "reconnect-address"],
|
||||||
outbox: [DATA_VERSION, "connection", "outbox"],
|
outbox: [DATA_VERSION, "connection", "outbox"],
|
||||||
|
mailboxes: [DATA_VERSION, "connection", "mailboxes"],
|
||||||
// settings
|
// settings
|
||||||
username: [DATA_VERSION, "settings", "user-name"],
|
username: [DATA_VERSION, "settings", "user-name"],
|
||||||
firstDayOfWeek: [DATA_VERSION, "settings", "first-day-of-week"],
|
firstDayOfWeek: [DATA_VERSION, "settings", "first-day-of-week"],
|
||||||
@@ -1657,7 +1658,6 @@
|
|||||||
connect = (address) => {
|
connect = (address) => {
|
||||||
this.udn.connect(address);
|
this.udn.connect(address);
|
||||||
};
|
};
|
||||||
a;
|
|
||||||
disconnect = () => {
|
disconnect = () => {
|
||||||
this.udn.disconnect();
|
this.udn.disconnect();
|
||||||
const reconnectAddressPath = storageKeys.reconnectAddress;
|
const reconnectAddressPath = storageKeys.reconnectAddress;
|
||||||
@@ -1671,10 +1671,29 @@
|
|||||||
this.connectionChangeHandler();
|
this.connectionChangeHandler();
|
||||||
if (this.isConnected == false) return;
|
if (this.isConnected == false) return;
|
||||||
if (!this.address) return;
|
if (!this.address) return;
|
||||||
|
this.connectMailbox();
|
||||||
this.storeAddress(this.address);
|
this.storeAddress(this.address);
|
||||||
this.sendSubscriptionRequest();
|
this.sendSubscriptionRequest();
|
||||||
this.sendMessagesInOutbox();
|
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
|
// subscription
|
||||||
addChannel = (channel) => {
|
addChannel = (channel) => {
|
||||||
this.channelsToSubscribe.add(channel);
|
this.channelsToSubscribe.add(channel);
|
||||||
@@ -1685,6 +1704,7 @@
|
|||||||
for (const channel of this.channelsToSubscribe) {
|
for (const channel of this.channelsToSubscribe) {
|
||||||
this.udn.subscribe(channel);
|
this.udn.subscribe(channel);
|
||||||
}
|
}
|
||||||
|
this.connectMailbox();
|
||||||
};
|
};
|
||||||
// outbox
|
// outbox
|
||||||
getOutboxMessags = () => {
|
getOutboxMessags = () => {
|
||||||
@@ -1743,7 +1763,6 @@
|
|||||||
this.storageModel.store(addressPath, "");
|
this.storageModel.store(addressPath, "");
|
||||||
const reconnectAddressPath = storageKeys.reconnectAddress;
|
const reconnectAddressPath = storageKeys.reconnectAddress;
|
||||||
this.storageModel.store(reconnectAddressPath, address);
|
this.storageModel.store(reconnectAddressPath, address);
|
||||||
this.storageModel.print();
|
|
||||||
};
|
};
|
||||||
removeAddress = (address) => {
|
removeAddress = (address) => {
|
||||||
const addressPath = this.getAddressPath(address);
|
const addressPath = this.getAddressPath(address);
|
||||||
@@ -1776,6 +1795,17 @@
|
|||||||
this.udn.ondisconnect = () => {
|
this.udn.ondisconnect = () => {
|
||||||
this.handleConnectionChange();
|
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 reconnectAddressPath = storageKeys.reconnectAddress;
|
||||||
const reconnectAddress = storageModel2.restore(reconnectAddressPath);
|
const reconnectAddress = storageModel2.restore(reconnectAddressPath);
|
||||||
if (reconnectAddress != null) {
|
if (reconnectAddress != null) {
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"bloatless-react": "^1.3.8",
|
"bloatless-react": "^1.3.9",
|
||||||
"esbuild": "^0.23.0",
|
"esbuild": "^0.23.0",
|
||||||
"udn-frontend": "^1.0.7-beta1",
|
"udn-frontend": "^1.0.8",
|
||||||
"uuid": "^10.0.0"
|
"uuid": "^10.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -50,11 +50,34 @@ export default class ConnectionModel {
|
|||||||
if (this.isConnected == false) return;
|
if (this.isConnected == false) return;
|
||||||
if (!this.address) return;
|
if (!this.address) return;
|
||||||
|
|
||||||
|
this.connectMailbox();
|
||||||
this.storeAddress(this.address);
|
this.storeAddress(this.address);
|
||||||
this.sendSubscriptionRequest();
|
this.sendSubscriptionRequest();
|
||||||
this.sendMessagesInOutbox();
|
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
|
// subscription
|
||||||
addChannel = (channel: string): void => {
|
addChannel = (channel: string): void => {
|
||||||
this.channelsToSubscribe.add(channel);
|
this.channelsToSubscribe.add(channel);
|
||||||
@@ -67,6 +90,8 @@ export default class ConnectionModel {
|
|||||||
for (const channel of this.channelsToSubscribe) {
|
for (const channel of this.channelsToSubscribe) {
|
||||||
this.udn.subscribe(channel);
|
this.udn.subscribe(channel);
|
||||||
}
|
}
|
||||||
|
// update mailbox
|
||||||
|
this.connectMailbox();
|
||||||
};
|
};
|
||||||
|
|
||||||
// outbox
|
// outbox
|
||||||
@@ -142,7 +167,6 @@ export default class ConnectionModel {
|
|||||||
// reconnect
|
// reconnect
|
||||||
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
|
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
|
||||||
this.storageModel.store(reconnectAddressPath, address);
|
this.storageModel.store(reconnectAddressPath, address);
|
||||||
this.storageModel.print();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
removeAddress = (address: string): void => {
|
removeAddress = (address: string): void => {
|
||||||
@@ -187,6 +211,19 @@ export default class ConnectionModel {
|
|||||||
this.handleConnectionChange();
|
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
|
// reconnect
|
||||||
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
|
const reconnectAddressPath: string[] = storageKeys.reconnectAddress;
|
||||||
const reconnectAddress: string | null =
|
const reconnectAddress: string | null =
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ export const storageKeys = {
|
|||||||
socketAddress: [DATA_VERSION, "connection", "socket-address"],
|
socketAddress: [DATA_VERSION, "connection", "socket-address"],
|
||||||
reconnectAddress: [DATA_VERSION, "connection", "reconnect-address"],
|
reconnectAddress: [DATA_VERSION, "connection", "reconnect-address"],
|
||||||
outbox: [DATA_VERSION, "connection", "outbox"],
|
outbox: [DATA_VERSION, "connection", "outbox"],
|
||||||
|
mailboxes: [DATA_VERSION, "connection", "mailboxes"],
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
username: [DATA_VERSION, "settings", "user-name"],
|
username: [DATA_VERSION, "settings", "user-name"],
|
||||||
|
|||||||
Reference in New Issue
Block a user