From d4553a3b57ac3dd0415260327f172e678d1e57fe Mon Sep 17 00:00:00 2001 From: balzack Date: Thu, 27 Jun 2024 23:01:56 -0700 Subject: [PATCH] adding contact and attribute interface --- app/sdk/src/api.ts | 57 ++++++++++++++++++++++++- app/sdk/src/attribute.ts | 41 +++++++++++++++++- app/sdk/src/contact.ts | 92 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 185 insertions(+), 5 deletions(-) diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index 33d1ccbf..0bb2f4e5 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -51,12 +51,42 @@ export interface Identity { } export interface Contact { + addCard(message: SignedMessage): Promise; + removeCard(cardId: string): Promise; + setCardConnecting(cardId: string): Promise; + setCardConnected(cardId: string, token: string, rev: number): Promise; + setCardConfirmed(cardId: string): Promise; + getCardOpenMessage(cardId: string): Promise; + setCardOpenMessage(server: string, message: SignedMessage): Promise; + getCardCloseMessage(cardId: string): Promise; + setCardCloseMessage(server: string, message: SignedMessage): Promise; + removeChannel(cardId: string, channelId: string): Promise; + addTopic(cardId: string, channelId: string, type: string, message: string, assets: Asset[]): Promise; + removeTopic(cardId: string, channelId: string, topicId: string): Promise; + setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise; + getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise; + getTopic(cardId: string, channelId: string, topicId: string): Promise; + resyncCard(cardId: string): Promise; + + getTopicAssetUrl(cardId: string, channelId: string, topicId: string, assetId: string): string; + getCardImageUrl(cardId: string): string; + + addCardListener(ev: (cards: Card[]) => void): void; + removeCardListener(ev: (cards: Card[]) => void): void; } export interface Group { } export interface Attribute { + addArticle(type: string, subject: string, cardIds: string[]): Promise; + removeArticle(articleId: string): Promise; + setArticleSubject(articleId: string, type: string, subject: string): Promise; + setArticleCard(articleId: string, cardId: string): Promise; + clearArticleCard(articleId: string, cardId: string): Promise; + + addArticleListener(ev: (articles: Article[]) => void): void; + removeArticleListener(ev: (articles: Article[]) => void): void; } export interface Content { @@ -68,10 +98,11 @@ export interface Content { addTopic(channelId: string, type: string, message: string, assets: Asset[]): Promise; removeTopic(channelId: string, topicId: string): Promise; setTopicSubject(channelId: string, topicId: string, type: string, subject: string): Promise; - getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string; getTopics(channelId: string, revision: number, count: number, begin: number, end: number): Promise; getTopic(channelId: string, topicId: string): Promise; + getTopicAssetUrl(channelId: string, topicId: string, assetId: string): string; + addChannelListener(ev: (channels: Channel[]) => void): void; removeChannelListener(ev: (channels: Channel[]) => void): void; } @@ -127,3 +158,27 @@ export interface Topic { export interface Asset { } + +export interface Alias { +} + +export interface Article { +} + +export interface SignedMessage { + message: string; + keyType: string; + publicKey: string; + signature: string; + signatureType: string; +} + +export interface ContactStatus { + token: string; + profileRevision: number; + articleRevision: number; + channelRevision: number; + viewRevision: number; + status: string; +} + diff --git a/app/sdk/src/attribute.ts b/app/sdk/src/attribute.ts index 9ff2c5d3..1b152f86 100644 --- a/app/sdk/src/attribute.ts +++ b/app/sdk/src/attribute.ts @@ -1,17 +1,54 @@ import { EventEmitter } from 'events'; -import { type Attribute } from './api'; +import { type Attribute, type Article } from './api'; export class AttributeModule implements Attribute { - private sync: (flag: boolean) => void; private token: string; private url: string; + private sync: (flag: boolean) => void; + private emitter: EventEmitter; constructor(token: string, url: string, sync: (flag: boolean) => void) { this.token = token; this.url = url; this.sync = sync; + this.emitter = new EventEmitter(); } + public addCardListener(ev: (articles: Article[]) => void): void { + this.emitter.on('artcile', ev); + } + + public removeCardListener(ev: (articles: Article[]) => void): void { + this.emitter.off('article', ev); + } + + public async setRevision(rev: number): Promise { + } + + public async resync(): Promise { + } + + public async addArticle(type: string, subject: string, cardIds: string[]): Promise { + return ''; + } + + public async removeArticle(articleId: string): Promise { + } + + public async setArticleSubject(articleId: string, type: string, subject: string): Promise { + } + + public async setArticleCard(articleId: string, cardId: string): Promise { + } + + public async clearArticleCard(articleId: string, cardId: string): Promise { + } + + public addArticleListener(ev: (articles: Article[]) => void): void { + } + + public removeArticleListener(ev: (articles: Article[]) => void): void { + } } diff --git a/app/sdk/src/contact.ts b/app/sdk/src/contact.ts index 749363d6..aa71c5b9 100644 --- a/app/sdk/src/contact.ts +++ b/app/sdk/src/contact.ts @@ -1,6 +1,94 @@ -import { type Contact } from './api'; +import { EventEmitter } from 'events'; +import { type Contact, type Card, type Topic, type SignedMessage, type ContactStatus, type Asset} from './api'; export class ContactModule implements Contact { - constructor(token: string, url: string, sync: (flag: boolean) => void) {} + + private token: string; + private url: string; + private sync: (flag: boolean) => void; + private emitter: EventEmitter; + + constructor(token: string, url: string, sync: (flag: boolean) => void) { + this.token = token; + this.url = url; + this.sync = sync; + this.emitter = new EventEmitter(); + } + + public addCardListener(ev: (cards: Card[]) => void): void { + this.emitter.on('card', ev); + } + + public removeCardListener(ev: (cards: Card[]) => void): void { + this.emitter.off('card', ev); + } + + public async setRevision(rev: number): Promise { + } + + public async resync(): Promise { + } + + public async addCard(message: SignedMessage): Promise { + return ''; + } + + public async removeCard(cardId: string): Promise { + } + + public async setCardConnecting(cardId: string): Promise { + } + + public async setCardConnected(cardId: string, token: string, rev: number): Promise { + } + + public async setCardConfirmed(cardId: string): Promise { + } + + public async getCardOpenMessage(cardId: string): Promise { + return { message: '', keyType: '', publicKey: '', signature: '', signatureType: '' }; + } + + public async setCardOpenMessage(server: string, message: SignedMessage): Promise { + return { token: '', profileRevision: 0, articleRevision: 0, channelRevision: 0, viewRevision: 0, status: '' }; + } + + public async getCardCloseMessage(cardId: string): Promise { + return { message: '', keyType: '', publicKey: '', signature: '', signatureType: '' }; + } + + public async setCardCloseMessage(server: string, message: SignedMessage): Promise { + } + + public async removeChannel(cardId: string, channelId: string): Promise { + } + + public async addTopic(cardId: string, channelId: string, type: string, message: string, assets: Asset[]): Promise { + return ''; + } + + public async removeTopic(cardId: string, channelId: string, topicId: string): Promise { + } + + public async setTopicSubject(cardId: string, channelId: string, topicId: string, type: string, subject: string): Promise { + } + + public async getTopics(cardId: string, channelId: string, revision: number, count: number, begin: number, end: number): Promise { + } + + public async getTopic(cardId: string, channelId: string, topicId: string): Promise { + return {} + } + + public async resyncCard(cardId: string): Promise { + } + + public getTopicAssetUrl(cardId: string, channelId: string, topicId: string, assetId: string): string { + return ''; + } + + public getCardImageUrl(cardId: string): string { + return ''; + } }