@amityco/ts-sdk 7.11.1-459a5ad.0 → 7.11.1-4c0bf09.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 +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +13 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +7 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +30 -1
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +10 -4
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +12 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/client/utils/setCurrentUser.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/eventRepository/events/enums.d.ts +3 -1
- package/dist/eventRepository/events/enums.d.ts.map +1 -1
- package/dist/eventRepository/events/index.d.ts +4 -0
- package/dist/eventRepository/events/index.d.ts.map +1 -1
- package/dist/eventRepository/events/onEventCreated.d.ts +1 -1
- package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
- package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
- package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
- package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
- package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/createRSVP.d.ts +17 -0
- package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
- package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
- package/dist/eventRepository/internalApi/index.d.ts +3 -0
- package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
- package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
- package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
- package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
- package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
- package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
- package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
- package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
- package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
- package/dist/eventRepository/observers/index.d.ts +2 -0
- package/dist/eventRepository/observers/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
- package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
- package/dist/eventRepository/utils/index.d.ts +2 -0
- package/dist/eventRepository/utils/index.d.ts.map +1 -1
- package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
- package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
- package/dist/index.cjs.js +2637 -1743
- package/dist/index.esm.js +2466 -1572
- package/dist/index.umd.js +3 -3
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts/CommunityLiveRoomPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts.d.ts +22 -0
- package/dist/postRepository/observers/getCommunityLiveRoomPosts.d.ts.map +1 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getLiveRoomPosts/LiveRoomPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getLiveRoomPosts.d.ts +23 -0
- package/dist/postRepository/observers/getLiveRoomPosts.d.ts.map +1 -0
- package/dist/postRepository/observers/index.d.ts +2 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/eventResponseLinkObject.d.ts +2 -0
- package/dist/utils/linkedObject/eventResponseLinkObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -209,7 +209,6 @@ var AmityEventStatus;
|
|
|
209
209
|
var AmityEventResponseStatus;
|
|
210
210
|
(function (AmityEventResponseStatus) {
|
|
211
211
|
AmityEventResponseStatus["Going"] = "going";
|
|
212
|
-
AmityEventResponseStatus["Interested"] = "interested";
|
|
213
212
|
AmityEventResponseStatus["NotGoing"] = "not_going";
|
|
214
213
|
})(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
|
|
215
214
|
var AmityEventSortOption;
|
|
@@ -672,7 +671,9 @@ const idResolvers = {
|
|
|
672
671
|
invitation: ({ _id }) => _id,
|
|
673
672
|
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
674
673
|
room: ({ roomId }) => roomId,
|
|
674
|
+
viewer: ({ userId }) => userId,
|
|
675
675
|
event: ({ eventId }) => eventId,
|
|
676
|
+
eventResponse: ({ eventId }) => eventId,
|
|
676
677
|
};
|
|
677
678
|
/**
|
|
678
679
|
* Retrieve the id resolver matching a domain name
|
|
@@ -731,6 +732,7 @@ const PAYLOAD2MODEL = {
|
|
|
731
732
|
rooms: 'room',
|
|
732
733
|
events: 'event',
|
|
733
734
|
viewers: 'viewer',
|
|
735
|
+
eventResponses: 'eventResponse',
|
|
734
736
|
};
|
|
735
737
|
/** hidden */
|
|
736
738
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -23405,6 +23407,13 @@ const getToken = async ({ params, options, }) => {
|
|
|
23405
23407
|
return data;
|
|
23406
23408
|
};
|
|
23407
23409
|
|
|
23410
|
+
function prepareUserPayload(response) {
|
|
23411
|
+
return {
|
|
23412
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
23413
|
+
files: response.files,
|
|
23414
|
+
};
|
|
23415
|
+
}
|
|
23416
|
+
|
|
23408
23417
|
/**
|
|
23409
23418
|
* A util to set or refresh client token
|
|
23410
23419
|
*
|
|
@@ -23421,7 +23430,7 @@ const setClientToken = async (params) => {
|
|
|
23421
23430
|
const client = getActiveClient();
|
|
23422
23431
|
// begin establishing session
|
|
23423
23432
|
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
23424
|
-
const { accessToken, users, expiresAt, issuedAt, userType } = await getToken(params);
|
|
23433
|
+
const { accessToken, users, expiresAt, issuedAt, userType, files } = await getToken(params);
|
|
23425
23434
|
// manually setup the token for http transport
|
|
23426
23435
|
client.http.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23427
23436
|
client.http.defaults.metadata = {
|
|
@@ -23437,6 +23446,10 @@ const setClientToken = async (params) => {
|
|
|
23437
23446
|
};
|
|
23438
23447
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
23439
23448
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23449
|
+
ingestInCache(prepareUserPayload({
|
|
23450
|
+
users,
|
|
23451
|
+
files,
|
|
23452
|
+
}));
|
|
23440
23453
|
return { accessToken, users, userType };
|
|
23441
23454
|
};
|
|
23442
23455
|
|
|
@@ -23499,13 +23512,6 @@ const setVisitorClientToken = async (params) => {
|
|
|
23499
23512
|
return { accessToken, users, userType };
|
|
23500
23513
|
};
|
|
23501
23514
|
|
|
23502
|
-
function prepareUserPayload(response) {
|
|
23503
|
-
return {
|
|
23504
|
-
users: response.users.map(convertRawUserToInternalUser),
|
|
23505
|
-
files: response.files,
|
|
23506
|
-
};
|
|
23507
|
-
}
|
|
23508
|
-
|
|
23509
23515
|
const createUserEventSubscriber = (event, callback) => {
|
|
23510
23516
|
const client = getActiveClient();
|
|
23511
23517
|
const filter = (data) => {
|
|
@@ -24974,7 +24980,6 @@ const setCurrentUserType = (userType) => {
|
|
|
24974
24980
|
const setCurrentUser = ({ user, userType, }) => {
|
|
24975
24981
|
setActiveUser(user);
|
|
24976
24982
|
setCurrentUserType(userType);
|
|
24977
|
-
pushToCache(['user', 'get', user.userId], user);
|
|
24978
24983
|
};
|
|
24979
24984
|
|
|
24980
24985
|
/* eslint-disable no-param-reassign */
|
|
@@ -28921,411 +28926,6 @@ const roomLinkedObject = (room) => {
|
|
|
28921
28926
|
} });
|
|
28922
28927
|
};
|
|
28923
28928
|
|
|
28924
|
-
const postLinkedObject = (post) => {
|
|
28925
|
-
return shallowClone(post, {
|
|
28926
|
-
childrenPosts: post.children
|
|
28927
|
-
.map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
28928
|
-
.filter(isNonNullable)
|
|
28929
|
-
.map(postLinkedObject),
|
|
28930
|
-
analytics: {
|
|
28931
|
-
markAsViewed: () => {
|
|
28932
|
-
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
28933
|
-
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
28934
|
-
},
|
|
28935
|
-
},
|
|
28936
|
-
get latestComments() {
|
|
28937
|
-
if (!post.comments)
|
|
28938
|
-
return [];
|
|
28939
|
-
return (post.comments
|
|
28940
|
-
.map(commentId => {
|
|
28941
|
-
var _a;
|
|
28942
|
-
const commentCached = (_a = pullFromCache([
|
|
28943
|
-
'comment',
|
|
28944
|
-
'get',
|
|
28945
|
-
commentId,
|
|
28946
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
28947
|
-
if (!commentCached)
|
|
28948
|
-
return null;
|
|
28949
|
-
return commentLinkedObject(commentCached);
|
|
28950
|
-
})
|
|
28951
|
-
.filter(Boolean) || []);
|
|
28952
|
-
},
|
|
28953
|
-
get creator() {
|
|
28954
|
-
const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
|
|
28955
|
-
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
28956
|
-
return;
|
|
28957
|
-
return userLinkedObject(cacheData.data);
|
|
28958
|
-
},
|
|
28959
|
-
getImageInfo() {
|
|
28960
|
-
var _a, _b;
|
|
28961
|
-
return isAmityImagePost(post)
|
|
28962
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28963
|
-
: undefined;
|
|
28964
|
-
},
|
|
28965
|
-
getVideoInfo() {
|
|
28966
|
-
var _a, _b, _c;
|
|
28967
|
-
return isAmityVideoPost(post)
|
|
28968
|
-
? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
|
|
28969
|
-
: undefined;
|
|
28970
|
-
},
|
|
28971
|
-
getVideoThumbnailInfo() {
|
|
28972
|
-
var _a, _b;
|
|
28973
|
-
return isAmityVideoPost(post)
|
|
28974
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28975
|
-
: undefined;
|
|
28976
|
-
},
|
|
28977
|
-
getFileInfo() {
|
|
28978
|
-
var _a, _b;
|
|
28979
|
-
return isAmityFilePost(post)
|
|
28980
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
28981
|
-
: undefined;
|
|
28982
|
-
},
|
|
28983
|
-
getLivestreamInfo() {
|
|
28984
|
-
var _a, _b;
|
|
28985
|
-
if (!isAmityLivestreamPost(post))
|
|
28986
|
-
return;
|
|
28987
|
-
const cache = (_b = pullFromCache([
|
|
28988
|
-
'stream',
|
|
28989
|
-
'get',
|
|
28990
|
-
(_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
|
|
28991
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
28992
|
-
if (!cache)
|
|
28993
|
-
return;
|
|
28994
|
-
return streamLinkedObject(cache);
|
|
28995
|
-
},
|
|
28996
|
-
getPollInfo() {
|
|
28997
|
-
var _a, _b;
|
|
28998
|
-
if (!isAmityPollPost(post))
|
|
28999
|
-
return;
|
|
29000
|
-
const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29001
|
-
if (!cache)
|
|
29002
|
-
return;
|
|
29003
|
-
return cache;
|
|
29004
|
-
},
|
|
29005
|
-
getClipInfo() {
|
|
29006
|
-
var _a, _b;
|
|
29007
|
-
return isAmityClipPost(post)
|
|
29008
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29009
|
-
: undefined;
|
|
29010
|
-
},
|
|
29011
|
-
getAudioInfo() {
|
|
29012
|
-
var _a, _b;
|
|
29013
|
-
return isAmityAudioPost(post)
|
|
29014
|
-
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29015
|
-
: undefined;
|
|
29016
|
-
},
|
|
29017
|
-
getRoomInfo() {
|
|
29018
|
-
var _a, _b;
|
|
29019
|
-
if (!isAmityRoomPost(post))
|
|
29020
|
-
return;
|
|
29021
|
-
const room = (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29022
|
-
return room ? roomLinkedObject(room) : undefined;
|
|
29023
|
-
},
|
|
29024
|
-
});
|
|
29025
|
-
};
|
|
29026
|
-
|
|
29027
|
-
/** @hidden */
|
|
29028
|
-
const dispatchReactable = (referenceType, model) => {
|
|
29029
|
-
if (referenceType === 'message')
|
|
29030
|
-
// @ts-ignore: refactor later
|
|
29031
|
-
fireEvent('local.message.updated', { messages: [model] });
|
|
29032
|
-
else if (referenceType === 'post')
|
|
29033
|
-
// @ts-ignore: refactor later
|
|
29034
|
-
fireEvent('post.updated', { posts: [model] });
|
|
29035
|
-
else if (referenceType === 'comment')
|
|
29036
|
-
// @ts-ignore: refactor later
|
|
29037
|
-
fireEvent('comment.updated', { comments: [model] });
|
|
29038
|
-
else if (referenceType === 'story')
|
|
29039
|
-
// Need to provide all data same StoryPayload from BE
|
|
29040
|
-
fireEvent('story.updated', {
|
|
29041
|
-
categories: [],
|
|
29042
|
-
comments: [],
|
|
29043
|
-
communities: [],
|
|
29044
|
-
communityUsers: [],
|
|
29045
|
-
files: [],
|
|
29046
|
-
users: [],
|
|
29047
|
-
stories: [model],
|
|
29048
|
-
});
|
|
29049
|
-
};
|
|
29050
|
-
|
|
29051
|
-
const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29052
|
-
var _a, _b, _c;
|
|
29053
|
-
const client = getActiveClient();
|
|
29054
|
-
client.log('reaction/createReaction', {
|
|
29055
|
-
referenceId,
|
|
29056
|
-
referenceType,
|
|
29057
|
-
reactionName,
|
|
29058
|
-
});
|
|
29059
|
-
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29060
|
-
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29061
|
-
const { data } = await client.http.post('/api/v2/reactions', {
|
|
29062
|
-
referenceId,
|
|
29063
|
-
referenceType,
|
|
29064
|
-
reactionName,
|
|
29065
|
-
referenceVersion,
|
|
29066
|
-
});
|
|
29067
|
-
if (client.cache) {
|
|
29068
|
-
const model = pullFromCache([
|
|
29069
|
-
referenceType,
|
|
29070
|
-
'get',
|
|
29071
|
-
referenceId,
|
|
29072
|
-
]);
|
|
29073
|
-
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29074
|
-
return true;
|
|
29075
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
|
|
29076
|
-
if (referenceType === 'comment') {
|
|
29077
|
-
fireEvent('local.comment.addReaction', {
|
|
29078
|
-
comment: updatedModel,
|
|
29079
|
-
reactor: {
|
|
29080
|
-
userId: client.userId,
|
|
29081
|
-
reactionName,
|
|
29082
|
-
reactionId: data.addedId,
|
|
29083
|
-
},
|
|
29084
|
-
});
|
|
29085
|
-
return true;
|
|
29086
|
-
}
|
|
29087
|
-
if (referenceType === 'post') {
|
|
29088
|
-
fireEvent('local.post.addReaction', {
|
|
29089
|
-
post: updatedModel,
|
|
29090
|
-
reactor: {
|
|
29091
|
-
userId: client.userId,
|
|
29092
|
-
reactionName,
|
|
29093
|
-
reactionId: data.addedId,
|
|
29094
|
-
},
|
|
29095
|
-
});
|
|
29096
|
-
return true;
|
|
29097
|
-
}
|
|
29098
|
-
if (referenceType === 'story') {
|
|
29099
|
-
fireEvent('local.story.reactionAdded', {
|
|
29100
|
-
story: updatedModel,
|
|
29101
|
-
reactor: {
|
|
29102
|
-
userId: client.userId,
|
|
29103
|
-
reactionName,
|
|
29104
|
-
reactionId: data.addedId,
|
|
29105
|
-
},
|
|
29106
|
-
});
|
|
29107
|
-
return true;
|
|
29108
|
-
}
|
|
29109
|
-
}
|
|
29110
|
-
return true;
|
|
29111
|
-
};
|
|
29112
|
-
addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
|
|
29113
|
-
var _a, _b, _c, _d, _e;
|
|
29114
|
-
const client = getActiveClient();
|
|
29115
|
-
client.log('reaction/createReaction.optimistically', {
|
|
29116
|
-
referenceId,
|
|
29117
|
-
referenceType,
|
|
29118
|
-
reactionName,
|
|
29119
|
-
});
|
|
29120
|
-
if (!client.cache)
|
|
29121
|
-
return;
|
|
29122
|
-
const model = pullFromCache([
|
|
29123
|
-
referenceType,
|
|
29124
|
-
'get',
|
|
29125
|
-
referenceId,
|
|
29126
|
-
]);
|
|
29127
|
-
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29128
|
-
return;
|
|
29129
|
-
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
29130
|
-
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
29131
|
-
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
29132
|
-
});
|
|
29133
|
-
dispatchReactable(referenceType, reaction);
|
|
29134
|
-
return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
|
|
29135
|
-
};
|
|
29136
|
-
|
|
29137
|
-
const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29138
|
-
var _a, _b;
|
|
29139
|
-
const client = getActiveClient();
|
|
29140
|
-
client.log('reaction/removeReaction', {
|
|
29141
|
-
referenceId,
|
|
29142
|
-
referenceType,
|
|
29143
|
-
reactionName,
|
|
29144
|
-
});
|
|
29145
|
-
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29146
|
-
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29147
|
-
const { data } = await client.http.delete(`/api/v2/reactions`, {
|
|
29148
|
-
data: {
|
|
29149
|
-
referenceId,
|
|
29150
|
-
referenceType,
|
|
29151
|
-
reactionName,
|
|
29152
|
-
referenceVersion,
|
|
29153
|
-
},
|
|
29154
|
-
});
|
|
29155
|
-
if (client.cache) {
|
|
29156
|
-
const model = pullFromCache([
|
|
29157
|
-
referenceType,
|
|
29158
|
-
'get',
|
|
29159
|
-
referenceId,
|
|
29160
|
-
]);
|
|
29161
|
-
if (!model)
|
|
29162
|
-
return true;
|
|
29163
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
|
|
29164
|
-
if (referenceType === 'comment') {
|
|
29165
|
-
fireEvent('local.comment.removeReaction', {
|
|
29166
|
-
comment: updatedModel,
|
|
29167
|
-
reactor: {
|
|
29168
|
-
reactionId: data.removedId,
|
|
29169
|
-
reactionName,
|
|
29170
|
-
userId: client.userId,
|
|
29171
|
-
},
|
|
29172
|
-
});
|
|
29173
|
-
return true;
|
|
29174
|
-
}
|
|
29175
|
-
if (referenceType === 'post') {
|
|
29176
|
-
fireEvent('local.post.removeReaction', {
|
|
29177
|
-
post: updatedModel,
|
|
29178
|
-
reactor: {
|
|
29179
|
-
reactionId: data.removedId,
|
|
29180
|
-
reactionName,
|
|
29181
|
-
userId: client.userId,
|
|
29182
|
-
},
|
|
29183
|
-
});
|
|
29184
|
-
return true;
|
|
29185
|
-
}
|
|
29186
|
-
if (referenceType === 'story') {
|
|
29187
|
-
fireEvent('local.story.reactionAdded', {
|
|
29188
|
-
story: updatedModel,
|
|
29189
|
-
reactor: {
|
|
29190
|
-
userId: client.userId,
|
|
29191
|
-
reactionName,
|
|
29192
|
-
reactionId: data.removedId,
|
|
29193
|
-
},
|
|
29194
|
-
});
|
|
29195
|
-
return true;
|
|
29196
|
-
}
|
|
29197
|
-
}
|
|
29198
|
-
return true;
|
|
29199
|
-
};
|
|
29200
|
-
|
|
29201
|
-
const addReactionToMessage = (reactionName, message) => {
|
|
29202
|
-
const isMessageV3 = message.publicId !== message.messageId;
|
|
29203
|
-
return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29204
|
-
};
|
|
29205
|
-
|
|
29206
|
-
const getCachedMarker = (message) => {
|
|
29207
|
-
var _a, _b;
|
|
29208
|
-
const key = {
|
|
29209
|
-
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
29210
|
-
feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
|
|
29211
|
-
contentId: message.messageId,
|
|
29212
|
-
};
|
|
29213
|
-
return (_b = pullFromCache([
|
|
29214
|
-
'messageMarker',
|
|
29215
|
-
'get',
|
|
29216
|
-
getResolver('messageMarker')(key),
|
|
29217
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29218
|
-
};
|
|
29219
|
-
const getMessageReadCount = (message, marker) => {
|
|
29220
|
-
var _a;
|
|
29221
|
-
// Look in the marker param first
|
|
29222
|
-
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
29223
|
-
// If the marker param is not set, look in the cache
|
|
29224
|
-
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
29225
|
-
}; // and if not found in cache use default value `0`
|
|
29226
|
-
|
|
29227
|
-
const removeReactionToMessage = (reactionName, message) => {
|
|
29228
|
-
const isMessageV3 = message.publicId !== message.messageId;
|
|
29229
|
-
return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29230
|
-
};
|
|
29231
|
-
|
|
29232
|
-
const messageLinkedObject = (message) => {
|
|
29233
|
-
const rest = __rest(message, ["creatorPrivateId"]);
|
|
29234
|
-
return Object.assign(Object.assign({}, rest), { get readCount() {
|
|
29235
|
-
return getMessageReadCount(message).readCount;
|
|
29236
|
-
},
|
|
29237
|
-
get deliveredCount() {
|
|
29238
|
-
return getMessageReadCount(message).deliveredCount;
|
|
29239
|
-
},
|
|
29240
|
-
get creator() {
|
|
29241
|
-
var _a;
|
|
29242
|
-
return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29243
|
-
}, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
|
|
29244
|
-
};
|
|
29245
|
-
|
|
29246
|
-
const reactorLinkedObject = (reactor) => {
|
|
29247
|
-
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
29248
|
-
var _a;
|
|
29249
|
-
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29250
|
-
if (!user)
|
|
29251
|
-
return undefined;
|
|
29252
|
-
return userLinkedObject(user);
|
|
29253
|
-
} });
|
|
29254
|
-
};
|
|
29255
|
-
|
|
29256
|
-
const adLinkedObject = (ad) => {
|
|
29257
|
-
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
29258
|
-
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
29259
|
-
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
29260
|
-
markAsSeen: (placement) => {
|
|
29261
|
-
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
29262
|
-
},
|
|
29263
|
-
markLinkAsClicked: (placement) => {
|
|
29264
|
-
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
29265
|
-
},
|
|
29266
|
-
}, get advertiser() {
|
|
29267
|
-
var _a, _b;
|
|
29268
|
-
const advertiserData = (_a = pullFromCache([
|
|
29269
|
-
'advertiser',
|
|
29270
|
-
'get',
|
|
29271
|
-
ad.advertiserId,
|
|
29272
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29273
|
-
if (!advertiserData)
|
|
29274
|
-
return;
|
|
29275
|
-
const avatarFile = (_b = pullFromCache([
|
|
29276
|
-
'file',
|
|
29277
|
-
'get',
|
|
29278
|
-
advertiserData.avatarFileId,
|
|
29279
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29280
|
-
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
29281
|
-
},
|
|
29282
|
-
get image1_1() {
|
|
29283
|
-
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
29284
|
-
if (!cacheData)
|
|
29285
|
-
return undefined;
|
|
29286
|
-
return cacheData.data || undefined;
|
|
29287
|
-
},
|
|
29288
|
-
get image9_16() {
|
|
29289
|
-
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
29290
|
-
if (!cacheData)
|
|
29291
|
-
return undefined;
|
|
29292
|
-
return cacheData.data || undefined;
|
|
29293
|
-
} });
|
|
29294
|
-
};
|
|
29295
|
-
|
|
29296
|
-
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
29297
|
-
var _a;
|
|
29298
|
-
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
29299
|
-
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
29300
|
-
var _a;
|
|
29301
|
-
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
29302
|
-
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
29303
|
-
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
29304
|
-
get post() {
|
|
29305
|
-
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
29306
|
-
return;
|
|
29307
|
-
return postLinkedObject(postCached.data);
|
|
29308
|
-
},
|
|
29309
|
-
get target() {
|
|
29310
|
-
const pinTarget = pullFromCache([
|
|
29311
|
-
'pinTarget',
|
|
29312
|
-
'get',
|
|
29313
|
-
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
29314
|
-
]);
|
|
29315
|
-
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
29316
|
-
return;
|
|
29317
|
-
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
29318
|
-
} });
|
|
29319
|
-
};
|
|
29320
|
-
|
|
29321
|
-
const notificationTrayLinkedObject = (noti) => {
|
|
29322
|
-
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
29323
|
-
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
29324
|
-
.filter(isNonNullable)
|
|
29325
|
-
.map(({ data }) => data)
|
|
29326
|
-
.map(user => userLinkedObject(user)) });
|
|
29327
|
-
};
|
|
29328
|
-
|
|
29329
28929
|
/*
|
|
29330
28930
|
* verifies membership status
|
|
29331
28931
|
*/
|
|
@@ -29902,6 +29502,17 @@ const communityLinkedObject = (community) => {
|
|
|
29902
29502
|
return undefined;
|
|
29903
29503
|
})
|
|
29904
29504
|
.filter(category => !!category);
|
|
29505
|
+
},
|
|
29506
|
+
get avatar() {
|
|
29507
|
+
var _a;
|
|
29508
|
+
if (!community.avatarFileId)
|
|
29509
|
+
return undefined;
|
|
29510
|
+
const avatar = (_a = pullFromCache([
|
|
29511
|
+
'file',
|
|
29512
|
+
'get',
|
|
29513
|
+
community.avatarFileId,
|
|
29514
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29515
|
+
return avatar;
|
|
29905
29516
|
}, createInvitations: async (userIds) => {
|
|
29906
29517
|
await createInvitations({
|
|
29907
29518
|
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
@@ -29925,6 +29536,946 @@ const communityLinkedObject = (community) => {
|
|
|
29925
29536
|
} });
|
|
29926
29537
|
};
|
|
29927
29538
|
|
|
29539
|
+
const postLinkedObject = (post) => {
|
|
29540
|
+
return shallowClone(post, {
|
|
29541
|
+
childrenPosts: post.children
|
|
29542
|
+
.map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
29543
|
+
.filter(isNonNullable)
|
|
29544
|
+
.map(postLinkedObject),
|
|
29545
|
+
analytics: {
|
|
29546
|
+
markAsViewed: () => {
|
|
29547
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
29548
|
+
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
29549
|
+
},
|
|
29550
|
+
},
|
|
29551
|
+
get latestComments() {
|
|
29552
|
+
if (!post.comments)
|
|
29553
|
+
return [];
|
|
29554
|
+
return (post.comments
|
|
29555
|
+
.map(commentId => {
|
|
29556
|
+
var _a;
|
|
29557
|
+
const commentCached = (_a = pullFromCache([
|
|
29558
|
+
'comment',
|
|
29559
|
+
'get',
|
|
29560
|
+
commentId,
|
|
29561
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29562
|
+
if (!commentCached)
|
|
29563
|
+
return null;
|
|
29564
|
+
return commentLinkedObject(commentCached);
|
|
29565
|
+
})
|
|
29566
|
+
.filter(Boolean) || []);
|
|
29567
|
+
},
|
|
29568
|
+
get creator() {
|
|
29569
|
+
const cacheData = pullFromCache(['user', 'get', post.postedUserId]);
|
|
29570
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29571
|
+
return;
|
|
29572
|
+
return userLinkedObject(cacheData.data);
|
|
29573
|
+
},
|
|
29574
|
+
get targetCommunity() {
|
|
29575
|
+
var _a;
|
|
29576
|
+
const communityCache = (_a = pullFromCache([
|
|
29577
|
+
'community',
|
|
29578
|
+
'get',
|
|
29579
|
+
post.targetId,
|
|
29580
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29581
|
+
if (!communityCache)
|
|
29582
|
+
return;
|
|
29583
|
+
return communityLinkedObject(communityCache);
|
|
29584
|
+
},
|
|
29585
|
+
getImageInfo() {
|
|
29586
|
+
var _a, _b;
|
|
29587
|
+
return isAmityImagePost(post)
|
|
29588
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29589
|
+
: undefined;
|
|
29590
|
+
},
|
|
29591
|
+
getVideoInfo() {
|
|
29592
|
+
var _a, _b, _c;
|
|
29593
|
+
return isAmityVideoPost(post)
|
|
29594
|
+
? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
|
|
29595
|
+
: undefined;
|
|
29596
|
+
},
|
|
29597
|
+
getVideoThumbnailInfo() {
|
|
29598
|
+
var _a, _b;
|
|
29599
|
+
return isAmityVideoPost(post)
|
|
29600
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29601
|
+
: undefined;
|
|
29602
|
+
},
|
|
29603
|
+
getFileInfo() {
|
|
29604
|
+
var _a, _b;
|
|
29605
|
+
return isAmityFilePost(post)
|
|
29606
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29607
|
+
: undefined;
|
|
29608
|
+
},
|
|
29609
|
+
getLivestreamInfo() {
|
|
29610
|
+
var _a, _b;
|
|
29611
|
+
if (!isAmityLivestreamPost(post))
|
|
29612
|
+
return;
|
|
29613
|
+
const cache = (_b = pullFromCache([
|
|
29614
|
+
'stream',
|
|
29615
|
+
'get',
|
|
29616
|
+
(_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.streamId,
|
|
29617
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29618
|
+
if (!cache)
|
|
29619
|
+
return;
|
|
29620
|
+
return streamLinkedObject(cache);
|
|
29621
|
+
},
|
|
29622
|
+
getPollInfo() {
|
|
29623
|
+
var _a, _b;
|
|
29624
|
+
if (!isAmityPollPost(post))
|
|
29625
|
+
return;
|
|
29626
|
+
const cache = (_b = pullFromCache(['poll', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.pollId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29627
|
+
if (!cache)
|
|
29628
|
+
return;
|
|
29629
|
+
return cache;
|
|
29630
|
+
},
|
|
29631
|
+
getClipInfo() {
|
|
29632
|
+
var _a, _b;
|
|
29633
|
+
return isAmityClipPost(post)
|
|
29634
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29635
|
+
: undefined;
|
|
29636
|
+
},
|
|
29637
|
+
getAudioInfo() {
|
|
29638
|
+
var _a, _b;
|
|
29639
|
+
return isAmityAudioPost(post)
|
|
29640
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
29641
|
+
: undefined;
|
|
29642
|
+
},
|
|
29643
|
+
getRoomInfo() {
|
|
29644
|
+
var _a, _b;
|
|
29645
|
+
if (!isAmityRoomPost(post))
|
|
29646
|
+
return;
|
|
29647
|
+
const room = (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29648
|
+
return room ? roomLinkedObject(room) : undefined;
|
|
29649
|
+
},
|
|
29650
|
+
});
|
|
29651
|
+
};
|
|
29652
|
+
|
|
29653
|
+
/** @hidden */
|
|
29654
|
+
const dispatchReactable = (referenceType, model) => {
|
|
29655
|
+
if (referenceType === 'message')
|
|
29656
|
+
// @ts-ignore: refactor later
|
|
29657
|
+
fireEvent('local.message.updated', { messages: [model] });
|
|
29658
|
+
else if (referenceType === 'post')
|
|
29659
|
+
// @ts-ignore: refactor later
|
|
29660
|
+
fireEvent('post.updated', { posts: [model] });
|
|
29661
|
+
else if (referenceType === 'comment')
|
|
29662
|
+
// @ts-ignore: refactor later
|
|
29663
|
+
fireEvent('comment.updated', { comments: [model] });
|
|
29664
|
+
else if (referenceType === 'story')
|
|
29665
|
+
// Need to provide all data same StoryPayload from BE
|
|
29666
|
+
fireEvent('story.updated', {
|
|
29667
|
+
categories: [],
|
|
29668
|
+
comments: [],
|
|
29669
|
+
communities: [],
|
|
29670
|
+
communityUsers: [],
|
|
29671
|
+
files: [],
|
|
29672
|
+
users: [],
|
|
29673
|
+
stories: [model],
|
|
29674
|
+
});
|
|
29675
|
+
};
|
|
29676
|
+
|
|
29677
|
+
const addReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29678
|
+
var _a, _b, _c;
|
|
29679
|
+
const client = getActiveClient();
|
|
29680
|
+
client.log('reaction/createReaction', {
|
|
29681
|
+
referenceId,
|
|
29682
|
+
referenceType,
|
|
29683
|
+
reactionName,
|
|
29684
|
+
});
|
|
29685
|
+
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29686
|
+
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29687
|
+
const { data } = await client.http.post('/api/v2/reactions', {
|
|
29688
|
+
referenceId,
|
|
29689
|
+
referenceType,
|
|
29690
|
+
reactionName,
|
|
29691
|
+
referenceVersion,
|
|
29692
|
+
});
|
|
29693
|
+
if (client.cache) {
|
|
29694
|
+
const model = pullFromCache([
|
|
29695
|
+
referenceType,
|
|
29696
|
+
'get',
|
|
29697
|
+
referenceId,
|
|
29698
|
+
]);
|
|
29699
|
+
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29700
|
+
return true;
|
|
29701
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
|
|
29702
|
+
if (referenceType === 'comment') {
|
|
29703
|
+
fireEvent('local.comment.addReaction', {
|
|
29704
|
+
comment: updatedModel,
|
|
29705
|
+
reactor: {
|
|
29706
|
+
userId: client.userId,
|
|
29707
|
+
reactionName,
|
|
29708
|
+
reactionId: data.addedId,
|
|
29709
|
+
},
|
|
29710
|
+
});
|
|
29711
|
+
return true;
|
|
29712
|
+
}
|
|
29713
|
+
if (referenceType === 'post') {
|
|
29714
|
+
fireEvent('local.post.addReaction', {
|
|
29715
|
+
post: updatedModel,
|
|
29716
|
+
reactor: {
|
|
29717
|
+
userId: client.userId,
|
|
29718
|
+
reactionName,
|
|
29719
|
+
reactionId: data.addedId,
|
|
29720
|
+
},
|
|
29721
|
+
});
|
|
29722
|
+
return true;
|
|
29723
|
+
}
|
|
29724
|
+
if (referenceType === 'story') {
|
|
29725
|
+
fireEvent('local.story.reactionAdded', {
|
|
29726
|
+
story: updatedModel,
|
|
29727
|
+
reactor: {
|
|
29728
|
+
userId: client.userId,
|
|
29729
|
+
reactionName,
|
|
29730
|
+
reactionId: data.addedId,
|
|
29731
|
+
},
|
|
29732
|
+
});
|
|
29733
|
+
return true;
|
|
29734
|
+
}
|
|
29735
|
+
}
|
|
29736
|
+
return true;
|
|
29737
|
+
};
|
|
29738
|
+
addReaction$1.optimistically = (referenceType, referenceId, reactionName) => {
|
|
29739
|
+
var _a, _b, _c, _d, _e;
|
|
29740
|
+
const client = getActiveClient();
|
|
29741
|
+
client.log('reaction/createReaction.optimistically', {
|
|
29742
|
+
referenceId,
|
|
29743
|
+
referenceType,
|
|
29744
|
+
reactionName,
|
|
29745
|
+
});
|
|
29746
|
+
if (!client.cache)
|
|
29747
|
+
return;
|
|
29748
|
+
const model = pullFromCache([
|
|
29749
|
+
referenceType,
|
|
29750
|
+
'get',
|
|
29751
|
+
referenceId,
|
|
29752
|
+
]);
|
|
29753
|
+
if (!(model === null || model === void 0 ? void 0 : model.data) || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
29754
|
+
return;
|
|
29755
|
+
const reaction = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
29756
|
+
upsertInCache([referenceType, 'get', referenceId], reaction, {
|
|
29757
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
29758
|
+
});
|
|
29759
|
+
dispatchReactable(referenceType, reaction);
|
|
29760
|
+
return (_e = (_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName)) !== null && _e !== void 0 ? _e : false;
|
|
29761
|
+
};
|
|
29762
|
+
|
|
29763
|
+
const removeReaction$1 = async (referenceType, referenceId, reactionName, referenceVersion) => {
|
|
29764
|
+
var _a, _b;
|
|
29765
|
+
const client = getActiveClient();
|
|
29766
|
+
client.log('reaction/removeReaction', {
|
|
29767
|
+
referenceId,
|
|
29768
|
+
referenceType,
|
|
29769
|
+
reactionName,
|
|
29770
|
+
});
|
|
29771
|
+
if (!['post', 'comment', 'story', 'message'].includes(referenceType))
|
|
29772
|
+
throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29773
|
+
const { data } = await client.http.delete(`/api/v2/reactions`, {
|
|
29774
|
+
data: {
|
|
29775
|
+
referenceId,
|
|
29776
|
+
referenceType,
|
|
29777
|
+
reactionName,
|
|
29778
|
+
referenceVersion,
|
|
29779
|
+
},
|
|
29780
|
+
});
|
|
29781
|
+
if (client.cache) {
|
|
29782
|
+
const model = pullFromCache([
|
|
29783
|
+
referenceType,
|
|
29784
|
+
'get',
|
|
29785
|
+
referenceId,
|
|
29786
|
+
]);
|
|
29787
|
+
if (!model)
|
|
29788
|
+
return true;
|
|
29789
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
|
|
29790
|
+
if (referenceType === 'comment') {
|
|
29791
|
+
fireEvent('local.comment.removeReaction', {
|
|
29792
|
+
comment: updatedModel,
|
|
29793
|
+
reactor: {
|
|
29794
|
+
reactionId: data.removedId,
|
|
29795
|
+
reactionName,
|
|
29796
|
+
userId: client.userId,
|
|
29797
|
+
},
|
|
29798
|
+
});
|
|
29799
|
+
return true;
|
|
29800
|
+
}
|
|
29801
|
+
if (referenceType === 'post') {
|
|
29802
|
+
fireEvent('local.post.removeReaction', {
|
|
29803
|
+
post: updatedModel,
|
|
29804
|
+
reactor: {
|
|
29805
|
+
reactionId: data.removedId,
|
|
29806
|
+
reactionName,
|
|
29807
|
+
userId: client.userId,
|
|
29808
|
+
},
|
|
29809
|
+
});
|
|
29810
|
+
return true;
|
|
29811
|
+
}
|
|
29812
|
+
if (referenceType === 'story') {
|
|
29813
|
+
fireEvent('local.story.reactionAdded', {
|
|
29814
|
+
story: updatedModel,
|
|
29815
|
+
reactor: {
|
|
29816
|
+
userId: client.userId,
|
|
29817
|
+
reactionName,
|
|
29818
|
+
reactionId: data.removedId,
|
|
29819
|
+
},
|
|
29820
|
+
});
|
|
29821
|
+
return true;
|
|
29822
|
+
}
|
|
29823
|
+
}
|
|
29824
|
+
return true;
|
|
29825
|
+
};
|
|
29826
|
+
|
|
29827
|
+
const addReactionToMessage = (reactionName, message) => {
|
|
29828
|
+
const isMessageV3 = message.publicId !== message.messageId;
|
|
29829
|
+
return addReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29830
|
+
};
|
|
29831
|
+
|
|
29832
|
+
const getCachedMarker = (message) => {
|
|
29833
|
+
var _a, _b;
|
|
29834
|
+
const key = {
|
|
29835
|
+
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
29836
|
+
feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
|
|
29837
|
+
contentId: message.messageId,
|
|
29838
|
+
};
|
|
29839
|
+
return (_b = pullFromCache([
|
|
29840
|
+
'messageMarker',
|
|
29841
|
+
'get',
|
|
29842
|
+
getResolver('messageMarker')(key),
|
|
29843
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29844
|
+
};
|
|
29845
|
+
const getMessageReadCount = (message, marker) => {
|
|
29846
|
+
var _a;
|
|
29847
|
+
// Look in the marker param first
|
|
29848
|
+
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
29849
|
+
// If the marker param is not set, look in the cache
|
|
29850
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
29851
|
+
}; // and if not found in cache use default value `0`
|
|
29852
|
+
|
|
29853
|
+
const removeReactionToMessage = (reactionName, message) => {
|
|
29854
|
+
const isMessageV3 = message.publicId !== message.messageId;
|
|
29855
|
+
return removeReaction$1('message', isMessageV3 ? message.publicId : message.messageId, reactionName, isMessageV3 ? 3 : 5);
|
|
29856
|
+
};
|
|
29857
|
+
|
|
29858
|
+
const messageLinkedObject = (message) => {
|
|
29859
|
+
const rest = __rest(message, ["creatorPrivateId"]);
|
|
29860
|
+
return Object.assign(Object.assign({}, rest), { get readCount() {
|
|
29861
|
+
return getMessageReadCount(message).readCount;
|
|
29862
|
+
},
|
|
29863
|
+
get deliveredCount() {
|
|
29864
|
+
return getMessageReadCount(message).deliveredCount;
|
|
29865
|
+
},
|
|
29866
|
+
get creator() {
|
|
29867
|
+
var _a;
|
|
29868
|
+
return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29869
|
+
}, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
|
|
29870
|
+
};
|
|
29871
|
+
|
|
29872
|
+
const reactorLinkedObject = (reactor) => {
|
|
29873
|
+
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
29874
|
+
var _a;
|
|
29875
|
+
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29876
|
+
if (!user)
|
|
29877
|
+
return undefined;
|
|
29878
|
+
return userLinkedObject(user);
|
|
29879
|
+
} });
|
|
29880
|
+
};
|
|
29881
|
+
|
|
29882
|
+
const adLinkedObject = (ad) => {
|
|
29883
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
29884
|
+
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
29885
|
+
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
29886
|
+
markAsSeen: (placement) => {
|
|
29887
|
+
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
29888
|
+
},
|
|
29889
|
+
markLinkAsClicked: (placement) => {
|
|
29890
|
+
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
29891
|
+
},
|
|
29892
|
+
}, get advertiser() {
|
|
29893
|
+
var _a, _b;
|
|
29894
|
+
const advertiserData = (_a = pullFromCache([
|
|
29895
|
+
'advertiser',
|
|
29896
|
+
'get',
|
|
29897
|
+
ad.advertiserId,
|
|
29898
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29899
|
+
if (!advertiserData)
|
|
29900
|
+
return;
|
|
29901
|
+
const avatarFile = (_b = pullFromCache([
|
|
29902
|
+
'file',
|
|
29903
|
+
'get',
|
|
29904
|
+
advertiserData.avatarFileId,
|
|
29905
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
29906
|
+
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
29907
|
+
},
|
|
29908
|
+
get image1_1() {
|
|
29909
|
+
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
29910
|
+
if (!cacheData)
|
|
29911
|
+
return undefined;
|
|
29912
|
+
return cacheData.data || undefined;
|
|
29913
|
+
},
|
|
29914
|
+
get image9_16() {
|
|
29915
|
+
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
29916
|
+
if (!cacheData)
|
|
29917
|
+
return undefined;
|
|
29918
|
+
return cacheData.data || undefined;
|
|
29919
|
+
} });
|
|
29920
|
+
};
|
|
29921
|
+
|
|
29922
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
29923
|
+
var _a;
|
|
29924
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
29925
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
29926
|
+
var _a;
|
|
29927
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
29928
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
29929
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
29930
|
+
get post() {
|
|
29931
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
29932
|
+
return;
|
|
29933
|
+
return postLinkedObject(postCached.data);
|
|
29934
|
+
},
|
|
29935
|
+
get target() {
|
|
29936
|
+
const pinTarget = pullFromCache([
|
|
29937
|
+
'pinTarget',
|
|
29938
|
+
'get',
|
|
29939
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
29940
|
+
]);
|
|
29941
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
29942
|
+
return;
|
|
29943
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
29944
|
+
} });
|
|
29945
|
+
};
|
|
29946
|
+
|
|
29947
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
29948
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
29949
|
+
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
29950
|
+
.filter(isNonNullable)
|
|
29951
|
+
.map(({ data }) => data)
|
|
29952
|
+
.map(user => userLinkedObject(user)), get event() {
|
|
29953
|
+
const cacheData = pullFromCache(['event', 'get', noti.actionReferenceId]);
|
|
29954
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29955
|
+
return;
|
|
29956
|
+
return cacheData.data;
|
|
29957
|
+
} });
|
|
29958
|
+
};
|
|
29959
|
+
|
|
29960
|
+
const prepareEventResponsePayload = (rawPayload) => {
|
|
29961
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
29962
|
+
};
|
|
29963
|
+
|
|
29964
|
+
const eventResponseLinkedObject = (event) => {
|
|
29965
|
+
return Object.assign(Object.assign({}, event), { get status() {
|
|
29966
|
+
return event.status;
|
|
29967
|
+
},
|
|
29968
|
+
get userId() {
|
|
29969
|
+
return event.userId;
|
|
29970
|
+
},
|
|
29971
|
+
get eventId() {
|
|
29972
|
+
return event.eventId;
|
|
29973
|
+
},
|
|
29974
|
+
get respondedAt() {
|
|
29975
|
+
return event.respondedAt;
|
|
29976
|
+
},
|
|
29977
|
+
get event() {
|
|
29978
|
+
const cacheData = pullFromCache(['event', 'get', event.eventId]);
|
|
29979
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29980
|
+
return;
|
|
29981
|
+
return cacheData.data;
|
|
29982
|
+
},
|
|
29983
|
+
get user() {
|
|
29984
|
+
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
29985
|
+
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
|
|
29986
|
+
return;
|
|
29987
|
+
return userLinkedObject(cacheData.data);
|
|
29988
|
+
} });
|
|
29989
|
+
};
|
|
29990
|
+
|
|
29991
|
+
/* begin_public_function
|
|
29992
|
+
id: event.rsvp.create
|
|
29993
|
+
*/
|
|
29994
|
+
/**
|
|
29995
|
+
* ```js
|
|
29996
|
+
* import { event } from '@amityco/ts-sdk'
|
|
29997
|
+
* const response = await event.createRSVP(eventId, status)
|
|
29998
|
+
* ```
|
|
29999
|
+
*
|
|
30000
|
+
* Creates an {@link Amity.EventResponse} for the active user for a specific event.
|
|
30001
|
+
*
|
|
30002
|
+
* @param eventId The ID of the {@link Amity.EventResponse} to create an RSVP for
|
|
30003
|
+
* @param status The RSVP status to set for the event
|
|
30004
|
+
* @returns The {@link Amity.EventResponse} with updated RSVP information
|
|
30005
|
+
*
|
|
30006
|
+
* @category Event API
|
|
30007
|
+
* @async
|
|
30008
|
+
*/
|
|
30009
|
+
const createRSVP = async (eventId, status) => {
|
|
30010
|
+
const client = getActiveClient();
|
|
30011
|
+
client.log('event/createRSVP', eventId, status);
|
|
30012
|
+
const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
30013
|
+
fireEvent('local.rsvp.created', payload);
|
|
30014
|
+
const data = prepareEventResponsePayload(payload);
|
|
30015
|
+
const cachedAt = client.cache && Date.now();
|
|
30016
|
+
if (client.cache)
|
|
30017
|
+
ingestInCache(data, { cachedAt });
|
|
30018
|
+
return {
|
|
30019
|
+
data: eventResponseLinkedObject(data.eventResponses[0]),
|
|
30020
|
+
cachedAt,
|
|
30021
|
+
};
|
|
30022
|
+
};
|
|
30023
|
+
/* end_public_function */
|
|
30024
|
+
|
|
30025
|
+
/* begin_public_function
|
|
30026
|
+
id: event.update
|
|
30027
|
+
*/
|
|
30028
|
+
/**
|
|
30029
|
+
* ```js
|
|
30030
|
+
* import { event } from '@amityco/ts-sdk'
|
|
30031
|
+
* const response = await event.updateRSVP(eventId, status)
|
|
30032
|
+
* ```
|
|
30033
|
+
*
|
|
30034
|
+
* Updates an {@link Amity.EventResponse}
|
|
30035
|
+
*
|
|
30036
|
+
* @param eventId The ID of the {@link Amity.EventResponse} to edit
|
|
30037
|
+
* @param bundle The data necessary to update an existing {@link Amity.EventResponse}
|
|
30038
|
+
* @returns the updated {@link Amity.EventResponse}
|
|
30039
|
+
*
|
|
30040
|
+
* @category Event API
|
|
30041
|
+
* @async
|
|
30042
|
+
*/
|
|
30043
|
+
const updateRSVP = async (eventId, status) => {
|
|
30044
|
+
const client = getActiveClient();
|
|
30045
|
+
client.log('event/updateRSVP', eventId, status);
|
|
30046
|
+
const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
|
|
30047
|
+
fireEvent('local.rsvp.updated', payload);
|
|
30048
|
+
const data = prepareEventResponsePayload(payload);
|
|
30049
|
+
const cachedAt = client.cache && Date.now();
|
|
30050
|
+
if (client.cache)
|
|
30051
|
+
ingestInCache(data, { cachedAt });
|
|
30052
|
+
return {
|
|
30053
|
+
data: eventResponseLinkedObject(data.eventResponses[0]),
|
|
30054
|
+
cachedAt,
|
|
30055
|
+
};
|
|
30056
|
+
};
|
|
30057
|
+
/* end_public_function */
|
|
30058
|
+
|
|
30059
|
+
const prepareEventPayload = (rawPayload) => {
|
|
30060
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
30061
|
+
};
|
|
30062
|
+
|
|
30063
|
+
const createEventEventSubscriber = (event, callback) => {
|
|
30064
|
+
const client = getActiveClient();
|
|
30065
|
+
const filter = (payload) => {
|
|
30066
|
+
const unpackedPayload = prepareEventPayload(payload);
|
|
30067
|
+
if (!client.cache) {
|
|
30068
|
+
callback(unpackedPayload.events[0]);
|
|
30069
|
+
}
|
|
30070
|
+
else {
|
|
30071
|
+
ingestInCache(unpackedPayload);
|
|
30072
|
+
const event = pullFromCache([
|
|
30073
|
+
'event',
|
|
30074
|
+
'get',
|
|
30075
|
+
unpackedPayload.events[0].eventId,
|
|
30076
|
+
]);
|
|
30077
|
+
callback(event.data);
|
|
30078
|
+
}
|
|
30079
|
+
};
|
|
30080
|
+
return createEventSubscriber(client, event, event, filter);
|
|
30081
|
+
};
|
|
30082
|
+
|
|
30083
|
+
const createEventResponseSubscriber = (event, callback) => {
|
|
30084
|
+
const client = getActiveClient();
|
|
30085
|
+
const filter = (payload) => {
|
|
30086
|
+
const unpackedPayload = prepareEventResponsePayload(payload);
|
|
30087
|
+
if (!client.cache) {
|
|
30088
|
+
callback(unpackedPayload);
|
|
30089
|
+
}
|
|
30090
|
+
else {
|
|
30091
|
+
ingestInCache(unpackedPayload.event[0]);
|
|
30092
|
+
const eventResponse = pullFromCache([
|
|
30093
|
+
'eventResponse',
|
|
30094
|
+
'get',
|
|
30095
|
+
payload.eventResponses[0].eventId,
|
|
30096
|
+
]);
|
|
30097
|
+
callback(eventResponse.data);
|
|
30098
|
+
}
|
|
30099
|
+
};
|
|
30100
|
+
return createEventSubscriber(client, event, event, filter);
|
|
30101
|
+
};
|
|
30102
|
+
|
|
30103
|
+
/* begin_public_function
|
|
30104
|
+
id: event.rsvp.me
|
|
30105
|
+
*/
|
|
30106
|
+
/**
|
|
30107
|
+
* ```js
|
|
30108
|
+
* import { event } from '@amityco/ts-sdk'
|
|
30109
|
+
* const myRSVP = await event.getMyRSVP()
|
|
30110
|
+
* ```
|
|
30111
|
+
*
|
|
30112
|
+
* Joins a {@link Amity.EventResponse} object
|
|
30113
|
+
*
|
|
30114
|
+
* @param eventId the {@link Amity.EventResponse} to get RSVP for
|
|
30115
|
+
* @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
|
|
30116
|
+
*
|
|
30117
|
+
* @category Event API
|
|
30118
|
+
* @async
|
|
30119
|
+
*/
|
|
30120
|
+
const getMyRSVP = async (eventId) => {
|
|
30121
|
+
const client = getActiveClient();
|
|
30122
|
+
client.log('event/getMyRSVP', eventId);
|
|
30123
|
+
const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
|
|
30124
|
+
const data = prepareEventResponsePayload(payload);
|
|
30125
|
+
const cachedAt = client.cache && Date.now();
|
|
30126
|
+
if (client.cache)
|
|
30127
|
+
ingestInCache(data, { cachedAt });
|
|
30128
|
+
return {
|
|
30129
|
+
data: eventResponseLinkedObject(data.eventResponses[0]),
|
|
30130
|
+
cachedAt,
|
|
30131
|
+
};
|
|
30132
|
+
};
|
|
30133
|
+
/* end_public_function */
|
|
30134
|
+
/**
|
|
30135
|
+
* ```js
|
|
30136
|
+
* import { event } from '@amityco/ts-sdk'
|
|
30137
|
+
* const event = event.getMyRSVP.locally(eventId)
|
|
30138
|
+
* ```
|
|
30139
|
+
*
|
|
30140
|
+
* Fetches a {@link Amity.EventResponse} object in cache
|
|
30141
|
+
*
|
|
30142
|
+
* @param eventId the ID of the {@link Amity.EventResponse} to fetch
|
|
30143
|
+
* @returns the associated {@link Amity.EventResponse} object
|
|
30144
|
+
*
|
|
30145
|
+
* @category Event API
|
|
30146
|
+
*/
|
|
30147
|
+
getMyRSVP.locally = (eventId) => {
|
|
30148
|
+
const client = getActiveClient();
|
|
30149
|
+
client.log('event/getMyRSVP.locally', eventId);
|
|
30150
|
+
if (!client.cache)
|
|
30151
|
+
return;
|
|
30152
|
+
const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
|
|
30153
|
+
if (!cache)
|
|
30154
|
+
return;
|
|
30155
|
+
return {
|
|
30156
|
+
data: cache.data,
|
|
30157
|
+
cachedAt: cache.cachedAt,
|
|
30158
|
+
};
|
|
30159
|
+
};
|
|
30160
|
+
|
|
30161
|
+
var EventActionsEnum;
|
|
30162
|
+
(function (EventActionsEnum) {
|
|
30163
|
+
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
30164
|
+
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
30165
|
+
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
30166
|
+
EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
|
|
30167
|
+
EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
|
|
30168
|
+
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
30169
|
+
|
|
30170
|
+
class RSVPPaginationController extends PaginationController {
|
|
30171
|
+
async getRequest(queryParams, token) {
|
|
30172
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
|
|
30173
|
+
const options = token ? { token } : { limit };
|
|
30174
|
+
const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
30175
|
+
return response;
|
|
30176
|
+
}
|
|
30177
|
+
}
|
|
30178
|
+
|
|
30179
|
+
class RSVPQueryStreamController extends QueryStreamController {
|
|
30180
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30181
|
+
super(query, cacheKey);
|
|
30182
|
+
this.notifyChange = notifyChange;
|
|
30183
|
+
this.preparePayload = preparePayload;
|
|
30184
|
+
}
|
|
30185
|
+
async saveToMainDB(response) {
|
|
30186
|
+
const processedPayload = this.preparePayload(response);
|
|
30187
|
+
const client = getActiveClient();
|
|
30188
|
+
const cachedAt = client.cache && Date.now();
|
|
30189
|
+
if (client.cache)
|
|
30190
|
+
ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
|
|
30191
|
+
}
|
|
30192
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
30193
|
+
var _a, _b;
|
|
30194
|
+
if (refresh) {
|
|
30195
|
+
pushToCache(this.cacheKey, {
|
|
30196
|
+
data: response.eventResponses.map(getResolver('eventResponse')),
|
|
30197
|
+
});
|
|
30198
|
+
}
|
|
30199
|
+
else {
|
|
30200
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30201
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30202
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
30203
|
+
...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
|
|
30204
|
+
] }));
|
|
30205
|
+
}
|
|
30206
|
+
}
|
|
30207
|
+
reactor(action) {
|
|
30208
|
+
return (event) => {
|
|
30209
|
+
var _a;
|
|
30210
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30211
|
+
if (!collection)
|
|
30212
|
+
return;
|
|
30213
|
+
if (action === EventActionsEnum.OnRSVPCreated) {
|
|
30214
|
+
const client = getActiveClient();
|
|
30215
|
+
if (client.userId !== event.userId)
|
|
30216
|
+
return;
|
|
30217
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
30218
|
+
}
|
|
30219
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
30220
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
30221
|
+
}
|
|
30222
|
+
pushToCache(this.cacheKey, collection);
|
|
30223
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30224
|
+
};
|
|
30225
|
+
}
|
|
30226
|
+
subscribeRTE(createSubscriber) {
|
|
30227
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30228
|
+
}
|
|
30229
|
+
}
|
|
30230
|
+
|
|
30231
|
+
/**
|
|
30232
|
+
* ```js
|
|
30233
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30234
|
+
* const dispose = EventRepository.onEventCreated(event => {
|
|
30235
|
+
* // ...
|
|
30236
|
+
* })
|
|
30237
|
+
* ```
|
|
30238
|
+
*
|
|
30239
|
+
* Fired when an RSVP response for a {@link Amity.Event} has been created
|
|
30240
|
+
*
|
|
30241
|
+
* @param callback The function to call when the event was fired
|
|
30242
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30243
|
+
*
|
|
30244
|
+
* @category Event Events
|
|
30245
|
+
*/
|
|
30246
|
+
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
30247
|
+
|
|
30248
|
+
/**
|
|
30249
|
+
* ```js
|
|
30250
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30251
|
+
* const dispose = EventRepository.onEventUpdated(event => {
|
|
30252
|
+
* // ...
|
|
30253
|
+
* })
|
|
30254
|
+
* ```
|
|
30255
|
+
*
|
|
30256
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30257
|
+
*
|
|
30258
|
+
* @param callback The function to call when the event was fired
|
|
30259
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30260
|
+
*
|
|
30261
|
+
* @category Event Events
|
|
30262
|
+
*/
|
|
30263
|
+
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
30264
|
+
|
|
30265
|
+
/**
|
|
30266
|
+
* ```js
|
|
30267
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30268
|
+
* const dispose = EventRepository.onEventDeleted(event => {
|
|
30269
|
+
* // ...
|
|
30270
|
+
* })
|
|
30271
|
+
* ```
|
|
30272
|
+
*
|
|
30273
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30274
|
+
*
|
|
30275
|
+
* @param callback The function to call when the event was fired
|
|
30276
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30277
|
+
*
|
|
30278
|
+
* @category Event Events
|
|
30279
|
+
*/
|
|
30280
|
+
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
30281
|
+
|
|
30282
|
+
/**
|
|
30283
|
+
* ```js
|
|
30284
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30285
|
+
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
30286
|
+
* // ...
|
|
30287
|
+
* })
|
|
30288
|
+
* ```
|
|
30289
|
+
*
|
|
30290
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30291
|
+
*
|
|
30292
|
+
* @param callback The function to call when the event was fired
|
|
30293
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30294
|
+
*
|
|
30295
|
+
* @category Event Events
|
|
30296
|
+
*/
|
|
30297
|
+
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
30298
|
+
|
|
30299
|
+
/**
|
|
30300
|
+
* ```js
|
|
30301
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30302
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30303
|
+
* // ...
|
|
30304
|
+
* })
|
|
30305
|
+
* ```
|
|
30306
|
+
*
|
|
30307
|
+
* Fired when a {@link Amity.Event} has been updated
|
|
30308
|
+
*
|
|
30309
|
+
* @param callback The function to call when the event was fired
|
|
30310
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30311
|
+
*
|
|
30312
|
+
* @category Event Events
|
|
30313
|
+
*/
|
|
30314
|
+
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
30315
|
+
|
|
30316
|
+
/**
|
|
30317
|
+
* ```js
|
|
30318
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30319
|
+
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
30320
|
+
* // ...
|
|
30321
|
+
* })
|
|
30322
|
+
* ```
|
|
30323
|
+
*
|
|
30324
|
+
* Fired when a {@link Amity.Event} has been deleted
|
|
30325
|
+
*
|
|
30326
|
+
* @param callback The function to call when the event was fired
|
|
30327
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30328
|
+
*
|
|
30329
|
+
* @category Event Events
|
|
30330
|
+
*/
|
|
30331
|
+
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
30332
|
+
|
|
30333
|
+
/**
|
|
30334
|
+
* ```js
|
|
30335
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30336
|
+
* const dispose = EventRepository.onRSVPCreated(event => {
|
|
30337
|
+
* // ...
|
|
30338
|
+
* })
|
|
30339
|
+
* ```
|
|
30340
|
+
*
|
|
30341
|
+
* Fired when a {@link Amity.Event} has been created
|
|
30342
|
+
*
|
|
30343
|
+
* @param callback The function to call when the event was fired
|
|
30344
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30345
|
+
*
|
|
30346
|
+
* @category Event Events
|
|
30347
|
+
*/
|
|
30348
|
+
const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
|
|
30349
|
+
|
|
30350
|
+
/**
|
|
30351
|
+
* ```js
|
|
30352
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30353
|
+
* const dispose = EventRepository.onRSVPUpdated(event => {
|
|
30354
|
+
* // ...
|
|
30355
|
+
* })
|
|
30356
|
+
* ```
|
|
30357
|
+
*
|
|
30358
|
+
* Fired when a {@link Amity.InternalEventResponse} has been updated
|
|
30359
|
+
*
|
|
30360
|
+
* @param callback The function to call when the event was fired
|
|
30361
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30362
|
+
*
|
|
30363
|
+
* @category Event Events
|
|
30364
|
+
*/
|
|
30365
|
+
const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
|
|
30366
|
+
|
|
30367
|
+
/**
|
|
30368
|
+
* ```js
|
|
30369
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30370
|
+
* const dispose = EventRepository.onLocalRSVPCreated(event => {
|
|
30371
|
+
* // ...
|
|
30372
|
+
* })
|
|
30373
|
+
* ```
|
|
30374
|
+
*
|
|
30375
|
+
* Fired when an RSVP response for a {@link Amity.EventResponse} has been created
|
|
30376
|
+
*
|
|
30377
|
+
* @param callback The function to call when the event was fired
|
|
30378
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30379
|
+
*
|
|
30380
|
+
* @category Event Events
|
|
30381
|
+
*/
|
|
30382
|
+
const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
|
|
30383
|
+
|
|
30384
|
+
/**
|
|
30385
|
+
* ```js
|
|
30386
|
+
* import { EventRepository } from '@amityco/ts-sdk'
|
|
30387
|
+
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
30388
|
+
* // ...
|
|
30389
|
+
* })
|
|
30390
|
+
* ```
|
|
30391
|
+
*
|
|
30392
|
+
* Fired when an RSVP response for a {@link Amity.EventResponse} has been updated
|
|
30393
|
+
*
|
|
30394
|
+
* @param callback The function to call when the event was fired
|
|
30395
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
30396
|
+
*
|
|
30397
|
+
* @category Event Events
|
|
30398
|
+
*/
|
|
30399
|
+
const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
|
|
30400
|
+
|
|
30401
|
+
class RSVPLiveCollectionController extends LiveCollectionController {
|
|
30402
|
+
constructor(query, callback) {
|
|
30403
|
+
const queryStreamId = hash(query);
|
|
30404
|
+
const cacheKey = ['eventResponse', 'collection', queryStreamId];
|
|
30405
|
+
const paginationController = new RSVPPaginationController(query);
|
|
30406
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
30407
|
+
this.query = query;
|
|
30408
|
+
this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
|
|
30409
|
+
this.callback = callback.bind(this);
|
|
30410
|
+
this.loadPage({ initial: true });
|
|
30411
|
+
}
|
|
30412
|
+
setup() {
|
|
30413
|
+
var _a;
|
|
30414
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30415
|
+
if (!collection)
|
|
30416
|
+
pushToCache(this.cacheKey, { data: [], params: this.query });
|
|
30417
|
+
}
|
|
30418
|
+
async persistModel(queryPayload) {
|
|
30419
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
30420
|
+
}
|
|
30421
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30422
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30423
|
+
}
|
|
30424
|
+
startSubscription() {
|
|
30425
|
+
return this.queryStreamController.subscribeRTE([
|
|
30426
|
+
{ fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
30427
|
+
{ fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
30428
|
+
{ fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
|
|
30429
|
+
{ fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
|
|
30430
|
+
]);
|
|
30431
|
+
}
|
|
30432
|
+
notifyChange({ origin, loading, error }) {
|
|
30433
|
+
var _a, _b;
|
|
30434
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30435
|
+
if (!collection)
|
|
30436
|
+
return;
|
|
30437
|
+
const data = (_b = collection.data
|
|
30438
|
+
.map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
|
|
30439
|
+
.filter(isNonNullable)
|
|
30440
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [].map(eventResponseLinkedObject);
|
|
30441
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
30442
|
+
return;
|
|
30443
|
+
this.callback({
|
|
30444
|
+
data,
|
|
30445
|
+
error,
|
|
30446
|
+
loading,
|
|
30447
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30448
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30449
|
+
});
|
|
30450
|
+
}
|
|
30451
|
+
}
|
|
30452
|
+
|
|
30453
|
+
/**
|
|
30454
|
+
* Get events
|
|
30455
|
+
*
|
|
30456
|
+
* @param params the query parameters
|
|
30457
|
+
* @param callback the callback to be called when the events are updated
|
|
30458
|
+
* @returns events
|
|
30459
|
+
*
|
|
30460
|
+
* @category RSVP Live Collection
|
|
30461
|
+
*
|
|
30462
|
+
*/
|
|
30463
|
+
const getRSVPs = (params, callback, config) => {
|
|
30464
|
+
const { log, cache } = getActiveClient();
|
|
30465
|
+
if (!cache)
|
|
30466
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30467
|
+
const timestamp = Date.now();
|
|
30468
|
+
log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
|
|
30469
|
+
const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
|
|
30470
|
+
const disposers = rsvpLiveCollection.startSubscription();
|
|
30471
|
+
const cacheKey = rsvpLiveCollection.getCacheKey();
|
|
30472
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30473
|
+
return () => {
|
|
30474
|
+
log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
|
|
30475
|
+
disposers.forEach(fn => fn());
|
|
30476
|
+
};
|
|
30477
|
+
};
|
|
30478
|
+
|
|
29928
30479
|
const eventLinkedObject = (event) => {
|
|
29929
30480
|
return Object.assign(Object.assign({}, event), { get creator() {
|
|
29930
30481
|
const cacheData = pullFromCache(['user', 'get', event.userId]);
|
|
@@ -29964,6 +30515,17 @@ const eventLinkedObject = (event) => {
|
|
|
29964
30515
|
if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.length) || !cacheData[0].data)
|
|
29965
30516
|
return;
|
|
29966
30517
|
return roomLinkedObject(cacheData[0].data);
|
|
30518
|
+
}, createRSVP: async (status) => {
|
|
30519
|
+
const { data } = await createRSVP(event.eventId, status);
|
|
30520
|
+
return data;
|
|
30521
|
+
}, updateRSVP: async (status) => {
|
|
30522
|
+
const { data } = await updateRSVP(event.eventId, status);
|
|
30523
|
+
return data;
|
|
30524
|
+
}, getMyRSVP: async () => {
|
|
30525
|
+
const { data } = await getMyRSVP(event.eventId);
|
|
30526
|
+
return data;
|
|
30527
|
+
}, getRSVPs: (params, callback) => {
|
|
30528
|
+
return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
|
|
29967
30529
|
} });
|
|
29968
30530
|
};
|
|
29969
30531
|
|
|
@@ -29987,6 +30549,7 @@ const LinkedObject = {
|
|
|
29987
30549
|
channelMember: channelMemberLinkedObject,
|
|
29988
30550
|
room: roomLinkedObject,
|
|
29989
30551
|
event: eventLinkedObject,
|
|
30552
|
+
eventResponse: eventResponseLinkedObject,
|
|
29990
30553
|
};
|
|
29991
30554
|
|
|
29992
30555
|
/* begin_public_function
|
|
@@ -43345,521 +43908,1166 @@ const searchPostsByHashtag = (params, callback, config) => {
|
|
|
43345
43908
|
};
|
|
43346
43909
|
/* end_public_function */
|
|
43347
43910
|
|
|
43348
|
-
|
|
43349
|
-
|
|
43350
|
-
|
|
43351
|
-
|
|
43352
|
-
|
|
43353
|
-
|
|
43354
|
-
|
|
43355
|
-
|
|
43356
|
-
|
|
43357
|
-
|
|
43358
|
-
|
|
43359
|
-
|
|
43360
|
-
|
|
43361
|
-
|
|
43362
|
-
|
|
43363
|
-
|
|
43364
|
-
|
|
43365
|
-
|
|
43366
|
-
|
|
43367
|
-
|
|
43368
|
-
|
|
43369
|
-
|
|
43370
|
-
|
|
43371
|
-
|
|
43372
|
-
|
|
43373
|
-
|
|
43374
|
-
|
|
43375
|
-
|
|
43376
|
-
|
|
43377
|
-
|
|
43378
|
-
|
|
43379
|
-
|
|
43911
|
+
class LiveRoomPostPaginationController extends PaginationNoPageController {
|
|
43912
|
+
async getRequest(queryParams) {
|
|
43913
|
+
const { limit = 100 } = queryParams;
|
|
43914
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/rooms/lives`, {
|
|
43915
|
+
params: {
|
|
43916
|
+
targetTypes: ['all'],
|
|
43917
|
+
options: {
|
|
43918
|
+
limit,
|
|
43919
|
+
sortBy: 'last_created',
|
|
43920
|
+
},
|
|
43921
|
+
},
|
|
43922
|
+
});
|
|
43923
|
+
return queryResponse;
|
|
43924
|
+
}
|
|
43925
|
+
}
|
|
43926
|
+
|
|
43927
|
+
class LiveRoomPostQueryStreamController extends QueryStreamController {
|
|
43928
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
43929
|
+
super(query, cacheKey);
|
|
43930
|
+
this.notifyChange = notifyChange;
|
|
43931
|
+
this.preparePayload = preparePayload;
|
|
43932
|
+
}
|
|
43933
|
+
async saveToMainDB(response) {
|
|
43934
|
+
const processedPayload = await this.preparePayload(response);
|
|
43935
|
+
const client = getActiveClient();
|
|
43936
|
+
const cachedAt = client.cache && Date.now();
|
|
43937
|
+
if (client.cache) {
|
|
43938
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
43939
|
+
}
|
|
43940
|
+
}
|
|
43941
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
43942
|
+
var _a, _b;
|
|
43943
|
+
if (refresh) {
|
|
43944
|
+
pushToCache(this.cacheKey, {
|
|
43945
|
+
data: response.posts.map(getResolver('post')),
|
|
43946
|
+
});
|
|
43947
|
+
}
|
|
43948
|
+
else {
|
|
43949
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43950
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
43951
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
43952
|
+
}
|
|
43953
|
+
}
|
|
43954
|
+
reactor(action) {
|
|
43955
|
+
return (room) => {
|
|
43956
|
+
var _a;
|
|
43957
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43958
|
+
if (!collection)
|
|
43959
|
+
return;
|
|
43960
|
+
if (room.status === 'ended') {
|
|
43961
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: collection.data.filter(postId => room.referenceId !== postId) }));
|
|
43962
|
+
}
|
|
43963
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
43964
|
+
};
|
|
43965
|
+
}
|
|
43966
|
+
subscribeRTE(createSubscriber) {
|
|
43967
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
43968
|
+
}
|
|
43969
|
+
}
|
|
43380
43970
|
|
|
43381
43971
|
/* begin_public_function
|
|
43382
|
-
id:
|
|
43972
|
+
id: room.create
|
|
43383
43973
|
*/
|
|
43384
43974
|
/**
|
|
43385
43975
|
* ```js
|
|
43386
|
-
* import {
|
|
43387
|
-
* const created = await
|
|
43976
|
+
* import { createRoom } from '@amityco/ts-sdk'
|
|
43977
|
+
* const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
|
|
43388
43978
|
* ```
|
|
43389
43979
|
*
|
|
43390
|
-
* Creates an {@link Amity.
|
|
43980
|
+
* Creates an {@link Amity.Room}
|
|
43391
43981
|
*
|
|
43392
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
43393
|
-
* @returns The newly created {@link Amity.
|
|
43982
|
+
* @param bundle The data necessary to create a new {@link Amity.Room}
|
|
43983
|
+
* @returns The newly created {@link Amity.Room}
|
|
43394
43984
|
*
|
|
43395
|
-
* @category
|
|
43985
|
+
* @category Room API
|
|
43396
43986
|
* @async
|
|
43397
43987
|
*/
|
|
43398
|
-
const
|
|
43988
|
+
const createRoom = async (bundle) => {
|
|
43399
43989
|
const client = getActiveClient();
|
|
43400
|
-
client.log('
|
|
43401
|
-
const { data } = await client.http.post('/api/
|
|
43990
|
+
client.log('room/createRoom', bundle);
|
|
43991
|
+
const { data } = await client.http.post('/api/v1/rooms', bundle);
|
|
43992
|
+
fireEvent('local.room.created', data);
|
|
43402
43993
|
const cachedAt = client.cache && Date.now();
|
|
43994
|
+
// TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
|
|
43403
43995
|
if (client.cache)
|
|
43404
43996
|
ingestInCache(data, { cachedAt });
|
|
43405
|
-
const {
|
|
43997
|
+
const { rooms } = data;
|
|
43406
43998
|
return {
|
|
43407
|
-
data:
|
|
43999
|
+
data: roomLinkedObject(rooms[0]),
|
|
43408
44000
|
cachedAt,
|
|
43409
44001
|
};
|
|
43410
44002
|
};
|
|
43411
44003
|
/* end_public_function */
|
|
43412
44004
|
|
|
43413
44005
|
/* begin_public_function
|
|
43414
|
-
id:
|
|
44006
|
+
id: room.update
|
|
43415
44007
|
*/
|
|
43416
44008
|
/**
|
|
43417
|
-
* @deprecated this function is deprecated,
|
|
43418
|
-
* please use {@link Amity.StreamRepository.editStream} instead.
|
|
43419
|
-
*
|
|
43420
44009
|
* ```js
|
|
43421
|
-
* import {
|
|
43422
|
-
* const updated = await
|
|
44010
|
+
* import { updateRoom } from '@amityco/ts-sdk'
|
|
44011
|
+
* const updated = await updateRoom('roomId', { title: 'updated title' })
|
|
43423
44012
|
* ```
|
|
43424
44013
|
*
|
|
43425
|
-
* Updates an {@link Amity.
|
|
44014
|
+
* Updates an {@link Amity.InternalRoom}
|
|
43426
44015
|
*
|
|
43427
|
-
* @param
|
|
43428
|
-
* @param
|
|
43429
|
-
* @returns
|
|
44016
|
+
* @param roomId The ID of the room to update
|
|
44017
|
+
* @param bundle The data to update the room with
|
|
44018
|
+
* @returns The updated {@link Amity.InternalRoom}
|
|
43430
44019
|
*
|
|
43431
|
-
* @category
|
|
44020
|
+
* @category Room API
|
|
43432
44021
|
* @async
|
|
43433
44022
|
*/
|
|
43434
|
-
const
|
|
44023
|
+
const updateRoom = async (roomId, bundle) => {
|
|
43435
44024
|
const client = getActiveClient();
|
|
43436
|
-
client.log('
|
|
43437
|
-
const { data } = await client.http.put(`/api/
|
|
44025
|
+
client.log('room/updateRoom', { roomId, bundle });
|
|
44026
|
+
const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
|
|
44027
|
+
fireEvent('local.room.updated', data);
|
|
43438
44028
|
const cachedAt = client.cache && Date.now();
|
|
43439
44029
|
if (client.cache)
|
|
43440
44030
|
ingestInCache(data, { cachedAt });
|
|
43441
|
-
const {
|
|
44031
|
+
const { rooms } = data;
|
|
43442
44032
|
return {
|
|
43443
|
-
data:
|
|
44033
|
+
data: roomLinkedObject(rooms[0]),
|
|
43444
44034
|
cachedAt,
|
|
43445
44035
|
};
|
|
43446
44036
|
};
|
|
43447
44037
|
/* end_public_function */
|
|
43448
44038
|
|
|
43449
44039
|
/* begin_public_function
|
|
43450
|
-
id:
|
|
44040
|
+
id: room.delete
|
|
43451
44041
|
*/
|
|
43452
44042
|
/**
|
|
43453
44043
|
* ```js
|
|
43454
|
-
* import {
|
|
43455
|
-
* const
|
|
44044
|
+
* import { deleteRoom } from '@amityco/ts-sdk'
|
|
44045
|
+
* const result = await deleteRoom('roomId')
|
|
43456
44046
|
* ```
|
|
43457
44047
|
*
|
|
43458
|
-
*
|
|
44048
|
+
* Deletes an {@link Amity.Room}
|
|
43459
44049
|
*
|
|
43460
|
-
* @param
|
|
43461
|
-
* @returns the
|
|
44050
|
+
* @param roomId The ID of the room to delete
|
|
44051
|
+
* @returns Promise that resolves when the room is deleted
|
|
43462
44052
|
*
|
|
43463
|
-
* @category
|
|
44053
|
+
* @category Room API
|
|
43464
44054
|
* @async
|
|
43465
44055
|
*/
|
|
43466
|
-
const
|
|
44056
|
+
const deleteRoom = async (roomId) => {
|
|
43467
44057
|
const client = getActiveClient();
|
|
43468
|
-
client.log('
|
|
43469
|
-
|
|
44058
|
+
client.log('room/deleteRoom', { roomId });
|
|
44059
|
+
await client.http.delete(`/api/v1/rooms/${roomId}`);
|
|
44060
|
+
fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
|
|
44061
|
+
};
|
|
44062
|
+
/* end_public_function */
|
|
44063
|
+
|
|
44064
|
+
/* begin_public_function
|
|
44065
|
+
id: room.stop
|
|
44066
|
+
*/
|
|
44067
|
+
/**
|
|
44068
|
+
* ```js
|
|
44069
|
+
* import { stopRoom } from '@amityco/ts-sdk'
|
|
44070
|
+
* const result = await stopRoom('roomId')
|
|
44071
|
+
* ```
|
|
44072
|
+
*
|
|
44073
|
+
* Stops a room's broadcasting
|
|
44074
|
+
*
|
|
44075
|
+
* @param roomId The ID of the room to stop
|
|
44076
|
+
* @returns The updated room data
|
|
44077
|
+
*
|
|
44078
|
+
* @category Room API
|
|
44079
|
+
* @async
|
|
44080
|
+
*/
|
|
44081
|
+
const stopRoom = async (roomId) => {
|
|
44082
|
+
const client = getActiveClient();
|
|
44083
|
+
client.log('room/stopRoom', { roomId });
|
|
44084
|
+
const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
|
|
44085
|
+
fireEvent('local.room.stopped', data);
|
|
43470
44086
|
const cachedAt = client.cache && Date.now();
|
|
43471
44087
|
if (client.cache)
|
|
43472
44088
|
ingestInCache(data, { cachedAt });
|
|
43473
|
-
const {
|
|
44089
|
+
const { rooms } = data;
|
|
43474
44090
|
return {
|
|
43475
|
-
data:
|
|
44091
|
+
data: rooms[0],
|
|
43476
44092
|
cachedAt,
|
|
43477
44093
|
};
|
|
43478
44094
|
};
|
|
43479
44095
|
/* end_public_function */
|
|
44096
|
+
|
|
44097
|
+
/* begin_public_function
|
|
44098
|
+
id: room.getBroadcasterData
|
|
44099
|
+
*/
|
|
43480
44100
|
/**
|
|
43481
44101
|
* ```js
|
|
43482
|
-
* import {
|
|
43483
|
-
* const
|
|
44102
|
+
* import { getBroadcasterData } from '@amityco/ts-sdk'
|
|
44103
|
+
* const token = await getBroadcasterData('roomId')
|
|
44104
|
+
* ```
|
|
44105
|
+
*
|
|
44106
|
+
* Gets broadcaster data for a room
|
|
44107
|
+
*
|
|
44108
|
+
* @param roomId The ID of the room to get token for
|
|
44109
|
+
* @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
|
|
44110
|
+
*
|
|
44111
|
+
* @category Room API
|
|
44112
|
+
* @async
|
|
44113
|
+
*/
|
|
44114
|
+
const getBroadcasterData = async (roomId) => {
|
|
44115
|
+
const client = getActiveClient();
|
|
44116
|
+
client.log('room/getBroadcasterData', { roomId });
|
|
44117
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
|
|
44118
|
+
return data;
|
|
44119
|
+
};
|
|
44120
|
+
/* end_public_function */
|
|
44121
|
+
|
|
44122
|
+
/* begin_public_function
|
|
44123
|
+
id: room.getRecordedUrl
|
|
44124
|
+
*/
|
|
44125
|
+
/**
|
|
44126
|
+
* ```js
|
|
44127
|
+
* import { getRecordedUrl } from '@amityco/ts-sdk'
|
|
44128
|
+
* const recordedUrl = await getRecordedUrl('roomId')
|
|
44129
|
+
* ```
|
|
44130
|
+
*
|
|
44131
|
+
* Gets the recorded URL for a room
|
|
44132
|
+
*
|
|
44133
|
+
* @param roomId The ID of the room to get recorded URL for
|
|
44134
|
+
* @returns The recorded URL information
|
|
44135
|
+
*
|
|
44136
|
+
* @category Room API
|
|
44137
|
+
* @async
|
|
44138
|
+
*/
|
|
44139
|
+
const getRecordedUrl = async (roomId) => {
|
|
44140
|
+
const client = getActiveClient();
|
|
44141
|
+
client.log('room/getRecordedUrl', { roomId });
|
|
44142
|
+
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
|
|
44143
|
+
return data;
|
|
44144
|
+
};
|
|
44145
|
+
/* end_public_function */
|
|
44146
|
+
|
|
44147
|
+
/* begin_public_function
|
|
44148
|
+
id: room.removeParticipant
|
|
44149
|
+
*/
|
|
44150
|
+
/**
|
|
44151
|
+
* ```js
|
|
44152
|
+
* import { removeParticipant } from '@amityco/ts-sdk'
|
|
44153
|
+
* const result = await removeParticipant('roomId', 'participantUserId')
|
|
44154
|
+
* ```
|
|
44155
|
+
*
|
|
44156
|
+
* Removes a participant from an {@link Amity.Room}
|
|
44157
|
+
*
|
|
44158
|
+
* @param roomId The ID of the room to remove participant from
|
|
44159
|
+
* @param participantUserId The ID of the user to remove as participant
|
|
44160
|
+
* @returns Promise that resolves when the participant is removed
|
|
44161
|
+
*
|
|
44162
|
+
* @category Room API
|
|
44163
|
+
* @async
|
|
44164
|
+
*/
|
|
44165
|
+
const removeParticipant = async (roomId, participantUserId) => {
|
|
44166
|
+
const client = getActiveClient();
|
|
44167
|
+
client.log('room/removeParticipant', { roomId, participantUserId });
|
|
44168
|
+
await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
|
|
44169
|
+
fireEvent('local.room.participantRemoved', {
|
|
44170
|
+
rooms: [{ _id: roomId }],
|
|
44171
|
+
users: [{ _id: participantUserId }],
|
|
44172
|
+
});
|
|
44173
|
+
};
|
|
44174
|
+
/* end_public_function */
|
|
44175
|
+
|
|
44176
|
+
/* begin_public_function
|
|
44177
|
+
id: room.leave
|
|
44178
|
+
*/
|
|
44179
|
+
/**
|
|
44180
|
+
* ```js
|
|
44181
|
+
* import { leaveRoom } from '@amityco/ts-sdk'
|
|
44182
|
+
* const result = await leaveRoom('roomId')
|
|
44183
|
+
* ```
|
|
44184
|
+
*
|
|
44185
|
+
* Leaves an {@link Amity.Room}
|
|
44186
|
+
*
|
|
44187
|
+
* @param roomId The ID of the room to leave
|
|
44188
|
+
* @returns Promise that resolves when the user has left the room
|
|
44189
|
+
*
|
|
44190
|
+
* @category Room API
|
|
44191
|
+
* @async
|
|
44192
|
+
*/
|
|
44193
|
+
const leaveRoom = async (roomId) => {
|
|
44194
|
+
const client = getActiveClient();
|
|
44195
|
+
client.log('room/leaveRoom', { roomId });
|
|
44196
|
+
await client.http.post(`/api/v1/rooms/${roomId}/leave`);
|
|
44197
|
+
fireEvent('local.room.left', {
|
|
44198
|
+
rooms: [{ _id: roomId }],
|
|
44199
|
+
});
|
|
44200
|
+
};
|
|
44201
|
+
/* end_public_function */
|
|
44202
|
+
|
|
44203
|
+
/**
|
|
44204
|
+
* ```js
|
|
44205
|
+
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
44206
|
+
* const dispose = onRoomStartBroadcasting(room => {
|
|
44207
|
+
* // ...
|
|
44208
|
+
* })
|
|
44209
|
+
* ```
|
|
44210
|
+
*
|
|
44211
|
+
* Fired when a {@link Amity.Room} has started broadcasting
|
|
44212
|
+
*
|
|
44213
|
+
* @param callback The function to call when the event was fired
|
|
44214
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44215
|
+
*
|
|
44216
|
+
* @category Room Events
|
|
44217
|
+
*/
|
|
44218
|
+
const onRoomStartBroadcasting = (callback) => {
|
|
44219
|
+
const client = getActiveClient();
|
|
44220
|
+
const filter = (payload) => {
|
|
44221
|
+
ingestInCache(payload);
|
|
44222
|
+
callback(payload.rooms[0]);
|
|
44223
|
+
};
|
|
44224
|
+
return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
|
|
44225
|
+
};
|
|
44226
|
+
|
|
44227
|
+
/**
|
|
44228
|
+
* ```js
|
|
44229
|
+
* import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
|
|
44230
|
+
* const dispose = onRoomWaitingReconnect(room => {
|
|
44231
|
+
* // ...
|
|
44232
|
+
* })
|
|
44233
|
+
* ```
|
|
44234
|
+
*
|
|
44235
|
+
* Fired when a {@link Amity.Room} is waiting for reconnection
|
|
44236
|
+
*
|
|
44237
|
+
* @param callback The function to call when the event was fired
|
|
44238
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44239
|
+
*
|
|
44240
|
+
* @category Room Events
|
|
44241
|
+
*/
|
|
44242
|
+
const onRoomWaitingReconnect = (callback) => {
|
|
44243
|
+
const client = getActiveClient();
|
|
44244
|
+
const filter = (payload) => {
|
|
44245
|
+
ingestInCache(payload);
|
|
44246
|
+
callback(payload.rooms[0]);
|
|
44247
|
+
};
|
|
44248
|
+
return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
|
|
44249
|
+
};
|
|
44250
|
+
|
|
44251
|
+
/**
|
|
44252
|
+
* ```js
|
|
44253
|
+
* import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
|
|
44254
|
+
* const dispose = onRoomEndBroadcasting(room => {
|
|
44255
|
+
* // ...
|
|
44256
|
+
* })
|
|
44257
|
+
* ```
|
|
44258
|
+
*
|
|
44259
|
+
* Fired when a {@link Amity.Room} has ended broadcasting
|
|
44260
|
+
*
|
|
44261
|
+
* @param callback The function to call when the event was fired
|
|
44262
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44263
|
+
*
|
|
44264
|
+
* @category Room Events
|
|
44265
|
+
*/
|
|
44266
|
+
const onRoomEndBroadcasting = (callback) => {
|
|
44267
|
+
const client = getActiveClient();
|
|
44268
|
+
const filter = (payload) => {
|
|
44269
|
+
ingestInCache(payload);
|
|
44270
|
+
callback(payload.rooms[0]);
|
|
44271
|
+
};
|
|
44272
|
+
return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
|
|
44273
|
+
};
|
|
44274
|
+
|
|
44275
|
+
/**
|
|
44276
|
+
* ```js
|
|
44277
|
+
* import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
|
|
44278
|
+
* const dispose = onRoomRecordedAvailable(room => {
|
|
44279
|
+
* // ...
|
|
44280
|
+
* })
|
|
44281
|
+
* ```
|
|
44282
|
+
*
|
|
44283
|
+
* Fired when a {@link Amity.Room} recorded content becomes available
|
|
44284
|
+
*
|
|
44285
|
+
* @param callback The function to call when the event was fired
|
|
44286
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44287
|
+
*
|
|
44288
|
+
* @category Room Events
|
|
44289
|
+
*/
|
|
44290
|
+
const onRoomRecordedAvailable = (callback) => {
|
|
44291
|
+
const client = getActiveClient();
|
|
44292
|
+
const filter = (payload) => {
|
|
44293
|
+
ingestInCache(payload);
|
|
44294
|
+
callback(payload.rooms[0]);
|
|
44295
|
+
};
|
|
44296
|
+
return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
|
|
44297
|
+
};
|
|
44298
|
+
|
|
44299
|
+
/**
|
|
44300
|
+
* ```js
|
|
44301
|
+
* import { onRoomParticipantInviting } from '@amityco/ts-sdk'
|
|
44302
|
+
* const dispose = onRoomParticipantInviting(room => {
|
|
44303
|
+
* // ...
|
|
44304
|
+
* })
|
|
44305
|
+
* ```
|
|
44306
|
+
*
|
|
44307
|
+
* Fired when a participant is being invited to a {@link Amity.Room}
|
|
44308
|
+
*
|
|
44309
|
+
* @param callback The function to call when the event was fired
|
|
44310
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44311
|
+
*
|
|
44312
|
+
* @category Room Events
|
|
44313
|
+
*/
|
|
44314
|
+
const onRoomCoHostInvited = (callback) => {
|
|
44315
|
+
const client = getActiveClient();
|
|
44316
|
+
const filter = (payload) => {
|
|
44317
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44318
|
+
ingestInCache(data);
|
|
44319
|
+
callback(data.invitations);
|
|
44320
|
+
};
|
|
44321
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
|
|
44322
|
+
};
|
|
44323
|
+
|
|
44324
|
+
const getRoomById = async (roomId) => {
|
|
44325
|
+
const client = getActiveClient();
|
|
44326
|
+
client.log('room/getRoomById', roomId);
|
|
44327
|
+
// Check if room is in tombstone
|
|
44328
|
+
isInTombstone('room', roomId);
|
|
44329
|
+
let data;
|
|
44330
|
+
try {
|
|
44331
|
+
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
44332
|
+
data = response.data;
|
|
44333
|
+
}
|
|
44334
|
+
catch (error) {
|
|
44335
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
44336
|
+
pushToTombstone('room', roomId);
|
|
44337
|
+
}
|
|
44338
|
+
throw error;
|
|
44339
|
+
}
|
|
44340
|
+
const cachedAt = client.cache && Date.now();
|
|
44341
|
+
if (client.cache) {
|
|
44342
|
+
ingestInCache(data, { cachedAt });
|
|
44343
|
+
}
|
|
44344
|
+
return {
|
|
44345
|
+
data: data.rooms[0],
|
|
44346
|
+
cachedAt,
|
|
44347
|
+
};
|
|
44348
|
+
};
|
|
44349
|
+
getRoomById.locally = (roomId) => {
|
|
44350
|
+
const client = getActiveClient();
|
|
44351
|
+
client.log('room/getRoomById.locally', roomId);
|
|
44352
|
+
// Check if room is in tombstone
|
|
44353
|
+
isInTombstone('room', roomId);
|
|
44354
|
+
const cachedAt = client.cache && Date.now();
|
|
44355
|
+
const roomCache = pullFromCache(['room', 'get', roomId]);
|
|
44356
|
+
if (!roomCache)
|
|
44357
|
+
return;
|
|
44358
|
+
return {
|
|
44359
|
+
data: roomCache.data,
|
|
44360
|
+
cachedAt,
|
|
44361
|
+
};
|
|
44362
|
+
};
|
|
44363
|
+
|
|
44364
|
+
/**
|
|
44365
|
+
* ```js
|
|
44366
|
+
* import { onRoomCoHostInviteAccepted } from '@amityco/ts-sdk'
|
|
44367
|
+
* const dispose = onRoomCoHostInviteAccepted(room => {
|
|
44368
|
+
* // ...
|
|
44369
|
+
* })
|
|
44370
|
+
* ```
|
|
44371
|
+
*
|
|
44372
|
+
* Fired when a co-host invitation is accepted for a {@link Amity.Room}
|
|
44373
|
+
*
|
|
44374
|
+
* @param callback The function to call when the event was fired
|
|
44375
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44376
|
+
*
|
|
44377
|
+
* @category Room Events
|
|
44378
|
+
*/
|
|
44379
|
+
const onRoomCoHostInviteAccepted = (callback) => {
|
|
44380
|
+
const client = getActiveClient();
|
|
44381
|
+
const filter = async (payload) => {
|
|
44382
|
+
var _a;
|
|
44383
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44384
|
+
await getRoomById((_a = data.invitations) === null || _a === void 0 ? void 0 : _a[0].targetId);
|
|
44385
|
+
ingestInCache(data);
|
|
44386
|
+
callback(data.invitations[0]);
|
|
44387
|
+
};
|
|
44388
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
|
|
44389
|
+
};
|
|
44390
|
+
|
|
44391
|
+
/**
|
|
44392
|
+
* ```js
|
|
44393
|
+
* import { onRoomCoHostInviteRejected } from '@amityco/ts-sdk'
|
|
44394
|
+
* const dispose = onRoomCoHostInviteRejected(room => {
|
|
44395
|
+
* // ...
|
|
44396
|
+
* })
|
|
44397
|
+
* ```
|
|
44398
|
+
*
|
|
44399
|
+
* Fired when a co-host invitation is rejected for a {@link Amity.Room}
|
|
44400
|
+
*
|
|
44401
|
+
* @param callback The function to call when the event was fired
|
|
44402
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44403
|
+
*
|
|
44404
|
+
* @category Room Events
|
|
44405
|
+
*/
|
|
44406
|
+
const onRoomCoHostInviteRejected = (callback) => {
|
|
44407
|
+
const client = getActiveClient();
|
|
44408
|
+
const filter = (payload) => {
|
|
44409
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44410
|
+
ingestInCache(data);
|
|
44411
|
+
callback(data.invitations);
|
|
44412
|
+
};
|
|
44413
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteRejected', 'room.didCohostInviteReject', filter);
|
|
44414
|
+
};
|
|
44415
|
+
|
|
44416
|
+
/**
|
|
44417
|
+
* ```js
|
|
44418
|
+
* import { onRoomCoHostInviteCanceled } from '@amityco/ts-sdk'
|
|
44419
|
+
* const dispose = onRoomCoHostInviteCanceled(room => {
|
|
44420
|
+
* // ...
|
|
44421
|
+
* })
|
|
43484
44422
|
* ```
|
|
43485
44423
|
*
|
|
43486
|
-
*
|
|
44424
|
+
* Fired when a co-host invitation is canceled for a {@link Amity.Room}
|
|
43487
44425
|
*
|
|
43488
|
-
* @param
|
|
43489
|
-
* @returns
|
|
44426
|
+
* @param callback The function to call when the event was fired
|
|
44427
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43490
44428
|
*
|
|
43491
|
-
* @category
|
|
44429
|
+
* @category Room Events
|
|
43492
44430
|
*/
|
|
43493
|
-
|
|
44431
|
+
const onRoomCoHostInviteCanceled = (callback) => {
|
|
43494
44432
|
const client = getActiveClient();
|
|
43495
|
-
|
|
43496
|
-
|
|
43497
|
-
|
|
43498
|
-
|
|
43499
|
-
if (!cached)
|
|
43500
|
-
return;
|
|
43501
|
-
return {
|
|
43502
|
-
data: cached.data,
|
|
43503
|
-
cachedAt: cached.cachedAt,
|
|
44433
|
+
const filter = (payload) => {
|
|
44434
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
44435
|
+
ingestInCache(data);
|
|
44436
|
+
callback(data.invitations);
|
|
43504
44437
|
};
|
|
44438
|
+
return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCohostInviteCancel', filter);
|
|
43505
44439
|
};
|
|
43506
44440
|
|
|
43507
|
-
// import { unwrapPayload } from '~/core/transports'
|
|
43508
|
-
/* begin_public_function
|
|
43509
|
-
id: stream.delete
|
|
43510
|
-
*/
|
|
43511
44441
|
/**
|
|
43512
44442
|
* ```js
|
|
43513
|
-
* import {
|
|
43514
|
-
* const
|
|
44443
|
+
* import { onRoomParticipantJoined } from '@amityco/ts-sdk'
|
|
44444
|
+
* const dispose = onRoomParticipantJoined(room => {
|
|
44445
|
+
* // ...
|
|
44446
|
+
* })
|
|
43515
44447
|
* ```
|
|
43516
44448
|
*
|
|
43517
|
-
*
|
|
44449
|
+
* Fired when a participant has joined a {@link Amity.Room}
|
|
43518
44450
|
*
|
|
43519
|
-
* @param
|
|
43520
|
-
* @
|
|
44451
|
+
* @param callback The function to call when the event was fired
|
|
44452
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43521
44453
|
*
|
|
43522
|
-
* @category
|
|
43523
|
-
* @async
|
|
44454
|
+
* @category Room Events
|
|
43524
44455
|
*/
|
|
43525
|
-
const
|
|
44456
|
+
const onRoomParticipantJoined = (callback) => {
|
|
43526
44457
|
const client = getActiveClient();
|
|
43527
|
-
|
|
43528
|
-
|
|
43529
|
-
|
|
43530
|
-
|
|
43531
|
-
|
|
43532
|
-
const { success } = data; // unwrapPayload(data)
|
|
43533
|
-
const deleted = Object.assign(Object.assign({}, stream.data), { isDeleted: true });
|
|
43534
|
-
upsertInCache(['stream', 'get', streamId], deleted);
|
|
43535
|
-
return success;
|
|
44458
|
+
const filter = (payload) => {
|
|
44459
|
+
ingestInCache(payload);
|
|
44460
|
+
callback(payload.rooms[0]);
|
|
44461
|
+
};
|
|
44462
|
+
return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
|
|
43536
44463
|
};
|
|
43537
|
-
/* end_public_function */
|
|
43538
44464
|
|
|
43539
44465
|
/**
|
|
43540
44466
|
* ```js
|
|
43541
|
-
* import {
|
|
43542
|
-
* const
|
|
44467
|
+
* import { onRoomParticipantLeft } from '@amityco/ts-sdk'
|
|
44468
|
+
* const dispose = onRoomParticipantLeft(room => {
|
|
44469
|
+
* // ...
|
|
44470
|
+
* })
|
|
43543
44471
|
* ```
|
|
43544
44472
|
*
|
|
43545
|
-
*
|
|
43546
|
-
* Streaming status will be updated to "ended" and streaming url will be invalidated
|
|
44473
|
+
* Fired when a participant has left a {@link Amity.Room}
|
|
43547
44474
|
*
|
|
43548
|
-
* @param
|
|
43549
|
-
* @returns
|
|
44475
|
+
* @param callback The function to call when the event was fired
|
|
44476
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43550
44477
|
*
|
|
43551
|
-
* @category
|
|
43552
|
-
* @async
|
|
44478
|
+
* @category Room Events
|
|
43553
44479
|
*/
|
|
43554
|
-
const
|
|
44480
|
+
const onRoomParticipantLeft = (callback) => {
|
|
43555
44481
|
const client = getActiveClient();
|
|
43556
|
-
|
|
43557
|
-
|
|
43558
|
-
|
|
43559
|
-
if (client.cache)
|
|
43560
|
-
ingestInCache(data, { cachedAt });
|
|
43561
|
-
const { videoStreamings } = data;
|
|
43562
|
-
return {
|
|
43563
|
-
data: videoStreamings.find(stream => stream.streamId === streamId),
|
|
43564
|
-
cachedAt,
|
|
44482
|
+
const filter = (payload) => {
|
|
44483
|
+
ingestInCache(payload);
|
|
44484
|
+
callback(payload.rooms[0]);
|
|
43565
44485
|
};
|
|
44486
|
+
return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
|
|
43566
44487
|
};
|
|
43567
|
-
/* end_public_function */
|
|
43568
44488
|
|
|
43569
|
-
/* begin_public_function
|
|
43570
|
-
id: stream.update
|
|
43571
|
-
*/
|
|
43572
44489
|
/**
|
|
43573
|
-
*
|
|
43574
44490
|
* ```js
|
|
43575
|
-
* import {
|
|
43576
|
-
* const
|
|
44491
|
+
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
44492
|
+
* const dispose = onRoomCreated(room => {
|
|
44493
|
+
* // ...
|
|
44494
|
+
* })
|
|
43577
44495
|
* ```
|
|
43578
44496
|
*
|
|
43579
|
-
*
|
|
44497
|
+
* Fired when a {@link Amity.Room} has been created locally
|
|
43580
44498
|
*
|
|
43581
|
-
* @param
|
|
43582
|
-
* @
|
|
43583
|
-
* @returns the updated {@link Amity.Stream} object
|
|
44499
|
+
* @param callback The function to call when the event was fired
|
|
44500
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43584
44501
|
*
|
|
43585
|
-
* @category
|
|
43586
|
-
* @async
|
|
44502
|
+
* @category Room Events
|
|
43587
44503
|
*/
|
|
43588
|
-
const
|
|
44504
|
+
const onRoomCreated = (callback) => {
|
|
43589
44505
|
const client = getActiveClient();
|
|
43590
|
-
|
|
43591
|
-
|
|
43592
|
-
|
|
43593
|
-
if (client.cache)
|
|
43594
|
-
ingestInCache(data, { cachedAt });
|
|
43595
|
-
const { videoStreamings } = data;
|
|
43596
|
-
return {
|
|
43597
|
-
data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
|
|
43598
|
-
cachedAt,
|
|
44506
|
+
const filter = (payload) => {
|
|
44507
|
+
ingestInCache(payload);
|
|
44508
|
+
callback(payload.rooms[0]);
|
|
43599
44509
|
};
|
|
44510
|
+
return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
|
|
43600
44511
|
};
|
|
43601
|
-
/* end_public_function */
|
|
43602
44512
|
|
|
43603
44513
|
/**
|
|
43604
44514
|
* ```js
|
|
43605
|
-
* import {
|
|
43606
|
-
* const dispose =
|
|
44515
|
+
* import { onRoomUpdated } from '@amityco/ts-sdk'
|
|
44516
|
+
* const dispose = onRoomUpdated(room => {
|
|
43607
44517
|
* // ...
|
|
43608
44518
|
* })
|
|
43609
44519
|
* ```
|
|
43610
44520
|
*
|
|
43611
|
-
* Fired when a {@link Amity.
|
|
44521
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
43612
44522
|
*
|
|
43613
44523
|
* @param callback The function to call when the event was fired
|
|
43614
44524
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43615
44525
|
*
|
|
43616
|
-
* @category
|
|
44526
|
+
* @category Room Events
|
|
43617
44527
|
*/
|
|
43618
|
-
const
|
|
44528
|
+
const onRoomUpdated = (callback) => {
|
|
43619
44529
|
const client = getActiveClient();
|
|
43620
44530
|
const filter = (payload) => {
|
|
43621
44531
|
ingestInCache(payload);
|
|
43622
|
-
callback(payload.
|
|
44532
|
+
callback(payload.rooms[0]);
|
|
43623
44533
|
};
|
|
43624
|
-
return createEventSubscriber(client, '
|
|
44534
|
+
return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
|
|
43625
44535
|
};
|
|
43626
44536
|
|
|
43627
44537
|
/**
|
|
43628
44538
|
* ```js
|
|
43629
|
-
* import {
|
|
43630
|
-
* const dispose =
|
|
44539
|
+
* import { onRoomDeleted } from '@amityco/ts-sdk'
|
|
44540
|
+
* const dispose = onRoomDeleted(room => {
|
|
43631
44541
|
* // ...
|
|
43632
44542
|
* })
|
|
43633
44543
|
* ```
|
|
43634
44544
|
*
|
|
43635
|
-
* Fired when a {@link Amity.
|
|
44545
|
+
* Fired when a {@link Amity.Room} has been deleted locally
|
|
43636
44546
|
*
|
|
43637
44547
|
* @param callback The function to call when the event was fired
|
|
43638
44548
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43639
44549
|
*
|
|
43640
|
-
* @category
|
|
44550
|
+
* @category Room Events
|
|
43641
44551
|
*/
|
|
43642
|
-
const
|
|
44552
|
+
const onRoomDeleted = (callback) => {
|
|
43643
44553
|
const client = getActiveClient();
|
|
43644
44554
|
const filter = (payload) => {
|
|
43645
44555
|
ingestInCache(payload);
|
|
43646
|
-
callback(payload.
|
|
44556
|
+
callback(payload.rooms[0]);
|
|
43647
44557
|
};
|
|
43648
|
-
return createEventSubscriber(client, '
|
|
44558
|
+
return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
|
|
43649
44559
|
};
|
|
43650
44560
|
|
|
43651
44561
|
/**
|
|
43652
44562
|
* ```js
|
|
43653
|
-
* import {
|
|
43654
|
-
* const dispose =
|
|
44563
|
+
* import { onRoomStopped } from '@amityco/ts-sdk'
|
|
44564
|
+
* const dispose = onRoomStopped(room => {
|
|
43655
44565
|
* // ...
|
|
43656
44566
|
* })
|
|
43657
44567
|
* ```
|
|
43658
44568
|
*
|
|
43659
|
-
* Fired when
|
|
44569
|
+
* Fired when a {@link Amity.Room} has been stopped locally
|
|
43660
44570
|
*
|
|
43661
44571
|
* @param callback The function to call when the event was fired
|
|
43662
44572
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43663
44573
|
*
|
|
43664
|
-
* @category
|
|
44574
|
+
* @category Room Events
|
|
43665
44575
|
*/
|
|
43666
|
-
const
|
|
44576
|
+
const onRoomStopped = (callback) => {
|
|
43667
44577
|
const client = getActiveClient();
|
|
43668
44578
|
const filter = (payload) => {
|
|
43669
44579
|
ingestInCache(payload);
|
|
43670
|
-
callback(payload.
|
|
44580
|
+
callback(payload.rooms[0]);
|
|
43671
44581
|
};
|
|
43672
|
-
return createEventSubscriber(client, '
|
|
44582
|
+
return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
|
|
43673
44583
|
};
|
|
43674
44584
|
|
|
43675
44585
|
/**
|
|
43676
44586
|
* ```js
|
|
43677
|
-
* import {
|
|
43678
|
-
* const dispose =
|
|
44587
|
+
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
44588
|
+
* const dispose = onRoomParticipantRemoved(room => {
|
|
43679
44589
|
* // ...
|
|
43680
44590
|
* })
|
|
43681
44591
|
* ```
|
|
43682
44592
|
*
|
|
43683
|
-
* Fired when a {@link Amity.
|
|
44593
|
+
* Fired when a participant has been removed from a {@link Amity.Room} locally
|
|
43684
44594
|
*
|
|
43685
44595
|
* @param callback The function to call when the event was fired
|
|
43686
44596
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43687
44597
|
*
|
|
43688
|
-
* @category
|
|
44598
|
+
* @category Room Events
|
|
43689
44599
|
*/
|
|
43690
|
-
const
|
|
44600
|
+
const onRoomParticipantRemoved = (callback) => {
|
|
43691
44601
|
const client = getActiveClient();
|
|
43692
44602
|
const filter = (payload) => {
|
|
43693
44603
|
ingestInCache(payload);
|
|
43694
|
-
callback(payload.
|
|
44604
|
+
callback(payload.rooms[0]);
|
|
43695
44605
|
};
|
|
43696
|
-
return createEventSubscriber(client, '
|
|
44606
|
+
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'room.participantRemoved', filter);
|
|
43697
44607
|
};
|
|
43698
44608
|
|
|
43699
44609
|
/**
|
|
43700
44610
|
* ```js
|
|
43701
|
-
* import {
|
|
43702
|
-
* const dispose =
|
|
44611
|
+
* import { onRoomLeft } from '@amityco/ts-sdk'
|
|
44612
|
+
* const dispose = onRoomLeft(room => {
|
|
43703
44613
|
* // ...
|
|
43704
44614
|
* })
|
|
43705
44615
|
* ```
|
|
43706
44616
|
*
|
|
43707
|
-
* Fired when a {@link Amity.
|
|
44617
|
+
* Fired when a user has left a {@link Amity.Room} locally
|
|
43708
44618
|
*
|
|
43709
44619
|
* @param callback The function to call when the event was fired
|
|
43710
44620
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43711
44621
|
*
|
|
43712
|
-
* @category
|
|
44622
|
+
* @category Room Events
|
|
43713
44623
|
*/
|
|
43714
|
-
const
|
|
44624
|
+
const onRoomLeft = (callback) => {
|
|
43715
44625
|
const client = getActiveClient();
|
|
43716
44626
|
const filter = (payload) => {
|
|
43717
44627
|
ingestInCache(payload);
|
|
43718
|
-
callback(payload.
|
|
44628
|
+
callback(payload.rooms[0]);
|
|
43719
44629
|
};
|
|
43720
|
-
return createEventSubscriber(client, '
|
|
44630
|
+
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
43721
44631
|
};
|
|
43722
44632
|
|
|
43723
44633
|
/**
|
|
43724
44634
|
* ```js
|
|
43725
|
-
* import {
|
|
43726
|
-
* const dispose =
|
|
44635
|
+
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
44636
|
+
* const dispose = onRoomParticipantRemoved(room => {
|
|
43727
44637
|
* // ...
|
|
43728
44638
|
* })
|
|
43729
44639
|
* ```
|
|
43730
44640
|
*
|
|
43731
|
-
* Fired when a
|
|
44641
|
+
* Fired when a participant has been removed from a {@link Amity.Room} locally
|
|
43732
44642
|
*
|
|
43733
44643
|
* @param callback The function to call when the event was fired
|
|
43734
44644
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43735
44645
|
*
|
|
43736
|
-
* @category
|
|
44646
|
+
* @category Room Events
|
|
43737
44647
|
*/
|
|
43738
|
-
const
|
|
44648
|
+
const onRoomParticipantRemovedLocal = (callback) => {
|
|
43739
44649
|
const client = getActiveClient();
|
|
43740
|
-
const filter =
|
|
44650
|
+
const filter = (payload) => {
|
|
44651
|
+
ingestInCache(payload);
|
|
44652
|
+
callback(payload.rooms[0]);
|
|
44653
|
+
};
|
|
44654
|
+
return createEventSubscriber(client, 'room/onRoomParticipantRemoved', 'local.room.participantRemoved', filter);
|
|
44655
|
+
};
|
|
44656
|
+
|
|
44657
|
+
const getRoom = (roomId, callback) => {
|
|
44658
|
+
// TODO: add callbackDataSelector if there are linked object fields
|
|
44659
|
+
return liveObject(roomId, callback, '_id', getRoomById, [
|
|
44660
|
+
onRoomEndBroadcasting,
|
|
44661
|
+
onRoomStartBroadcasting,
|
|
44662
|
+
onRoomWaitingReconnect,
|
|
44663
|
+
onRoomRecordedAvailable,
|
|
44664
|
+
onRoomParticipantJoined,
|
|
44665
|
+
onRoomParticipantLeft,
|
|
44666
|
+
onRoomParticipantRemoved,
|
|
44667
|
+
onRoomParticipantRemovedLocal,
|
|
44668
|
+
convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
44669
|
+
], {
|
|
44670
|
+
callbackDataSelector: (data) => {
|
|
44671
|
+
if (!data)
|
|
44672
|
+
return data;
|
|
44673
|
+
return LinkedObject.room(data);
|
|
44674
|
+
},
|
|
44675
|
+
});
|
|
44676
|
+
};
|
|
44677
|
+
|
|
44678
|
+
class RoomPaginationController extends PaginationController {
|
|
44679
|
+
async getRequest(queryParams, token) {
|
|
44680
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
44681
|
+
const baseOptions = {
|
|
44682
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
44683
|
+
};
|
|
44684
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
44685
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
|
|
44686
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
44687
|
+
});
|
|
44688
|
+
return queryResponse;
|
|
44689
|
+
}
|
|
44690
|
+
}
|
|
44691
|
+
|
|
44692
|
+
var EnumRoomActions;
|
|
44693
|
+
(function (EnumRoomActions) {
|
|
44694
|
+
EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
|
|
44695
|
+
EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
|
|
44696
|
+
EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
|
|
44697
|
+
EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
|
|
44698
|
+
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
44699
|
+
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
44700
|
+
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
44701
|
+
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
44702
|
+
|
|
44703
|
+
class RoomQueryStreamController extends QueryStreamController {
|
|
44704
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
44705
|
+
super(query, cacheKey);
|
|
44706
|
+
this.notifyChange = notifyChange;
|
|
44707
|
+
this.preparePayload = preparePayload;
|
|
44708
|
+
}
|
|
44709
|
+
async saveToMainDB(response) {
|
|
44710
|
+
const processedPayload = await this.preparePayload(response);
|
|
44711
|
+
const client = getActiveClient();
|
|
44712
|
+
const cachedAt = client.cache && Date.now();
|
|
44713
|
+
if (client.cache) {
|
|
44714
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
44715
|
+
}
|
|
44716
|
+
}
|
|
44717
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
44718
|
+
var _a, _b;
|
|
44719
|
+
if (refresh) {
|
|
44720
|
+
pushToCache(this.cacheKey, {
|
|
44721
|
+
data: response.rooms.map(getResolver('room')),
|
|
44722
|
+
});
|
|
44723
|
+
}
|
|
44724
|
+
else {
|
|
44725
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44726
|
+
const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
44727
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
|
|
44728
|
+
}
|
|
44729
|
+
}
|
|
44730
|
+
reactor(action) {
|
|
44731
|
+
return (room) => {
|
|
44732
|
+
var _a;
|
|
44733
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44734
|
+
if (!collection)
|
|
44735
|
+
return;
|
|
44736
|
+
if (action === EnumRoomActions.OnRoomDeleted) {
|
|
44737
|
+
collection.data = collection.data.filter(roomId => roomId !== room._id);
|
|
44738
|
+
}
|
|
44739
|
+
if (action === EnumRoomActions.OnRoomCreated) {
|
|
44740
|
+
collection.data = [...new Set([room._id, ...collection.data])];
|
|
44741
|
+
}
|
|
44742
|
+
pushToCache(this.cacheKey, collection);
|
|
44743
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44744
|
+
};
|
|
44745
|
+
}
|
|
44746
|
+
subscribeRTE(createSubscriber) {
|
|
44747
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
44748
|
+
}
|
|
44749
|
+
}
|
|
44750
|
+
|
|
44751
|
+
// TODO: confirm related events
|
|
44752
|
+
const getRoomSubscription = () => [
|
|
44753
|
+
{
|
|
44754
|
+
fn: onRoomStartBroadcasting,
|
|
44755
|
+
action: EnumRoomActions.OnRoomStartBroadcasting,
|
|
44756
|
+
},
|
|
44757
|
+
{
|
|
44758
|
+
fn: onRoomEndBroadcasting,
|
|
44759
|
+
action: EnumRoomActions.OnRoomEndBroadcasting,
|
|
44760
|
+
},
|
|
44761
|
+
{
|
|
44762
|
+
fn: onRoomRecordedAvailable,
|
|
44763
|
+
action: EnumRoomActions.OnRoomUpdated,
|
|
44764
|
+
},
|
|
44765
|
+
];
|
|
44766
|
+
|
|
44767
|
+
class RoomLiveCollectionController extends LiveCollectionController {
|
|
44768
|
+
constructor(query, callback) {
|
|
44769
|
+
const queryStreamId = hash(query);
|
|
44770
|
+
const cacheKey = ['rooms', 'collection', queryStreamId];
|
|
44771
|
+
const paginationController = new RoomPaginationController(query);
|
|
44772
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
44773
|
+
this.query = query;
|
|
44774
|
+
this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
44775
|
+
this.callback = callback.bind(this);
|
|
44776
|
+
this.loadPage({ initial: true });
|
|
44777
|
+
}
|
|
44778
|
+
setup() {
|
|
43741
44779
|
var _a;
|
|
43742
|
-
|
|
43743
|
-
|
|
43744
|
-
|
|
43745
|
-
|
|
43746
|
-
|
|
44780
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44781
|
+
if (!collection) {
|
|
44782
|
+
pushToCache(this.cacheKey, {
|
|
44783
|
+
data: [],
|
|
44784
|
+
params: {},
|
|
44785
|
+
});
|
|
44786
|
+
}
|
|
44787
|
+
}
|
|
44788
|
+
async persistModel(queryPayload) {
|
|
44789
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
44790
|
+
}
|
|
44791
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
44792
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44793
|
+
}
|
|
44794
|
+
startSubscription() {
|
|
44795
|
+
return this.queryStreamController.subscribeRTE(getRoomSubscription());
|
|
44796
|
+
}
|
|
44797
|
+
notifyChange({ origin, loading, error }) {
|
|
44798
|
+
var _a, _b;
|
|
44799
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44800
|
+
if (!collection)
|
|
44801
|
+
return;
|
|
44802
|
+
const data = this.applyFilter((_b = collection.data
|
|
44803
|
+
.map(id => pullFromCache(['room', 'get', id]))
|
|
44804
|
+
.filter(isNonNullable)
|
|
44805
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
|
|
44806
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
44807
|
+
return;
|
|
44808
|
+
this.callback({
|
|
44809
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
44810
|
+
data,
|
|
44811
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
44812
|
+
loading,
|
|
44813
|
+
error,
|
|
44814
|
+
});
|
|
44815
|
+
}
|
|
44816
|
+
applyFilter(data) {
|
|
44817
|
+
let rooms = data;
|
|
44818
|
+
if (!this.query.includeDeleted) {
|
|
44819
|
+
rooms = filterByPropEquality(rooms, 'isDeleted', false);
|
|
44820
|
+
}
|
|
44821
|
+
if (this.query.statuses && this.query.statuses.length > 0) {
|
|
44822
|
+
rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
|
|
44823
|
+
}
|
|
44824
|
+
if (this.query.type) {
|
|
44825
|
+
rooms = filterByPropEquality(rooms, 'type', this.query.type);
|
|
44826
|
+
}
|
|
44827
|
+
switch (this.query.sortBy) {
|
|
44828
|
+
case 'firstCreated':
|
|
44829
|
+
rooms = rooms.sort(sortByFirstCreated);
|
|
44830
|
+
break;
|
|
44831
|
+
case 'lastCreated':
|
|
44832
|
+
default:
|
|
44833
|
+
rooms = rooms.sort(sortByLastCreated);
|
|
44834
|
+
break;
|
|
44835
|
+
}
|
|
44836
|
+
return rooms;
|
|
44837
|
+
}
|
|
44838
|
+
}
|
|
44839
|
+
|
|
44840
|
+
/* begin_public_function
|
|
44841
|
+
id: room.get_rooms
|
|
44842
|
+
*/
|
|
44843
|
+
/**
|
|
44844
|
+
* ```js
|
|
44845
|
+
* import { RoomRepository } from '@amityco/ts-sdk'
|
|
44846
|
+
*
|
|
44847
|
+
* let rooms = []
|
|
44848
|
+
* const unsub = RoomRepository.getRooms({
|
|
44849
|
+
* type: 'direct_streaming',
|
|
44850
|
+
* statuses: ['live', 'idle'],
|
|
44851
|
+
* sortBy: 'lastCreated',
|
|
44852
|
+
* limit: 20,
|
|
44853
|
+
* includeDeleted: false
|
|
44854
|
+
* }, response => merge(rooms, response.data))
|
|
44855
|
+
* ```
|
|
44856
|
+
*
|
|
44857
|
+
* Observe all mutations on a list of {@link Amity.Room} for a given query
|
|
44858
|
+
*
|
|
44859
|
+
* @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
|
|
44860
|
+
* @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
|
|
44861
|
+
* @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
|
|
44862
|
+
* @param params.limit maximum number of rooms to retrieve per page
|
|
44863
|
+
* @param params.includeDeleted whether to include deleted rooms in the results
|
|
44864
|
+
* @param callback the function to call when new data are available
|
|
44865
|
+
* @param config optional configuration for the live collection
|
|
44866
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
|
|
44867
|
+
*
|
|
44868
|
+
* @category Rooms Live Collection
|
|
44869
|
+
*/
|
|
44870
|
+
const getRooms = (params, callback, config) => {
|
|
44871
|
+
const { log, cache } = getActiveClient();
|
|
44872
|
+
if (!cache) {
|
|
44873
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
44874
|
+
}
|
|
44875
|
+
const timestamp = Date.now();
|
|
44876
|
+
log(`getRooms(tmpid: ${timestamp}) > listen`);
|
|
44877
|
+
const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
|
|
44878
|
+
const disposers = roomsLiveCollection.startSubscription();
|
|
44879
|
+
const cacheKey = roomsLiveCollection.getCacheKey();
|
|
44880
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
44881
|
+
return () => {
|
|
44882
|
+
log(`getRooms(tmpid: ${timestamp}) > dispose`);
|
|
44883
|
+
disposers.forEach(fn => fn());
|
|
44884
|
+
};
|
|
44885
|
+
};
|
|
44886
|
+
/* end_public_function */
|
|
44887
|
+
|
|
44888
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
44889
|
+
__proto__: null,
|
|
44890
|
+
createRoom: createRoom,
|
|
44891
|
+
updateRoom: updateRoom,
|
|
44892
|
+
deleteRoom: deleteRoom,
|
|
44893
|
+
stopRoom: stopRoom,
|
|
44894
|
+
getBroadcasterData: getBroadcasterData,
|
|
44895
|
+
getRecordedUrl: getRecordedUrl,
|
|
44896
|
+
removeParticipant: removeParticipant,
|
|
44897
|
+
leaveRoom: leaveRoom,
|
|
44898
|
+
onRoomStartBroadcasting: onRoomStartBroadcasting,
|
|
44899
|
+
onRoomWaitingReconnect: onRoomWaitingReconnect,
|
|
44900
|
+
onRoomEndBroadcasting: onRoomEndBroadcasting,
|
|
44901
|
+
onRoomRecordedAvailable: onRoomRecordedAvailable,
|
|
44902
|
+
onRoomCoHostInvited: onRoomCoHostInvited,
|
|
44903
|
+
onRoomCoHostInviteAccepted: onRoomCoHostInviteAccepted,
|
|
44904
|
+
onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
|
|
44905
|
+
onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
|
|
44906
|
+
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
44907
|
+
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
44908
|
+
onRoomCreated: onRoomCreated,
|
|
44909
|
+
onRoomUpdated: onRoomUpdated,
|
|
44910
|
+
onRoomDeleted: onRoomDeleted,
|
|
44911
|
+
onRoomStopped: onRoomStopped,
|
|
44912
|
+
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
44913
|
+
onRoomLeft: onRoomLeft,
|
|
44914
|
+
getRoom: getRoom,
|
|
44915
|
+
getRooms: getRooms
|
|
44916
|
+
});
|
|
44917
|
+
|
|
44918
|
+
class LiveRoomPostLiveCollectionController extends LiveCollectionController {
|
|
44919
|
+
constructor(callback) {
|
|
44920
|
+
const query = { limit: 100 };
|
|
44921
|
+
const queryStreamId = hash(query);
|
|
44922
|
+
const cacheKey = ['liveRoomPosts', 'collection', queryStreamId];
|
|
44923
|
+
const paginationController = new LiveRoomPostPaginationController(query);
|
|
44924
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
44925
|
+
this.query = query;
|
|
44926
|
+
this.queryStreamController = new LiveRoomPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
44927
|
+
this.callback = callback.bind(this);
|
|
44928
|
+
this.loadPage({ initial: true });
|
|
44929
|
+
}
|
|
44930
|
+
setup() {
|
|
44931
|
+
var _a;
|
|
44932
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44933
|
+
if (!collection) {
|
|
44934
|
+
pushToCache(this.cacheKey, {
|
|
44935
|
+
data: [],
|
|
44936
|
+
params: {},
|
|
44937
|
+
});
|
|
44938
|
+
}
|
|
44939
|
+
}
|
|
44940
|
+
async persistModel(queryPayload) {
|
|
44941
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
44942
|
+
}
|
|
44943
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
44944
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44945
|
+
}
|
|
44946
|
+
startSubscription() {
|
|
44947
|
+
return this.queryStreamController.subscribeRTE([
|
|
44948
|
+
{ fn: onRoomEndBroadcasting, action: EnumPostActions.OnPostUpdated },
|
|
44949
|
+
]);
|
|
44950
|
+
}
|
|
44951
|
+
notifyChange({ origin, loading, error }) {
|
|
44952
|
+
var _a, _b;
|
|
44953
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44954
|
+
if (!collection)
|
|
43747
44955
|
return;
|
|
43748
|
-
|
|
43749
|
-
|
|
43750
|
-
|
|
43751
|
-
};
|
|
44956
|
+
const data = this.applyFilter((_b = collection.data
|
|
44957
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
44958
|
+
.filter(isNonNullable)
|
|
44959
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
44960
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
44961
|
+
return;
|
|
44962
|
+
this.callback({
|
|
44963
|
+
data,
|
|
44964
|
+
loading,
|
|
44965
|
+
error,
|
|
44966
|
+
});
|
|
44967
|
+
}
|
|
44968
|
+
// eslint-disable-next-line class-methods-use-this
|
|
44969
|
+
applyFilter(data) {
|
|
44970
|
+
// No additional filtering needed for live room posts
|
|
44971
|
+
// API handles all filtering based on targetId and targetType
|
|
44972
|
+
return data;
|
|
44973
|
+
}
|
|
44974
|
+
}
|
|
43752
44975
|
|
|
43753
|
-
/* eslint-disable no-use-before-define */
|
|
43754
44976
|
/* begin_public_function
|
|
43755
|
-
id:
|
|
44977
|
+
id: post.liveRoom.query
|
|
43756
44978
|
*/
|
|
43757
44979
|
/**
|
|
43758
44980
|
* ```js
|
|
43759
|
-
* import {
|
|
43760
|
-
* const unsub = StreamRepository.getStreamById('foobar')
|
|
43761
|
-
* unsub()
|
|
43762
|
-
* ```
|
|
43763
|
-
*
|
|
43764
|
-
* Fetches a {@link Amity.Stream} object
|
|
43765
|
-
*
|
|
43766
|
-
* @param streamId the ID of the {@link Amity.Stream} to get
|
|
43767
|
-
* @param callback
|
|
43768
|
-
* @returns the associated {@link Amity.Stream} object
|
|
44981
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43769
44982
|
*
|
|
43770
|
-
*
|
|
43771
|
-
|
|
43772
|
-
|
|
43773
|
-
|
|
43774
|
-
|
|
43775
|
-
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
|
|
43776
|
-
};
|
|
43777
|
-
return liveObject(streamId, reactor, 'streamId', getStream, [
|
|
43778
|
-
onStreamRecorded,
|
|
43779
|
-
onStreamStarted,
|
|
43780
|
-
onStreamStopped,
|
|
43781
|
-
onStreamFlagged,
|
|
43782
|
-
onStreamTerminated,
|
|
43783
|
-
onStreamViewerBanned,
|
|
43784
|
-
]);
|
|
43785
|
-
};
|
|
43786
|
-
/* end_public_function */
|
|
43787
|
-
/**
|
|
43788
|
-
* ```js
|
|
43789
|
-
* import { StreamRepository } from '@amityco/ts-sdk'
|
|
43790
|
-
* const stream = StreamRepository.getStreamById.locally('foobar')
|
|
44983
|
+
* let posts = []
|
|
44984
|
+
* const unsub = PostRepository.getLiveRoomPosts({
|
|
44985
|
+
* targetType: Amity.PostTargetType,
|
|
44986
|
+
* targetId: Amity.Post['targetId'],
|
|
44987
|
+
* }, response => merge(posts, response.data))
|
|
43791
44988
|
* ```
|
|
43792
44989
|
*
|
|
43793
|
-
*
|
|
44990
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given live room
|
|
43794
44991
|
*
|
|
43795
|
-
* @param
|
|
43796
|
-
* @
|
|
44992
|
+
* @param params.targetType the type of the target
|
|
44993
|
+
* @param params.targetId the ID of the target
|
|
44994
|
+
* @param callback the function to call when new data are available
|
|
44995
|
+
* @param config
|
|
44996
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
|
|
43797
44997
|
*
|
|
43798
|
-
* @category
|
|
44998
|
+
* @category Posts Live Collection
|
|
43799
44999
|
*/
|
|
43800
|
-
|
|
43801
|
-
const
|
|
43802
|
-
|
|
43803
|
-
|
|
43804
|
-
|
|
43805
|
-
const
|
|
43806
|
-
|
|
43807
|
-
|
|
43808
|
-
|
|
43809
|
-
|
|
43810
|
-
|
|
45000
|
+
const getLiveRoomPosts = (callback) => {
|
|
45001
|
+
const { log, cache } = getActiveClient();
|
|
45002
|
+
if (!cache) {
|
|
45003
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
45004
|
+
}
|
|
45005
|
+
const timestamp = Date.now();
|
|
45006
|
+
log(`getLiveRoomPosts(tmpid: ${timestamp}) > listen`);
|
|
45007
|
+
const liveRoomPostsLiveCollection = new LiveRoomPostLiveCollectionController(callback);
|
|
45008
|
+
const disposers = liveRoomPostsLiveCollection.startSubscription();
|
|
45009
|
+
const cacheKey = liveRoomPostsLiveCollection.getCacheKey();
|
|
45010
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
45011
|
+
return () => {
|
|
45012
|
+
log(`getLiveRoomPosts(tmpid: ${timestamp}) > dispose`);
|
|
45013
|
+
disposers.forEach(fn => fn());
|
|
43811
45014
|
};
|
|
43812
45015
|
};
|
|
45016
|
+
/* end_public_function */
|
|
43813
45017
|
|
|
43814
|
-
class
|
|
43815
|
-
async getRequest(queryParams
|
|
43816
|
-
const { limit =
|
|
43817
|
-
const
|
|
43818
|
-
|
|
43819
|
-
|
|
45018
|
+
class CommunityLiveRoomPostPaginationController extends PaginationNoPageController {
|
|
45019
|
+
async getRequest(queryParams) {
|
|
45020
|
+
const { limit = 100, communityIds } = queryParams;
|
|
45021
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/rooms/lives`, {
|
|
45022
|
+
params: {
|
|
45023
|
+
targetTypes: ['community'],
|
|
45024
|
+
targetIds: communityIds,
|
|
45025
|
+
options: {
|
|
45026
|
+
limit,
|
|
45027
|
+
sortBy: 'lastCreated',
|
|
45028
|
+
},
|
|
45029
|
+
},
|
|
43820
45030
|
});
|
|
43821
|
-
return
|
|
45031
|
+
return queryResponse;
|
|
43822
45032
|
}
|
|
43823
45033
|
}
|
|
43824
45034
|
|
|
43825
|
-
class
|
|
43826
|
-
constructor(query, cacheKey, notifyChange,
|
|
45035
|
+
class CommunityLiveRoomPostQueryStreamController extends QueryStreamController {
|
|
45036
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
43827
45037
|
super(query, cacheKey);
|
|
43828
45038
|
this.notifyChange = notifyChange;
|
|
43829
|
-
this.
|
|
45039
|
+
this.preparePayload = preparePayload;
|
|
43830
45040
|
}
|
|
43831
|
-
|
|
43832
|
-
|
|
45041
|
+
async saveToMainDB(response) {
|
|
45042
|
+
const processedPayload = await this.preparePayload(response);
|
|
43833
45043
|
const client = getActiveClient();
|
|
43834
45044
|
const cachedAt = client.cache && Date.now();
|
|
43835
45045
|
if (client.cache) {
|
|
43836
|
-
ingestInCache(
|
|
45046
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
43837
45047
|
}
|
|
43838
45048
|
}
|
|
43839
45049
|
appendToQueryStream(response, direction, refresh = false) {
|
|
43840
45050
|
var _a, _b;
|
|
43841
45051
|
if (refresh) {
|
|
43842
45052
|
pushToCache(this.cacheKey, {
|
|
43843
|
-
data: response.
|
|
43844
|
-
query: this.query,
|
|
45053
|
+
data: response.posts.map(getResolver('post')),
|
|
43845
45054
|
});
|
|
43846
45055
|
}
|
|
43847
45056
|
else {
|
|
43848
45057
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43849
|
-
const
|
|
43850
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data:
|
|
43851
|
-
? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
|
|
43852
|
-
: [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])] }));
|
|
45058
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
45059
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
43853
45060
|
}
|
|
43854
45061
|
}
|
|
43855
45062
|
reactor(action) {
|
|
43856
|
-
return (
|
|
45063
|
+
return (room) => {
|
|
43857
45064
|
var _a;
|
|
43858
45065
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43859
45066
|
if (!collection)
|
|
43860
45067
|
return;
|
|
43861
|
-
|
|
43862
|
-
|
|
45068
|
+
if (room.status === 'ended') {
|
|
45069
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: collection.data.filter(postId => room.referenceId !== postId) }));
|
|
45070
|
+
}
|
|
43863
45071
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
43864
45072
|
};
|
|
43865
45073
|
}
|
|
@@ -43868,54 +45076,17 @@ class GetStreamsQueryStreamController extends QueryStreamController {
|
|
|
43868
45076
|
}
|
|
43869
45077
|
}
|
|
43870
45078
|
|
|
43871
|
-
class
|
|
45079
|
+
class CommunityLiveRoomPostLiveCollectionController extends LiveCollectionController {
|
|
43872
45080
|
constructor(query, callback) {
|
|
43873
45081
|
const queryStreamId = hash(query);
|
|
43874
|
-
const cacheKey = ['
|
|
43875
|
-
const paginationController = new
|
|
45082
|
+
const cacheKey = ['communityLiveRoomPosts', 'collection', queryStreamId];
|
|
45083
|
+
const paginationController = new CommunityLiveRoomPostPaginationController(query);
|
|
43876
45084
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
43877
|
-
this.applyFilter = (data) => {
|
|
43878
|
-
let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
|
|
43879
|
-
streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
43880
|
-
return streams;
|
|
43881
|
-
};
|
|
43882
45085
|
this.query = query;
|
|
43883
|
-
this.queryStreamController = new
|
|
43884
|
-
this.paginationController = paginationController;
|
|
45086
|
+
this.queryStreamController = new CommunityLiveRoomPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
43885
45087
|
this.callback = callback.bind(this);
|
|
43886
45088
|
this.loadPage({ initial: true });
|
|
43887
45089
|
}
|
|
43888
|
-
notifyChange({ origin, loading, error }) {
|
|
43889
|
-
var _a;
|
|
43890
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43891
|
-
if (!collection)
|
|
43892
|
-
return;
|
|
43893
|
-
let data = collection.data
|
|
43894
|
-
.map(streamId => pullFromCache(['stream', 'get', streamId]))
|
|
43895
|
-
.filter(Boolean)
|
|
43896
|
-
.map(stream => LinkedObject.stream(stream.data));
|
|
43897
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
43898
|
-
return;
|
|
43899
|
-
data = this.applyFilter(data);
|
|
43900
|
-
this.callback({
|
|
43901
|
-
onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
43902
|
-
data,
|
|
43903
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
43904
|
-
loading,
|
|
43905
|
-
error,
|
|
43906
|
-
});
|
|
43907
|
-
}
|
|
43908
|
-
startSubscription() {
|
|
43909
|
-
return this.queryStreamController.subscribeRTE([
|
|
43910
|
-
{ fn: onStreamRecorded, action: 'onStreamRecorded' },
|
|
43911
|
-
{ fn: onStreamStarted, action: 'onStreamStarted' },
|
|
43912
|
-
{ fn: onStreamStopped, action: 'onStreamStopped' },
|
|
43913
|
-
{ fn: onStreamFlagged, action: 'onStreamFlagged' },
|
|
43914
|
-
{ fn: onStreamTerminated, action: 'onStreamTerminated' },
|
|
43915
|
-
{ fn: onStreamViewerBanned, action: 'onStreamViewerBanned' },
|
|
43916
|
-
{ fn: onStreamViewerUnbanned, action: 'onStreamViewerUnbanned' },
|
|
43917
|
-
]);
|
|
43918
|
-
}
|
|
43919
45090
|
setup() {
|
|
43920
45091
|
var _a;
|
|
43921
45092
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -43926,822 +45097,599 @@ class GetStreamsLiveCollectionController extends LiveCollectionController {
|
|
|
43926
45097
|
});
|
|
43927
45098
|
}
|
|
43928
45099
|
}
|
|
43929
|
-
persistModel(
|
|
43930
|
-
this.queryStreamController.saveToMainDB(
|
|
45100
|
+
async persistModel(queryPayload) {
|
|
45101
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
43931
45102
|
}
|
|
43932
45103
|
persistQueryStream({ response, direction, refresh, }) {
|
|
43933
45104
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
43934
45105
|
}
|
|
43935
|
-
|
|
43936
|
-
|
|
43937
|
-
|
|
43938
|
-
|
|
43939
|
-
if (!cache) {
|
|
43940
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
45106
|
+
startSubscription() {
|
|
45107
|
+
return this.queryStreamController.subscribeRTE([
|
|
45108
|
+
{ fn: onRoomEndBroadcasting, action: EnumPostActions.OnPostUpdated },
|
|
45109
|
+
]);
|
|
43941
45110
|
}
|
|
43942
|
-
|
|
43943
|
-
|
|
43944
|
-
|
|
43945
|
-
|
|
43946
|
-
|
|
43947
|
-
|
|
43948
|
-
|
|
43949
|
-
|
|
43950
|
-
|
|
43951
|
-
|
|
43952
|
-
|
|
43953
|
-
|
|
43954
|
-
|
|
43955
|
-
|
|
43956
|
-
|
|
43957
|
-
|
|
43958
|
-
|
|
43959
|
-
|
|
43960
|
-
|
|
43961
|
-
|
|
43962
|
-
|
|
43963
|
-
|
|
43964
|
-
|
|
43965
|
-
|
|
43966
|
-
onStreamFlagged: onStreamFlagged,
|
|
43967
|
-
onStreamTerminated: onStreamTerminated,
|
|
43968
|
-
onStreamViewerBanned: onStreamViewerBanned,
|
|
43969
|
-
onStreamViewerUnbanned: onStreamViewerUnbanned,
|
|
43970
|
-
getStreamById: getStreamById,
|
|
43971
|
-
getStreams: getStreams
|
|
43972
|
-
});
|
|
43973
|
-
|
|
43974
|
-
/* begin_public_function
|
|
43975
|
-
id: room.create
|
|
43976
|
-
*/
|
|
43977
|
-
/**
|
|
43978
|
-
* ```js
|
|
43979
|
-
* import { createRoom } from '@amityco/ts-sdk'
|
|
43980
|
-
* const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
|
|
43981
|
-
* ```
|
|
43982
|
-
*
|
|
43983
|
-
* Creates an {@link Amity.Room}
|
|
43984
|
-
*
|
|
43985
|
-
* @param bundle The data necessary to create a new {@link Amity.Room}
|
|
43986
|
-
* @returns The newly created {@link Amity.Room}
|
|
43987
|
-
*
|
|
43988
|
-
* @category Room API
|
|
43989
|
-
* @async
|
|
43990
|
-
*/
|
|
43991
|
-
const createRoom = async (bundle) => {
|
|
43992
|
-
const client = getActiveClient();
|
|
43993
|
-
client.log('room/createRoom', bundle);
|
|
43994
|
-
const { data } = await client.http.post('/api/v1/rooms', bundle);
|
|
43995
|
-
fireEvent('local.room.created', data);
|
|
43996
|
-
const cachedAt = client.cache && Date.now();
|
|
43997
|
-
// TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
|
|
43998
|
-
if (client.cache)
|
|
43999
|
-
ingestInCache(data, { cachedAt });
|
|
44000
|
-
const { rooms } = data;
|
|
44001
|
-
return {
|
|
44002
|
-
data: roomLinkedObject(rooms[0]),
|
|
44003
|
-
cachedAt,
|
|
44004
|
-
};
|
|
44005
|
-
};
|
|
44006
|
-
/* end_public_function */
|
|
44007
|
-
|
|
44008
|
-
/* begin_public_function
|
|
44009
|
-
id: room.update
|
|
44010
|
-
*/
|
|
44011
|
-
/**
|
|
44012
|
-
* ```js
|
|
44013
|
-
* import { updateRoom } from '@amityco/ts-sdk'
|
|
44014
|
-
* const updated = await updateRoom('roomId', { title: 'updated title' })
|
|
44015
|
-
* ```
|
|
44016
|
-
*
|
|
44017
|
-
* Updates an {@link Amity.InternalRoom}
|
|
44018
|
-
*
|
|
44019
|
-
* @param roomId The ID of the room to update
|
|
44020
|
-
* @param bundle The data to update the room with
|
|
44021
|
-
* @returns The updated {@link Amity.InternalRoom}
|
|
44022
|
-
*
|
|
44023
|
-
* @category Room API
|
|
44024
|
-
* @async
|
|
44025
|
-
*/
|
|
44026
|
-
const updateRoom = async (roomId, bundle) => {
|
|
44027
|
-
const client = getActiveClient();
|
|
44028
|
-
client.log('room/updateRoom', { roomId, bundle });
|
|
44029
|
-
const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
|
|
44030
|
-
fireEvent('local.room.updated', data);
|
|
44031
|
-
const cachedAt = client.cache && Date.now();
|
|
44032
|
-
if (client.cache)
|
|
44033
|
-
ingestInCache(data, { cachedAt });
|
|
44034
|
-
const { rooms } = data;
|
|
44035
|
-
return {
|
|
44036
|
-
data: roomLinkedObject(rooms[0]),
|
|
44037
|
-
cachedAt,
|
|
44038
|
-
};
|
|
44039
|
-
};
|
|
44040
|
-
/* end_public_function */
|
|
44041
|
-
|
|
44042
|
-
/* begin_public_function
|
|
44043
|
-
id: room.delete
|
|
44044
|
-
*/
|
|
44045
|
-
/**
|
|
44046
|
-
* ```js
|
|
44047
|
-
* import { deleteRoom } from '@amityco/ts-sdk'
|
|
44048
|
-
* const result = await deleteRoom('roomId')
|
|
44049
|
-
* ```
|
|
44050
|
-
*
|
|
44051
|
-
* Deletes an {@link Amity.Room}
|
|
44052
|
-
*
|
|
44053
|
-
* @param roomId The ID of the room to delete
|
|
44054
|
-
* @returns Promise that resolves when the room is deleted
|
|
44055
|
-
*
|
|
44056
|
-
* @category Room API
|
|
44057
|
-
* @async
|
|
44058
|
-
*/
|
|
44059
|
-
const deleteRoom = async (roomId) => {
|
|
44060
|
-
const client = getActiveClient();
|
|
44061
|
-
client.log('room/deleteRoom', { roomId });
|
|
44062
|
-
await client.http.delete(`/api/v1/rooms/${roomId}`);
|
|
44063
|
-
fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
|
|
44064
|
-
};
|
|
44065
|
-
/* end_public_function */
|
|
44066
|
-
|
|
44067
|
-
/* begin_public_function
|
|
44068
|
-
id: room.stop
|
|
44069
|
-
*/
|
|
44070
|
-
/**
|
|
44071
|
-
* ```js
|
|
44072
|
-
* import { stopRoom } from '@amityco/ts-sdk'
|
|
44073
|
-
* const result = await stopRoom('roomId')
|
|
44074
|
-
* ```
|
|
44075
|
-
*
|
|
44076
|
-
* Stops a room's broadcasting
|
|
44077
|
-
*
|
|
44078
|
-
* @param roomId The ID of the room to stop
|
|
44079
|
-
* @returns The updated room data
|
|
44080
|
-
*
|
|
44081
|
-
* @category Room API
|
|
44082
|
-
* @async
|
|
44083
|
-
*/
|
|
44084
|
-
const stopRoom = async (roomId) => {
|
|
44085
|
-
const client = getActiveClient();
|
|
44086
|
-
client.log('room/stopRoom', { roomId });
|
|
44087
|
-
const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
|
|
44088
|
-
fireEvent('local.room.stopped', data);
|
|
44089
|
-
const cachedAt = client.cache && Date.now();
|
|
44090
|
-
if (client.cache)
|
|
44091
|
-
ingestInCache(data, { cachedAt });
|
|
44092
|
-
const { rooms } = data;
|
|
44093
|
-
return {
|
|
44094
|
-
data: rooms[0],
|
|
44095
|
-
cachedAt,
|
|
44096
|
-
};
|
|
44097
|
-
};
|
|
44098
|
-
/* end_public_function */
|
|
44099
|
-
|
|
44100
|
-
/* begin_public_function
|
|
44101
|
-
id: room.getBroadcasterData
|
|
44102
|
-
*/
|
|
44103
|
-
/**
|
|
44104
|
-
* ```js
|
|
44105
|
-
* import { getBroadcasterData } from '@amityco/ts-sdk'
|
|
44106
|
-
* const token = await getBroadcasterData('roomId')
|
|
44107
|
-
* ```
|
|
44108
|
-
*
|
|
44109
|
-
* Gets broadcaster data for a room
|
|
44110
|
-
*
|
|
44111
|
-
* @param roomId The ID of the room to get token for
|
|
44112
|
-
* @returns The broadcaster data of the room including coHostToken, coHostUrl and direactStreamUrl
|
|
44113
|
-
*
|
|
44114
|
-
* @category Room API
|
|
44115
|
-
* @async
|
|
44116
|
-
*/
|
|
44117
|
-
const getBroadcasterData = async (roomId) => {
|
|
44118
|
-
const client = getActiveClient();
|
|
44119
|
-
client.log('room/getBroadcasterData', { roomId });
|
|
44120
|
-
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
|
|
44121
|
-
return data;
|
|
44122
|
-
};
|
|
44123
|
-
/* end_public_function */
|
|
44124
|
-
|
|
44125
|
-
/* begin_public_function
|
|
44126
|
-
id: room.getRecordedUrl
|
|
44127
|
-
*/
|
|
44128
|
-
/**
|
|
44129
|
-
* ```js
|
|
44130
|
-
* import { getRecordedUrl } from '@amityco/ts-sdk'
|
|
44131
|
-
* const recordedUrl = await getRecordedUrl('roomId')
|
|
44132
|
-
* ```
|
|
44133
|
-
*
|
|
44134
|
-
* Gets the recorded URL for a room
|
|
44135
|
-
*
|
|
44136
|
-
* @param roomId The ID of the room to get recorded URL for
|
|
44137
|
-
* @returns The recorded URL information
|
|
44138
|
-
*
|
|
44139
|
-
* @category Room API
|
|
44140
|
-
* @async
|
|
44141
|
-
*/
|
|
44142
|
-
const getRecordedUrl = async (roomId) => {
|
|
44143
|
-
const client = getActiveClient();
|
|
44144
|
-
client.log('room/getRecordedUrl', { roomId });
|
|
44145
|
-
const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
|
|
44146
|
-
return data;
|
|
44147
|
-
};
|
|
44148
|
-
/* end_public_function */
|
|
44149
|
-
|
|
44150
|
-
/* begin_public_function
|
|
44151
|
-
id: room.removeParticipant
|
|
44152
|
-
*/
|
|
44153
|
-
/**
|
|
44154
|
-
* ```js
|
|
44155
|
-
* import { removeParticipant } from '@amityco/ts-sdk'
|
|
44156
|
-
* const result = await removeParticipant('roomId', 'participantUserId')
|
|
44157
|
-
* ```
|
|
44158
|
-
*
|
|
44159
|
-
* Removes a participant from an {@link Amity.Room}
|
|
44160
|
-
*
|
|
44161
|
-
* @param roomId The ID of the room to remove participant from
|
|
44162
|
-
* @param participantUserId The ID of the user to remove as participant
|
|
44163
|
-
* @returns Promise that resolves when the participant is removed
|
|
44164
|
-
*
|
|
44165
|
-
* @category Room API
|
|
44166
|
-
* @async
|
|
44167
|
-
*/
|
|
44168
|
-
const removeParticipant = async (roomId, participantUserId) => {
|
|
44169
|
-
const client = getActiveClient();
|
|
44170
|
-
client.log('room/removeParticipant', { roomId, participantUserId });
|
|
44171
|
-
await client.http.delete(`/api/v1/rooms/${roomId}/participants/${participantUserId}`);
|
|
44172
|
-
fireEvent('local.room.participantRemoved', {
|
|
44173
|
-
rooms: [{ _id: roomId }],
|
|
44174
|
-
users: [{ _id: participantUserId }],
|
|
44175
|
-
});
|
|
44176
|
-
};
|
|
44177
|
-
/* end_public_function */
|
|
44178
|
-
|
|
44179
|
-
/* begin_public_function
|
|
44180
|
-
id: room.leave
|
|
44181
|
-
*/
|
|
44182
|
-
/**
|
|
44183
|
-
* ```js
|
|
44184
|
-
* import { leaveRoom } from '@amityco/ts-sdk'
|
|
44185
|
-
* const result = await leaveRoom('roomId')
|
|
44186
|
-
* ```
|
|
44187
|
-
*
|
|
44188
|
-
* Leaves an {@link Amity.Room}
|
|
44189
|
-
*
|
|
44190
|
-
* @param roomId The ID of the room to leave
|
|
44191
|
-
* @returns Promise that resolves when the user has left the room
|
|
44192
|
-
*
|
|
44193
|
-
* @category Room API
|
|
44194
|
-
* @async
|
|
44195
|
-
*/
|
|
44196
|
-
const leaveRoom = async (roomId) => {
|
|
44197
|
-
const client = getActiveClient();
|
|
44198
|
-
client.log('room/leaveRoom', { roomId });
|
|
44199
|
-
await client.http.post(`/api/v1/rooms/${roomId}/leave`);
|
|
44200
|
-
fireEvent('local.room.left', {
|
|
44201
|
-
rooms: [{ _id: roomId }],
|
|
44202
|
-
});
|
|
44203
|
-
};
|
|
44204
|
-
/* end_public_function */
|
|
44205
|
-
|
|
44206
|
-
/**
|
|
44207
|
-
* ```js
|
|
44208
|
-
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
44209
|
-
* const dispose = onRoomStartBroadcasting(room => {
|
|
44210
|
-
* // ...
|
|
44211
|
-
* })
|
|
44212
|
-
* ```
|
|
44213
|
-
*
|
|
44214
|
-
* Fired when a {@link Amity.Room} has started broadcasting
|
|
44215
|
-
*
|
|
44216
|
-
* @param callback The function to call when the event was fired
|
|
44217
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44218
|
-
*
|
|
44219
|
-
* @category Room Events
|
|
44220
|
-
*/
|
|
44221
|
-
const onRoomStartBroadcasting = (callback) => {
|
|
44222
|
-
const client = getActiveClient();
|
|
44223
|
-
const filter = (payload) => {
|
|
44224
|
-
ingestInCache(payload);
|
|
44225
|
-
callback(payload.rooms[0]);
|
|
44226
|
-
};
|
|
44227
|
-
return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
|
|
44228
|
-
};
|
|
44229
|
-
|
|
44230
|
-
/**
|
|
44231
|
-
* ```js
|
|
44232
|
-
* import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
|
|
44233
|
-
* const dispose = onRoomWaitingReconnect(room => {
|
|
44234
|
-
* // ...
|
|
44235
|
-
* })
|
|
44236
|
-
* ```
|
|
44237
|
-
*
|
|
44238
|
-
* Fired when a {@link Amity.Room} is waiting for reconnection
|
|
44239
|
-
*
|
|
44240
|
-
* @param callback The function to call when the event was fired
|
|
44241
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44242
|
-
*
|
|
44243
|
-
* @category Room Events
|
|
44244
|
-
*/
|
|
44245
|
-
const onRoomWaitingReconnect = (callback) => {
|
|
44246
|
-
const client = getActiveClient();
|
|
44247
|
-
const filter = (payload) => {
|
|
44248
|
-
ingestInCache(payload);
|
|
44249
|
-
callback(payload.rooms[0]);
|
|
44250
|
-
};
|
|
44251
|
-
return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
|
|
44252
|
-
};
|
|
45111
|
+
notifyChange({ origin, loading, error }) {
|
|
45112
|
+
var _a, _b;
|
|
45113
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45114
|
+
if (!collection)
|
|
45115
|
+
return;
|
|
45116
|
+
const data = this.applyFilter((_b = collection.data
|
|
45117
|
+
.map((id) => pullFromCache(['post', 'get', id]))
|
|
45118
|
+
.filter(isNonNullable)
|
|
45119
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
45120
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
45121
|
+
return;
|
|
45122
|
+
this.callback({
|
|
45123
|
+
data,
|
|
45124
|
+
loading,
|
|
45125
|
+
error,
|
|
45126
|
+
});
|
|
45127
|
+
}
|
|
45128
|
+
// eslint-disable-next-line class-methods-use-this
|
|
45129
|
+
applyFilter(data) {
|
|
45130
|
+
// No additional filtering needed for live room posts
|
|
45131
|
+
// API handles all filtering based on targetId and targetType
|
|
45132
|
+
return data;
|
|
45133
|
+
}
|
|
45134
|
+
}
|
|
44253
45135
|
|
|
45136
|
+
/* begin_public_function
|
|
45137
|
+
id: post.communityLiveRoom.query
|
|
45138
|
+
*/
|
|
44254
45139
|
/**
|
|
44255
45140
|
* ```js
|
|
44256
|
-
* import {
|
|
44257
|
-
*
|
|
44258
|
-
*
|
|
44259
|
-
*
|
|
45141
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
45142
|
+
*
|
|
45143
|
+
* let posts = []
|
|
45144
|
+
* const unsub = PostRepository.getCommunityLiveRoomPosts({
|
|
45145
|
+
* targetId: 'communityId',
|
|
45146
|
+
* }, response => merge(posts, response.data))
|
|
44260
45147
|
* ```
|
|
44261
45148
|
*
|
|
44262
|
-
*
|
|
45149
|
+
* Observe all mutations on a list of {@link Amity.Post} for live rooms in a specific community
|
|
44263
45150
|
*
|
|
44264
|
-
* @param
|
|
44265
|
-
* @
|
|
45151
|
+
* @param params.targetId the ID of the community
|
|
45152
|
+
* @param params.limit optional limit for the number of posts to fetch
|
|
45153
|
+
* @param callback the function to call when new data are available
|
|
45154
|
+
* @param config
|
|
45155
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
|
|
44266
45156
|
*
|
|
44267
|
-
* @category
|
|
45157
|
+
* @category Posts Live Collection
|
|
44268
45158
|
*/
|
|
44269
|
-
const
|
|
44270
|
-
const
|
|
44271
|
-
|
|
44272
|
-
|
|
44273
|
-
|
|
45159
|
+
const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
45160
|
+
const { log, cache } = getActiveClient();
|
|
45161
|
+
if (!cache) {
|
|
45162
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
45163
|
+
}
|
|
45164
|
+
const timestamp = Date.now();
|
|
45165
|
+
log(`getCommunityLiveRoomPosts(tmpid: ${timestamp}) > listen`);
|
|
45166
|
+
const communityLiveRoomPostsLiveCollection = new CommunityLiveRoomPostLiveCollectionController(params, callback);
|
|
45167
|
+
const disposers = communityLiveRoomPostsLiveCollection.startSubscription();
|
|
45168
|
+
const cacheKey = communityLiveRoomPostsLiveCollection.getCacheKey();
|
|
45169
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
45170
|
+
return () => {
|
|
45171
|
+
log(`getCommunityLiveRoomPosts(tmpid: ${timestamp}) > dispose`);
|
|
45172
|
+
disposers.forEach(fn => fn());
|
|
44274
45173
|
};
|
|
44275
|
-
return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
|
|
44276
45174
|
};
|
|
45175
|
+
/* end_public_function */
|
|
45176
|
+
|
|
45177
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
45178
|
+
__proto__: null,
|
|
45179
|
+
getPostByIds: getPostByIds,
|
|
45180
|
+
createPost: createPost,
|
|
45181
|
+
editPost: editPost,
|
|
45182
|
+
deletePost: deletePost,
|
|
45183
|
+
softDeletePost: softDeletePost,
|
|
45184
|
+
hardDeletePost: hardDeletePost,
|
|
45185
|
+
approvePost: approvePost,
|
|
45186
|
+
declinePost: declinePost,
|
|
45187
|
+
flagPost: flagPost,
|
|
45188
|
+
unflagPost: unflagPost,
|
|
45189
|
+
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
45190
|
+
createClipPost: createClipPost,
|
|
45191
|
+
createAudioPost: createAudioPost,
|
|
45192
|
+
createMixedMediaPost: createMixedMediaPost,
|
|
45193
|
+
onPostCreated: onPostCreated,
|
|
45194
|
+
onPostUpdated: onPostUpdated,
|
|
45195
|
+
onPostDeleted: onPostDeleted,
|
|
45196
|
+
onPostApproved: onPostApproved,
|
|
45197
|
+
onPostDeclined: onPostDeclined,
|
|
45198
|
+
onPostFlagged: onPostFlagged,
|
|
45199
|
+
onPostUnflagged: onPostUnflagged,
|
|
45200
|
+
onPostReactionAdded: onPostReactionAdded,
|
|
45201
|
+
onPostReactionRemoved: onPostReactionRemoved,
|
|
45202
|
+
getPost: getPost,
|
|
45203
|
+
getPosts: getPosts,
|
|
45204
|
+
getPinnedPosts: getPinnedPosts,
|
|
45205
|
+
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
45206
|
+
semanticSearchPosts: semanticSearchPosts,
|
|
45207
|
+
searchPostsByHashtag: searchPostsByHashtag,
|
|
45208
|
+
getLiveRoomPosts: getLiveRoomPosts,
|
|
45209
|
+
getCommunityLiveRoomPosts: getCommunityLiveRoomPosts
|
|
45210
|
+
});
|
|
44277
45211
|
|
|
45212
|
+
/* begin_public_function
|
|
45213
|
+
id: stream.create
|
|
45214
|
+
*/
|
|
44278
45215
|
/**
|
|
44279
45216
|
* ```js
|
|
44280
|
-
* import {
|
|
44281
|
-
* const
|
|
44282
|
-
* // ...
|
|
44283
|
-
* })
|
|
45217
|
+
* import { createStream } from '@amityco/ts-sdk'
|
|
45218
|
+
* const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
|
|
44284
45219
|
* ```
|
|
44285
45220
|
*
|
|
44286
|
-
*
|
|
45221
|
+
* Creates an {@link Amity.InternalStream}
|
|
44287
45222
|
*
|
|
44288
|
-
* @param
|
|
44289
|
-
* @returns
|
|
45223
|
+
* @param bundle The data necessary to create a new {@link Amity.InternalStream}
|
|
45224
|
+
* @returns The newly created {@link Amity.InternalStream}
|
|
44290
45225
|
*
|
|
44291
|
-
* @category
|
|
45226
|
+
* @category Stream API
|
|
45227
|
+
* @async
|
|
44292
45228
|
*/
|
|
44293
|
-
const
|
|
45229
|
+
const createStream = async (bundle) => {
|
|
44294
45230
|
const client = getActiveClient();
|
|
44295
|
-
|
|
44296
|
-
|
|
44297
|
-
|
|
45231
|
+
client.log('stream/createStream', bundle);
|
|
45232
|
+
const { data } = await client.http.post('/api/v3/video-streaming', bundle);
|
|
45233
|
+
const cachedAt = client.cache && Date.now();
|
|
45234
|
+
if (client.cache)
|
|
45235
|
+
ingestInCache(data, { cachedAt });
|
|
45236
|
+
const { videoStreamings } = data;
|
|
45237
|
+
return {
|
|
45238
|
+
data: LinkedObject.stream(videoStreamings[0]),
|
|
45239
|
+
cachedAt,
|
|
44298
45240
|
};
|
|
44299
|
-
return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
|
|
44300
45241
|
};
|
|
45242
|
+
/* end_public_function */
|
|
44301
45243
|
|
|
45244
|
+
/* begin_public_function
|
|
45245
|
+
id: stream.update
|
|
45246
|
+
*/
|
|
44302
45247
|
/**
|
|
45248
|
+
* @deprecated this function is deprecated,
|
|
45249
|
+
* please use {@link Amity.StreamRepository.editStream} instead.
|
|
45250
|
+
*
|
|
44303
45251
|
* ```js
|
|
44304
|
-
* import {
|
|
44305
|
-
* const
|
|
44306
|
-
* // ...
|
|
44307
|
-
* })
|
|
45252
|
+
* import { updateStream } from '@amityco/ts-sdk'
|
|
45253
|
+
* const updated = await updateStream(streamId, { title: 'foobar' })
|
|
44308
45254
|
* ```
|
|
44309
45255
|
*
|
|
44310
|
-
*
|
|
45256
|
+
* Updates an {@link Amity.Stream}
|
|
44311
45257
|
*
|
|
44312
|
-
* @param
|
|
44313
|
-
* @
|
|
45258
|
+
* @param streamId The ID of the {@link Amity.Stream} to edit
|
|
45259
|
+
* @param patch The patch data to apply
|
|
45260
|
+
* @returns the updated {@link Amity.Stream} object
|
|
44314
45261
|
*
|
|
44315
|
-
* @category
|
|
45262
|
+
* @category Stream API
|
|
45263
|
+
* @async
|
|
44316
45264
|
*/
|
|
44317
|
-
const
|
|
44318
|
-
const client = getActiveClient();
|
|
44319
|
-
const filter = (payload) => {
|
|
44320
|
-
const data = prepareMyInvitationsPayload(payload);
|
|
44321
|
-
ingestInCache(data);
|
|
44322
|
-
callback(data.invitations);
|
|
44323
|
-
};
|
|
44324
|
-
return createEventSubscriber(client, 'room/onRoomCoHostInvited', 'room.didCohostInvite', filter);
|
|
44325
|
-
};
|
|
44326
|
-
|
|
44327
|
-
const getRoomById = async (roomId) => {
|
|
45265
|
+
const updateStream = async (streamId, patch) => {
|
|
44328
45266
|
const client = getActiveClient();
|
|
44329
|
-
client.log('
|
|
44330
|
-
|
|
44331
|
-
isInTombstone('room', roomId);
|
|
44332
|
-
let data;
|
|
44333
|
-
try {
|
|
44334
|
-
const response = await client.http.get(`/api/v1/rooms/${roomId}`);
|
|
44335
|
-
data = response.data;
|
|
44336
|
-
}
|
|
44337
|
-
catch (error) {
|
|
44338
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
44339
|
-
pushToTombstone('room', roomId);
|
|
44340
|
-
}
|
|
44341
|
-
throw error;
|
|
44342
|
-
}
|
|
45267
|
+
client.log('stream/updateStream', streamId, patch);
|
|
45268
|
+
const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
|
|
44343
45269
|
const cachedAt = client.cache && Date.now();
|
|
44344
|
-
if (client.cache)
|
|
45270
|
+
if (client.cache)
|
|
44345
45271
|
ingestInCache(data, { cachedAt });
|
|
44346
|
-
}
|
|
45272
|
+
const { videoStreamings } = data;
|
|
44347
45273
|
return {
|
|
44348
|
-
data:
|
|
45274
|
+
data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
|
|
44349
45275
|
cachedAt,
|
|
44350
45276
|
};
|
|
44351
45277
|
};
|
|
44352
|
-
|
|
45278
|
+
/* end_public_function */
|
|
45279
|
+
|
|
45280
|
+
/* begin_public_function
|
|
45281
|
+
id: stream.get
|
|
45282
|
+
*/
|
|
45283
|
+
/**
|
|
45284
|
+
* ```js
|
|
45285
|
+
* import { getStream } from '@amityco/ts-sdk'
|
|
45286
|
+
* const stream = await getStream('foobar')
|
|
45287
|
+
* ```
|
|
45288
|
+
*
|
|
45289
|
+
* Fetches a {@link Amity.Stream} object
|
|
45290
|
+
*
|
|
45291
|
+
* @param streamId the ID of the {@link Amity.Stream} to fetch
|
|
45292
|
+
* @returns the associated {@link Amity.Stream} object
|
|
45293
|
+
*
|
|
45294
|
+
* @category Stream API
|
|
45295
|
+
* @async
|
|
45296
|
+
*/
|
|
45297
|
+
const getStream = async (streamId) => {
|
|
44353
45298
|
const client = getActiveClient();
|
|
44354
|
-
client.log('
|
|
44355
|
-
|
|
44356
|
-
isInTombstone('room', roomId);
|
|
45299
|
+
client.log('stream/getStream', streamId);
|
|
45300
|
+
const { data } = await client.http.get(`/api/v3/video-streaming/${streamId}`);
|
|
44357
45301
|
const cachedAt = client.cache && Date.now();
|
|
44358
|
-
|
|
44359
|
-
|
|
44360
|
-
|
|
45302
|
+
if (client.cache)
|
|
45303
|
+
ingestInCache(data, { cachedAt });
|
|
45304
|
+
const { videoStreamings } = data;
|
|
44361
45305
|
return {
|
|
44362
|
-
data:
|
|
45306
|
+
data: videoStreamings.find(stream => stream.streamId === streamId),
|
|
44363
45307
|
cachedAt,
|
|
44364
45308
|
};
|
|
44365
45309
|
};
|
|
44366
|
-
|
|
45310
|
+
/* end_public_function */
|
|
44367
45311
|
/**
|
|
44368
45312
|
* ```js
|
|
44369
|
-
* import {
|
|
44370
|
-
* const
|
|
44371
|
-
* // ...
|
|
44372
|
-
* })
|
|
45313
|
+
* import { getStream } from '@amityco/ts-sdk'
|
|
45314
|
+
* const stream = getStream.locally('foobar')
|
|
44373
45315
|
* ```
|
|
44374
45316
|
*
|
|
44375
|
-
*
|
|
45317
|
+
* Fetches a {@link Amity.Stream} object
|
|
44376
45318
|
*
|
|
44377
|
-
* @param
|
|
44378
|
-
* @returns
|
|
45319
|
+
* @param streamId the ID of the {@link Amity.Stream} to fetch
|
|
45320
|
+
* @returns the associated {@link Amity.Stream} object
|
|
44379
45321
|
*
|
|
44380
|
-
* @category
|
|
45322
|
+
* @category Stream API
|
|
44381
45323
|
*/
|
|
44382
|
-
|
|
45324
|
+
getStream.locally = (streamId) => {
|
|
44383
45325
|
const client = getActiveClient();
|
|
44384
|
-
|
|
44385
|
-
|
|
44386
|
-
|
|
44387
|
-
|
|
44388
|
-
|
|
44389
|
-
|
|
45326
|
+
client.log('stream/getStream', streamId);
|
|
45327
|
+
if (!client.cache)
|
|
45328
|
+
return;
|
|
45329
|
+
const cached = pullFromCache(['stream', 'get', streamId]);
|
|
45330
|
+
if (!cached)
|
|
45331
|
+
return;
|
|
45332
|
+
return {
|
|
45333
|
+
data: cached.data,
|
|
45334
|
+
cachedAt: cached.cachedAt,
|
|
44390
45335
|
};
|
|
44391
|
-
return createEventSubscriber(client, 'room/onRoomCoHostInviteAccepted', 'room.didCohostInviteAccept', filter);
|
|
44392
45336
|
};
|
|
44393
45337
|
|
|
45338
|
+
// import { unwrapPayload } from '~/core/transports'
|
|
45339
|
+
/* begin_public_function
|
|
45340
|
+
id: stream.delete
|
|
45341
|
+
*/
|
|
44394
45342
|
/**
|
|
44395
45343
|
* ```js
|
|
44396
|
-
* import {
|
|
44397
|
-
* const
|
|
44398
|
-
* // ...
|
|
44399
|
-
* })
|
|
45344
|
+
* import { deleteStream } from '@amityco/ts-sdk'
|
|
45345
|
+
* const success = await deleteStream(streamId)
|
|
44400
45346
|
* ```
|
|
44401
45347
|
*
|
|
44402
|
-
*
|
|
45348
|
+
* Deletes a {@link Amity.InternalStream}
|
|
44403
45349
|
*
|
|
44404
|
-
* @param
|
|
44405
|
-
* @
|
|
45350
|
+
* @param streamId The {@link Amity.InternalStream} ID to delete
|
|
45351
|
+
* @return A success boolean if the {@link Amity.InternalStream} was deleted
|
|
44406
45352
|
*
|
|
44407
|
-
* @category
|
|
45353
|
+
* @category Stream API
|
|
45354
|
+
* @async
|
|
44408
45355
|
*/
|
|
44409
|
-
const
|
|
45356
|
+
const deleteStream = async (streamId) => {
|
|
44410
45357
|
const client = getActiveClient();
|
|
44411
|
-
|
|
44412
|
-
|
|
44413
|
-
|
|
44414
|
-
|
|
44415
|
-
};
|
|
44416
|
-
|
|
45358
|
+
client.log('stream/deleteStream', streamId);
|
|
45359
|
+
const stream = await getStream(streamId);
|
|
45360
|
+
// API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
|
|
45361
|
+
// API-FIX: swagger docs are wrong!
|
|
45362
|
+
const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}`);
|
|
45363
|
+
const { success } = data; // unwrapPayload(data)
|
|
45364
|
+
const deleted = Object.assign(Object.assign({}, stream.data), { isDeleted: true });
|
|
45365
|
+
upsertInCache(['stream', 'get', streamId], deleted);
|
|
45366
|
+
return success;
|
|
44417
45367
|
};
|
|
45368
|
+
/* end_public_function */
|
|
44418
45369
|
|
|
44419
45370
|
/**
|
|
44420
45371
|
* ```js
|
|
44421
|
-
* import {
|
|
44422
|
-
* const
|
|
44423
|
-
* // ...
|
|
44424
|
-
* })
|
|
45372
|
+
* import { disposeStream } from '@amityco/ts-sdk'
|
|
45373
|
+
* const stream = await disposeStream(streamId)
|
|
44425
45374
|
* ```
|
|
44426
45375
|
*
|
|
44427
|
-
*
|
|
45376
|
+
* Dispose a {@link Amity.InternalStream}.
|
|
45377
|
+
* Streaming status will be updated to "ended" and streaming url will be invalidated
|
|
44428
45378
|
*
|
|
44429
|
-
* @param
|
|
44430
|
-
* @returns
|
|
45379
|
+
* @param streamId The {@link Amity.InternalStream} ID to dispose
|
|
45380
|
+
* @returns the associated {@link Amity.InternalStream} object
|
|
44431
45381
|
*
|
|
44432
|
-
* @category
|
|
45382
|
+
* @category Stream API
|
|
45383
|
+
* @async
|
|
44433
45384
|
*/
|
|
44434
|
-
const
|
|
45385
|
+
const disposeStream = async (streamId) => {
|
|
44435
45386
|
const client = getActiveClient();
|
|
44436
|
-
|
|
44437
|
-
|
|
44438
|
-
|
|
44439
|
-
|
|
45387
|
+
client.log('stream/disposeStream', streamId);
|
|
45388
|
+
const { data } = await client.http.delete(`/api/v3/video-streaming/${streamId}/streaming-url`);
|
|
45389
|
+
const cachedAt = client.cache && Date.now();
|
|
45390
|
+
if (client.cache)
|
|
45391
|
+
ingestInCache(data, { cachedAt });
|
|
45392
|
+
const { videoStreamings } = data;
|
|
45393
|
+
return {
|
|
45394
|
+
data: videoStreamings.find(stream => stream.streamId === streamId),
|
|
45395
|
+
cachedAt,
|
|
44440
45396
|
};
|
|
44441
|
-
return createEventSubscriber(client, 'room/onRoomCoHostInviteCanceled', 'room.didCohostInviteCancel', filter);
|
|
44442
45397
|
};
|
|
45398
|
+
/* end_public_function */
|
|
44443
45399
|
|
|
45400
|
+
/* begin_public_function
|
|
45401
|
+
id: stream.update
|
|
45402
|
+
*/
|
|
44444
45403
|
/**
|
|
45404
|
+
*
|
|
44445
45405
|
* ```js
|
|
44446
|
-
* import {
|
|
44447
|
-
* const
|
|
44448
|
-
* // ...
|
|
44449
|
-
* })
|
|
45406
|
+
* import { StreamRepository } from '@amityco/ts-sdk'
|
|
45407
|
+
* const updated = await StreamRepository.editStream(streamId, { title: 'foobar' })
|
|
44450
45408
|
* ```
|
|
44451
45409
|
*
|
|
44452
|
-
*
|
|
45410
|
+
* Updates an {@link Amity.Stream}
|
|
44453
45411
|
*
|
|
44454
|
-
* @param
|
|
44455
|
-
* @
|
|
45412
|
+
* @param streamId The ID of the {@link Amity.Stream} to edit
|
|
45413
|
+
* @param patch The patch data to apply
|
|
45414
|
+
* @returns the updated {@link Amity.Stream} object
|
|
44456
45415
|
*
|
|
44457
|
-
* @category
|
|
45416
|
+
* @category Stream API
|
|
45417
|
+
* @async
|
|
44458
45418
|
*/
|
|
44459
|
-
const
|
|
45419
|
+
const editStream = async (streamId, patch) => {
|
|
44460
45420
|
const client = getActiveClient();
|
|
44461
|
-
|
|
44462
|
-
|
|
44463
|
-
|
|
45421
|
+
client.log('stream/updateStream', streamId, patch);
|
|
45422
|
+
const { data } = await client.http.put(`/api/v3/video-streaming/${streamId}`, patch);
|
|
45423
|
+
const cachedAt = client.cache && Date.now();
|
|
45424
|
+
if (client.cache)
|
|
45425
|
+
ingestInCache(data, { cachedAt });
|
|
45426
|
+
const { videoStreamings } = data;
|
|
45427
|
+
return {
|
|
45428
|
+
data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
|
|
45429
|
+
cachedAt,
|
|
44464
45430
|
};
|
|
44465
|
-
return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
|
|
44466
45431
|
};
|
|
45432
|
+
/* end_public_function */
|
|
44467
45433
|
|
|
44468
45434
|
/**
|
|
44469
45435
|
* ```js
|
|
44470
|
-
* import {
|
|
44471
|
-
* const dispose =
|
|
45436
|
+
* import { onStreamStarted } from '@amityco/ts-sdk'
|
|
45437
|
+
* const dispose = onStreamStarted(stream => {
|
|
44472
45438
|
* // ...
|
|
44473
45439
|
* })
|
|
44474
45440
|
* ```
|
|
44475
45441
|
*
|
|
44476
|
-
* Fired when a
|
|
45442
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
44477
45443
|
*
|
|
44478
45444
|
* @param callback The function to call when the event was fired
|
|
44479
45445
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44480
45446
|
*
|
|
44481
|
-
* @category
|
|
45447
|
+
* @category Stream Events
|
|
44482
45448
|
*/
|
|
44483
|
-
const
|
|
45449
|
+
const onStreamStarted = (callback) => {
|
|
44484
45450
|
const client = getActiveClient();
|
|
44485
45451
|
const filter = (payload) => {
|
|
44486
45452
|
ingestInCache(payload);
|
|
44487
|
-
callback(payload.
|
|
45453
|
+
callback(payload.videoStreamings[0]);
|
|
44488
45454
|
};
|
|
44489
|
-
return createEventSubscriber(client, '
|
|
45455
|
+
return createEventSubscriber(client, 'stream/onStreamStarted', 'video-streaming.didStart', filter);
|
|
44490
45456
|
};
|
|
44491
45457
|
|
|
44492
45458
|
/**
|
|
44493
45459
|
* ```js
|
|
44494
|
-
* import {
|
|
44495
|
-
* const dispose =
|
|
45460
|
+
* import { onStreamStopped } from '@amityco/ts-sdk'
|
|
45461
|
+
* const dispose = onStreamStopped(stream => {
|
|
44496
45462
|
* // ...
|
|
44497
45463
|
* })
|
|
44498
45464
|
* ```
|
|
44499
45465
|
*
|
|
44500
|
-
* Fired when a {@link Amity.
|
|
45466
|
+
* Fired when a {@link Amity.InternalStream} has stopped airing
|
|
44501
45467
|
*
|
|
44502
45468
|
* @param callback The function to call when the event was fired
|
|
44503
45469
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44504
45470
|
*
|
|
44505
|
-
* @category
|
|
45471
|
+
* @category Stream Events
|
|
44506
45472
|
*/
|
|
44507
|
-
const
|
|
45473
|
+
const onStreamStopped = (callback) => {
|
|
44508
45474
|
const client = getActiveClient();
|
|
44509
45475
|
const filter = (payload) => {
|
|
44510
45476
|
ingestInCache(payload);
|
|
44511
|
-
callback(payload.
|
|
45477
|
+
callback(payload.videoStreamings[0]);
|
|
44512
45478
|
};
|
|
44513
|
-
return createEventSubscriber(client, '
|
|
45479
|
+
return createEventSubscriber(client, 'stream/onStreamStropped', 'video-streaming.didStop', filter);
|
|
44514
45480
|
};
|
|
44515
45481
|
|
|
44516
45482
|
/**
|
|
44517
45483
|
* ```js
|
|
44518
|
-
* import {
|
|
44519
|
-
* const dispose =
|
|
45484
|
+
* import { onStreamRecorded } from '@amityco/ts-sdk'
|
|
45485
|
+
* const dispose = onStreamRecorded(stream => {
|
|
44520
45486
|
* // ...
|
|
44521
45487
|
* })
|
|
44522
45488
|
* ```
|
|
44523
45489
|
*
|
|
44524
|
-
* Fired when a {@link Amity.
|
|
45490
|
+
* Fired when the recordings of a {@link Amity.InternalStream} are available
|
|
44525
45491
|
*
|
|
44526
45492
|
* @param callback The function to call when the event was fired
|
|
44527
45493
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44528
45494
|
*
|
|
44529
|
-
* @category
|
|
45495
|
+
* @category Stream Events
|
|
44530
45496
|
*/
|
|
44531
|
-
const
|
|
45497
|
+
const onStreamRecorded = (callback) => {
|
|
44532
45498
|
const client = getActiveClient();
|
|
44533
45499
|
const filter = (payload) => {
|
|
44534
45500
|
ingestInCache(payload);
|
|
44535
|
-
callback(payload.
|
|
45501
|
+
callback(payload.videoStreamings[0]);
|
|
44536
45502
|
};
|
|
44537
|
-
return createEventSubscriber(client, '
|
|
45503
|
+
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
44538
45504
|
};
|
|
44539
45505
|
|
|
44540
45506
|
/**
|
|
44541
45507
|
* ```js
|
|
44542
|
-
* import {
|
|
44543
|
-
* const dispose =
|
|
45508
|
+
* import { onStreamFlagged } from '@amityco/ts-sdk'
|
|
45509
|
+
* const dispose = onStreamFlagged(stream => {
|
|
44544
45510
|
* // ...
|
|
44545
45511
|
* })
|
|
44546
45512
|
* ```
|
|
44547
45513
|
*
|
|
44548
|
-
* Fired when a {@link Amity.
|
|
45514
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
44549
45515
|
*
|
|
44550
45516
|
* @param callback The function to call when the event was fired
|
|
44551
45517
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44552
45518
|
*
|
|
44553
|
-
* @category
|
|
45519
|
+
* @category Stream Events
|
|
44554
45520
|
*/
|
|
44555
|
-
const
|
|
45521
|
+
const onStreamFlagged = (callback) => {
|
|
44556
45522
|
const client = getActiveClient();
|
|
44557
45523
|
const filter = (payload) => {
|
|
44558
45524
|
ingestInCache(payload);
|
|
44559
|
-
callback(payload.
|
|
45525
|
+
callback(payload.videoStreamings[0]);
|
|
44560
45526
|
};
|
|
44561
|
-
return createEventSubscriber(client, '
|
|
45527
|
+
return createEventSubscriber(client, 'stream/onStreamFlagged', 'video-streaming.didFlag', filter);
|
|
44562
45528
|
};
|
|
44563
45529
|
|
|
44564
45530
|
/**
|
|
44565
45531
|
* ```js
|
|
44566
|
-
* import {
|
|
44567
|
-
* const dispose =
|
|
45532
|
+
* import { onStreamTerminated } from '@amityco/ts-sdk'
|
|
45533
|
+
* const dispose = onStreamTerminated(stream => {
|
|
44568
45534
|
* // ...
|
|
44569
45535
|
* })
|
|
44570
45536
|
* ```
|
|
44571
45537
|
*
|
|
44572
|
-
* Fired when a {@link Amity.
|
|
45538
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
44573
45539
|
*
|
|
44574
45540
|
* @param callback The function to call when the event was fired
|
|
44575
45541
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44576
45542
|
*
|
|
44577
|
-
* @category
|
|
45543
|
+
* @category Stream Events
|
|
44578
45544
|
*/
|
|
44579
|
-
const
|
|
45545
|
+
const onStreamTerminated = (callback) => {
|
|
44580
45546
|
const client = getActiveClient();
|
|
44581
45547
|
const filter = (payload) => {
|
|
44582
45548
|
ingestInCache(payload);
|
|
44583
|
-
callback(payload.
|
|
45549
|
+
callback(payload.videoStreamings[0]);
|
|
44584
45550
|
};
|
|
44585
|
-
return createEventSubscriber(client, '
|
|
45551
|
+
return createEventSubscriber(client, 'stream/onStreamTerminated', 'video-streaming.didTerminate', filter);
|
|
44586
45552
|
};
|
|
44587
45553
|
|
|
44588
45554
|
/**
|
|
44589
45555
|
* ```js
|
|
44590
|
-
* import {
|
|
44591
|
-
* const dispose =
|
|
45556
|
+
* import { onStreamViewerUnbanned } from '@amityco/ts-sdk'
|
|
45557
|
+
* const dispose = onStreamViewerBanned(stream => {
|
|
44592
45558
|
* // ...
|
|
44593
45559
|
* })
|
|
44594
45560
|
* ```
|
|
44595
45561
|
*
|
|
44596
|
-
* Fired when a
|
|
45562
|
+
* Fired when a user in channel linked to stream has been unbanned
|
|
44597
45563
|
*
|
|
44598
45564
|
* @param callback The function to call when the event was fired
|
|
44599
45565
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
44600
45566
|
*
|
|
44601
|
-
* @category
|
|
45567
|
+
* @category Stream Events
|
|
44602
45568
|
*/
|
|
44603
|
-
const
|
|
45569
|
+
const onStreamViewerUnbanned = (callback) => {
|
|
44604
45570
|
const client = getActiveClient();
|
|
44605
|
-
const filter = (
|
|
44606
|
-
|
|
44607
|
-
|
|
45571
|
+
const filter = async (payloads) => {
|
|
45572
|
+
var _a;
|
|
45573
|
+
// Get new stream object to restore stream watcherUrl in cache
|
|
45574
|
+
const { list } = payloads;
|
|
45575
|
+
await Promise.all(list.map(({ streamId }) => getStream(streamId)));
|
|
45576
|
+
const stream = (_a = pullFromCache(['stream', 'get', list[0].streamId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
45577
|
+
if (!stream)
|
|
45578
|
+
return;
|
|
45579
|
+
callback(stream);
|
|
44608
45580
|
};
|
|
44609
|
-
return createEventSubscriber(client, '
|
|
45581
|
+
return createEventSubscriber(client, 'stream/onStreamViewerDidUnban', 'video-streaming.viewerDidUnban', filter);
|
|
44610
45582
|
};
|
|
44611
45583
|
|
|
45584
|
+
/* eslint-disable no-use-before-define */
|
|
45585
|
+
/* begin_public_function
|
|
45586
|
+
id: stream.get
|
|
45587
|
+
*/
|
|
44612
45588
|
/**
|
|
44613
45589
|
* ```js
|
|
44614
|
-
* import {
|
|
44615
|
-
* const
|
|
44616
|
-
*
|
|
44617
|
-
* })
|
|
45590
|
+
* import { StreamRepository } from '@amityco/ts-sdk'
|
|
45591
|
+
* const unsub = StreamRepository.getStreamById('foobar')
|
|
45592
|
+
* unsub()
|
|
44618
45593
|
* ```
|
|
44619
45594
|
*
|
|
44620
|
-
*
|
|
45595
|
+
* Fetches a {@link Amity.Stream} object
|
|
44621
45596
|
*
|
|
44622
|
-
* @param
|
|
44623
|
-
* @
|
|
45597
|
+
* @param streamId the ID of the {@link Amity.Stream} to get
|
|
45598
|
+
* @param callback
|
|
45599
|
+
* @returns the associated {@link Amity.Stream} object
|
|
44624
45600
|
*
|
|
44625
|
-
* @category
|
|
45601
|
+
* @category Stream Live Object
|
|
44626
45602
|
*/
|
|
44627
|
-
const
|
|
44628
|
-
const
|
|
44629
|
-
|
|
44630
|
-
|
|
44631
|
-
callback(payload.rooms[0]);
|
|
45603
|
+
const getStreamById = (streamId, callback) => {
|
|
45604
|
+
const reactor = (snapshot) => {
|
|
45605
|
+
const { data } = snapshot;
|
|
45606
|
+
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
|
|
44632
45607
|
};
|
|
44633
|
-
return
|
|
45608
|
+
return liveObject(streamId, reactor, 'streamId', getStream, [
|
|
45609
|
+
onStreamRecorded,
|
|
45610
|
+
onStreamStarted,
|
|
45611
|
+
onStreamStopped,
|
|
45612
|
+
onStreamFlagged,
|
|
45613
|
+
onStreamTerminated,
|
|
45614
|
+
onStreamViewerBanned,
|
|
45615
|
+
]);
|
|
44634
45616
|
};
|
|
44635
|
-
|
|
45617
|
+
/* end_public_function */
|
|
44636
45618
|
/**
|
|
44637
45619
|
* ```js
|
|
44638
|
-
* import {
|
|
44639
|
-
* const
|
|
44640
|
-
* // ...
|
|
44641
|
-
* })
|
|
45620
|
+
* import { StreamRepository } from '@amityco/ts-sdk'
|
|
45621
|
+
* const stream = StreamRepository.getStreamById.locally('foobar')
|
|
44642
45622
|
* ```
|
|
44643
45623
|
*
|
|
44644
|
-
*
|
|
45624
|
+
* Fetches a {@link Amity.Stream} live object
|
|
44645
45625
|
*
|
|
44646
|
-
* @param
|
|
44647
|
-
* @returns
|
|
45626
|
+
* @param streamId the ID of the {@link Amity.Stream} to fetch
|
|
45627
|
+
* @returns the associated {@link Amity.Stream} live object
|
|
44648
45628
|
*
|
|
44649
|
-
* @category
|
|
45629
|
+
* @category Stream API
|
|
44650
45630
|
*/
|
|
44651
|
-
|
|
45631
|
+
getStreamById.locally = (streamId) => {
|
|
44652
45632
|
const client = getActiveClient();
|
|
44653
|
-
|
|
44654
|
-
|
|
44655
|
-
|
|
44656
|
-
|
|
44657
|
-
|
|
44658
|
-
|
|
44659
|
-
|
|
44660
|
-
|
|
44661
|
-
|
|
44662
|
-
|
|
44663
|
-
onRoomEndBroadcasting,
|
|
44664
|
-
onRoomStartBroadcasting,
|
|
44665
|
-
onRoomWaitingReconnect,
|
|
44666
|
-
onRoomRecordedAvailable,
|
|
44667
|
-
onRoomParticipantJoined,
|
|
44668
|
-
onRoomParticipantLeft,
|
|
44669
|
-
onRoomParticipantRemoved,
|
|
44670
|
-
onRoomParticipantRemovedLocal,
|
|
44671
|
-
convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
44672
|
-
], {
|
|
44673
|
-
callbackDataSelector: (data) => {
|
|
44674
|
-
if (!data)
|
|
44675
|
-
return data;
|
|
44676
|
-
return LinkedObject.room(data);
|
|
44677
|
-
},
|
|
44678
|
-
});
|
|
45633
|
+
client.log('stream/getStreamById', streamId);
|
|
45634
|
+
if (!client.cache)
|
|
45635
|
+
return;
|
|
45636
|
+
const cached = pullFromCache(['stream', 'get', streamId]);
|
|
45637
|
+
if (!cached)
|
|
45638
|
+
return;
|
|
45639
|
+
return {
|
|
45640
|
+
data: LinkedObject.stream(cached.data),
|
|
45641
|
+
cachedAt: cached.cachedAt,
|
|
45642
|
+
};
|
|
44679
45643
|
};
|
|
44680
45644
|
|
|
44681
|
-
class
|
|
45645
|
+
class GetStreamsPageController extends PaginationController {
|
|
44682
45646
|
async getRequest(queryParams, token) {
|
|
44683
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT
|
|
44684
|
-
const
|
|
44685
|
-
|
|
44686
|
-
|
|
44687
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
44688
|
-
const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
|
|
44689
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
45647
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
45648
|
+
const options = token ? { token } : { limit };
|
|
45649
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/video-streaming`, {
|
|
45650
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
44690
45651
|
});
|
|
44691
|
-
return queryResponse;
|
|
45652
|
+
return Object.assign(Object.assign({}, queryResponse.results), { paging: queryResponse.paging });
|
|
44692
45653
|
}
|
|
44693
45654
|
}
|
|
44694
45655
|
|
|
44695
|
-
|
|
44696
|
-
(
|
|
44697
|
-
EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
|
|
44698
|
-
EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
|
|
44699
|
-
EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
|
|
44700
|
-
EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
|
|
44701
|
-
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
44702
|
-
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
44703
|
-
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
44704
|
-
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
44705
|
-
|
|
44706
|
-
class RoomQueryStreamController extends QueryStreamController {
|
|
44707
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
45656
|
+
class GetStreamsQueryStreamController extends QueryStreamController {
|
|
45657
|
+
constructor(query, cacheKey, notifyChange, paginationController) {
|
|
44708
45658
|
super(query, cacheKey);
|
|
44709
45659
|
this.notifyChange = notifyChange;
|
|
44710
|
-
this.
|
|
45660
|
+
this.paginationController = paginationController;
|
|
44711
45661
|
}
|
|
44712
|
-
|
|
44713
|
-
|
|
45662
|
+
// eslint-disable-next-line class-methods-use-this
|
|
45663
|
+
saveToMainDB(response) {
|
|
44714
45664
|
const client = getActiveClient();
|
|
44715
45665
|
const cachedAt = client.cache && Date.now();
|
|
44716
45666
|
if (client.cache) {
|
|
44717
|
-
ingestInCache(
|
|
45667
|
+
ingestInCache(response, { cachedAt });
|
|
44718
45668
|
}
|
|
44719
45669
|
}
|
|
44720
45670
|
appendToQueryStream(response, direction, refresh = false) {
|
|
44721
45671
|
var _a, _b;
|
|
44722
45672
|
if (refresh) {
|
|
44723
45673
|
pushToCache(this.cacheKey, {
|
|
44724
|
-
data: response.
|
|
45674
|
+
data: response.videoStreamings.map(getResolver('stream')),
|
|
45675
|
+
query: this.query,
|
|
44725
45676
|
});
|
|
44726
45677
|
}
|
|
44727
45678
|
else {
|
|
44728
45679
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44729
|
-
const
|
|
44730
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data:
|
|
45680
|
+
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
45681
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
45682
|
+
? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
|
|
45683
|
+
: [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])] }));
|
|
44731
45684
|
}
|
|
44732
45685
|
}
|
|
44733
45686
|
reactor(action) {
|
|
44734
|
-
return (
|
|
45687
|
+
return (payload) => {
|
|
44735
45688
|
var _a;
|
|
44736
45689
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44737
45690
|
if (!collection)
|
|
44738
45691
|
return;
|
|
44739
|
-
|
|
44740
|
-
collection.data = collection.data.filter(roomId => roomId !== room._id);
|
|
44741
|
-
}
|
|
44742
|
-
if (action === EnumRoomActions.OnRoomCreated) {
|
|
44743
|
-
collection.data = [...new Set([room._id, ...collection.data])];
|
|
44744
|
-
}
|
|
45692
|
+
collection.data = [...new Set([payload.streamId, ...collection.data])];
|
|
44745
45693
|
pushToCache(this.cacheKey, collection);
|
|
44746
45694
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44747
45695
|
};
|
|
@@ -44751,171 +45699,107 @@ class RoomQueryStreamController extends QueryStreamController {
|
|
|
44751
45699
|
}
|
|
44752
45700
|
}
|
|
44753
45701
|
|
|
44754
|
-
|
|
44755
|
-
const getRoomSubscription = () => [
|
|
44756
|
-
{
|
|
44757
|
-
fn: onRoomStartBroadcasting,
|
|
44758
|
-
action: EnumRoomActions.OnRoomStartBroadcasting,
|
|
44759
|
-
},
|
|
44760
|
-
{
|
|
44761
|
-
fn: onRoomEndBroadcasting,
|
|
44762
|
-
action: EnumRoomActions.OnRoomEndBroadcasting,
|
|
44763
|
-
},
|
|
44764
|
-
{
|
|
44765
|
-
fn: onRoomRecordedAvailable,
|
|
44766
|
-
action: EnumRoomActions.OnRoomUpdated,
|
|
44767
|
-
},
|
|
44768
|
-
];
|
|
44769
|
-
|
|
44770
|
-
class RoomLiveCollectionController extends LiveCollectionController {
|
|
45702
|
+
class GetStreamsLiveCollectionController extends LiveCollectionController {
|
|
44771
45703
|
constructor(query, callback) {
|
|
44772
45704
|
const queryStreamId = hash(query);
|
|
44773
|
-
const cacheKey = ['
|
|
44774
|
-
const paginationController = new
|
|
45705
|
+
const cacheKey = ['streams', 'collection', queryStreamId];
|
|
45706
|
+
const paginationController = new GetStreamsPageController(query);
|
|
44775
45707
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
45708
|
+
this.applyFilter = (data) => {
|
|
45709
|
+
let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
|
|
45710
|
+
streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
45711
|
+
return streams;
|
|
45712
|
+
};
|
|
44776
45713
|
this.query = query;
|
|
44777
|
-
this.queryStreamController = new
|
|
45714
|
+
this.queryStreamController = new GetStreamsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
45715
|
+
this.paginationController = paginationController;
|
|
44778
45716
|
this.callback = callback.bind(this);
|
|
44779
45717
|
this.loadPage({ initial: true });
|
|
44780
45718
|
}
|
|
44781
|
-
setup() {
|
|
44782
|
-
var _a;
|
|
44783
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44784
|
-
if (!collection) {
|
|
44785
|
-
pushToCache(this.cacheKey, {
|
|
44786
|
-
data: [],
|
|
44787
|
-
params: {},
|
|
44788
|
-
});
|
|
44789
|
-
}
|
|
44790
|
-
}
|
|
44791
|
-
async persistModel(queryPayload) {
|
|
44792
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
44793
|
-
}
|
|
44794
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
44795
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44796
|
-
}
|
|
44797
|
-
startSubscription() {
|
|
44798
|
-
return this.queryStreamController.subscribeRTE(getRoomSubscription());
|
|
44799
|
-
}
|
|
44800
45719
|
notifyChange({ origin, loading, error }) {
|
|
44801
|
-
var _a
|
|
45720
|
+
var _a;
|
|
44802
45721
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
44803
45722
|
if (!collection)
|
|
44804
45723
|
return;
|
|
44805
|
-
|
|
44806
|
-
.map(
|
|
44807
|
-
.filter(
|
|
44808
|
-
.map(
|
|
45724
|
+
let data = collection.data
|
|
45725
|
+
.map(streamId => pullFromCache(['stream', 'get', streamId]))
|
|
45726
|
+
.filter(Boolean)
|
|
45727
|
+
.map(stream => LinkedObject.stream(stream.data));
|
|
44809
45728
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
44810
45729
|
return;
|
|
45730
|
+
data = this.applyFilter(data);
|
|
44811
45731
|
this.callback({
|
|
44812
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
45732
|
+
onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
44813
45733
|
data,
|
|
44814
45734
|
hasNextPage: !!this.paginationController.getNextToken(),
|
|
44815
45735
|
loading,
|
|
44816
45736
|
error,
|
|
44817
45737
|
});
|
|
44818
45738
|
}
|
|
44819
|
-
|
|
44820
|
-
|
|
44821
|
-
|
|
44822
|
-
|
|
44823
|
-
|
|
44824
|
-
|
|
44825
|
-
|
|
44826
|
-
|
|
44827
|
-
|
|
44828
|
-
|
|
44829
|
-
|
|
44830
|
-
|
|
44831
|
-
|
|
44832
|
-
|
|
44833
|
-
|
|
44834
|
-
|
|
44835
|
-
|
|
44836
|
-
|
|
44837
|
-
|
|
45739
|
+
startSubscription() {
|
|
45740
|
+
return this.queryStreamController.subscribeRTE([
|
|
45741
|
+
{ fn: onStreamRecorded, action: 'onStreamRecorded' },
|
|
45742
|
+
{ fn: onStreamStarted, action: 'onStreamStarted' },
|
|
45743
|
+
{ fn: onStreamStopped, action: 'onStreamStopped' },
|
|
45744
|
+
{ fn: onStreamFlagged, action: 'onStreamFlagged' },
|
|
45745
|
+
{ fn: onStreamTerminated, action: 'onStreamTerminated' },
|
|
45746
|
+
{ fn: onStreamViewerBanned, action: 'onStreamViewerBanned' },
|
|
45747
|
+
{ fn: onStreamViewerUnbanned, action: 'onStreamViewerUnbanned' },
|
|
45748
|
+
]);
|
|
45749
|
+
}
|
|
45750
|
+
setup() {
|
|
45751
|
+
var _a;
|
|
45752
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45753
|
+
if (!collection) {
|
|
45754
|
+
pushToCache(this.cacheKey, {
|
|
45755
|
+
data: [],
|
|
45756
|
+
params: {},
|
|
45757
|
+
});
|
|
44838
45758
|
}
|
|
44839
|
-
|
|
45759
|
+
}
|
|
45760
|
+
persistModel(response) {
|
|
45761
|
+
this.queryStreamController.saveToMainDB(response);
|
|
45762
|
+
}
|
|
45763
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
45764
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
44840
45765
|
}
|
|
44841
45766
|
}
|
|
44842
45767
|
|
|
44843
|
-
|
|
44844
|
-
|
|
44845
|
-
*/
|
|
44846
|
-
/**
|
|
44847
|
-
* ```js
|
|
44848
|
-
* import { RoomRepository } from '@amityco/ts-sdk'
|
|
44849
|
-
*
|
|
44850
|
-
* let rooms = []
|
|
44851
|
-
* const unsub = RoomRepository.getRooms({
|
|
44852
|
-
* type: 'direct_streaming',
|
|
44853
|
-
* statuses: ['live', 'idle'],
|
|
44854
|
-
* sortBy: 'lastCreated',
|
|
44855
|
-
* limit: 20,
|
|
44856
|
-
* includeDeleted: false
|
|
44857
|
-
* }, response => merge(rooms, response.data))
|
|
44858
|
-
* ```
|
|
44859
|
-
*
|
|
44860
|
-
* Observe all mutations on a list of {@link Amity.Room} for a given query
|
|
44861
|
-
*
|
|
44862
|
-
* @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
|
|
44863
|
-
* @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
|
|
44864
|
-
* @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
|
|
44865
|
-
* @param params.limit maximum number of rooms to retrieve per page
|
|
44866
|
-
* @param params.includeDeleted whether to include deleted rooms in the results
|
|
44867
|
-
* @param callback the function to call when new data are available
|
|
44868
|
-
* @param config optional configuration for the live collection
|
|
44869
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
|
|
44870
|
-
*
|
|
44871
|
-
* @category Rooms Live Collection
|
|
44872
|
-
*/
|
|
44873
|
-
const getRooms = (params, callback, config) => {
|
|
44874
|
-
const { log, cache } = getActiveClient();
|
|
45768
|
+
const getStreams = (params, callback, config) => {
|
|
45769
|
+
const { log, cache, userId } = getActiveClient();
|
|
44875
45770
|
if (!cache) {
|
|
44876
45771
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
44877
45772
|
}
|
|
44878
45773
|
const timestamp = Date.now();
|
|
44879
|
-
log(`
|
|
44880
|
-
const
|
|
44881
|
-
const disposers =
|
|
44882
|
-
const cacheKey =
|
|
44883
|
-
disposers.push(() =>
|
|
45774
|
+
log(`getStreams(tmpid: ${timestamp}) > listen`);
|
|
45775
|
+
const liveCollection = new GetStreamsLiveCollectionController(params, callback);
|
|
45776
|
+
const disposers = liveCollection.startSubscription();
|
|
45777
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
45778
|
+
disposers.push(() => {
|
|
45779
|
+
dropFromCache(cacheKey);
|
|
45780
|
+
});
|
|
44884
45781
|
return () => {
|
|
44885
|
-
log(`
|
|
45782
|
+
log(`getStreams(tmpid: ${timestamp}) > dispose`);
|
|
44886
45783
|
disposers.forEach(fn => fn());
|
|
44887
45784
|
};
|
|
44888
45785
|
};
|
|
44889
|
-
/* end_public_function */
|
|
44890
45786
|
|
|
44891
45787
|
var index$9 = /*#__PURE__*/Object.freeze({
|
|
44892
45788
|
__proto__: null,
|
|
44893
|
-
|
|
44894
|
-
|
|
44895
|
-
|
|
44896
|
-
|
|
44897
|
-
|
|
44898
|
-
|
|
44899
|
-
|
|
44900
|
-
|
|
44901
|
-
|
|
44902
|
-
|
|
44903
|
-
|
|
44904
|
-
|
|
44905
|
-
|
|
44906
|
-
|
|
44907
|
-
onRoomCoHostInviteRejected: onRoomCoHostInviteRejected,
|
|
44908
|
-
onRoomCoHostInviteCanceled: onRoomCoHostInviteCanceled,
|
|
44909
|
-
onRoomParticipantJoined: onRoomParticipantJoined,
|
|
44910
|
-
onRoomParticipantLeft: onRoomParticipantLeft,
|
|
44911
|
-
onRoomCreated: onRoomCreated,
|
|
44912
|
-
onRoomUpdated: onRoomUpdated,
|
|
44913
|
-
onRoomDeleted: onRoomDeleted,
|
|
44914
|
-
onRoomStopped: onRoomStopped,
|
|
44915
|
-
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
44916
|
-
onRoomLeft: onRoomLeft,
|
|
44917
|
-
getRoom: getRoom,
|
|
44918
|
-
getRooms: getRooms
|
|
45789
|
+
createStream: createStream,
|
|
45790
|
+
updateStream: updateStream,
|
|
45791
|
+
deleteStream: deleteStream,
|
|
45792
|
+
disposeStream: disposeStream,
|
|
45793
|
+
editStream: editStream,
|
|
45794
|
+
onStreamStarted: onStreamStarted,
|
|
45795
|
+
onStreamStopped: onStreamStopped,
|
|
45796
|
+
onStreamRecorded: onStreamRecorded,
|
|
45797
|
+
onStreamFlagged: onStreamFlagged,
|
|
45798
|
+
onStreamTerminated: onStreamTerminated,
|
|
45799
|
+
onStreamViewerBanned: onStreamViewerBanned,
|
|
45800
|
+
onStreamViewerUnbanned: onStreamViewerUnbanned,
|
|
45801
|
+
getStreamById: getStreamById,
|
|
45802
|
+
getStreams: getStreams
|
|
44919
45803
|
});
|
|
44920
45804
|
|
|
44921
45805
|
/* begin_public_function
|
|
@@ -47944,30 +48828,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
47944
48828
|
getReactions: getReactions
|
|
47945
48829
|
});
|
|
47946
48830
|
|
|
47947
|
-
const prepareEventPayload = (rawPayload) => {
|
|
47948
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
47949
|
-
};
|
|
47950
|
-
|
|
47951
|
-
const createEventEventSubscriber = (event, callback) => {
|
|
47952
|
-
const client = getActiveClient();
|
|
47953
|
-
const filter = (payload) => {
|
|
47954
|
-
const unpackedPayload = prepareEventPayload(payload);
|
|
47955
|
-
if (!client.cache) {
|
|
47956
|
-
callback(unpackedPayload.events[0]);
|
|
47957
|
-
}
|
|
47958
|
-
else {
|
|
47959
|
-
ingestInCache(unpackedPayload);
|
|
47960
|
-
const event = pullFromCache([
|
|
47961
|
-
'event',
|
|
47962
|
-
'get',
|
|
47963
|
-
unpackedPayload.events[0].eventId,
|
|
47964
|
-
]);
|
|
47965
|
-
callback(event.data);
|
|
47966
|
-
}
|
|
47967
|
-
};
|
|
47968
|
-
return createEventSubscriber(client, event, event, filter);
|
|
47969
|
-
};
|
|
47970
|
-
|
|
47971
48831
|
/* begin_public_function
|
|
47972
48832
|
id: event.create
|
|
47973
48833
|
*/
|
|
@@ -48127,108 +48987,6 @@ const deleteEvent = async (eventId) => {
|
|
|
48127
48987
|
};
|
|
48128
48988
|
/* end_public_function */
|
|
48129
48989
|
|
|
48130
|
-
/**
|
|
48131
|
-
* ```js
|
|
48132
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48133
|
-
* const dispose = EventRepository.onEventCreated(event => {
|
|
48134
|
-
* // ...
|
|
48135
|
-
* })
|
|
48136
|
-
* ```
|
|
48137
|
-
*
|
|
48138
|
-
* Fired when a {@link Amity.Event} has been created
|
|
48139
|
-
*
|
|
48140
|
-
* @param callback The function to call when the event was fired
|
|
48141
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48142
|
-
*
|
|
48143
|
-
* @category Event Events
|
|
48144
|
-
*/
|
|
48145
|
-
const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
|
|
48146
|
-
|
|
48147
|
-
/**
|
|
48148
|
-
* ```js
|
|
48149
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48150
|
-
* const dispose = EventRepository.onEventUpdated(event => {
|
|
48151
|
-
* // ...
|
|
48152
|
-
* })
|
|
48153
|
-
* ```
|
|
48154
|
-
*
|
|
48155
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
48156
|
-
*
|
|
48157
|
-
* @param callback The function to call when the event was fired
|
|
48158
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48159
|
-
*
|
|
48160
|
-
* @category Event Events
|
|
48161
|
-
*/
|
|
48162
|
-
const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
|
|
48163
|
-
|
|
48164
|
-
/**
|
|
48165
|
-
* ```js
|
|
48166
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48167
|
-
* const dispose = EventRepository.onEventDeleted(event => {
|
|
48168
|
-
* // ...
|
|
48169
|
-
* })
|
|
48170
|
-
* ```
|
|
48171
|
-
*
|
|
48172
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
48173
|
-
*
|
|
48174
|
-
* @param callback The function to call when the event was fired
|
|
48175
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48176
|
-
*
|
|
48177
|
-
* @category Event Events
|
|
48178
|
-
*/
|
|
48179
|
-
const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
|
|
48180
|
-
|
|
48181
|
-
/**
|
|
48182
|
-
* ```js
|
|
48183
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48184
|
-
* const dispose = EventRepository.onLocalEventCreated(event => {
|
|
48185
|
-
* // ...
|
|
48186
|
-
* })
|
|
48187
|
-
* ```
|
|
48188
|
-
*
|
|
48189
|
-
* Fired when a {@link Amity.Event} has been created
|
|
48190
|
-
*
|
|
48191
|
-
* @param callback The function to call when the event was fired
|
|
48192
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48193
|
-
*
|
|
48194
|
-
* @category Event Events
|
|
48195
|
-
*/
|
|
48196
|
-
const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
|
|
48197
|
-
|
|
48198
|
-
/**
|
|
48199
|
-
* ```js
|
|
48200
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48201
|
-
* const dispose = EventRepository.onLocalEventUpdated(event => {
|
|
48202
|
-
* // ...
|
|
48203
|
-
* })
|
|
48204
|
-
* ```
|
|
48205
|
-
*
|
|
48206
|
-
* Fired when a {@link Amity.Event} has been updated
|
|
48207
|
-
*
|
|
48208
|
-
* @param callback The function to call when the event was fired
|
|
48209
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48210
|
-
*
|
|
48211
|
-
* @category Event Events
|
|
48212
|
-
*/
|
|
48213
|
-
const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
|
|
48214
|
-
|
|
48215
|
-
/**
|
|
48216
|
-
* ```js
|
|
48217
|
-
* import { EventRepository } from '@amityco/ts-sdk'
|
|
48218
|
-
* const dispose = EventRepository.onLocalEventDeleted(event => {
|
|
48219
|
-
* // ...
|
|
48220
|
-
* })
|
|
48221
|
-
* ```
|
|
48222
|
-
*
|
|
48223
|
-
* Fired when a {@link Amity.Event} has been deleted
|
|
48224
|
-
*
|
|
48225
|
-
* @param callback The function to call when the event was fired
|
|
48226
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
48227
|
-
*
|
|
48228
|
-
* @category Event Events
|
|
48229
|
-
*/
|
|
48230
|
-
const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
|
|
48231
|
-
|
|
48232
48990
|
/* begin_public_function
|
|
48233
48991
|
id: event.get
|
|
48234
48992
|
*/
|
|
@@ -48258,13 +49016,6 @@ const getEvent = (eventId, callback) => {
|
|
|
48258
49016
|
};
|
|
48259
49017
|
/* end_public_function */
|
|
48260
49018
|
|
|
48261
|
-
var EventActionsEnum;
|
|
48262
|
-
(function (EventActionsEnum) {
|
|
48263
|
-
EventActionsEnum["OnEventCreated"] = "onEventCreated";
|
|
48264
|
-
EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
|
|
48265
|
-
EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
|
|
48266
|
-
})(EventActionsEnum || (EventActionsEnum = {}));
|
|
48267
|
-
|
|
48268
49019
|
class EventPaginationController extends PaginationController {
|
|
48269
49020
|
async getRequest(queryParams, token) {
|
|
48270
49021
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
@@ -48399,6 +49150,143 @@ const getEvents = (params, callback, config) => {
|
|
|
48399
49150
|
};
|
|
48400
49151
|
};
|
|
48401
49152
|
|
|
49153
|
+
class MyEventPaginationController extends PaginationController {
|
|
49154
|
+
async getRequest(queryParams, token) {
|
|
49155
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
49156
|
+
const options = token ? { token } : { limit };
|
|
49157
|
+
const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
49158
|
+
return response;
|
|
49159
|
+
}
|
|
49160
|
+
}
|
|
49161
|
+
|
|
49162
|
+
class MyEventQueryStreamController extends QueryStreamController {
|
|
49163
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
49164
|
+
super(query, cacheKey);
|
|
49165
|
+
this.notifyChange = notifyChange;
|
|
49166
|
+
this.preparePayload = preparePayload;
|
|
49167
|
+
}
|
|
49168
|
+
async saveToMainDB(response) {
|
|
49169
|
+
const processedPayload = this.preparePayload(response);
|
|
49170
|
+
const client = getActiveClient();
|
|
49171
|
+
const cachedAt = client.cache && Date.now();
|
|
49172
|
+
if (client.cache)
|
|
49173
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
49174
|
+
}
|
|
49175
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
49176
|
+
var _a, _b;
|
|
49177
|
+
if (refresh) {
|
|
49178
|
+
pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
|
|
49179
|
+
}
|
|
49180
|
+
else {
|
|
49181
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49182
|
+
const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
49183
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
|
|
49184
|
+
}
|
|
49185
|
+
}
|
|
49186
|
+
reactor(action) {
|
|
49187
|
+
return (event) => {
|
|
49188
|
+
var _a;
|
|
49189
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49190
|
+
if (!collection)
|
|
49191
|
+
return;
|
|
49192
|
+
if (action === EventActionsEnum.OnEventCreated) {
|
|
49193
|
+
const client = getActiveClient();
|
|
49194
|
+
if (client.userId !== event.userId)
|
|
49195
|
+
return;
|
|
49196
|
+
collection.data = [...new Set([event.eventId, ...collection.data])];
|
|
49197
|
+
}
|
|
49198
|
+
if (action === EventActionsEnum.OnEventDeleted) {
|
|
49199
|
+
collection.data = collection.data.filter(eventId => eventId !== event.eventId);
|
|
49200
|
+
}
|
|
49201
|
+
pushToCache(this.cacheKey, collection);
|
|
49202
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
49203
|
+
};
|
|
49204
|
+
}
|
|
49205
|
+
subscribeRTE(createSubscriber) {
|
|
49206
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
49207
|
+
}
|
|
49208
|
+
}
|
|
49209
|
+
|
|
49210
|
+
class MyEventLiveCollectionController extends LiveCollectionController {
|
|
49211
|
+
constructor(query, callback) {
|
|
49212
|
+
const queryStreamId = hash(query);
|
|
49213
|
+
const cacheKey = ['event', 'collection', queryStreamId];
|
|
49214
|
+
const paginationController = new MyEventPaginationController(query);
|
|
49215
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
49216
|
+
this.query = query;
|
|
49217
|
+
this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
|
|
49218
|
+
this.callback = callback.bind(this);
|
|
49219
|
+
this.loadPage({ initial: true });
|
|
49220
|
+
}
|
|
49221
|
+
setup() {
|
|
49222
|
+
var _a;
|
|
49223
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49224
|
+
if (!collection)
|
|
49225
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
49226
|
+
}
|
|
49227
|
+
async persistModel(queryPayload) {
|
|
49228
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
49229
|
+
}
|
|
49230
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
49231
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
49232
|
+
}
|
|
49233
|
+
startSubscription() {
|
|
49234
|
+
return this.queryStreamController.subscribeRTE([
|
|
49235
|
+
{ fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
49236
|
+
{ fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
49237
|
+
{ fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
49238
|
+
{ fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
|
|
49239
|
+
{ fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
|
|
49240
|
+
{ fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
|
|
49241
|
+
]);
|
|
49242
|
+
}
|
|
49243
|
+
notifyChange({ origin, loading, error }) {
|
|
49244
|
+
var _a, _b;
|
|
49245
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49246
|
+
if (!collection)
|
|
49247
|
+
return;
|
|
49248
|
+
const data = ((_b = collection.data
|
|
49249
|
+
.map(eventId => pullFromCache(['event', 'get', eventId]))
|
|
49250
|
+
.filter(isNonNullable)
|
|
49251
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
|
|
49252
|
+
if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
|
|
49253
|
+
return;
|
|
49254
|
+
this.callback({
|
|
49255
|
+
data,
|
|
49256
|
+
error,
|
|
49257
|
+
loading,
|
|
49258
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
49259
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
49260
|
+
});
|
|
49261
|
+
}
|
|
49262
|
+
}
|
|
49263
|
+
|
|
49264
|
+
/**
|
|
49265
|
+
* Get my events
|
|
49266
|
+
*
|
|
49267
|
+
* @param params the query parameters
|
|
49268
|
+
* @param callback the callback to be called when the events are updated
|
|
49269
|
+
* @returns events
|
|
49270
|
+
*
|
|
49271
|
+
* @category Event Live Collection
|
|
49272
|
+
*
|
|
49273
|
+
*/
|
|
49274
|
+
const getMyEvents = (params, callback, config) => {
|
|
49275
|
+
const { log, cache } = getActiveClient();
|
|
49276
|
+
if (!cache)
|
|
49277
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
49278
|
+
const timestamp = Date.now();
|
|
49279
|
+
log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
|
|
49280
|
+
const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
|
|
49281
|
+
const disposers = myEventLiveCollection.startSubscription();
|
|
49282
|
+
const cacheKey = myEventLiveCollection.getCacheKey();
|
|
49283
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
49284
|
+
return () => {
|
|
49285
|
+
log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
|
|
49286
|
+
disposers.forEach(fn => fn());
|
|
49287
|
+
};
|
|
49288
|
+
};
|
|
49289
|
+
|
|
48402
49290
|
var index = /*#__PURE__*/Object.freeze({
|
|
48403
49291
|
__proto__: null,
|
|
48404
49292
|
createEvent: createEvent,
|
|
@@ -48410,8 +49298,14 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
48410
49298
|
onLocalEventCreated: onLocalEventCreated,
|
|
48411
49299
|
onLocalEventUpdated: onLocalEventUpdated,
|
|
48412
49300
|
onLocalEventDeleted: onLocalEventDeleted,
|
|
49301
|
+
onRSVPCreated: onRSVPCreated,
|
|
49302
|
+
onRSVPUpdated: onRSVPUpdated,
|
|
49303
|
+
onLocalRSVPCreated: onLocalRSVPCreated,
|
|
49304
|
+
onLocalRSVPUpdated: onLocalRSVPUpdated,
|
|
48413
49305
|
getEvent: getEvent,
|
|
48414
|
-
getEvents: getEvents
|
|
49306
|
+
getEvents: getEvents,
|
|
49307
|
+
getMyEvents: getMyEvents,
|
|
49308
|
+
getRSVPs: getRSVPs
|
|
48415
49309
|
});
|
|
48416
49310
|
|
|
48417
|
-
export { API_REGIONS, index$4 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$e as CategoryRepository, index$i as ChannelRepository, index$r as Client, index$d as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$f as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$c as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$o as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$m as MessageRepository, index$7 as PollRepository, PostContentType, index$
|
|
49311
|
+
export { API_REGIONS, index$4 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$e as CategoryRepository, index$i as ChannelRepository, index$r as Client, index$d as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$f as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$c as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$o as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$m as MessageRepository, index$7 as PollRepository, PostContentType, index$a as PostRepository, PostStructureType, index$n as ReactionRepository, index$8 as RoomPresenceRepository, index$b as RoomRepository, index$5 as StoryRepository, index$9 as StreamRepository, index$l as SubChannelRepository, SubscriptionLevels, index$p as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|