diff --git a/app/sdk/src/focus.ts b/app/sdk/src/focus.ts index 84397f71..7cb1b354 100644 --- a/app/sdk/src/focus.ts +++ b/app/sdk/src/focus.ts @@ -16,7 +16,9 @@ import { getContactChannelTopicDetail } from './net/getContactChannelTopicDetail import { addChannelTopic } from './net/addChannelTopic'; import { addContactChannelTopic } from './net/addContactChannelTopic'; import { setChannelTopicSubject } from './net/setChannelTopicSubject'; -import { addContactChannelTopicSubject } from './net/setContactChannelTopicSubject'; +import { setContactChannelTopicSubject } from './net/setContactChannelTopicSubject'; +import { removeChannelTopic } from './net/removeChannelTopic'; +import { removeContactChannelTopic } from './net/removeContactChannelTopic'; const BATCH_COUNT = 64; const MIN_LOAD_SIZE = 32; @@ -1081,6 +1083,19 @@ export class FocusModule implements Focus { } } + private async removeRemoveChannelTopic(topicId: string) { + const { cardId, channelId, connection } = this; + if (!connection) { + throw new Error('disconnected from channel'); + } + const { node, secure, token } = this.connection; + if (cardId) { + return await removeContactChannelTopicSubject(node, secure, token, channelId, topicId); + } else { + return await removeChannelTopic(node, secure, token, channelId, topicId); + } + } + private isTopicBlocked(topicId: string): boolean { const { cardId, channelId } = this; const card = cardId ? `"${cardId}"` : 'null'; diff --git a/app/sdk/src/net/removeChannelTopic.ts b/app/sdk/src/net/removeChannelTopic.ts new file mode 100644 index 00000000..a1b58aa3 --- /dev/null +++ b/app/sdk/src/net/removeChannelTopic.ts @@ -0,0 +1,7 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; + +export async function removeChannelTopic(node: string, secure: boolean, token: string, channelId: string, topicId: string): Promise { + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/${topics}/${topicId}?agent=${token}`; + const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' }); + checkResponse(status); +} diff --git a/app/sdk/src/net/removeContactChannelTopic.ts b/app/sdk/src/net/removeContactChannelTopic.ts new file mode 100644 index 00000000..2b225855 --- /dev/null +++ b/app/sdk/src/net/removeContactChannelTopic.ts @@ -0,0 +1,7 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; + +export async function removeContactChannelTopic(node: string, secure: boolean, guidToken: string, channelId: string) { + const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/topics/${topicId}?contact=${guidToken}`; + const response = await fetchWithTimeout(endpoint, { method: 'DELETE' }); + checkResponse(response.status); +} diff --git a/app/sdk/src/net/setContactChannelTopicSubject.ts b/app/sdk/src/net/setContactChannelTopicSubject.ts index cc3c6c14..778e9d9f 100644 --- a/app/sdk/src/net/setContactChannelTopicSubject.ts +++ b/app/sdk/src/net/setContactChannelTopicSubject.ts @@ -1,6 +1,6 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; -export async function setContactChannelTopicSubject(node: string, secure: boolean, guidToken: string, channelId: topicId: string, dataType: string, data: any) { +export async function setContactChannelTopicSubject(node: string, secure: boolean, guidToken: string, channelId: string, topicId: string, dataType: string, data: any) { const subject = { data: JSON.stringify(data), dataType }; const endpoint = `http${secure ? 's' : '' }://${node}/content/channels/${channelId}/topics/${topicId}/subject?contact=${guidToken}&confirm=true`; const { status } = await fetchWithTimeout(endpoint, { method: 'PUT', body: JSON.stringify(subject) });