mirror of
https://github.com/balzack/databag.git
synced 2025-05-04 07:25:15 +00:00
more contact module
This commit is contained in:
parent
aa2ba3b072
commit
96a225a6b7
@ -77,21 +77,15 @@ export interface Contact {
|
|||||||
flagCard(cardId: string): Promise<void>;
|
flagCard(cardId: string): Promise<void>;
|
||||||
flagArticle(cardId: string, articleId: string): Promise<void>;
|
flagArticle(cardId: string, articleId: string): Promise<void>;
|
||||||
flagChannel(cardId: string, channelId: string): Promise<void>;
|
flagChannel(cardId: string, channelId: string): Promise<void>;
|
||||||
setBlockCard(cardId: string): Promise<void>;
|
setBlockedCard(cardId: string, blocked: boolean): Promise<void>;
|
||||||
setBlockArticle(cardId: string, articleId: string): Promise<void>;
|
setBlockedArticle(cardId: string, articleId: string, blocked: boolean): Promise<void>;
|
||||||
setBlockChannel(cardId: string, channelId: string): Promise<void>;
|
setBlockedChannel(cardId: string, channelId: string, blocked: boolean): Promise<void>;
|
||||||
clearBlockCard(cardId: string): Promise<void>;
|
|
||||||
clearBlockArticle(cardId: string, articleId: string): Promise<void>;
|
|
||||||
clearBlockChannel(cardId: string, channelId: string): Promise<void>;
|
|
||||||
getBlockedCards(): Promise<{ cardId: string }[]>;
|
getBlockedCards(): Promise<{ cardId: string }[]>;
|
||||||
getBlockedChannels(): Promise<{ cardId: string; channelId: string }[]>;
|
getBlockedChannels(): Promise<{ cardId: string; channelId: string }[]>;
|
||||||
getBlockedArticles(): Promise<{ cardId: string; articleId: string }[]>;
|
getBlockedArticles(): Promise<{ cardId: string; articleId: string }[]>;
|
||||||
|
|
||||||
enableChannelNotifications(cardId: string, channelId: string): Promise<void>;
|
|
||||||
disableChannelNotifications(chardId: string, channelId: string): Promise<void>;
|
|
||||||
|
|
||||||
setUnreadChannel(cardId: string, channelId: string): Promise<void>;
|
setUnreadChannel(cardId: string, channelId: string): Promise<void>;
|
||||||
clearUnreadChannel(cardId: string, channelId: string): Promise<void>;
|
|
||||||
|
setChannelNotifications(cardId: string, channelId: string, enabled: boolean): Promise<void>;
|
||||||
|
|
||||||
getRegistry(server: string): Promise<Profile[]>;
|
getRegistry(server: string): Promise<Profile[]>;
|
||||||
getRegistryImageUrl(server: string, guid: string): string;
|
getRegistryImageUrl(server: string, guid: string): string;
|
||||||
@ -100,6 +94,9 @@ export interface Contact {
|
|||||||
|
|
||||||
addCardListener(ev: (cards: Card[]) => void): void;
|
addCardListener(ev: (cards: Card[]) => void): void;
|
||||||
removeCardListener(ev: (cards: Card[]) => void): void;
|
removeCardListener(ev: (cards: Card[]) => void): void;
|
||||||
|
|
||||||
|
addChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void;
|
||||||
|
removeChannelListener(id: string | null, ev: (arg: { cardId: string; channels: Channel[] }) => void): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Alias {
|
export interface Alias {
|
||||||
|
@ -494,9 +494,55 @@ export class ContactModule implements Contact {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async rejectCard(cardId: string): Promise<void> {}
|
public async denyCard(cardId: string): Promise<void> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
const entry = this.cardEntries.get(cardId);
|
||||||
|
if (entry) {
|
||||||
|
try {
|
||||||
|
const message = await getCardCloseMessage(node, secure, token, cardId);
|
||||||
|
const server = entry.item.profile.node ? entry.item.profile.node : node;
|
||||||
|
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
|
||||||
|
await setCardCloseMessage(server, !insecure, message);
|
||||||
|
} catch (err) {
|
||||||
|
this.log.warn("failed to deliver close message");
|
||||||
|
}
|
||||||
|
if (entry.item.detail.status === 'pending') {
|
||||||
|
await removeCard(node, secure, token, cardId);
|
||||||
|
} else {
|
||||||
|
await setCardConfirmed(node, secure, token, cardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async ignoreCard(cardId: string): Promise<void> {}
|
public async ignoreCard(cardId: string): Promise<void> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
const entry = this.cardEntries.get(cardId);
|
||||||
|
if (entry) {
|
||||||
|
if (entry.item.detail.status === 'pending') {
|
||||||
|
await removeCard(node, secure, token, cardId);
|
||||||
|
} else {
|
||||||
|
await setCardConfirmed(node, secure, token, cardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async cancelCard(cardId: string): Promise<void> {
|
||||||
|
const { node, secure, token } = this;
|
||||||
|
const entry = this.cardEntries.get(cardId);
|
||||||
|
if (entry) {
|
||||||
|
if (entry.item.detail.status === 'requesting') {
|
||||||
|
try {
|
||||||
|
const message = await getCardCloseMessage(node, secure, token, cardId);
|
||||||
|
const server = entry.item.profile.node ? entry.item.profile.node : node;
|
||||||
|
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(server);
|
||||||
|
await setCardCloseMessage(server, !insecure, message);
|
||||||
|
} catch (err) {
|
||||||
|
this.log.warn("failed to deliver close message");
|
||||||
|
}
|
||||||
|
await setCardConfirmed(node, secure, token, cardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async resyncCard(cardId: string): Promise<void> {}
|
public async resyncCard(cardId: string): Promise<void> {}
|
||||||
|
|
||||||
@ -506,29 +552,31 @@ export class ContactModule implements Contact {
|
|||||||
|
|
||||||
public async flagChannel(cardId: string, channelId: string): Promise<void> {}
|
public async flagChannel(cardId: string, channelId: string): Promise<void> {}
|
||||||
|
|
||||||
public async setBlockCard(cardId: string): Promise<void> {}
|
public async setBlockedCard(cardId: string, boolean: blocked): Promise<void> {
|
||||||
|
const entry = this.cardEntries.get(cardId);
|
||||||
|
if (entry) {
|
||||||
|
entry.item.blocked = blocked;
|
||||||
|
entry.item.card = this.setCard(cardId, entry.item);
|
||||||
|
await this.store.setContactCardBlocked(this.guid, cardId, blocked);
|
||||||
|
this.emitCards();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async setBlockArticle(cardId: string, articleId: string): Promise<void> {}
|
public async setBlockedArticle(cardId: string, articleId: string, boolean: blocked): Promise<void> {}
|
||||||
|
|
||||||
public async setBlockChannel(cardId: string, channelId: string): Promise<void> {
|
public async setBlockedChannel(cardId: string, channelId: string, boolean: blocked): Promise<void> {
|
||||||
const entries = this.channelEntries.get(cardId);
|
const entries = this.channelEntries.get(cardId);
|
||||||
if (entries) {
|
if (entries) {
|
||||||
const entry = entries.get(channelId);
|
const entry = entries.get(channelId);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
item.entry.blocked = true;
|
entry.item.blocked = blocked;
|
||||||
item.entry.channel = this.setChannel(cardId, channelId, entry.item);
|
entry.item.channel = this.setChannel(cardId, channelId, entry.item);
|
||||||
await this.store.setContactCardChannelBlocked(this.guid, cardId, channelId, blocked);
|
await this.store.setContactCardChannelBlocked(this.guid, cardId, channelId, blocked);
|
||||||
this.emitChannels(cardId);
|
this.emitChannels(cardId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async clearBlockCard(cardId: string): Promise<void> {}
|
|
||||||
|
|
||||||
public async clearBlockArticle(cardId: string, articleId: string): Promise<void> {}
|
|
||||||
|
|
||||||
public async clearBlockChannel(cardId: string, channelId: string): Promise<void> {}
|
|
||||||
|
|
||||||
public async getBlockedCards(): Promise<{ cardId: string }[]> {
|
public async getBlockedCards(): Promise<{ cardId: string }[]> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -545,13 +593,20 @@ export class ContactModule implements Contact {
|
|||||||
|
|
||||||
public async removeChannel(cardId: string, channelId: string): Promise<void> {}
|
public async removeChannel(cardId: string, channelId: string): Promise<void> {}
|
||||||
|
|
||||||
public async enableChannelNotifications(cardId: string, channelId: string): Promise<void> {}
|
public async setChannelNotifications(cardId: string, channelId: string, enabled: boolean): Promise<void> {}
|
||||||
|
|
||||||
public async disableChannelNotifications(cardId: string, channelid: string): Promise<void> {}
|
public async setUnreadChannel(cardId: string, channelId: string, unread: boolean): Promise<void> {
|
||||||
|
const entries = this.channelEntries.get(cardId);
|
||||||
public async setUnreadChannel(cardId: string, channelId: string): Promise<void> {}
|
if (entries) {
|
||||||
|
const entry = entries.get(channelId);
|
||||||
public async clearUnreadChannel(cardId: string, channelId: string): Promise<void> {}
|
if (entry) {
|
||||||
|
entry.item.unread = unread;
|
||||||
|
entry.item.channel = this.setChannel(cardId, channelId, entry.item);
|
||||||
|
await this.store.setContactCardChannelUnread(this.guid, cardId, channelId, unread);
|
||||||
|
this.emitChannels(cardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async getRegistry(server: string): Promise<Profile[]> {
|
public async getRegistry(server: string): Promise<Profile[]> {
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user