@amityco/ts-sdk 7.4.1-b9f48528.0 → 7.4.1-c116567e.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 +3 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +11 -4
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +72 -0
- package/dist/@types/domains/invitation.d.ts.map +1 -0
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +2 -2
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +1 -1
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/utils.d.ts +2 -2
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +1 -1
- package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityCreated.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityCreated.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityDeleted.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityDeleted.d.ts.map +1 -1
- package/dist/communityRepository/events/onCommunityUpdated.d.ts +1 -1
- package/dist/communityRepository/events/onCommunityUpdated.d.ts.map +1 -1
- package/dist/communityRepository/events/utils.d.ts +1 -1
- package/dist/communityRepository/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +2 -2
- package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +1 -1
- package/dist/communityRepository/utils/payload.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/index.cjs.js +2929 -2421
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2277 -1770
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/events/index.d.ts +4 -0
- package/dist/invitationRepository/events/index.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -0
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +17 -0
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -0
- package/dist/invitationRepository/index.d.ts +2 -0
- package/dist/invitationRepository/index.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/acceptInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/acceptInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/createInvitations.d.ts +21 -0
- package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/index.d.ts +5 -0
- package/dist/invitationRepository/internalApi/index.d.ts.map +1 -0
- package/dist/invitationRepository/internalApi/rejectInvitation.d.ts +16 -0
- package/dist/invitationRepository/internalApi/rejectInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/utils/index.d.ts +2 -0
- package/dist/invitationRepository/utils/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/communityLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +2 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts +3 -3
- package/package.json +1 -1
- package/src/@types/core/events.ts +4 -0
- package/src/@types/core/model.ts +5 -1
- package/src/@types/core/payload.ts +13 -4
- package/src/@types/domains/community.ts +15 -1
- package/src/@types/domains/invitation.ts +92 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/createCommunity.ts +2 -1
- package/src/communityRepository/api/getCommunities.ts +7 -2
- package/src/communityRepository/api/getCommunity.ts +4 -1
- package/src/communityRepository/api/getRecommendedCommunities.ts +11 -4
- package/src/communityRepository/api/getTrendingCommunities.ts +11 -4
- package/src/communityRepository/api/queryCommunities.ts +6 -1
- package/src/communityRepository/api/updateCommunity.ts +13 -3
- package/src/communityRepository/communityMembership/events/onCommunityJoined.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityLeft.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserBanned.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserChanged.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRoleAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onCommunityUserUnbanned.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +1 -1
- package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +1 -1
- package/src/communityRepository/communityMembership/events/onUserDeleted.ts +3 -1
- package/src/communityRepository/communityMembership/events/utils.ts +2 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +8 -2
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +8 -2
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +1 -1
- package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +1 -1
- package/src/communityRepository/events/onCommunityCreated.ts +1 -1
- package/src/communityRepository/events/onCommunityDeleted.ts +1 -1
- package/src/communityRepository/events/onCommunityUpdated.ts +1 -1
- package/src/communityRepository/events/utils.ts +1 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +2 -2
- package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +2 -2
- package/src/communityRepository/utils/communityWithMembership.ts +8 -4
- package/src/communityRepository/utils/payload.ts +1 -1
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- package/src/core/model/idResolvers.ts +2 -0
- package/src/core/model/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/invitationRepository/events/index.ts +3 -0
- package/src/invitationRepository/events/onLocalInvitationCreated.ts +33 -0
- package/src/invitationRepository/events/onLocalInvitationDeleted.ts +33 -0
- package/src/invitationRepository/events/onLocalInvitationUpdated.ts +33 -0
- package/src/invitationRepository/index.ts +1 -0
- package/src/invitationRepository/internalApi/acceptInvitation.ts +45 -0
- package/src/invitationRepository/internalApi/cancelInvitation.ts +44 -0
- package/src/invitationRepository/internalApi/createInvitations.ts +52 -0
- package/src/invitationRepository/internalApi/index.ts +4 -0
- package/src/invitationRepository/internalApi/rejectInvitation.ts +45 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
- package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
- package/src/invitationRepository/observers/getInvitations.ts +44 -0
- package/src/invitationRepository/utils/index.ts +1 -0
- package/src/invitationRepository/utils/prepareInvitationPayload.ts +11 -0
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
- package/src/utils/linkedObject/communityLinkedObject.ts +29 -0
- package/src/utils/linkedObject/index.ts +4 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +44 -0
package/dist/index.esm.js
CHANGED
|
@@ -103,6 +103,24 @@ const PostContentType = Object.freeze({
|
|
|
103
103
|
POLL: 'poll',
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
var InvitationTypeEnum;
|
|
107
|
+
(function (InvitationTypeEnum) {
|
|
108
|
+
InvitationTypeEnum["CommunityMemberInvite"] = "communityMemberInvite";
|
|
109
|
+
InvitationTypeEnum["LivestreamInvite"] = "livestreamInvite";
|
|
110
|
+
})(InvitationTypeEnum || (InvitationTypeEnum = {}));
|
|
111
|
+
var InvitationStatusEnum;
|
|
112
|
+
(function (InvitationStatusEnum) {
|
|
113
|
+
InvitationStatusEnum["Pending"] = "pending";
|
|
114
|
+
InvitationStatusEnum["Approved"] = "approved";
|
|
115
|
+
InvitationStatusEnum["Rejected"] = "rejected";
|
|
116
|
+
InvitationStatusEnum["Cancelled"] = "cancelled";
|
|
117
|
+
})(InvitationStatusEnum || (InvitationStatusEnum = {}));
|
|
118
|
+
var InvitationSortByEnum;
|
|
119
|
+
(function (InvitationSortByEnum) {
|
|
120
|
+
InvitationSortByEnum["FirstCreated"] = "firstCreated";
|
|
121
|
+
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
122
|
+
})(InvitationSortByEnum || (InvitationSortByEnum = {}));
|
|
123
|
+
|
|
106
124
|
function getVersion() {
|
|
107
125
|
try {
|
|
108
126
|
// the string ''v7.4.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -549,6 +567,7 @@ const idResolvers = {
|
|
|
549
567
|
pinTarget: ({ targetId }) => targetId,
|
|
550
568
|
notificationTrayItem: ({ _id }) => _id,
|
|
551
569
|
notificationTraySeen: ({ userId }) => userId,
|
|
570
|
+
invitation: ({ _id }) => _id,
|
|
552
571
|
};
|
|
553
572
|
/**
|
|
554
573
|
* Retrieve the id resolver matching a domain name
|
|
@@ -601,6 +620,7 @@ const PAYLOAD2MODEL = {
|
|
|
601
620
|
pinTargets: 'pinTarget',
|
|
602
621
|
pins: 'pin',
|
|
603
622
|
notificationTrayItems: 'notificationTrayItem',
|
|
623
|
+
invitations: 'invitation',
|
|
604
624
|
};
|
|
605
625
|
/** hidden */
|
|
606
626
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -20975,305 +20995,6 @@ const getChannelMessagePreview = (channelId) => {
|
|
|
20975
20995
|
return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
20976
20996
|
};
|
|
20977
20997
|
|
|
20978
|
-
const ANALYTIC_CACHE_KEY = ['analytic', 'normal-priority'];
|
|
20979
|
-
const HIGH_PRIORITY_ANALYTIC_CACHE_KEY = ['analytic', 'high-priority'];
|
|
20980
|
-
|
|
20981
|
-
const syncEvent = async (events) => {
|
|
20982
|
-
const client = getActiveClient();
|
|
20983
|
-
const params = {
|
|
20984
|
-
activities: events,
|
|
20985
|
-
};
|
|
20986
|
-
await client.http.post('/api/v1/analytics/activities', params);
|
|
20987
|
-
};
|
|
20988
|
-
|
|
20989
|
-
class AnalyticsEventSyncer {
|
|
20990
|
-
constructor() {
|
|
20991
|
-
this._timer = undefined;
|
|
20992
|
-
this._high_priority_timer = undefined;
|
|
20993
|
-
}
|
|
20994
|
-
start() {
|
|
20995
|
-
this.syncCapturedEvent();
|
|
20996
|
-
this._timer = setInterval(() => {
|
|
20997
|
-
this.syncCapturedEvent();
|
|
20998
|
-
}, 1 * MINUTE);
|
|
20999
|
-
this._high_priority_timer = setInterval(() => {
|
|
21000
|
-
this.syncHighPriorityCapturedEvent();
|
|
21001
|
-
}, 10 * SECOND$1);
|
|
21002
|
-
}
|
|
21003
|
-
stop() {
|
|
21004
|
-
if (this._timer) {
|
|
21005
|
-
clearInterval(this._timer);
|
|
21006
|
-
this._timer = undefined;
|
|
21007
|
-
}
|
|
21008
|
-
if (this._high_priority_timer) {
|
|
21009
|
-
clearInterval(this._high_priority_timer);
|
|
21010
|
-
this._high_priority_timer = undefined;
|
|
21011
|
-
}
|
|
21012
|
-
}
|
|
21013
|
-
async syncCapturedEvent() {
|
|
21014
|
-
try {
|
|
21015
|
-
// Must query only objects that have same userId with current logged-in user.
|
|
21016
|
-
// Query captured event with maximum of 1000
|
|
21017
|
-
// Order by latest first
|
|
21018
|
-
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
21019
|
-
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
21020
|
-
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
21021
|
-
return;
|
|
21022
|
-
if (cache.data.event.length === 0)
|
|
21023
|
-
return;
|
|
21024
|
-
const capturedEvents = cache.data.event;
|
|
21025
|
-
await syncEvent(capturedEvents);
|
|
21026
|
-
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
21027
|
-
}
|
|
21028
|
-
catch (error) {
|
|
21029
|
-
// stop and destroy all events
|
|
21030
|
-
this.stop();
|
|
21031
|
-
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
21032
|
-
}
|
|
21033
|
-
}
|
|
21034
|
-
async syncHighPriorityCapturedEvent() {
|
|
21035
|
-
try {
|
|
21036
|
-
// Must query only objects that have same userId with current logged-in user.
|
|
21037
|
-
// Query captured event with maximum of 1000
|
|
21038
|
-
// Order by latest first
|
|
21039
|
-
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
21040
|
-
const cache = pullFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
21041
|
-
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
21042
|
-
return;
|
|
21043
|
-
if (cache.data.event.length === 0)
|
|
21044
|
-
return;
|
|
21045
|
-
const capturedEvents = cache.data.event;
|
|
21046
|
-
await syncEvent(capturedEvents);
|
|
21047
|
-
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
21048
|
-
}
|
|
21049
|
-
catch (error) {
|
|
21050
|
-
// stop and destroy all events
|
|
21051
|
-
this.stop();
|
|
21052
|
-
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
21053
|
-
}
|
|
21054
|
-
}
|
|
21055
|
-
}
|
|
21056
|
-
|
|
21057
|
-
class AnalyticsEventCapturer {
|
|
21058
|
-
constructor() {
|
|
21059
|
-
this._expireTime = 5 * MINUTE;
|
|
21060
|
-
this._poolLimit = 1000;
|
|
21061
|
-
this._recentViewed = {};
|
|
21062
|
-
this._recentHighPriorityViewed = {};
|
|
21063
|
-
// Story
|
|
21064
|
-
this._throttleStoryTimer = undefined;
|
|
21065
|
-
this._bufferNewSeenStoryReferenceIds = [];
|
|
21066
|
-
}
|
|
21067
|
-
isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
|
|
21068
|
-
const now = new Date();
|
|
21069
|
-
// Get the recent view date (if any)
|
|
21070
|
-
const recentViewedDate = isHighPriority
|
|
21071
|
-
? this._recentHighPriorityViewed[uniqueId]
|
|
21072
|
-
: this._recentViewed[uniqueId];
|
|
21073
|
-
// If this is the first view, always allow it
|
|
21074
|
-
if (!recentViewedDate) {
|
|
21075
|
-
return true;
|
|
21076
|
-
}
|
|
21077
|
-
const timeDiff = now.getTime() - recentViewedDate.getTime();
|
|
21078
|
-
if (timeDiff < expireTime) {
|
|
21079
|
-
// just recently view this post, ignore the event.
|
|
21080
|
-
return false;
|
|
21081
|
-
}
|
|
21082
|
-
return true;
|
|
21083
|
-
}
|
|
21084
|
-
markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
|
|
21085
|
-
if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
|
|
21086
|
-
return;
|
|
21087
|
-
const now = new Date();
|
|
21088
|
-
const currentData = { event: [] };
|
|
21089
|
-
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
21090
|
-
if (cache === null || cache === void 0 ? void 0 : cache.data) {
|
|
21091
|
-
currentData.event = cache.data.event;
|
|
21092
|
-
}
|
|
21093
|
-
// If the pool is full (Max 1000 items), remove the oldest data
|
|
21094
|
-
if (currentData.event.length >= this._poolLimit) {
|
|
21095
|
-
// Remove oldest data
|
|
21096
|
-
currentData.event.shift();
|
|
21097
|
-
}
|
|
21098
|
-
const analyticItem = {
|
|
21099
|
-
contentId,
|
|
21100
|
-
contentType,
|
|
21101
|
-
activityType,
|
|
21102
|
-
timestamp: now.toISOString(),
|
|
21103
|
-
};
|
|
21104
|
-
if (metadata) {
|
|
21105
|
-
analyticItem.metadata = metadata;
|
|
21106
|
-
}
|
|
21107
|
-
currentData.event.push(analyticItem);
|
|
21108
|
-
upsertInCache(ANALYTIC_CACHE_KEY, currentData);
|
|
21109
|
-
this._recentViewed[uniqueId] = now;
|
|
21110
|
-
}
|
|
21111
|
-
markPostAsViewed(postId) {
|
|
21112
|
-
this.markAs({
|
|
21113
|
-
uniqueId: postId,
|
|
21114
|
-
contentId: postId,
|
|
21115
|
-
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
21116
|
-
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
21117
|
-
});
|
|
21118
|
-
}
|
|
21119
|
-
markStory(story, activityType) {
|
|
21120
|
-
if (!story.expiresAt)
|
|
21121
|
-
return;
|
|
21122
|
-
const now = new Date();
|
|
21123
|
-
const expireTime = new Date(story.expiresAt);
|
|
21124
|
-
if (!this.isAbleToEnqueue({
|
|
21125
|
-
uniqueId: story.storyId,
|
|
21126
|
-
expireTime: expireTime.getTime(),
|
|
21127
|
-
isHighPriority: true,
|
|
21128
|
-
}))
|
|
21129
|
-
return;
|
|
21130
|
-
const currentData = { event: [] };
|
|
21131
|
-
const cache = pullFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
21132
|
-
if (cache === null || cache === void 0 ? void 0 : cache.data) {
|
|
21133
|
-
currentData.event = cache.data.event;
|
|
21134
|
-
}
|
|
21135
|
-
// If the pool is full (Max 1000 items), remove the oldest data
|
|
21136
|
-
if (currentData.event.length >= this._poolLimit) {
|
|
21137
|
-
// Remove oldest data
|
|
21138
|
-
currentData.event.shift();
|
|
21139
|
-
}
|
|
21140
|
-
currentData.event.push({
|
|
21141
|
-
contentId: story.storyId,
|
|
21142
|
-
contentType: "story" /* Amity.AnalyticEventContentType.Story */,
|
|
21143
|
-
activityType,
|
|
21144
|
-
timestamp: now.toISOString(),
|
|
21145
|
-
});
|
|
21146
|
-
upsertInCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY, currentData);
|
|
21147
|
-
this._recentHighPriorityViewed[story.storyId] = now;
|
|
21148
|
-
// Fire internal event if the activity type is not click
|
|
21149
|
-
if (activityType === "linkClicked" /* Amity.AnalyticEventActivityType.Click */)
|
|
21150
|
-
return;
|
|
21151
|
-
// Mark story as SEEN
|
|
21152
|
-
pushToCache(["story-seen" /* STORY_KEY_CACHE.IS_SEEN */, 'get', story.storyId], new Date().toISOString());
|
|
21153
|
-
// Update the latest timestamp for LocalStoryLastSeen
|
|
21154
|
-
const currentLastSeen = pullFromCache([
|
|
21155
|
-
"story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */,
|
|
21156
|
-
story.targetId,
|
|
21157
|
-
]);
|
|
21158
|
-
if (currentLastSeen === null || currentLastSeen === void 0 ? void 0 : currentLastSeen.data) {
|
|
21159
|
-
if (new Date(currentLastSeen.data).getTime() < new Date(story.expiresAt).getTime()) {
|
|
21160
|
-
pushToCache(["story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */, story.targetId], story.expiresAt);
|
|
21161
|
-
}
|
|
21162
|
-
}
|
|
21163
|
-
else {
|
|
21164
|
-
pushToCache(["story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */, story.targetId], story.expiresAt);
|
|
21165
|
-
}
|
|
21166
|
-
this._bufferNewSeenStoryReferenceIds.push(story.referenceId);
|
|
21167
|
-
if (this._throttleStoryTimer)
|
|
21168
|
-
return;
|
|
21169
|
-
this._throttleStoryTimer = setTimeout(() => {
|
|
21170
|
-
clearTimeout(this._throttleStoryTimer);
|
|
21171
|
-
fireEvent('local.story.reload', { referenceIds: this._bufferNewSeenStoryReferenceIds });
|
|
21172
|
-
this._bufferNewSeenStoryReferenceIds = [];
|
|
21173
|
-
}, 300);
|
|
21174
|
-
}
|
|
21175
|
-
resetAllBuckets() {
|
|
21176
|
-
this._recentViewed = {};
|
|
21177
|
-
this._recentHighPriorityViewed = {};
|
|
21178
|
-
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
21179
|
-
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
21180
|
-
}
|
|
21181
|
-
markStoryAsViewed(story) {
|
|
21182
|
-
this.markStory(story, "view" /* Amity.AnalyticEventActivityType.View */);
|
|
21183
|
-
}
|
|
21184
|
-
markStoryAsClicked(story) {
|
|
21185
|
-
this.markStory(story, "linkClicked" /* Amity.AnalyticEventActivityType.Click */);
|
|
21186
|
-
}
|
|
21187
|
-
markAdAsViewed(ad, placement) {
|
|
21188
|
-
const metadata = {
|
|
21189
|
-
placement,
|
|
21190
|
-
};
|
|
21191
|
-
const activityType = "view" /* Amity.AnalyticEventActivityType.View */;
|
|
21192
|
-
this.markAs({
|
|
21193
|
-
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
21194
|
-
contentId: ad.adId,
|
|
21195
|
-
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
21196
|
-
activityType,
|
|
21197
|
-
metadata,
|
|
21198
|
-
});
|
|
21199
|
-
}
|
|
21200
|
-
markAdAsClicked(ad, placement) {
|
|
21201
|
-
const metadata = {
|
|
21202
|
-
placement,
|
|
21203
|
-
};
|
|
21204
|
-
const activityType = "linkClicked" /* Amity.AnalyticEventActivityType.Click */;
|
|
21205
|
-
this.markAs({
|
|
21206
|
-
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
21207
|
-
contentId: ad.adId,
|
|
21208
|
-
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
21209
|
-
activityType,
|
|
21210
|
-
metadata,
|
|
21211
|
-
});
|
|
21212
|
-
}
|
|
21213
|
-
}
|
|
21214
|
-
|
|
21215
|
-
class AnalyticsEngine {
|
|
21216
|
-
constructor() {
|
|
21217
|
-
this._client = getActiveClient();
|
|
21218
|
-
this._eventCapturer = new AnalyticsEventCapturer();
|
|
21219
|
-
this._eventSyncer = new AnalyticsEventSyncer();
|
|
21220
|
-
}
|
|
21221
|
-
markPostAsViewed(postId) {
|
|
21222
|
-
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
21223
|
-
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
21224
|
-
) {
|
|
21225
|
-
this._eventCapturer.markPostAsViewed(postId);
|
|
21226
|
-
}
|
|
21227
|
-
}
|
|
21228
|
-
markStoryAsViewed(story) {
|
|
21229
|
-
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
21230
|
-
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
21231
|
-
) {
|
|
21232
|
-
this._eventCapturer.markStoryAsViewed(story);
|
|
21233
|
-
}
|
|
21234
|
-
}
|
|
21235
|
-
markAdAsViewed(ad, placement) {
|
|
21236
|
-
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
21237
|
-
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
21238
|
-
this._eventCapturer.markAdAsViewed(ad, placement);
|
|
21239
|
-
}
|
|
21240
|
-
}
|
|
21241
|
-
markAdAsClicked(ad, placement) {
|
|
21242
|
-
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
21243
|
-
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
21244
|
-
this._eventCapturer.markAdAsClicked(ad, placement);
|
|
21245
|
-
}
|
|
21246
|
-
}
|
|
21247
|
-
markStoryAsClicked(story) {
|
|
21248
|
-
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
21249
|
-
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
21250
|
-
this._eventCapturer.markStoryAsClicked(story);
|
|
21251
|
-
}
|
|
21252
|
-
}
|
|
21253
|
-
established() {
|
|
21254
|
-
this._eventSyncer.start();
|
|
21255
|
-
}
|
|
21256
|
-
handleTokenExpired() {
|
|
21257
|
-
this._stopAndDestroy();
|
|
21258
|
-
}
|
|
21259
|
-
destroy() {
|
|
21260
|
-
this._stopAndDestroy();
|
|
21261
|
-
}
|
|
21262
|
-
_stopAndDestroy() {
|
|
21263
|
-
this._eventSyncer.stop();
|
|
21264
|
-
this._eventCapturer.resetAllBuckets();
|
|
21265
|
-
}
|
|
21266
|
-
}
|
|
21267
|
-
let instance$5;
|
|
21268
|
-
var AnalyticsEngine$1 = {
|
|
21269
|
-
getInstance: () => {
|
|
21270
|
-
if (!instance$5) {
|
|
21271
|
-
instance$5 = new AnalyticsEngine();
|
|
21272
|
-
}
|
|
21273
|
-
return instance$5;
|
|
21274
|
-
},
|
|
21275
|
-
};
|
|
21276
|
-
|
|
21277
20998
|
const userLinkedObject = (user) => {
|
|
21278
20999
|
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
21279
21000
|
var _a;
|
|
@@ -21288,141 +21009,1522 @@ const userLinkedObject = (user) => {
|
|
|
21288
21009
|
} });
|
|
21289
21010
|
};
|
|
21290
21011
|
|
|
21291
|
-
|
|
21292
|
-
|
|
21293
|
-
|
|
21294
|
-
|
|
21295
|
-
|
|
21296
|
-
|
|
21297
|
-
|
|
21298
|
-
|
|
21299
|
-
|
|
21300
|
-
|
|
21301
|
-
|
|
21302
|
-
|
|
21303
|
-
|
|
21304
|
-
|
|
21305
|
-
|
|
21306
|
-
|
|
21307
|
-
|
|
21308
|
-
|
|
21309
|
-
|
|
21310
|
-
|
|
21311
|
-
|
|
21312
|
-
return this._lastStorySeenExpiresAt ? new Date(this._lastStorySeenExpiresAt).getTime() : 0;
|
|
21313
|
-
}
|
|
21314
|
-
get localLastStoryExpires() {
|
|
21315
|
-
var _a, _b;
|
|
21316
|
-
return ((_a = this.cacheStoryExpireTime) === null || _a === void 0 ? void 0 : _a.data)
|
|
21317
|
-
? new Date((_b = this.cacheStoryExpireTime) === null || _b === void 0 ? void 0 : _b.data).getTime()
|
|
21318
|
-
: 0;
|
|
21319
|
-
}
|
|
21320
|
-
get localLastStorySeenExpiresAt() {
|
|
21321
|
-
var _a, _b;
|
|
21322
|
-
return ((_a = this.cacheStoreSeenTime) === null || _a === void 0 ? void 0 : _a.data) ? new Date((_b = this.cacheStoreSeenTime) === null || _b === void 0 ? void 0 : _b.data).getTime() : 0;
|
|
21323
|
-
}
|
|
21324
|
-
get isContainUnSyncedStory() {
|
|
21325
|
-
const currentSyncingState = pullFromCache([
|
|
21326
|
-
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
21327
|
-
this._targetId,
|
|
21328
|
-
]);
|
|
21329
|
-
if (!(currentSyncingState === null || currentSyncingState === void 0 ? void 0 : currentSyncingState.data))
|
|
21330
|
-
return false;
|
|
21331
|
-
return ["syncing" /* Amity.SyncState.Syncing */, "error" /* Amity.SyncState.Error */].includes(currentSyncingState.data);
|
|
21332
|
-
}
|
|
21333
|
-
getLocalLastSortingDate() {
|
|
21334
|
-
if (this.isContainUnSyncedStory) {
|
|
21335
|
-
return this.localLastStoryExpires;
|
|
21336
|
-
}
|
|
21337
|
-
return this.lastStoryExpiresAt;
|
|
21338
|
-
}
|
|
21339
|
-
getHasUnseenFlag() {
|
|
21340
|
-
const now = new Date().getTime();
|
|
21341
|
-
const highestSeen = Math.max(this.lastStorySeenExpiresAt, this.localLastStorySeenExpiresAt);
|
|
21342
|
-
pullFromCache([
|
|
21343
|
-
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
21344
|
-
this._targetId,
|
|
21345
|
-
]);
|
|
21346
|
-
if (this.isContainUnSyncedStory) {
|
|
21347
|
-
return this.localLastStoryExpires > now && this.localLastStoryExpires > highestSeen;
|
|
21348
|
-
}
|
|
21349
|
-
return this.lastStoryExpiresAt > now && this.lastStoryExpiresAt > highestSeen;
|
|
21350
|
-
}
|
|
21351
|
-
getTotalStoryByStatus() {
|
|
21352
|
-
const stories = queryCache(["story" /* STORY_KEY_CACHE.STORY */, 'get']);
|
|
21353
|
-
if (!stories) {
|
|
21354
|
-
this._errorStoriesCount = 0;
|
|
21355
|
-
this._syncingStoriesCount = 0;
|
|
21356
|
-
return;
|
|
21357
|
-
}
|
|
21358
|
-
const groupByType = stories.reduce((acc, story) => {
|
|
21359
|
-
const { data: { targetId, syncState, isDeleted }, } = story;
|
|
21360
|
-
if (targetId === this._targetId && !isDeleted) {
|
|
21361
|
-
acc[syncState] += 1;
|
|
21362
|
-
}
|
|
21363
|
-
return acc;
|
|
21364
|
-
}, {
|
|
21365
|
-
syncing: 0,
|
|
21366
|
-
error: 0,
|
|
21367
|
-
synced: 0,
|
|
21012
|
+
const getChannelMessagePreviewWithUser = (channel) => {
|
|
21013
|
+
var _a;
|
|
21014
|
+
const messagePreview = channel.messagePreviewId
|
|
21015
|
+
? getChannelMessagePreview(channel.channelId)
|
|
21016
|
+
: null;
|
|
21017
|
+
const internalUser = (_a = pullFromCache([
|
|
21018
|
+
'user',
|
|
21019
|
+
'get',
|
|
21020
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
21021
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21022
|
+
const messagePreviewWithUser = messagePreview
|
|
21023
|
+
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? userLinkedObject(internalUser) : undefined }) : null;
|
|
21024
|
+
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
21025
|
+
};
|
|
21026
|
+
|
|
21027
|
+
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
21028
|
+
var _a, _b;
|
|
21029
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21030
|
+
var _a;
|
|
21031
|
+
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21032
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21368
21033
|
});
|
|
21369
|
-
|
|
21370
|
-
|
|
21371
|
-
|
|
21372
|
-
|
|
21373
|
-
|
|
21374
|
-
|
|
21375
|
-
|
|
21376
|
-
|
|
21377
|
-
|
|
21378
|
-
|
|
21034
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
21035
|
+
return {
|
|
21036
|
+
channelId,
|
|
21037
|
+
subChannelId,
|
|
21038
|
+
data,
|
|
21039
|
+
dataType,
|
|
21040
|
+
isDeleted,
|
|
21041
|
+
segment,
|
|
21042
|
+
creatorId,
|
|
21043
|
+
createdAt,
|
|
21044
|
+
updatedAt,
|
|
21045
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21046
|
+
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
21047
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21048
|
+
};
|
|
21049
|
+
};
|
|
21050
|
+
const newData = {
|
|
21051
|
+
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21052
|
+
};
|
|
21053
|
+
ingestInCache(newData);
|
|
21054
|
+
};
|
|
21379
21055
|
|
|
21380
|
-
const
|
|
21381
|
-
|
|
21382
|
-
|
|
21383
|
-
|
|
21384
|
-
|
|
21385
|
-
|
|
21386
|
-
|
|
21387
|
-
|
|
21388
|
-
|
|
21389
|
-
|
|
21390
|
-
|
|
21391
|
-
|
|
21392
|
-
|
|
21393
|
-
|
|
21394
|
-
|
|
21395
|
-
|
|
21056
|
+
const getSubChannelMessagePreview = (subChannelId) => {
|
|
21057
|
+
var _a, _b;
|
|
21058
|
+
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
21059
|
+
};
|
|
21060
|
+
|
|
21061
|
+
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
21062
|
+
var _a;
|
|
21063
|
+
const messagePreview = subChannel.messagePreviewId
|
|
21064
|
+
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
21065
|
+
: null;
|
|
21066
|
+
const messagePreviewWithUser = messagePreview
|
|
21067
|
+
? Object.assign(Object.assign({}, messagePreview), { user: (_a = pullFromCache(['user', 'get', messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId])) === null || _a === void 0 ? void 0 : _a.data }) : null;
|
|
21068
|
+
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
21069
|
+
};
|
|
21070
|
+
|
|
21071
|
+
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
21072
|
+
var _a, _b;
|
|
21073
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21074
|
+
var _a;
|
|
21075
|
+
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21076
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21077
|
+
});
|
|
21078
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
21079
|
+
return {
|
|
21080
|
+
messagePreviewId,
|
|
21081
|
+
channelId,
|
|
21082
|
+
subChannelId,
|
|
21083
|
+
data,
|
|
21084
|
+
dataType,
|
|
21085
|
+
isDeleted,
|
|
21086
|
+
segment,
|
|
21087
|
+
creatorId,
|
|
21088
|
+
createdAt,
|
|
21089
|
+
updatedAt,
|
|
21090
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21091
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21092
|
+
};
|
|
21093
|
+
};
|
|
21094
|
+
const newData = {
|
|
21095
|
+
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21396
21096
|
};
|
|
21097
|
+
ingestInCache(newData);
|
|
21397
21098
|
};
|
|
21398
21099
|
|
|
21399
|
-
|
|
21400
|
-
|
|
21401
|
-
|
|
21402
|
-
|
|
21403
|
-
|
|
21404
|
-
|
|
21405
|
-
|
|
21406
|
-
|
|
21407
|
-
|
|
21408
|
-
|
|
21409
|
-
|
|
21410
|
-
|
|
21411
|
-
|
|
21412
|
-
|
|
21413
|
-
|
|
21414
|
-
|
|
21415
|
-
|
|
21416
|
-
|
|
21417
|
-
|
|
21418
|
-
|
|
21419
|
-
|
|
21420
|
-
|
|
21421
|
-
|
|
21422
|
-
|
|
21423
|
-
|
|
21424
|
-
|
|
21425
|
-
|
|
21100
|
+
/**
|
|
21101
|
+
* ```js
|
|
21102
|
+
* import { shallowClone } from '~/utils/shallowClone'
|
|
21103
|
+
* const newObj = shallowClone(obj)
|
|
21104
|
+
* ```
|
|
21105
|
+
*
|
|
21106
|
+
* Clone an object with same prototype and properties
|
|
21107
|
+
*
|
|
21108
|
+
* @param obj the object to clone
|
|
21109
|
+
* @returns new object with same prototype and properties
|
|
21110
|
+
*
|
|
21111
|
+
* @category utility
|
|
21112
|
+
* @private
|
|
21113
|
+
*/
|
|
21114
|
+
function shallowClone(source, target) {
|
|
21115
|
+
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
21116
|
+
}
|
|
21117
|
+
|
|
21118
|
+
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
21119
|
+
pushToCache(['subChannel', 'get', subChannelId],
|
|
21120
|
+
// eslint-disable-next-line prefer-object-spread
|
|
21121
|
+
shallowClone(subChannel, params));
|
|
21122
|
+
}
|
|
21123
|
+
|
|
21124
|
+
/**
|
|
21125
|
+
* ```js
|
|
21126
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
21127
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
21128
|
+
* ```
|
|
21129
|
+
*
|
|
21130
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
21131
|
+
* in cache and it's not expired means it's in tombstone
|
|
21132
|
+
* and we throw an Error
|
|
21133
|
+
*
|
|
21134
|
+
* @param model the model to check
|
|
21135
|
+
* @param modelId the object id to check
|
|
21136
|
+
* @returns the matching cache entry, or undefined.
|
|
21137
|
+
*
|
|
21138
|
+
* @category Cache API
|
|
21139
|
+
*/
|
|
21140
|
+
const isInTombstone = (model, modelId) => {
|
|
21141
|
+
const { log, cache } = getActiveClient();
|
|
21142
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
21143
|
+
if (!cache)
|
|
21144
|
+
return;
|
|
21145
|
+
log('cache/api/isInTombstone', key);
|
|
21146
|
+
const isInTombstone = pullFromCache(key);
|
|
21147
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
21148
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
21149
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
21150
|
+
}
|
|
21151
|
+
};
|
|
21152
|
+
|
|
21153
|
+
/**
|
|
21154
|
+
* ```js
|
|
21155
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
21156
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
21157
|
+
* ```
|
|
21158
|
+
*
|
|
21159
|
+
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
21160
|
+
*
|
|
21161
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
21162
|
+
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
21163
|
+
*
|
|
21164
|
+
* @category Channel API
|
|
21165
|
+
* @async
|
|
21166
|
+
* @private
|
|
21167
|
+
*/
|
|
21168
|
+
const getMessageMarkers = async (messageIds) => {
|
|
21169
|
+
const client = getActiveClient();
|
|
21170
|
+
client.log('channel/getMessageMarkers', messageIds);
|
|
21171
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
21172
|
+
params: {
|
|
21173
|
+
messageIds,
|
|
21174
|
+
},
|
|
21175
|
+
});
|
|
21176
|
+
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
21177
|
+
const cachedAt = client.cache && Date.now();
|
|
21178
|
+
if (client.cache)
|
|
21179
|
+
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
21180
|
+
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
21181
|
+
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
21182
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21183
|
+
return { data: contentMarkers, cachedAt };
|
|
21184
|
+
};
|
|
21185
|
+
|
|
21186
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21187
|
+
var _a;
|
|
21188
|
+
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
21189
|
+
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21190
|
+
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
21191
|
+
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
21192
|
+
let channelUnreads = 0;
|
|
21193
|
+
let isMentioned = false;
|
|
21194
|
+
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
21195
|
+
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
21196
|
+
return data.channelId === channelId && !data.isDeleted;
|
|
21197
|
+
});
|
|
21198
|
+
channelUnreads = subChannelUnreadsInfo
|
|
21199
|
+
.map(({ data }) => data.unreadCount)
|
|
21200
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
21201
|
+
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
21202
|
+
}
|
|
21203
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
21204
|
+
channelId,
|
|
21205
|
+
createdAt: new Date().toISOString(),
|
|
21206
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
21207
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
21208
|
+
return channelUnreadInfo;
|
|
21209
|
+
};
|
|
21210
|
+
|
|
21211
|
+
const persistUnreadCountInfo = (payload) => {
|
|
21212
|
+
const { feedMarkers, userFeedMarkers } = payload;
|
|
21213
|
+
// calculate sub channel unread info and channel unread info
|
|
21214
|
+
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
21215
|
+
const channelIds = [];
|
|
21216
|
+
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
21217
|
+
userFeedMarkers.forEach(userFeedMarker => {
|
|
21218
|
+
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
21219
|
+
if (!feedMarker)
|
|
21220
|
+
return;
|
|
21221
|
+
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
21222
|
+
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
21223
|
+
const subChannelUnreadInfo = {
|
|
21224
|
+
subChannelId: feedMarker.feedId,
|
|
21225
|
+
channelId: feedMarker.entityId,
|
|
21226
|
+
readToSegment: userFeedMarker.readToSegment,
|
|
21227
|
+
lastSegment: feedMarker.lastSegment,
|
|
21228
|
+
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
21229
|
+
unreadCount: Math.max(0, unreadCount),
|
|
21230
|
+
isMentioned: userFeedMarker.isMentioned,
|
|
21231
|
+
isDeleted: feedMarker.isDeleted,
|
|
21232
|
+
createdAt: userFeedMarker.createdAt,
|
|
21233
|
+
updatedAt: userFeedMarker.updatedAt,
|
|
21234
|
+
};
|
|
21235
|
+
// update sub channel unread info in cache
|
|
21236
|
+
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
21237
|
+
if (!channelIds.includes(feedMarker.entityId)) {
|
|
21238
|
+
channelIds.push(feedMarker.entityId);
|
|
21239
|
+
}
|
|
21240
|
+
}
|
|
21241
|
+
});
|
|
21242
|
+
// re-calculate channel unread info in cache
|
|
21243
|
+
channelIds.forEach(channelId => {
|
|
21244
|
+
reCalculateChannelUnreadInfo(channelId);
|
|
21245
|
+
});
|
|
21246
|
+
}
|
|
21247
|
+
};
|
|
21248
|
+
|
|
21249
|
+
/**
|
|
21250
|
+
* ```js
|
|
21251
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21252
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21253
|
+
* ```
|
|
21254
|
+
*
|
|
21255
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21256
|
+
*
|
|
21257
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21258
|
+
* @param page
|
|
21259
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21260
|
+
*
|
|
21261
|
+
* @category Channel API
|
|
21262
|
+
* @async
|
|
21263
|
+
* @private
|
|
21264
|
+
*/
|
|
21265
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
21266
|
+
const client = getActiveClient();
|
|
21267
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
21268
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
21269
|
+
params: {
|
|
21270
|
+
messageFeedIds,
|
|
21271
|
+
options: {
|
|
21272
|
+
token: toToken(page, 'skiplimit'),
|
|
21273
|
+
},
|
|
21274
|
+
},
|
|
21275
|
+
});
|
|
21276
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21277
|
+
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
21278
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
21279
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21280
|
+
persistUnreadCountInfo({
|
|
21281
|
+
feedMarkers: feedMarkersPayload,
|
|
21282
|
+
userFeedMarkers: userFeedMarkersPayload,
|
|
21283
|
+
});
|
|
21284
|
+
}
|
|
21285
|
+
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
21286
|
+
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
21287
|
+
const cachedAt = client.cache && Date.now();
|
|
21288
|
+
if (client.cache)
|
|
21289
|
+
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
21290
|
+
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21291
|
+
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
21292
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21293
|
+
const nextPage = toPage(paging.next);
|
|
21294
|
+
const prevPage = toPage(paging.previous);
|
|
21295
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
21296
|
+
};
|
|
21297
|
+
|
|
21298
|
+
const getUserMarker = async () => {
|
|
21299
|
+
const client = getActiveClient();
|
|
21300
|
+
client.log('channel/getUserMarker');
|
|
21301
|
+
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
21302
|
+
const { userMarkers } = payload;
|
|
21303
|
+
const cachedAt = client.cache && Date.now();
|
|
21304
|
+
if (client.cache)
|
|
21305
|
+
ingestInCache({ userMarkers }, { cachedAt });
|
|
21306
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21307
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
21308
|
+
if (maxUserMarker == null ||
|
|
21309
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
21310
|
+
return userMarker;
|
|
21311
|
+
}
|
|
21312
|
+
return maxUserMarker;
|
|
21313
|
+
}, undefined);
|
|
21314
|
+
return { data: latestUserMarker, cachedAt };
|
|
21315
|
+
};
|
|
21316
|
+
|
|
21317
|
+
/** @hidden */
|
|
21318
|
+
/*
|
|
21319
|
+
* @param message payload from http request without myReactions
|
|
21320
|
+
* add myReactions to http response if the event was a reaction event
|
|
21321
|
+
*/
|
|
21322
|
+
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
21323
|
+
const client = getActiveClient();
|
|
21324
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
21325
|
+
// '[]' in cases where the new reaction is the first one
|
|
21326
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
21327
|
+
// add myReactions to the payload
|
|
21328
|
+
Object.assign(payload, { myReactions });
|
|
21329
|
+
// check if there are any updates to the reactions
|
|
21330
|
+
const latestReaction = reactors[0];
|
|
21331
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
21332
|
+
if (!isLatestReactionMine) {
|
|
21333
|
+
return;
|
|
21334
|
+
}
|
|
21335
|
+
// new reaction added
|
|
21336
|
+
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
21337
|
+
Object.assign(payload, {
|
|
21338
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
21339
|
+
});
|
|
21340
|
+
}
|
|
21341
|
+
// existing reaction removed
|
|
21342
|
+
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
21343
|
+
Object.assign(payload, {
|
|
21344
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
21345
|
+
});
|
|
21346
|
+
}
|
|
21347
|
+
};
|
|
21348
|
+
|
|
21349
|
+
/*
|
|
21350
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
21351
|
+
* value of includeDeleted
|
|
21352
|
+
*
|
|
21353
|
+
* There are two important things to note here:
|
|
21354
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
21355
|
+
* the server
|
|
21356
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
21357
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
21358
|
+
* for deleted entities
|
|
21359
|
+
*
|
|
21360
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
21361
|
+
* DRY
|
|
21362
|
+
*/
|
|
21363
|
+
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
21364
|
+
|
|
21365
|
+
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
21366
|
+
var _a, _b;
|
|
21367
|
+
// Look for `unreadCount` in the marker param first
|
|
21368
|
+
if (marker) {
|
|
21369
|
+
return marker.hasMentioned;
|
|
21370
|
+
}
|
|
21371
|
+
const client = getActiveClient();
|
|
21372
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21373
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21374
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21375
|
+
'subChannelUnreadInfo',
|
|
21376
|
+
'get',
|
|
21377
|
+
subChannelId,
|
|
21378
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21379
|
+
if (cachedUnreadCount) {
|
|
21380
|
+
return cachedUnreadCount.isMentioned;
|
|
21381
|
+
}
|
|
21382
|
+
return false;
|
|
21383
|
+
}
|
|
21384
|
+
const key = {
|
|
21385
|
+
entityId: channelId,
|
|
21386
|
+
feedId: subChannelId,
|
|
21387
|
+
userId: getActiveUser()._id,
|
|
21388
|
+
};
|
|
21389
|
+
// If the marker param is not set, look in the cache
|
|
21390
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21391
|
+
'subChannelMarker',
|
|
21392
|
+
'get',
|
|
21393
|
+
getResolver('subChannelMarker')(key),
|
|
21394
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21395
|
+
if (cachedMarker) {
|
|
21396
|
+
return cachedMarker.hasMentioned;
|
|
21397
|
+
}
|
|
21398
|
+
// and if not found in cache use default value `false`
|
|
21399
|
+
return false;
|
|
21400
|
+
}
|
|
21401
|
+
|
|
21402
|
+
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
21403
|
+
var _a, _b;
|
|
21404
|
+
// Look for `unreadCount` in the marker param first
|
|
21405
|
+
if (marker) {
|
|
21406
|
+
return marker.unreadCount;
|
|
21407
|
+
}
|
|
21408
|
+
const client = getActiveClient();
|
|
21409
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21410
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21411
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21412
|
+
'subChannelUnreadInfo',
|
|
21413
|
+
'get',
|
|
21414
|
+
subChannelId,
|
|
21415
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21416
|
+
if (cachedUnreadCount) {
|
|
21417
|
+
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
21418
|
+
}
|
|
21419
|
+
return 0;
|
|
21420
|
+
}
|
|
21421
|
+
const key = {
|
|
21422
|
+
entityId: channelId,
|
|
21423
|
+
feedId: subChannelId,
|
|
21424
|
+
userId: getActiveUser()._id,
|
|
21425
|
+
};
|
|
21426
|
+
// If the marker param is not set, look in the cache
|
|
21427
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21428
|
+
'subChannelMarker',
|
|
21429
|
+
'get',
|
|
21430
|
+
getResolver('subChannelMarker')(key),
|
|
21431
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21432
|
+
if (cachedMarker) {
|
|
21433
|
+
return cachedMarker.unreadCount;
|
|
21434
|
+
}
|
|
21435
|
+
// and if not found in cache use default value `0`
|
|
21436
|
+
return 0;
|
|
21437
|
+
}
|
|
21438
|
+
|
|
21439
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
21440
|
+
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
21441
|
+
function convertFromRaw$2(_a) {
|
|
21442
|
+
var { channelId, channelPublicId, channelType, childCount, creatorId, creatorPublicId, lastMessageId, lastMessageTimestamp, messageFeedId, name } = _a, rest = __rest(_a, ["channelId", "channelPublicId", "channelType", "childCount", "creatorId", "creatorPublicId", "lastMessageId", "lastMessageTimestamp", "messageFeedId", "name"]);
|
|
21443
|
+
return Object.assign(Object.assign({ get unreadCount() {
|
|
21444
|
+
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
21445
|
+
},
|
|
21446
|
+
get hasMentioned() {
|
|
21447
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21448
|
+
},
|
|
21449
|
+
get isMentioned() {
|
|
21450
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21451
|
+
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
21452
|
+
}
|
|
21453
|
+
|
|
21454
|
+
const mergePayloadWithLocal = (payload) => {
|
|
21455
|
+
var _a, _b, _c;
|
|
21456
|
+
const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
21457
|
+
if (localMessage) {
|
|
21458
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
21459
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
21460
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
21461
|
+
}
|
|
21462
|
+
return payload;
|
|
21463
|
+
};
|
|
21464
|
+
function convertFromRaw$1(message, reactors, event) {
|
|
21465
|
+
var _a;
|
|
21466
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
21467
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
21468
|
+
let cache;
|
|
21469
|
+
if (referenceId) {
|
|
21470
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
21471
|
+
}
|
|
21472
|
+
if (!cache) {
|
|
21473
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
21474
|
+
}
|
|
21475
|
+
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, creatorPrivateId: message.creatorId, reactions: reactions !== null && reactions !== void 0 ? reactions : {},
|
|
21476
|
+
/*
|
|
21477
|
+
* Previously, myReactions were added only if it was part of the payload.
|
|
21478
|
+
* So empty myReactions were not present. So I've edited the payload to add
|
|
21479
|
+
* a default for those cases.
|
|
21480
|
+
*
|
|
21481
|
+
* Check git blame for previous iteration
|
|
21482
|
+
*/
|
|
21483
|
+
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
21484
|
+
if (mentionedUsers) {
|
|
21485
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
21486
|
+
if (mention.type === 'channel') {
|
|
21487
|
+
return mention;
|
|
21488
|
+
}
|
|
21489
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
21490
|
+
});
|
|
21491
|
+
}
|
|
21492
|
+
if (reactors && reactors.length && event) {
|
|
21493
|
+
// mqtt event
|
|
21494
|
+
prepareMessagePayloadForCache(out, reactors, event);
|
|
21495
|
+
}
|
|
21496
|
+
return out;
|
|
21497
|
+
}
|
|
21498
|
+
const preUpdateMessageCache = (rawPayload) => {
|
|
21499
|
+
ingestInCache({
|
|
21500
|
+
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
21501
|
+
});
|
|
21502
|
+
};
|
|
21503
|
+
const DEBOUNCE_TIME = 2000;
|
|
21504
|
+
const currentDebounceMap = {};
|
|
21505
|
+
const prepareMessagePayload = async (payload, event) => {
|
|
21506
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
21507
|
+
if (markerIds.length > 0) {
|
|
21508
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21509
|
+
preUpdateMessageCache(payload);
|
|
21510
|
+
const markerIdsKey = markerIds.join('');
|
|
21511
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
21512
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
21513
|
+
}
|
|
21514
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
21515
|
+
try {
|
|
21516
|
+
getMessageMarkers(markerIds);
|
|
21517
|
+
}
|
|
21518
|
+
catch (_error) {
|
|
21519
|
+
// do nothing
|
|
21520
|
+
}
|
|
21521
|
+
}, DEBOUNCE_TIME);
|
|
21522
|
+
}
|
|
21523
|
+
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
21524
|
+
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
21525
|
+
if (messageFeeds && messageFeeds.length > 0) {
|
|
21526
|
+
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
21527
|
+
var _a, _b;
|
|
21528
|
+
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
21529
|
+
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
21530
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
21531
|
+
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
21532
|
+
});
|
|
21533
|
+
}
|
|
21534
|
+
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
21535
|
+
};
|
|
21536
|
+
function convertParams(_a) {
|
|
21537
|
+
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
21538
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
21539
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
21540
|
+
}
|
|
21541
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
21542
|
+
}
|
|
21543
|
+
function convertQueryParams$1(_a) {
|
|
21544
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
21545
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
21546
|
+
sortBy,
|
|
21547
|
+
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
21548
|
+
around: aroundMessageId,
|
|
21549
|
+
} });
|
|
21550
|
+
if (includingTags) {
|
|
21551
|
+
out.includeTags = includingTags;
|
|
21552
|
+
}
|
|
21553
|
+
if (type) {
|
|
21554
|
+
out.dataType = type;
|
|
21555
|
+
}
|
|
21556
|
+
if (excludingTags) {
|
|
21557
|
+
out.excludeTags = excludingTags;
|
|
21558
|
+
}
|
|
21559
|
+
return out;
|
|
21560
|
+
}
|
|
21561
|
+
|
|
21562
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21563
|
+
/**
|
|
21564
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
21565
|
+
*/
|
|
21566
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
21567
|
+
const preUpdateSubChannelCache = (rawPayload) => {
|
|
21568
|
+
ingestInCache({
|
|
21569
|
+
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
21570
|
+
});
|
|
21571
|
+
};
|
|
21572
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
21573
|
+
const markerIds = rawPayload.messageFeeds
|
|
21574
|
+
.filter(isUnreadCountSupport$1)
|
|
21575
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
21576
|
+
if (markerIds.length > 0) {
|
|
21577
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21578
|
+
preUpdateSubChannelCache(rawPayload);
|
|
21579
|
+
try {
|
|
21580
|
+
await getSubChannelMarkers(markerIds);
|
|
21581
|
+
}
|
|
21582
|
+
catch (e) {
|
|
21583
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21584
|
+
}
|
|
21585
|
+
}
|
|
21586
|
+
updateSubChannelMessagePreviewCache(rawPayload);
|
|
21587
|
+
// attach marker to sub channel
|
|
21588
|
+
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
21589
|
+
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
21590
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
21591
|
+
messages });
|
|
21592
|
+
};
|
|
21593
|
+
function convertQueryParams(_a) {
|
|
21594
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
21595
|
+
const out = Object.assign({}, rest);
|
|
21596
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
21597
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
21598
|
+
}
|
|
21599
|
+
return out;
|
|
21600
|
+
}
|
|
21601
|
+
|
|
21602
|
+
/**
|
|
21603
|
+
* ```js
|
|
21604
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21605
|
+
* const subChannel = await getSubChannel('foobar')
|
|
21606
|
+
* ```
|
|
21607
|
+
*
|
|
21608
|
+
* Fetches a {@link Amity.SubChannel} object
|
|
21609
|
+
*
|
|
21610
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21611
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21612
|
+
*
|
|
21613
|
+
* @category Channel API
|
|
21614
|
+
* @async
|
|
21615
|
+
*/
|
|
21616
|
+
const getSubChannel$1 = async (subChannelId) => {
|
|
21617
|
+
const client = getActiveClient();
|
|
21618
|
+
client.log('channel/getSubChannel', subChannelId);
|
|
21619
|
+
isInTombstone('subChannel', subChannelId);
|
|
21620
|
+
try {
|
|
21621
|
+
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
21622
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
21623
|
+
const cachedAt = client.cache && Date.now();
|
|
21624
|
+
if (client.cache)
|
|
21625
|
+
ingestInCache(data, { cachedAt });
|
|
21626
|
+
fireEvent('local.message-feed.fetched', data);
|
|
21627
|
+
return {
|
|
21628
|
+
data: data.messageFeeds[0],
|
|
21629
|
+
cachedAt,
|
|
21630
|
+
};
|
|
21631
|
+
}
|
|
21632
|
+
catch (error) {
|
|
21633
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
21634
|
+
pushToTombstone('subChannel', subChannelId);
|
|
21635
|
+
}
|
|
21636
|
+
throw error;
|
|
21637
|
+
}
|
|
21638
|
+
};
|
|
21639
|
+
/**
|
|
21640
|
+
* ```js
|
|
21641
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21642
|
+
* const subChannel = getSubChannel.locally('foobar')
|
|
21643
|
+
* ```
|
|
21644
|
+
*
|
|
21645
|
+
* Fetches a {@link Amity.SubChannel} object from cache
|
|
21646
|
+
*
|
|
21647
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21648
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21649
|
+
*
|
|
21650
|
+
* @category Channel API
|
|
21651
|
+
*/
|
|
21652
|
+
getSubChannel$1.locally = (subChannelId) => {
|
|
21653
|
+
const client = getActiveClient();
|
|
21654
|
+
client.log('channel/getSubChannel.locally', subChannelId);
|
|
21655
|
+
if (!client.cache)
|
|
21656
|
+
return;
|
|
21657
|
+
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
21658
|
+
if (!cached)
|
|
21659
|
+
return;
|
|
21660
|
+
return {
|
|
21661
|
+
data: cached.data,
|
|
21662
|
+
cachedAt: cached.cachedAt,
|
|
21663
|
+
};
|
|
21664
|
+
};
|
|
21665
|
+
|
|
21666
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
21667
|
+
return new Date(dateString).getTime();
|
|
21668
|
+
};
|
|
21669
|
+
|
|
21670
|
+
const getMessagePreviewSetting$1 = async () => {
|
|
21671
|
+
const client = getActiveClient();
|
|
21672
|
+
return client.getMessagePreviewSetting(false);
|
|
21673
|
+
};
|
|
21674
|
+
const getSubChannelCache = async (subChannelId) => {
|
|
21675
|
+
var _a;
|
|
21676
|
+
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21677
|
+
if (!subChannelCache) {
|
|
21678
|
+
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
21679
|
+
}
|
|
21680
|
+
return subChannelCache;
|
|
21681
|
+
};
|
|
21682
|
+
const isLastestMessageOnSubchannel = (message) => {
|
|
21683
|
+
var _a;
|
|
21684
|
+
const cache = (_a = pullFromCache([
|
|
21685
|
+
'messagePreviewSubChannel',
|
|
21686
|
+
'get',
|
|
21687
|
+
message.subChannelId,
|
|
21688
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21689
|
+
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
21690
|
+
return (!cache ||
|
|
21691
|
+
cache.segment <= message.channelSegment ||
|
|
21692
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21693
|
+
};
|
|
21694
|
+
const isLastestMessageOnChannel = (message) => {
|
|
21695
|
+
var _a;
|
|
21696
|
+
const cache = (_a = pullFromCache([
|
|
21697
|
+
'messagePreviewChannel',
|
|
21698
|
+
'get',
|
|
21699
|
+
message.channelId,
|
|
21700
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21701
|
+
return (!cache ||
|
|
21702
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21703
|
+
};
|
|
21704
|
+
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
21705
|
+
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
21706
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21707
|
+
// 1. get subChannel from cache, if not exist fetch from server
|
|
21708
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21709
|
+
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
21710
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
21711
|
+
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
21712
|
+
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
21713
|
+
convertDateStringToTimestamp(createdAt))
|
|
21714
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21715
|
+
lastActivity: createdAt,
|
|
21716
|
+
});
|
|
21717
|
+
return;
|
|
21718
|
+
}
|
|
21719
|
+
// 3. if messagePreviewSetting is `NOT` NO_MESSAGE_PREVEIW, update messagePreviewSubChannel and subChannel cache
|
|
21720
|
+
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
21721
|
+
if (!isLastestMessageOnSubchannel(message))
|
|
21722
|
+
return;
|
|
21723
|
+
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
21724
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21725
|
+
channelId,
|
|
21726
|
+
creatorId,
|
|
21727
|
+
messagePreviewId,
|
|
21728
|
+
createdAt,
|
|
21729
|
+
updatedAt,
|
|
21730
|
+
subChannelId,
|
|
21731
|
+
data,
|
|
21732
|
+
dataType,
|
|
21733
|
+
segment,
|
|
21734
|
+
isDeleted,
|
|
21735
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21736
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21737
|
+
});
|
|
21738
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21739
|
+
lastActivity: createdAt,
|
|
21740
|
+
messagePreviewId,
|
|
21741
|
+
});
|
|
21742
|
+
};
|
|
21743
|
+
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
21744
|
+
var _a;
|
|
21745
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21746
|
+
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
21747
|
+
'messagePreviewSubChannel',
|
|
21748
|
+
'get',
|
|
21749
|
+
message.subChannelId,
|
|
21750
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21751
|
+
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
21752
|
+
if (messagePreviewSubChannelCache &&
|
|
21753
|
+
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
21754
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21755
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21756
|
+
channelId,
|
|
21757
|
+
creatorId,
|
|
21758
|
+
messagePreviewId,
|
|
21759
|
+
createdAt,
|
|
21760
|
+
updatedAt,
|
|
21761
|
+
subChannelId,
|
|
21762
|
+
data,
|
|
21763
|
+
dataType,
|
|
21764
|
+
segment,
|
|
21765
|
+
isDeleted,
|
|
21766
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21767
|
+
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
21768
|
+
});
|
|
21769
|
+
}
|
|
21770
|
+
};
|
|
21771
|
+
const handleMessageCreated = async (message) => {
|
|
21772
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21773
|
+
if (isLastestMessageOnChannel(message)) {
|
|
21774
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21775
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21776
|
+
channelId,
|
|
21777
|
+
creatorId,
|
|
21778
|
+
messagePreviewId,
|
|
21779
|
+
createdAt,
|
|
21780
|
+
updatedAt,
|
|
21781
|
+
subChannelId,
|
|
21782
|
+
data,
|
|
21783
|
+
dataType,
|
|
21784
|
+
segment,
|
|
21785
|
+
isDeleted,
|
|
21786
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21787
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21788
|
+
});
|
|
21789
|
+
}
|
|
21790
|
+
};
|
|
21791
|
+
const handleMessageUpdated = async (message) => {
|
|
21792
|
+
/**
|
|
21793
|
+
* Channel Case
|
|
21794
|
+
*/
|
|
21795
|
+
var _a;
|
|
21796
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21797
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21798
|
+
'messagePreviewChannel',
|
|
21799
|
+
'get',
|
|
21800
|
+
message.channelId,
|
|
21801
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21802
|
+
if (messagePreviewChannelCache &&
|
|
21803
|
+
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
21804
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21805
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21806
|
+
channelId,
|
|
21807
|
+
creatorId,
|
|
21808
|
+
messagePreviewId,
|
|
21809
|
+
createdAt,
|
|
21810
|
+
updatedAt,
|
|
21811
|
+
subChannelId,
|
|
21812
|
+
data,
|
|
21813
|
+
dataType,
|
|
21814
|
+
segment,
|
|
21815
|
+
isDeleted,
|
|
21816
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21817
|
+
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
21818
|
+
});
|
|
21819
|
+
}
|
|
21820
|
+
};
|
|
21821
|
+
const handleSubChannelUpdated = async (subChannel) => {
|
|
21822
|
+
var _a, _b, _c, _d;
|
|
21823
|
+
const { channelId, subChannelId } = subChannel;
|
|
21824
|
+
/** Channel Case */
|
|
21825
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21826
|
+
'messagePreviewChannel',
|
|
21827
|
+
'get',
|
|
21828
|
+
channelId,
|
|
21829
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21830
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
21831
|
+
const subChannelCache = (_b = pullFromCache([
|
|
21832
|
+
'subChannel',
|
|
21833
|
+
'get',
|
|
21834
|
+
subChannelId,
|
|
21835
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21836
|
+
pushToCache(['messagePreviewChannel', 'get', channelId], Object.assign(Object.assign({}, messagePreviewChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
21837
|
+
}
|
|
21838
|
+
/** SubChannel Case */
|
|
21839
|
+
const messagePreviewSubChannelCache = (_c = pullFromCache([
|
|
21840
|
+
'messagePreviewSubChannel',
|
|
21841
|
+
'get',
|
|
21842
|
+
subChannelId,
|
|
21843
|
+
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
21844
|
+
if (messagePreviewSubChannelCache &&
|
|
21845
|
+
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
21846
|
+
new Date(subChannel.updatedAt).valueOf()) {
|
|
21847
|
+
const subChannelCache = (_d = pullFromCache([
|
|
21848
|
+
'subChannel',
|
|
21849
|
+
'get',
|
|
21850
|
+
subChannelId,
|
|
21851
|
+
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
21852
|
+
pushToCache(['messagePreviewSubChannel', 'get', subChannelId], Object.assign(Object.assign({}, messagePreviewSubChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
21853
|
+
}
|
|
21854
|
+
};
|
|
21855
|
+
|
|
21856
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
21857
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
21858
|
+
}
|
|
21859
|
+
|
|
21860
|
+
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21861
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
21862
|
+
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
21863
|
+
var _a;
|
|
21864
|
+
let { messagePreviewId } = channel;
|
|
21865
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21866
|
+
'messagePreviewChannel',
|
|
21867
|
+
'get',
|
|
21868
|
+
channel.channelId,
|
|
21869
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21870
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
21871
|
+
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
21872
|
+
}
|
|
21873
|
+
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
21874
|
+
}
|
|
21875
|
+
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21876
|
+
ingestInCache({
|
|
21877
|
+
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
21878
|
+
});
|
|
21879
|
+
};
|
|
21880
|
+
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
21881
|
+
for (let i = 0; i < channels.length; i += 1) {
|
|
21882
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
21883
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
21884
|
+
let unreadCount = 0;
|
|
21885
|
+
let readToSegment = null;
|
|
21886
|
+
let lastMentionedSegment = null;
|
|
21887
|
+
let isMentioned = false;
|
|
21888
|
+
if (channelUser) {
|
|
21889
|
+
readToSegment = channelUser.readToSegment;
|
|
21890
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
21891
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
21892
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
21893
|
+
}
|
|
21894
|
+
const cacheChannelUnread = {
|
|
21895
|
+
channelId: channels[i].channelId,
|
|
21896
|
+
lastSegment: channels[i].messageCount,
|
|
21897
|
+
readToSegment,
|
|
21898
|
+
lastMentionedSegment,
|
|
21899
|
+
unreadCount,
|
|
21900
|
+
isMentioned,
|
|
21901
|
+
isDeleted: channels[i].isDeleted || false,
|
|
21902
|
+
};
|
|
21903
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
21904
|
+
}
|
|
21905
|
+
};
|
|
21906
|
+
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21907
|
+
const client = getActiveClient();
|
|
21908
|
+
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
21909
|
+
if (options.isMessagePreviewUpdated &&
|
|
21910
|
+
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
21911
|
+
rawPayload.messagePreviews &&
|
|
21912
|
+
rawPayload.messagePreviews.length > 0) {
|
|
21913
|
+
updateChannelMessagePreviewCache(rawPayload);
|
|
21914
|
+
}
|
|
21915
|
+
if (client.useLegacyUnreadCount) {
|
|
21916
|
+
updateChannelUnread({
|
|
21917
|
+
channels: rawPayload.channels,
|
|
21918
|
+
channelUsers: rawPayload.channelUsers,
|
|
21919
|
+
currentUserId: client.userId,
|
|
21920
|
+
});
|
|
21921
|
+
}
|
|
21922
|
+
else {
|
|
21923
|
+
const markerIds = rawPayload.channels
|
|
21924
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
21925
|
+
.filter(isUnreadCountSupport)
|
|
21926
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
21927
|
+
if (markerIds.length > 0) {
|
|
21928
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21929
|
+
preUpdateChannelCache(rawPayload, {
|
|
21930
|
+
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
21931
|
+
});
|
|
21932
|
+
try {
|
|
21933
|
+
await getChannelMarkers(markerIds);
|
|
21934
|
+
}
|
|
21935
|
+
catch (e) {
|
|
21936
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21937
|
+
}
|
|
21938
|
+
}
|
|
21939
|
+
}
|
|
21940
|
+
// convert raw channel to internal channel
|
|
21941
|
+
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
21942
|
+
// convert raw channel user to membership (add user object)
|
|
21943
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
21944
|
+
return convertRawMembershipToMembership(channelUser);
|
|
21945
|
+
});
|
|
21946
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
21947
|
+
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
21948
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
21949
|
+
channels,
|
|
21950
|
+
channelUsers });
|
|
21951
|
+
};
|
|
21952
|
+
|
|
21953
|
+
/**
|
|
21954
|
+
* ```js
|
|
21955
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21956
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21957
|
+
* ```
|
|
21958
|
+
*
|
|
21959
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21960
|
+
*
|
|
21961
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21962
|
+
* @param page
|
|
21963
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21964
|
+
*
|
|
21965
|
+
* @category Channel API
|
|
21966
|
+
* @async
|
|
21967
|
+
* @private
|
|
21968
|
+
*/
|
|
21969
|
+
const getUserMessageFeedMakers = async (channelIds) => {
|
|
21970
|
+
const client = getActiveClient();
|
|
21971
|
+
client.log('channel/getUserMessageFeedMakers', channelIds);
|
|
21972
|
+
const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
|
|
21973
|
+
params: {
|
|
21974
|
+
channelIds,
|
|
21975
|
+
},
|
|
21976
|
+
});
|
|
21977
|
+
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
21978
|
+
return data;
|
|
21979
|
+
};
|
|
21980
|
+
|
|
21981
|
+
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
21982
|
+
const client = getActiveClient();
|
|
21983
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
21984
|
+
// Marker service API uses channelInternalId as channelId
|
|
21985
|
+
const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
|
|
21986
|
+
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
21987
|
+
persistUnreadCountInfo({
|
|
21988
|
+
feedMarkers,
|
|
21989
|
+
userFeedMarkers,
|
|
21990
|
+
});
|
|
21991
|
+
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
21992
|
+
};
|
|
21993
|
+
|
|
21994
|
+
const getCachedMarker$2 = (entityId) => {
|
|
21995
|
+
var _a;
|
|
21996
|
+
const key = {
|
|
21997
|
+
entityId,
|
|
21998
|
+
userId: getActiveUser()._id,
|
|
21999
|
+
};
|
|
22000
|
+
return (_a = pullFromCache([
|
|
22001
|
+
'channelMarker',
|
|
22002
|
+
'get',
|
|
22003
|
+
getResolver('channelMarker')(key),
|
|
22004
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22005
|
+
};
|
|
22006
|
+
const getUnreadInfoCached$1 = (channelId) => {
|
|
22007
|
+
var _a;
|
|
22008
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22009
|
+
};
|
|
22010
|
+
/**
|
|
22011
|
+
* The function use to get value of hasMentioned or isMentioned field.
|
|
22012
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22013
|
+
*
|
|
22014
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22015
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22016
|
+
* If not found in the both cache, use `false` as defaul value.
|
|
22017
|
+
*/
|
|
22018
|
+
const getChannelIsMentioned = (channel, marker) => {
|
|
22019
|
+
var _a, _b, _c, _d;
|
|
22020
|
+
const client = getActiveClient();
|
|
22021
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22022
|
+
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22023
|
+
}
|
|
22024
|
+
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
22025
|
+
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
22026
|
+
: (_d = (_c = getCachedMarker$2(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22027
|
+
};
|
|
22028
|
+
|
|
22029
|
+
const getCachedMarker$1 = (entityId) => {
|
|
22030
|
+
var _a;
|
|
22031
|
+
const key = {
|
|
22032
|
+
entityId,
|
|
22033
|
+
userId: getActiveUser()._id,
|
|
22034
|
+
};
|
|
22035
|
+
return (_a = pullFromCache([
|
|
22036
|
+
'channelMarker',
|
|
22037
|
+
'get',
|
|
22038
|
+
getResolver('channelMarker')(key),
|
|
22039
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22040
|
+
};
|
|
22041
|
+
const getUnreadInfoCached = (channelId) => {
|
|
22042
|
+
var _a;
|
|
22043
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22044
|
+
};
|
|
22045
|
+
/**
|
|
22046
|
+
* The function use to get value of unreadCount field.
|
|
22047
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22048
|
+
*
|
|
22049
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22050
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22051
|
+
* If not found in the both cache, use `0` as defaul value.
|
|
22052
|
+
*/
|
|
22053
|
+
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
22054
|
+
var _a, _b, _c, _d, _e;
|
|
22055
|
+
const client = getActiveClient();
|
|
22056
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22057
|
+
// Marker service API uses channelInternalId as channelId
|
|
22058
|
+
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22059
|
+
}
|
|
22060
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
22061
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
22062
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
22063
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
22064
|
+
return 0;
|
|
22065
|
+
}
|
|
22066
|
+
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
22067
|
+
};
|
|
22068
|
+
|
|
22069
|
+
const getLegacyChannelUnread = (channelId) => {
|
|
22070
|
+
var _a;
|
|
22071
|
+
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22072
|
+
};
|
|
22073
|
+
|
|
22074
|
+
const constructChannelDynamicValue = (channel) => {
|
|
22075
|
+
const client = getActiveClient();
|
|
22076
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
22077
|
+
return shallowClone(rest, {
|
|
22078
|
+
get unreadCount() {
|
|
22079
|
+
var _a, _b;
|
|
22080
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22081
|
+
},
|
|
22082
|
+
get subChannelsUnreadCount() {
|
|
22083
|
+
return getSubChannelsUnreadCount(rest);
|
|
22084
|
+
},
|
|
22085
|
+
get isMentioned() {
|
|
22086
|
+
var _a, _b;
|
|
22087
|
+
if (client.useLegacyUnreadCount)
|
|
22088
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22089
|
+
return getChannelIsMentioned(rest);
|
|
22090
|
+
},
|
|
22091
|
+
});
|
|
22092
|
+
};
|
|
22093
|
+
|
|
22094
|
+
const ANALYTIC_CACHE_KEY = ['analytic', 'normal-priority'];
|
|
22095
|
+
const HIGH_PRIORITY_ANALYTIC_CACHE_KEY = ['analytic', 'high-priority'];
|
|
22096
|
+
|
|
22097
|
+
const syncEvent = async (events) => {
|
|
22098
|
+
const client = getActiveClient();
|
|
22099
|
+
const params = {
|
|
22100
|
+
activities: events,
|
|
22101
|
+
};
|
|
22102
|
+
await client.http.post('/api/v1/analytics/activities', params);
|
|
22103
|
+
};
|
|
22104
|
+
|
|
22105
|
+
class AnalyticsEventSyncer {
|
|
22106
|
+
constructor() {
|
|
22107
|
+
this._timer = undefined;
|
|
22108
|
+
this._high_priority_timer = undefined;
|
|
22109
|
+
}
|
|
22110
|
+
start() {
|
|
22111
|
+
this.syncCapturedEvent();
|
|
22112
|
+
this._timer = setInterval(() => {
|
|
22113
|
+
this.syncCapturedEvent();
|
|
22114
|
+
}, 1 * MINUTE);
|
|
22115
|
+
this._high_priority_timer = setInterval(() => {
|
|
22116
|
+
this.syncHighPriorityCapturedEvent();
|
|
22117
|
+
}, 10 * SECOND$1);
|
|
22118
|
+
}
|
|
22119
|
+
stop() {
|
|
22120
|
+
if (this._timer) {
|
|
22121
|
+
clearInterval(this._timer);
|
|
22122
|
+
this._timer = undefined;
|
|
22123
|
+
}
|
|
22124
|
+
if (this._high_priority_timer) {
|
|
22125
|
+
clearInterval(this._high_priority_timer);
|
|
22126
|
+
this._high_priority_timer = undefined;
|
|
22127
|
+
}
|
|
22128
|
+
}
|
|
22129
|
+
async syncCapturedEvent() {
|
|
22130
|
+
try {
|
|
22131
|
+
// Must query only objects that have same userId with current logged-in user.
|
|
22132
|
+
// Query captured event with maximum of 1000
|
|
22133
|
+
// Order by latest first
|
|
22134
|
+
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
22135
|
+
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
22136
|
+
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
22137
|
+
return;
|
|
22138
|
+
if (cache.data.event.length === 0)
|
|
22139
|
+
return;
|
|
22140
|
+
const capturedEvents = cache.data.event;
|
|
22141
|
+
await syncEvent(capturedEvents);
|
|
22142
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
22143
|
+
}
|
|
22144
|
+
catch (error) {
|
|
22145
|
+
// stop and destroy all events
|
|
22146
|
+
this.stop();
|
|
22147
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
22148
|
+
}
|
|
22149
|
+
}
|
|
22150
|
+
async syncHighPriorityCapturedEvent() {
|
|
22151
|
+
try {
|
|
22152
|
+
// Must query only objects that have same userId with current logged-in user.
|
|
22153
|
+
// Query captured event with maximum of 1000
|
|
22154
|
+
// Order by latest first
|
|
22155
|
+
// e.g., If there are 2000 events we will query 1000-2000 first
|
|
22156
|
+
const cache = pullFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
22157
|
+
if (!(cache === null || cache === void 0 ? void 0 : cache.data))
|
|
22158
|
+
return;
|
|
22159
|
+
if (cache.data.event.length === 0)
|
|
22160
|
+
return;
|
|
22161
|
+
const capturedEvents = cache.data.event;
|
|
22162
|
+
await syncEvent(capturedEvents);
|
|
22163
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
22164
|
+
}
|
|
22165
|
+
catch (error) {
|
|
22166
|
+
// stop and destroy all events
|
|
22167
|
+
this.stop();
|
|
22168
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
22169
|
+
}
|
|
22170
|
+
}
|
|
22171
|
+
}
|
|
22172
|
+
|
|
22173
|
+
class AnalyticsEventCapturer {
|
|
22174
|
+
constructor() {
|
|
22175
|
+
this._expireTime = 5 * MINUTE;
|
|
22176
|
+
this._poolLimit = 1000;
|
|
22177
|
+
this._recentViewed = {};
|
|
22178
|
+
this._recentHighPriorityViewed = {};
|
|
22179
|
+
// Story
|
|
22180
|
+
this._throttleStoryTimer = undefined;
|
|
22181
|
+
this._bufferNewSeenStoryReferenceIds = [];
|
|
22182
|
+
}
|
|
22183
|
+
isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
|
|
22184
|
+
const now = new Date();
|
|
22185
|
+
// Get the recent view date (if any)
|
|
22186
|
+
const recentViewedDate = isHighPriority
|
|
22187
|
+
? this._recentHighPriorityViewed[uniqueId]
|
|
22188
|
+
: this._recentViewed[uniqueId];
|
|
22189
|
+
// If this is the first view, always allow it
|
|
22190
|
+
if (!recentViewedDate) {
|
|
22191
|
+
return true;
|
|
22192
|
+
}
|
|
22193
|
+
const timeDiff = now.getTime() - recentViewedDate.getTime();
|
|
22194
|
+
if (timeDiff < expireTime) {
|
|
22195
|
+
// just recently view this post, ignore the event.
|
|
22196
|
+
return false;
|
|
22197
|
+
}
|
|
22198
|
+
return true;
|
|
22199
|
+
}
|
|
22200
|
+
markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
|
|
22201
|
+
if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
|
|
22202
|
+
return;
|
|
22203
|
+
const now = new Date();
|
|
22204
|
+
const currentData = { event: [] };
|
|
22205
|
+
const cache = pullFromCache(ANALYTIC_CACHE_KEY);
|
|
22206
|
+
if (cache === null || cache === void 0 ? void 0 : cache.data) {
|
|
22207
|
+
currentData.event = cache.data.event;
|
|
22208
|
+
}
|
|
22209
|
+
// If the pool is full (Max 1000 items), remove the oldest data
|
|
22210
|
+
if (currentData.event.length >= this._poolLimit) {
|
|
22211
|
+
// Remove oldest data
|
|
22212
|
+
currentData.event.shift();
|
|
22213
|
+
}
|
|
22214
|
+
const analyticItem = {
|
|
22215
|
+
contentId,
|
|
22216
|
+
contentType,
|
|
22217
|
+
activityType,
|
|
22218
|
+
timestamp: now.toISOString(),
|
|
22219
|
+
};
|
|
22220
|
+
if (metadata) {
|
|
22221
|
+
analyticItem.metadata = metadata;
|
|
22222
|
+
}
|
|
22223
|
+
currentData.event.push(analyticItem);
|
|
22224
|
+
upsertInCache(ANALYTIC_CACHE_KEY, currentData);
|
|
22225
|
+
this._recentViewed[uniqueId] = now;
|
|
22226
|
+
}
|
|
22227
|
+
markPostAsViewed(postId) {
|
|
22228
|
+
this.markAs({
|
|
22229
|
+
uniqueId: postId,
|
|
22230
|
+
contentId: postId,
|
|
22231
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
22232
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
22233
|
+
});
|
|
22234
|
+
}
|
|
22235
|
+
markStory(story, activityType) {
|
|
22236
|
+
if (!story.expiresAt)
|
|
22237
|
+
return;
|
|
22238
|
+
const now = new Date();
|
|
22239
|
+
const expireTime = new Date(story.expiresAt);
|
|
22240
|
+
if (!this.isAbleToEnqueue({
|
|
22241
|
+
uniqueId: story.storyId,
|
|
22242
|
+
expireTime: expireTime.getTime(),
|
|
22243
|
+
isHighPriority: true,
|
|
22244
|
+
}))
|
|
22245
|
+
return;
|
|
22246
|
+
const currentData = { event: [] };
|
|
22247
|
+
const cache = pullFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
22248
|
+
if (cache === null || cache === void 0 ? void 0 : cache.data) {
|
|
22249
|
+
currentData.event = cache.data.event;
|
|
22250
|
+
}
|
|
22251
|
+
// If the pool is full (Max 1000 items), remove the oldest data
|
|
22252
|
+
if (currentData.event.length >= this._poolLimit) {
|
|
22253
|
+
// Remove oldest data
|
|
22254
|
+
currentData.event.shift();
|
|
22255
|
+
}
|
|
22256
|
+
currentData.event.push({
|
|
22257
|
+
contentId: story.storyId,
|
|
22258
|
+
contentType: "story" /* Amity.AnalyticEventContentType.Story */,
|
|
22259
|
+
activityType,
|
|
22260
|
+
timestamp: now.toISOString(),
|
|
22261
|
+
});
|
|
22262
|
+
upsertInCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY, currentData);
|
|
22263
|
+
this._recentHighPriorityViewed[story.storyId] = now;
|
|
22264
|
+
// Fire internal event if the activity type is not click
|
|
22265
|
+
if (activityType === "linkClicked" /* Amity.AnalyticEventActivityType.Click */)
|
|
22266
|
+
return;
|
|
22267
|
+
// Mark story as SEEN
|
|
22268
|
+
pushToCache(["story-seen" /* STORY_KEY_CACHE.IS_SEEN */, 'get', story.storyId], new Date().toISOString());
|
|
22269
|
+
// Update the latest timestamp for LocalStoryLastSeen
|
|
22270
|
+
const currentLastSeen = pullFromCache([
|
|
22271
|
+
"story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */,
|
|
22272
|
+
story.targetId,
|
|
22273
|
+
]);
|
|
22274
|
+
if (currentLastSeen === null || currentLastSeen === void 0 ? void 0 : currentLastSeen.data) {
|
|
22275
|
+
if (new Date(currentLastSeen.data).getTime() < new Date(story.expiresAt).getTime()) {
|
|
22276
|
+
pushToCache(["story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */, story.targetId], story.expiresAt);
|
|
22277
|
+
}
|
|
22278
|
+
}
|
|
22279
|
+
else {
|
|
22280
|
+
pushToCache(["story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */, story.targetId], story.expiresAt);
|
|
22281
|
+
}
|
|
22282
|
+
this._bufferNewSeenStoryReferenceIds.push(story.referenceId);
|
|
22283
|
+
if (this._throttleStoryTimer)
|
|
22284
|
+
return;
|
|
22285
|
+
this._throttleStoryTimer = setTimeout(() => {
|
|
22286
|
+
clearTimeout(this._throttleStoryTimer);
|
|
22287
|
+
fireEvent('local.story.reload', { referenceIds: this._bufferNewSeenStoryReferenceIds });
|
|
22288
|
+
this._bufferNewSeenStoryReferenceIds = [];
|
|
22289
|
+
}, 300);
|
|
22290
|
+
}
|
|
22291
|
+
resetAllBuckets() {
|
|
22292
|
+
this._recentViewed = {};
|
|
22293
|
+
this._recentHighPriorityViewed = {};
|
|
22294
|
+
dropFromCache(ANALYTIC_CACHE_KEY);
|
|
22295
|
+
dropFromCache(HIGH_PRIORITY_ANALYTIC_CACHE_KEY);
|
|
22296
|
+
}
|
|
22297
|
+
markStoryAsViewed(story) {
|
|
22298
|
+
this.markStory(story, "view" /* Amity.AnalyticEventActivityType.View */);
|
|
22299
|
+
}
|
|
22300
|
+
markStoryAsClicked(story) {
|
|
22301
|
+
this.markStory(story, "linkClicked" /* Amity.AnalyticEventActivityType.Click */);
|
|
22302
|
+
}
|
|
22303
|
+
markAdAsViewed(ad, placement) {
|
|
22304
|
+
const metadata = {
|
|
22305
|
+
placement,
|
|
22306
|
+
};
|
|
22307
|
+
const activityType = "view" /* Amity.AnalyticEventActivityType.View */;
|
|
22308
|
+
this.markAs({
|
|
22309
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
22310
|
+
contentId: ad.adId,
|
|
22311
|
+
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
22312
|
+
activityType,
|
|
22313
|
+
metadata,
|
|
22314
|
+
});
|
|
22315
|
+
}
|
|
22316
|
+
markAdAsClicked(ad, placement) {
|
|
22317
|
+
const metadata = {
|
|
22318
|
+
placement,
|
|
22319
|
+
};
|
|
22320
|
+
const activityType = "linkClicked" /* Amity.AnalyticEventActivityType.Click */;
|
|
22321
|
+
this.markAs({
|
|
22322
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
22323
|
+
contentId: ad.adId,
|
|
22324
|
+
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
22325
|
+
activityType,
|
|
22326
|
+
metadata,
|
|
22327
|
+
});
|
|
22328
|
+
}
|
|
22329
|
+
}
|
|
22330
|
+
|
|
22331
|
+
class AnalyticsEngine {
|
|
22332
|
+
constructor() {
|
|
22333
|
+
this._client = getActiveClient();
|
|
22334
|
+
this._eventCapturer = new AnalyticsEventCapturer();
|
|
22335
|
+
this._eventSyncer = new AnalyticsEventSyncer();
|
|
22336
|
+
}
|
|
22337
|
+
markPostAsViewed(postId) {
|
|
22338
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
22339
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
22340
|
+
) {
|
|
22341
|
+
this._eventCapturer.markPostAsViewed(postId);
|
|
22342
|
+
}
|
|
22343
|
+
}
|
|
22344
|
+
markStoryAsViewed(story) {
|
|
22345
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
22346
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
22347
|
+
) {
|
|
22348
|
+
this._eventCapturer.markStoryAsViewed(story);
|
|
22349
|
+
}
|
|
22350
|
+
}
|
|
22351
|
+
markAdAsViewed(ad, placement) {
|
|
22352
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
22353
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
22354
|
+
this._eventCapturer.markAdAsViewed(ad, placement);
|
|
22355
|
+
}
|
|
22356
|
+
}
|
|
22357
|
+
markAdAsClicked(ad, placement) {
|
|
22358
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
22359
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
22360
|
+
this._eventCapturer.markAdAsClicked(ad, placement);
|
|
22361
|
+
}
|
|
22362
|
+
}
|
|
22363
|
+
markStoryAsClicked(story) {
|
|
22364
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
22365
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
22366
|
+
this._eventCapturer.markStoryAsClicked(story);
|
|
22367
|
+
}
|
|
22368
|
+
}
|
|
22369
|
+
established() {
|
|
22370
|
+
this._eventSyncer.start();
|
|
22371
|
+
}
|
|
22372
|
+
handleTokenExpired() {
|
|
22373
|
+
this._stopAndDestroy();
|
|
22374
|
+
}
|
|
22375
|
+
destroy() {
|
|
22376
|
+
this._stopAndDestroy();
|
|
22377
|
+
}
|
|
22378
|
+
_stopAndDestroy() {
|
|
22379
|
+
this._eventSyncer.stop();
|
|
22380
|
+
this._eventCapturer.resetAllBuckets();
|
|
22381
|
+
}
|
|
22382
|
+
}
|
|
22383
|
+
let instance$5;
|
|
22384
|
+
var AnalyticsEngine$1 = {
|
|
22385
|
+
getInstance: () => {
|
|
22386
|
+
if (!instance$5) {
|
|
22387
|
+
instance$5 = new AnalyticsEngine();
|
|
22388
|
+
}
|
|
22389
|
+
return instance$5;
|
|
22390
|
+
},
|
|
22391
|
+
};
|
|
22392
|
+
|
|
22393
|
+
class StoryComputedValue {
|
|
22394
|
+
constructor(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt) {
|
|
22395
|
+
this._syncingStoriesCount = 0;
|
|
22396
|
+
this._errorStoriesCount = 0;
|
|
22397
|
+
this._targetId = targetId;
|
|
22398
|
+
this._lastStoryExpiresAt = lastStoryExpiresAt;
|
|
22399
|
+
this._lastStorySeenExpiresAt = lastStorySeenExpiresAt;
|
|
22400
|
+
this.cacheStoryExpireTime = pullFromCache([
|
|
22401
|
+
"story-expire" /* STORY_KEY_CACHE.EXPIRE */,
|
|
22402
|
+
this._targetId,
|
|
22403
|
+
]);
|
|
22404
|
+
this.cacheStoreSeenTime = pullFromCache([
|
|
22405
|
+
"story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */,
|
|
22406
|
+
this._targetId,
|
|
22407
|
+
]);
|
|
22408
|
+
this.getTotalStoryByStatus();
|
|
22409
|
+
}
|
|
22410
|
+
get lastStoryExpiresAt() {
|
|
22411
|
+
return this._lastStoryExpiresAt ? new Date(this._lastStoryExpiresAt).getTime() : 0;
|
|
22412
|
+
}
|
|
22413
|
+
get lastStorySeenExpiresAt() {
|
|
22414
|
+
return this._lastStorySeenExpiresAt ? new Date(this._lastStorySeenExpiresAt).getTime() : 0;
|
|
22415
|
+
}
|
|
22416
|
+
get localLastStoryExpires() {
|
|
22417
|
+
var _a, _b;
|
|
22418
|
+
return ((_a = this.cacheStoryExpireTime) === null || _a === void 0 ? void 0 : _a.data)
|
|
22419
|
+
? new Date((_b = this.cacheStoryExpireTime) === null || _b === void 0 ? void 0 : _b.data).getTime()
|
|
22420
|
+
: 0;
|
|
22421
|
+
}
|
|
22422
|
+
get localLastStorySeenExpiresAt() {
|
|
22423
|
+
var _a, _b;
|
|
22424
|
+
return ((_a = this.cacheStoreSeenTime) === null || _a === void 0 ? void 0 : _a.data) ? new Date((_b = this.cacheStoreSeenTime) === null || _b === void 0 ? void 0 : _b.data).getTime() : 0;
|
|
22425
|
+
}
|
|
22426
|
+
get isContainUnSyncedStory() {
|
|
22427
|
+
const currentSyncingState = pullFromCache([
|
|
22428
|
+
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
22429
|
+
this._targetId,
|
|
22430
|
+
]);
|
|
22431
|
+
if (!(currentSyncingState === null || currentSyncingState === void 0 ? void 0 : currentSyncingState.data))
|
|
22432
|
+
return false;
|
|
22433
|
+
return ["syncing" /* Amity.SyncState.Syncing */, "error" /* Amity.SyncState.Error */].includes(currentSyncingState.data);
|
|
22434
|
+
}
|
|
22435
|
+
getLocalLastSortingDate() {
|
|
22436
|
+
if (this.isContainUnSyncedStory) {
|
|
22437
|
+
return this.localLastStoryExpires;
|
|
22438
|
+
}
|
|
22439
|
+
return this.lastStoryExpiresAt;
|
|
22440
|
+
}
|
|
22441
|
+
getHasUnseenFlag() {
|
|
22442
|
+
const now = new Date().getTime();
|
|
22443
|
+
const highestSeen = Math.max(this.lastStorySeenExpiresAt, this.localLastStorySeenExpiresAt);
|
|
22444
|
+
pullFromCache([
|
|
22445
|
+
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
22446
|
+
this._targetId,
|
|
22447
|
+
]);
|
|
22448
|
+
if (this.isContainUnSyncedStory) {
|
|
22449
|
+
return this.localLastStoryExpires > now && this.localLastStoryExpires > highestSeen;
|
|
22450
|
+
}
|
|
22451
|
+
return this.lastStoryExpiresAt > now && this.lastStoryExpiresAt > highestSeen;
|
|
22452
|
+
}
|
|
22453
|
+
getTotalStoryByStatus() {
|
|
22454
|
+
const stories = queryCache(["story" /* STORY_KEY_CACHE.STORY */, 'get']);
|
|
22455
|
+
if (!stories) {
|
|
22456
|
+
this._errorStoriesCount = 0;
|
|
22457
|
+
this._syncingStoriesCount = 0;
|
|
22458
|
+
return;
|
|
22459
|
+
}
|
|
22460
|
+
const groupByType = stories.reduce((acc, story) => {
|
|
22461
|
+
const { data: { targetId, syncState, isDeleted }, } = story;
|
|
22462
|
+
if (targetId === this._targetId && !isDeleted) {
|
|
22463
|
+
acc[syncState] += 1;
|
|
22464
|
+
}
|
|
22465
|
+
return acc;
|
|
22466
|
+
}, {
|
|
22467
|
+
syncing: 0,
|
|
22468
|
+
error: 0,
|
|
22469
|
+
synced: 0,
|
|
22470
|
+
});
|
|
22471
|
+
this._errorStoriesCount = groupByType.error;
|
|
22472
|
+
this._syncingStoriesCount = groupByType.syncing;
|
|
22473
|
+
}
|
|
22474
|
+
get syncingStoriesCount() {
|
|
22475
|
+
return this._syncingStoriesCount;
|
|
22476
|
+
}
|
|
22477
|
+
get failedStoriesCount() {
|
|
22478
|
+
return this._errorStoriesCount;
|
|
22479
|
+
}
|
|
22480
|
+
}
|
|
22481
|
+
|
|
22482
|
+
const storyTargetLinkedObject = (storyTarget) => {
|
|
22483
|
+
const { targetType, targetId, lastStoryExpiresAt, lastStorySeenExpiresAt, targetUpdatedAt, localFilter, } = storyTarget;
|
|
22484
|
+
const computedValue = new StoryComputedValue(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt);
|
|
22485
|
+
return {
|
|
22486
|
+
targetType,
|
|
22487
|
+
targetId,
|
|
22488
|
+
lastStoryExpiresAt,
|
|
22489
|
+
updatedAt: targetUpdatedAt,
|
|
22490
|
+
// Additional data
|
|
22491
|
+
hasUnseen: computedValue.getHasUnseenFlag(),
|
|
22492
|
+
syncingStoriesCount: computedValue.syncingStoriesCount,
|
|
22493
|
+
failedStoriesCount: computedValue.failedStoriesCount,
|
|
22494
|
+
localFilter,
|
|
22495
|
+
localLastExpires: computedValue.localLastStoryExpires,
|
|
22496
|
+
localLastSeen: computedValue.localLastStorySeenExpiresAt,
|
|
22497
|
+
localSortingDate: computedValue.getLocalLastSortingDate(),
|
|
22498
|
+
};
|
|
22499
|
+
};
|
|
22500
|
+
|
|
22501
|
+
const storyLinkedObject = (story) => {
|
|
22502
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
22503
|
+
const storyTargetCache = pullFromCache([
|
|
22504
|
+
"storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */,
|
|
22505
|
+
'get',
|
|
22506
|
+
story.targetId,
|
|
22507
|
+
]);
|
|
22508
|
+
const communityCacheData = pullFromCache(['community', 'get', story.targetId]);
|
|
22509
|
+
return Object.assign(Object.assign({}, story), { analytics: {
|
|
22510
|
+
markAsSeen: () => {
|
|
22511
|
+
if (!story.expiresAt)
|
|
22512
|
+
return;
|
|
22513
|
+
if (story.syncState !== "synced" /* Amity.SyncState.Synced */)
|
|
22514
|
+
return;
|
|
22515
|
+
analyticsEngineInstance.markStoryAsViewed(story);
|
|
22516
|
+
},
|
|
22517
|
+
markLinkAsClicked: () => {
|
|
22518
|
+
if (!story.expiresAt)
|
|
22519
|
+
return;
|
|
22520
|
+
if (story.syncState !== "synced" /* Amity.SyncState.Synced */)
|
|
22521
|
+
return;
|
|
22522
|
+
analyticsEngineInstance.markStoryAsClicked(story);
|
|
22523
|
+
},
|
|
22524
|
+
}, get videoData() {
|
|
22525
|
+
var _a, _b;
|
|
22526
|
+
const cache = pullFromCache([
|
|
22527
|
+
'file',
|
|
21426
22528
|
'get',
|
|
21427
22529
|
(_b = (_a = story.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original,
|
|
21428
22530
|
]);
|
|
@@ -21719,7 +22821,7 @@ const postLinkedObject = (post) => {
|
|
|
21719
22821
|
} });
|
|
21720
22822
|
};
|
|
21721
22823
|
|
|
21722
|
-
const getCachedMarker
|
|
22824
|
+
const getCachedMarker = (message) => {
|
|
21723
22825
|
var _a, _b;
|
|
21724
22826
|
const key = {
|
|
21725
22827
|
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
@@ -21737,7 +22839,7 @@ const getMessageReadCount = (message, marker) => {
|
|
|
21737
22839
|
// Look in the marker param first
|
|
21738
22840
|
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
21739
22841
|
// If the marker param is not set, look in the cache
|
|
21740
|
-
getCachedMarker
|
|
22842
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
21741
22843
|
}; // and if not found in cache use default value `0`
|
|
21742
22844
|
|
|
21743
22845
|
/**
|
|
@@ -21980,31 +23082,6 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
21980
23082
|
}
|
|
21981
23083
|
};
|
|
21982
23084
|
|
|
21983
|
-
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21984
|
-
var _a;
|
|
21985
|
-
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
21986
|
-
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21987
|
-
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
21988
|
-
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
21989
|
-
let channelUnreads = 0;
|
|
21990
|
-
let isMentioned = false;
|
|
21991
|
-
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
21992
|
-
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
21993
|
-
return data.channelId === channelId && !data.isDeleted;
|
|
21994
|
-
});
|
|
21995
|
-
channelUnreads = subChannelUnreadsInfo
|
|
21996
|
-
.map(({ data }) => data.unreadCount)
|
|
21997
|
-
.reduce((acc, cur) => acc + cur, 0);
|
|
21998
|
-
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
21999
|
-
}
|
|
22000
|
-
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
22001
|
-
channelId,
|
|
22002
|
-
createdAt: new Date().toISOString(),
|
|
22003
|
-
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
22004
|
-
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
22005
|
-
return channelUnreadInfo;
|
|
22006
|
-
};
|
|
22007
|
-
|
|
22008
23085
|
class LegacyMessageReadReceiptSyncEngine {
|
|
22009
23086
|
constructor() {
|
|
22010
23087
|
this.isActive = true;
|
|
@@ -22248,1198 +23325,801 @@ const messageLinkedObject = (message) => {
|
|
|
22248
23325
|
}, markRead: () => markReadMessage(message) });
|
|
22249
23326
|
};
|
|
22250
23327
|
|
|
22251
|
-
const reactorLinkedObject = (reactor) => {
|
|
22252
|
-
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
22253
|
-
var _a;
|
|
22254
|
-
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22255
|
-
if (!user)
|
|
22256
|
-
return undefined;
|
|
22257
|
-
return userLinkedObject(user);
|
|
22258
|
-
} });
|
|
22259
|
-
};
|
|
22260
|
-
|
|
22261
|
-
/**
|
|
22262
|
-
* ```js
|
|
22263
|
-
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
22264
|
-
* const success = await ChannelRepository.markAsRead('channelId')
|
|
22265
|
-
* ```
|
|
22266
|
-
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
22267
|
-
*
|
|
22268
|
-
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
22269
|
-
* @returns A success boolean if the {@link Amity.Channel} was mark read
|
|
22270
|
-
*
|
|
22271
|
-
* @category Channel API
|
|
22272
|
-
* @async
|
|
22273
|
-
*/
|
|
22274
|
-
const markAsRead = async (channelId) => {
|
|
22275
|
-
const client = getActiveClient();
|
|
22276
|
-
client.log('channel/markAsRead', channelId);
|
|
22277
|
-
const { data } = await client.http.put(`/api/v1/markers/channels/${channelId}/mark-read`);
|
|
22278
|
-
const { userMarkers, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
|
|
22279
|
-
const cachedAt = client.cache && Date.now();
|
|
22280
|
-
const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22281
|
-
const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22282
|
-
if (client.cache)
|
|
22283
|
-
ingestInCache(Object.assign({ userMarkers, userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
|
|
22284
|
-
fireEvent('local.channelMarker.updated', {
|
|
22285
|
-
userEntityMarkers: channelMarkers,
|
|
22286
|
-
});
|
|
22287
|
-
fireEvent('local.subChannelMarker.updated', {
|
|
22288
|
-
userFeedMarkers: subChannelMarkers,
|
|
22289
|
-
});
|
|
22290
|
-
return true;
|
|
22291
|
-
};
|
|
22292
|
-
|
|
22293
|
-
/**
|
|
22294
|
-
* ```js
|
|
22295
|
-
* import { shallowClone } from '~/utils/shallowClone'
|
|
22296
|
-
* const newObj = shallowClone(obj)
|
|
22297
|
-
* ```
|
|
22298
|
-
*
|
|
22299
|
-
* Clone an object with same prototype and properties
|
|
22300
|
-
*
|
|
22301
|
-
* @param obj the object to clone
|
|
22302
|
-
* @returns new object with same prototype and properties
|
|
22303
|
-
*
|
|
22304
|
-
* @category utility
|
|
22305
|
-
* @private
|
|
22306
|
-
*/
|
|
22307
|
-
function shallowClone(source, target) {
|
|
22308
|
-
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
22309
|
-
}
|
|
22310
|
-
|
|
22311
|
-
const channelLinkedObject = (channel) => {
|
|
22312
|
-
return shallowClone(channel, {
|
|
22313
|
-
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
22314
|
-
});
|
|
22315
|
-
};
|
|
22316
|
-
|
|
22317
|
-
const adLinkedObject = (ad) => {
|
|
22318
|
-
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
22319
|
-
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
22320
|
-
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
22321
|
-
markAsSeen: (placement) => {
|
|
22322
|
-
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
22323
|
-
},
|
|
22324
|
-
markLinkAsClicked: (placement) => {
|
|
22325
|
-
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
22326
|
-
},
|
|
22327
|
-
}, get advertiser() {
|
|
22328
|
-
var _a, _b;
|
|
22329
|
-
const advertiserData = (_a = pullFromCache([
|
|
22330
|
-
'advertiser',
|
|
22331
|
-
'get',
|
|
22332
|
-
ad.advertiserId,
|
|
22333
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22334
|
-
if (!advertiserData)
|
|
22335
|
-
return;
|
|
22336
|
-
const avatarFile = (_b = pullFromCache([
|
|
22337
|
-
'file',
|
|
22338
|
-
'get',
|
|
22339
|
-
advertiserData.avatarFileId,
|
|
22340
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22341
|
-
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
22342
|
-
},
|
|
22343
|
-
get image1_1() {
|
|
22344
|
-
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
22345
|
-
if (!cacheData)
|
|
22346
|
-
return undefined;
|
|
22347
|
-
return cacheData.data || undefined;
|
|
22348
|
-
},
|
|
22349
|
-
get image9_16() {
|
|
22350
|
-
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
22351
|
-
if (!cacheData)
|
|
22352
|
-
return undefined;
|
|
22353
|
-
return cacheData.data || undefined;
|
|
22354
|
-
} });
|
|
22355
|
-
};
|
|
22356
|
-
|
|
22357
|
-
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22358
|
-
var _a;
|
|
22359
|
-
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
22360
|
-
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
22361
|
-
var _a;
|
|
22362
|
-
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
22363
|
-
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
22364
|
-
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
22365
|
-
get post() {
|
|
22366
|
-
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
22367
|
-
return;
|
|
22368
|
-
return postLinkedObject(postCached.data);
|
|
22369
|
-
},
|
|
22370
|
-
get target() {
|
|
22371
|
-
const pinTarget = pullFromCache([
|
|
22372
|
-
'pinTarget',
|
|
22373
|
-
'get',
|
|
22374
|
-
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
22375
|
-
]);
|
|
22376
|
-
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
22377
|
-
return;
|
|
22378
|
-
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
22379
|
-
} });
|
|
22380
|
-
};
|
|
22381
|
-
|
|
22382
|
-
const notificationTrayLinkedObject = (noti) => {
|
|
22383
|
-
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
22384
|
-
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
22385
|
-
.filter(isNonNullable)
|
|
22386
|
-
.map(({ data }) => data)
|
|
22387
|
-
.map(user => userLinkedObject(user)) });
|
|
22388
|
-
};
|
|
22389
|
-
|
|
22390
|
-
const LinkedObject = {
|
|
22391
|
-
ad: adLinkedObject,
|
|
22392
|
-
comment: commentLinkedObject,
|
|
22393
|
-
post: postLinkedObject,
|
|
22394
|
-
user: userLinkedObject,
|
|
22395
|
-
category: categoryLinkedObject,
|
|
22396
|
-
stream: streamLinkedObject,
|
|
22397
|
-
story: storyLinkedObject,
|
|
22398
|
-
storyTarget: storyTargetLinkedObject,
|
|
22399
|
-
message: messageLinkedObject,
|
|
22400
|
-
reactor: reactorLinkedObject,
|
|
22401
|
-
channel: channelLinkedObject,
|
|
22402
|
-
pinnedPost: pinnedPostLinkedObject,
|
|
22403
|
-
notificationTray: notificationTrayLinkedObject,
|
|
22404
|
-
};
|
|
22405
|
-
|
|
22406
|
-
const getChannelMessagePreviewWithUser = (channel) => {
|
|
22407
|
-
var _a;
|
|
22408
|
-
const messagePreview = channel.messagePreviewId
|
|
22409
|
-
? getChannelMessagePreview(channel.channelId)
|
|
22410
|
-
: null;
|
|
22411
|
-
const internalUser = (_a = pullFromCache([
|
|
22412
|
-
'user',
|
|
22413
|
-
'get',
|
|
22414
|
-
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
22415
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22416
|
-
const messagePreviewWithUser = messagePreview
|
|
22417
|
-
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? LinkedObject.user(internalUser) : undefined }) : null;
|
|
22418
|
-
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
22419
|
-
};
|
|
22420
|
-
|
|
22421
|
-
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
22422
|
-
var _a, _b;
|
|
22423
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
22424
|
-
var _a;
|
|
22425
|
-
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
22426
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
22427
|
-
});
|
|
22428
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
22429
|
-
return {
|
|
22430
|
-
channelId,
|
|
22431
|
-
subChannelId,
|
|
22432
|
-
data,
|
|
22433
|
-
dataType,
|
|
22434
|
-
isDeleted,
|
|
22435
|
-
segment,
|
|
22436
|
-
creatorId,
|
|
22437
|
-
createdAt,
|
|
22438
|
-
updatedAt,
|
|
22439
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
22440
|
-
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
22441
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
22442
|
-
};
|
|
22443
|
-
};
|
|
22444
|
-
const newData = {
|
|
22445
|
-
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
22446
|
-
};
|
|
22447
|
-
ingestInCache(newData);
|
|
22448
|
-
};
|
|
22449
|
-
|
|
22450
|
-
const getSubChannelMessagePreview = (subChannelId) => {
|
|
22451
|
-
var _a, _b;
|
|
22452
|
-
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
22453
|
-
};
|
|
22454
|
-
|
|
22455
|
-
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
22456
|
-
var _a;
|
|
22457
|
-
const messagePreview = subChannel.messagePreviewId
|
|
22458
|
-
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
22459
|
-
: null;
|
|
22460
|
-
const messagePreviewWithUser = messagePreview
|
|
22461
|
-
? Object.assign(Object.assign({}, messagePreview), { user: (_a = pullFromCache(['user', 'get', messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId])) === null || _a === void 0 ? void 0 : _a.data }) : null;
|
|
22462
|
-
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
22463
|
-
};
|
|
22464
|
-
|
|
22465
|
-
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
22466
|
-
var _a, _b;
|
|
22467
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
22468
|
-
var _a;
|
|
22469
|
-
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
22470
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
22471
|
-
});
|
|
22472
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
22473
|
-
return {
|
|
22474
|
-
messagePreviewId,
|
|
22475
|
-
channelId,
|
|
22476
|
-
subChannelId,
|
|
22477
|
-
data,
|
|
22478
|
-
dataType,
|
|
22479
|
-
isDeleted,
|
|
22480
|
-
segment,
|
|
22481
|
-
creatorId,
|
|
22482
|
-
createdAt,
|
|
22483
|
-
updatedAt,
|
|
22484
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
22485
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
22486
|
-
};
|
|
22487
|
-
};
|
|
22488
|
-
const newData = {
|
|
22489
|
-
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
22490
|
-
};
|
|
22491
|
-
ingestInCache(newData);
|
|
22492
|
-
};
|
|
22493
|
-
|
|
22494
|
-
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
22495
|
-
pushToCache(['subChannel', 'get', subChannelId],
|
|
22496
|
-
// eslint-disable-next-line prefer-object-spread
|
|
22497
|
-
shallowClone(subChannel, params));
|
|
22498
|
-
}
|
|
22499
|
-
|
|
22500
|
-
/**
|
|
22501
|
-
* ```js
|
|
22502
|
-
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
22503
|
-
* const user = isInTombstone(["message", "messageId"])
|
|
22504
|
-
* ```
|
|
22505
|
-
*
|
|
22506
|
-
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
22507
|
-
* in cache and it's not expired means it's in tombstone
|
|
22508
|
-
* and we throw an Error
|
|
22509
|
-
*
|
|
22510
|
-
* @param model the model to check
|
|
22511
|
-
* @param modelId the object id to check
|
|
22512
|
-
* @returns the matching cache entry, or undefined.
|
|
22513
|
-
*
|
|
22514
|
-
* @category Cache API
|
|
22515
|
-
*/
|
|
22516
|
-
const isInTombstone = (model, modelId) => {
|
|
22517
|
-
const { log, cache } = getActiveClient();
|
|
22518
|
-
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
22519
|
-
if (!cache)
|
|
22520
|
-
return;
|
|
22521
|
-
log('cache/api/isInTombstone', key);
|
|
22522
|
-
const isInTombstone = pullFromCache(key);
|
|
22523
|
-
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
22524
|
-
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
22525
|
-
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22526
|
-
}
|
|
22527
|
-
};
|
|
22528
|
-
|
|
22529
|
-
/**
|
|
22530
|
-
* ```js
|
|
22531
|
-
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
22532
|
-
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
22533
|
-
* ```
|
|
22534
|
-
*
|
|
22535
|
-
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
22536
|
-
*
|
|
22537
|
-
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
22538
|
-
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
22539
|
-
*
|
|
22540
|
-
* @category Channel API
|
|
22541
|
-
* @async
|
|
22542
|
-
* @private
|
|
22543
|
-
*/
|
|
22544
|
-
const getMessageMarkers = async (messageIds) => {
|
|
22545
|
-
const client = getActiveClient();
|
|
22546
|
-
client.log('channel/getMessageMarkers', messageIds);
|
|
22547
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
22548
|
-
params: {
|
|
22549
|
-
messageIds,
|
|
22550
|
-
},
|
|
22551
|
-
});
|
|
22552
|
-
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
22553
|
-
const cachedAt = client.cache && Date.now();
|
|
22554
|
-
if (client.cache)
|
|
22555
|
-
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
22556
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
22557
|
-
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
22558
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22559
|
-
return { data: contentMarkers, cachedAt };
|
|
22560
|
-
};
|
|
22561
|
-
|
|
22562
|
-
const persistUnreadCountInfo = (payload) => {
|
|
22563
|
-
const { feedMarkers, userFeedMarkers } = payload;
|
|
22564
|
-
// calculate sub channel unread info and channel unread info
|
|
22565
|
-
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
22566
|
-
const channelIds = [];
|
|
22567
|
-
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
22568
|
-
userFeedMarkers.forEach(userFeedMarker => {
|
|
22569
|
-
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
22570
|
-
if (!feedMarker)
|
|
22571
|
-
return;
|
|
22572
|
-
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
22573
|
-
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
22574
|
-
const subChannelUnreadInfo = {
|
|
22575
|
-
subChannelId: feedMarker.feedId,
|
|
22576
|
-
channelId: feedMarker.entityId,
|
|
22577
|
-
readToSegment: userFeedMarker.readToSegment,
|
|
22578
|
-
lastSegment: feedMarker.lastSegment,
|
|
22579
|
-
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
22580
|
-
unreadCount: Math.max(0, unreadCount),
|
|
22581
|
-
isMentioned: userFeedMarker.isMentioned,
|
|
22582
|
-
isDeleted: feedMarker.isDeleted,
|
|
22583
|
-
createdAt: userFeedMarker.createdAt,
|
|
22584
|
-
updatedAt: userFeedMarker.updatedAt,
|
|
22585
|
-
};
|
|
22586
|
-
// update sub channel unread info in cache
|
|
22587
|
-
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
22588
|
-
if (!channelIds.includes(feedMarker.entityId)) {
|
|
22589
|
-
channelIds.push(feedMarker.entityId);
|
|
22590
|
-
}
|
|
22591
|
-
}
|
|
22592
|
-
});
|
|
22593
|
-
// re-calculate channel unread info in cache
|
|
22594
|
-
channelIds.forEach(channelId => {
|
|
22595
|
-
reCalculateChannelUnreadInfo(channelId);
|
|
22596
|
-
});
|
|
22597
|
-
}
|
|
23328
|
+
const reactorLinkedObject = (reactor) => {
|
|
23329
|
+
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
23330
|
+
var _a;
|
|
23331
|
+
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23332
|
+
if (!user)
|
|
23333
|
+
return undefined;
|
|
23334
|
+
return userLinkedObject(user);
|
|
23335
|
+
} });
|
|
22598
23336
|
};
|
|
22599
23337
|
|
|
22600
23338
|
/**
|
|
22601
23339
|
* ```js
|
|
22602
|
-
* import {
|
|
22603
|
-
* const
|
|
23340
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
23341
|
+
* const success = await ChannelRepository.markAsRead('channelId')
|
|
22604
23342
|
* ```
|
|
23343
|
+
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
22605
23344
|
*
|
|
22606
|
-
*
|
|
22607
|
-
*
|
|
22608
|
-
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
22609
|
-
* @param page
|
|
22610
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
23345
|
+
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
23346
|
+
* @returns A success boolean if the {@link Amity.Channel} was mark read
|
|
22611
23347
|
*
|
|
22612
23348
|
* @category Channel API
|
|
22613
23349
|
* @async
|
|
22614
|
-
* @private
|
|
22615
23350
|
*/
|
|
22616
|
-
const
|
|
22617
|
-
const client = getActiveClient();
|
|
22618
|
-
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
22619
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
22620
|
-
params: {
|
|
22621
|
-
messageFeedIds,
|
|
22622
|
-
options: {
|
|
22623
|
-
token: toToken(page, 'skiplimit'),
|
|
22624
|
-
},
|
|
22625
|
-
},
|
|
22626
|
-
});
|
|
22627
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22628
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
22629
|
-
// if consistent mode is enabled, persist the unread count info to the cache
|
|
22630
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22631
|
-
persistUnreadCountInfo({
|
|
22632
|
-
feedMarkers: feedMarkersPayload,
|
|
22633
|
-
userFeedMarkers: userFeedMarkersPayload,
|
|
22634
|
-
});
|
|
22635
|
-
}
|
|
22636
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22637
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22638
|
-
const cachedAt = client.cache && Date.now();
|
|
22639
|
-
if (client.cache)
|
|
22640
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
22641
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
22642
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
22643
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22644
|
-
const nextPage = toPage(paging.next);
|
|
22645
|
-
const prevPage = toPage(paging.previous);
|
|
22646
|
-
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
22647
|
-
};
|
|
22648
|
-
|
|
22649
|
-
const getUserMarker = async () => {
|
|
23351
|
+
const markAsRead = async (channelId) => {
|
|
22650
23352
|
const client = getActiveClient();
|
|
22651
|
-
client.log('channel/
|
|
22652
|
-
const { data
|
|
22653
|
-
const { userMarkers } =
|
|
23353
|
+
client.log('channel/markAsRead', channelId);
|
|
23354
|
+
const { data } = await client.http.put(`/api/v1/markers/channels/${channelId}/mark-read`);
|
|
23355
|
+
const { userMarkers, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
|
|
22654
23356
|
const cachedAt = client.cache && Date.now();
|
|
23357
|
+
const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23358
|
+
const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22655
23359
|
if (client.cache)
|
|
22656
|
-
ingestInCache({ userMarkers }, { cachedAt });
|
|
22657
|
-
fireEvent('local.
|
|
22658
|
-
|
|
22659
|
-
|
|
22660
|
-
|
|
22661
|
-
|
|
22662
|
-
|
|
22663
|
-
|
|
22664
|
-
}, undefined);
|
|
22665
|
-
return { data: latestUserMarker, cachedAt };
|
|
23360
|
+
ingestInCache(Object.assign({ userMarkers, userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
|
|
23361
|
+
fireEvent('local.channelMarker.updated', {
|
|
23362
|
+
userEntityMarkers: channelMarkers,
|
|
23363
|
+
});
|
|
23364
|
+
fireEvent('local.subChannelMarker.updated', {
|
|
23365
|
+
userFeedMarkers: subChannelMarkers,
|
|
23366
|
+
});
|
|
23367
|
+
return true;
|
|
22666
23368
|
};
|
|
22667
23369
|
|
|
22668
|
-
|
|
22669
|
-
|
|
22670
|
-
|
|
22671
|
-
|
|
22672
|
-
*/
|
|
22673
|
-
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
22674
|
-
const client = getActiveClient();
|
|
22675
|
-
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22676
|
-
// '[]' in cases where the new reaction is the first one
|
|
22677
|
-
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22678
|
-
// add myReactions to the payload
|
|
22679
|
-
Object.assign(payload, { myReactions });
|
|
22680
|
-
// check if there are any updates to the reactions
|
|
22681
|
-
const latestReaction = reactors[0];
|
|
22682
|
-
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22683
|
-
if (!isLatestReactionMine) {
|
|
22684
|
-
return;
|
|
22685
|
-
}
|
|
22686
|
-
// new reaction added
|
|
22687
|
-
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22688
|
-
Object.assign(payload, {
|
|
22689
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22690
|
-
});
|
|
22691
|
-
}
|
|
22692
|
-
// existing reaction removed
|
|
22693
|
-
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
22694
|
-
Object.assign(payload, {
|
|
22695
|
-
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22696
|
-
});
|
|
22697
|
-
}
|
|
23370
|
+
const channelLinkedObject = (channel) => {
|
|
23371
|
+
return shallowClone(channel, {
|
|
23372
|
+
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
23373
|
+
});
|
|
22698
23374
|
};
|
|
22699
23375
|
|
|
22700
|
-
|
|
22701
|
-
|
|
22702
|
-
|
|
22703
|
-
|
|
22704
|
-
|
|
22705
|
-
|
|
22706
|
-
|
|
22707
|
-
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22715
|
-
|
|
22716
|
-
|
|
22717
|
-
|
|
22718
|
-
|
|
22719
|
-
|
|
22720
|
-
|
|
22721
|
-
|
|
22722
|
-
|
|
22723
|
-
|
|
22724
|
-
|
|
22725
|
-
const cachedUnreadCount = (_a = pullFromCache([
|
|
22726
|
-
'subChannelUnreadInfo',
|
|
22727
|
-
'get',
|
|
22728
|
-
subChannelId,
|
|
22729
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22730
|
-
if (cachedUnreadCount) {
|
|
22731
|
-
return cachedUnreadCount.isMentioned;
|
|
22732
|
-
}
|
|
22733
|
-
return false;
|
|
22734
|
-
}
|
|
22735
|
-
const key = {
|
|
22736
|
-
entityId: channelId,
|
|
22737
|
-
feedId: subChannelId,
|
|
22738
|
-
userId: getActiveUser()._id,
|
|
22739
|
-
};
|
|
22740
|
-
// If the marker param is not set, look in the cache
|
|
22741
|
-
const cachedMarker = (_b = pullFromCache([
|
|
22742
|
-
'subChannelMarker',
|
|
22743
|
-
'get',
|
|
22744
|
-
getResolver('subChannelMarker')(key),
|
|
22745
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22746
|
-
if (cachedMarker) {
|
|
22747
|
-
return cachedMarker.hasMentioned;
|
|
22748
|
-
}
|
|
22749
|
-
// and if not found in cache use default value `false`
|
|
22750
|
-
return false;
|
|
22751
|
-
}
|
|
22752
|
-
|
|
22753
|
-
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
22754
|
-
var _a, _b;
|
|
22755
|
-
// Look for `unreadCount` in the marker param first
|
|
22756
|
-
if (marker) {
|
|
22757
|
-
return marker.unreadCount;
|
|
22758
|
-
}
|
|
22759
|
-
const client = getActiveClient();
|
|
22760
|
-
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22761
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22762
|
-
const cachedUnreadCount = (_a = pullFromCache([
|
|
22763
|
-
'subChannelUnreadInfo',
|
|
22764
|
-
'get',
|
|
22765
|
-
subChannelId,
|
|
22766
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22767
|
-
if (cachedUnreadCount) {
|
|
22768
|
-
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
22769
|
-
}
|
|
22770
|
-
return 0;
|
|
22771
|
-
}
|
|
22772
|
-
const key = {
|
|
22773
|
-
entityId: channelId,
|
|
22774
|
-
feedId: subChannelId,
|
|
22775
|
-
userId: getActiveUser()._id,
|
|
22776
|
-
};
|
|
22777
|
-
// If the marker param is not set, look in the cache
|
|
22778
|
-
const cachedMarker = (_b = pullFromCache([
|
|
22779
|
-
'subChannelMarker',
|
|
22780
|
-
'get',
|
|
22781
|
-
getResolver('subChannelMarker')(key),
|
|
22782
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22783
|
-
if (cachedMarker) {
|
|
22784
|
-
return cachedMarker.unreadCount;
|
|
22785
|
-
}
|
|
22786
|
-
// and if not found in cache use default value `0`
|
|
22787
|
-
return 0;
|
|
22788
|
-
}
|
|
22789
|
-
|
|
22790
|
-
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
22791
|
-
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
22792
|
-
function convertFromRaw$2(_a) {
|
|
22793
|
-
var { channelId, channelPublicId, channelType, childCount, creatorId, creatorPublicId, lastMessageId, lastMessageTimestamp, messageFeedId, name } = _a, rest = __rest(_a, ["channelId", "channelPublicId", "channelType", "childCount", "creatorId", "creatorPublicId", "lastMessageId", "lastMessageTimestamp", "messageFeedId", "name"]);
|
|
22794
|
-
return Object.assign(Object.assign({ get unreadCount() {
|
|
22795
|
-
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
23376
|
+
const adLinkedObject = (ad) => {
|
|
23377
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
23378
|
+
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
23379
|
+
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
23380
|
+
markAsSeen: (placement) => {
|
|
23381
|
+
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
23382
|
+
},
|
|
23383
|
+
markLinkAsClicked: (placement) => {
|
|
23384
|
+
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
23385
|
+
},
|
|
23386
|
+
}, get advertiser() {
|
|
23387
|
+
var _a, _b;
|
|
23388
|
+
const advertiserData = (_a = pullFromCache([
|
|
23389
|
+
'advertiser',
|
|
23390
|
+
'get',
|
|
23391
|
+
ad.advertiserId,
|
|
23392
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23393
|
+
if (!advertiserData)
|
|
23394
|
+
return;
|
|
23395
|
+
const avatarFile = (_b = pullFromCache([
|
|
23396
|
+
'file',
|
|
23397
|
+
'get',
|
|
23398
|
+
advertiserData.avatarFileId,
|
|
23399
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
23400
|
+
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
22796
23401
|
},
|
|
22797
|
-
get
|
|
22798
|
-
|
|
23402
|
+
get image1_1() {
|
|
23403
|
+
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
23404
|
+
if (!cacheData)
|
|
23405
|
+
return undefined;
|
|
23406
|
+
return cacheData.data || undefined;
|
|
22799
23407
|
},
|
|
22800
|
-
get
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
23408
|
+
get image9_16() {
|
|
23409
|
+
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
23410
|
+
if (!cacheData)
|
|
23411
|
+
return undefined;
|
|
23412
|
+
return cacheData.data || undefined;
|
|
23413
|
+
} });
|
|
23414
|
+
};
|
|
22804
23415
|
|
|
22805
|
-
const
|
|
22806
|
-
var _a, _b, _c;
|
|
22807
|
-
const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
22808
|
-
if (localMessage) {
|
|
22809
|
-
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
22810
|
-
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
22811
|
-
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
22812
|
-
}
|
|
22813
|
-
return payload;
|
|
22814
|
-
};
|
|
22815
|
-
function convertFromRaw$1(message, reactors, event) {
|
|
23416
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22816
23417
|
var _a;
|
|
22817
|
-
const
|
|
22818
|
-
const
|
|
22819
|
-
|
|
22820
|
-
|
|
22821
|
-
|
|
22822
|
-
}
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
22827
|
-
|
|
22828
|
-
|
|
22829
|
-
|
|
22830
|
-
|
|
22831
|
-
|
|
22832
|
-
|
|
22833
|
-
|
|
22834
|
-
|
|
22835
|
-
|
|
22836
|
-
|
|
22837
|
-
if (mention.type === 'channel') {
|
|
22838
|
-
return mention;
|
|
22839
|
-
}
|
|
22840
|
-
return { type: 'user', userIds: mention.userPublicIds };
|
|
22841
|
-
});
|
|
22842
|
-
}
|
|
22843
|
-
if (reactors && reactors.length && event) {
|
|
22844
|
-
// mqtt event
|
|
22845
|
-
prepareMessagePayloadForCache(out, reactors, event);
|
|
22846
|
-
}
|
|
22847
|
-
return out;
|
|
22848
|
-
}
|
|
22849
|
-
const preUpdateMessageCache = (rawPayload) => {
|
|
22850
|
-
ingestInCache({
|
|
22851
|
-
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
22852
|
-
});
|
|
22853
|
-
};
|
|
22854
|
-
const DEBOUNCE_TIME = 2000;
|
|
22855
|
-
const currentDebounceMap = {};
|
|
22856
|
-
const prepareMessagePayload = async (payload, event) => {
|
|
22857
|
-
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
22858
|
-
if (markerIds.length > 0) {
|
|
22859
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
22860
|
-
preUpdateMessageCache(payload);
|
|
22861
|
-
const markerIdsKey = markerIds.join('');
|
|
22862
|
-
if (currentDebounceMap[markerIdsKey]) {
|
|
22863
|
-
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
22864
|
-
}
|
|
22865
|
-
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
22866
|
-
try {
|
|
22867
|
-
getMessageMarkers(markerIds);
|
|
22868
|
-
}
|
|
22869
|
-
catch (_error) {
|
|
22870
|
-
// do nothing
|
|
22871
|
-
}
|
|
22872
|
-
}, DEBOUNCE_TIME);
|
|
22873
|
-
}
|
|
22874
|
-
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
22875
|
-
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
22876
|
-
if (messageFeeds && messageFeeds.length > 0) {
|
|
22877
|
-
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
22878
|
-
var _a, _b;
|
|
22879
|
-
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
22880
|
-
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
22881
|
-
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
22882
|
-
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
22883
|
-
});
|
|
22884
|
-
}
|
|
22885
|
-
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
22886
|
-
};
|
|
22887
|
-
function convertParams(_a) {
|
|
22888
|
-
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
22889
|
-
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
22890
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
22891
|
-
}
|
|
22892
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
22893
|
-
}
|
|
22894
|
-
function convertQueryParams$1(_a) {
|
|
22895
|
-
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
22896
|
-
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
22897
|
-
sortBy,
|
|
22898
|
-
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
22899
|
-
around: aroundMessageId,
|
|
23418
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
23419
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
23420
|
+
var _a;
|
|
23421
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
23422
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
23423
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
23424
|
+
get post() {
|
|
23425
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
23426
|
+
return;
|
|
23427
|
+
return postLinkedObject(postCached.data);
|
|
23428
|
+
},
|
|
23429
|
+
get target() {
|
|
23430
|
+
const pinTarget = pullFromCache([
|
|
23431
|
+
'pinTarget',
|
|
23432
|
+
'get',
|
|
23433
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
23434
|
+
]);
|
|
23435
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
23436
|
+
return;
|
|
23437
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
22900
23438
|
} });
|
|
22901
|
-
|
|
22902
|
-
out.includeTags = includingTags;
|
|
22903
|
-
}
|
|
22904
|
-
if (type) {
|
|
22905
|
-
out.dataType = type;
|
|
22906
|
-
}
|
|
22907
|
-
if (excludingTags) {
|
|
22908
|
-
out.excludeTags = excludingTags;
|
|
22909
|
-
}
|
|
22910
|
-
return out;
|
|
22911
|
-
}
|
|
23439
|
+
};
|
|
22912
23440
|
|
|
22913
|
-
const
|
|
23441
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
23442
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
23443
|
+
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
23444
|
+
.filter(isNonNullable)
|
|
23445
|
+
.map(({ data }) => data)
|
|
23446
|
+
.map(user => userLinkedObject(user)) });
|
|
23447
|
+
};
|
|
23448
|
+
|
|
23449
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
23450
|
+
return {
|
|
23451
|
+
invitations: rawPayload.invitations.map(invitation => (Object.assign(Object.assign({}, invitation), { invitationId: invitation._id, createdById: invitation.createdBy }))),
|
|
23452
|
+
};
|
|
23453
|
+
};
|
|
23454
|
+
|
|
23455
|
+
/* begin_public_function
|
|
23456
|
+
id: invitation.createInvitations
|
|
23457
|
+
*/
|
|
22914
23458
|
/**
|
|
22915
|
-
*
|
|
23459
|
+
* ```js
|
|
23460
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
23461
|
+
* const created = await createInvitations({
|
|
23462
|
+
* type: string,
|
|
23463
|
+
* targetType: string,
|
|
23464
|
+
* targetId: string,
|
|
23465
|
+
* userIds: string[]
|
|
23466
|
+
* }))
|
|
23467
|
+
* ```
|
|
23468
|
+
*
|
|
23469
|
+
* Creates an {@link Amity.Invitation}
|
|
23470
|
+
*
|
|
23471
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
23472
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
23473
|
+
*
|
|
23474
|
+
* @category Invitation API
|
|
23475
|
+
* @async
|
|
22916
23476
|
*/
|
|
22917
|
-
const
|
|
22918
|
-
const
|
|
22919
|
-
|
|
22920
|
-
|
|
22921
|
-
|
|
22922
|
-
|
|
22923
|
-
|
|
22924
|
-
|
|
22925
|
-
|
|
22926
|
-
|
|
22927
|
-
|
|
22928
|
-
|
|
22929
|
-
|
|
22930
|
-
try {
|
|
22931
|
-
await getSubChannelMarkers(markerIds);
|
|
22932
|
-
}
|
|
22933
|
-
catch (e) {
|
|
22934
|
-
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
22935
|
-
}
|
|
22936
|
-
}
|
|
22937
|
-
updateSubChannelMessagePreviewCache(rawPayload);
|
|
22938
|
-
// attach marker to sub channel
|
|
22939
|
-
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
22940
|
-
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
22941
|
-
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
22942
|
-
messages });
|
|
23477
|
+
const createInvitations = async (bundle) => {
|
|
23478
|
+
const client = getActiveClient();
|
|
23479
|
+
client.log('invitation/createInvitations', bundle);
|
|
23480
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
23481
|
+
const data = prepareInvitationPayload(payload);
|
|
23482
|
+
const cachedAt = client.cache && Date.now();
|
|
23483
|
+
if (client.cache)
|
|
23484
|
+
ingestInCache(data, { cachedAt });
|
|
23485
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
23486
|
+
return {
|
|
23487
|
+
data: data.invitations,
|
|
23488
|
+
cachedAt,
|
|
23489
|
+
};
|
|
22943
23490
|
};
|
|
22944
|
-
|
|
22945
|
-
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
22946
|
-
const out = Object.assign({}, rest);
|
|
22947
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
22948
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
22949
|
-
}
|
|
22950
|
-
return out;
|
|
22951
|
-
}
|
|
23491
|
+
/* end_public_function */
|
|
22952
23492
|
|
|
23493
|
+
/* begin_public_function
|
|
23494
|
+
id: invitation.accept
|
|
23495
|
+
*/
|
|
22953
23496
|
/**
|
|
22954
23497
|
* ```js
|
|
22955
|
-
* import {
|
|
22956
|
-
* const
|
|
23498
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
23499
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
22957
23500
|
* ```
|
|
22958
23501
|
*
|
|
22959
|
-
*
|
|
23502
|
+
* Accepts a {@link Amity.Invitation} object
|
|
22960
23503
|
*
|
|
22961
|
-
* @param
|
|
22962
|
-
* @returns the
|
|
23504
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
23505
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
22963
23506
|
*
|
|
22964
|
-
* @category
|
|
23507
|
+
* @category Invitation API
|
|
22965
23508
|
* @async
|
|
22966
23509
|
*/
|
|
22967
|
-
const
|
|
23510
|
+
const acceptInvitation = async (invitationId) => {
|
|
23511
|
+
var _a;
|
|
22968
23512
|
const client = getActiveClient();
|
|
22969
|
-
client.log('
|
|
22970
|
-
|
|
22971
|
-
|
|
22972
|
-
|
|
22973
|
-
|
|
22974
|
-
|
|
22975
|
-
|
|
22976
|
-
|
|
22977
|
-
|
|
22978
|
-
|
|
22979
|
-
data: data.messageFeeds[0],
|
|
22980
|
-
cachedAt,
|
|
22981
|
-
};
|
|
22982
|
-
}
|
|
22983
|
-
catch (error) {
|
|
22984
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22985
|
-
pushToTombstone('subChannel', subChannelId);
|
|
22986
|
-
}
|
|
22987
|
-
throw error;
|
|
23513
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
23514
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
23515
|
+
const invitation = (_a = pullFromCache([
|
|
23516
|
+
'invitation',
|
|
23517
|
+
'get',
|
|
23518
|
+
invitationId,
|
|
23519
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23520
|
+
if (invitation) {
|
|
23521
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
23522
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
22988
23523
|
}
|
|
23524
|
+
return data.success;
|
|
22989
23525
|
};
|
|
23526
|
+
/* end_public_function */
|
|
23527
|
+
|
|
23528
|
+
/* begin_public_function
|
|
23529
|
+
id: invitation.reject
|
|
23530
|
+
*/
|
|
22990
23531
|
/**
|
|
22991
23532
|
* ```js
|
|
22992
|
-
* import {
|
|
22993
|
-
* const
|
|
23533
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
23534
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
22994
23535
|
* ```
|
|
22995
23536
|
*
|
|
22996
|
-
*
|
|
23537
|
+
* Rejects a {@link Amity.Invitation} object
|
|
22997
23538
|
*
|
|
22998
|
-
* @param
|
|
22999
|
-
* @returns the
|
|
23539
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
23540
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
23000
23541
|
*
|
|
23001
|
-
* @category
|
|
23542
|
+
* @category Invitation API
|
|
23543
|
+
* @async
|
|
23002
23544
|
*/
|
|
23003
|
-
|
|
23004
|
-
const client = getActiveClient();
|
|
23005
|
-
client.log('channel/getSubChannel.locally', subChannelId);
|
|
23006
|
-
if (!client.cache)
|
|
23007
|
-
return;
|
|
23008
|
-
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
23009
|
-
if (!cached)
|
|
23010
|
-
return;
|
|
23011
|
-
return {
|
|
23012
|
-
data: cached.data,
|
|
23013
|
-
cachedAt: cached.cachedAt,
|
|
23014
|
-
};
|
|
23015
|
-
};
|
|
23016
|
-
|
|
23017
|
-
const convertDateStringToTimestamp = (dateString) => {
|
|
23018
|
-
return new Date(dateString).getTime();
|
|
23019
|
-
};
|
|
23020
|
-
|
|
23021
|
-
const getMessagePreviewSetting$1 = async () => {
|
|
23022
|
-
const client = getActiveClient();
|
|
23023
|
-
return client.getMessagePreviewSetting(false);
|
|
23024
|
-
};
|
|
23025
|
-
const getSubChannelCache = async (subChannelId) => {
|
|
23026
|
-
var _a;
|
|
23027
|
-
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23028
|
-
if (!subChannelCache) {
|
|
23029
|
-
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
23030
|
-
}
|
|
23031
|
-
return subChannelCache;
|
|
23032
|
-
};
|
|
23033
|
-
const isLastestMessageOnSubchannel = (message) => {
|
|
23034
|
-
var _a;
|
|
23035
|
-
const cache = (_a = pullFromCache([
|
|
23036
|
-
'messagePreviewSubChannel',
|
|
23037
|
-
'get',
|
|
23038
|
-
message.subChannelId,
|
|
23039
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23040
|
-
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
23041
|
-
return (!cache ||
|
|
23042
|
-
cache.segment <= message.channelSegment ||
|
|
23043
|
-
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
23044
|
-
};
|
|
23045
|
-
const isLastestMessageOnChannel = (message) => {
|
|
23545
|
+
const rejectInvitation = async (invitationId) => {
|
|
23046
23546
|
var _a;
|
|
23047
|
-
const
|
|
23048
|
-
|
|
23547
|
+
const client = getActiveClient();
|
|
23548
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
23549
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
23550
|
+
const invitation = (_a = pullFromCache([
|
|
23551
|
+
'invitation',
|
|
23049
23552
|
'get',
|
|
23050
|
-
|
|
23553
|
+
invitationId,
|
|
23051
23554
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23052
|
-
|
|
23053
|
-
|
|
23054
|
-
|
|
23055
|
-
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
23056
|
-
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
23057
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
23058
|
-
// 1. get subChannel from cache, if not exist fetch from server
|
|
23059
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23060
|
-
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
23061
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
23062
|
-
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
23063
|
-
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
23064
|
-
convertDateStringToTimestamp(createdAt))
|
|
23065
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
23066
|
-
lastActivity: createdAt,
|
|
23067
|
-
});
|
|
23068
|
-
return;
|
|
23555
|
+
if (invitation) {
|
|
23556
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
23557
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
23069
23558
|
}
|
|
23070
|
-
|
|
23071
|
-
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
23072
|
-
if (!isLastestMessageOnSubchannel(message))
|
|
23073
|
-
return;
|
|
23074
|
-
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
23075
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
23076
|
-
channelId,
|
|
23077
|
-
creatorId,
|
|
23078
|
-
messagePreviewId,
|
|
23079
|
-
createdAt,
|
|
23080
|
-
updatedAt,
|
|
23081
|
-
subChannelId,
|
|
23082
|
-
data,
|
|
23083
|
-
dataType,
|
|
23084
|
-
segment,
|
|
23085
|
-
isDeleted,
|
|
23086
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
23087
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
23088
|
-
});
|
|
23089
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
23090
|
-
lastActivity: createdAt,
|
|
23091
|
-
messagePreviewId,
|
|
23092
|
-
});
|
|
23559
|
+
return data.success;
|
|
23093
23560
|
};
|
|
23094
|
-
|
|
23561
|
+
/* end_public_function */
|
|
23562
|
+
|
|
23563
|
+
/* begin_public_function
|
|
23564
|
+
id: invitation.cancel
|
|
23565
|
+
*/
|
|
23566
|
+
/**
|
|
23567
|
+
* ```js
|
|
23568
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
23569
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
23570
|
+
* ```
|
|
23571
|
+
*
|
|
23572
|
+
* Cancels a {@link Amity.Invitation} object
|
|
23573
|
+
*
|
|
23574
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
23575
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
23576
|
+
*
|
|
23577
|
+
* @category Invitation API
|
|
23578
|
+
* @async
|
|
23579
|
+
*/
|
|
23580
|
+
const cancelInvitation = async (invitationId) => {
|
|
23095
23581
|
var _a;
|
|
23096
|
-
const
|
|
23097
|
-
|
|
23098
|
-
|
|
23582
|
+
const client = getActiveClient();
|
|
23583
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
23584
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
23585
|
+
const invitation = (_a = pullFromCache([
|
|
23586
|
+
'invitation',
|
|
23099
23587
|
'get',
|
|
23100
|
-
|
|
23588
|
+
invitationId,
|
|
23101
23589
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23102
|
-
|
|
23103
|
-
|
|
23104
|
-
|
|
23105
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23106
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
23107
|
-
channelId,
|
|
23108
|
-
creatorId,
|
|
23109
|
-
messagePreviewId,
|
|
23110
|
-
createdAt,
|
|
23111
|
-
updatedAt,
|
|
23112
|
-
subChannelId,
|
|
23113
|
-
data,
|
|
23114
|
-
dataType,
|
|
23115
|
-
segment,
|
|
23116
|
-
isDeleted,
|
|
23117
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
23118
|
-
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
23119
|
-
});
|
|
23590
|
+
if (invitation) {
|
|
23591
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
23592
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
23120
23593
|
}
|
|
23594
|
+
return data.success;
|
|
23121
23595
|
};
|
|
23122
|
-
|
|
23123
|
-
|
|
23124
|
-
|
|
23125
|
-
|
|
23126
|
-
|
|
23127
|
-
|
|
23128
|
-
|
|
23129
|
-
|
|
23130
|
-
|
|
23131
|
-
|
|
23132
|
-
|
|
23133
|
-
|
|
23134
|
-
|
|
23135
|
-
|
|
23136
|
-
|
|
23137
|
-
|
|
23138
|
-
|
|
23139
|
-
|
|
23596
|
+
/* end_public_function */
|
|
23597
|
+
|
|
23598
|
+
var InvitationActionsEnum;
|
|
23599
|
+
(function (InvitationActionsEnum) {
|
|
23600
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
23601
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
23602
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
23603
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
23604
|
+
|
|
23605
|
+
const invitationLinkedObject = (invitation) => {
|
|
23606
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
23607
|
+
const cacheData = pullFromCache(['user', 'get', invitation.userId]);
|
|
23608
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23609
|
+
return userLinkedObject(cacheData.data);
|
|
23610
|
+
return undefined;
|
|
23611
|
+
},
|
|
23612
|
+
get createdBy() {
|
|
23613
|
+
const cacheData = pullFromCache(['user', 'get', invitation.createdById]);
|
|
23614
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23615
|
+
return userLinkedObject(cacheData.data);
|
|
23616
|
+
return undefined;
|
|
23617
|
+
},
|
|
23618
|
+
get target() {
|
|
23619
|
+
if (invitation.targetType === 'community') {
|
|
23620
|
+
const cacheData = pullFromCache([
|
|
23621
|
+
'community',
|
|
23622
|
+
'get',
|
|
23623
|
+
invitation.targetId,
|
|
23624
|
+
]);
|
|
23625
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23626
|
+
return cacheData.data;
|
|
23627
|
+
return undefined;
|
|
23628
|
+
}
|
|
23629
|
+
return undefined;
|
|
23630
|
+
}, accept: async () => {
|
|
23631
|
+
await acceptInvitation(invitation._id);
|
|
23632
|
+
}, reject: async () => {
|
|
23633
|
+
await rejectInvitation(invitation._id);
|
|
23634
|
+
}, cancel: async () => {
|
|
23635
|
+
await cancelInvitation(invitation._id);
|
|
23636
|
+
} });
|
|
23637
|
+
};
|
|
23638
|
+
|
|
23639
|
+
class PaginationController {
|
|
23640
|
+
constructor(queryParams) {
|
|
23641
|
+
const { http } = getActiveClient();
|
|
23642
|
+
this.queryParams = queryParams;
|
|
23643
|
+
this.http = http;
|
|
23140
23644
|
}
|
|
23141
|
-
|
|
23142
|
-
|
|
23143
|
-
/**
|
|
23144
|
-
* Channel Case
|
|
23145
|
-
*/
|
|
23146
|
-
var _a;
|
|
23147
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
23148
|
-
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
23149
|
-
'messagePreviewChannel',
|
|
23150
|
-
'get',
|
|
23151
|
-
message.channelId,
|
|
23152
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23153
|
-
if (messagePreviewChannelCache &&
|
|
23154
|
-
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
23155
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23156
|
-
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
23157
|
-
channelId,
|
|
23158
|
-
creatorId,
|
|
23159
|
-
messagePreviewId,
|
|
23160
|
-
createdAt,
|
|
23161
|
-
updatedAt,
|
|
23162
|
-
subChannelId,
|
|
23163
|
-
data,
|
|
23164
|
-
dataType,
|
|
23165
|
-
segment,
|
|
23166
|
-
isDeleted,
|
|
23167
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
23168
|
-
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
23169
|
-
});
|
|
23645
|
+
loadFirstPage() {
|
|
23646
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
23170
23647
|
}
|
|
23171
|
-
|
|
23172
|
-
|
|
23173
|
-
var _a, _b, _c, _d;
|
|
23174
|
-
const { channelId, subChannelId } = subChannel;
|
|
23175
|
-
/** Channel Case */
|
|
23176
|
-
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
23177
|
-
'messagePreviewChannel',
|
|
23178
|
-
'get',
|
|
23179
|
-
channelId,
|
|
23180
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23181
|
-
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
23182
|
-
const subChannelCache = (_b = pullFromCache([
|
|
23183
|
-
'subChannel',
|
|
23184
|
-
'get',
|
|
23185
|
-
subChannelId,
|
|
23186
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
23187
|
-
pushToCache(['messagePreviewChannel', 'get', channelId], Object.assign(Object.assign({}, messagePreviewChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
23648
|
+
loadNextPage() {
|
|
23649
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
23188
23650
|
}
|
|
23189
|
-
|
|
23190
|
-
|
|
23191
|
-
'messagePreviewSubChannel',
|
|
23192
|
-
'get',
|
|
23193
|
-
subChannelId,
|
|
23194
|
-
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
23195
|
-
if (messagePreviewSubChannelCache &&
|
|
23196
|
-
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
23197
|
-
new Date(subChannel.updatedAt).valueOf()) {
|
|
23198
|
-
const subChannelCache = (_d = pullFromCache([
|
|
23199
|
-
'subChannel',
|
|
23200
|
-
'get',
|
|
23201
|
-
subChannelId,
|
|
23202
|
-
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
23203
|
-
pushToCache(['messagePreviewSubChannel', 'get', subChannelId], Object.assign(Object.assign({}, messagePreviewSubChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
23651
|
+
loadPreviousPage() {
|
|
23652
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
23204
23653
|
}
|
|
23205
|
-
|
|
23654
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
23655
|
+
var _a, _b, _c, _d;
|
|
23656
|
+
if (direction === 'prev' && !this.previousToken)
|
|
23657
|
+
return;
|
|
23658
|
+
if (direction === 'next' && !this.nextToken)
|
|
23659
|
+
return;
|
|
23660
|
+
let token;
|
|
23661
|
+
if (direction === 'prev')
|
|
23662
|
+
token = this.previousToken;
|
|
23663
|
+
if (direction === 'next')
|
|
23664
|
+
token = this.nextToken;
|
|
23665
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
23666
|
+
if (direction === 'first') {
|
|
23667
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
23668
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
23669
|
+
}
|
|
23670
|
+
if (direction === 'prev')
|
|
23671
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
23672
|
+
if (direction === 'next')
|
|
23673
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
23674
|
+
return queryResponse;
|
|
23675
|
+
}
|
|
23676
|
+
getNextToken() {
|
|
23677
|
+
return this.nextToken;
|
|
23678
|
+
}
|
|
23679
|
+
getPrevToken() {
|
|
23680
|
+
return this.previousToken;
|
|
23681
|
+
}
|
|
23682
|
+
}
|
|
23206
23683
|
|
|
23207
|
-
|
|
23208
|
-
|
|
23684
|
+
class InvitationsPaginationController extends PaginationController {
|
|
23685
|
+
async getRequest(queryParams, token) {
|
|
23686
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23687
|
+
const options = token ? { token } : { limit };
|
|
23688
|
+
const { data } = await this.http.get(`/api/v1/invitations`, { params: Object.assign(Object.assign({}, params), { options }) });
|
|
23689
|
+
return data;
|
|
23690
|
+
}
|
|
23209
23691
|
}
|
|
23210
23692
|
|
|
23211
|
-
|
|
23212
|
-
|
|
23213
|
-
|
|
23214
|
-
|
|
23215
|
-
let { messagePreviewId } = channel;
|
|
23216
|
-
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
23217
|
-
'messagePreviewChannel',
|
|
23218
|
-
'get',
|
|
23219
|
-
channel.channelId,
|
|
23220
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23221
|
-
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
23222
|
-
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
23693
|
+
class QueryStreamController {
|
|
23694
|
+
constructor(query, cacheKey) {
|
|
23695
|
+
this.query = query;
|
|
23696
|
+
this.cacheKey = cacheKey;
|
|
23223
23697
|
}
|
|
23224
|
-
|
|
23698
|
+
}
|
|
23699
|
+
|
|
23700
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
23701
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23702
|
+
super(query, cacheKey);
|
|
23703
|
+
this.notifyChange = notifyChange;
|
|
23704
|
+
this.preparePayload = preparePayload;
|
|
23705
|
+
}
|
|
23706
|
+
async saveToMainDB(response) {
|
|
23707
|
+
const processedPayload = await this.preparePayload(response);
|
|
23708
|
+
const client = getActiveClient();
|
|
23709
|
+
const cachedAt = client.cache && Date.now();
|
|
23710
|
+
if (client.cache) {
|
|
23711
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23712
|
+
}
|
|
23713
|
+
}
|
|
23714
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23715
|
+
var _a, _b;
|
|
23716
|
+
if (refresh) {
|
|
23717
|
+
pushToCache(this.cacheKey, {
|
|
23718
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
23719
|
+
});
|
|
23720
|
+
}
|
|
23721
|
+
else {
|
|
23722
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23723
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23724
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23725
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
23726
|
+
] }));
|
|
23727
|
+
}
|
|
23728
|
+
}
|
|
23729
|
+
reactor(action) {
|
|
23730
|
+
return (invitations) => {
|
|
23731
|
+
var _a;
|
|
23732
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23733
|
+
if (!collection)
|
|
23734
|
+
return;
|
|
23735
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
23736
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
23737
|
+
if (!isExist)
|
|
23738
|
+
return;
|
|
23739
|
+
}
|
|
23740
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
23741
|
+
collection.data = [
|
|
23742
|
+
...new Set([
|
|
23743
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
23744
|
+
...collection.data,
|
|
23745
|
+
]),
|
|
23746
|
+
];
|
|
23747
|
+
}
|
|
23748
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
23749
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
23750
|
+
}
|
|
23751
|
+
pushToCache(this.cacheKey, collection);
|
|
23752
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23753
|
+
};
|
|
23754
|
+
}
|
|
23755
|
+
subscribeRTE(createSubscriber) {
|
|
23756
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23757
|
+
}
|
|
23758
|
+
}
|
|
23759
|
+
|
|
23760
|
+
function isObject(value) {
|
|
23761
|
+
return typeof value === 'object' && value !== null;
|
|
23225
23762
|
}
|
|
23226
|
-
|
|
23227
|
-
|
|
23228
|
-
|
|
23763
|
+
/**
|
|
23764
|
+
* convert all object getter property to static value
|
|
23765
|
+
*/
|
|
23766
|
+
const convertGetterPropsToStatic = (obj) => {
|
|
23767
|
+
if (!isObject(obj)) {
|
|
23768
|
+
return obj;
|
|
23769
|
+
}
|
|
23770
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23771
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
23772
|
+
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
23773
|
+
return [key, descriptor.get.call(obj)];
|
|
23774
|
+
}
|
|
23775
|
+
return [key, value];
|
|
23229
23776
|
});
|
|
23777
|
+
return Object.fromEntries(entries);
|
|
23230
23778
|
};
|
|
23231
|
-
const
|
|
23232
|
-
|
|
23233
|
-
|
|
23234
|
-
|
|
23235
|
-
|
|
23236
|
-
|
|
23237
|
-
|
|
23238
|
-
let isMentioned = false;
|
|
23239
|
-
if (channelUser) {
|
|
23240
|
-
readToSegment = channelUser.readToSegment;
|
|
23241
|
-
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
23242
|
-
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
23243
|
-
isMentioned = lastMentionedSegment > readToSegment;
|
|
23779
|
+
const removeFunctionProperties = (obj) => {
|
|
23780
|
+
if (!isObject(obj)) {
|
|
23781
|
+
return obj;
|
|
23782
|
+
}
|
|
23783
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23784
|
+
if (typeof value === 'function') {
|
|
23785
|
+
return [key, undefined];
|
|
23244
23786
|
}
|
|
23245
|
-
|
|
23246
|
-
|
|
23247
|
-
|
|
23248
|
-
|
|
23249
|
-
|
|
23250
|
-
|
|
23251
|
-
|
|
23252
|
-
|
|
23253
|
-
|
|
23254
|
-
|
|
23787
|
+
return [key, value];
|
|
23788
|
+
});
|
|
23789
|
+
return Object.fromEntries(entries);
|
|
23790
|
+
};
|
|
23791
|
+
|
|
23792
|
+
class PaginationNoPageController {
|
|
23793
|
+
constructor(queryParams) {
|
|
23794
|
+
const { http } = getActiveClient();
|
|
23795
|
+
this.queryParams = queryParams;
|
|
23796
|
+
this.http = http;
|
|
23255
23797
|
}
|
|
23256
|
-
|
|
23257
|
-
const
|
|
23258
|
-
|
|
23259
|
-
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
23260
|
-
if (options.isMessagePreviewUpdated &&
|
|
23261
|
-
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
23262
|
-
rawPayload.messagePreviews &&
|
|
23263
|
-
rawPayload.messagePreviews.length > 0) {
|
|
23264
|
-
updateChannelMessagePreviewCache(rawPayload);
|
|
23798
|
+
async onFetch() {
|
|
23799
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
23800
|
+
return queryResponse;
|
|
23265
23801
|
}
|
|
23266
|
-
|
|
23267
|
-
|
|
23268
|
-
|
|
23269
|
-
|
|
23270
|
-
|
|
23271
|
-
|
|
23802
|
+
}
|
|
23803
|
+
|
|
23804
|
+
class LiveCollectionController {
|
|
23805
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
23806
|
+
this.paginationController = paginationController;
|
|
23807
|
+
this.queryStreamId = queryStreamId;
|
|
23808
|
+
this.cacheKey = cacheKey;
|
|
23809
|
+
this.callback = callback;
|
|
23272
23810
|
}
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
.
|
|
23277
|
-
|
|
23278
|
-
if (markerIds.length > 0) {
|
|
23279
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
23280
|
-
preUpdateChannelCache(rawPayload, {
|
|
23281
|
-
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
23282
|
-
});
|
|
23283
|
-
try {
|
|
23284
|
-
await getChannelMarkers(markerIds);
|
|
23811
|
+
async refresh() {
|
|
23812
|
+
try {
|
|
23813
|
+
let result;
|
|
23814
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
23815
|
+
result = await this.paginationController.onFetch();
|
|
23285
23816
|
}
|
|
23286
|
-
|
|
23287
|
-
|
|
23817
|
+
else {
|
|
23818
|
+
result = await this.paginationController.loadFirstPage();
|
|
23288
23819
|
}
|
|
23820
|
+
if (!result)
|
|
23821
|
+
return;
|
|
23822
|
+
await this.persistModel(result);
|
|
23823
|
+
this.persistQueryStream({
|
|
23824
|
+
response: result,
|
|
23825
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23826
|
+
refresh: true,
|
|
23827
|
+
});
|
|
23828
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23829
|
+
}
|
|
23830
|
+
catch (e) {
|
|
23831
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23832
|
+
}
|
|
23833
|
+
}
|
|
23834
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
23835
|
+
this.setup();
|
|
23836
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
23837
|
+
if (initial) {
|
|
23838
|
+
this.refresh();
|
|
23839
|
+
}
|
|
23840
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
23841
|
+
this.loadPrevPage();
|
|
23842
|
+
}
|
|
23843
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
23844
|
+
this.loadNextPage();
|
|
23845
|
+
}
|
|
23846
|
+
}
|
|
23847
|
+
async loadNextPage() {
|
|
23848
|
+
try {
|
|
23849
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
23850
|
+
return;
|
|
23851
|
+
const result = await this.paginationController.loadNextPage();
|
|
23852
|
+
if (!result)
|
|
23853
|
+
return;
|
|
23854
|
+
await this.persistModel(result);
|
|
23855
|
+
this.persistQueryStream({
|
|
23856
|
+
response: result,
|
|
23857
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23858
|
+
});
|
|
23859
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23860
|
+
}
|
|
23861
|
+
catch (e) {
|
|
23862
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23863
|
+
}
|
|
23864
|
+
}
|
|
23865
|
+
async loadPrevPage() {
|
|
23866
|
+
try {
|
|
23867
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
23868
|
+
return;
|
|
23869
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
23870
|
+
if (!result)
|
|
23871
|
+
return;
|
|
23872
|
+
await this.persistModel(result);
|
|
23873
|
+
this.persistQueryStream({
|
|
23874
|
+
response: result,
|
|
23875
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
23876
|
+
});
|
|
23877
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23878
|
+
}
|
|
23879
|
+
catch (e) {
|
|
23880
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23289
23881
|
}
|
|
23290
23882
|
}
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
|
|
23294
|
-
|
|
23295
|
-
|
|
23296
|
-
|
|
23297
|
-
|
|
23298
|
-
|
|
23299
|
-
|
|
23300
|
-
|
|
23301
|
-
|
|
23302
|
-
};
|
|
23883
|
+
shouldNotify(data) {
|
|
23884
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
23885
|
+
if (isEqual(this.snapshot, newData))
|
|
23886
|
+
return false;
|
|
23887
|
+
this.snapshot = newData;
|
|
23888
|
+
return true;
|
|
23889
|
+
}
|
|
23890
|
+
getCacheKey() {
|
|
23891
|
+
return this.cacheKey;
|
|
23892
|
+
}
|
|
23893
|
+
}
|
|
23303
23894
|
|
|
23304
23895
|
/**
|
|
23305
23896
|
* ```js
|
|
23306
|
-
* import {
|
|
23307
|
-
* const
|
|
23897
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
23898
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
23899
|
+
* // ...
|
|
23900
|
+
* })
|
|
23308
23901
|
* ```
|
|
23309
23902
|
*
|
|
23310
|
-
*
|
|
23903
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
23311
23904
|
*
|
|
23312
|
-
* @param
|
|
23313
|
-
* @
|
|
23314
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
23905
|
+
* @param callback The function to call when the event was fired
|
|
23906
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23315
23907
|
*
|
|
23316
|
-
* @category
|
|
23317
|
-
* @async
|
|
23318
|
-
* @private
|
|
23908
|
+
* @category Invitation Events
|
|
23319
23909
|
*/
|
|
23320
|
-
const
|
|
23910
|
+
const onLocalInvitationCreated = (callback) => {
|
|
23321
23911
|
const client = getActiveClient();
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23325
|
-
|
|
23326
|
-
|
|
23327
|
-
}
|
|
23328
|
-
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
23329
|
-
return data;
|
|
23912
|
+
const disposers = [
|
|
23913
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
23914
|
+
];
|
|
23915
|
+
return () => {
|
|
23916
|
+
disposers.forEach(fn => fn());
|
|
23917
|
+
};
|
|
23330
23918
|
};
|
|
23331
23919
|
|
|
23332
|
-
|
|
23920
|
+
/**
|
|
23921
|
+
* ```js
|
|
23922
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
23923
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
23924
|
+
* // ...
|
|
23925
|
+
* })
|
|
23926
|
+
* ```
|
|
23927
|
+
*
|
|
23928
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
23929
|
+
*
|
|
23930
|
+
* @param callback The function to call when the event was fired
|
|
23931
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23932
|
+
*
|
|
23933
|
+
* @category Invitation Events
|
|
23934
|
+
*/
|
|
23935
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
23333
23936
|
const client = getActiveClient();
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
userFeedMarkers,
|
|
23341
|
-
});
|
|
23342
|
-
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
23937
|
+
const disposers = [
|
|
23938
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
23939
|
+
];
|
|
23940
|
+
return () => {
|
|
23941
|
+
disposers.forEach(fn => fn());
|
|
23942
|
+
};
|
|
23343
23943
|
};
|
|
23344
23944
|
|
|
23345
|
-
const getCachedMarker$1 = (entityId) => {
|
|
23346
|
-
var _a;
|
|
23347
|
-
const key = {
|
|
23348
|
-
entityId,
|
|
23349
|
-
userId: getActiveUser()._id,
|
|
23350
|
-
};
|
|
23351
|
-
return (_a = pullFromCache([
|
|
23352
|
-
'channelMarker',
|
|
23353
|
-
'get',
|
|
23354
|
-
getResolver('channelMarker')(key),
|
|
23355
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23356
|
-
};
|
|
23357
|
-
const getUnreadInfoCached$1 = (channelId) => {
|
|
23358
|
-
var _a;
|
|
23359
|
-
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23360
|
-
};
|
|
23361
23945
|
/**
|
|
23362
|
-
*
|
|
23363
|
-
*
|
|
23946
|
+
* ```js
|
|
23947
|
+
* import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
|
|
23948
|
+
* const dispose = onLocalInvitationDeleted(data => {
|
|
23949
|
+
* // ...
|
|
23950
|
+
* })
|
|
23951
|
+
* ```
|
|
23364
23952
|
*
|
|
23365
|
-
*
|
|
23366
|
-
*
|
|
23367
|
-
*
|
|
23953
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
23954
|
+
*
|
|
23955
|
+
* @param callback The function to call when the event was fired
|
|
23956
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23957
|
+
*
|
|
23958
|
+
* @category Invitation Events
|
|
23368
23959
|
*/
|
|
23369
|
-
const
|
|
23370
|
-
var _a, _b, _c, _d;
|
|
23960
|
+
const onLocalInvitationDeleted = (callback) => {
|
|
23371
23961
|
const client = getActiveClient();
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
|
|
23375
|
-
return (
|
|
23376
|
-
|
|
23377
|
-
|
|
23962
|
+
const disposers = [
|
|
23963
|
+
createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload => callback(payload)),
|
|
23964
|
+
];
|
|
23965
|
+
return () => {
|
|
23966
|
+
disposers.forEach(fn => fn());
|
|
23967
|
+
};
|
|
23378
23968
|
};
|
|
23379
23969
|
|
|
23380
|
-
|
|
23381
|
-
|
|
23382
|
-
|
|
23383
|
-
|
|
23384
|
-
|
|
23385
|
-
|
|
23386
|
-
|
|
23387
|
-
|
|
23388
|
-
|
|
23389
|
-
|
|
23390
|
-
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
|
|
23395
|
-
|
|
23970
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
23971
|
+
constructor(query, callback) {
|
|
23972
|
+
const queryStreamId = hash(query);
|
|
23973
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
23974
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
23975
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23976
|
+
this.query = query;
|
|
23977
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
23978
|
+
this.callback = callback.bind(this);
|
|
23979
|
+
this.loadPage({ initial: true });
|
|
23980
|
+
}
|
|
23981
|
+
setup() {
|
|
23982
|
+
var _a;
|
|
23983
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23984
|
+
if (!collection) {
|
|
23985
|
+
pushToCache(this.cacheKey, {
|
|
23986
|
+
data: [],
|
|
23987
|
+
params: {},
|
|
23988
|
+
});
|
|
23989
|
+
}
|
|
23990
|
+
}
|
|
23991
|
+
async persistModel(queryPayload) {
|
|
23992
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
23993
|
+
}
|
|
23994
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23995
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23996
|
+
}
|
|
23997
|
+
startSubscription() {
|
|
23998
|
+
return this.queryStreamController.subscribeRTE([
|
|
23999
|
+
{
|
|
24000
|
+
fn: onLocalInvitationCreated,
|
|
24001
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
24002
|
+
},
|
|
24003
|
+
{
|
|
24004
|
+
fn: onLocalInvitationUpdated,
|
|
24005
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
24006
|
+
},
|
|
24007
|
+
{
|
|
24008
|
+
fn: onLocalInvitationDeleted,
|
|
24009
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
24010
|
+
},
|
|
24011
|
+
]);
|
|
24012
|
+
}
|
|
24013
|
+
notifyChange({ origin, loading, error }) {
|
|
24014
|
+
var _a, _b;
|
|
24015
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24016
|
+
if (!collection)
|
|
24017
|
+
return;
|
|
24018
|
+
const data = this.applyFilter((_b = collection.data
|
|
24019
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
24020
|
+
.filter(isNonNullable)
|
|
24021
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
24022
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24023
|
+
return;
|
|
24024
|
+
this.callback({
|
|
24025
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24026
|
+
data,
|
|
24027
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24028
|
+
loading,
|
|
24029
|
+
error,
|
|
24030
|
+
});
|
|
24031
|
+
}
|
|
24032
|
+
applyFilter(data) {
|
|
24033
|
+
let invitations = data;
|
|
24034
|
+
if (this.query.targetId) {
|
|
24035
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
24036
|
+
}
|
|
24037
|
+
if (this.query.statuses) {
|
|
24038
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
24039
|
+
}
|
|
24040
|
+
if (this.query.targetType) {
|
|
24041
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
24042
|
+
}
|
|
24043
|
+
if (this.query.type) {
|
|
24044
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
24045
|
+
}
|
|
24046
|
+
const sortFn = (() => {
|
|
24047
|
+
switch (this.query.sortBy) {
|
|
24048
|
+
case 'firstCreated':
|
|
24049
|
+
return sortByFirstCreated;
|
|
24050
|
+
case 'lastCreated':
|
|
24051
|
+
return sortByLastCreated;
|
|
24052
|
+
default:
|
|
24053
|
+
return sortByLastCreated;
|
|
24054
|
+
}
|
|
24055
|
+
})();
|
|
24056
|
+
invitations = invitations.sort(sortFn);
|
|
24057
|
+
return invitations;
|
|
24058
|
+
}
|
|
24059
|
+
}
|
|
24060
|
+
|
|
23396
24061
|
/**
|
|
23397
|
-
*
|
|
23398
|
-
*
|
|
24062
|
+
* Get invitations
|
|
24063
|
+
*
|
|
24064
|
+
* @param params the query parameters
|
|
24065
|
+
* @param callback the callback to be called when the invitations are updated
|
|
24066
|
+
* @returns invitations
|
|
24067
|
+
*
|
|
24068
|
+
* @category Invitation Live Collection
|
|
23399
24069
|
*
|
|
23400
|
-
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
23401
|
-
* If not, the function will return the value from the channelMarker cache.
|
|
23402
|
-
* If not found in the both cache, use `0` as defaul value.
|
|
23403
24070
|
*/
|
|
23404
|
-
const
|
|
23405
|
-
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
// Marker service API uses channelInternalId as channelId
|
|
23409
|
-
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
23410
|
-
}
|
|
23411
|
-
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
23412
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
23413
|
-
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
23414
|
-
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
23415
|
-
return 0;
|
|
24071
|
+
const getInvitations = (params, callback, config) => {
|
|
24072
|
+
const { log, cache } = getActiveClient();
|
|
24073
|
+
if (!cache) {
|
|
24074
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23416
24075
|
}
|
|
23417
|
-
|
|
24076
|
+
const timestamp = Date.now();
|
|
24077
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
24078
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
24079
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
24080
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
24081
|
+
disposers.push(() => {
|
|
24082
|
+
dropFromCache(cacheKey);
|
|
24083
|
+
});
|
|
24084
|
+
return () => {
|
|
24085
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
24086
|
+
disposers.forEach(fn => fn());
|
|
24087
|
+
};
|
|
23418
24088
|
};
|
|
23419
24089
|
|
|
23420
|
-
const
|
|
23421
|
-
|
|
23422
|
-
|
|
24090
|
+
const communityLinkedObject = (community) => {
|
|
24091
|
+
return Object.assign(Object.assign({}, community), { createInvitations: async (userIds) => {
|
|
24092
|
+
await createInvitations({
|
|
24093
|
+
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
24094
|
+
targetType: 'community',
|
|
24095
|
+
targetId: community.communityId,
|
|
24096
|
+
userIds,
|
|
24097
|
+
});
|
|
24098
|
+
}, getMemberInvitations: (callback) => {
|
|
24099
|
+
return getInvitations({
|
|
24100
|
+
targetId: community.communityId,
|
|
24101
|
+
targetType: 'community',
|
|
24102
|
+
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
24103
|
+
}, callback);
|
|
24104
|
+
} });
|
|
23423
24105
|
};
|
|
23424
24106
|
|
|
23425
|
-
const
|
|
23426
|
-
|
|
23427
|
-
|
|
23428
|
-
|
|
23429
|
-
|
|
23430
|
-
|
|
23431
|
-
|
|
23432
|
-
|
|
23433
|
-
|
|
23434
|
-
|
|
23435
|
-
|
|
23436
|
-
|
|
23437
|
-
|
|
23438
|
-
|
|
23439
|
-
|
|
23440
|
-
|
|
23441
|
-
},
|
|
23442
|
-
});
|
|
24107
|
+
const LinkedObject = {
|
|
24108
|
+
ad: adLinkedObject,
|
|
24109
|
+
comment: commentLinkedObject,
|
|
24110
|
+
post: postLinkedObject,
|
|
24111
|
+
user: userLinkedObject,
|
|
24112
|
+
category: categoryLinkedObject,
|
|
24113
|
+
stream: streamLinkedObject,
|
|
24114
|
+
story: storyLinkedObject,
|
|
24115
|
+
storyTarget: storyTargetLinkedObject,
|
|
24116
|
+
message: messageLinkedObject,
|
|
24117
|
+
reactor: reactorLinkedObject,
|
|
24118
|
+
channel: channelLinkedObject,
|
|
24119
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
24120
|
+
notificationTray: notificationTrayLinkedObject,
|
|
24121
|
+
community: communityLinkedObject,
|
|
24122
|
+
invitation: invitationLinkedObject,
|
|
23443
24123
|
};
|
|
23444
24124
|
|
|
23445
24125
|
const constructChannelObject = (channel) => {
|
|
@@ -26161,38 +26841,6 @@ const onMessageMarked = (callback) => {
|
|
|
26161
26841
|
return createEventSubscriber(client, 'messageMarker/onMessageMarked', 'marker.marked-message', filter);
|
|
26162
26842
|
};
|
|
26163
26843
|
|
|
26164
|
-
function isObject(value) {
|
|
26165
|
-
return typeof value === 'object' && value !== null;
|
|
26166
|
-
}
|
|
26167
|
-
/**
|
|
26168
|
-
* convert all object getter property to static value
|
|
26169
|
-
*/
|
|
26170
|
-
const convertGetterPropsToStatic = (obj) => {
|
|
26171
|
-
if (!isObject(obj)) {
|
|
26172
|
-
return obj;
|
|
26173
|
-
}
|
|
26174
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
26175
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
26176
|
-
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
26177
|
-
return [key, descriptor.get.call(obj)];
|
|
26178
|
-
}
|
|
26179
|
-
return [key, value];
|
|
26180
|
-
});
|
|
26181
|
-
return Object.fromEntries(entries);
|
|
26182
|
-
};
|
|
26183
|
-
const removeFunctionProperties = (obj) => {
|
|
26184
|
-
if (!isObject(obj)) {
|
|
26185
|
-
return obj;
|
|
26186
|
-
}
|
|
26187
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
26188
|
-
if (typeof value === 'function') {
|
|
26189
|
-
return [key, undefined];
|
|
26190
|
-
}
|
|
26191
|
-
return [key, value];
|
|
26192
|
-
});
|
|
26193
|
-
return Object.fromEntries(entries);
|
|
26194
|
-
};
|
|
26195
|
-
|
|
26196
26844
|
/**
|
|
26197
26845
|
*
|
|
26198
26846
|
* ```js
|
|
@@ -26302,7 +26950,7 @@ const getUserUnread = (callback) => {
|
|
|
26302
26950
|
};
|
|
26303
26951
|
};
|
|
26304
26952
|
|
|
26305
|
-
var index$
|
|
26953
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
26306
26954
|
__proto__: null,
|
|
26307
26955
|
getActiveClient: getActiveClient,
|
|
26308
26956
|
getActiveUser: getActiveUser,
|
|
@@ -26806,51 +27454,6 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
26806
27454
|
|
|
26807
27455
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26808
27456
|
|
|
26809
|
-
class PaginationController {
|
|
26810
|
-
constructor(queryParams) {
|
|
26811
|
-
const { http } = getActiveClient();
|
|
26812
|
-
this.queryParams = queryParams;
|
|
26813
|
-
this.http = http;
|
|
26814
|
-
}
|
|
26815
|
-
loadFirstPage() {
|
|
26816
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26817
|
-
}
|
|
26818
|
-
loadNextPage() {
|
|
26819
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
26820
|
-
}
|
|
26821
|
-
loadPreviousPage() {
|
|
26822
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
26823
|
-
}
|
|
26824
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
26825
|
-
var _a, _b, _c, _d;
|
|
26826
|
-
if (direction === 'prev' && !this.previousToken)
|
|
26827
|
-
return;
|
|
26828
|
-
if (direction === 'next' && !this.nextToken)
|
|
26829
|
-
return;
|
|
26830
|
-
let token;
|
|
26831
|
-
if (direction === 'prev')
|
|
26832
|
-
token = this.previousToken;
|
|
26833
|
-
if (direction === 'next')
|
|
26834
|
-
token = this.nextToken;
|
|
26835
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
26836
|
-
if (direction === 'first') {
|
|
26837
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
26838
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
26839
|
-
}
|
|
26840
|
-
if (direction === 'prev')
|
|
26841
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
26842
|
-
if (direction === 'next')
|
|
26843
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
26844
|
-
return queryResponse;
|
|
26845
|
-
}
|
|
26846
|
-
getNextToken() {
|
|
26847
|
-
return this.nextToken;
|
|
26848
|
-
}
|
|
26849
|
-
getPrevToken() {
|
|
26850
|
-
return this.previousToken;
|
|
26851
|
-
}
|
|
26852
|
-
}
|
|
26853
|
-
|
|
26854
27457
|
class FollowerPaginationController extends PaginationController {
|
|
26855
27458
|
async getRequest(queryParams, token) {
|
|
26856
27459
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
@@ -26864,13 +27467,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
26864
27467
|
}
|
|
26865
27468
|
}
|
|
26866
27469
|
|
|
26867
|
-
class QueryStreamController {
|
|
26868
|
-
constructor(query, cacheKey) {
|
|
26869
|
-
this.query = query;
|
|
26870
|
-
this.cacheKey = cacheKey;
|
|
26871
|
-
}
|
|
26872
|
-
}
|
|
26873
|
-
|
|
26874
27470
|
var EnumFollowActions;
|
|
26875
27471
|
(function (EnumFollowActions) {
|
|
26876
27472
|
EnumFollowActions["OnRequested"] = "onRequested";
|
|
@@ -26938,109 +27534,6 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
26938
27534
|
}
|
|
26939
27535
|
}
|
|
26940
27536
|
|
|
26941
|
-
class PaginationNoPageController {
|
|
26942
|
-
constructor(queryParams) {
|
|
26943
|
-
const { http } = getActiveClient();
|
|
26944
|
-
this.queryParams = queryParams;
|
|
26945
|
-
this.http = http;
|
|
26946
|
-
}
|
|
26947
|
-
async onFetch() {
|
|
26948
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
26949
|
-
return queryResponse;
|
|
26950
|
-
}
|
|
26951
|
-
}
|
|
26952
|
-
|
|
26953
|
-
class LiveCollectionController {
|
|
26954
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
26955
|
-
this.paginationController = paginationController;
|
|
26956
|
-
this.queryStreamId = queryStreamId;
|
|
26957
|
-
this.cacheKey = cacheKey;
|
|
26958
|
-
this.callback = callback;
|
|
26959
|
-
}
|
|
26960
|
-
async refresh() {
|
|
26961
|
-
try {
|
|
26962
|
-
let result;
|
|
26963
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
26964
|
-
result = await this.paginationController.onFetch();
|
|
26965
|
-
}
|
|
26966
|
-
else {
|
|
26967
|
-
result = await this.paginationController.loadFirstPage();
|
|
26968
|
-
}
|
|
26969
|
-
if (!result)
|
|
26970
|
-
return;
|
|
26971
|
-
await this.persistModel(result);
|
|
26972
|
-
this.persistQueryStream({
|
|
26973
|
-
response: result,
|
|
26974
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
26975
|
-
refresh: true,
|
|
26976
|
-
});
|
|
26977
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
26978
|
-
}
|
|
26979
|
-
catch (e) {
|
|
26980
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
26981
|
-
}
|
|
26982
|
-
}
|
|
26983
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
26984
|
-
this.setup();
|
|
26985
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
26986
|
-
if (initial) {
|
|
26987
|
-
this.refresh();
|
|
26988
|
-
}
|
|
26989
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
26990
|
-
this.loadPrevPage();
|
|
26991
|
-
}
|
|
26992
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
26993
|
-
this.loadNextPage();
|
|
26994
|
-
}
|
|
26995
|
-
}
|
|
26996
|
-
async loadNextPage() {
|
|
26997
|
-
try {
|
|
26998
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
26999
|
-
return;
|
|
27000
|
-
const result = await this.paginationController.loadNextPage();
|
|
27001
|
-
if (!result)
|
|
27002
|
-
return;
|
|
27003
|
-
await this.persistModel(result);
|
|
27004
|
-
this.persistQueryStream({
|
|
27005
|
-
response: result,
|
|
27006
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27007
|
-
});
|
|
27008
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27009
|
-
}
|
|
27010
|
-
catch (e) {
|
|
27011
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27012
|
-
}
|
|
27013
|
-
}
|
|
27014
|
-
async loadPrevPage() {
|
|
27015
|
-
try {
|
|
27016
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
27017
|
-
return;
|
|
27018
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
27019
|
-
if (!result)
|
|
27020
|
-
return;
|
|
27021
|
-
await this.persistModel(result);
|
|
27022
|
-
this.persistQueryStream({
|
|
27023
|
-
response: result,
|
|
27024
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
27025
|
-
});
|
|
27026
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27027
|
-
}
|
|
27028
|
-
catch (e) {
|
|
27029
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27030
|
-
}
|
|
27031
|
-
}
|
|
27032
|
-
shouldNotify(data) {
|
|
27033
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
27034
|
-
if (isEqual(this.snapshot, newData))
|
|
27035
|
-
return false;
|
|
27036
|
-
this.snapshot = newData;
|
|
27037
|
-
return true;
|
|
27038
|
-
}
|
|
27039
|
-
getCacheKey() {
|
|
27040
|
-
return this.cacheKey;
|
|
27041
|
-
}
|
|
27042
|
-
}
|
|
27043
|
-
|
|
27044
27537
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27045
27538
|
const client = getActiveClient();
|
|
27046
27539
|
const filter = (data) => {
|
|
@@ -27509,7 +28002,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27509
28002
|
};
|
|
27510
28003
|
/* end_public_function */
|
|
27511
28004
|
|
|
27512
|
-
var index$
|
|
28005
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
27513
28006
|
__proto__: null,
|
|
27514
28007
|
blockUser: blockUser,
|
|
27515
28008
|
unBlockUser: unBlockUser,
|
|
@@ -28524,9 +29017,9 @@ var AmityUserSearchMatchType;
|
|
|
28524
29017
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
28525
29018
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
28526
29019
|
|
|
28527
|
-
var index$
|
|
29020
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
28528
29021
|
__proto__: null,
|
|
28529
|
-
Relationship: index$
|
|
29022
|
+
Relationship: index$m,
|
|
28530
29023
|
getUserByIds: getUserByIds,
|
|
28531
29024
|
updateUser: updateUser,
|
|
28532
29025
|
flagUser: flagUser,
|
|
@@ -28834,7 +29327,7 @@ const updateAltText = async (fileId, altText) => {
|
|
|
28834
29327
|
};
|
|
28835
29328
|
/* end_public_function */
|
|
28836
29329
|
|
|
28837
|
-
var index$
|
|
29330
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
28838
29331
|
__proto__: null,
|
|
28839
29332
|
getFile: getFile,
|
|
28840
29333
|
uploadFile: uploadFile,
|
|
@@ -29205,7 +29698,11 @@ function isCurrentUserPartOfCommunity(c, m) {
|
|
|
29205
29698
|
*/
|
|
29206
29699
|
function updateMembershipStatus(communities, communityUsers) {
|
|
29207
29700
|
return communities.map(c => {
|
|
29208
|
-
const cachedCommunity = pullFromCache([
|
|
29701
|
+
const cachedCommunity = pullFromCache([
|
|
29702
|
+
'community',
|
|
29703
|
+
'get',
|
|
29704
|
+
c.communityId,
|
|
29705
|
+
]);
|
|
29209
29706
|
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
29210
29707
|
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
29211
29708
|
}
|
|
@@ -30702,7 +31199,7 @@ const getReactions = (params, callback, config) => {
|
|
|
30702
31199
|
};
|
|
30703
31200
|
/* end_public_function */
|
|
30704
31201
|
|
|
30705
|
-
var index$
|
|
31202
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
30706
31203
|
__proto__: null,
|
|
30707
31204
|
addReaction: addReaction,
|
|
30708
31205
|
removeReaction: removeReaction,
|
|
@@ -32525,7 +33022,7 @@ const getMessages = (params, callback, config) => {
|
|
|
32525
33022
|
};
|
|
32526
33023
|
/* end_public_function */
|
|
32527
33024
|
|
|
32528
|
-
var index$
|
|
33025
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
32529
33026
|
__proto__: null,
|
|
32530
33027
|
createMessage: createMessage,
|
|
32531
33028
|
updateMessage: updateMessage,
|
|
@@ -33051,7 +33548,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
33051
33548
|
};
|
|
33052
33549
|
/* end_public_function */
|
|
33053
33550
|
|
|
33054
|
-
var index$
|
|
33551
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
33055
33552
|
__proto__: null,
|
|
33056
33553
|
getSubChannelByIds: getSubChannels$1,
|
|
33057
33554
|
createSubChannel: createSubChannel,
|
|
@@ -34365,7 +34862,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
34365
34862
|
};
|
|
34366
34863
|
/* end_public_function */
|
|
34367
34864
|
|
|
34368
|
-
var index$
|
|
34865
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
34369
34866
|
__proto__: null,
|
|
34370
34867
|
addMembers: addMembers$1,
|
|
34371
34868
|
removeMembers: removeMembers$1,
|
|
@@ -34568,7 +35065,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
34568
35065
|
};
|
|
34569
35066
|
/* end_public_function */
|
|
34570
35067
|
|
|
34571
|
-
var index$
|
|
35068
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
34572
35069
|
__proto__: null,
|
|
34573
35070
|
addRole: addRole,
|
|
34574
35071
|
removeRole: removeRole,
|
|
@@ -34578,10 +35075,10 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
34578
35075
|
unmuteMembers: unmuteMembers
|
|
34579
35076
|
});
|
|
34580
35077
|
|
|
34581
|
-
var index$
|
|
35078
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
34582
35079
|
__proto__: null,
|
|
34583
|
-
Membership: index$
|
|
34584
|
-
Moderation: index$
|
|
35080
|
+
Membership: index$g,
|
|
35081
|
+
Moderation: index$f,
|
|
34585
35082
|
getChannelByIds: getChannelByIds$1,
|
|
34586
35083
|
createChannel: createChannel,
|
|
34587
35084
|
updateChannel: updateChannel,
|
|
@@ -34635,12 +35132,15 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34635
35132
|
* @category Community API
|
|
34636
35133
|
* @async
|
|
34637
35134
|
*/
|
|
34638
|
-
const getCommunities$1 = async (communityIds) => {
|
|
35135
|
+
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
34639
35136
|
const client = getActiveClient();
|
|
34640
35137
|
client.log('community/getCommunities', communityIds);
|
|
34641
35138
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
34642
35139
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
34643
|
-
params: {
|
|
35140
|
+
params: {
|
|
35141
|
+
communityIds,
|
|
35142
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35143
|
+
},
|
|
34644
35144
|
});
|
|
34645
35145
|
const data = prepareCommunityPayload(payload);
|
|
34646
35146
|
const cachedAt = client.cache && Date.now();
|
|
@@ -34649,7 +35149,7 @@ const getCommunities$1 = async (communityIds) => {
|
|
|
34649
35149
|
saveCommunityUsers(data.communities, data.communityUsers);
|
|
34650
35150
|
}
|
|
34651
35151
|
return {
|
|
34652
|
-
data: data.communities,
|
|
35152
|
+
data: data.communities.map(community => LinkedObject.community(community)),
|
|
34653
35153
|
cachedAt,
|
|
34654
35154
|
};
|
|
34655
35155
|
};
|
|
@@ -34715,7 +35215,7 @@ const createCommunity = async (bundle) => {
|
|
|
34715
35215
|
}
|
|
34716
35216
|
const { communities } = data;
|
|
34717
35217
|
return {
|
|
34718
|
-
data: communities[0],
|
|
35218
|
+
data: LinkedObject.community(communities[0]),
|
|
34719
35219
|
cachedAt,
|
|
34720
35220
|
};
|
|
34721
35221
|
};
|
|
@@ -34727,7 +35227,7 @@ const createCommunity = async (bundle) => {
|
|
|
34727
35227
|
/**
|
|
34728
35228
|
* ```js
|
|
34729
35229
|
* import { updateCommunity } from '@amityco/ts-sdk'
|
|
34730
|
-
* const updated = await updateCommunity(communityId, { displayName: 'foobar' })
|
|
35230
|
+
* const updated = await updateCommunity(communityId, { displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
34731
35231
|
* ```
|
|
34732
35232
|
*
|
|
34733
35233
|
* Updates an {@link Amity.Community}
|
|
@@ -34752,7 +35252,7 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
34752
35252
|
}
|
|
34753
35253
|
const { communities } = data;
|
|
34754
35254
|
return {
|
|
34755
|
-
data: communities.find(community => community.communityId === communityId),
|
|
35255
|
+
data: LinkedObject.community(communities.find(community => community.communityId === communityId)),
|
|
34756
35256
|
cachedAt,
|
|
34757
35257
|
};
|
|
34758
35258
|
};
|
|
@@ -34785,7 +35285,7 @@ const getCommunity$1 = async (communityId) => {
|
|
|
34785
35285
|
}
|
|
34786
35286
|
const { communities } = data;
|
|
34787
35287
|
return {
|
|
34788
|
-
data: communities.find(community => community.communityId === communityId),
|
|
35288
|
+
data: LinkedObject.community(communities.find(community => community.communityId === communityId)),
|
|
34789
35289
|
cachedAt,
|
|
34790
35290
|
};
|
|
34791
35291
|
};
|
|
@@ -35961,7 +36461,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
35961
36461
|
};
|
|
35962
36462
|
/* end_public_function */
|
|
35963
36463
|
|
|
35964
|
-
var index$
|
|
36464
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
35965
36465
|
__proto__: null,
|
|
35966
36466
|
addMembers: addMembers,
|
|
35967
36467
|
removeMembers: removeMembers,
|
|
@@ -36986,7 +37486,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
36986
37486
|
};
|
|
36987
37487
|
/* end_public_function */
|
|
36988
37488
|
|
|
36989
|
-
var index$
|
|
37489
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
36990
37490
|
__proto__: null,
|
|
36991
37491
|
addRoles: addRoles,
|
|
36992
37492
|
removeRoles: removeRoles,
|
|
@@ -36994,10 +37494,10 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
36994
37494
|
unbanMembers: unbanMembers
|
|
36995
37495
|
});
|
|
36996
37496
|
|
|
36997
|
-
var index$
|
|
37497
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
36998
37498
|
__proto__: null,
|
|
36999
|
-
Moderation: index$
|
|
37000
|
-
Membership: index$
|
|
37499
|
+
Moderation: index$c,
|
|
37500
|
+
Membership: index$d,
|
|
37001
37501
|
getCommunityByIds: getCommunities$1,
|
|
37002
37502
|
createCommunity: createCommunity,
|
|
37003
37503
|
updateCommunity: updateCommunity,
|
|
@@ -37230,7 +37730,7 @@ const getCategories = (params, callback, config) => {
|
|
|
37230
37730
|
};
|
|
37231
37731
|
/* end_public_function */
|
|
37232
37732
|
|
|
37233
|
-
var index$
|
|
37733
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
37234
37734
|
__proto__: null,
|
|
37235
37735
|
getCategory: getCategory,
|
|
37236
37736
|
getCategories: getCategories
|
|
@@ -37398,7 +37898,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
37398
37898
|
: undefined;
|
|
37399
37899
|
};
|
|
37400
37900
|
|
|
37401
|
-
var index$
|
|
37901
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
37402
37902
|
__proto__: null,
|
|
37403
37903
|
queryGlobalFeed: queryGlobalFeed,
|
|
37404
37904
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -38727,7 +39227,7 @@ const getComments = (params, callback, config) => {
|
|
|
38727
39227
|
};
|
|
38728
39228
|
/* end_public_function */
|
|
38729
39229
|
|
|
38730
|
-
var index$
|
|
39230
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
38731
39231
|
__proto__: null,
|
|
38732
39232
|
getCommentByIds: getCommentByIds,
|
|
38733
39233
|
createComment: createComment,
|
|
@@ -39734,7 +40234,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
39734
40234
|
};
|
|
39735
40235
|
};
|
|
39736
40236
|
|
|
39737
|
-
var index$
|
|
40237
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
39738
40238
|
__proto__: null,
|
|
39739
40239
|
getPostByIds: getPostByIds,
|
|
39740
40240
|
createPost: createPost,
|
|
@@ -40268,7 +40768,7 @@ const getStreams = (params, callback, config) => {
|
|
|
40268
40768
|
};
|
|
40269
40769
|
};
|
|
40270
40770
|
|
|
40271
|
-
var index$
|
|
40771
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
40272
40772
|
__proto__: null,
|
|
40273
40773
|
createStream: createStream,
|
|
40274
40774
|
updateStream: updateStream,
|
|
@@ -40555,7 +41055,7 @@ const getPoll = (pollId, callback) => {
|
|
|
40555
41055
|
};
|
|
40556
41056
|
/* end_public_function */
|
|
40557
41057
|
|
|
40558
|
-
var index$
|
|
41058
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
40559
41059
|
__proto__: null,
|
|
40560
41060
|
createPoll: createPoll,
|
|
40561
41061
|
closePoll: closePoll,
|
|
@@ -40926,7 +41426,7 @@ const getPlayer = async (parameters) => {
|
|
|
40926
41426
|
return video;
|
|
40927
41427
|
};
|
|
40928
41428
|
|
|
40929
|
-
var index$
|
|
41429
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
40930
41430
|
__proto__: null,
|
|
40931
41431
|
getPlayer: getPlayer
|
|
40932
41432
|
});
|
|
@@ -42099,7 +42599,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
42099
42599
|
};
|
|
42100
42600
|
};
|
|
42101
42601
|
|
|
42102
|
-
var index$
|
|
42602
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
42103
42603
|
__proto__: null,
|
|
42104
42604
|
createImageStory: createImageStory,
|
|
42105
42605
|
createVideoStory: createVideoStory,
|
|
@@ -42136,7 +42636,7 @@ const getNetworkAds = async () => {
|
|
|
42136
42636
|
};
|
|
42137
42637
|
};
|
|
42138
42638
|
|
|
42139
|
-
var index$
|
|
42639
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
42140
42640
|
__proto__: null,
|
|
42141
42641
|
getNetworkAds: getNetworkAds
|
|
42142
42642
|
});
|
|
@@ -42527,7 +43027,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
42527
43027
|
};
|
|
42528
43028
|
/* end_public_function */
|
|
42529
43029
|
|
|
42530
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
43030
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
42531
43031
|
__proto__: null,
|
|
42532
43032
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
42533
43033
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -42536,4 +43036,11 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
42536
43036
|
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
42537
43037
|
});
|
|
42538
43038
|
|
|
42539
|
-
|
|
43039
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
43040
|
+
__proto__: null,
|
|
43041
|
+
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
43042
|
+
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
43043
|
+
onLocalInvitationDeleted: onLocalInvitationDeleted
|
|
43044
|
+
});
|
|
43045
|
+
|
|
43046
|
+
export { API_REGIONS, index$2 as AdRepository, index$a as CategoryRepository, index$e as ChannelRepository, index$n as Client, index$8 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$b as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$k as FileRepository, FileType, index as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, index$4 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$i as MessageRepository, index$5 as PollRepository, PostContentType, index$7 as PostRepository, index$j as ReactionRepository, index$3 as StoryRepository, index$6 as StreamRepository, index$h as SubChannelRepository, SubscriptionLevels, index$l as UserRepository, 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, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$1 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 };
|