@amityco/ts-sdk 7.4.1-d23fab2f.0 → 7.4.1-fd0f791a.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 +7 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +30 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +32 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +48 -3
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/@types/domains/joinRequest.d.ts +53 -0
- package/dist/@types/domains/joinRequest.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/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +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/joinCommunity.d.ts +3 -0
- package/dist/communityRepository/api/joinCommunity.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/internalAPI/getMyJoinRequest.d.ts +16 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- 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 +2608 -1576
- package/dist/index.esm.js +2432 -1400
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/events/index.d.ts +2 -0
- package/dist/invitationRepository/events/index.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -1
- package/dist/invitationRepository/index.d.ts +1 -0
- package/dist/invitationRepository/index.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
- package/dist/invitationRepository/internalApi/getInvitation.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/observers/getMyCommunityInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/index.d.ts +2 -0
- package/dist/invitationRepository/observers/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.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/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +3 -2
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +10 -4
- package/src/@types/core/model.ts +3 -0
- package/src/@types/core/payload.ts +39 -1
- package/src/@types/domains/community.ts +45 -2
- package/src/@types/domains/invitation.ts +67 -3
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +9 -1
- package/src/communityRepository/api/getRecommendedCommunities.ts +9 -3
- package/src/communityRepository/api/getTrendingCommunities.ts +9 -3
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/api/updateCommunity.ts +9 -2
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +51 -0
- package/src/communityRepository/joinRequest/events/index.ts +3 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
- package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
- package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
- package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
- package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequests.ts +44 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
- package/src/communityRepository/utils/communityWithMembership.ts +1 -1
- package/src/communityRepository/utils/payload.ts +27 -1
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/invitationRepository/events/index.ts +2 -0
- package/src/invitationRepository/events/onLocalInvitationCreated.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationDeleted.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationUpdated.ts +1 -1
- package/src/invitationRepository/index.ts +1 -0
- package/src/invitationRepository/internalApi/acceptInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/cancelInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/createInvitations.ts +8 -2
- package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
- package/src/invitationRepository/internalApi/rejectInvitation.ts +1 -1
- 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/observers/getMyCommunityInvitations.ts +48 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
- package/src/invitationRepository/observers/index.ts +1 -0
- package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
- package/src/invitationRepository/utils/index.ts +1 -0
- package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
- package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +43 -1
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +25 -1
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
package/dist/index.esm.js
CHANGED
|
@@ -114,7 +114,25 @@ var InvitationStatusEnum;
|
|
|
114
114
|
InvitationStatusEnum["Approved"] = "approved";
|
|
115
115
|
InvitationStatusEnum["Rejected"] = "rejected";
|
|
116
116
|
InvitationStatusEnum["Cancelled"] = "cancelled";
|
|
117
|
-
})(InvitationStatusEnum || (InvitationStatusEnum = {}));
|
|
117
|
+
})(InvitationStatusEnum || (InvitationStatusEnum = {}));
|
|
118
|
+
var InvitationSortByEnum;
|
|
119
|
+
(function (InvitationSortByEnum) {
|
|
120
|
+
InvitationSortByEnum["FirstCreated"] = "firstCreated";
|
|
121
|
+
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
122
|
+
})(InvitationSortByEnum || (InvitationSortByEnum = {}));
|
|
123
|
+
|
|
124
|
+
var JoinRequestStatusEnum;
|
|
125
|
+
(function (JoinRequestStatusEnum) {
|
|
126
|
+
JoinRequestStatusEnum["Pending"] = "pending";
|
|
127
|
+
JoinRequestStatusEnum["Approved"] = "approved";
|
|
128
|
+
JoinRequestStatusEnum["Rejected"] = "rejected";
|
|
129
|
+
JoinRequestStatusEnum["Cancelled"] = "cancelled";
|
|
130
|
+
})(JoinRequestStatusEnum || (JoinRequestStatusEnum = {}));
|
|
131
|
+
var JoinResultStatusEnum;
|
|
132
|
+
(function (JoinResultStatusEnum) {
|
|
133
|
+
JoinResultStatusEnum["Success"] = "success";
|
|
134
|
+
JoinResultStatusEnum["Pending"] = "pending";
|
|
135
|
+
})(JoinResultStatusEnum || (JoinResultStatusEnum = {}));
|
|
118
136
|
|
|
119
137
|
function getVersion() {
|
|
120
138
|
try {
|
|
@@ -563,6 +581,7 @@ const idResolvers = {
|
|
|
563
581
|
notificationTrayItem: ({ _id }) => _id,
|
|
564
582
|
notificationTraySeen: ({ userId }) => userId,
|
|
565
583
|
invitation: ({ _id }) => _id,
|
|
584
|
+
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
566
585
|
};
|
|
567
586
|
/**
|
|
568
587
|
* Retrieve the id resolver matching a domain name
|
|
@@ -616,6 +635,7 @@ const PAYLOAD2MODEL = {
|
|
|
616
635
|
pins: 'pin',
|
|
617
636
|
notificationTrayItems: 'notificationTrayItem',
|
|
618
637
|
invitations: 'invitation',
|
|
638
|
+
joinRequests: 'joinRequest',
|
|
619
639
|
};
|
|
620
640
|
/** hidden */
|
|
621
641
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -20990,6 +21010,1103 @@ const getChannelMessagePreview = (channelId) => {
|
|
|
20990
21010
|
return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
20991
21011
|
};
|
|
20992
21012
|
|
|
21013
|
+
const userLinkedObject = (user) => {
|
|
21014
|
+
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
21015
|
+
var _a;
|
|
21016
|
+
if (!user.avatarFileId)
|
|
21017
|
+
return undefined;
|
|
21018
|
+
const avatar = (_a = pullFromCache([
|
|
21019
|
+
'file',
|
|
21020
|
+
'get',
|
|
21021
|
+
`${user.avatarFileId}`,
|
|
21022
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21023
|
+
return avatar;
|
|
21024
|
+
} });
|
|
21025
|
+
};
|
|
21026
|
+
|
|
21027
|
+
const getChannelMessagePreviewWithUser = (channel) => {
|
|
21028
|
+
var _a;
|
|
21029
|
+
const messagePreview = channel.messagePreviewId
|
|
21030
|
+
? getChannelMessagePreview(channel.channelId)
|
|
21031
|
+
: null;
|
|
21032
|
+
const internalUser = (_a = pullFromCache([
|
|
21033
|
+
'user',
|
|
21034
|
+
'get',
|
|
21035
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
21036
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21037
|
+
const messagePreviewWithUser = messagePreview
|
|
21038
|
+
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? userLinkedObject(internalUser) : undefined }) : null;
|
|
21039
|
+
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
21040
|
+
};
|
|
21041
|
+
|
|
21042
|
+
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
21043
|
+
var _a, _b;
|
|
21044
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21045
|
+
var _a;
|
|
21046
|
+
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21047
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21048
|
+
});
|
|
21049
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
21050
|
+
return {
|
|
21051
|
+
channelId,
|
|
21052
|
+
subChannelId,
|
|
21053
|
+
data,
|
|
21054
|
+
dataType,
|
|
21055
|
+
isDeleted,
|
|
21056
|
+
segment,
|
|
21057
|
+
creatorId,
|
|
21058
|
+
createdAt,
|
|
21059
|
+
updatedAt,
|
|
21060
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21061
|
+
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
21062
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21063
|
+
};
|
|
21064
|
+
};
|
|
21065
|
+
const newData = {
|
|
21066
|
+
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21067
|
+
};
|
|
21068
|
+
ingestInCache(newData);
|
|
21069
|
+
};
|
|
21070
|
+
|
|
21071
|
+
const getSubChannelMessagePreview = (subChannelId) => {
|
|
21072
|
+
var _a, _b;
|
|
21073
|
+
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
21074
|
+
};
|
|
21075
|
+
|
|
21076
|
+
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
21077
|
+
var _a;
|
|
21078
|
+
const messagePreview = subChannel.messagePreviewId
|
|
21079
|
+
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
21080
|
+
: null;
|
|
21081
|
+
const messagePreviewWithUser = messagePreview
|
|
21082
|
+
? 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;
|
|
21083
|
+
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
21084
|
+
};
|
|
21085
|
+
|
|
21086
|
+
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
21087
|
+
var _a, _b;
|
|
21088
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21089
|
+
var _a;
|
|
21090
|
+
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21091
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21092
|
+
});
|
|
21093
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
21094
|
+
return {
|
|
21095
|
+
messagePreviewId,
|
|
21096
|
+
channelId,
|
|
21097
|
+
subChannelId,
|
|
21098
|
+
data,
|
|
21099
|
+
dataType,
|
|
21100
|
+
isDeleted,
|
|
21101
|
+
segment,
|
|
21102
|
+
creatorId,
|
|
21103
|
+
createdAt,
|
|
21104
|
+
updatedAt,
|
|
21105
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21106
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21107
|
+
};
|
|
21108
|
+
};
|
|
21109
|
+
const newData = {
|
|
21110
|
+
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21111
|
+
};
|
|
21112
|
+
ingestInCache(newData);
|
|
21113
|
+
};
|
|
21114
|
+
|
|
21115
|
+
/**
|
|
21116
|
+
* ```js
|
|
21117
|
+
* import { shallowClone } from '~/utils/shallowClone'
|
|
21118
|
+
* const newObj = shallowClone(obj)
|
|
21119
|
+
* ```
|
|
21120
|
+
*
|
|
21121
|
+
* Clone an object with same prototype and properties
|
|
21122
|
+
*
|
|
21123
|
+
* @param obj the object to clone
|
|
21124
|
+
* @returns new object with same prototype and properties
|
|
21125
|
+
*
|
|
21126
|
+
* @category utility
|
|
21127
|
+
* @private
|
|
21128
|
+
*/
|
|
21129
|
+
function shallowClone(source, target) {
|
|
21130
|
+
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
21131
|
+
}
|
|
21132
|
+
|
|
21133
|
+
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
21134
|
+
pushToCache(['subChannel', 'get', subChannelId],
|
|
21135
|
+
// eslint-disable-next-line prefer-object-spread
|
|
21136
|
+
shallowClone(subChannel, params));
|
|
21137
|
+
}
|
|
21138
|
+
|
|
21139
|
+
/**
|
|
21140
|
+
* ```js
|
|
21141
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
21142
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
21143
|
+
* ```
|
|
21144
|
+
*
|
|
21145
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
21146
|
+
* in cache and it's not expired means it's in tombstone
|
|
21147
|
+
* and we throw an Error
|
|
21148
|
+
*
|
|
21149
|
+
* @param model the model to check
|
|
21150
|
+
* @param modelId the object id to check
|
|
21151
|
+
* @returns the matching cache entry, or undefined.
|
|
21152
|
+
*
|
|
21153
|
+
* @category Cache API
|
|
21154
|
+
*/
|
|
21155
|
+
const isInTombstone = (model, modelId) => {
|
|
21156
|
+
const { log, cache } = getActiveClient();
|
|
21157
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
21158
|
+
if (!cache)
|
|
21159
|
+
return;
|
|
21160
|
+
log('cache/api/isInTombstone', key);
|
|
21161
|
+
const isInTombstone = pullFromCache(key);
|
|
21162
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
21163
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
21164
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
21165
|
+
}
|
|
21166
|
+
};
|
|
21167
|
+
|
|
21168
|
+
/**
|
|
21169
|
+
* ```js
|
|
21170
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
21171
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
21172
|
+
* ```
|
|
21173
|
+
*
|
|
21174
|
+
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
21175
|
+
*
|
|
21176
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
21177
|
+
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
21178
|
+
*
|
|
21179
|
+
* @category Channel API
|
|
21180
|
+
* @async
|
|
21181
|
+
* @private
|
|
21182
|
+
*/
|
|
21183
|
+
const getMessageMarkers = async (messageIds) => {
|
|
21184
|
+
const client = getActiveClient();
|
|
21185
|
+
client.log('channel/getMessageMarkers', messageIds);
|
|
21186
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
21187
|
+
params: {
|
|
21188
|
+
messageIds,
|
|
21189
|
+
},
|
|
21190
|
+
});
|
|
21191
|
+
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
21192
|
+
const cachedAt = client.cache && Date.now();
|
|
21193
|
+
if (client.cache)
|
|
21194
|
+
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
21195
|
+
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
21196
|
+
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
21197
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21198
|
+
return { data: contentMarkers, cachedAt };
|
|
21199
|
+
};
|
|
21200
|
+
|
|
21201
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21202
|
+
var _a;
|
|
21203
|
+
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
21204
|
+
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21205
|
+
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
21206
|
+
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
21207
|
+
let channelUnreads = 0;
|
|
21208
|
+
let isMentioned = false;
|
|
21209
|
+
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
21210
|
+
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
21211
|
+
return data.channelId === channelId && !data.isDeleted;
|
|
21212
|
+
});
|
|
21213
|
+
channelUnreads = subChannelUnreadsInfo
|
|
21214
|
+
.map(({ data }) => data.unreadCount)
|
|
21215
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
21216
|
+
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
21217
|
+
}
|
|
21218
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
21219
|
+
channelId,
|
|
21220
|
+
createdAt: new Date().toISOString(),
|
|
21221
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
21222
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
21223
|
+
return channelUnreadInfo;
|
|
21224
|
+
};
|
|
21225
|
+
|
|
21226
|
+
const persistUnreadCountInfo = (payload) => {
|
|
21227
|
+
const { feedMarkers, userFeedMarkers } = payload;
|
|
21228
|
+
// calculate sub channel unread info and channel unread info
|
|
21229
|
+
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
21230
|
+
const channelIds = [];
|
|
21231
|
+
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
21232
|
+
userFeedMarkers.forEach(userFeedMarker => {
|
|
21233
|
+
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
21234
|
+
if (!feedMarker)
|
|
21235
|
+
return;
|
|
21236
|
+
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
21237
|
+
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
21238
|
+
const subChannelUnreadInfo = {
|
|
21239
|
+
subChannelId: feedMarker.feedId,
|
|
21240
|
+
channelId: feedMarker.entityId,
|
|
21241
|
+
readToSegment: userFeedMarker.readToSegment,
|
|
21242
|
+
lastSegment: feedMarker.lastSegment,
|
|
21243
|
+
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
21244
|
+
unreadCount: Math.max(0, unreadCount),
|
|
21245
|
+
isMentioned: userFeedMarker.isMentioned,
|
|
21246
|
+
isDeleted: feedMarker.isDeleted,
|
|
21247
|
+
createdAt: userFeedMarker.createdAt,
|
|
21248
|
+
updatedAt: userFeedMarker.updatedAt,
|
|
21249
|
+
};
|
|
21250
|
+
// update sub channel unread info in cache
|
|
21251
|
+
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
21252
|
+
if (!channelIds.includes(feedMarker.entityId)) {
|
|
21253
|
+
channelIds.push(feedMarker.entityId);
|
|
21254
|
+
}
|
|
21255
|
+
}
|
|
21256
|
+
});
|
|
21257
|
+
// re-calculate channel unread info in cache
|
|
21258
|
+
channelIds.forEach(channelId => {
|
|
21259
|
+
reCalculateChannelUnreadInfo(channelId);
|
|
21260
|
+
});
|
|
21261
|
+
}
|
|
21262
|
+
};
|
|
21263
|
+
|
|
21264
|
+
/**
|
|
21265
|
+
* ```js
|
|
21266
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21267
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21268
|
+
* ```
|
|
21269
|
+
*
|
|
21270
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21271
|
+
*
|
|
21272
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21273
|
+
* @param page
|
|
21274
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21275
|
+
*
|
|
21276
|
+
* @category Channel API
|
|
21277
|
+
* @async
|
|
21278
|
+
* @private
|
|
21279
|
+
*/
|
|
21280
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
21281
|
+
const client = getActiveClient();
|
|
21282
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
21283
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
21284
|
+
params: {
|
|
21285
|
+
messageFeedIds,
|
|
21286
|
+
options: {
|
|
21287
|
+
token: toToken(page, 'skiplimit'),
|
|
21288
|
+
},
|
|
21289
|
+
},
|
|
21290
|
+
});
|
|
21291
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21292
|
+
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
21293
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
21294
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21295
|
+
persistUnreadCountInfo({
|
|
21296
|
+
feedMarkers: feedMarkersPayload,
|
|
21297
|
+
userFeedMarkers: userFeedMarkersPayload,
|
|
21298
|
+
});
|
|
21299
|
+
}
|
|
21300
|
+
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
21301
|
+
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
21302
|
+
const cachedAt = client.cache && Date.now();
|
|
21303
|
+
if (client.cache)
|
|
21304
|
+
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
21305
|
+
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21306
|
+
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
21307
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21308
|
+
const nextPage = toPage(paging.next);
|
|
21309
|
+
const prevPage = toPage(paging.previous);
|
|
21310
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
21311
|
+
};
|
|
21312
|
+
|
|
21313
|
+
const getUserMarker = async () => {
|
|
21314
|
+
const client = getActiveClient();
|
|
21315
|
+
client.log('channel/getUserMarker');
|
|
21316
|
+
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
21317
|
+
const { userMarkers } = payload;
|
|
21318
|
+
const cachedAt = client.cache && Date.now();
|
|
21319
|
+
if (client.cache)
|
|
21320
|
+
ingestInCache({ userMarkers }, { cachedAt });
|
|
21321
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21322
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
21323
|
+
if (maxUserMarker == null ||
|
|
21324
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
21325
|
+
return userMarker;
|
|
21326
|
+
}
|
|
21327
|
+
return maxUserMarker;
|
|
21328
|
+
}, undefined);
|
|
21329
|
+
return { data: latestUserMarker, cachedAt };
|
|
21330
|
+
};
|
|
21331
|
+
|
|
21332
|
+
/** @hidden */
|
|
21333
|
+
/*
|
|
21334
|
+
* @param message payload from http request without myReactions
|
|
21335
|
+
* add myReactions to http response if the event was a reaction event
|
|
21336
|
+
*/
|
|
21337
|
+
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
21338
|
+
const client = getActiveClient();
|
|
21339
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
21340
|
+
// '[]' in cases where the new reaction is the first one
|
|
21341
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
21342
|
+
// add myReactions to the payload
|
|
21343
|
+
Object.assign(payload, { myReactions });
|
|
21344
|
+
// check if there are any updates to the reactions
|
|
21345
|
+
const latestReaction = reactors[0];
|
|
21346
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
21347
|
+
if (!isLatestReactionMine) {
|
|
21348
|
+
return;
|
|
21349
|
+
}
|
|
21350
|
+
// new reaction added
|
|
21351
|
+
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
21352
|
+
Object.assign(payload, {
|
|
21353
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
21354
|
+
});
|
|
21355
|
+
}
|
|
21356
|
+
// existing reaction removed
|
|
21357
|
+
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
21358
|
+
Object.assign(payload, {
|
|
21359
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
21360
|
+
});
|
|
21361
|
+
}
|
|
21362
|
+
};
|
|
21363
|
+
|
|
21364
|
+
/*
|
|
21365
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
21366
|
+
* value of includeDeleted
|
|
21367
|
+
*
|
|
21368
|
+
* There are two important things to note here:
|
|
21369
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
21370
|
+
* the server
|
|
21371
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
21372
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
21373
|
+
* for deleted entities
|
|
21374
|
+
*
|
|
21375
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
21376
|
+
* DRY
|
|
21377
|
+
*/
|
|
21378
|
+
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
21379
|
+
|
|
21380
|
+
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
21381
|
+
var _a, _b;
|
|
21382
|
+
// Look for `unreadCount` in the marker param first
|
|
21383
|
+
if (marker) {
|
|
21384
|
+
return marker.hasMentioned;
|
|
21385
|
+
}
|
|
21386
|
+
const client = getActiveClient();
|
|
21387
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21388
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21389
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21390
|
+
'subChannelUnreadInfo',
|
|
21391
|
+
'get',
|
|
21392
|
+
subChannelId,
|
|
21393
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21394
|
+
if (cachedUnreadCount) {
|
|
21395
|
+
return cachedUnreadCount.isMentioned;
|
|
21396
|
+
}
|
|
21397
|
+
return false;
|
|
21398
|
+
}
|
|
21399
|
+
const key = {
|
|
21400
|
+
entityId: channelId,
|
|
21401
|
+
feedId: subChannelId,
|
|
21402
|
+
userId: getActiveUser()._id,
|
|
21403
|
+
};
|
|
21404
|
+
// If the marker param is not set, look in the cache
|
|
21405
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21406
|
+
'subChannelMarker',
|
|
21407
|
+
'get',
|
|
21408
|
+
getResolver('subChannelMarker')(key),
|
|
21409
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21410
|
+
if (cachedMarker) {
|
|
21411
|
+
return cachedMarker.hasMentioned;
|
|
21412
|
+
}
|
|
21413
|
+
// and if not found in cache use default value `false`
|
|
21414
|
+
return false;
|
|
21415
|
+
}
|
|
21416
|
+
|
|
21417
|
+
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
21418
|
+
var _a, _b;
|
|
21419
|
+
// Look for `unreadCount` in the marker param first
|
|
21420
|
+
if (marker) {
|
|
21421
|
+
return marker.unreadCount;
|
|
21422
|
+
}
|
|
21423
|
+
const client = getActiveClient();
|
|
21424
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21425
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21426
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21427
|
+
'subChannelUnreadInfo',
|
|
21428
|
+
'get',
|
|
21429
|
+
subChannelId,
|
|
21430
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21431
|
+
if (cachedUnreadCount) {
|
|
21432
|
+
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
21433
|
+
}
|
|
21434
|
+
return 0;
|
|
21435
|
+
}
|
|
21436
|
+
const key = {
|
|
21437
|
+
entityId: channelId,
|
|
21438
|
+
feedId: subChannelId,
|
|
21439
|
+
userId: getActiveUser()._id,
|
|
21440
|
+
};
|
|
21441
|
+
// If the marker param is not set, look in the cache
|
|
21442
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21443
|
+
'subChannelMarker',
|
|
21444
|
+
'get',
|
|
21445
|
+
getResolver('subChannelMarker')(key),
|
|
21446
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21447
|
+
if (cachedMarker) {
|
|
21448
|
+
return cachedMarker.unreadCount;
|
|
21449
|
+
}
|
|
21450
|
+
// and if not found in cache use default value `0`
|
|
21451
|
+
return 0;
|
|
21452
|
+
}
|
|
21453
|
+
|
|
21454
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
21455
|
+
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
21456
|
+
function convertFromRaw$2(_a) {
|
|
21457
|
+
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"]);
|
|
21458
|
+
return Object.assign(Object.assign({ get unreadCount() {
|
|
21459
|
+
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
21460
|
+
},
|
|
21461
|
+
get hasMentioned() {
|
|
21462
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21463
|
+
},
|
|
21464
|
+
get isMentioned() {
|
|
21465
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21466
|
+
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
21467
|
+
}
|
|
21468
|
+
|
|
21469
|
+
const mergePayloadWithLocal = (payload) => {
|
|
21470
|
+
var _a, _b, _c;
|
|
21471
|
+
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;
|
|
21472
|
+
if (localMessage) {
|
|
21473
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
21474
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
21475
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
21476
|
+
}
|
|
21477
|
+
return payload;
|
|
21478
|
+
};
|
|
21479
|
+
function convertFromRaw$1(message, reactors, event) {
|
|
21480
|
+
var _a;
|
|
21481
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
21482
|
+
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"]);
|
|
21483
|
+
let cache;
|
|
21484
|
+
if (referenceId) {
|
|
21485
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
21486
|
+
}
|
|
21487
|
+
if (!cache) {
|
|
21488
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
21489
|
+
}
|
|
21490
|
+
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 : {},
|
|
21491
|
+
/*
|
|
21492
|
+
* Previously, myReactions were added only if it was part of the payload.
|
|
21493
|
+
* So empty myReactions were not present. So I've edited the payload to add
|
|
21494
|
+
* a default for those cases.
|
|
21495
|
+
*
|
|
21496
|
+
* Check git blame for previous iteration
|
|
21497
|
+
*/
|
|
21498
|
+
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 */ });
|
|
21499
|
+
if (mentionedUsers) {
|
|
21500
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
21501
|
+
if (mention.type === 'channel') {
|
|
21502
|
+
return mention;
|
|
21503
|
+
}
|
|
21504
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
21505
|
+
});
|
|
21506
|
+
}
|
|
21507
|
+
if (reactors && reactors.length && event) {
|
|
21508
|
+
// mqtt event
|
|
21509
|
+
prepareMessagePayloadForCache(out, reactors, event);
|
|
21510
|
+
}
|
|
21511
|
+
return out;
|
|
21512
|
+
}
|
|
21513
|
+
const preUpdateMessageCache = (rawPayload) => {
|
|
21514
|
+
ingestInCache({
|
|
21515
|
+
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
21516
|
+
});
|
|
21517
|
+
};
|
|
21518
|
+
const DEBOUNCE_TIME = 2000;
|
|
21519
|
+
const currentDebounceMap = {};
|
|
21520
|
+
const prepareMessagePayload = async (payload, event) => {
|
|
21521
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
21522
|
+
if (markerIds.length > 0) {
|
|
21523
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21524
|
+
preUpdateMessageCache(payload);
|
|
21525
|
+
const markerIdsKey = markerIds.join('');
|
|
21526
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
21527
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
21528
|
+
}
|
|
21529
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
21530
|
+
try {
|
|
21531
|
+
getMessageMarkers(markerIds);
|
|
21532
|
+
}
|
|
21533
|
+
catch (_error) {
|
|
21534
|
+
// do nothing
|
|
21535
|
+
}
|
|
21536
|
+
}, DEBOUNCE_TIME);
|
|
21537
|
+
}
|
|
21538
|
+
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
21539
|
+
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
21540
|
+
if (messageFeeds && messageFeeds.length > 0) {
|
|
21541
|
+
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
21542
|
+
var _a, _b;
|
|
21543
|
+
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
21544
|
+
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
21545
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
21546
|
+
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
21547
|
+
});
|
|
21548
|
+
}
|
|
21549
|
+
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
21550
|
+
};
|
|
21551
|
+
function convertParams(_a) {
|
|
21552
|
+
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
21553
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
21554
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
21555
|
+
}
|
|
21556
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
21557
|
+
}
|
|
21558
|
+
function convertQueryParams$1(_a) {
|
|
21559
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
21560
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
21561
|
+
sortBy,
|
|
21562
|
+
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
21563
|
+
around: aroundMessageId,
|
|
21564
|
+
} });
|
|
21565
|
+
if (includingTags) {
|
|
21566
|
+
out.includeTags = includingTags;
|
|
21567
|
+
}
|
|
21568
|
+
if (type) {
|
|
21569
|
+
out.dataType = type;
|
|
21570
|
+
}
|
|
21571
|
+
if (excludingTags) {
|
|
21572
|
+
out.excludeTags = excludingTags;
|
|
21573
|
+
}
|
|
21574
|
+
return out;
|
|
21575
|
+
}
|
|
21576
|
+
|
|
21577
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
21578
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
21579
|
+
}
|
|
21580
|
+
|
|
21581
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21582
|
+
/**
|
|
21583
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
21584
|
+
*/
|
|
21585
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
21586
|
+
const preUpdateSubChannelCache = (rawPayload) => {
|
|
21587
|
+
ingestInCache({
|
|
21588
|
+
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
21589
|
+
});
|
|
21590
|
+
};
|
|
21591
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
21592
|
+
const markerIds = rawPayload.messageFeeds
|
|
21593
|
+
.filter(isUnreadCountSupport$1)
|
|
21594
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
21595
|
+
if (markerIds.length > 0) {
|
|
21596
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21597
|
+
preUpdateSubChannelCache(rawPayload);
|
|
21598
|
+
try {
|
|
21599
|
+
await getSubChannelMarkers(markerIds);
|
|
21600
|
+
}
|
|
21601
|
+
catch (e) {
|
|
21602
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21603
|
+
}
|
|
21604
|
+
}
|
|
21605
|
+
updateSubChannelMessagePreviewCache(rawPayload);
|
|
21606
|
+
// attach marker to sub channel
|
|
21607
|
+
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
21608
|
+
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
21609
|
+
const user = rawPayload.users.map(convertRawUserToInternalUser);
|
|
21610
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
21611
|
+
messages, users: user });
|
|
21612
|
+
};
|
|
21613
|
+
function convertQueryParams(_a) {
|
|
21614
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
21615
|
+
const out = Object.assign({}, rest);
|
|
21616
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
21617
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
21618
|
+
}
|
|
21619
|
+
return out;
|
|
21620
|
+
}
|
|
21621
|
+
|
|
21622
|
+
/**
|
|
21623
|
+
* ```js
|
|
21624
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21625
|
+
* const subChannel = await getSubChannel('foobar')
|
|
21626
|
+
* ```
|
|
21627
|
+
*
|
|
21628
|
+
* Fetches a {@link Amity.SubChannel} object
|
|
21629
|
+
*
|
|
21630
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21631
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21632
|
+
*
|
|
21633
|
+
* @category Channel API
|
|
21634
|
+
* @async
|
|
21635
|
+
*/
|
|
21636
|
+
const getSubChannel$1 = async (subChannelId) => {
|
|
21637
|
+
const client = getActiveClient();
|
|
21638
|
+
client.log('channel/getSubChannel', subChannelId);
|
|
21639
|
+
isInTombstone('subChannel', subChannelId);
|
|
21640
|
+
try {
|
|
21641
|
+
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
21642
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
21643
|
+
const cachedAt = client.cache && Date.now();
|
|
21644
|
+
if (client.cache)
|
|
21645
|
+
ingestInCache(data, { cachedAt });
|
|
21646
|
+
fireEvent('local.message-feed.fetched', data);
|
|
21647
|
+
return {
|
|
21648
|
+
data: data.messageFeeds[0],
|
|
21649
|
+
cachedAt,
|
|
21650
|
+
};
|
|
21651
|
+
}
|
|
21652
|
+
catch (error) {
|
|
21653
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
21654
|
+
pushToTombstone('subChannel', subChannelId);
|
|
21655
|
+
}
|
|
21656
|
+
throw error;
|
|
21657
|
+
}
|
|
21658
|
+
};
|
|
21659
|
+
/**
|
|
21660
|
+
* ```js
|
|
21661
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21662
|
+
* const subChannel = getSubChannel.locally('foobar')
|
|
21663
|
+
* ```
|
|
21664
|
+
*
|
|
21665
|
+
* Fetches a {@link Amity.SubChannel} object from cache
|
|
21666
|
+
*
|
|
21667
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21668
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21669
|
+
*
|
|
21670
|
+
* @category Channel API
|
|
21671
|
+
*/
|
|
21672
|
+
getSubChannel$1.locally = (subChannelId) => {
|
|
21673
|
+
const client = getActiveClient();
|
|
21674
|
+
client.log('channel/getSubChannel.locally', subChannelId);
|
|
21675
|
+
if (!client.cache)
|
|
21676
|
+
return;
|
|
21677
|
+
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
21678
|
+
if (!cached)
|
|
21679
|
+
return;
|
|
21680
|
+
return {
|
|
21681
|
+
data: cached.data,
|
|
21682
|
+
cachedAt: cached.cachedAt,
|
|
21683
|
+
};
|
|
21684
|
+
};
|
|
21685
|
+
|
|
21686
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
21687
|
+
return new Date(dateString).getTime();
|
|
21688
|
+
};
|
|
21689
|
+
|
|
21690
|
+
const getMessagePreviewSetting$1 = async () => {
|
|
21691
|
+
const client = getActiveClient();
|
|
21692
|
+
return client.getMessagePreviewSetting(false);
|
|
21693
|
+
};
|
|
21694
|
+
const getSubChannelCache = async (subChannelId) => {
|
|
21695
|
+
var _a;
|
|
21696
|
+
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21697
|
+
if (!subChannelCache) {
|
|
21698
|
+
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
21699
|
+
}
|
|
21700
|
+
return subChannelCache;
|
|
21701
|
+
};
|
|
21702
|
+
const isLastestMessageOnSubchannel = (message) => {
|
|
21703
|
+
var _a;
|
|
21704
|
+
const cache = (_a = pullFromCache([
|
|
21705
|
+
'messagePreviewSubChannel',
|
|
21706
|
+
'get',
|
|
21707
|
+
message.subChannelId,
|
|
21708
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21709
|
+
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
21710
|
+
return (!cache ||
|
|
21711
|
+
cache.segment <= message.channelSegment ||
|
|
21712
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21713
|
+
};
|
|
21714
|
+
const isLastestMessageOnChannel = (message) => {
|
|
21715
|
+
var _a;
|
|
21716
|
+
const cache = (_a = pullFromCache([
|
|
21717
|
+
'messagePreviewChannel',
|
|
21718
|
+
'get',
|
|
21719
|
+
message.channelId,
|
|
21720
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21721
|
+
return (!cache ||
|
|
21722
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21723
|
+
};
|
|
21724
|
+
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
21725
|
+
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
21726
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21727
|
+
// 1. get subChannel from cache, if not exist fetch from server
|
|
21728
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21729
|
+
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
21730
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
21731
|
+
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
21732
|
+
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
21733
|
+
convertDateStringToTimestamp(createdAt))
|
|
21734
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21735
|
+
lastActivity: createdAt,
|
|
21736
|
+
});
|
|
21737
|
+
return;
|
|
21738
|
+
}
|
|
21739
|
+
// 3. if messagePreviewSetting is `NOT` NO_MESSAGE_PREVEIW, update messagePreviewSubChannel and subChannel cache
|
|
21740
|
+
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
21741
|
+
if (!isLastestMessageOnSubchannel(message))
|
|
21742
|
+
return;
|
|
21743
|
+
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
21744
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21745
|
+
channelId,
|
|
21746
|
+
creatorId,
|
|
21747
|
+
messagePreviewId,
|
|
21748
|
+
createdAt,
|
|
21749
|
+
updatedAt,
|
|
21750
|
+
subChannelId,
|
|
21751
|
+
data,
|
|
21752
|
+
dataType,
|
|
21753
|
+
segment,
|
|
21754
|
+
isDeleted,
|
|
21755
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21756
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21757
|
+
});
|
|
21758
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21759
|
+
lastActivity: createdAt,
|
|
21760
|
+
messagePreviewId,
|
|
21761
|
+
});
|
|
21762
|
+
};
|
|
21763
|
+
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
21764
|
+
var _a;
|
|
21765
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21766
|
+
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
21767
|
+
'messagePreviewSubChannel',
|
|
21768
|
+
'get',
|
|
21769
|
+
message.subChannelId,
|
|
21770
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21771
|
+
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
21772
|
+
if (messagePreviewSubChannelCache &&
|
|
21773
|
+
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
21774
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21775
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21776
|
+
channelId,
|
|
21777
|
+
creatorId,
|
|
21778
|
+
messagePreviewId,
|
|
21779
|
+
createdAt,
|
|
21780
|
+
updatedAt,
|
|
21781
|
+
subChannelId,
|
|
21782
|
+
data,
|
|
21783
|
+
dataType,
|
|
21784
|
+
segment,
|
|
21785
|
+
isDeleted,
|
|
21786
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21787
|
+
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
21788
|
+
});
|
|
21789
|
+
}
|
|
21790
|
+
};
|
|
21791
|
+
const handleMessageCreated = async (message) => {
|
|
21792
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21793
|
+
if (isLastestMessageOnChannel(message)) {
|
|
21794
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21795
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21796
|
+
channelId,
|
|
21797
|
+
creatorId,
|
|
21798
|
+
messagePreviewId,
|
|
21799
|
+
createdAt,
|
|
21800
|
+
updatedAt,
|
|
21801
|
+
subChannelId,
|
|
21802
|
+
data,
|
|
21803
|
+
dataType,
|
|
21804
|
+
segment,
|
|
21805
|
+
isDeleted,
|
|
21806
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21807
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21808
|
+
});
|
|
21809
|
+
}
|
|
21810
|
+
};
|
|
21811
|
+
const handleMessageUpdated = async (message) => {
|
|
21812
|
+
/**
|
|
21813
|
+
* Channel Case
|
|
21814
|
+
*/
|
|
21815
|
+
var _a;
|
|
21816
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21817
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21818
|
+
'messagePreviewChannel',
|
|
21819
|
+
'get',
|
|
21820
|
+
message.channelId,
|
|
21821
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21822
|
+
if (messagePreviewChannelCache &&
|
|
21823
|
+
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
21824
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21825
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21826
|
+
channelId,
|
|
21827
|
+
creatorId,
|
|
21828
|
+
messagePreviewId,
|
|
21829
|
+
createdAt,
|
|
21830
|
+
updatedAt,
|
|
21831
|
+
subChannelId,
|
|
21832
|
+
data,
|
|
21833
|
+
dataType,
|
|
21834
|
+
segment,
|
|
21835
|
+
isDeleted,
|
|
21836
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21837
|
+
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
21838
|
+
});
|
|
21839
|
+
}
|
|
21840
|
+
};
|
|
21841
|
+
const handleSubChannelUpdated = async (subChannel) => {
|
|
21842
|
+
var _a, _b, _c, _d;
|
|
21843
|
+
const { channelId, subChannelId } = subChannel;
|
|
21844
|
+
/** Channel Case */
|
|
21845
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21846
|
+
'messagePreviewChannel',
|
|
21847
|
+
'get',
|
|
21848
|
+
channelId,
|
|
21849
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21850
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
21851
|
+
const subChannelCache = (_b = pullFromCache([
|
|
21852
|
+
'subChannel',
|
|
21853
|
+
'get',
|
|
21854
|
+
subChannelId,
|
|
21855
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21856
|
+
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 }));
|
|
21857
|
+
}
|
|
21858
|
+
/** SubChannel Case */
|
|
21859
|
+
const messagePreviewSubChannelCache = (_c = pullFromCache([
|
|
21860
|
+
'messagePreviewSubChannel',
|
|
21861
|
+
'get',
|
|
21862
|
+
subChannelId,
|
|
21863
|
+
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
21864
|
+
if (messagePreviewSubChannelCache &&
|
|
21865
|
+
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
21866
|
+
new Date(subChannel.updatedAt).valueOf()) {
|
|
21867
|
+
const subChannelCache = (_d = pullFromCache([
|
|
21868
|
+
'subChannel',
|
|
21869
|
+
'get',
|
|
21870
|
+
subChannelId,
|
|
21871
|
+
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
21872
|
+
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 }));
|
|
21873
|
+
}
|
|
21874
|
+
};
|
|
21875
|
+
|
|
21876
|
+
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21877
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
21878
|
+
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
21879
|
+
var _a;
|
|
21880
|
+
let { messagePreviewId } = channel;
|
|
21881
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21882
|
+
'messagePreviewChannel',
|
|
21883
|
+
'get',
|
|
21884
|
+
channel.channelId,
|
|
21885
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21886
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
21887
|
+
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
21888
|
+
}
|
|
21889
|
+
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
21890
|
+
}
|
|
21891
|
+
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21892
|
+
ingestInCache({
|
|
21893
|
+
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
21894
|
+
});
|
|
21895
|
+
};
|
|
21896
|
+
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
21897
|
+
for (let i = 0; i < channels.length; i += 1) {
|
|
21898
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
21899
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
21900
|
+
let unreadCount = 0;
|
|
21901
|
+
let readToSegment = null;
|
|
21902
|
+
let lastMentionedSegment = null;
|
|
21903
|
+
let isMentioned = false;
|
|
21904
|
+
if (channelUser) {
|
|
21905
|
+
readToSegment = channelUser.readToSegment;
|
|
21906
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
21907
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
21908
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
21909
|
+
}
|
|
21910
|
+
const cacheChannelUnread = {
|
|
21911
|
+
channelId: channels[i].channelId,
|
|
21912
|
+
lastSegment: channels[i].messageCount,
|
|
21913
|
+
readToSegment,
|
|
21914
|
+
lastMentionedSegment,
|
|
21915
|
+
unreadCount,
|
|
21916
|
+
isMentioned,
|
|
21917
|
+
isDeleted: channels[i].isDeleted || false,
|
|
21918
|
+
};
|
|
21919
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
21920
|
+
}
|
|
21921
|
+
};
|
|
21922
|
+
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21923
|
+
const client = getActiveClient();
|
|
21924
|
+
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
21925
|
+
if (options.isMessagePreviewUpdated &&
|
|
21926
|
+
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
21927
|
+
rawPayload.messagePreviews &&
|
|
21928
|
+
rawPayload.messagePreviews.length > 0) {
|
|
21929
|
+
updateChannelMessagePreviewCache(rawPayload);
|
|
21930
|
+
}
|
|
21931
|
+
if (client.useLegacyUnreadCount) {
|
|
21932
|
+
updateChannelUnread({
|
|
21933
|
+
channels: rawPayload.channels,
|
|
21934
|
+
channelUsers: rawPayload.channelUsers,
|
|
21935
|
+
currentUserId: client.userId,
|
|
21936
|
+
});
|
|
21937
|
+
}
|
|
21938
|
+
else {
|
|
21939
|
+
const markerIds = rawPayload.channels
|
|
21940
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
21941
|
+
.filter(isUnreadCountSupport)
|
|
21942
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
21943
|
+
if (markerIds.length > 0) {
|
|
21944
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21945
|
+
preUpdateChannelCache(rawPayload, {
|
|
21946
|
+
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
21947
|
+
});
|
|
21948
|
+
try {
|
|
21949
|
+
await getChannelMarkers(markerIds);
|
|
21950
|
+
}
|
|
21951
|
+
catch (e) {
|
|
21952
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21953
|
+
}
|
|
21954
|
+
}
|
|
21955
|
+
}
|
|
21956
|
+
// convert raw channel to internal channel
|
|
21957
|
+
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
21958
|
+
// convert raw channel user to membership (add user object)
|
|
21959
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
21960
|
+
return convertRawMembershipToMembership(channelUser);
|
|
21961
|
+
});
|
|
21962
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
21963
|
+
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
21964
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
21965
|
+
channels,
|
|
21966
|
+
channelUsers });
|
|
21967
|
+
};
|
|
21968
|
+
|
|
21969
|
+
/**
|
|
21970
|
+
* ```js
|
|
21971
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21972
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21973
|
+
* ```
|
|
21974
|
+
*
|
|
21975
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21976
|
+
*
|
|
21977
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21978
|
+
* @param page
|
|
21979
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21980
|
+
*
|
|
21981
|
+
* @category Channel API
|
|
21982
|
+
* @async
|
|
21983
|
+
* @private
|
|
21984
|
+
*/
|
|
21985
|
+
const getUserMessageFeedMakers = async (channelIds) => {
|
|
21986
|
+
const client = getActiveClient();
|
|
21987
|
+
client.log('channel/getUserMessageFeedMakers', channelIds);
|
|
21988
|
+
const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
|
|
21989
|
+
params: {
|
|
21990
|
+
channelIds,
|
|
21991
|
+
},
|
|
21992
|
+
});
|
|
21993
|
+
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
21994
|
+
return data;
|
|
21995
|
+
};
|
|
21996
|
+
|
|
21997
|
+
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
21998
|
+
const client = getActiveClient();
|
|
21999
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
22000
|
+
// Marker service API uses channelInternalId as channelId
|
|
22001
|
+
const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
|
|
22002
|
+
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
22003
|
+
persistUnreadCountInfo({
|
|
22004
|
+
feedMarkers,
|
|
22005
|
+
userFeedMarkers,
|
|
22006
|
+
});
|
|
22007
|
+
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
22008
|
+
};
|
|
22009
|
+
|
|
22010
|
+
const getCachedMarker$2 = (entityId) => {
|
|
22011
|
+
var _a;
|
|
22012
|
+
const key = {
|
|
22013
|
+
entityId,
|
|
22014
|
+
userId: getActiveUser()._id,
|
|
22015
|
+
};
|
|
22016
|
+
return (_a = pullFromCache([
|
|
22017
|
+
'channelMarker',
|
|
22018
|
+
'get',
|
|
22019
|
+
getResolver('channelMarker')(key),
|
|
22020
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22021
|
+
};
|
|
22022
|
+
const getUnreadInfoCached$1 = (channelId) => {
|
|
22023
|
+
var _a;
|
|
22024
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22025
|
+
};
|
|
22026
|
+
/**
|
|
22027
|
+
* The function use to get value of hasMentioned or isMentioned field.
|
|
22028
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22029
|
+
*
|
|
22030
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22031
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22032
|
+
* If not found in the both cache, use `false` as defaul value.
|
|
22033
|
+
*/
|
|
22034
|
+
const getChannelIsMentioned = (channel, marker) => {
|
|
22035
|
+
var _a, _b, _c, _d;
|
|
22036
|
+
const client = getActiveClient();
|
|
22037
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22038
|
+
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22039
|
+
}
|
|
22040
|
+
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
22041
|
+
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
22042
|
+
: (_d = (_c = getCachedMarker$2(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22043
|
+
};
|
|
22044
|
+
|
|
22045
|
+
const getCachedMarker$1 = (entityId) => {
|
|
22046
|
+
var _a;
|
|
22047
|
+
const key = {
|
|
22048
|
+
entityId,
|
|
22049
|
+
userId: getActiveUser()._id,
|
|
22050
|
+
};
|
|
22051
|
+
return (_a = pullFromCache([
|
|
22052
|
+
'channelMarker',
|
|
22053
|
+
'get',
|
|
22054
|
+
getResolver('channelMarker')(key),
|
|
22055
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22056
|
+
};
|
|
22057
|
+
const getUnreadInfoCached = (channelId) => {
|
|
22058
|
+
var _a;
|
|
22059
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22060
|
+
};
|
|
22061
|
+
/**
|
|
22062
|
+
* The function use to get value of unreadCount field.
|
|
22063
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22064
|
+
*
|
|
22065
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22066
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22067
|
+
* If not found in the both cache, use `0` as defaul value.
|
|
22068
|
+
*/
|
|
22069
|
+
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
22070
|
+
var _a, _b, _c, _d, _e;
|
|
22071
|
+
const client = getActiveClient();
|
|
22072
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22073
|
+
// Marker service API uses channelInternalId as channelId
|
|
22074
|
+
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22075
|
+
}
|
|
22076
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
22077
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
22078
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
22079
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
22080
|
+
return 0;
|
|
22081
|
+
}
|
|
22082
|
+
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;
|
|
22083
|
+
};
|
|
22084
|
+
|
|
22085
|
+
const getLegacyChannelUnread = (channelId) => {
|
|
22086
|
+
var _a;
|
|
22087
|
+
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22088
|
+
};
|
|
22089
|
+
|
|
22090
|
+
const constructChannelDynamicValue = (channel) => {
|
|
22091
|
+
const client = getActiveClient();
|
|
22092
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
22093
|
+
return shallowClone(rest, {
|
|
22094
|
+
get unreadCount() {
|
|
22095
|
+
var _a, _b;
|
|
22096
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22097
|
+
},
|
|
22098
|
+
get subChannelsUnreadCount() {
|
|
22099
|
+
return getSubChannelsUnreadCount(rest);
|
|
22100
|
+
},
|
|
22101
|
+
get isMentioned() {
|
|
22102
|
+
var _a, _b;
|
|
22103
|
+
if (client.useLegacyUnreadCount)
|
|
22104
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22105
|
+
return getChannelIsMentioned(rest);
|
|
22106
|
+
},
|
|
22107
|
+
});
|
|
22108
|
+
};
|
|
22109
|
+
|
|
20993
22110
|
const ANALYTIC_CACHE_KEY = ['analytic', 'normal-priority'];
|
|
20994
22111
|
const HIGH_PRIORITY_ANALYTIC_CACHE_KEY = ['analytic', 'high-priority'];
|
|
20995
22112
|
|
|
@@ -21289,20 +22406,6 @@ var AnalyticsEngine$1 = {
|
|
|
21289
22406
|
},
|
|
21290
22407
|
};
|
|
21291
22408
|
|
|
21292
|
-
const userLinkedObject = (user) => {
|
|
21293
|
-
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
21294
|
-
var _a;
|
|
21295
|
-
if (!user.avatarFileId)
|
|
21296
|
-
return undefined;
|
|
21297
|
-
const avatar = (_a = pullFromCache([
|
|
21298
|
-
'file',
|
|
21299
|
-
'get',
|
|
21300
|
-
`${user.avatarFileId}`,
|
|
21301
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21302
|
-
return avatar;
|
|
21303
|
-
} });
|
|
21304
|
-
};
|
|
21305
|
-
|
|
21306
22409
|
class StoryComputedValue {
|
|
21307
22410
|
constructor(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt) {
|
|
21308
22411
|
this._syncingStoriesCount = 0;
|
|
@@ -21734,7 +22837,7 @@ const postLinkedObject = (post) => {
|
|
|
21734
22837
|
} });
|
|
21735
22838
|
};
|
|
21736
22839
|
|
|
21737
|
-
const getCachedMarker
|
|
22840
|
+
const getCachedMarker = (message) => {
|
|
21738
22841
|
var _a, _b;
|
|
21739
22842
|
const key = {
|
|
21740
22843
|
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
@@ -21752,7 +22855,7 @@ const getMessageReadCount = (message, marker) => {
|
|
|
21752
22855
|
// Look in the marker param first
|
|
21753
22856
|
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
21754
22857
|
// If the marker param is not set, look in the cache
|
|
21755
|
-
getCachedMarker
|
|
22858
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
21756
22859
|
}; // and if not found in cache use default value `0`
|
|
21757
22860
|
|
|
21758
22861
|
/**
|
|
@@ -21995,31 +23098,6 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
21995
23098
|
}
|
|
21996
23099
|
};
|
|
21997
23100
|
|
|
21998
|
-
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21999
|
-
var _a;
|
|
22000
|
-
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
22001
|
-
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22002
|
-
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
22003
|
-
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
22004
|
-
let channelUnreads = 0;
|
|
22005
|
-
let isMentioned = false;
|
|
22006
|
-
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
22007
|
-
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
22008
|
-
return data.channelId === channelId && !data.isDeleted;
|
|
22009
|
-
});
|
|
22010
|
-
channelUnreads = subChannelUnreadsInfo
|
|
22011
|
-
.map(({ data }) => data.unreadCount)
|
|
22012
|
-
.reduce((acc, cur) => acc + cur, 0);
|
|
22013
|
-
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
22014
|
-
}
|
|
22015
|
-
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
22016
|
-
channelId,
|
|
22017
|
-
createdAt: new Date().toISOString(),
|
|
22018
|
-
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
22019
|
-
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
22020
|
-
return channelUnreadInfo;
|
|
22021
|
-
};
|
|
22022
|
-
|
|
22023
23101
|
class LegacyMessageReadReceiptSyncEngine {
|
|
22024
23102
|
constructor() {
|
|
22025
23103
|
this.isActive = true;
|
|
@@ -22305,24 +23383,6 @@ const markAsRead = async (channelId) => {
|
|
|
22305
23383
|
return true;
|
|
22306
23384
|
};
|
|
22307
23385
|
|
|
22308
|
-
/**
|
|
22309
|
-
* ```js
|
|
22310
|
-
* import { shallowClone } from '~/utils/shallowClone'
|
|
22311
|
-
* const newObj = shallowClone(obj)
|
|
22312
|
-
* ```
|
|
22313
|
-
*
|
|
22314
|
-
* Clone an object with same prototype and properties
|
|
22315
|
-
*
|
|
22316
|
-
* @param obj the object to clone
|
|
22317
|
-
* @returns new object with same prototype and properties
|
|
22318
|
-
*
|
|
22319
|
-
* @category utility
|
|
22320
|
-
* @private
|
|
22321
|
-
*/
|
|
22322
|
-
function shallowClone(source, target) {
|
|
22323
|
-
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
22324
|
-
}
|
|
22325
|
-
|
|
22326
23386
|
const channelLinkedObject = (channel) => {
|
|
22327
23387
|
return shallowClone(channel, {
|
|
22328
23388
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
@@ -22402,1224 +23462,1281 @@ const notificationTrayLinkedObject = (noti) => {
|
|
|
22402
23462
|
.map(user => userLinkedObject(user)) });
|
|
22403
23463
|
};
|
|
22404
23464
|
|
|
22405
|
-
/*
|
|
22406
|
-
|
|
22407
|
-
*/
|
|
22408
|
-
/**
|
|
22409
|
-
* ```js
|
|
22410
|
-
* import { createInvitations } from '@amityco/ts-sdk'
|
|
22411
|
-
* const created = await createInvitations({
|
|
22412
|
-
* type: string,
|
|
22413
|
-
* targetType: string,
|
|
22414
|
-
* targetId: string,
|
|
22415
|
-
* userIds: string[]
|
|
22416
|
-
* }))
|
|
22417
|
-
* ```
|
|
22418
|
-
*
|
|
22419
|
-
* Creates an {@link Amity.Invitation}
|
|
22420
|
-
*
|
|
22421
|
-
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
22422
|
-
* @returns The newly created {@link Amity.Invitation}
|
|
22423
|
-
*
|
|
22424
|
-
* @category Invitation API
|
|
22425
|
-
* @async
|
|
23465
|
+
/*
|
|
23466
|
+
* verifies membership status
|
|
22426
23467
|
*/
|
|
22427
|
-
|
|
22428
|
-
|
|
22429
|
-
|
|
22430
|
-
|
|
22431
|
-
|
|
22432
|
-
|
|
22433
|
-
|
|
22434
|
-
|
|
22435
|
-
return
|
|
22436
|
-
|
|
22437
|
-
|
|
22438
|
-
|
|
22439
|
-
|
|
22440
|
-
/* end_public_function */
|
|
22441
|
-
|
|
22442
|
-
/* begin_public_function
|
|
22443
|
-
id: invitation.accept
|
|
22444
|
-
*/
|
|
22445
|
-
/**
|
|
22446
|
-
* ```js
|
|
22447
|
-
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
22448
|
-
* const isAccepted = await acceptInvitation(invitationId)
|
|
22449
|
-
* ```
|
|
22450
|
-
*
|
|
22451
|
-
* Accepts a {@link Amity.Invitation} object
|
|
22452
|
-
*
|
|
22453
|
-
* @param invitationId the {@link Amity.Invitation} to accept
|
|
22454
|
-
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
23468
|
+
function isMember(membership) {
|
|
23469
|
+
return membership !== 'none';
|
|
23470
|
+
}
|
|
23471
|
+
/*
|
|
23472
|
+
* checks if currently logged in user is part of the community
|
|
23473
|
+
*/
|
|
23474
|
+
function isCurrentUserPartOfCommunity(c, m) {
|
|
23475
|
+
const { userId } = getActiveUser();
|
|
23476
|
+
return c.communityId === m.communityId && m.userId === userId;
|
|
23477
|
+
}
|
|
23478
|
+
/*
|
|
23479
|
+
* For mqtt events server will not send user specific data as it's broadcasted
|
|
23480
|
+
* to multiple users and it also does not include communityUser
|
|
22455
23481
|
*
|
|
22456
|
-
*
|
|
22457
|
-
*
|
|
23482
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
23483
|
+
* Althought this can be calculated, it's not scalable.
|
|
22458
23484
|
*/
|
|
22459
|
-
|
|
23485
|
+
function updateMembershipStatus(communities, communityUsers) {
|
|
23486
|
+
return communities.map(c => {
|
|
23487
|
+
const cachedCommunity = pullFromCache([
|
|
23488
|
+
'community',
|
|
23489
|
+
'get',
|
|
23490
|
+
c.communityId,
|
|
23491
|
+
]);
|
|
23492
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
23493
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
23494
|
+
}
|
|
23495
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
23496
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
23497
|
+
});
|
|
23498
|
+
}
|
|
23499
|
+
|
|
23500
|
+
const getMatchPostSetting = (value) => {
|
|
22460
23501
|
var _a;
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
const invitation = (_a = pullFromCache([
|
|
22465
|
-
'invitation',
|
|
22466
|
-
'get',
|
|
22467
|
-
invitationId,
|
|
22468
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22469
|
-
if (invitation) {
|
|
22470
|
-
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
22471
|
-
fireEvent('local.invitation.updated', { invitations: [invitation] });
|
|
22472
|
-
}
|
|
22473
|
-
return data.success;
|
|
23502
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
23503
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
23504
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
22474
23505
|
};
|
|
22475
|
-
|
|
23506
|
+
function addPostSetting({ communities }) {
|
|
23507
|
+
return communities.map((_a) => {
|
|
23508
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
23509
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
23510
|
+
needApprovalOnPostCreation,
|
|
23511
|
+
onlyAdminCanPost,
|
|
23512
|
+
}) }, restCommunityPayload));
|
|
23513
|
+
});
|
|
23514
|
+
}
|
|
23515
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
23516
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
23517
|
+
// Convert users to internal format
|
|
23518
|
+
const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
|
|
23519
|
+
// map users with community
|
|
23520
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
23521
|
+
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
23522
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
23523
|
+
});
|
|
23524
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
23525
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
23526
|
+
};
|
|
23527
|
+
const prepareCommunityJoinRequestPayload = (rawPayload) => {
|
|
23528
|
+
const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
|
|
23529
|
+
return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
|
|
23530
|
+
});
|
|
23531
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
23532
|
+
return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
|
|
23533
|
+
};
|
|
23534
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
23535
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
23536
|
+
// map users with community
|
|
23537
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
23538
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
23539
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
23540
|
+
});
|
|
23541
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
23542
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
23543
|
+
};
|
|
23544
|
+
const prepareCommunityRequest = (params) => {
|
|
23545
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
23546
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
23547
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
23548
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
23549
|
+
};
|
|
23550
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
23551
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
23552
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
23553
|
+
return Object.assign({}, processedCommunityPayload);
|
|
23554
|
+
};
|
|
22476
23555
|
|
|
22477
23556
|
/* begin_public_function
|
|
22478
|
-
id:
|
|
23557
|
+
id: joinRequest.approve
|
|
22479
23558
|
*/
|
|
22480
23559
|
/**
|
|
22481
23560
|
* ```js
|
|
22482
|
-
* import {
|
|
22483
|
-
* const
|
|
23561
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23562
|
+
* const isAccepted = await joinRequest.approve()
|
|
22484
23563
|
* ```
|
|
22485
23564
|
*
|
|
22486
|
-
*
|
|
23565
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
22487
23566
|
*
|
|
22488
|
-
* @param
|
|
22489
|
-
* @returns A success boolean if the {@link Amity.
|
|
23567
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
23568
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
22490
23569
|
*
|
|
22491
|
-
* @category
|
|
23570
|
+
* @category Join Request API
|
|
22492
23571
|
* @async
|
|
22493
23572
|
*/
|
|
22494
|
-
const
|
|
23573
|
+
const approveJoinRequest = async (joinRequest) => {
|
|
22495
23574
|
var _a;
|
|
22496
23575
|
const client = getActiveClient();
|
|
22497
|
-
client.log('
|
|
22498
|
-
const { data } = await client.http.post(`/api/
|
|
22499
|
-
|
|
22500
|
-
|
|
23576
|
+
client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
|
|
23577
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
|
|
23578
|
+
userId: joinRequest.requestorInternalId,
|
|
23579
|
+
});
|
|
23580
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23581
|
+
'joinRequest',
|
|
22501
23582
|
'get',
|
|
22502
|
-
|
|
23583
|
+
joinRequest.joinRequestId,
|
|
22503
23584
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22504
|
-
if (
|
|
22505
|
-
upsertInCache(['
|
|
22506
|
-
|
|
23585
|
+
if (joinRequestCache) {
|
|
23586
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23587
|
+
status: "approved" /* JoinRequestStatusEnum.Approved */,
|
|
23588
|
+
});
|
|
23589
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
22507
23590
|
}
|
|
22508
23591
|
return data.success;
|
|
22509
23592
|
};
|
|
22510
23593
|
/* end_public_function */
|
|
22511
23594
|
|
|
22512
23595
|
/* begin_public_function
|
|
22513
|
-
id:
|
|
23596
|
+
id: joinRequest.cancel
|
|
22514
23597
|
*/
|
|
22515
23598
|
/**
|
|
22516
23599
|
* ```js
|
|
22517
|
-
* import {
|
|
22518
|
-
* const isCanceled = await
|
|
23600
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23601
|
+
* const isCanceled = await joinRequest.cancel()
|
|
22519
23602
|
* ```
|
|
22520
23603
|
*
|
|
22521
|
-
* Cancels a {@link Amity.
|
|
23604
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
22522
23605
|
*
|
|
22523
|
-
* @param
|
|
22524
|
-
* @returns A success boolean if the {@link Amity.
|
|
23606
|
+
* @param joinRequest the {@link Amity.JoinRequest} to cancel
|
|
23607
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was canceled
|
|
22525
23608
|
*
|
|
22526
|
-
* @category
|
|
23609
|
+
* @category Join Request API
|
|
22527
23610
|
* @async
|
|
22528
23611
|
*/
|
|
22529
|
-
const
|
|
22530
|
-
var _a;
|
|
22531
|
-
const client = getActiveClient();
|
|
22532
|
-
client.log('invitation/cancelInvitation', invitationId);
|
|
22533
|
-
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
22534
|
-
const invitation = (_a = pullFromCache([
|
|
22535
|
-
'invitation',
|
|
22536
|
-
'get',
|
|
22537
|
-
invitationId,
|
|
22538
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22539
|
-
if (invitation) {
|
|
22540
|
-
dropFromCache(['invitation', 'get', invitationId]);
|
|
22541
|
-
fireEvent('local.invitation.deleted', { invitations: [invitation] });
|
|
22542
|
-
}
|
|
22543
|
-
return data.success;
|
|
22544
|
-
};
|
|
22545
|
-
/* end_public_function */
|
|
22546
|
-
|
|
22547
|
-
const communityLinkedObject = (community) => {
|
|
22548
|
-
return Object.assign(Object.assign({}, community), { createInvitations: async (userIds) => {
|
|
22549
|
-
await createInvitations({
|
|
22550
|
-
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
22551
|
-
targetType: 'community',
|
|
22552
|
-
targetId: community.communityId,
|
|
22553
|
-
userIds,
|
|
22554
|
-
});
|
|
22555
|
-
} });
|
|
22556
|
-
};
|
|
22557
|
-
|
|
22558
|
-
const invitationLinkedObject = (invitation) => {
|
|
22559
|
-
return Object.assign(Object.assign({}, invitation), { accept: async () => {
|
|
22560
|
-
await acceptInvitation(invitation._id);
|
|
22561
|
-
}, reject: async () => {
|
|
22562
|
-
await rejectInvitation(invitation._id);
|
|
22563
|
-
}, cancel: async () => {
|
|
22564
|
-
await cancelInvitation(invitation._id);
|
|
22565
|
-
} });
|
|
22566
|
-
};
|
|
22567
|
-
|
|
22568
|
-
const LinkedObject = {
|
|
22569
|
-
ad: adLinkedObject,
|
|
22570
|
-
comment: commentLinkedObject,
|
|
22571
|
-
post: postLinkedObject,
|
|
22572
|
-
user: userLinkedObject,
|
|
22573
|
-
category: categoryLinkedObject,
|
|
22574
|
-
stream: streamLinkedObject,
|
|
22575
|
-
story: storyLinkedObject,
|
|
22576
|
-
storyTarget: storyTargetLinkedObject,
|
|
22577
|
-
message: messageLinkedObject,
|
|
22578
|
-
reactor: reactorLinkedObject,
|
|
22579
|
-
channel: channelLinkedObject,
|
|
22580
|
-
pinnedPost: pinnedPostLinkedObject,
|
|
22581
|
-
notificationTray: notificationTrayLinkedObject,
|
|
22582
|
-
community: communityLinkedObject,
|
|
22583
|
-
invitation: invitationLinkedObject,
|
|
22584
|
-
};
|
|
22585
|
-
|
|
22586
|
-
const getChannelMessagePreviewWithUser = (channel) => {
|
|
23612
|
+
const cancelJoinRequest = async (joinRequest) => {
|
|
22587
23613
|
var _a;
|
|
22588
|
-
const messagePreview = channel.messagePreviewId
|
|
22589
|
-
? getChannelMessagePreview(channel.channelId)
|
|
22590
|
-
: null;
|
|
22591
|
-
const internalUser = (_a = pullFromCache([
|
|
22592
|
-
'user',
|
|
22593
|
-
'get',
|
|
22594
|
-
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
22595
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22596
|
-
const messagePreviewWithUser = messagePreview
|
|
22597
|
-
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? LinkedObject.user(internalUser) : undefined }) : null;
|
|
22598
|
-
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
22599
|
-
};
|
|
22600
|
-
|
|
22601
|
-
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
22602
|
-
var _a, _b;
|
|
22603
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
22604
|
-
var _a;
|
|
22605
|
-
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
22606
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
22607
|
-
});
|
|
22608
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
22609
|
-
return {
|
|
22610
|
-
channelId,
|
|
22611
|
-
subChannelId,
|
|
22612
|
-
data,
|
|
22613
|
-
dataType,
|
|
22614
|
-
isDeleted,
|
|
22615
|
-
segment,
|
|
22616
|
-
creatorId,
|
|
22617
|
-
createdAt,
|
|
22618
|
-
updatedAt,
|
|
22619
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
22620
|
-
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
22621
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
22622
|
-
};
|
|
22623
|
-
};
|
|
22624
|
-
const newData = {
|
|
22625
|
-
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
22626
|
-
};
|
|
22627
|
-
ingestInCache(newData);
|
|
22628
|
-
};
|
|
22629
|
-
|
|
22630
|
-
const getSubChannelMessagePreview = (subChannelId) => {
|
|
22631
|
-
var _a, _b;
|
|
22632
|
-
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
22633
|
-
};
|
|
22634
|
-
|
|
22635
|
-
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
22636
|
-
var _a;
|
|
22637
|
-
const messagePreview = subChannel.messagePreviewId
|
|
22638
|
-
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
22639
|
-
: null;
|
|
22640
|
-
const messagePreviewWithUser = messagePreview
|
|
22641
|
-
? 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;
|
|
22642
|
-
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
22643
|
-
};
|
|
22644
|
-
|
|
22645
|
-
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
22646
|
-
var _a, _b;
|
|
22647
|
-
const withMessageFeedInfo = (messagePreview) => {
|
|
22648
|
-
var _a;
|
|
22649
|
-
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
22650
|
-
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
22651
|
-
});
|
|
22652
|
-
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
22653
|
-
return {
|
|
22654
|
-
messagePreviewId,
|
|
22655
|
-
channelId,
|
|
22656
|
-
subChannelId,
|
|
22657
|
-
data,
|
|
22658
|
-
dataType,
|
|
22659
|
-
isDeleted,
|
|
22660
|
-
segment,
|
|
22661
|
-
creatorId,
|
|
22662
|
-
createdAt,
|
|
22663
|
-
updatedAt,
|
|
22664
|
-
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
22665
|
-
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
22666
|
-
};
|
|
22667
|
-
};
|
|
22668
|
-
const newData = {
|
|
22669
|
-
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
22670
|
-
};
|
|
22671
|
-
ingestInCache(newData);
|
|
22672
|
-
};
|
|
22673
|
-
|
|
22674
|
-
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
22675
|
-
pushToCache(['subChannel', 'get', subChannelId],
|
|
22676
|
-
// eslint-disable-next-line prefer-object-spread
|
|
22677
|
-
shallowClone(subChannel, params));
|
|
22678
|
-
}
|
|
22679
|
-
|
|
22680
|
-
/**
|
|
22681
|
-
* ```js
|
|
22682
|
-
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
22683
|
-
* const user = isInTombstone(["message", "messageId"])
|
|
22684
|
-
* ```
|
|
22685
|
-
*
|
|
22686
|
-
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
22687
|
-
* in cache and it's not expired means it's in tombstone
|
|
22688
|
-
* and we throw an Error
|
|
22689
|
-
*
|
|
22690
|
-
* @param model the model to check
|
|
22691
|
-
* @param modelId the object id to check
|
|
22692
|
-
* @returns the matching cache entry, or undefined.
|
|
22693
|
-
*
|
|
22694
|
-
* @category Cache API
|
|
22695
|
-
*/
|
|
22696
|
-
const isInTombstone = (model, modelId) => {
|
|
22697
|
-
const { log, cache } = getActiveClient();
|
|
22698
|
-
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
22699
|
-
if (!cache)
|
|
22700
|
-
return;
|
|
22701
|
-
log('cache/api/isInTombstone', key);
|
|
22702
|
-
const isInTombstone = pullFromCache(key);
|
|
22703
|
-
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
22704
|
-
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
22705
|
-
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22706
|
-
}
|
|
22707
|
-
};
|
|
22708
|
-
|
|
22709
|
-
/**
|
|
22710
|
-
* ```js
|
|
22711
|
-
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
22712
|
-
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
22713
|
-
* ```
|
|
22714
|
-
*
|
|
22715
|
-
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
22716
|
-
*
|
|
22717
|
-
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
22718
|
-
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
22719
|
-
*
|
|
22720
|
-
* @category Channel API
|
|
22721
|
-
* @async
|
|
22722
|
-
* @private
|
|
22723
|
-
*/
|
|
22724
|
-
const getMessageMarkers = async (messageIds) => {
|
|
22725
23614
|
const client = getActiveClient();
|
|
22726
|
-
client.log('
|
|
22727
|
-
const { data
|
|
22728
|
-
|
|
22729
|
-
|
|
22730
|
-
|
|
22731
|
-
|
|
22732
|
-
|
|
22733
|
-
|
|
22734
|
-
|
|
22735
|
-
|
|
22736
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
22737
|
-
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
22738
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22739
|
-
return { data: contentMarkers, cachedAt };
|
|
22740
|
-
};
|
|
22741
|
-
|
|
22742
|
-
const persistUnreadCountInfo = (payload) => {
|
|
22743
|
-
const { feedMarkers, userFeedMarkers } = payload;
|
|
22744
|
-
// calculate sub channel unread info and channel unread info
|
|
22745
|
-
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
22746
|
-
const channelIds = [];
|
|
22747
|
-
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
22748
|
-
userFeedMarkers.forEach(userFeedMarker => {
|
|
22749
|
-
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
22750
|
-
if (!feedMarker)
|
|
22751
|
-
return;
|
|
22752
|
-
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
22753
|
-
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
22754
|
-
const subChannelUnreadInfo = {
|
|
22755
|
-
subChannelId: feedMarker.feedId,
|
|
22756
|
-
channelId: feedMarker.entityId,
|
|
22757
|
-
readToSegment: userFeedMarker.readToSegment,
|
|
22758
|
-
lastSegment: feedMarker.lastSegment,
|
|
22759
|
-
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
22760
|
-
unreadCount: Math.max(0, unreadCount),
|
|
22761
|
-
isMentioned: userFeedMarker.isMentioned,
|
|
22762
|
-
isDeleted: feedMarker.isDeleted,
|
|
22763
|
-
createdAt: userFeedMarker.createdAt,
|
|
22764
|
-
updatedAt: userFeedMarker.updatedAt,
|
|
22765
|
-
};
|
|
22766
|
-
// update sub channel unread info in cache
|
|
22767
|
-
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
22768
|
-
if (!channelIds.includes(feedMarker.entityId)) {
|
|
22769
|
-
channelIds.push(feedMarker.entityId);
|
|
22770
|
-
}
|
|
22771
|
-
}
|
|
22772
|
-
});
|
|
22773
|
-
// re-calculate channel unread info in cache
|
|
22774
|
-
channelIds.forEach(channelId => {
|
|
22775
|
-
reCalculateChannelUnreadInfo(channelId);
|
|
22776
|
-
});
|
|
23615
|
+
client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
|
|
23616
|
+
const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
|
|
23617
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23618
|
+
'joinRequest',
|
|
23619
|
+
'get',
|
|
23620
|
+
joinRequest.joinRequestId,
|
|
23621
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23622
|
+
if (joinRequestCache) {
|
|
23623
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
23624
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
22777
23625
|
}
|
|
22778
|
-
|
|
23626
|
+
return data.success;
|
|
23627
|
+
};
|
|
23628
|
+
/* end_public_function */
|
|
22779
23629
|
|
|
23630
|
+
/* begin_public_function
|
|
23631
|
+
id: joinRequest.reject
|
|
23632
|
+
*/
|
|
22780
23633
|
/**
|
|
22781
23634
|
* ```js
|
|
22782
|
-
* import {
|
|
22783
|
-
* const
|
|
23635
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23636
|
+
* const isRejected = await joinRequest.reject()
|
|
22784
23637
|
* ```
|
|
22785
23638
|
*
|
|
22786
|
-
*
|
|
23639
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
22787
23640
|
*
|
|
22788
|
-
* @param
|
|
22789
|
-
* @
|
|
22790
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
23641
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
23642
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
22791
23643
|
*
|
|
22792
|
-
* @category
|
|
23644
|
+
* @category Join Request API
|
|
22793
23645
|
* @async
|
|
22794
|
-
* @private
|
|
22795
23646
|
*/
|
|
22796
|
-
const
|
|
23647
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
23648
|
+
var _a;
|
|
22797
23649
|
const client = getActiveClient();
|
|
22798
|
-
client.log('
|
|
22799
|
-
const { data
|
|
22800
|
-
|
|
22801
|
-
messageFeedIds,
|
|
22802
|
-
options: {
|
|
22803
|
-
token: toToken(page, 'skiplimit'),
|
|
22804
|
-
},
|
|
22805
|
-
},
|
|
23650
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
23651
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
|
|
23652
|
+
userId: joinRequest.requestorInternalId,
|
|
22806
23653
|
});
|
|
22807
|
-
const
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
22813
|
-
|
|
23654
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23655
|
+
'joinRequest',
|
|
23656
|
+
'get',
|
|
23657
|
+
joinRequest.joinRequestId,
|
|
23658
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23659
|
+
if (joinRequestCache) {
|
|
23660
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23661
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
22814
23662
|
});
|
|
23663
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
22815
23664
|
}
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
22821
|
-
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
23665
|
+
return data.success;
|
|
23666
|
+
};
|
|
23667
|
+
/* end_public_function */
|
|
23668
|
+
|
|
23669
|
+
const joinRequestLinkedObject = (joinRequest) => {
|
|
23670
|
+
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
23671
|
+
var _a;
|
|
23672
|
+
const user = (_a = pullFromCache([
|
|
23673
|
+
'user',
|
|
23674
|
+
'get',
|
|
23675
|
+
joinRequest.requestorPublicId,
|
|
23676
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23677
|
+
if (!user)
|
|
23678
|
+
return undefined;
|
|
23679
|
+
return userLinkedObject(user);
|
|
23680
|
+
}, cancel: async () => {
|
|
23681
|
+
await cancelJoinRequest(joinRequest);
|
|
23682
|
+
}, approve: async () => {
|
|
23683
|
+
await approveJoinRequest(joinRequest);
|
|
23684
|
+
}, reject: async () => {
|
|
23685
|
+
await rejectJoinRequest(joinRequest);
|
|
23686
|
+
} });
|
|
22827
23687
|
};
|
|
22828
23688
|
|
|
22829
|
-
|
|
23689
|
+
/* begin_public_function
|
|
23690
|
+
id: community.getMyJoinRequest
|
|
23691
|
+
*/
|
|
23692
|
+
/**
|
|
23693
|
+
* ```js
|
|
23694
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23695
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
23696
|
+
* ```
|
|
23697
|
+
*
|
|
23698
|
+
* Joins a {@link Amity.Community} object
|
|
23699
|
+
*
|
|
23700
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23701
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
23702
|
+
*
|
|
23703
|
+
* @category Community API
|
|
23704
|
+
* @async
|
|
23705
|
+
*/
|
|
23706
|
+
const getMyJoinRequest = async (communityId) => {
|
|
22830
23707
|
const client = getActiveClient();
|
|
22831
|
-
client.log('
|
|
22832
|
-
const { data: payload } = await client.http.get(`/api/
|
|
22833
|
-
const
|
|
23708
|
+
client.log('community/myJoinRequest', communityId);
|
|
23709
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
23710
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
22834
23711
|
const cachedAt = client.cache && Date.now();
|
|
22835
23712
|
if (client.cache)
|
|
22836
|
-
ingestInCache(
|
|
22837
|
-
|
|
22838
|
-
|
|
22839
|
-
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
22843
|
-
return maxUserMarker;
|
|
22844
|
-
}, undefined);
|
|
22845
|
-
return { data: latestUserMarker, cachedAt };
|
|
22846
|
-
};
|
|
23713
|
+
ingestInCache(data, { cachedAt });
|
|
23714
|
+
return {
|
|
23715
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
23716
|
+
cachedAt,
|
|
23717
|
+
};
|
|
23718
|
+
};
|
|
23719
|
+
/* end_public_function */
|
|
22847
23720
|
|
|
22848
|
-
|
|
22849
|
-
|
|
22850
|
-
|
|
22851
|
-
|
|
23721
|
+
/* begin_public_function
|
|
23722
|
+
id: community.join
|
|
23723
|
+
*/
|
|
23724
|
+
/**
|
|
23725
|
+
* ```js
|
|
23726
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23727
|
+
* const isJoined = await community.join('foobar')
|
|
23728
|
+
* ```
|
|
23729
|
+
*
|
|
23730
|
+
* Joins a {@link Amity.Community} object
|
|
23731
|
+
*
|
|
23732
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23733
|
+
* @returns A status join result
|
|
23734
|
+
*
|
|
23735
|
+
* @category Community API
|
|
23736
|
+
* @async
|
|
22852
23737
|
*/
|
|
22853
|
-
const
|
|
23738
|
+
const joinRequest = async (communityId) => {
|
|
22854
23739
|
const client = getActiveClient();
|
|
22855
|
-
|
|
22856
|
-
|
|
22857
|
-
const
|
|
22858
|
-
|
|
22859
|
-
|
|
22860
|
-
|
|
22861
|
-
|
|
22862
|
-
const
|
|
22863
|
-
|
|
22864
|
-
|
|
23740
|
+
client.log('community/joinRequest', communityId);
|
|
23741
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
23742
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23743
|
+
const cachedAt = client.cache && Date.now();
|
|
23744
|
+
if (client.cache)
|
|
23745
|
+
ingestInCache(data, { cachedAt });
|
|
23746
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
23747
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
23748
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
23749
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
23750
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
23751
|
+
? { status }
|
|
23752
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
23753
|
+
};
|
|
23754
|
+
/* end_public_function */
|
|
23755
|
+
|
|
23756
|
+
class PaginationController {
|
|
23757
|
+
constructor(queryParams) {
|
|
23758
|
+
const { http } = getActiveClient();
|
|
23759
|
+
this.queryParams = queryParams;
|
|
23760
|
+
this.http = http;
|
|
22865
23761
|
}
|
|
22866
|
-
|
|
22867
|
-
|
|
22868
|
-
Object.assign(payload, {
|
|
22869
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22870
|
-
});
|
|
23762
|
+
loadFirstPage() {
|
|
23763
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
22871
23764
|
}
|
|
22872
|
-
|
|
22873
|
-
|
|
22874
|
-
Object.assign(payload, {
|
|
22875
|
-
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22876
|
-
});
|
|
23765
|
+
loadNextPage() {
|
|
23766
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
22877
23767
|
}
|
|
22878
|
-
|
|
22879
|
-
|
|
22880
|
-
/*
|
|
22881
|
-
* This is a simple utility that infers the value of isDeleted based on the
|
|
22882
|
-
* value of includeDeleted
|
|
22883
|
-
*
|
|
22884
|
-
* There are two important things to note here:
|
|
22885
|
-
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
22886
|
-
* the server
|
|
22887
|
-
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
22888
|
-
* param for queries) is false | undefined and want to disallow users to query
|
|
22889
|
-
* for deleted entities
|
|
22890
|
-
*
|
|
22891
|
-
* Although this is a very simple utility, it's only purpose is to keep things
|
|
22892
|
-
* DRY
|
|
22893
|
-
*/
|
|
22894
|
-
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
22895
|
-
|
|
22896
|
-
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
22897
|
-
var _a, _b;
|
|
22898
|
-
// Look for `unreadCount` in the marker param first
|
|
22899
|
-
if (marker) {
|
|
22900
|
-
return marker.hasMentioned;
|
|
23768
|
+
loadPreviousPage() {
|
|
23769
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
22901
23770
|
}
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
|
|
23771
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
23772
|
+
var _a, _b, _c, _d;
|
|
23773
|
+
if (direction === 'prev' && !this.previousToken)
|
|
23774
|
+
return;
|
|
23775
|
+
if (direction === 'next' && !this.nextToken)
|
|
23776
|
+
return;
|
|
23777
|
+
let token;
|
|
23778
|
+
if (direction === 'prev')
|
|
23779
|
+
token = this.previousToken;
|
|
23780
|
+
if (direction === 'next')
|
|
23781
|
+
token = this.nextToken;
|
|
23782
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
23783
|
+
if (direction === 'first') {
|
|
23784
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
23785
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
22912
23786
|
}
|
|
22913
|
-
|
|
23787
|
+
if (direction === 'prev')
|
|
23788
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
23789
|
+
if (direction === 'next')
|
|
23790
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
23791
|
+
return queryResponse;
|
|
22914
23792
|
}
|
|
22915
|
-
|
|
22916
|
-
|
|
22917
|
-
|
|
22918
|
-
|
|
22919
|
-
|
|
22920
|
-
// If the marker param is not set, look in the cache
|
|
22921
|
-
const cachedMarker = (_b = pullFromCache([
|
|
22922
|
-
'subChannelMarker',
|
|
22923
|
-
'get',
|
|
22924
|
-
getResolver('subChannelMarker')(key),
|
|
22925
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22926
|
-
if (cachedMarker) {
|
|
22927
|
-
return cachedMarker.hasMentioned;
|
|
23793
|
+
getNextToken() {
|
|
23794
|
+
return this.nextToken;
|
|
23795
|
+
}
|
|
23796
|
+
getPrevToken() {
|
|
23797
|
+
return this.previousToken;
|
|
22928
23798
|
}
|
|
22929
|
-
// and if not found in cache use default value `false`
|
|
22930
|
-
return false;
|
|
22931
23799
|
}
|
|
22932
23800
|
|
|
22933
|
-
|
|
22934
|
-
|
|
22935
|
-
|
|
22936
|
-
|
|
22937
|
-
|
|
22938
|
-
|
|
22939
|
-
|
|
22940
|
-
|
|
22941
|
-
|
|
22942
|
-
|
|
22943
|
-
|
|
22944
|
-
|
|
22945
|
-
subChannelId,
|
|
22946
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22947
|
-
if (cachedUnreadCount) {
|
|
22948
|
-
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
22949
|
-
}
|
|
22950
|
-
return 0;
|
|
22951
|
-
}
|
|
22952
|
-
const key = {
|
|
22953
|
-
entityId: channelId,
|
|
22954
|
-
feedId: subChannelId,
|
|
22955
|
-
userId: getActiveUser()._id,
|
|
22956
|
-
};
|
|
22957
|
-
// If the marker param is not set, look in the cache
|
|
22958
|
-
const cachedMarker = (_b = pullFromCache([
|
|
22959
|
-
'subChannelMarker',
|
|
22960
|
-
'get',
|
|
22961
|
-
getResolver('subChannelMarker')(key),
|
|
22962
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22963
|
-
if (cachedMarker) {
|
|
22964
|
-
return cachedMarker.unreadCount;
|
|
23801
|
+
/**
|
|
23802
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
23803
|
+
* TODO: check if querybyIds is supported
|
|
23804
|
+
*/
|
|
23805
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
23806
|
+
async getRequest(queryParams, token) {
|
|
23807
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
23808
|
+
const options = token ? { token } : { limit };
|
|
23809
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
23810
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
23811
|
+
});
|
|
23812
|
+
return queryResponse;
|
|
22965
23813
|
}
|
|
22966
|
-
// and if not found in cache use default value `0`
|
|
22967
|
-
return 0;
|
|
22968
23814
|
}
|
|
22969
23815
|
|
|
22970
|
-
|
|
22971
|
-
|
|
22972
|
-
|
|
22973
|
-
|
|
22974
|
-
|
|
22975
|
-
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
22976
|
-
},
|
|
22977
|
-
get hasMentioned() {
|
|
22978
|
-
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
22979
|
-
},
|
|
22980
|
-
get isMentioned() {
|
|
22981
|
-
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
22982
|
-
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
23816
|
+
class QueryStreamController {
|
|
23817
|
+
constructor(query, cacheKey) {
|
|
23818
|
+
this.query = query;
|
|
23819
|
+
this.cacheKey = cacheKey;
|
|
23820
|
+
}
|
|
22983
23821
|
}
|
|
22984
23822
|
|
|
22985
|
-
|
|
22986
|
-
|
|
22987
|
-
|
|
22988
|
-
|
|
22989
|
-
|
|
22990
|
-
|
|
22991
|
-
|
|
23823
|
+
var EnumJoinRequestAction;
|
|
23824
|
+
(function (EnumJoinRequestAction) {
|
|
23825
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
23826
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
23827
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
23828
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
23829
|
+
|
|
23830
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
23831
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23832
|
+
super(query, cacheKey);
|
|
23833
|
+
this.notifyChange = notifyChange;
|
|
23834
|
+
this.preparePayload = preparePayload;
|
|
22992
23835
|
}
|
|
22993
|
-
|
|
22994
|
-
|
|
22995
|
-
|
|
22996
|
-
|
|
22997
|
-
|
|
22998
|
-
|
|
22999
|
-
|
|
23000
|
-
if (referenceId) {
|
|
23001
|
-
cache = pullFromCache(['message', 'get', referenceId]);
|
|
23836
|
+
async saveToMainDB(response) {
|
|
23837
|
+
const processedPayload = await this.preparePayload(response);
|
|
23838
|
+
const client = getActiveClient();
|
|
23839
|
+
const cachedAt = client.cache && Date.now();
|
|
23840
|
+
if (client.cache) {
|
|
23841
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23842
|
+
}
|
|
23002
23843
|
}
|
|
23003
|
-
|
|
23004
|
-
|
|
23844
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23845
|
+
var _a, _b;
|
|
23846
|
+
if (refresh) {
|
|
23847
|
+
pushToCache(this.cacheKey, {
|
|
23848
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23849
|
+
});
|
|
23850
|
+
}
|
|
23851
|
+
else {
|
|
23852
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23853
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23854
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23855
|
+
...new Set([
|
|
23856
|
+
...joinRequests,
|
|
23857
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23858
|
+
]),
|
|
23859
|
+
] }));
|
|
23860
|
+
}
|
|
23005
23861
|
}
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
|
|
23011
|
-
|
|
23012
|
-
|
|
23013
|
-
|
|
23014
|
-
|
|
23015
|
-
|
|
23016
|
-
out.mentionees = mentionedUsers.map(mention => {
|
|
23017
|
-
if (mention.type === 'channel') {
|
|
23018
|
-
return mention;
|
|
23862
|
+
reactor(action) {
|
|
23863
|
+
return (joinRequest) => {
|
|
23864
|
+
var _a;
|
|
23865
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23866
|
+
if (!collection)
|
|
23867
|
+
return;
|
|
23868
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
23869
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
23870
|
+
if (!isExist)
|
|
23871
|
+
return;
|
|
23019
23872
|
}
|
|
23020
|
-
|
|
23021
|
-
|
|
23873
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
23874
|
+
collection.data = [
|
|
23875
|
+
...new Set([
|
|
23876
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
23877
|
+
...collection.data,
|
|
23878
|
+
]),
|
|
23879
|
+
];
|
|
23880
|
+
}
|
|
23881
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
23882
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
23883
|
+
}
|
|
23884
|
+
pushToCache(this.cacheKey, collection);
|
|
23885
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23886
|
+
};
|
|
23022
23887
|
}
|
|
23023
|
-
|
|
23024
|
-
|
|
23025
|
-
prepareMessagePayloadForCache(out, reactors, event);
|
|
23888
|
+
subscribeRTE(createSubscriber) {
|
|
23889
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23026
23890
|
}
|
|
23027
|
-
|
|
23891
|
+
}
|
|
23892
|
+
|
|
23893
|
+
function isObject(value) {
|
|
23894
|
+
return typeof value === 'object' && value !== null;
|
|
23028
23895
|
}
|
|
23029
|
-
|
|
23030
|
-
|
|
23031
|
-
|
|
23896
|
+
/**
|
|
23897
|
+
* convert all object getter property to static value
|
|
23898
|
+
*/
|
|
23899
|
+
const convertGetterPropsToStatic = (obj) => {
|
|
23900
|
+
if (!isObject(obj)) {
|
|
23901
|
+
return obj;
|
|
23902
|
+
}
|
|
23903
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23904
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
23905
|
+
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
23906
|
+
return [key, descriptor.get.call(obj)];
|
|
23907
|
+
}
|
|
23908
|
+
return [key, value];
|
|
23032
23909
|
});
|
|
23910
|
+
return Object.fromEntries(entries);
|
|
23033
23911
|
};
|
|
23034
|
-
const
|
|
23035
|
-
|
|
23036
|
-
|
|
23037
|
-
|
|
23038
|
-
|
|
23039
|
-
|
|
23040
|
-
|
|
23041
|
-
const markerIdsKey = markerIds.join('');
|
|
23042
|
-
if (currentDebounceMap[markerIdsKey]) {
|
|
23043
|
-
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
23912
|
+
const removeFunctionProperties = (obj) => {
|
|
23913
|
+
if (!isObject(obj)) {
|
|
23914
|
+
return obj;
|
|
23915
|
+
}
|
|
23916
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23917
|
+
if (typeof value === 'function') {
|
|
23918
|
+
return [key, undefined];
|
|
23044
23919
|
}
|
|
23045
|
-
|
|
23046
|
-
|
|
23047
|
-
|
|
23048
|
-
|
|
23049
|
-
|
|
23050
|
-
|
|
23051
|
-
|
|
23052
|
-
}
|
|
23920
|
+
return [key, value];
|
|
23921
|
+
});
|
|
23922
|
+
return Object.fromEntries(entries);
|
|
23923
|
+
};
|
|
23924
|
+
|
|
23925
|
+
class PaginationNoPageController {
|
|
23926
|
+
constructor(queryParams) {
|
|
23927
|
+
const { http } = getActiveClient();
|
|
23928
|
+
this.queryParams = queryParams;
|
|
23929
|
+
this.http = http;
|
|
23053
23930
|
}
|
|
23054
|
-
|
|
23055
|
-
|
|
23056
|
-
|
|
23057
|
-
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
23058
|
-
var _a, _b;
|
|
23059
|
-
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
23060
|
-
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
23061
|
-
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
23062
|
-
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
23063
|
-
});
|
|
23931
|
+
async onFetch() {
|
|
23932
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
23933
|
+
return queryResponse;
|
|
23064
23934
|
}
|
|
23065
|
-
|
|
23066
|
-
|
|
23067
|
-
|
|
23068
|
-
|
|
23069
|
-
|
|
23070
|
-
|
|
23935
|
+
}
|
|
23936
|
+
|
|
23937
|
+
class LiveCollectionController {
|
|
23938
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
23939
|
+
this.paginationController = paginationController;
|
|
23940
|
+
this.queryStreamId = queryStreamId;
|
|
23941
|
+
this.cacheKey = cacheKey;
|
|
23942
|
+
this.callback = callback;
|
|
23071
23943
|
}
|
|
23072
|
-
|
|
23073
|
-
|
|
23074
|
-
|
|
23075
|
-
|
|
23076
|
-
|
|
23077
|
-
|
|
23078
|
-
|
|
23079
|
-
|
|
23080
|
-
|
|
23081
|
-
|
|
23082
|
-
|
|
23944
|
+
async refresh() {
|
|
23945
|
+
try {
|
|
23946
|
+
let result;
|
|
23947
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
23948
|
+
result = await this.paginationController.onFetch();
|
|
23949
|
+
}
|
|
23950
|
+
else {
|
|
23951
|
+
result = await this.paginationController.loadFirstPage();
|
|
23952
|
+
}
|
|
23953
|
+
if (!result)
|
|
23954
|
+
return;
|
|
23955
|
+
await this.persistModel(result);
|
|
23956
|
+
this.persistQueryStream({
|
|
23957
|
+
response: result,
|
|
23958
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23959
|
+
refresh: true,
|
|
23960
|
+
});
|
|
23961
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23962
|
+
}
|
|
23963
|
+
catch (e) {
|
|
23964
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23965
|
+
}
|
|
23083
23966
|
}
|
|
23084
|
-
|
|
23085
|
-
|
|
23967
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
23968
|
+
this.setup();
|
|
23969
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
23970
|
+
if (initial) {
|
|
23971
|
+
this.refresh();
|
|
23972
|
+
}
|
|
23973
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
23974
|
+
this.loadPrevPage();
|
|
23975
|
+
}
|
|
23976
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
23977
|
+
this.loadNextPage();
|
|
23978
|
+
}
|
|
23086
23979
|
}
|
|
23087
|
-
|
|
23088
|
-
|
|
23980
|
+
async loadNextPage() {
|
|
23981
|
+
try {
|
|
23982
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
23983
|
+
return;
|
|
23984
|
+
const result = await this.paginationController.loadNextPage();
|
|
23985
|
+
if (!result)
|
|
23986
|
+
return;
|
|
23987
|
+
await this.persistModel(result);
|
|
23988
|
+
this.persistQueryStream({
|
|
23989
|
+
response: result,
|
|
23990
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23991
|
+
});
|
|
23992
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23993
|
+
}
|
|
23994
|
+
catch (e) {
|
|
23995
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23996
|
+
}
|
|
23089
23997
|
}
|
|
23090
|
-
|
|
23091
|
-
}
|
|
23092
|
-
|
|
23093
|
-
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
23094
|
-
/**
|
|
23095
|
-
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
23096
|
-
*/
|
|
23097
|
-
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
23098
|
-
const preUpdateSubChannelCache = (rawPayload) => {
|
|
23099
|
-
ingestInCache({
|
|
23100
|
-
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
23101
|
-
});
|
|
23102
|
-
};
|
|
23103
|
-
const prepareSubChannelPayload = async (rawPayload) => {
|
|
23104
|
-
const markerIds = rawPayload.messageFeeds
|
|
23105
|
-
.filter(isUnreadCountSupport$1)
|
|
23106
|
-
.map(({ messageFeedId }) => messageFeedId);
|
|
23107
|
-
if (markerIds.length > 0) {
|
|
23108
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
23109
|
-
preUpdateSubChannelCache(rawPayload);
|
|
23998
|
+
async loadPrevPage() {
|
|
23110
23999
|
try {
|
|
23111
|
-
|
|
24000
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
24001
|
+
return;
|
|
24002
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
24003
|
+
if (!result)
|
|
24004
|
+
return;
|
|
24005
|
+
await this.persistModel(result);
|
|
24006
|
+
this.persistQueryStream({
|
|
24007
|
+
response: result,
|
|
24008
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
24009
|
+
});
|
|
24010
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23112
24011
|
}
|
|
23113
24012
|
catch (e) {
|
|
23114
|
-
|
|
24013
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23115
24014
|
}
|
|
23116
24015
|
}
|
|
23117
|
-
|
|
23118
|
-
|
|
23119
|
-
|
|
23120
|
-
|
|
23121
|
-
|
|
23122
|
-
|
|
23123
|
-
}
|
|
23124
|
-
|
|
23125
|
-
|
|
23126
|
-
const out = Object.assign({}, rest);
|
|
23127
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
23128
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
24016
|
+
shouldNotify(data) {
|
|
24017
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
24018
|
+
if (isEqual(this.snapshot, newData))
|
|
24019
|
+
return false;
|
|
24020
|
+
this.snapshot = newData;
|
|
24021
|
+
return true;
|
|
24022
|
+
}
|
|
24023
|
+
getCacheKey() {
|
|
24024
|
+
return this.cacheKey;
|
|
23129
24025
|
}
|
|
23130
|
-
return out;
|
|
23131
24026
|
}
|
|
23132
24027
|
|
|
23133
24028
|
/**
|
|
23134
24029
|
* ```js
|
|
23135
|
-
* import {
|
|
23136
|
-
* const
|
|
24030
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
24031
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
24032
|
+
* // ...
|
|
24033
|
+
* })
|
|
23137
24034
|
* ```
|
|
23138
24035
|
*
|
|
23139
|
-
*
|
|
24036
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
23140
24037
|
*
|
|
23141
|
-
* @param
|
|
23142
|
-
* @returns
|
|
24038
|
+
* @param callback The function to call when the event was fired
|
|
24039
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23143
24040
|
*
|
|
23144
|
-
* @category
|
|
23145
|
-
* @async
|
|
24041
|
+
* @category JoinRequest Events
|
|
23146
24042
|
*/
|
|
23147
|
-
const
|
|
24043
|
+
const onJoinRequestCreated = (callback) => {
|
|
23148
24044
|
const client = getActiveClient();
|
|
23149
|
-
|
|
23150
|
-
|
|
23151
|
-
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
|
|
23157
|
-
fireEvent('local.message-feed.fetched', data);
|
|
23158
|
-
return {
|
|
23159
|
-
data: data.messageFeeds[0],
|
|
23160
|
-
cachedAt,
|
|
23161
|
-
};
|
|
23162
|
-
}
|
|
23163
|
-
catch (error) {
|
|
23164
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23165
|
-
pushToTombstone('subChannel', subChannelId);
|
|
23166
|
-
}
|
|
23167
|
-
throw error;
|
|
23168
|
-
}
|
|
23169
|
-
};
|
|
24045
|
+
const disposers = [
|
|
24046
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
24047
|
+
];
|
|
24048
|
+
return () => {
|
|
24049
|
+
disposers.forEach(fn => fn());
|
|
24050
|
+
};
|
|
24051
|
+
};
|
|
24052
|
+
|
|
23170
24053
|
/**
|
|
23171
24054
|
* ```js
|
|
23172
|
-
* import {
|
|
23173
|
-
* const
|
|
24055
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
24056
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
24057
|
+
* // ...
|
|
24058
|
+
* })
|
|
23174
24059
|
* ```
|
|
23175
24060
|
*
|
|
23176
|
-
*
|
|
24061
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
23177
24062
|
*
|
|
23178
|
-
* @param
|
|
23179
|
-
* @returns
|
|
24063
|
+
* @param callback The function to call when the event was fired
|
|
24064
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23180
24065
|
*
|
|
23181
|
-
* @category
|
|
24066
|
+
* @category JoinRequest Events
|
|
23182
24067
|
*/
|
|
23183
|
-
|
|
24068
|
+
const onJoinRequestUpdated = (callback) => {
|
|
23184
24069
|
const client = getActiveClient();
|
|
23185
|
-
|
|
23186
|
-
|
|
23187
|
-
|
|
23188
|
-
|
|
23189
|
-
|
|
23190
|
-
return;
|
|
23191
|
-
return {
|
|
23192
|
-
data: cached.data,
|
|
23193
|
-
cachedAt: cached.cachedAt,
|
|
24070
|
+
const disposers = [
|
|
24071
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
24072
|
+
];
|
|
24073
|
+
return () => {
|
|
24074
|
+
disposers.forEach(fn => fn());
|
|
23194
24075
|
};
|
|
23195
24076
|
};
|
|
23196
24077
|
|
|
23197
|
-
|
|
23198
|
-
|
|
24078
|
+
/**
|
|
24079
|
+
* ```js
|
|
24080
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
24081
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
24082
|
+
* // ...
|
|
24083
|
+
* })
|
|
24084
|
+
* ```
|
|
24085
|
+
*
|
|
24086
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24087
|
+
*
|
|
24088
|
+
* @param callback The function to call when the event was fired
|
|
24089
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24090
|
+
*
|
|
24091
|
+
* @category JoinRequest Events
|
|
24092
|
+
*/
|
|
24093
|
+
const onJoinRequestDeleted = (callback) => {
|
|
24094
|
+
const client = getActiveClient();
|
|
24095
|
+
const disposers = [
|
|
24096
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
24097
|
+
];
|
|
24098
|
+
return () => {
|
|
24099
|
+
disposers.forEach(fn => fn());
|
|
24100
|
+
};
|
|
23199
24101
|
};
|
|
23200
24102
|
|
|
23201
|
-
|
|
23202
|
-
|
|
23203
|
-
|
|
23204
|
-
|
|
23205
|
-
const
|
|
23206
|
-
|
|
23207
|
-
|
|
23208
|
-
|
|
23209
|
-
|
|
24103
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
24104
|
+
constructor(query, callback) {
|
|
24105
|
+
const queryStreamId = hash(query);
|
|
24106
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
24107
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
24108
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24109
|
+
this.query = query;
|
|
24110
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
24111
|
+
this.callback = callback.bind(this);
|
|
24112
|
+
this.loadPage({ initial: true });
|
|
23210
24113
|
}
|
|
23211
|
-
|
|
23212
|
-
|
|
23213
|
-
const
|
|
23214
|
-
|
|
23215
|
-
|
|
23216
|
-
|
|
23217
|
-
|
|
23218
|
-
message.subChannelId,
|
|
23219
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23220
|
-
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
23221
|
-
return (!cache ||
|
|
23222
|
-
cache.segment <= message.channelSegment ||
|
|
23223
|
-
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
23224
|
-
};
|
|
23225
|
-
const isLastestMessageOnChannel = (message) => {
|
|
23226
|
-
var _a;
|
|
23227
|
-
const cache = (_a = pullFromCache([
|
|
23228
|
-
'messagePreviewChannel',
|
|
23229
|
-
'get',
|
|
23230
|
-
message.channelId,
|
|
23231
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23232
|
-
return (!cache ||
|
|
23233
|
-
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
23234
|
-
};
|
|
23235
|
-
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
23236
|
-
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
23237
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
23238
|
-
// 1. get subChannel from cache, if not exist fetch from server
|
|
23239
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23240
|
-
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
23241
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
23242
|
-
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
23243
|
-
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
23244
|
-
convertDateStringToTimestamp(createdAt))
|
|
23245
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
23246
|
-
lastActivity: createdAt,
|
|
24114
|
+
setup() {
|
|
24115
|
+
var _a;
|
|
24116
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24117
|
+
if (!collection) {
|
|
24118
|
+
pushToCache(this.cacheKey, {
|
|
24119
|
+
data: [],
|
|
24120
|
+
params: this.query,
|
|
23247
24121
|
});
|
|
23248
|
-
|
|
24122
|
+
}
|
|
23249
24123
|
}
|
|
23250
|
-
|
|
23251
|
-
|
|
23252
|
-
if (!isLastestMessageOnSubchannel(message))
|
|
23253
|
-
return;
|
|
23254
|
-
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
23255
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
23256
|
-
channelId,
|
|
23257
|
-
creatorId,
|
|
23258
|
-
messagePreviewId,
|
|
23259
|
-
createdAt,
|
|
23260
|
-
updatedAt,
|
|
23261
|
-
subChannelId,
|
|
23262
|
-
data,
|
|
23263
|
-
dataType,
|
|
23264
|
-
segment,
|
|
23265
|
-
isDeleted,
|
|
23266
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
23267
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
23268
|
-
});
|
|
23269
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
23270
|
-
lastActivity: createdAt,
|
|
23271
|
-
messagePreviewId,
|
|
23272
|
-
});
|
|
23273
|
-
};
|
|
23274
|
-
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
23275
|
-
var _a;
|
|
23276
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
23277
|
-
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
23278
|
-
'messagePreviewSubChannel',
|
|
23279
|
-
'get',
|
|
23280
|
-
message.subChannelId,
|
|
23281
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23282
|
-
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
23283
|
-
if (messagePreviewSubChannelCache &&
|
|
23284
|
-
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
23285
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23286
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
23287
|
-
channelId,
|
|
23288
|
-
creatorId,
|
|
23289
|
-
messagePreviewId,
|
|
23290
|
-
createdAt,
|
|
23291
|
-
updatedAt,
|
|
23292
|
-
subChannelId,
|
|
23293
|
-
data,
|
|
23294
|
-
dataType,
|
|
23295
|
-
segment,
|
|
23296
|
-
isDeleted,
|
|
23297
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
23298
|
-
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
23299
|
-
});
|
|
24124
|
+
async persistModel(queryPayload) {
|
|
24125
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
23300
24126
|
}
|
|
23301
|
-
}
|
|
23302
|
-
const
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
23306
|
-
|
|
23307
|
-
|
|
23308
|
-
|
|
23309
|
-
|
|
23310
|
-
|
|
23311
|
-
|
|
23312
|
-
|
|
24127
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24128
|
+
const joinRequestResponse = response;
|
|
24129
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
24130
|
+
}
|
|
24131
|
+
startSubscription() {
|
|
24132
|
+
return this.queryStreamController.subscribeRTE([
|
|
24133
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
24134
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
24135
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
24136
|
+
]);
|
|
24137
|
+
}
|
|
24138
|
+
notifyChange({ origin, loading, error }) {
|
|
24139
|
+
var _a;
|
|
24140
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24141
|
+
if (!collection)
|
|
24142
|
+
return;
|
|
24143
|
+
const data = this.applyFilter(collection.data
|
|
24144
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
24145
|
+
.filter(isNonNullable)
|
|
24146
|
+
.map(({ data }) => data)
|
|
24147
|
+
.map(joinRequestLinkedObject));
|
|
24148
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24149
|
+
return;
|
|
24150
|
+
this.callback({
|
|
24151
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23313
24152
|
data,
|
|
23314
|
-
|
|
23315
|
-
|
|
23316
|
-
|
|
23317
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
23318
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
24153
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24154
|
+
loading,
|
|
24155
|
+
error,
|
|
23319
24156
|
});
|
|
23320
24157
|
}
|
|
24158
|
+
applyFilter(data) {
|
|
24159
|
+
let joinRequest = data;
|
|
24160
|
+
if (this.query.status) {
|
|
24161
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
24162
|
+
}
|
|
24163
|
+
const sortFn = (() => {
|
|
24164
|
+
switch (this.query.sortBy) {
|
|
24165
|
+
case 'firstCreated':
|
|
24166
|
+
return sortByFirstCreated;
|
|
24167
|
+
case 'lastCreated':
|
|
24168
|
+
return sortByLastCreated;
|
|
24169
|
+
default:
|
|
24170
|
+
return sortByLastCreated;
|
|
24171
|
+
}
|
|
24172
|
+
})();
|
|
24173
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
24174
|
+
return joinRequest;
|
|
24175
|
+
}
|
|
24176
|
+
}
|
|
24177
|
+
|
|
24178
|
+
/**
|
|
24179
|
+
* Get Join Requests
|
|
24180
|
+
*
|
|
24181
|
+
* @param params the query parameters
|
|
24182
|
+
* @param callback the callback to be called when the join request are updated
|
|
24183
|
+
* @returns joinRequests
|
|
24184
|
+
*
|
|
24185
|
+
* @category joinRequest Live Collection
|
|
24186
|
+
*
|
|
24187
|
+
*/
|
|
24188
|
+
const getJoinRequests = (params, callback, config) => {
|
|
24189
|
+
const { log, cache } = getActiveClient();
|
|
24190
|
+
if (!cache) {
|
|
24191
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24192
|
+
}
|
|
24193
|
+
const timestamp = Date.now();
|
|
24194
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
24195
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
24196
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
24197
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
24198
|
+
disposers.push(() => {
|
|
24199
|
+
dropFromCache(cacheKey);
|
|
24200
|
+
});
|
|
24201
|
+
return () => {
|
|
24202
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
24203
|
+
disposers.forEach(fn => fn());
|
|
24204
|
+
};
|
|
24205
|
+
};
|
|
24206
|
+
|
|
24207
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
24208
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
24209
|
+
};
|
|
24210
|
+
|
|
24211
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
24212
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
24213
|
+
};
|
|
24214
|
+
|
|
24215
|
+
/* begin_public_function
|
|
24216
|
+
id: invitation.createInvitations
|
|
24217
|
+
*/
|
|
24218
|
+
/**
|
|
24219
|
+
* ```js
|
|
24220
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
24221
|
+
* const created = await createInvitations({
|
|
24222
|
+
* type: string,
|
|
24223
|
+
* targetType: string,
|
|
24224
|
+
* targetId: string,
|
|
24225
|
+
* userIds: string[]
|
|
24226
|
+
* }))
|
|
24227
|
+
* ```
|
|
24228
|
+
*
|
|
24229
|
+
* Creates an {@link Amity.Invitation}
|
|
24230
|
+
*
|
|
24231
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
24232
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
24233
|
+
*
|
|
24234
|
+
* @category Invitation API
|
|
24235
|
+
* @async
|
|
24236
|
+
*/
|
|
24237
|
+
const createInvitations = async (bundle) => {
|
|
24238
|
+
const client = getActiveClient();
|
|
24239
|
+
client.log('invitation/createInvitations', bundle);
|
|
24240
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
24241
|
+
const data = prepareInvitationPayload(payload);
|
|
24242
|
+
const cachedAt = client.cache && Date.now();
|
|
24243
|
+
if (client.cache)
|
|
24244
|
+
ingestInCache(data, { cachedAt });
|
|
24245
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
24246
|
+
return {
|
|
24247
|
+
data: data.invitations,
|
|
24248
|
+
cachedAt,
|
|
24249
|
+
};
|
|
23321
24250
|
};
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23325
|
-
|
|
24251
|
+
/* end_public_function */
|
|
24252
|
+
|
|
24253
|
+
/* begin_public_function
|
|
24254
|
+
id: invitation.accept
|
|
24255
|
+
*/
|
|
24256
|
+
/**
|
|
24257
|
+
* ```js
|
|
24258
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
24259
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
24260
|
+
* ```
|
|
24261
|
+
*
|
|
24262
|
+
* Accepts a {@link Amity.Invitation} object
|
|
24263
|
+
*
|
|
24264
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
24265
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
24266
|
+
*
|
|
24267
|
+
* @category Invitation API
|
|
24268
|
+
* @async
|
|
24269
|
+
*/
|
|
24270
|
+
const acceptInvitation = async (invitationId) => {
|
|
23326
24271
|
var _a;
|
|
23327
|
-
const
|
|
23328
|
-
|
|
23329
|
-
|
|
24272
|
+
const client = getActiveClient();
|
|
24273
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
24274
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
24275
|
+
const invitation = (_a = pullFromCache([
|
|
24276
|
+
'invitation',
|
|
23330
24277
|
'get',
|
|
23331
|
-
|
|
24278
|
+
invitationId,
|
|
23332
24279
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23333
|
-
if (
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
23337
|
-
channelId,
|
|
23338
|
-
creatorId,
|
|
23339
|
-
messagePreviewId,
|
|
23340
|
-
createdAt,
|
|
23341
|
-
updatedAt,
|
|
23342
|
-
subChannelId,
|
|
23343
|
-
data,
|
|
23344
|
-
dataType,
|
|
23345
|
-
segment,
|
|
23346
|
-
isDeleted,
|
|
23347
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
23348
|
-
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
23349
|
-
});
|
|
24280
|
+
if (invitation) {
|
|
24281
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
24282
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
23350
24283
|
}
|
|
24284
|
+
return data.success;
|
|
23351
24285
|
};
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
|
|
24286
|
+
/* end_public_function */
|
|
24287
|
+
|
|
24288
|
+
/* begin_public_function
|
|
24289
|
+
id: invitation.reject
|
|
24290
|
+
*/
|
|
24291
|
+
/**
|
|
24292
|
+
* ```js
|
|
24293
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
24294
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
24295
|
+
* ```
|
|
24296
|
+
*
|
|
24297
|
+
* Rejects a {@link Amity.Invitation} object
|
|
24298
|
+
*
|
|
24299
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
24300
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
24301
|
+
*
|
|
24302
|
+
* @category Invitation API
|
|
24303
|
+
* @async
|
|
24304
|
+
*/
|
|
24305
|
+
const rejectInvitation = async (invitationId) => {
|
|
24306
|
+
var _a;
|
|
24307
|
+
const client = getActiveClient();
|
|
24308
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
24309
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
24310
|
+
const invitation = (_a = pullFromCache([
|
|
24311
|
+
'invitation',
|
|
23358
24312
|
'get',
|
|
23359
|
-
|
|
24313
|
+
invitationId,
|
|
23360
24314
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23361
|
-
if (
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
'get',
|
|
23365
|
-
subChannelId,
|
|
23366
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
23367
|
-
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 }));
|
|
24315
|
+
if (invitation) {
|
|
24316
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
24317
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
23368
24318
|
}
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
24319
|
+
return data.success;
|
|
24320
|
+
};
|
|
24321
|
+
/* end_public_function */
|
|
24322
|
+
|
|
24323
|
+
/* begin_public_function
|
|
24324
|
+
id: invitation.cancel
|
|
24325
|
+
*/
|
|
24326
|
+
/**
|
|
24327
|
+
* ```js
|
|
24328
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
24329
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
24330
|
+
* ```
|
|
24331
|
+
*
|
|
24332
|
+
* Cancels a {@link Amity.Invitation} object
|
|
24333
|
+
*
|
|
24334
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
24335
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
24336
|
+
*
|
|
24337
|
+
* @category Invitation API
|
|
24338
|
+
* @async
|
|
24339
|
+
*/
|
|
24340
|
+
const cancelInvitation = async (invitationId) => {
|
|
24341
|
+
var _a;
|
|
24342
|
+
const client = getActiveClient();
|
|
24343
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
24344
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
24345
|
+
const invitation = (_a = pullFromCache([
|
|
24346
|
+
'invitation',
|
|
23372
24347
|
'get',
|
|
23373
|
-
|
|
23374
|
-
])) === null ||
|
|
23375
|
-
if (
|
|
23376
|
-
|
|
23377
|
-
|
|
23378
|
-
const subChannelCache = (_d = pullFromCache([
|
|
23379
|
-
'subChannel',
|
|
23380
|
-
'get',
|
|
23381
|
-
subChannelId,
|
|
23382
|
-
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
23383
|
-
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 }));
|
|
24348
|
+
invitationId,
|
|
24349
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24350
|
+
if (invitation) {
|
|
24351
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
24352
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
23384
24353
|
}
|
|
24354
|
+
return data.success;
|
|
24355
|
+
};
|
|
24356
|
+
/* end_public_function */
|
|
24357
|
+
|
|
24358
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
24359
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
24360
|
+
};
|
|
24361
|
+
|
|
24362
|
+
const invitationLinkedObject = (invitation) => {
|
|
24363
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
24364
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
24365
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24366
|
+
return userLinkedObject(cacheData.data);
|
|
24367
|
+
return undefined;
|
|
24368
|
+
},
|
|
24369
|
+
get createdBy() {
|
|
24370
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
24371
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24372
|
+
return userLinkedObject(cacheData.data);
|
|
24373
|
+
return undefined;
|
|
24374
|
+
},
|
|
24375
|
+
get target() {
|
|
24376
|
+
if (invitation.targetType === 'community') {
|
|
24377
|
+
const cacheData = pullFromCache([
|
|
24378
|
+
'community',
|
|
24379
|
+
'get',
|
|
24380
|
+
invitation.targetId,
|
|
24381
|
+
]);
|
|
24382
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24383
|
+
return cacheData.data;
|
|
24384
|
+
return undefined;
|
|
24385
|
+
}
|
|
24386
|
+
return undefined;
|
|
24387
|
+
}, accept: async () => {
|
|
24388
|
+
await acceptInvitation(invitation._id);
|
|
24389
|
+
}, reject: async () => {
|
|
24390
|
+
await rejectInvitation(invitation._id);
|
|
24391
|
+
}, cancel: async () => {
|
|
24392
|
+
await cancelInvitation(invitation._id);
|
|
24393
|
+
} });
|
|
23385
24394
|
};
|
|
23386
24395
|
|
|
23387
|
-
|
|
23388
|
-
|
|
24396
|
+
/* begin_public_function
|
|
24397
|
+
id: invitation.get
|
|
24398
|
+
*/
|
|
24399
|
+
/**
|
|
24400
|
+
* ```js
|
|
24401
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
24402
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
24403
|
+
* ```
|
|
24404
|
+
*
|
|
24405
|
+
* Get a {@link Amity.Invitation} object
|
|
24406
|
+
*
|
|
24407
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
24408
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
24409
|
+
* @returns A {@link Amity.Invitation} object
|
|
24410
|
+
*
|
|
24411
|
+
* @category Invitation API
|
|
24412
|
+
* @async
|
|
24413
|
+
*/
|
|
24414
|
+
const getInvitation = async (targetType, targetId) => {
|
|
24415
|
+
const client = getActiveClient();
|
|
24416
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
24417
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
24418
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
24419
|
+
const cachedAt = client.cache && Date.now();
|
|
24420
|
+
if (client.cache)
|
|
24421
|
+
ingestInCache(data, { cachedAt });
|
|
24422
|
+
return {
|
|
24423
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
24424
|
+
cachedAt,
|
|
24425
|
+
};
|
|
24426
|
+
};
|
|
24427
|
+
/* end_public_function */
|
|
24428
|
+
|
|
24429
|
+
var InvitationActionsEnum;
|
|
24430
|
+
(function (InvitationActionsEnum) {
|
|
24431
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
24432
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
24433
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
24434
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
24435
|
+
|
|
24436
|
+
class InvitationsPaginationController extends PaginationController {
|
|
24437
|
+
async getRequest(queryParams, token) {
|
|
24438
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
24439
|
+
const options = token ? { token } : { limit };
|
|
24440
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
24441
|
+
return data;
|
|
24442
|
+
}
|
|
23389
24443
|
}
|
|
23390
24444
|
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
|
|
23395
|
-
|
|
23396
|
-
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
23397
|
-
'messagePreviewChannel',
|
|
23398
|
-
'get',
|
|
23399
|
-
channel.channelId,
|
|
23400
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23401
|
-
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
23402
|
-
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
24445
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
24446
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24447
|
+
super(query, cacheKey);
|
|
24448
|
+
this.notifyChange = notifyChange;
|
|
24449
|
+
this.preparePayload = preparePayload;
|
|
23403
24450
|
}
|
|
23404
|
-
|
|
23405
|
-
|
|
23406
|
-
const
|
|
23407
|
-
|
|
23408
|
-
|
|
23409
|
-
|
|
23410
|
-
};
|
|
23411
|
-
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
23412
|
-
for (let i = 0; i < channels.length; i += 1) {
|
|
23413
|
-
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
23414
|
-
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
23415
|
-
let unreadCount = 0;
|
|
23416
|
-
let readToSegment = null;
|
|
23417
|
-
let lastMentionedSegment = null;
|
|
23418
|
-
let isMentioned = false;
|
|
23419
|
-
if (channelUser) {
|
|
23420
|
-
readToSegment = channelUser.readToSegment;
|
|
23421
|
-
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
23422
|
-
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
23423
|
-
isMentioned = lastMentionedSegment > readToSegment;
|
|
24451
|
+
async saveToMainDB(response) {
|
|
24452
|
+
const processedPayload = await this.preparePayload(response);
|
|
24453
|
+
const client = getActiveClient();
|
|
24454
|
+
const cachedAt = client.cache && Date.now();
|
|
24455
|
+
if (client.cache) {
|
|
24456
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23424
24457
|
}
|
|
23425
|
-
const cacheChannelUnread = {
|
|
23426
|
-
channelId: channels[i].channelId,
|
|
23427
|
-
lastSegment: channels[i].messageCount,
|
|
23428
|
-
readToSegment,
|
|
23429
|
-
lastMentionedSegment,
|
|
23430
|
-
unreadCount,
|
|
23431
|
-
isMentioned,
|
|
23432
|
-
isDeleted: channels[i].isDeleted || false,
|
|
23433
|
-
};
|
|
23434
|
-
pushToCache(cacheKey, cacheChannelUnread);
|
|
23435
24458
|
}
|
|
23436
|
-
|
|
23437
|
-
|
|
23438
|
-
|
|
23439
|
-
|
|
23440
|
-
|
|
23441
|
-
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
23442
|
-
rawPayload.messagePreviews &&
|
|
23443
|
-
rawPayload.messagePreviews.length > 0) {
|
|
23444
|
-
updateChannelMessagePreviewCache(rawPayload);
|
|
23445
|
-
}
|
|
23446
|
-
if (client.useLegacyUnreadCount) {
|
|
23447
|
-
updateChannelUnread({
|
|
23448
|
-
channels: rawPayload.channels,
|
|
23449
|
-
channelUsers: rawPayload.channelUsers,
|
|
23450
|
-
currentUserId: client.userId,
|
|
23451
|
-
});
|
|
23452
|
-
}
|
|
23453
|
-
else {
|
|
23454
|
-
const markerIds = rawPayload.channels
|
|
23455
|
-
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
23456
|
-
.filter(isUnreadCountSupport)
|
|
23457
|
-
.map(({ channelInternalId }) => channelInternalId);
|
|
23458
|
-
if (markerIds.length > 0) {
|
|
23459
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
23460
|
-
preUpdateChannelCache(rawPayload, {
|
|
23461
|
-
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
24459
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
24460
|
+
var _a, _b;
|
|
24461
|
+
if (refresh) {
|
|
24462
|
+
pushToCache(this.cacheKey, {
|
|
24463
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
23462
24464
|
});
|
|
23463
|
-
|
|
23464
|
-
|
|
24465
|
+
}
|
|
24466
|
+
else {
|
|
24467
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24468
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24469
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
24470
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
24471
|
+
] }));
|
|
24472
|
+
}
|
|
24473
|
+
}
|
|
24474
|
+
reactor(action) {
|
|
24475
|
+
return (invitations) => {
|
|
24476
|
+
var _a;
|
|
24477
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24478
|
+
if (!collection)
|
|
24479
|
+
return;
|
|
24480
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
24481
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
24482
|
+
if (!isExist)
|
|
24483
|
+
return;
|
|
23465
24484
|
}
|
|
23466
|
-
|
|
23467
|
-
|
|
24485
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
24486
|
+
collection.data = [
|
|
24487
|
+
...new Set([
|
|
24488
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
24489
|
+
...collection.data,
|
|
24490
|
+
]),
|
|
24491
|
+
];
|
|
23468
24492
|
}
|
|
23469
|
-
|
|
24493
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
24494
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
24495
|
+
}
|
|
24496
|
+
pushToCache(this.cacheKey, collection);
|
|
24497
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24498
|
+
};
|
|
23470
24499
|
}
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
return convertRawMembershipToMembership(channelUser);
|
|
23476
|
-
});
|
|
23477
|
-
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
23478
|
-
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
23479
|
-
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
23480
|
-
channels,
|
|
23481
|
-
channelUsers });
|
|
23482
|
-
};
|
|
24500
|
+
subscribeRTE(createSubscriber) {
|
|
24501
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24502
|
+
}
|
|
24503
|
+
}
|
|
23483
24504
|
|
|
23484
24505
|
/**
|
|
23485
24506
|
* ```js
|
|
23486
|
-
* import {
|
|
23487
|
-
* const
|
|
24507
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
24508
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
24509
|
+
* // ...
|
|
24510
|
+
* })
|
|
23488
24511
|
* ```
|
|
23489
24512
|
*
|
|
23490
|
-
*
|
|
24513
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
23491
24514
|
*
|
|
23492
|
-
* @param
|
|
23493
|
-
* @
|
|
23494
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
24515
|
+
* @param callback The function to call when the event was fired
|
|
24516
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23495
24517
|
*
|
|
23496
|
-
* @category
|
|
23497
|
-
* @async
|
|
23498
|
-
* @private
|
|
24518
|
+
* @category Invitation Events
|
|
23499
24519
|
*/
|
|
23500
|
-
const
|
|
24520
|
+
const onLocalInvitationCreated = (callback) => {
|
|
23501
24521
|
const client = getActiveClient();
|
|
23502
|
-
|
|
23503
|
-
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23507
|
-
}
|
|
23508
|
-
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
23509
|
-
return data;
|
|
24522
|
+
const disposers = [
|
|
24523
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
24524
|
+
];
|
|
24525
|
+
return () => {
|
|
24526
|
+
disposers.forEach(fn => fn());
|
|
24527
|
+
};
|
|
23510
24528
|
};
|
|
23511
24529
|
|
|
23512
|
-
|
|
24530
|
+
/**
|
|
24531
|
+
* ```js
|
|
24532
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
24533
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
24534
|
+
* // ...
|
|
24535
|
+
* })
|
|
24536
|
+
* ```
|
|
24537
|
+
*
|
|
24538
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
24539
|
+
*
|
|
24540
|
+
* @param callback The function to call when the event was fired
|
|
24541
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24542
|
+
*
|
|
24543
|
+
* @category Invitation Events
|
|
24544
|
+
*/
|
|
24545
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
23513
24546
|
const client = getActiveClient();
|
|
23514
|
-
|
|
23515
|
-
|
|
23516
|
-
|
|
23517
|
-
|
|
23518
|
-
|
|
23519
|
-
|
|
23520
|
-
userFeedMarkers,
|
|
23521
|
-
});
|
|
23522
|
-
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
24547
|
+
const disposers = [
|
|
24548
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
24549
|
+
];
|
|
24550
|
+
return () => {
|
|
24551
|
+
disposers.forEach(fn => fn());
|
|
24552
|
+
};
|
|
23523
24553
|
};
|
|
23524
24554
|
|
|
23525
|
-
const getCachedMarker$1 = (entityId) => {
|
|
23526
|
-
var _a;
|
|
23527
|
-
const key = {
|
|
23528
|
-
entityId,
|
|
23529
|
-
userId: getActiveUser()._id,
|
|
23530
|
-
};
|
|
23531
|
-
return (_a = pullFromCache([
|
|
23532
|
-
'channelMarker',
|
|
23533
|
-
'get',
|
|
23534
|
-
getResolver('channelMarker')(key),
|
|
23535
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23536
|
-
};
|
|
23537
|
-
const getUnreadInfoCached$1 = (channelId) => {
|
|
23538
|
-
var _a;
|
|
23539
|
-
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23540
|
-
};
|
|
23541
24555
|
/**
|
|
23542
|
-
*
|
|
23543
|
-
*
|
|
24556
|
+
* ```js
|
|
24557
|
+
* import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
|
|
24558
|
+
* const dispose = onLocalInvitationDeleted(data => {
|
|
24559
|
+
* // ...
|
|
24560
|
+
* })
|
|
24561
|
+
* ```
|
|
23544
24562
|
*
|
|
23545
|
-
*
|
|
23546
|
-
*
|
|
23547
|
-
*
|
|
24563
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
24564
|
+
*
|
|
24565
|
+
* @param callback The function to call when the event was fired
|
|
24566
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24567
|
+
*
|
|
24568
|
+
* @category Invitation Events
|
|
23548
24569
|
*/
|
|
23549
|
-
const
|
|
23550
|
-
var _a, _b, _c, _d;
|
|
24570
|
+
const onLocalInvitationDeleted = (callback) => {
|
|
23551
24571
|
const client = getActiveClient();
|
|
23552
|
-
|
|
23553
|
-
|
|
23554
|
-
|
|
23555
|
-
return (
|
|
23556
|
-
|
|
23557
|
-
|
|
24572
|
+
const disposers = [
|
|
24573
|
+
createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload => callback(payload)),
|
|
24574
|
+
];
|
|
24575
|
+
return () => {
|
|
24576
|
+
disposers.forEach(fn => fn());
|
|
24577
|
+
};
|
|
23558
24578
|
};
|
|
23559
24579
|
|
|
23560
|
-
|
|
23561
|
-
|
|
23562
|
-
|
|
23563
|
-
|
|
23564
|
-
|
|
23565
|
-
|
|
23566
|
-
|
|
23567
|
-
|
|
23568
|
-
|
|
23569
|
-
|
|
23570
|
-
|
|
23571
|
-
|
|
23572
|
-
|
|
23573
|
-
|
|
23574
|
-
|
|
23575
|
-
|
|
24580
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
24581
|
+
constructor(query, callback) {
|
|
24582
|
+
const queryStreamId = hash(query);
|
|
24583
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
24584
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
24585
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24586
|
+
this.query = query;
|
|
24587
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
24588
|
+
this.callback = callback.bind(this);
|
|
24589
|
+
this.loadPage({ initial: true });
|
|
24590
|
+
}
|
|
24591
|
+
setup() {
|
|
24592
|
+
var _a;
|
|
24593
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24594
|
+
if (!collection) {
|
|
24595
|
+
pushToCache(this.cacheKey, {
|
|
24596
|
+
data: [],
|
|
24597
|
+
params: this.query,
|
|
24598
|
+
});
|
|
24599
|
+
}
|
|
24600
|
+
}
|
|
24601
|
+
async persistModel(queryPayload) {
|
|
24602
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24603
|
+
}
|
|
24604
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24605
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24606
|
+
}
|
|
24607
|
+
startSubscription() {
|
|
24608
|
+
return this.queryStreamController.subscribeRTE([
|
|
24609
|
+
{
|
|
24610
|
+
fn: onLocalInvitationCreated,
|
|
24611
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
24612
|
+
},
|
|
24613
|
+
{
|
|
24614
|
+
fn: onLocalInvitationUpdated,
|
|
24615
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
24616
|
+
},
|
|
24617
|
+
{
|
|
24618
|
+
fn: onLocalInvitationDeleted,
|
|
24619
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
24620
|
+
},
|
|
24621
|
+
]);
|
|
24622
|
+
}
|
|
24623
|
+
notifyChange({ origin, loading, error }) {
|
|
24624
|
+
var _a, _b;
|
|
24625
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24626
|
+
if (!collection)
|
|
24627
|
+
return;
|
|
24628
|
+
const data = this.applyFilter((_b = collection.data
|
|
24629
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
24630
|
+
.filter(isNonNullable)
|
|
24631
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
24632
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24633
|
+
return;
|
|
24634
|
+
this.callback({
|
|
24635
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24636
|
+
data,
|
|
24637
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24638
|
+
loading,
|
|
24639
|
+
error,
|
|
24640
|
+
});
|
|
24641
|
+
}
|
|
24642
|
+
applyFilter(data) {
|
|
24643
|
+
let invitations = data;
|
|
24644
|
+
if (this.query.targetId) {
|
|
24645
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
24646
|
+
}
|
|
24647
|
+
if (this.query.statuses) {
|
|
24648
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
24649
|
+
}
|
|
24650
|
+
if (this.query.targetType) {
|
|
24651
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
24652
|
+
}
|
|
24653
|
+
if (this.query.type) {
|
|
24654
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
24655
|
+
}
|
|
24656
|
+
const sortFn = (() => {
|
|
24657
|
+
switch (this.query.sortBy) {
|
|
24658
|
+
case 'firstCreated':
|
|
24659
|
+
return sortByFirstCreated;
|
|
24660
|
+
case 'lastCreated':
|
|
24661
|
+
return sortByLastCreated;
|
|
24662
|
+
default:
|
|
24663
|
+
return sortByLastCreated;
|
|
24664
|
+
}
|
|
24665
|
+
})();
|
|
24666
|
+
invitations = invitations.sort(sortFn);
|
|
24667
|
+
return invitations;
|
|
24668
|
+
}
|
|
24669
|
+
}
|
|
24670
|
+
|
|
23576
24671
|
/**
|
|
23577
|
-
*
|
|
23578
|
-
*
|
|
24672
|
+
* Get invitations
|
|
24673
|
+
*
|
|
24674
|
+
* @param params the query parameters
|
|
24675
|
+
* @param callback the callback to be called when the invitations are updated
|
|
24676
|
+
* @returns invitations
|
|
24677
|
+
*
|
|
24678
|
+
* @category Invitation Live Collection
|
|
23579
24679
|
*
|
|
23580
|
-
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
23581
|
-
* If not, the function will return the value from the channelMarker cache.
|
|
23582
|
-
* If not found in the both cache, use `0` as defaul value.
|
|
23583
24680
|
*/
|
|
23584
|
-
const
|
|
23585
|
-
|
|
23586
|
-
|
|
23587
|
-
|
|
23588
|
-
// Marker service API uses channelInternalId as channelId
|
|
23589
|
-
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
23590
|
-
}
|
|
23591
|
-
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
23592
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
23593
|
-
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
23594
|
-
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
23595
|
-
return 0;
|
|
24681
|
+
const getInvitations = (params, callback, config) => {
|
|
24682
|
+
const { log, cache } = getActiveClient();
|
|
24683
|
+
if (!cache) {
|
|
24684
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23596
24685
|
}
|
|
23597
|
-
|
|
24686
|
+
const timestamp = Date.now();
|
|
24687
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
24688
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
24689
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
24690
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
24691
|
+
disposers.push(() => {
|
|
24692
|
+
dropFromCache(cacheKey);
|
|
24693
|
+
});
|
|
24694
|
+
return () => {
|
|
24695
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
24696
|
+
disposers.forEach(fn => fn());
|
|
24697
|
+
};
|
|
23598
24698
|
};
|
|
23599
24699
|
|
|
23600
|
-
const
|
|
23601
|
-
|
|
23602
|
-
|
|
24700
|
+
const communityLinkedObject = (community) => {
|
|
24701
|
+
return Object.assign(Object.assign({}, community), { createInvitations: async (userIds) => {
|
|
24702
|
+
await createInvitations({
|
|
24703
|
+
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
24704
|
+
targetType: 'community',
|
|
24705
|
+
targetId: community.communityId,
|
|
24706
|
+
userIds,
|
|
24707
|
+
});
|
|
24708
|
+
}, getMemberInvitations: (params, callback) => {
|
|
24709
|
+
return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
|
|
24710
|
+
}, getInvitation: async () => {
|
|
24711
|
+
const { data } = await getInvitation('community', community.communityId);
|
|
24712
|
+
return data;
|
|
24713
|
+
}, join: async () => {
|
|
24714
|
+
return joinRequest(community.communityId);
|
|
24715
|
+
}, getJoinRequests: (params, callback) => {
|
|
24716
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
24717
|
+
}, getMyJoinRequest: async () => {
|
|
24718
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
24719
|
+
return data;
|
|
24720
|
+
} });
|
|
23603
24721
|
};
|
|
23604
24722
|
|
|
23605
|
-
const
|
|
23606
|
-
|
|
23607
|
-
|
|
23608
|
-
|
|
23609
|
-
|
|
23610
|
-
|
|
23611
|
-
|
|
23612
|
-
|
|
23613
|
-
|
|
23614
|
-
|
|
23615
|
-
|
|
23616
|
-
|
|
23617
|
-
|
|
23618
|
-
|
|
23619
|
-
|
|
23620
|
-
|
|
23621
|
-
|
|
23622
|
-
});
|
|
24723
|
+
const LinkedObject = {
|
|
24724
|
+
ad: adLinkedObject,
|
|
24725
|
+
comment: commentLinkedObject,
|
|
24726
|
+
post: postLinkedObject,
|
|
24727
|
+
user: userLinkedObject,
|
|
24728
|
+
category: categoryLinkedObject,
|
|
24729
|
+
stream: streamLinkedObject,
|
|
24730
|
+
story: storyLinkedObject,
|
|
24731
|
+
storyTarget: storyTargetLinkedObject,
|
|
24732
|
+
message: messageLinkedObject,
|
|
24733
|
+
reactor: reactorLinkedObject,
|
|
24734
|
+
channel: channelLinkedObject,
|
|
24735
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
24736
|
+
notificationTray: notificationTrayLinkedObject,
|
|
24737
|
+
community: communityLinkedObject,
|
|
24738
|
+
invitation: invitationLinkedObject,
|
|
24739
|
+
joinRequest: joinRequestLinkedObject,
|
|
23623
24740
|
};
|
|
23624
24741
|
|
|
23625
24742
|
const constructChannelObject = (channel) => {
|
|
@@ -26341,38 +27458,6 @@ const onMessageMarked = (callback) => {
|
|
|
26341
27458
|
return createEventSubscriber(client, 'messageMarker/onMessageMarked', 'marker.marked-message', filter);
|
|
26342
27459
|
};
|
|
26343
27460
|
|
|
26344
|
-
function isObject(value) {
|
|
26345
|
-
return typeof value === 'object' && value !== null;
|
|
26346
|
-
}
|
|
26347
|
-
/**
|
|
26348
|
-
* convert all object getter property to static value
|
|
26349
|
-
*/
|
|
26350
|
-
const convertGetterPropsToStatic = (obj) => {
|
|
26351
|
-
if (!isObject(obj)) {
|
|
26352
|
-
return obj;
|
|
26353
|
-
}
|
|
26354
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
26355
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
26356
|
-
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
26357
|
-
return [key, descriptor.get.call(obj)];
|
|
26358
|
-
}
|
|
26359
|
-
return [key, value];
|
|
26360
|
-
});
|
|
26361
|
-
return Object.fromEntries(entries);
|
|
26362
|
-
};
|
|
26363
|
-
const removeFunctionProperties = (obj) => {
|
|
26364
|
-
if (!isObject(obj)) {
|
|
26365
|
-
return obj;
|
|
26366
|
-
}
|
|
26367
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
26368
|
-
if (typeof value === 'function') {
|
|
26369
|
-
return [key, undefined];
|
|
26370
|
-
}
|
|
26371
|
-
return [key, value];
|
|
26372
|
-
});
|
|
26373
|
-
return Object.fromEntries(entries);
|
|
26374
|
-
};
|
|
26375
|
-
|
|
26376
27461
|
/**
|
|
26377
27462
|
*
|
|
26378
27463
|
* ```js
|
|
@@ -26986,51 +28071,6 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
26986
28071
|
|
|
26987
28072
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26988
28073
|
|
|
26989
|
-
class PaginationController {
|
|
26990
|
-
constructor(queryParams) {
|
|
26991
|
-
const { http } = getActiveClient();
|
|
26992
|
-
this.queryParams = queryParams;
|
|
26993
|
-
this.http = http;
|
|
26994
|
-
}
|
|
26995
|
-
loadFirstPage() {
|
|
26996
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
26997
|
-
}
|
|
26998
|
-
loadNextPage() {
|
|
26999
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
27000
|
-
}
|
|
27001
|
-
loadPreviousPage() {
|
|
27002
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
27003
|
-
}
|
|
27004
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
27005
|
-
var _a, _b, _c, _d;
|
|
27006
|
-
if (direction === 'prev' && !this.previousToken)
|
|
27007
|
-
return;
|
|
27008
|
-
if (direction === 'next' && !this.nextToken)
|
|
27009
|
-
return;
|
|
27010
|
-
let token;
|
|
27011
|
-
if (direction === 'prev')
|
|
27012
|
-
token = this.previousToken;
|
|
27013
|
-
if (direction === 'next')
|
|
27014
|
-
token = this.nextToken;
|
|
27015
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
27016
|
-
if (direction === 'first') {
|
|
27017
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
27018
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
27019
|
-
}
|
|
27020
|
-
if (direction === 'prev')
|
|
27021
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
27022
|
-
if (direction === 'next')
|
|
27023
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
27024
|
-
return queryResponse;
|
|
27025
|
-
}
|
|
27026
|
-
getNextToken() {
|
|
27027
|
-
return this.nextToken;
|
|
27028
|
-
}
|
|
27029
|
-
getPrevToken() {
|
|
27030
|
-
return this.previousToken;
|
|
27031
|
-
}
|
|
27032
|
-
}
|
|
27033
|
-
|
|
27034
28074
|
class FollowerPaginationController extends PaginationController {
|
|
27035
28075
|
async getRequest(queryParams, token) {
|
|
27036
28076
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
@@ -27044,13 +28084,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
27044
28084
|
}
|
|
27045
28085
|
}
|
|
27046
28086
|
|
|
27047
|
-
class QueryStreamController {
|
|
27048
|
-
constructor(query, cacheKey) {
|
|
27049
|
-
this.query = query;
|
|
27050
|
-
this.cacheKey = cacheKey;
|
|
27051
|
-
}
|
|
27052
|
-
}
|
|
27053
|
-
|
|
27054
28087
|
var EnumFollowActions;
|
|
27055
28088
|
(function (EnumFollowActions) {
|
|
27056
28089
|
EnumFollowActions["OnRequested"] = "onRequested";
|
|
@@ -27118,109 +28151,6 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
27118
28151
|
}
|
|
27119
28152
|
}
|
|
27120
28153
|
|
|
27121
|
-
class PaginationNoPageController {
|
|
27122
|
-
constructor(queryParams) {
|
|
27123
|
-
const { http } = getActiveClient();
|
|
27124
|
-
this.queryParams = queryParams;
|
|
27125
|
-
this.http = http;
|
|
27126
|
-
}
|
|
27127
|
-
async onFetch() {
|
|
27128
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
27129
|
-
return queryResponse;
|
|
27130
|
-
}
|
|
27131
|
-
}
|
|
27132
|
-
|
|
27133
|
-
class LiveCollectionController {
|
|
27134
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
27135
|
-
this.paginationController = paginationController;
|
|
27136
|
-
this.queryStreamId = queryStreamId;
|
|
27137
|
-
this.cacheKey = cacheKey;
|
|
27138
|
-
this.callback = callback;
|
|
27139
|
-
}
|
|
27140
|
-
async refresh() {
|
|
27141
|
-
try {
|
|
27142
|
-
let result;
|
|
27143
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
27144
|
-
result = await this.paginationController.onFetch();
|
|
27145
|
-
}
|
|
27146
|
-
else {
|
|
27147
|
-
result = await this.paginationController.loadFirstPage();
|
|
27148
|
-
}
|
|
27149
|
-
if (!result)
|
|
27150
|
-
return;
|
|
27151
|
-
await this.persistModel(result);
|
|
27152
|
-
this.persistQueryStream({
|
|
27153
|
-
response: result,
|
|
27154
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27155
|
-
refresh: true,
|
|
27156
|
-
});
|
|
27157
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27158
|
-
}
|
|
27159
|
-
catch (e) {
|
|
27160
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27161
|
-
}
|
|
27162
|
-
}
|
|
27163
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
27164
|
-
this.setup();
|
|
27165
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
27166
|
-
if (initial) {
|
|
27167
|
-
this.refresh();
|
|
27168
|
-
}
|
|
27169
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
27170
|
-
this.loadPrevPage();
|
|
27171
|
-
}
|
|
27172
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
27173
|
-
this.loadNextPage();
|
|
27174
|
-
}
|
|
27175
|
-
}
|
|
27176
|
-
async loadNextPage() {
|
|
27177
|
-
try {
|
|
27178
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
27179
|
-
return;
|
|
27180
|
-
const result = await this.paginationController.loadNextPage();
|
|
27181
|
-
if (!result)
|
|
27182
|
-
return;
|
|
27183
|
-
await this.persistModel(result);
|
|
27184
|
-
this.persistQueryStream({
|
|
27185
|
-
response: result,
|
|
27186
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27187
|
-
});
|
|
27188
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27189
|
-
}
|
|
27190
|
-
catch (e) {
|
|
27191
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27192
|
-
}
|
|
27193
|
-
}
|
|
27194
|
-
async loadPrevPage() {
|
|
27195
|
-
try {
|
|
27196
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
27197
|
-
return;
|
|
27198
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
27199
|
-
if (!result)
|
|
27200
|
-
return;
|
|
27201
|
-
await this.persistModel(result);
|
|
27202
|
-
this.persistQueryStream({
|
|
27203
|
-
response: result,
|
|
27204
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
27205
|
-
});
|
|
27206
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27207
|
-
}
|
|
27208
|
-
catch (e) {
|
|
27209
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27210
|
-
}
|
|
27211
|
-
}
|
|
27212
|
-
shouldNotify(data) {
|
|
27213
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
27214
|
-
if (isEqual(this.snapshot, newData))
|
|
27215
|
-
return false;
|
|
27216
|
-
this.snapshot = newData;
|
|
27217
|
-
return true;
|
|
27218
|
-
}
|
|
27219
|
-
getCacheKey() {
|
|
27220
|
-
return this.cacheKey;
|
|
27221
|
-
}
|
|
27222
|
-
}
|
|
27223
|
-
|
|
27224
28154
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27225
28155
|
const client = getActiveClient();
|
|
27226
28156
|
const filter = (data) => {
|
|
@@ -29363,41 +30293,6 @@ getComment$2.locally = (commentId) => {
|
|
|
29363
30293
|
};
|
|
29364
30294
|
};
|
|
29365
30295
|
|
|
29366
|
-
/*
|
|
29367
|
-
* verifies membership status
|
|
29368
|
-
*/
|
|
29369
|
-
function isMember(membership) {
|
|
29370
|
-
return membership !== 'none';
|
|
29371
|
-
}
|
|
29372
|
-
/*
|
|
29373
|
-
* checks if currently logged in user is part of the community
|
|
29374
|
-
*/
|
|
29375
|
-
function isCurrentUserPartOfCommunity(c, m) {
|
|
29376
|
-
const { userId } = getActiveUser();
|
|
29377
|
-
return c.communityId === m.communityId && m.userId === userId;
|
|
29378
|
-
}
|
|
29379
|
-
/*
|
|
29380
|
-
* For mqtt events server will not send user specific data as it's broadcasted
|
|
29381
|
-
* to multiple users and it also does not include communityUser
|
|
29382
|
-
*
|
|
29383
|
-
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
29384
|
-
* Althought this can be calculated, it's not scalable.
|
|
29385
|
-
*/
|
|
29386
|
-
function updateMembershipStatus(communities, communityUsers) {
|
|
29387
|
-
return communities.map(c => {
|
|
29388
|
-
const cachedCommunity = pullFromCache([
|
|
29389
|
-
'community',
|
|
29390
|
-
'get',
|
|
29391
|
-
c.communityId,
|
|
29392
|
-
]);
|
|
29393
|
-
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
29394
|
-
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
29395
|
-
}
|
|
29396
|
-
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
29397
|
-
return Object.assign(Object.assign({}, c), { isJoined });
|
|
29398
|
-
});
|
|
29399
|
-
}
|
|
29400
|
-
|
|
29401
30296
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
29402
30297
|
var _a, _b;
|
|
29403
30298
|
let id;
|
|
@@ -29712,53 +30607,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
29712
30607
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
29713
30608
|
};
|
|
29714
30609
|
|
|
29715
|
-
const getMatchPostSetting = (value) => {
|
|
29716
|
-
var _a;
|
|
29717
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
29718
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
29719
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
29720
|
-
};
|
|
29721
|
-
function addPostSetting({ communities }) {
|
|
29722
|
-
return communities.map((_a) => {
|
|
29723
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
29724
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
29725
|
-
needApprovalOnPostCreation,
|
|
29726
|
-
onlyAdminCanPost,
|
|
29727
|
-
}) }, restCommunityPayload));
|
|
29728
|
-
});
|
|
29729
|
-
}
|
|
29730
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
29731
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29732
|
-
// map users with community
|
|
29733
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29734
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29735
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29736
|
-
});
|
|
29737
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29738
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29739
|
-
};
|
|
29740
|
-
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
29741
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
29742
|
-
// map users with community
|
|
29743
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
29744
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
29745
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
29746
|
-
});
|
|
29747
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
29748
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29749
|
-
};
|
|
29750
|
-
const prepareCommunityRequest = (params) => {
|
|
29751
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
29752
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
29753
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
29754
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
29755
|
-
};
|
|
29756
|
-
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
29757
|
-
var communityPayload = __rest(_a, ["searchResult"]);
|
|
29758
|
-
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
29759
|
-
return Object.assign({}, processedCommunityPayload);
|
|
29760
|
-
};
|
|
29761
|
-
|
|
29762
30610
|
const preparePostPayload = (payload) => {
|
|
29763
30611
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
29764
30612
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -34819,12 +35667,15 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34819
35667
|
* @category Community API
|
|
34820
35668
|
* @async
|
|
34821
35669
|
*/
|
|
34822
|
-
const getCommunities$1 = async (communityIds) => {
|
|
35670
|
+
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
34823
35671
|
const client = getActiveClient();
|
|
34824
35672
|
client.log('community/getCommunities', communityIds);
|
|
34825
35673
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
34826
35674
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
34827
|
-
params: {
|
|
35675
|
+
params: {
|
|
35676
|
+
communityIds,
|
|
35677
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35678
|
+
},
|
|
34828
35679
|
});
|
|
34829
35680
|
const data = prepareCommunityPayload(payload);
|
|
34830
35681
|
const cachedAt = client.cache && Date.now();
|
|
@@ -34911,7 +35762,7 @@ const createCommunity = async (bundle) => {
|
|
|
34911
35762
|
/**
|
|
34912
35763
|
* ```js
|
|
34913
35764
|
* import { updateCommunity } from '@amityco/ts-sdk'
|
|
34914
|
-
* const updated = await updateCommunity(communityId, { displayName: 'foobar' })
|
|
35765
|
+
* const updated = await updateCommunity(communityId, { displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
34915
35766
|
* ```
|
|
34916
35767
|
*
|
|
34917
35768
|
* Updates an {@link Amity.Community}
|
|
@@ -34956,11 +35807,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
34956
35807
|
* @category Community API
|
|
34957
35808
|
* @async
|
|
34958
35809
|
*/
|
|
34959
|
-
const getCommunity$1 = async (communityId) => {
|
|
35810
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
34960
35811
|
const client = getActiveClient();
|
|
34961
35812
|
client.log('community/getCommunity', communityId);
|
|
34962
35813
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
34963
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
35814
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
35815
|
+
params: {
|
|
35816
|
+
type: 'communityJoinRequest',
|
|
35817
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35818
|
+
},
|
|
35819
|
+
});
|
|
34964
35820
|
const data = prepareCommunityPayload(payload);
|
|
34965
35821
|
const cachedAt = client.cache && Date.now();
|
|
34966
35822
|
if (client.cache) {
|
|
@@ -34995,7 +35851,7 @@ getCommunity$1.locally = (communityId) => {
|
|
|
34995
35851
|
if (!cached)
|
|
34996
35852
|
return;
|
|
34997
35853
|
return {
|
|
34998
|
-
data: cached.data,
|
|
35854
|
+
data: LinkedObject.community(cached.data),
|
|
34999
35855
|
cachedAt: cached.cachedAt,
|
|
35000
35856
|
};
|
|
35001
35857
|
};
|
|
@@ -35035,6 +35891,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
35035
35891
|
};
|
|
35036
35892
|
/* end_public_function */
|
|
35037
35893
|
|
|
35894
|
+
/**
|
|
35895
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
35896
|
+
*/
|
|
35038
35897
|
/* begin_public_function
|
|
35039
35898
|
id: community.join
|
|
35040
35899
|
*/
|
|
@@ -35175,10 +36034,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
35175
36034
|
*/
|
|
35176
36035
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35177
36036
|
async getRequest(queryParams, token) {
|
|
36037
|
+
var _a;
|
|
35178
36038
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35179
36039
|
const options = token ? { token } : { limit };
|
|
35180
36040
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35181
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
36041
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, includeDiscoverablePrivateCommunity: (_a = params.includeDiscoverablePrivateCommunity) !== null && _a !== void 0 ? _a : true, options }),
|
|
35182
36042
|
});
|
|
35183
36043
|
return queryResponse;
|
|
35184
36044
|
}
|
|
@@ -36625,7 +37485,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36625
37485
|
const data = (_b = collection.data
|
|
36626
37486
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36627
37487
|
.filter(isNonNullable)
|
|
36628
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37488
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
36629
37489
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36630
37490
|
return;
|
|
36631
37491
|
this.callback({
|
|
@@ -36787,7 +37647,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
36787
37647
|
const data = (_b = collection.data
|
|
36788
37648
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36789
37649
|
.filter(isNonNullable)
|
|
36790
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37650
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
36791
37651
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36792
37652
|
return;
|
|
36793
37653
|
this.callback({
|
|
@@ -39437,7 +40297,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39437
40297
|
const client = getActiveClient();
|
|
39438
40298
|
const cachedAt = client.cache && Date.now();
|
|
39439
40299
|
if (client.cache) {
|
|
39440
|
-
|
|
40300
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
40301
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39441
40302
|
}
|
|
39442
40303
|
}
|
|
39443
40304
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -39566,7 +40427,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39566
40427
|
const client = getActiveClient();
|
|
39567
40428
|
const cachedAt = client.cache && Date.now();
|
|
39568
40429
|
if (client.cache) {
|
|
39569
|
-
|
|
40430
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
40431
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39570
40432
|
}
|
|
39571
40433
|
}
|
|
39572
40434
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -42720,34 +43582,204 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
42720
43582
|
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
42721
43583
|
});
|
|
42722
43584
|
|
|
43585
|
+
class MyInvitationsPaginationController extends PaginationController {
|
|
43586
|
+
async getRequest(queryParams, token) {
|
|
43587
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
43588
|
+
const options = token ? { token } : { limit };
|
|
43589
|
+
const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
43590
|
+
await getCommunities$1(data.invitations.map(invitation => invitation.targetId));
|
|
43591
|
+
return data;
|
|
43592
|
+
}
|
|
43593
|
+
}
|
|
43594
|
+
|
|
43595
|
+
class MyInvitationsQueryStreamController extends QueryStreamController {
|
|
43596
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
43597
|
+
super(query, cacheKey);
|
|
43598
|
+
this.notifyChange = notifyChange;
|
|
43599
|
+
this.preparePayload = preparePayload;
|
|
43600
|
+
}
|
|
43601
|
+
async saveToMainDB(response) {
|
|
43602
|
+
const processedPayload = await this.preparePayload(response);
|
|
43603
|
+
const client = getActiveClient();
|
|
43604
|
+
const cachedAt = client.cache && Date.now();
|
|
43605
|
+
if (client.cache) {
|
|
43606
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
43607
|
+
}
|
|
43608
|
+
}
|
|
43609
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
43610
|
+
var _a, _b;
|
|
43611
|
+
if (refresh) {
|
|
43612
|
+
pushToCache(this.cacheKey, {
|
|
43613
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
43614
|
+
});
|
|
43615
|
+
}
|
|
43616
|
+
else {
|
|
43617
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43618
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
43619
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
43620
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
43621
|
+
] }));
|
|
43622
|
+
}
|
|
43623
|
+
}
|
|
43624
|
+
reactor(action) {
|
|
43625
|
+
return (invitations) => {
|
|
43626
|
+
var _a;
|
|
43627
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43628
|
+
if (!collection)
|
|
43629
|
+
return;
|
|
43630
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
43631
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
43632
|
+
if (!isExist)
|
|
43633
|
+
return;
|
|
43634
|
+
}
|
|
43635
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
43636
|
+
const client = getActiveClient();
|
|
43637
|
+
const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
|
|
43638
|
+
collection.data = [
|
|
43639
|
+
...new Set([
|
|
43640
|
+
...myInvitations.map(invitation => invitation.invitationId),
|
|
43641
|
+
...collection.data,
|
|
43642
|
+
]),
|
|
43643
|
+
];
|
|
43644
|
+
}
|
|
43645
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
43646
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
43647
|
+
}
|
|
43648
|
+
pushToCache(this.cacheKey, collection);
|
|
43649
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
43650
|
+
};
|
|
43651
|
+
}
|
|
43652
|
+
subscribeRTE(createSubscriber) {
|
|
43653
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
43654
|
+
}
|
|
43655
|
+
}
|
|
43656
|
+
|
|
43657
|
+
class MyInvitationsLiveCollectionController extends LiveCollectionController {
|
|
43658
|
+
constructor(query, callback) {
|
|
43659
|
+
const queryStreamId = hash(query);
|
|
43660
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
43661
|
+
const paginationController = new MyInvitationsPaginationController(query);
|
|
43662
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
43663
|
+
this.query = query;
|
|
43664
|
+
this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
|
|
43665
|
+
this.callback = callback.bind(this);
|
|
43666
|
+
this.loadPage({ initial: true });
|
|
43667
|
+
}
|
|
43668
|
+
setup() {
|
|
43669
|
+
var _a;
|
|
43670
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43671
|
+
if (!collection) {
|
|
43672
|
+
pushToCache(this.cacheKey, {
|
|
43673
|
+
data: [],
|
|
43674
|
+
params: this.query,
|
|
43675
|
+
});
|
|
43676
|
+
}
|
|
43677
|
+
}
|
|
43678
|
+
async persistModel(queryPayload) {
|
|
43679
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
43680
|
+
}
|
|
43681
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
43682
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
43683
|
+
}
|
|
43684
|
+
startSubscription() {
|
|
43685
|
+
return this.queryStreamController.subscribeRTE([
|
|
43686
|
+
{
|
|
43687
|
+
fn: onLocalInvitationCreated,
|
|
43688
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
43689
|
+
},
|
|
43690
|
+
{
|
|
43691
|
+
fn: onLocalInvitationUpdated,
|
|
43692
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
43693
|
+
},
|
|
43694
|
+
{
|
|
43695
|
+
fn: onLocalInvitationDeleted,
|
|
43696
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
43697
|
+
},
|
|
43698
|
+
]);
|
|
43699
|
+
}
|
|
43700
|
+
notifyChange({ origin, loading, error }) {
|
|
43701
|
+
var _a, _b;
|
|
43702
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43703
|
+
if (!collection)
|
|
43704
|
+
return;
|
|
43705
|
+
const data = this.applyFilter((_b = collection.data
|
|
43706
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
43707
|
+
.filter(isNonNullable)
|
|
43708
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
43709
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
43710
|
+
return;
|
|
43711
|
+
this.callback({
|
|
43712
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
43713
|
+
data,
|
|
43714
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
43715
|
+
loading,
|
|
43716
|
+
error,
|
|
43717
|
+
});
|
|
43718
|
+
}
|
|
43719
|
+
applyFilter(data) {
|
|
43720
|
+
let invitations = data;
|
|
43721
|
+
if (this.query.targetId) {
|
|
43722
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
43723
|
+
}
|
|
43724
|
+
if (this.query.statuses) {
|
|
43725
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
43726
|
+
}
|
|
43727
|
+
if (this.query.targetType) {
|
|
43728
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
43729
|
+
}
|
|
43730
|
+
if (this.query.type) {
|
|
43731
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
43732
|
+
}
|
|
43733
|
+
const sortFn = (() => {
|
|
43734
|
+
switch (this.query.sortBy) {
|
|
43735
|
+
case 'firstCreated':
|
|
43736
|
+
return sortByFirstCreated;
|
|
43737
|
+
case 'lastCreated':
|
|
43738
|
+
return sortByLastCreated;
|
|
43739
|
+
default:
|
|
43740
|
+
return sortByLastCreated;
|
|
43741
|
+
}
|
|
43742
|
+
})();
|
|
43743
|
+
invitations = invitations.sort(sortFn);
|
|
43744
|
+
return invitations;
|
|
43745
|
+
}
|
|
43746
|
+
}
|
|
43747
|
+
|
|
42723
43748
|
/**
|
|
42724
|
-
*
|
|
42725
|
-
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
42726
|
-
* const dispose = onLocalInvitationCreated(data => {
|
|
42727
|
-
* // ...
|
|
42728
|
-
* })
|
|
42729
|
-
* ```
|
|
43749
|
+
* Get my community invitations
|
|
42730
43750
|
*
|
|
42731
|
-
*
|
|
43751
|
+
* @param params the query parameters
|
|
43752
|
+
* @param callback the callback to be called when the invitations are fetched
|
|
43753
|
+
* @returns invitations
|
|
42732
43754
|
*
|
|
42733
|
-
* @
|
|
42734
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43755
|
+
* @category My Community Invitations Live Collection
|
|
42735
43756
|
*
|
|
42736
|
-
* @category Invitation Events
|
|
42737
43757
|
*/
|
|
42738
|
-
const
|
|
42739
|
-
const
|
|
42740
|
-
|
|
42741
|
-
|
|
42742
|
-
|
|
43758
|
+
const getMyCommunityInvitations = (params, callback, config) => {
|
|
43759
|
+
const { log, cache } = getActiveClient();
|
|
43760
|
+
if (!cache) {
|
|
43761
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
43762
|
+
}
|
|
43763
|
+
const timestamp = Date.now();
|
|
43764
|
+
log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
|
|
43765
|
+
const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
|
|
43766
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
43767
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
43768
|
+
disposers.push(() => {
|
|
43769
|
+
dropFromCache(cacheKey);
|
|
43770
|
+
});
|
|
42743
43771
|
return () => {
|
|
43772
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
42744
43773
|
disposers.forEach(fn => fn());
|
|
42745
43774
|
};
|
|
42746
43775
|
};
|
|
42747
43776
|
|
|
42748
43777
|
var index = /*#__PURE__*/Object.freeze({
|
|
42749
43778
|
__proto__: null,
|
|
42750
|
-
onLocalInvitationCreated: onLocalInvitationCreated
|
|
43779
|
+
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
43780
|
+
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
43781
|
+
onLocalInvitationDeleted: onLocalInvitationDeleted,
|
|
43782
|
+
getMyCommunityInvitations: getMyCommunityInvitations
|
|
42751
43783
|
});
|
|
42752
43784
|
|
|
42753
|
-
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, 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 };
|
|
43785
|
+
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, JoinRequestStatusEnum, JoinResultStatusEnum, 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 };
|