@amityco/ts-sdk 7.11.1-18669c3.0 → 7.11.1-1893f045.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +1 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/linkPreviewMetadata.d.ts +12 -0
- package/dist/@types/core/linkPreviewMetadata.d.ts.map +1 -0
- package/dist/@types/core/model.d.ts +1 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +1 -1
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +2 -1
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +11 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +9 -5
- package/dist/@types/domains/room.d.ts.map +1 -1
- package/dist/client/api/fetchLinkPreview.d.ts +3 -0
- package/dist/client/api/fetchLinkPreview.d.ts.map +1 -1
- package/dist/client/api/getCurrentUser.d.ts +1 -1
- package/dist/client/api/getCurrentUser.d.ts.map +1 -1
- package/dist/client/api/getLinkPreviewMetadata.d.ts +14 -0
- package/dist/client/api/getLinkPreviewMetadata.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/utils/setBotClientToken.d.ts.map +1 -1
- package/dist/client/utils/setVisitorClientToken.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -1
- package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -1
- package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -1
- package/dist/index.cjs.js +540 -478
- package/dist/index.esm.js +594 -532
- package/dist/index.umd.js +2 -2
- package/dist/postRepository/api/createPost.d.ts +1 -0
- package/dist/postRepository/api/createPost.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +1 -0
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/utils.d.ts +1 -0
- package/dist/postRepository/observers/utils.d.ts.map +1 -1
- package/dist/roomPresenceRepository/api/getRoomUserCount.d.ts.map +1 -1
- package/dist/roomRepository/events/index.d.ts +1 -0
- package/dist/roomRepository/events/index.d.ts.map +1 -1
- package/dist/roomRepository/events/onRoomTerminated.d.ts +17 -0
- package/dist/roomRepository/events/onRoomTerminated.d.ts.map +1 -0
- package/dist/roomRepository/observers/getRoom.d.ts.map +1 -1
- package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -688,7 +688,7 @@ const idResolvers = {
|
|
|
688
688
|
room: ({ roomId }) => roomId,
|
|
689
689
|
viewer: ({ userId }) => userId,
|
|
690
690
|
event: ({ eventId }) => eventId,
|
|
691
|
-
eventResponse: ({
|
|
691
|
+
eventResponse: ({ userId }) => userId,
|
|
692
692
|
};
|
|
693
693
|
/**
|
|
694
694
|
* Retrieve the id resolver matching a domain name
|
|
@@ -1571,10 +1571,7 @@ const getCurrentUser = () => {
|
|
|
1571
1571
|
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
1572
1572
|
}
|
|
1573
1573
|
const cache = (_a = pullFromCache(['user', 'get', client.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
1574
|
-
|
|
1575
|
-
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
1576
|
-
}
|
|
1577
|
-
return userLinkedObject(cache);
|
|
1574
|
+
return cache ? userLinkedObject(cache) : null;
|
|
1578
1575
|
};
|
|
1579
1576
|
/* end_public_function */
|
|
1580
1577
|
|
|
@@ -7407,7 +7404,7 @@ const setVisitorClientToken = async (params) => {
|
|
|
7407
7404
|
const client = getActiveClient();
|
|
7408
7405
|
// begin establishing session
|
|
7409
7406
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
7410
|
-
const { accessToken, users, expiresAt, issuedAt, userType } = await getVisitorToken(params);
|
|
7407
|
+
const { accessToken, users, expiresAt, issuedAt, userType, files } = await getVisitorToken(params);
|
|
7411
7408
|
// manually setup the token for http transport
|
|
7412
7409
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
7413
7410
|
client.http.defaults.metadata = {
|
|
@@ -7417,6 +7414,10 @@ const setVisitorClientToken = async (params) => {
|
|
|
7417
7414
|
};
|
|
7418
7415
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
7419
7416
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
7417
|
+
ingestInCache(prepareUserPayload({
|
|
7418
|
+
users,
|
|
7419
|
+
files,
|
|
7420
|
+
}));
|
|
7420
7421
|
return { accessToken, users, userType };
|
|
7421
7422
|
};
|
|
7422
7423
|
|
|
@@ -9994,6 +9995,9 @@ function setUploadedFileAccessType(accessType) {
|
|
|
9994
9995
|
GlobalFileAccessType$1.getInstance().setFileAccessType(accessType);
|
|
9995
9996
|
}
|
|
9996
9997
|
|
|
9998
|
+
/**
|
|
9999
|
+
* @deprecated This function will to be deprecated and use the new getLinkPreviewMetadata
|
|
10000
|
+
*/
|
|
9997
10001
|
/**
|
|
9998
10002
|
* ```js
|
|
9999
10003
|
* import { fetchLinkPreview } from '@amityco/ts-sdk'
|
|
@@ -10016,6 +10020,24 @@ const fetchLinkPreview = async (url) => {
|
|
|
10016
10020
|
return data;
|
|
10017
10021
|
};
|
|
10018
10022
|
|
|
10023
|
+
/**
|
|
10024
|
+
* ```js
|
|
10025
|
+
* import { getLinkPreviewMetadata } from '@amityco/ts-sdk'
|
|
10026
|
+
* const { title, description, imageUrl } = getLinkPreviewMetadata('https://www.example.com/')
|
|
10027
|
+
* ```
|
|
10028
|
+
*
|
|
10029
|
+
*
|
|
10030
|
+
* @param url the url to fetch link preview
|
|
10031
|
+
* @returns A {@link Amity.LinkPreviewMetadata} instance
|
|
10032
|
+
*
|
|
10033
|
+
* @category Client API
|
|
10034
|
+
* */
|
|
10035
|
+
const getLinkPreviewMetadata = async (url) => {
|
|
10036
|
+
const client = getActiveClient();
|
|
10037
|
+
const { data } = await client.http.get(`/api/v1/link-preview?url=${url}`);
|
|
10038
|
+
return data;
|
|
10039
|
+
};
|
|
10040
|
+
|
|
10019
10041
|
/**
|
|
10020
10042
|
* ```js
|
|
10021
10043
|
* import Client from '@amityco/ts-sdk'
|
|
@@ -10074,7 +10096,7 @@ const setBotClientToken = async (params) => {
|
|
|
10074
10096
|
const client = getActiveClient();
|
|
10075
10097
|
// begin establishing session
|
|
10076
10098
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
10077
|
-
const { accessToken, users, expiresAt, issuedAt, userType } = await getBotToken(params);
|
|
10099
|
+
const { accessToken, users, expiresAt, issuedAt, userType, files } = await getBotToken(params);
|
|
10078
10100
|
// manually setup the token for http transport
|
|
10079
10101
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
10080
10102
|
client.http.defaults.metadata = {
|
|
@@ -10084,6 +10106,10 @@ const setBotClientToken = async (params) => {
|
|
|
10084
10106
|
};
|
|
10085
10107
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
10086
10108
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
10109
|
+
ingestInCache(prepareUserPayload({
|
|
10110
|
+
users,
|
|
10111
|
+
files,
|
|
10112
|
+
}));
|
|
10087
10113
|
return { accessToken, users, userType };
|
|
10088
10114
|
};
|
|
10089
10115
|
|
|
@@ -10541,6 +10567,7 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
10541
10567
|
enableUnreadCount: enableUnreadCount,
|
|
10542
10568
|
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
10543
10569
|
fetchLinkPreview: fetchLinkPreview,
|
|
10570
|
+
getLinkPreviewMetadata: getLinkPreviewMetadata,
|
|
10544
10571
|
getSocialSettings: getSocialSettings,
|
|
10545
10572
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
10546
10573
|
loginAsVisitor: loginAsVisitor,
|
|
@@ -12441,12 +12468,9 @@ const rejectInvitation = async (invitationId) => {
|
|
|
12441
12468
|
};
|
|
12442
12469
|
/* end_public_function */
|
|
12443
12470
|
|
|
12444
|
-
|
|
12445
|
-
(
|
|
12446
|
-
|
|
12447
|
-
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
12448
|
-
InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
|
|
12449
|
-
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
12471
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
12472
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
12473
|
+
};
|
|
12450
12474
|
|
|
12451
12475
|
const invitationLinkedObject = (invitation) => {
|
|
12452
12476
|
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
@@ -12480,379 +12504,107 @@ const invitationLinkedObject = (invitation) => {
|
|
|
12480
12504
|
} });
|
|
12481
12505
|
};
|
|
12482
12506
|
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
const options = token ? { token } : { limit };
|
|
12487
|
-
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
12488
|
-
return data;
|
|
12489
|
-
}
|
|
12490
|
-
}
|
|
12491
|
-
|
|
12492
|
-
class InvitationsQueryStreamController extends QueryStreamController {
|
|
12493
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
12494
|
-
super(query, cacheKey);
|
|
12495
|
-
this.notifyChange = notifyChange;
|
|
12496
|
-
this.preparePayload = preparePayload;
|
|
12497
|
-
}
|
|
12498
|
-
async saveToMainDB(response) {
|
|
12499
|
-
const processedPayload = await this.preparePayload(response);
|
|
12500
|
-
const client = getActiveClient();
|
|
12501
|
-
const cachedAt = client.cache && Date.now();
|
|
12502
|
-
if (client.cache) {
|
|
12503
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
12504
|
-
}
|
|
12505
|
-
}
|
|
12506
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
12507
|
-
var _a, _b;
|
|
12508
|
-
if (refresh) {
|
|
12509
|
-
pushToCache(this.cacheKey, {
|
|
12510
|
-
data: response.invitations.map(getResolver('invitation')),
|
|
12511
|
-
});
|
|
12512
|
-
}
|
|
12513
|
-
else {
|
|
12514
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12515
|
-
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
12516
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
12517
|
-
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
12518
|
-
] }));
|
|
12519
|
-
}
|
|
12520
|
-
}
|
|
12521
|
-
reactor(action) {
|
|
12522
|
-
return (invitations) => {
|
|
12523
|
-
var _a;
|
|
12524
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12525
|
-
if (!collection)
|
|
12526
|
-
return;
|
|
12527
|
-
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
12528
|
-
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
12529
|
-
if (!isExist)
|
|
12530
|
-
return;
|
|
12531
|
-
}
|
|
12532
|
-
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
12533
|
-
collection.data = [
|
|
12534
|
-
...new Set([
|
|
12535
|
-
...invitations.map(invitation => invitation.invitationId),
|
|
12536
|
-
...collection.data,
|
|
12537
|
-
]),
|
|
12538
|
-
];
|
|
12539
|
-
}
|
|
12540
|
-
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
12541
|
-
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
12542
|
-
}
|
|
12543
|
-
pushToCache(this.cacheKey, collection);
|
|
12544
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
12545
|
-
};
|
|
12546
|
-
}
|
|
12547
|
-
subscribeRTE(createSubscriber) {
|
|
12548
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
12549
|
-
}
|
|
12550
|
-
}
|
|
12551
|
-
|
|
12507
|
+
/* begin_public_function
|
|
12508
|
+
id: invitation.get
|
|
12509
|
+
*/
|
|
12552
12510
|
/**
|
|
12553
12511
|
* ```js
|
|
12554
|
-
* import {
|
|
12555
|
-
* const
|
|
12556
|
-
* // ...
|
|
12557
|
-
* })
|
|
12512
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
12513
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
12558
12514
|
* ```
|
|
12559
12515
|
*
|
|
12560
|
-
*
|
|
12516
|
+
* Get a {@link Amity.Invitation} object
|
|
12561
12517
|
*
|
|
12562
|
-
* @param
|
|
12563
|
-
* @
|
|
12518
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
12519
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
12520
|
+
* @returns A {@link Amity.Invitation} object
|
|
12564
12521
|
*
|
|
12565
|
-
* @category Invitation
|
|
12522
|
+
* @category Invitation API
|
|
12523
|
+
* @async
|
|
12566
12524
|
*/
|
|
12567
|
-
const
|
|
12525
|
+
const getInvitation = async (params) => {
|
|
12568
12526
|
const client = getActiveClient();
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12527
|
+
client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
|
|
12528
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
|
|
12529
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
12530
|
+
const cachedAt = client.cache && Date.now();
|
|
12531
|
+
if (client.cache)
|
|
12532
|
+
ingestInCache(data, { cachedAt });
|
|
12533
|
+
return {
|
|
12534
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
12535
|
+
cachedAt,
|
|
12574
12536
|
};
|
|
12575
12537
|
};
|
|
12538
|
+
/* end_public_function */
|
|
12576
12539
|
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
const
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
|
|
12540
|
+
const roomLinkedObject = (room) => {
|
|
12541
|
+
return Object.assign(Object.assign({}, room), { get post() {
|
|
12542
|
+
var _a;
|
|
12543
|
+
if (room.referenceType !== 'post')
|
|
12544
|
+
return;
|
|
12545
|
+
return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12546
|
+
},
|
|
12547
|
+
get community() {
|
|
12548
|
+
var _a;
|
|
12549
|
+
if (room.targetType !== 'community')
|
|
12550
|
+
return;
|
|
12551
|
+
return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12552
|
+
},
|
|
12553
|
+
get user() {
|
|
12554
|
+
var _a;
|
|
12555
|
+
const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12556
|
+
return user ? userLinkedObject(user) : user;
|
|
12557
|
+
},
|
|
12558
|
+
get childRooms() {
|
|
12559
|
+
if (!room.childRoomIds || room.childRoomIds.length === 0)
|
|
12560
|
+
return [];
|
|
12561
|
+
return room.childRoomIds
|
|
12562
|
+
.map(id => {
|
|
12563
|
+
var _a;
|
|
12564
|
+
const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12565
|
+
if (!roomCache)
|
|
12566
|
+
return undefined;
|
|
12567
|
+
return roomLinkedObject(roomCache);
|
|
12568
|
+
})
|
|
12569
|
+
.filter(isNonNullable);
|
|
12570
|
+
}, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
|
|
12571
|
+
var _a;
|
|
12572
|
+
const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12573
|
+
return user ? userLinkedObject(user) : user;
|
|
12574
|
+
} }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
|
|
12575
|
+
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
12576
|
+
targetType: 'room',
|
|
12577
|
+
targetId: room.roomId,
|
|
12578
|
+
userIds: [userId],
|
|
12579
|
+
}), getInvitations: async () => {
|
|
12580
|
+
const { data } = await getInvitation({
|
|
12581
|
+
targetId: room.roomId,
|
|
12582
|
+
targetType: 'room',
|
|
12583
|
+
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
12584
|
+
});
|
|
12585
|
+
return data;
|
|
12586
|
+
} });
|
|
12600
12587
|
};
|
|
12601
12588
|
|
|
12602
|
-
|
|
12603
|
-
*
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
*
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12589
|
+
/*
|
|
12590
|
+
* verifies membership status
|
|
12591
|
+
*/
|
|
12592
|
+
function isMember(membership) {
|
|
12593
|
+
return membership !== 'none';
|
|
12594
|
+
}
|
|
12595
|
+
/*
|
|
12596
|
+
* checks if currently logged in user is part of the community
|
|
12597
|
+
*/
|
|
12598
|
+
function isCurrentUserPartOfCommunity(c, m) {
|
|
12599
|
+
const { userId } = getActiveUser();
|
|
12600
|
+
return c.communityId === m.communityId && m.userId === userId;
|
|
12601
|
+
}
|
|
12602
|
+
/*
|
|
12603
|
+
* For mqtt events server will not send user specific data as it's broadcasted
|
|
12604
|
+
* to multiple users and it also does not include communityUser
|
|
12614
12605
|
*
|
|
12615
|
-
*
|
|
12616
|
-
|
|
12617
|
-
const onLocalInvitationCanceled = (callback) => {
|
|
12618
|
-
const client = getActiveClient();
|
|
12619
|
-
const disposers = [
|
|
12620
|
-
createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
|
|
12621
|
-
];
|
|
12622
|
-
return () => {
|
|
12623
|
-
disposers.forEach(fn => fn());
|
|
12624
|
-
};
|
|
12625
|
-
};
|
|
12626
|
-
|
|
12627
|
-
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
12628
|
-
constructor(query, callback) {
|
|
12629
|
-
const queryStreamId = hash__default["default"](query);
|
|
12630
|
-
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
12631
|
-
const paginationController = new InvitationsPaginationController(query);
|
|
12632
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
12633
|
-
this.query = query;
|
|
12634
|
-
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
12635
|
-
this.callback = callback.bind(this);
|
|
12636
|
-
this.loadPage({ initial: true });
|
|
12637
|
-
}
|
|
12638
|
-
setup() {
|
|
12639
|
-
var _a;
|
|
12640
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12641
|
-
if (!collection) {
|
|
12642
|
-
pushToCache(this.cacheKey, {
|
|
12643
|
-
data: [],
|
|
12644
|
-
params: this.query,
|
|
12645
|
-
});
|
|
12646
|
-
}
|
|
12647
|
-
}
|
|
12648
|
-
async persistModel(queryPayload) {
|
|
12649
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
12650
|
-
}
|
|
12651
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
12652
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
12653
|
-
}
|
|
12654
|
-
startSubscription() {
|
|
12655
|
-
return this.queryStreamController.subscribeRTE([
|
|
12656
|
-
{
|
|
12657
|
-
fn: onLocalInvitationCreated,
|
|
12658
|
-
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
12659
|
-
},
|
|
12660
|
-
{
|
|
12661
|
-
fn: onLocalInvitationUpdated,
|
|
12662
|
-
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
12663
|
-
},
|
|
12664
|
-
{
|
|
12665
|
-
fn: onLocalInvitationCanceled,
|
|
12666
|
-
action: InvitationActionsEnum.OnLocalInvitationCanceled,
|
|
12667
|
-
},
|
|
12668
|
-
]);
|
|
12669
|
-
}
|
|
12670
|
-
notifyChange({ origin, loading, error }) {
|
|
12671
|
-
var _a, _b;
|
|
12672
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12673
|
-
if (!collection)
|
|
12674
|
-
return;
|
|
12675
|
-
const data = this.applyFilter((_b = collection.data
|
|
12676
|
-
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
12677
|
-
.filter(isNonNullable)
|
|
12678
|
-
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
12679
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
12680
|
-
return;
|
|
12681
|
-
this.callback({
|
|
12682
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
12683
|
-
data,
|
|
12684
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
12685
|
-
loading,
|
|
12686
|
-
error,
|
|
12687
|
-
});
|
|
12688
|
-
}
|
|
12689
|
-
applyFilter(data) {
|
|
12690
|
-
let invitations = data;
|
|
12691
|
-
if (this.query.targetId) {
|
|
12692
|
-
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
12693
|
-
}
|
|
12694
|
-
if (this.query.statuses) {
|
|
12695
|
-
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
12696
|
-
}
|
|
12697
|
-
if (this.query.targetType) {
|
|
12698
|
-
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
12699
|
-
}
|
|
12700
|
-
if (this.query.type) {
|
|
12701
|
-
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
12702
|
-
}
|
|
12703
|
-
const sortFn = (() => {
|
|
12704
|
-
switch (this.query.sortBy) {
|
|
12705
|
-
case 'firstCreated':
|
|
12706
|
-
return sortByFirstCreated;
|
|
12707
|
-
case 'lastCreated':
|
|
12708
|
-
return sortByLastCreated;
|
|
12709
|
-
default:
|
|
12710
|
-
return sortByLastCreated;
|
|
12711
|
-
}
|
|
12712
|
-
})();
|
|
12713
|
-
invitations = invitations.sort(sortFn);
|
|
12714
|
-
return invitations;
|
|
12715
|
-
}
|
|
12716
|
-
}
|
|
12717
|
-
|
|
12718
|
-
/**
|
|
12719
|
-
* Get invitations
|
|
12720
|
-
*
|
|
12721
|
-
* @param params the query parameters
|
|
12722
|
-
* @param callback the callback to be called when the invitations are updated
|
|
12723
|
-
* @returns invitations
|
|
12724
|
-
*
|
|
12725
|
-
* @category Invitation Live Collection
|
|
12726
|
-
*
|
|
12727
|
-
*/
|
|
12728
|
-
const getInvitations$1 = (params, callback, config) => {
|
|
12729
|
-
const { log, cache } = getActiveClient();
|
|
12730
|
-
if (!cache) {
|
|
12731
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
12732
|
-
}
|
|
12733
|
-
const timestamp = Date.now();
|
|
12734
|
-
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
12735
|
-
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
12736
|
-
const disposers = invitationsLiveCollection.startSubscription();
|
|
12737
|
-
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
12738
|
-
disposers.push(() => {
|
|
12739
|
-
dropFromCache(cacheKey);
|
|
12740
|
-
});
|
|
12741
|
-
return () => {
|
|
12742
|
-
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
12743
|
-
disposers.forEach(fn => fn());
|
|
12744
|
-
};
|
|
12745
|
-
};
|
|
12746
|
-
|
|
12747
|
-
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
12748
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
12749
|
-
};
|
|
12750
|
-
|
|
12751
|
-
/* begin_public_function
|
|
12752
|
-
id: invitation.get
|
|
12753
|
-
*/
|
|
12754
|
-
/**
|
|
12755
|
-
* ```js
|
|
12756
|
-
* import { getInvitation } from '@amityco/ts-sdk'
|
|
12757
|
-
* const { invitation } = await getInvitation(targetType, targetId)
|
|
12758
|
-
* ```
|
|
12759
|
-
*
|
|
12760
|
-
* Get a {@link Amity.Invitation} object
|
|
12761
|
-
*
|
|
12762
|
-
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
12763
|
-
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
12764
|
-
* @returns A {@link Amity.Invitation} object
|
|
12765
|
-
*
|
|
12766
|
-
* @category Invitation API
|
|
12767
|
-
* @async
|
|
12768
|
-
*/
|
|
12769
|
-
const getInvitation = async (params) => {
|
|
12770
|
-
const client = getActiveClient();
|
|
12771
|
-
client.log('invitation/getInvitation', params.targetType, params.targetId, params.type);
|
|
12772
|
-
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params });
|
|
12773
|
-
const data = prepareMyInvitationsPayload(payload);
|
|
12774
|
-
const cachedAt = client.cache && Date.now();
|
|
12775
|
-
if (client.cache)
|
|
12776
|
-
ingestInCache(data, { cachedAt });
|
|
12777
|
-
return {
|
|
12778
|
-
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
12779
|
-
cachedAt,
|
|
12780
|
-
};
|
|
12781
|
-
};
|
|
12782
|
-
/* end_public_function */
|
|
12783
|
-
|
|
12784
|
-
const roomLinkedObject = (room) => {
|
|
12785
|
-
return Object.assign(Object.assign({}, room), { get moderation() {
|
|
12786
|
-
var _a;
|
|
12787
|
-
return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12788
|
-
},
|
|
12789
|
-
get post() {
|
|
12790
|
-
var _a;
|
|
12791
|
-
if (room.referenceType !== 'post')
|
|
12792
|
-
return;
|
|
12793
|
-
return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12794
|
-
},
|
|
12795
|
-
get community() {
|
|
12796
|
-
var _a;
|
|
12797
|
-
if (room.targetType !== 'community')
|
|
12798
|
-
return;
|
|
12799
|
-
return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12800
|
-
},
|
|
12801
|
-
get user() {
|
|
12802
|
-
var _a;
|
|
12803
|
-
const user = (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12804
|
-
return user ? userLinkedObject(user) : user;
|
|
12805
|
-
},
|
|
12806
|
-
get childRooms() {
|
|
12807
|
-
if (!room.childRoomIds || room.childRoomIds.length === 0)
|
|
12808
|
-
return [];
|
|
12809
|
-
return room.childRoomIds
|
|
12810
|
-
.map(id => {
|
|
12811
|
-
var _a;
|
|
12812
|
-
const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12813
|
-
if (!roomCache)
|
|
12814
|
-
return undefined;
|
|
12815
|
-
return roomLinkedObject(roomCache);
|
|
12816
|
-
})
|
|
12817
|
-
.filter(isNonNullable);
|
|
12818
|
-
}, participants: room.participants.map(participant => (Object.assign(Object.assign({}, participant), { get user() {
|
|
12819
|
-
var _a;
|
|
12820
|
-
const user = (_a = pullFromCache(['user', 'get', participant.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
12821
|
-
return user ? userLinkedObject(user) : user;
|
|
12822
|
-
} }))), getLiveChat: () => getLiveChat(room), createInvitation: (userId) => createInvitations({
|
|
12823
|
-
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
12824
|
-
targetType: 'room',
|
|
12825
|
-
targetId: room.roomId,
|
|
12826
|
-
userIds: [userId],
|
|
12827
|
-
}), getInvitations: (params, callback) => getInvitations$1(Object.assign(Object.assign({}, params), { targetId: room.roomId, targetType: 'room', type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */ }), callback), getMyInvitation: async () => {
|
|
12828
|
-
const { data } = await getInvitation({
|
|
12829
|
-
targetId: room.roomId,
|
|
12830
|
-
targetType: 'room',
|
|
12831
|
-
type: "livestreamCohostInvite" /* InvitationTypeEnum.LivestreamCohostInvite */,
|
|
12832
|
-
});
|
|
12833
|
-
return data;
|
|
12834
|
-
} });
|
|
12835
|
-
};
|
|
12836
|
-
|
|
12837
|
-
/*
|
|
12838
|
-
* verifies membership status
|
|
12839
|
-
*/
|
|
12840
|
-
function isMember(membership) {
|
|
12841
|
-
return membership !== 'none';
|
|
12842
|
-
}
|
|
12843
|
-
/*
|
|
12844
|
-
* checks if currently logged in user is part of the community
|
|
12845
|
-
*/
|
|
12846
|
-
function isCurrentUserPartOfCommunity(c, m) {
|
|
12847
|
-
const { userId } = getActiveUser();
|
|
12848
|
-
return c.communityId === m.communityId && m.userId === userId;
|
|
12849
|
-
}
|
|
12850
|
-
/*
|
|
12851
|
-
* For mqtt events server will not send user specific data as it's broadcasted
|
|
12852
|
-
* to multiple users and it also does not include communityUser
|
|
12853
|
-
*
|
|
12854
|
-
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
12855
|
-
* Althought this can be calculated, it's not scalable.
|
|
12606
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
12607
|
+
* Althought this can be calculated, it's not scalable.
|
|
12856
12608
|
*/
|
|
12857
12609
|
function updateMembershipStatus(communities, communityUsers) {
|
|
12858
12610
|
return communities.map(c => {
|
|
@@ -13128,36 +12880,294 @@ const joinRequest = async (communityId) => {
|
|
|
13128
12880
|
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
13129
12881
|
}
|
|
13130
12882
|
}
|
|
13131
|
-
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
13132
|
-
return status === "success" /* JoinResultStatusEnum.Success */
|
|
13133
|
-
? { status }
|
|
13134
|
-
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
13135
|
-
};
|
|
13136
|
-
/* end_public_function */
|
|
12883
|
+
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
12884
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
12885
|
+
? { status }
|
|
12886
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
12887
|
+
};
|
|
12888
|
+
/* end_public_function */
|
|
12889
|
+
|
|
12890
|
+
/**
|
|
12891
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
12892
|
+
* TODO: check if querybyIds is supported
|
|
12893
|
+
*/
|
|
12894
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
12895
|
+
async getRequest(queryParams, token) {
|
|
12896
|
+
const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
12897
|
+
const options = token ? { token } : { limit };
|
|
12898
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
12899
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
12900
|
+
});
|
|
12901
|
+
return queryResponse;
|
|
12902
|
+
}
|
|
12903
|
+
}
|
|
12904
|
+
|
|
12905
|
+
var EnumJoinRequestAction$1;
|
|
12906
|
+
(function (EnumJoinRequestAction) {
|
|
12907
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
12908
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
12909
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
12910
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
12911
|
+
|
|
12912
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
12913
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
12914
|
+
super(query, cacheKey);
|
|
12915
|
+
this.notifyChange = notifyChange;
|
|
12916
|
+
this.preparePayload = preparePayload;
|
|
12917
|
+
}
|
|
12918
|
+
async saveToMainDB(response) {
|
|
12919
|
+
const processedPayload = await this.preparePayload(response);
|
|
12920
|
+
const client = getActiveClient();
|
|
12921
|
+
const cachedAt = client.cache && Date.now();
|
|
12922
|
+
if (client.cache) {
|
|
12923
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
12924
|
+
}
|
|
12925
|
+
}
|
|
12926
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
12927
|
+
var _a, _b;
|
|
12928
|
+
if (refresh) {
|
|
12929
|
+
pushToCache(this.cacheKey, {
|
|
12930
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
12931
|
+
});
|
|
12932
|
+
}
|
|
12933
|
+
else {
|
|
12934
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12935
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
12936
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
12937
|
+
...new Set([
|
|
12938
|
+
...joinRequests,
|
|
12939
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
12940
|
+
]),
|
|
12941
|
+
] }));
|
|
12942
|
+
}
|
|
12943
|
+
}
|
|
12944
|
+
reactor(action) {
|
|
12945
|
+
return (joinRequest) => {
|
|
12946
|
+
var _a;
|
|
12947
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
12948
|
+
if (!collection)
|
|
12949
|
+
return;
|
|
12950
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
12951
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
12952
|
+
if (!isExist)
|
|
12953
|
+
return;
|
|
12954
|
+
}
|
|
12955
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
12956
|
+
collection.data = [
|
|
12957
|
+
...new Set([
|
|
12958
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
12959
|
+
...collection.data,
|
|
12960
|
+
]),
|
|
12961
|
+
];
|
|
12962
|
+
}
|
|
12963
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
12964
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
12965
|
+
}
|
|
12966
|
+
pushToCache(this.cacheKey, collection);
|
|
12967
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
12968
|
+
};
|
|
12969
|
+
}
|
|
12970
|
+
subscribeRTE(createSubscriber) {
|
|
12971
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
12972
|
+
}
|
|
12973
|
+
}
|
|
12974
|
+
|
|
12975
|
+
/**
|
|
12976
|
+
* ```js
|
|
12977
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
12978
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
12979
|
+
* // ...
|
|
12980
|
+
* })
|
|
12981
|
+
* ```
|
|
12982
|
+
*
|
|
12983
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
12984
|
+
*
|
|
12985
|
+
* @param callback The function to call when the event was fired
|
|
12986
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
12987
|
+
*
|
|
12988
|
+
* @category JoinRequest Events
|
|
12989
|
+
*/
|
|
12990
|
+
const onJoinRequestCreated = (callback) => {
|
|
12991
|
+
const client = getActiveClient();
|
|
12992
|
+
const disposers = [
|
|
12993
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
12994
|
+
];
|
|
12995
|
+
return () => {
|
|
12996
|
+
disposers.forEach(fn => fn());
|
|
12997
|
+
};
|
|
12998
|
+
};
|
|
12999
|
+
|
|
13000
|
+
/**
|
|
13001
|
+
* ```js
|
|
13002
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
13003
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
13004
|
+
* // ...
|
|
13005
|
+
* })
|
|
13006
|
+
* ```
|
|
13007
|
+
*
|
|
13008
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
13009
|
+
*
|
|
13010
|
+
* @param callback The function to call when the event was fired
|
|
13011
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13012
|
+
*
|
|
13013
|
+
* @category JoinRequest Events
|
|
13014
|
+
*/
|
|
13015
|
+
const onJoinRequestUpdated = (callback) => {
|
|
13016
|
+
const client = getActiveClient();
|
|
13017
|
+
const disposers = [
|
|
13018
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
13019
|
+
];
|
|
13020
|
+
return () => {
|
|
13021
|
+
disposers.forEach(fn => fn());
|
|
13022
|
+
};
|
|
13023
|
+
};
|
|
13024
|
+
|
|
13025
|
+
/**
|
|
13026
|
+
* ```js
|
|
13027
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
13028
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
13029
|
+
* // ...
|
|
13030
|
+
* })
|
|
13031
|
+
* ```
|
|
13032
|
+
*
|
|
13033
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
13034
|
+
*
|
|
13035
|
+
* @param callback The function to call when the event was fired
|
|
13036
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13037
|
+
*
|
|
13038
|
+
* @category JoinRequest Events
|
|
13039
|
+
*/
|
|
13040
|
+
const onJoinRequestDeleted = (callback) => {
|
|
13041
|
+
const client = getActiveClient();
|
|
13042
|
+
const disposers = [
|
|
13043
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
13044
|
+
];
|
|
13045
|
+
return () => {
|
|
13046
|
+
disposers.forEach(fn => fn());
|
|
13047
|
+
};
|
|
13048
|
+
};
|
|
13049
|
+
|
|
13050
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
13051
|
+
constructor(query, callback) {
|
|
13052
|
+
const queryStreamId = hash__default["default"](query);
|
|
13053
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
13054
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
13055
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
13056
|
+
this.query = query;
|
|
13057
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
13058
|
+
this.callback = callback.bind(this);
|
|
13059
|
+
this.loadPage({ initial: true });
|
|
13060
|
+
}
|
|
13061
|
+
setup() {
|
|
13062
|
+
var _a;
|
|
13063
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13064
|
+
if (!collection) {
|
|
13065
|
+
pushToCache(this.cacheKey, {
|
|
13066
|
+
data: [],
|
|
13067
|
+
params: this.query,
|
|
13068
|
+
});
|
|
13069
|
+
}
|
|
13070
|
+
}
|
|
13071
|
+
async persistModel(queryPayload) {
|
|
13072
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
13073
|
+
}
|
|
13074
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
13075
|
+
const joinRequestResponse = response;
|
|
13076
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
13077
|
+
}
|
|
13078
|
+
startSubscription() {
|
|
13079
|
+
return this.queryStreamController.subscribeRTE([
|
|
13080
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
13081
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
13082
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
13083
|
+
]);
|
|
13084
|
+
}
|
|
13085
|
+
notifyChange({ origin, loading, error }) {
|
|
13086
|
+
var _a;
|
|
13087
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13088
|
+
if (!collection)
|
|
13089
|
+
return;
|
|
13090
|
+
const data = this.applyFilter(collection.data
|
|
13091
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
13092
|
+
.filter(isNonNullable)
|
|
13093
|
+
.map(({ data }) => data)
|
|
13094
|
+
.map(joinRequestLinkedObject));
|
|
13095
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
13096
|
+
return;
|
|
13097
|
+
this.callback({
|
|
13098
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
13099
|
+
data,
|
|
13100
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
13101
|
+
loading,
|
|
13102
|
+
error,
|
|
13103
|
+
});
|
|
13104
|
+
}
|
|
13105
|
+
applyFilter(data) {
|
|
13106
|
+
let joinRequest = data;
|
|
13107
|
+
if (this.query.status) {
|
|
13108
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
13109
|
+
}
|
|
13110
|
+
const sortFn = (() => {
|
|
13111
|
+
switch (this.query.sortBy) {
|
|
13112
|
+
case 'firstCreated':
|
|
13113
|
+
return sortByFirstCreated;
|
|
13114
|
+
case 'lastCreated':
|
|
13115
|
+
return sortByLastCreated;
|
|
13116
|
+
default:
|
|
13117
|
+
return sortByLastCreated;
|
|
13118
|
+
}
|
|
13119
|
+
})();
|
|
13120
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
13121
|
+
return joinRequest;
|
|
13122
|
+
}
|
|
13123
|
+
}
|
|
13137
13124
|
|
|
13138
13125
|
/**
|
|
13139
|
-
*
|
|
13140
|
-
*
|
|
13126
|
+
* Get Join Requests
|
|
13127
|
+
*
|
|
13128
|
+
* @param params the query parameters
|
|
13129
|
+
* @param callback the callback to be called when the join request are updated
|
|
13130
|
+
* @returns joinRequests
|
|
13131
|
+
*
|
|
13132
|
+
* @category joinRequest Live Collection
|
|
13133
|
+
*
|
|
13141
13134
|
*/
|
|
13142
|
-
|
|
13135
|
+
const getJoinRequests = (params, callback, config) => {
|
|
13136
|
+
const { log, cache } = getActiveClient();
|
|
13137
|
+
if (!cache) {
|
|
13138
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
13139
|
+
}
|
|
13140
|
+
const timestamp = Date.now();
|
|
13141
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
13142
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
13143
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
13144
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
13145
|
+
disposers.push(() => {
|
|
13146
|
+
dropFromCache(cacheKey);
|
|
13147
|
+
});
|
|
13148
|
+
return () => {
|
|
13149
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
13150
|
+
disposers.forEach(fn => fn());
|
|
13151
|
+
};
|
|
13152
|
+
};
|
|
13153
|
+
|
|
13154
|
+
var InvitationActionsEnum;
|
|
13155
|
+
(function (InvitationActionsEnum) {
|
|
13156
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
13157
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
13158
|
+
InvitationActionsEnum["OnLocalInvitationCanceled"] = "onLocalInvitationCanceled";
|
|
13159
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
13160
|
+
|
|
13161
|
+
class InvitationsPaginationController extends PaginationController {
|
|
13143
13162
|
async getRequest(queryParams, token) {
|
|
13144
|
-
const { limit =
|
|
13163
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
13145
13164
|
const options = token ? { token } : { limit };
|
|
13146
|
-
const { data
|
|
13147
|
-
|
|
13148
|
-
});
|
|
13149
|
-
return queryResponse;
|
|
13165
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
13166
|
+
return data;
|
|
13150
13167
|
}
|
|
13151
13168
|
}
|
|
13152
13169
|
|
|
13153
|
-
|
|
13154
|
-
(function (EnumJoinRequestAction) {
|
|
13155
|
-
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
13156
|
-
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
13157
|
-
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
13158
|
-
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
13159
|
-
|
|
13160
|
-
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
13170
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
13161
13171
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
13162
13172
|
super(query, cacheKey);
|
|
13163
13173
|
this.notifyChange = notifyChange;
|
|
@@ -13175,41 +13185,38 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
13175
13185
|
var _a, _b;
|
|
13176
13186
|
if (refresh) {
|
|
13177
13187
|
pushToCache(this.cacheKey, {
|
|
13178
|
-
data: response.
|
|
13188
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
13179
13189
|
});
|
|
13180
13190
|
}
|
|
13181
13191
|
else {
|
|
13182
13192
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13183
|
-
const
|
|
13193
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
13184
13194
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
13185
|
-
...new Set([
|
|
13186
|
-
...joinRequests,
|
|
13187
|
-
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
13188
|
-
]),
|
|
13195
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
13189
13196
|
] }));
|
|
13190
13197
|
}
|
|
13191
13198
|
}
|
|
13192
13199
|
reactor(action) {
|
|
13193
|
-
return (
|
|
13200
|
+
return (invitations) => {
|
|
13194
13201
|
var _a;
|
|
13195
13202
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13196
13203
|
if (!collection)
|
|
13197
13204
|
return;
|
|
13198
|
-
if (action ===
|
|
13199
|
-
const isExist = collection.data.find(id => id ===
|
|
13205
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
13206
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
13200
13207
|
if (!isExist)
|
|
13201
13208
|
return;
|
|
13202
13209
|
}
|
|
13203
|
-
if (action ===
|
|
13210
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
13204
13211
|
collection.data = [
|
|
13205
13212
|
...new Set([
|
|
13206
|
-
...
|
|
13213
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
13207
13214
|
...collection.data,
|
|
13208
13215
|
]),
|
|
13209
13216
|
];
|
|
13210
13217
|
}
|
|
13211
|
-
if (action ===
|
|
13212
|
-
collection.data = collection.data.filter(id => id !==
|
|
13218
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
13219
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
13213
13220
|
}
|
|
13214
13221
|
pushToCache(this.cacheKey, collection);
|
|
13215
13222
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -13222,23 +13229,23 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
13222
13229
|
|
|
13223
13230
|
/**
|
|
13224
13231
|
* ```js
|
|
13225
|
-
* import {
|
|
13226
|
-
* const dispose =
|
|
13232
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
13233
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
13227
13234
|
* // ...
|
|
13228
13235
|
* })
|
|
13229
13236
|
* ```
|
|
13230
13237
|
*
|
|
13231
|
-
* Fired when an {@link Amity.
|
|
13238
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
13232
13239
|
*
|
|
13233
13240
|
* @param callback The function to call when the event was fired
|
|
13234
13241
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13235
13242
|
*
|
|
13236
|
-
* @category
|
|
13243
|
+
* @category Invitation Events
|
|
13237
13244
|
*/
|
|
13238
|
-
const
|
|
13245
|
+
const onLocalInvitationCreated = (callback) => {
|
|
13239
13246
|
const client = getActiveClient();
|
|
13240
13247
|
const disposers = [
|
|
13241
|
-
createEventSubscriber(client, '
|
|
13248
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
13242
13249
|
];
|
|
13243
13250
|
return () => {
|
|
13244
13251
|
disposers.forEach(fn => fn());
|
|
@@ -13247,23 +13254,23 @@ const onJoinRequestCreated = (callback) => {
|
|
|
13247
13254
|
|
|
13248
13255
|
/**
|
|
13249
13256
|
* ```js
|
|
13250
|
-
* import {
|
|
13251
|
-
* const dispose =
|
|
13257
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
13258
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
13252
13259
|
* // ...
|
|
13253
13260
|
* })
|
|
13254
13261
|
* ```
|
|
13255
13262
|
*
|
|
13256
|
-
* Fired when an {@link Amity.
|
|
13263
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
13257
13264
|
*
|
|
13258
13265
|
* @param callback The function to call when the event was fired
|
|
13259
13266
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13260
13267
|
*
|
|
13261
|
-
* @category
|
|
13268
|
+
* @category Invitation Events
|
|
13262
13269
|
*/
|
|
13263
|
-
const
|
|
13270
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
13264
13271
|
const client = getActiveClient();
|
|
13265
13272
|
const disposers = [
|
|
13266
|
-
createEventSubscriber(client, '
|
|
13273
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
13267
13274
|
];
|
|
13268
13275
|
return () => {
|
|
13269
13276
|
disposers.forEach(fn => fn());
|
|
@@ -13272,37 +13279,37 @@ const onJoinRequestUpdated = (callback) => {
|
|
|
13272
13279
|
|
|
13273
13280
|
/**
|
|
13274
13281
|
* ```js
|
|
13275
|
-
* import {
|
|
13276
|
-
* const dispose =
|
|
13282
|
+
* import { onLocalInvitationCanceled } from '@amityco/ts-sdk'
|
|
13283
|
+
* const dispose = onLocalInvitationCanceled(data => {
|
|
13277
13284
|
* // ...
|
|
13278
13285
|
* })
|
|
13279
13286
|
* ```
|
|
13280
13287
|
*
|
|
13281
|
-
* Fired when an {@link Amity.
|
|
13288
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
13282
13289
|
*
|
|
13283
13290
|
* @param callback The function to call when the event was fired
|
|
13284
13291
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
13285
13292
|
*
|
|
13286
|
-
* @category
|
|
13293
|
+
* @category Invitation Events
|
|
13287
13294
|
*/
|
|
13288
|
-
const
|
|
13295
|
+
const onLocalInvitationCanceled = (callback) => {
|
|
13289
13296
|
const client = getActiveClient();
|
|
13290
13297
|
const disposers = [
|
|
13291
|
-
createEventSubscriber(client, '
|
|
13298
|
+
createEventSubscriber(client, 'onLocalInvitationCanceled', 'local.invitation.canceled', payload => callback(payload)),
|
|
13292
13299
|
];
|
|
13293
13300
|
return () => {
|
|
13294
13301
|
disposers.forEach(fn => fn());
|
|
13295
13302
|
};
|
|
13296
13303
|
};
|
|
13297
13304
|
|
|
13298
|
-
class
|
|
13305
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
13299
13306
|
constructor(query, callback) {
|
|
13300
13307
|
const queryStreamId = hash__default["default"](query);
|
|
13301
|
-
const cacheKey = ['
|
|
13302
|
-
const paginationController = new
|
|
13308
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
13309
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
13303
13310
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
13304
13311
|
this.query = query;
|
|
13305
|
-
this.queryStreamController = new
|
|
13312
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
13306
13313
|
this.callback = callback.bind(this);
|
|
13307
13314
|
this.loadPage({ initial: true });
|
|
13308
13315
|
}
|
|
@@ -13320,26 +13327,33 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
|
13320
13327
|
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
13321
13328
|
}
|
|
13322
13329
|
persistQueryStream({ response, direction, refresh, }) {
|
|
13323
|
-
|
|
13324
|
-
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
13330
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
13325
13331
|
}
|
|
13326
13332
|
startSubscription() {
|
|
13327
13333
|
return this.queryStreamController.subscribeRTE([
|
|
13328
|
-
{
|
|
13329
|
-
|
|
13330
|
-
|
|
13334
|
+
{
|
|
13335
|
+
fn: onLocalInvitationCreated,
|
|
13336
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
13337
|
+
},
|
|
13338
|
+
{
|
|
13339
|
+
fn: onLocalInvitationUpdated,
|
|
13340
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
13341
|
+
},
|
|
13342
|
+
{
|
|
13343
|
+
fn: onLocalInvitationCanceled,
|
|
13344
|
+
action: InvitationActionsEnum.OnLocalInvitationCanceled,
|
|
13345
|
+
},
|
|
13331
13346
|
]);
|
|
13332
13347
|
}
|
|
13333
13348
|
notifyChange({ origin, loading, error }) {
|
|
13334
|
-
var _a;
|
|
13349
|
+
var _a, _b;
|
|
13335
13350
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13336
13351
|
if (!collection)
|
|
13337
13352
|
return;
|
|
13338
|
-
const data = this.applyFilter(collection.data
|
|
13339
|
-
.map(id => pullFromCache(['
|
|
13353
|
+
const data = this.applyFilter((_b = collection.data
|
|
13354
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
13340
13355
|
.filter(isNonNullable)
|
|
13341
|
-
.map(({ data }) => data)
|
|
13342
|
-
.map(joinRequestLinkedObject));
|
|
13356
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
13343
13357
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
13344
13358
|
return;
|
|
13345
13359
|
this.callback({
|
|
@@ -13351,9 +13365,18 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
|
13351
13365
|
});
|
|
13352
13366
|
}
|
|
13353
13367
|
applyFilter(data) {
|
|
13354
|
-
let
|
|
13355
|
-
if (this.query.
|
|
13356
|
-
|
|
13368
|
+
let invitations = data;
|
|
13369
|
+
if (this.query.targetId) {
|
|
13370
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
13371
|
+
}
|
|
13372
|
+
if (this.query.statuses) {
|
|
13373
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
13374
|
+
}
|
|
13375
|
+
if (this.query.targetType) {
|
|
13376
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
13377
|
+
}
|
|
13378
|
+
if (this.query.type) {
|
|
13379
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
13357
13380
|
}
|
|
13358
13381
|
const sortFn = (() => {
|
|
13359
13382
|
switch (this.query.sortBy) {
|
|
@@ -13365,36 +13388,36 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
|
13365
13388
|
return sortByLastCreated;
|
|
13366
13389
|
}
|
|
13367
13390
|
})();
|
|
13368
|
-
|
|
13369
|
-
return
|
|
13391
|
+
invitations = invitations.sort(sortFn);
|
|
13392
|
+
return invitations;
|
|
13370
13393
|
}
|
|
13371
13394
|
}
|
|
13372
13395
|
|
|
13373
13396
|
/**
|
|
13374
|
-
* Get
|
|
13397
|
+
* Get invitations
|
|
13375
13398
|
*
|
|
13376
13399
|
* @param params the query parameters
|
|
13377
|
-
* @param callback the callback to be called when the
|
|
13378
|
-
* @returns
|
|
13400
|
+
* @param callback the callback to be called when the invitations are updated
|
|
13401
|
+
* @returns invitations
|
|
13379
13402
|
*
|
|
13380
|
-
* @category
|
|
13403
|
+
* @category Invitation Live Collection
|
|
13381
13404
|
*
|
|
13382
13405
|
*/
|
|
13383
|
-
const
|
|
13406
|
+
const getInvitations$1 = (params, callback, config) => {
|
|
13384
13407
|
const { log, cache } = getActiveClient();
|
|
13385
13408
|
if (!cache) {
|
|
13386
13409
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
13387
13410
|
}
|
|
13388
13411
|
const timestamp = Date.now();
|
|
13389
|
-
log(`
|
|
13390
|
-
const
|
|
13391
|
-
const disposers =
|
|
13392
|
-
const cacheKey =
|
|
13412
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
13413
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
13414
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
13415
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
13393
13416
|
disposers.push(() => {
|
|
13394
13417
|
dropFromCache(cacheKey);
|
|
13395
13418
|
});
|
|
13396
13419
|
return () => {
|
|
13397
|
-
log(`
|
|
13420
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
13398
13421
|
disposers.forEach(fn => fn());
|
|
13399
13422
|
};
|
|
13400
13423
|
};
|
|
@@ -14095,7 +14118,7 @@ class RSVPQueryStreamController extends QueryStreamController {
|
|
|
14095
14118
|
const client = getActiveClient();
|
|
14096
14119
|
const cachedAt = client.cache && Date.now();
|
|
14097
14120
|
if (client.cache)
|
|
14098
|
-
ingestInCache(
|
|
14121
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
14099
14122
|
}
|
|
14100
14123
|
appendToQueryStream(response, direction, refresh = false) {
|
|
14101
14124
|
var _a, _b;
|
|
@@ -14119,10 +14142,7 @@ class RSVPQueryStreamController extends QueryStreamController {
|
|
|
14119
14142
|
if (!collection)
|
|
14120
14143
|
return;
|
|
14121
14144
|
if (action === EventActionsEnum.OnRSVPCreated) {
|
|
14122
|
-
|
|
14123
|
-
if (client.userId !== event.userId)
|
|
14124
|
-
return;
|
|
14125
|
-
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
14145
|
+
collection.data = [...new Set([event.userId, ...collection.data])];
|
|
14126
14146
|
}
|
|
14127
14147
|
if (action === EventActionsEnum.OnEventDeleted) {
|
|
14128
14148
|
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
@@ -14338,14 +14358,14 @@ class RSVPLiveCollectionController extends LiveCollectionController {
|
|
|
14338
14358
|
]);
|
|
14339
14359
|
}
|
|
14340
14360
|
notifyChange({ origin, loading, error }) {
|
|
14341
|
-
var _a
|
|
14361
|
+
var _a;
|
|
14342
14362
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14343
14363
|
if (!collection)
|
|
14344
14364
|
return;
|
|
14345
|
-
const data =
|
|
14346
|
-
.map(
|
|
14365
|
+
const data = collection.data
|
|
14366
|
+
.map(userId => pullFromCache(['eventResponse', 'get', userId]))
|
|
14347
14367
|
.filter(isNonNullable)
|
|
14348
|
-
.map(({ data }) => data))
|
|
14368
|
+
.map(({ data }) => eventResponseLinkedObject(data));
|
|
14349
14369
|
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
14350
14370
|
return;
|
|
14351
14371
|
this.callback({
|
|
@@ -26931,6 +26951,15 @@ const getPostSubscription = (cacheKey) => {
|
|
|
26931
26951
|
...generateCommentSubscriptions({ cacheKey }),
|
|
26932
26952
|
];
|
|
26933
26953
|
};
|
|
26954
|
+
const resolvePostIdsFromRooms = (rooms, posts) => {
|
|
26955
|
+
var _a;
|
|
26956
|
+
return ((_a = rooms
|
|
26957
|
+
.map(room => {
|
|
26958
|
+
const post = posts.find(post => post.postId === room.referenceId);
|
|
26959
|
+
return post ? getResolver('post')({ postId: post === null || post === void 0 ? void 0 : post.postId }) : undefined;
|
|
26960
|
+
})
|
|
26961
|
+
.filter(isNonNullable)) !== null && _a !== void 0 ? _a : []);
|
|
26962
|
+
};
|
|
26934
26963
|
|
|
26935
26964
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
26936
26965
|
constructor(query, callback) {
|
|
@@ -27824,7 +27853,7 @@ class LiveRoomPostPaginationController extends PaginationNoPageController {
|
|
|
27824
27853
|
targetTypes: ['all'],
|
|
27825
27854
|
options: {
|
|
27826
27855
|
limit,
|
|
27827
|
-
sortBy: '
|
|
27856
|
+
sortBy: 'lastCreated',
|
|
27828
27857
|
},
|
|
27829
27858
|
},
|
|
27830
27859
|
});
|
|
@@ -27850,13 +27879,13 @@ class LiveRoomPostQueryStreamController extends QueryStreamController {
|
|
|
27850
27879
|
var _a, _b;
|
|
27851
27880
|
if (refresh) {
|
|
27852
27881
|
pushToCache(this.cacheKey, {
|
|
27853
|
-
data: response.posts
|
|
27882
|
+
data: resolvePostIdsFromRooms(response.rooms, response.posts),
|
|
27854
27883
|
});
|
|
27855
27884
|
}
|
|
27856
27885
|
else {
|
|
27857
27886
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27858
27887
|
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27859
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts
|
|
27888
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...resolvePostIdsFromRooms(response.rooms, response.posts)])] }));
|
|
27860
27889
|
}
|
|
27861
27890
|
}
|
|
27862
27891
|
reactor(action) {
|
|
@@ -28394,6 +28423,30 @@ const onRoomParticipantLeft = (callback) => {
|
|
|
28394
28423
|
return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
|
|
28395
28424
|
};
|
|
28396
28425
|
|
|
28426
|
+
/**
|
|
28427
|
+
* ```js
|
|
28428
|
+
* import { onRoomTerminated } from '@amityco/ts-sdk'
|
|
28429
|
+
* const dispose = onRoomTerminated(room => {
|
|
28430
|
+
* // ...
|
|
28431
|
+
* })
|
|
28432
|
+
* ```
|
|
28433
|
+
*
|
|
28434
|
+
* Fired when a {@link Amity.Room} has started broadcasting
|
|
28435
|
+
*
|
|
28436
|
+
* @param callback The function to call when the event was fired
|
|
28437
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28438
|
+
*
|
|
28439
|
+
* @category Room Events
|
|
28440
|
+
*/
|
|
28441
|
+
const onRoomTerminated = (callback) => {
|
|
28442
|
+
const client = getActiveClient();
|
|
28443
|
+
const filter = (payload) => {
|
|
28444
|
+
ingestInCache(payload);
|
|
28445
|
+
callback(payload.rooms[0]);
|
|
28446
|
+
};
|
|
28447
|
+
return createEventSubscriber(client, 'room/onRoomTerminated', 'room.terminated', filter);
|
|
28448
|
+
};
|
|
28449
|
+
|
|
28397
28450
|
/**
|
|
28398
28451
|
* ```js
|
|
28399
28452
|
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
@@ -28568,6 +28621,7 @@ const getRoom = (roomId, callback) => {
|
|
|
28568
28621
|
onRoomEndBroadcasting,
|
|
28569
28622
|
onRoomStartBroadcasting,
|
|
28570
28623
|
onRoomWaitingReconnect,
|
|
28624
|
+
onRoomTerminated,
|
|
28571
28625
|
onRoomRecordedAvailable,
|
|
28572
28626
|
onRoomParticipantJoined,
|
|
28573
28627
|
onRoomParticipantLeft,
|
|
@@ -28813,6 +28867,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
28813
28867
|
onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
|
|
28814
28868
|
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
28815
28869
|
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
28870
|
+
onRoomTerminated: onRoomTerminated,
|
|
28816
28871
|
onRoomCreated: onRoomCreated,
|
|
28817
28872
|
onRoomUpdated: onRoomUpdated,
|
|
28818
28873
|
onRoomDeleted: onRoomDeleted,
|
|
@@ -28958,13 +29013,13 @@ class CommunityLiveRoomPostQueryStreamController extends QueryStreamController {
|
|
|
28958
29013
|
var _a, _b;
|
|
28959
29014
|
if (refresh) {
|
|
28960
29015
|
pushToCache(this.cacheKey, {
|
|
28961
|
-
data: response.posts
|
|
29016
|
+
data: resolvePostIdsFromRooms(response.rooms, response.posts),
|
|
28962
29017
|
});
|
|
28963
29018
|
}
|
|
28964
29019
|
else {
|
|
28965
29020
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28966
29021
|
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28967
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts
|
|
29022
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...resolvePostIdsFromRooms(response.rooms, response.posts)])] }));
|
|
28968
29023
|
}
|
|
28969
29024
|
}
|
|
28970
29025
|
reactor(action) {
|
|
@@ -29782,7 +29837,6 @@ const getRoomUserCount = async (roomId) => {
|
|
|
29782
29837
|
client.log('roomPresence/getRoomUserCount', { roomId });
|
|
29783
29838
|
const { data } = await client.http.get(`/api/v1/presence/rooms/${roomId}/users/count`);
|
|
29784
29839
|
pushToCache(['get', 'watchingCount', roomId], data);
|
|
29785
|
-
fireEvent('local.room.watchingCountUpdated', data);
|
|
29786
29840
|
return data;
|
|
29787
29841
|
};
|
|
29788
29842
|
/* end_public_function */
|
|
@@ -32823,15 +32877,23 @@ const updateEvent = async (eventId, bundle) => {
|
|
|
32823
32877
|
const getEvent$1 = async (eventId) => {
|
|
32824
32878
|
const client = getActiveClient();
|
|
32825
32879
|
client.log('event/getEvent', eventId);
|
|
32826
|
-
|
|
32827
|
-
|
|
32828
|
-
|
|
32829
|
-
|
|
32830
|
-
|
|
32831
|
-
|
|
32832
|
-
|
|
32833
|
-
|
|
32834
|
-
|
|
32880
|
+
try {
|
|
32881
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
|
|
32882
|
+
const data = prepareEventPayload(payload);
|
|
32883
|
+
const cachedAt = client.cache && Date.now();
|
|
32884
|
+
if (client.cache)
|
|
32885
|
+
ingestInCache(data, { cachedAt });
|
|
32886
|
+
return {
|
|
32887
|
+
data: data.events.find(event => event.eventId === eventId),
|
|
32888
|
+
cachedAt,
|
|
32889
|
+
};
|
|
32890
|
+
}
|
|
32891
|
+
catch (error) {
|
|
32892
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
32893
|
+
dropFromCache(['event', 'get', eventId]);
|
|
32894
|
+
}
|
|
32895
|
+
throw error;
|
|
32896
|
+
}
|
|
32835
32897
|
};
|
|
32836
32898
|
/* end_public_function */
|
|
32837
32899
|
/**
|