implementing focus module

This commit is contained in:
balzack 2024-12-01 17:41:02 -08:00
parent 4075ad184c
commit 0e24bf1bb4
4 changed files with 31 additions and 2 deletions

View File

@ -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';

View File

@ -0,0 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeChannelTopic(node: string, secure: boolean, token: string, channelId: string, topicId: string): Promise<void> {
const endpoint = `http${secure ? 's' : ''}://${node}/content/channels/${channelId}/${topics}/${topicId}?agent=${token}`;
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' });
checkResponse(status);
}

View File

@ -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);
}

View File

@ -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) });