Skip to content

Commit 93e1501

Browse files
committed
Basic chat support done
1 parent 72bd695 commit 93e1501

10 files changed

Lines changed: 74 additions & 20 deletions

js/appTemplates/CollectorClient.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export declare class CollectorClient {
2727
/** @property {Object} - full content of the request */
2828
get requestData(): any;
2929
get hasChatFeature(): boolean;
30+
get chatSettings(): {
31+
chatStreamIncoming: string;
32+
chatStreamMain: string;
33+
};
3034
/** @property {string} - one of 'Incoming', 'Active', 'Deactivated', 'Refused' */
3135
get status(): string;
3236
constructor(app: any, eventData: any, accessData?: any);
@@ -65,5 +69,8 @@ export declare class CollectorClient {
6569
*/
6670
static keyFromInfo(info: any): string;
6771
getSections(): Array<CollectorSectionInterface>;
72+
chatEventInfos(event: pryv.Event): {
73+
source: 'me' | 'requester' | 'unkown';
74+
};
6875
}
6976
//# sourceMappingURL=CollectorClient.d.ts.map

js/appTemplates/CollectorClient.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/appTemplates/CollectorClient.js

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/appTemplates/CollectorClient.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/appTemplates/CollectorInvite.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export declare class CollectorInvite {
2323
streamRead: string;
2424
streamWrite: string;
2525
};
26+
chatEventInfos(event: pryv.Event): {
27+
source: 'me' | 'user' | 'unkown';
28+
};
2629
/**
2730
* Check if connection is valid. (only if active)
2831
* If result is "forbidden" update and set as revoked

js/appTemplates/CollectorInvite.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/appTemplates/CollectorInvite.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/appTemplates/CollectorInvite.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/appTemplates/CollectorClient.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export class CollectorClient {
5757
return this.requestData.features.chat != null;
5858
}
5959

60+
get chatSettings (): {chatStreamIncoming: string, chatStreamMain: string} {
61+
if (!this.hasChatFeature) return null;
62+
return {
63+
chatStreamIncoming: `chat-${this.requesterUsername}-in`,
64+
chatStreamMain: `chat-${this.requesterUsername}`
65+
};
66+
}
67+
6068
/** @property {string} - one of 'Incoming', 'Active', 'Deactivated', 'Refused' */
6169
get status (): string {
6270
const eventStatus = this.eventData.content.status;
@@ -191,12 +199,11 @@ export class CollectorClient {
191199
// user supported mode - might me moved to a lib
192200

193201
// 2. create streams
194-
const chatStreamRead = `chat-${this.requesterUsername}`;
195-
const chatStreamWrite = `${chatStreamRead}-in`;
202+
const { chatStreamIncoming, chatStreamMain } = this.chatSettings;
196203
const chatStreamsCreateApiCalls = [
197204
{ method: 'streams.create', params: { name: 'Chats', id: 'chats' } },
198-
{ method: 'streams.create', params: { name: `Chat ${this.requesterUsername}`, parentId: 'chats', id: chatStreamRead } },
199-
{ method: 'streams.create', params: { name: `Chat ${this.requesterUsername}`, parentId: chatStreamRead, id: chatStreamWrite } }
205+
{ method: 'streams.create', params: { name: `Chat ${this.requesterUsername}`, parentId: 'chats', id: chatStreamMain } },
206+
{ method: 'streams.create', params: { name: `Chat ${this.requesterUsername}`, parentId: chatStreamMain, id: chatStreamIncoming } }
200207
];
201208
const streamCreateResults = await this.app.connection.api(chatStreamsCreateApiCalls);
202209
streamCreateResults.forEach((r) => {
@@ -205,13 +212,13 @@ export class CollectorClient {
205212
});
206213
// 3. add streams to permissions
207214
cleanedPermissions.push(...[
208-
{ streamId: chatStreamRead, level: 'read' },
209-
{ streamId: chatStreamWrite, level: 'manage' }
215+
{ streamId: chatStreamMain, level: 'read' },
216+
{ streamId: chatStreamIncoming, level: 'manage' }
210217
]);
211218
responseContent.chat = {
212219
type: 'user',
213-
streamRead: chatStreamRead,
214-
streamWrite: chatStreamWrite
220+
streamRead: chatStreamMain,
221+
streamWrite: chatStreamIncoming
215222
};
216223
// ---------- end chat ---------- //
217224
}
@@ -340,4 +347,11 @@ export class CollectorClient {
340347
getSections (): Array<CollectorSectionInterface> {
341348
return this.request?.sections;
342349
}
350+
351+
// -------------------- chat methods ----------------- //
352+
chatEventInfos (event: pryv.Event): {source: 'me' | 'requester' | 'unkown' } {
353+
if (event.streamIds.includes(this.chatSettings.chatStreamIncoming)) return { source: 'requester' };
354+
if (event.streamIds.includes(this.chatSettings.chatStreamMain)) return { source: 'me' };
355+
return { source: 'unkown' };
356+
}
343357
}

ts/appTemplates/CollectorInvite.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export class CollectorInvite {
5757
return this.eventData.content.chat;
5858
}
5959

60+
// -------------------- chat methods ----------------- //
61+
chatEventInfos (event: pryv.Event): {source: 'me' | 'user' | 'unkown' } {
62+
if (event.streamIds.includes(this.chatSettings.streamWrite)) return { source: 'me' };
63+
if (event.streamIds.includes(this.chatSettings.streamRead)) return { source: 'user' };
64+
return { source: 'unkown' };
65+
}
66+
6067
/**
6168
* Check if connection is valid. (only if active)
6269
* If result is "forbidden" update and set as revoked

0 commit comments

Comments
 (0)