more content api cleanup

This commit is contained in:
balzack 2024-10-30 17:00:13 -07:00
parent 6e12a07de2
commit 5ed2b67312
4 changed files with 9 additions and 8 deletions

View File

@ -339,7 +339,7 @@ Automate allocates the Bot interface for ia specific communication channel
Update the subject on specified channel
```Content::setChannelSubject(channelId: string, subject: string): Promise<void>```
```Content::setChannelSubject(channelId: string, type: string, subject: any): Promise<void>```
Add member to specified channel

View File

@ -90,7 +90,7 @@ export interface Contact {
export interface Content {
addChannel(sealed: boolean, type: string, subject: any, cardIds: string[]): Promise<string>;
removeChannel(channelId: string): Promise<void>;
setChannelSubject(channelId: string, subject: string): Promise<void>;
setChannelSubject(channelId: string, type: string, subject: any): Promise<void>;
setChannelCard(channelId: string, cardId: string): Promise<void>;
clearChannelCard(channelId: string, cardId: string): Promise<void>;

View File

@ -40,8 +40,8 @@ export class ContentModule implements Content {
return await this.stream.removeChannel(channelId);
}
public async setChannelSubject(channelId: string, subject: string): Promise<void> {
return await this.stream.setChannelSubject(channelId, subject);
public async setChannelSubject(channelId: string, type: string, subject: any): Promise<void> {
return await this.stream.setChannelSubject(channelId, type, subject);
}
public async setChannelCard(channelId: string, cardId: string): Promise<void> {

View File

@ -251,7 +251,7 @@ export class StreamModule {
return await removeChannel(node, secure, token);
}
public async setChannelSubject(channelId: string, subject: string): Promise<void> {
public async setChannelSubject(channelId: string, type: string, subject: any): Promise<void> {
const channel = this.channelEntries.get(channelId);
if (!channel) {
throw new Error('channel not found');
@ -269,12 +269,13 @@ export class StreamModule {
if (!item.channelKey) {
item.channelKey = await this.getChannelKey(seals);
}
const { encryptedDataB64 } = await crypto.aesEncrypt(subject, subjectIv, item.channelKey);
const subjectData = JSON.stringify(subject);
const { encryptedDataB64 } = await crypto.aesEncrypt(subjectData, subjectIv, item.channelKey);
const sealedSubject = { subjectEncrypted, encryptedDataB64, subjectIv, seals };
await setChannelSubject(node, secure, token, channelId, item.dataType, sealedSubject);
await setChannelSubject(node, secure, token, channelId, type, sealedSubject);
}
else {
await setChannelSubject(node, secure, token, channelId, item.dataType, { subject });
await setChannelSubject(node, secure, token, channelId, type, subject);
}
}