@amityco/ts-sdk 7.4.1-d23fab2f.0 → 7.4.1-e8631ca7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +3 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +14 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +4 -0
- 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/communityRepository/api/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.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/updateCommunity.d.ts +2 -2
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/index.cjs.js +1849 -1325
- package/dist/index.esm.js +2067 -1543
- 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/utils/linkedObject/communityLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +2 -2
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +3 -3
- package/src/@types/core/payload.ts +17 -0
- package/src/@types/domains/community.ts +7 -0
- package/src/@types/domains/invitation.ts +67 -3
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +1 -1
- package/src/communityRepository/api/getRecommendedCommunities.ts +9 -3
- package/src/communityRepository/api/getTrendingCommunities.ts +9 -3
- package/src/communityRepository/api/updateCommunity.ts +9 -2
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- 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/utils/linkedObject/communityLinkedObject.ts +21 -1
- package/src/utils/linkedObject/invitationLinkedObject.ts +25 -1
package/dist/index.esm.js
CHANGED
|
@@ -114,7 +114,12 @@ 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 = {}));
|
|
118
123
|
|
|
119
124
|
function getVersion() {
|
|
120
125
|
try {
|
|
@@ -20990,6 +20995,1102 @@ const getChannelMessagePreview = (channelId) => {
|
|
|
20990
20995
|
return ((_b = (_a = pullFromCache(['messagePreviewChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
20991
20996
|
};
|
|
20992
20997
|
|
|
20998
|
+
const userLinkedObject = (user) => {
|
|
20999
|
+
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
21000
|
+
var _a;
|
|
21001
|
+
if (!user.avatarFileId)
|
|
21002
|
+
return undefined;
|
|
21003
|
+
const avatar = (_a = pullFromCache([
|
|
21004
|
+
'file',
|
|
21005
|
+
'get',
|
|
21006
|
+
`${user.avatarFileId}`,
|
|
21007
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21008
|
+
return avatar;
|
|
21009
|
+
} });
|
|
21010
|
+
};
|
|
21011
|
+
|
|
21012
|
+
const getChannelMessagePreviewWithUser = (channel) => {
|
|
21013
|
+
var _a;
|
|
21014
|
+
const messagePreview = channel.messagePreviewId
|
|
21015
|
+
? getChannelMessagePreview(channel.channelId)
|
|
21016
|
+
: null;
|
|
21017
|
+
const internalUser = (_a = pullFromCache([
|
|
21018
|
+
'user',
|
|
21019
|
+
'get',
|
|
21020
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
21021
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21022
|
+
const messagePreviewWithUser = messagePreview
|
|
21023
|
+
? Object.assign(Object.assign({}, messagePreview), { user: internalUser ? userLinkedObject(internalUser) : undefined }) : null;
|
|
21024
|
+
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
21025
|
+
};
|
|
21026
|
+
|
|
21027
|
+
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
21028
|
+
var _a, _b;
|
|
21029
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21030
|
+
var _a;
|
|
21031
|
+
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21032
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21033
|
+
});
|
|
21034
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, data, dataType, isDeleted, segment, creatorPublicId: creatorId, createdAt, updatedAt, } = messagePreview;
|
|
21035
|
+
return {
|
|
21036
|
+
channelId,
|
|
21037
|
+
subChannelId,
|
|
21038
|
+
data,
|
|
21039
|
+
dataType,
|
|
21040
|
+
isDeleted,
|
|
21041
|
+
segment,
|
|
21042
|
+
creatorId,
|
|
21043
|
+
createdAt,
|
|
21044
|
+
updatedAt,
|
|
21045
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21046
|
+
messagePreviewId: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.messagePreviewId,
|
|
21047
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21048
|
+
};
|
|
21049
|
+
};
|
|
21050
|
+
const newData = {
|
|
21051
|
+
messagePreviewChannel: (_b = (_a = rawPayload.messagePreviews) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21052
|
+
};
|
|
21053
|
+
ingestInCache(newData);
|
|
21054
|
+
};
|
|
21055
|
+
|
|
21056
|
+
const getSubChannelMessagePreview = (subChannelId) => {
|
|
21057
|
+
var _a, _b;
|
|
21058
|
+
return ((_b = (_a = pullFromCache(['messagePreviewSubChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : null);
|
|
21059
|
+
};
|
|
21060
|
+
|
|
21061
|
+
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
21062
|
+
var _a;
|
|
21063
|
+
const messagePreview = subChannel.messagePreviewId
|
|
21064
|
+
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
21065
|
+
: null;
|
|
21066
|
+
const messagePreviewWithUser = messagePreview
|
|
21067
|
+
? Object.assign(Object.assign({}, messagePreview), { user: (_a = pullFromCache(['user', 'get', messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId])) === null || _a === void 0 ? void 0 : _a.data }) : null;
|
|
21068
|
+
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
21069
|
+
};
|
|
21070
|
+
|
|
21071
|
+
const updateSubChannelMessagePreviewCache = (rawPayload) => {
|
|
21072
|
+
var _a, _b;
|
|
21073
|
+
const withMessageFeedInfo = (messagePreview) => {
|
|
21074
|
+
var _a;
|
|
21075
|
+
const messageFeedInfo = (_a = rawPayload.messageFeeds) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
21076
|
+
return messageFeed.messageFeedId === messagePreview.messageFeedId;
|
|
21077
|
+
});
|
|
21078
|
+
const { channelPublicId: channelId, messageFeedId: subChannelId, messageId: messagePreviewId, creatorPublicId: creatorId, data, dataType, isDeleted, segment, createdAt, updatedAt, } = messagePreview;
|
|
21079
|
+
return {
|
|
21080
|
+
messagePreviewId,
|
|
21081
|
+
channelId,
|
|
21082
|
+
subChannelId,
|
|
21083
|
+
data,
|
|
21084
|
+
dataType,
|
|
21085
|
+
isDeleted,
|
|
21086
|
+
segment,
|
|
21087
|
+
creatorId,
|
|
21088
|
+
createdAt,
|
|
21089
|
+
updatedAt,
|
|
21090
|
+
subChannelName: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.name,
|
|
21091
|
+
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21092
|
+
};
|
|
21093
|
+
};
|
|
21094
|
+
const newData = {
|
|
21095
|
+
messagePreviewSubChannel: (_b = (_a = rawPayload.messages) === null || _a === void 0 ? void 0 : _a.map(messagePreview => withMessageFeedInfo(messagePreview))) !== null && _b !== void 0 ? _b : [],
|
|
21096
|
+
};
|
|
21097
|
+
ingestInCache(newData);
|
|
21098
|
+
};
|
|
21099
|
+
|
|
21100
|
+
/**
|
|
21101
|
+
* ```js
|
|
21102
|
+
* import { shallowClone } from '~/utils/shallowClone'
|
|
21103
|
+
* const newObj = shallowClone(obj)
|
|
21104
|
+
* ```
|
|
21105
|
+
*
|
|
21106
|
+
* Clone an object with same prototype and properties
|
|
21107
|
+
*
|
|
21108
|
+
* @param obj the object to clone
|
|
21109
|
+
* @returns new object with same prototype and properties
|
|
21110
|
+
*
|
|
21111
|
+
* @category utility
|
|
21112
|
+
* @private
|
|
21113
|
+
*/
|
|
21114
|
+
function shallowClone(source, target) {
|
|
21115
|
+
return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
|
|
21116
|
+
}
|
|
21117
|
+
|
|
21118
|
+
function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
21119
|
+
pushToCache(['subChannel', 'get', subChannelId],
|
|
21120
|
+
// eslint-disable-next-line prefer-object-spread
|
|
21121
|
+
shallowClone(subChannel, params));
|
|
21122
|
+
}
|
|
21123
|
+
|
|
21124
|
+
/**
|
|
21125
|
+
* ```js
|
|
21126
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
21127
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
21128
|
+
* ```
|
|
21129
|
+
*
|
|
21130
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
21131
|
+
* in cache and it's not expired means it's in tombstone
|
|
21132
|
+
* and we throw an Error
|
|
21133
|
+
*
|
|
21134
|
+
* @param model the model to check
|
|
21135
|
+
* @param modelId the object id to check
|
|
21136
|
+
* @returns the matching cache entry, or undefined.
|
|
21137
|
+
*
|
|
21138
|
+
* @category Cache API
|
|
21139
|
+
*/
|
|
21140
|
+
const isInTombstone = (model, modelId) => {
|
|
21141
|
+
const { log, cache } = getActiveClient();
|
|
21142
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
21143
|
+
if (!cache)
|
|
21144
|
+
return;
|
|
21145
|
+
log('cache/api/isInTombstone', key);
|
|
21146
|
+
const isInTombstone = pullFromCache(key);
|
|
21147
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
21148
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
21149
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
21150
|
+
}
|
|
21151
|
+
};
|
|
21152
|
+
|
|
21153
|
+
/**
|
|
21154
|
+
* ```js
|
|
21155
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
21156
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
21157
|
+
* ```
|
|
21158
|
+
*
|
|
21159
|
+
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
21160
|
+
*
|
|
21161
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
21162
|
+
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
21163
|
+
*
|
|
21164
|
+
* @category Channel API
|
|
21165
|
+
* @async
|
|
21166
|
+
* @private
|
|
21167
|
+
*/
|
|
21168
|
+
const getMessageMarkers = async (messageIds) => {
|
|
21169
|
+
const client = getActiveClient();
|
|
21170
|
+
client.log('channel/getMessageMarkers', messageIds);
|
|
21171
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
21172
|
+
params: {
|
|
21173
|
+
messageIds,
|
|
21174
|
+
},
|
|
21175
|
+
});
|
|
21176
|
+
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
21177
|
+
const cachedAt = client.cache && Date.now();
|
|
21178
|
+
if (client.cache)
|
|
21179
|
+
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
21180
|
+
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
21181
|
+
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
21182
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21183
|
+
return { data: contentMarkers, cachedAt };
|
|
21184
|
+
};
|
|
21185
|
+
|
|
21186
|
+
const reCalculateChannelUnreadInfo = (channelId) => {
|
|
21187
|
+
var _a;
|
|
21188
|
+
const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
|
|
21189
|
+
const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21190
|
+
const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
|
|
21191
|
+
const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
|
|
21192
|
+
let channelUnreads = 0;
|
|
21193
|
+
let isMentioned = false;
|
|
21194
|
+
if (cachedSubChannelUnreadInfo && (cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.length) > 0) {
|
|
21195
|
+
const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
|
|
21196
|
+
return data.channelId === channelId && !data.isDeleted;
|
|
21197
|
+
});
|
|
21198
|
+
channelUnreads = subChannelUnreadsInfo
|
|
21199
|
+
.map(({ data }) => data.unreadCount)
|
|
21200
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
21201
|
+
isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
|
|
21202
|
+
}
|
|
21203
|
+
const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
|
|
21204
|
+
channelId,
|
|
21205
|
+
createdAt: new Date().toISOString(),
|
|
21206
|
+
})), { updatedAt: new Date().toISOString(), unreadCount: channelUnreads, isMentioned });
|
|
21207
|
+
pushToCache(cacheKeyChannelUnread, channelUnreadInfo);
|
|
21208
|
+
return channelUnreadInfo;
|
|
21209
|
+
};
|
|
21210
|
+
|
|
21211
|
+
const persistUnreadCountInfo = (payload) => {
|
|
21212
|
+
const { feedMarkers, userFeedMarkers } = payload;
|
|
21213
|
+
// calculate sub channel unread info and channel unread info
|
|
21214
|
+
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
21215
|
+
const channelIds = [];
|
|
21216
|
+
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
21217
|
+
userFeedMarkers.forEach(userFeedMarker => {
|
|
21218
|
+
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
21219
|
+
if (!feedMarker)
|
|
21220
|
+
return;
|
|
21221
|
+
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
21222
|
+
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
21223
|
+
const subChannelUnreadInfo = {
|
|
21224
|
+
subChannelId: feedMarker.feedId,
|
|
21225
|
+
channelId: feedMarker.entityId,
|
|
21226
|
+
readToSegment: userFeedMarker.readToSegment,
|
|
21227
|
+
lastSegment: feedMarker.lastSegment,
|
|
21228
|
+
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
21229
|
+
unreadCount: Math.max(0, unreadCount),
|
|
21230
|
+
isMentioned: userFeedMarker.isMentioned,
|
|
21231
|
+
isDeleted: feedMarker.isDeleted,
|
|
21232
|
+
createdAt: userFeedMarker.createdAt,
|
|
21233
|
+
updatedAt: userFeedMarker.updatedAt,
|
|
21234
|
+
};
|
|
21235
|
+
// update sub channel unread info in cache
|
|
21236
|
+
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
21237
|
+
if (!channelIds.includes(feedMarker.entityId)) {
|
|
21238
|
+
channelIds.push(feedMarker.entityId);
|
|
21239
|
+
}
|
|
21240
|
+
}
|
|
21241
|
+
});
|
|
21242
|
+
// re-calculate channel unread info in cache
|
|
21243
|
+
channelIds.forEach(channelId => {
|
|
21244
|
+
reCalculateChannelUnreadInfo(channelId);
|
|
21245
|
+
});
|
|
21246
|
+
}
|
|
21247
|
+
};
|
|
21248
|
+
|
|
21249
|
+
/**
|
|
21250
|
+
* ```js
|
|
21251
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21252
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21253
|
+
* ```
|
|
21254
|
+
*
|
|
21255
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21256
|
+
*
|
|
21257
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21258
|
+
* @param page
|
|
21259
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21260
|
+
*
|
|
21261
|
+
* @category Channel API
|
|
21262
|
+
* @async
|
|
21263
|
+
* @private
|
|
21264
|
+
*/
|
|
21265
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
21266
|
+
const client = getActiveClient();
|
|
21267
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
21268
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
21269
|
+
params: {
|
|
21270
|
+
messageFeedIds,
|
|
21271
|
+
options: {
|
|
21272
|
+
token: toToken(page, 'skiplimit'),
|
|
21273
|
+
},
|
|
21274
|
+
},
|
|
21275
|
+
});
|
|
21276
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21277
|
+
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
21278
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
21279
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21280
|
+
persistUnreadCountInfo({
|
|
21281
|
+
feedMarkers: feedMarkersPayload,
|
|
21282
|
+
userFeedMarkers: userFeedMarkersPayload,
|
|
21283
|
+
});
|
|
21284
|
+
}
|
|
21285
|
+
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
21286
|
+
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
21287
|
+
const cachedAt = client.cache && Date.now();
|
|
21288
|
+
if (client.cache)
|
|
21289
|
+
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
21290
|
+
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21291
|
+
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
21292
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21293
|
+
const nextPage = toPage(paging.next);
|
|
21294
|
+
const prevPage = toPage(paging.previous);
|
|
21295
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
21296
|
+
};
|
|
21297
|
+
|
|
21298
|
+
const getUserMarker = async () => {
|
|
21299
|
+
const client = getActiveClient();
|
|
21300
|
+
client.log('channel/getUserMarker');
|
|
21301
|
+
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
21302
|
+
const { userMarkers } = payload;
|
|
21303
|
+
const cachedAt = client.cache && Date.now();
|
|
21304
|
+
if (client.cache)
|
|
21305
|
+
ingestInCache({ userMarkers }, { cachedAt });
|
|
21306
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21307
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
21308
|
+
if (maxUserMarker == null ||
|
|
21309
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
21310
|
+
return userMarker;
|
|
21311
|
+
}
|
|
21312
|
+
return maxUserMarker;
|
|
21313
|
+
}, undefined);
|
|
21314
|
+
return { data: latestUserMarker, cachedAt };
|
|
21315
|
+
};
|
|
21316
|
+
|
|
21317
|
+
/** @hidden */
|
|
21318
|
+
/*
|
|
21319
|
+
* @param message payload from http request without myReactions
|
|
21320
|
+
* add myReactions to http response if the event was a reaction event
|
|
21321
|
+
*/
|
|
21322
|
+
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
21323
|
+
const client = getActiveClient();
|
|
21324
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
21325
|
+
// '[]' in cases where the new reaction is the first one
|
|
21326
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
21327
|
+
// add myReactions to the payload
|
|
21328
|
+
Object.assign(payload, { myReactions });
|
|
21329
|
+
// check if there are any updates to the reactions
|
|
21330
|
+
const latestReaction = reactors[0];
|
|
21331
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
21332
|
+
if (!isLatestReactionMine) {
|
|
21333
|
+
return;
|
|
21334
|
+
}
|
|
21335
|
+
// new reaction added
|
|
21336
|
+
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
21337
|
+
Object.assign(payload, {
|
|
21338
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
21339
|
+
});
|
|
21340
|
+
}
|
|
21341
|
+
// existing reaction removed
|
|
21342
|
+
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
21343
|
+
Object.assign(payload, {
|
|
21344
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
21345
|
+
});
|
|
21346
|
+
}
|
|
21347
|
+
};
|
|
21348
|
+
|
|
21349
|
+
/*
|
|
21350
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
21351
|
+
* value of includeDeleted
|
|
21352
|
+
*
|
|
21353
|
+
* There are two important things to note here:
|
|
21354
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
21355
|
+
* the server
|
|
21356
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
21357
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
21358
|
+
* for deleted entities
|
|
21359
|
+
*
|
|
21360
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
21361
|
+
* DRY
|
|
21362
|
+
*/
|
|
21363
|
+
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
21364
|
+
|
|
21365
|
+
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
21366
|
+
var _a, _b;
|
|
21367
|
+
// Look for `unreadCount` in the marker param first
|
|
21368
|
+
if (marker) {
|
|
21369
|
+
return marker.hasMentioned;
|
|
21370
|
+
}
|
|
21371
|
+
const client = getActiveClient();
|
|
21372
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21373
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21374
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21375
|
+
'subChannelUnreadInfo',
|
|
21376
|
+
'get',
|
|
21377
|
+
subChannelId,
|
|
21378
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21379
|
+
if (cachedUnreadCount) {
|
|
21380
|
+
return cachedUnreadCount.isMentioned;
|
|
21381
|
+
}
|
|
21382
|
+
return false;
|
|
21383
|
+
}
|
|
21384
|
+
const key = {
|
|
21385
|
+
entityId: channelId,
|
|
21386
|
+
feedId: subChannelId,
|
|
21387
|
+
userId: getActiveUser()._id,
|
|
21388
|
+
};
|
|
21389
|
+
// If the marker param is not set, look in the cache
|
|
21390
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21391
|
+
'subChannelMarker',
|
|
21392
|
+
'get',
|
|
21393
|
+
getResolver('subChannelMarker')(key),
|
|
21394
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21395
|
+
if (cachedMarker) {
|
|
21396
|
+
return cachedMarker.hasMentioned;
|
|
21397
|
+
}
|
|
21398
|
+
// and if not found in cache use default value `false`
|
|
21399
|
+
return false;
|
|
21400
|
+
}
|
|
21401
|
+
|
|
21402
|
+
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
21403
|
+
var _a, _b;
|
|
21404
|
+
// Look for `unreadCount` in the marker param first
|
|
21405
|
+
if (marker) {
|
|
21406
|
+
return marker.unreadCount;
|
|
21407
|
+
}
|
|
21408
|
+
const client = getActiveClient();
|
|
21409
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
21410
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
21411
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
21412
|
+
'subChannelUnreadInfo',
|
|
21413
|
+
'get',
|
|
21414
|
+
subChannelId,
|
|
21415
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21416
|
+
if (cachedUnreadCount) {
|
|
21417
|
+
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
21418
|
+
}
|
|
21419
|
+
return 0;
|
|
21420
|
+
}
|
|
21421
|
+
const key = {
|
|
21422
|
+
entityId: channelId,
|
|
21423
|
+
feedId: subChannelId,
|
|
21424
|
+
userId: getActiveUser()._id,
|
|
21425
|
+
};
|
|
21426
|
+
// If the marker param is not set, look in the cache
|
|
21427
|
+
const cachedMarker = (_b = pullFromCache([
|
|
21428
|
+
'subChannelMarker',
|
|
21429
|
+
'get',
|
|
21430
|
+
getResolver('subChannelMarker')(key),
|
|
21431
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21432
|
+
if (cachedMarker) {
|
|
21433
|
+
return cachedMarker.unreadCount;
|
|
21434
|
+
}
|
|
21435
|
+
// and if not found in cache use default value `0`
|
|
21436
|
+
return 0;
|
|
21437
|
+
}
|
|
21438
|
+
|
|
21439
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
21440
|
+
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
21441
|
+
function convertFromRaw$2(_a) {
|
|
21442
|
+
var { channelId, channelPublicId, channelType, childCount, creatorId, creatorPublicId, lastMessageId, lastMessageTimestamp, messageFeedId, name } = _a, rest = __rest(_a, ["channelId", "channelPublicId", "channelType", "childCount", "creatorId", "creatorPublicId", "lastMessageId", "lastMessageTimestamp", "messageFeedId", "name"]);
|
|
21443
|
+
return Object.assign(Object.assign({ get unreadCount() {
|
|
21444
|
+
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
21445
|
+
},
|
|
21446
|
+
get hasMentioned() {
|
|
21447
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21448
|
+
},
|
|
21449
|
+
get isMentioned() {
|
|
21450
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
21451
|
+
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
21452
|
+
}
|
|
21453
|
+
|
|
21454
|
+
const mergePayloadWithLocal = (payload) => {
|
|
21455
|
+
var _a, _b, _c;
|
|
21456
|
+
const localMessage = (_b = (_a = queryCache(['message', 'get'])) === null || _a === void 0 ? void 0 : _a.find(({ data }) => data.messageId === payload.messageId)) === null || _b === void 0 ? void 0 : _b.data;
|
|
21457
|
+
if (localMessage) {
|
|
21458
|
+
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
21459
|
+
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
21460
|
+
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
21461
|
+
}
|
|
21462
|
+
return payload;
|
|
21463
|
+
};
|
|
21464
|
+
function convertFromRaw$1(message, reactors, event) {
|
|
21465
|
+
var _a;
|
|
21466
|
+
const mergeMessage = mergePayloadWithLocal(message);
|
|
21467
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = mergeMessage, rest = __rest(mergeMessage, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
21468
|
+
let cache;
|
|
21469
|
+
if (referenceId) {
|
|
21470
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
21471
|
+
}
|
|
21472
|
+
if (!cache) {
|
|
21473
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
21474
|
+
}
|
|
21475
|
+
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, creatorPrivateId: message.creatorId, reactions: reactions !== null && reactions !== void 0 ? reactions : {},
|
|
21476
|
+
/*
|
|
21477
|
+
* Previously, myReactions were added only if it was part of the payload.
|
|
21478
|
+
* So empty myReactions were not present. So I've edited the payload to add
|
|
21479
|
+
* a default for those cases.
|
|
21480
|
+
*
|
|
21481
|
+
* Check git blame for previous iteration
|
|
21482
|
+
*/
|
|
21483
|
+
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
21484
|
+
if (mentionedUsers) {
|
|
21485
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
21486
|
+
if (mention.type === 'channel') {
|
|
21487
|
+
return mention;
|
|
21488
|
+
}
|
|
21489
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
21490
|
+
});
|
|
21491
|
+
}
|
|
21492
|
+
if (reactors && reactors.length && event) {
|
|
21493
|
+
// mqtt event
|
|
21494
|
+
prepareMessagePayloadForCache(out, reactors, event);
|
|
21495
|
+
}
|
|
21496
|
+
return out;
|
|
21497
|
+
}
|
|
21498
|
+
const preUpdateMessageCache = (rawPayload) => {
|
|
21499
|
+
ingestInCache({
|
|
21500
|
+
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
21501
|
+
});
|
|
21502
|
+
};
|
|
21503
|
+
const DEBOUNCE_TIME = 2000;
|
|
21504
|
+
const currentDebounceMap = {};
|
|
21505
|
+
const prepareMessagePayload = async (payload, event) => {
|
|
21506
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
21507
|
+
if (markerIds.length > 0) {
|
|
21508
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21509
|
+
preUpdateMessageCache(payload);
|
|
21510
|
+
const markerIdsKey = markerIds.join('');
|
|
21511
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
21512
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
21513
|
+
}
|
|
21514
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
21515
|
+
try {
|
|
21516
|
+
getMessageMarkers(markerIds);
|
|
21517
|
+
}
|
|
21518
|
+
catch (_error) {
|
|
21519
|
+
// do nothing
|
|
21520
|
+
}
|
|
21521
|
+
}, DEBOUNCE_TIME);
|
|
21522
|
+
}
|
|
21523
|
+
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
21524
|
+
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
21525
|
+
if (messageFeeds && messageFeeds.length > 0) {
|
|
21526
|
+
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
21527
|
+
var _a, _b;
|
|
21528
|
+
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
21529
|
+
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
21530
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "isMentioned"]);
|
|
21531
|
+
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
21532
|
+
});
|
|
21533
|
+
}
|
|
21534
|
+
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
21535
|
+
};
|
|
21536
|
+
function convertParams(_a) {
|
|
21537
|
+
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
21538
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
21539
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
21540
|
+
}
|
|
21541
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
21542
|
+
}
|
|
21543
|
+
function convertQueryParams$1(_a) {
|
|
21544
|
+
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
21545
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
21546
|
+
sortBy,
|
|
21547
|
+
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
21548
|
+
around: aroundMessageId,
|
|
21549
|
+
} });
|
|
21550
|
+
if (includingTags) {
|
|
21551
|
+
out.includeTags = includingTags;
|
|
21552
|
+
}
|
|
21553
|
+
if (type) {
|
|
21554
|
+
out.dataType = type;
|
|
21555
|
+
}
|
|
21556
|
+
if (excludingTags) {
|
|
21557
|
+
out.excludeTags = excludingTags;
|
|
21558
|
+
}
|
|
21559
|
+
return out;
|
|
21560
|
+
}
|
|
21561
|
+
|
|
21562
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21563
|
+
/**
|
|
21564
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
21565
|
+
*/
|
|
21566
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
21567
|
+
const preUpdateSubChannelCache = (rawPayload) => {
|
|
21568
|
+
ingestInCache({
|
|
21569
|
+
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
21570
|
+
});
|
|
21571
|
+
};
|
|
21572
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
21573
|
+
const markerIds = rawPayload.messageFeeds
|
|
21574
|
+
.filter(isUnreadCountSupport$1)
|
|
21575
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
21576
|
+
if (markerIds.length > 0) {
|
|
21577
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21578
|
+
preUpdateSubChannelCache(rawPayload);
|
|
21579
|
+
try {
|
|
21580
|
+
await getSubChannelMarkers(markerIds);
|
|
21581
|
+
}
|
|
21582
|
+
catch (e) {
|
|
21583
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21584
|
+
}
|
|
21585
|
+
}
|
|
21586
|
+
updateSubChannelMessagePreviewCache(rawPayload);
|
|
21587
|
+
// attach marker to sub channel
|
|
21588
|
+
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
21589
|
+
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
21590
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
21591
|
+
messages });
|
|
21592
|
+
};
|
|
21593
|
+
function convertQueryParams(_a) {
|
|
21594
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
21595
|
+
const out = Object.assign({}, rest);
|
|
21596
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
21597
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
21598
|
+
}
|
|
21599
|
+
return out;
|
|
21600
|
+
}
|
|
21601
|
+
|
|
21602
|
+
/**
|
|
21603
|
+
* ```js
|
|
21604
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21605
|
+
* const subChannel = await getSubChannel('foobar')
|
|
21606
|
+
* ```
|
|
21607
|
+
*
|
|
21608
|
+
* Fetches a {@link Amity.SubChannel} object
|
|
21609
|
+
*
|
|
21610
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21611
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21612
|
+
*
|
|
21613
|
+
* @category Channel API
|
|
21614
|
+
* @async
|
|
21615
|
+
*/
|
|
21616
|
+
const getSubChannel$1 = async (subChannelId) => {
|
|
21617
|
+
const client = getActiveClient();
|
|
21618
|
+
client.log('channel/getSubChannel', subChannelId);
|
|
21619
|
+
isInTombstone('subChannel', subChannelId);
|
|
21620
|
+
try {
|
|
21621
|
+
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
21622
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
21623
|
+
const cachedAt = client.cache && Date.now();
|
|
21624
|
+
if (client.cache)
|
|
21625
|
+
ingestInCache(data, { cachedAt });
|
|
21626
|
+
fireEvent('local.message-feed.fetched', data);
|
|
21627
|
+
return {
|
|
21628
|
+
data: data.messageFeeds[0],
|
|
21629
|
+
cachedAt,
|
|
21630
|
+
};
|
|
21631
|
+
}
|
|
21632
|
+
catch (error) {
|
|
21633
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
21634
|
+
pushToTombstone('subChannel', subChannelId);
|
|
21635
|
+
}
|
|
21636
|
+
throw error;
|
|
21637
|
+
}
|
|
21638
|
+
};
|
|
21639
|
+
/**
|
|
21640
|
+
* ```js
|
|
21641
|
+
* import { getSubChannel } from '@amityco/ts-sdk'
|
|
21642
|
+
* const subChannel = getSubChannel.locally('foobar')
|
|
21643
|
+
* ```
|
|
21644
|
+
*
|
|
21645
|
+
* Fetches a {@link Amity.SubChannel} object from cache
|
|
21646
|
+
*
|
|
21647
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
21648
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
21649
|
+
*
|
|
21650
|
+
* @category Channel API
|
|
21651
|
+
*/
|
|
21652
|
+
getSubChannel$1.locally = (subChannelId) => {
|
|
21653
|
+
const client = getActiveClient();
|
|
21654
|
+
client.log('channel/getSubChannel.locally', subChannelId);
|
|
21655
|
+
if (!client.cache)
|
|
21656
|
+
return;
|
|
21657
|
+
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
21658
|
+
if (!cached)
|
|
21659
|
+
return;
|
|
21660
|
+
return {
|
|
21661
|
+
data: cached.data,
|
|
21662
|
+
cachedAt: cached.cachedAt,
|
|
21663
|
+
};
|
|
21664
|
+
};
|
|
21665
|
+
|
|
21666
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
21667
|
+
return new Date(dateString).getTime();
|
|
21668
|
+
};
|
|
21669
|
+
|
|
21670
|
+
const getMessagePreviewSetting$1 = async () => {
|
|
21671
|
+
const client = getActiveClient();
|
|
21672
|
+
return client.getMessagePreviewSetting(false);
|
|
21673
|
+
};
|
|
21674
|
+
const getSubChannelCache = async (subChannelId) => {
|
|
21675
|
+
var _a;
|
|
21676
|
+
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21677
|
+
if (!subChannelCache) {
|
|
21678
|
+
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
21679
|
+
}
|
|
21680
|
+
return subChannelCache;
|
|
21681
|
+
};
|
|
21682
|
+
const isLastestMessageOnSubchannel = (message) => {
|
|
21683
|
+
var _a;
|
|
21684
|
+
const cache = (_a = pullFromCache([
|
|
21685
|
+
'messagePreviewSubChannel',
|
|
21686
|
+
'get',
|
|
21687
|
+
message.subChannelId,
|
|
21688
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21689
|
+
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
21690
|
+
return (!cache ||
|
|
21691
|
+
cache.segment <= message.channelSegment ||
|
|
21692
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21693
|
+
};
|
|
21694
|
+
const isLastestMessageOnChannel = (message) => {
|
|
21695
|
+
var _a;
|
|
21696
|
+
const cache = (_a = pullFromCache([
|
|
21697
|
+
'messagePreviewChannel',
|
|
21698
|
+
'get',
|
|
21699
|
+
message.channelId,
|
|
21700
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21701
|
+
return (!cache ||
|
|
21702
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
21703
|
+
};
|
|
21704
|
+
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
21705
|
+
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
21706
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21707
|
+
// 1. get subChannel from cache, if not exist fetch from server
|
|
21708
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21709
|
+
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
21710
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
21711
|
+
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
21712
|
+
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
21713
|
+
convertDateStringToTimestamp(createdAt))
|
|
21714
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21715
|
+
lastActivity: createdAt,
|
|
21716
|
+
});
|
|
21717
|
+
return;
|
|
21718
|
+
}
|
|
21719
|
+
// 3. if messagePreviewSetting is `NOT` NO_MESSAGE_PREVEIW, update messagePreviewSubChannel and subChannel cache
|
|
21720
|
+
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
21721
|
+
if (!isLastestMessageOnSubchannel(message))
|
|
21722
|
+
return;
|
|
21723
|
+
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
21724
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21725
|
+
channelId,
|
|
21726
|
+
creatorId,
|
|
21727
|
+
messagePreviewId,
|
|
21728
|
+
createdAt,
|
|
21729
|
+
updatedAt,
|
|
21730
|
+
subChannelId,
|
|
21731
|
+
data,
|
|
21732
|
+
dataType,
|
|
21733
|
+
segment,
|
|
21734
|
+
isDeleted,
|
|
21735
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21736
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21737
|
+
});
|
|
21738
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
21739
|
+
lastActivity: createdAt,
|
|
21740
|
+
messagePreviewId,
|
|
21741
|
+
});
|
|
21742
|
+
};
|
|
21743
|
+
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
21744
|
+
var _a;
|
|
21745
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21746
|
+
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
21747
|
+
'messagePreviewSubChannel',
|
|
21748
|
+
'get',
|
|
21749
|
+
message.subChannelId,
|
|
21750
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21751
|
+
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
21752
|
+
if (messagePreviewSubChannelCache &&
|
|
21753
|
+
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
21754
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21755
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
21756
|
+
channelId,
|
|
21757
|
+
creatorId,
|
|
21758
|
+
messagePreviewId,
|
|
21759
|
+
createdAt,
|
|
21760
|
+
updatedAt,
|
|
21761
|
+
subChannelId,
|
|
21762
|
+
data,
|
|
21763
|
+
dataType,
|
|
21764
|
+
segment,
|
|
21765
|
+
isDeleted,
|
|
21766
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21767
|
+
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
21768
|
+
});
|
|
21769
|
+
}
|
|
21770
|
+
};
|
|
21771
|
+
const handleMessageCreated = async (message) => {
|
|
21772
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21773
|
+
if (isLastestMessageOnChannel(message)) {
|
|
21774
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21775
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21776
|
+
channelId,
|
|
21777
|
+
creatorId,
|
|
21778
|
+
messagePreviewId,
|
|
21779
|
+
createdAt,
|
|
21780
|
+
updatedAt,
|
|
21781
|
+
subChannelId,
|
|
21782
|
+
data,
|
|
21783
|
+
dataType,
|
|
21784
|
+
segment,
|
|
21785
|
+
isDeleted,
|
|
21786
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
21787
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
21788
|
+
});
|
|
21789
|
+
}
|
|
21790
|
+
};
|
|
21791
|
+
const handleMessageUpdated = async (message) => {
|
|
21792
|
+
/**
|
|
21793
|
+
* Channel Case
|
|
21794
|
+
*/
|
|
21795
|
+
var _a;
|
|
21796
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
21797
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21798
|
+
'messagePreviewChannel',
|
|
21799
|
+
'get',
|
|
21800
|
+
message.channelId,
|
|
21801
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21802
|
+
if (messagePreviewChannelCache &&
|
|
21803
|
+
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
21804
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
21805
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
21806
|
+
channelId,
|
|
21807
|
+
creatorId,
|
|
21808
|
+
messagePreviewId,
|
|
21809
|
+
createdAt,
|
|
21810
|
+
updatedAt,
|
|
21811
|
+
subChannelId,
|
|
21812
|
+
data,
|
|
21813
|
+
dataType,
|
|
21814
|
+
segment,
|
|
21815
|
+
isDeleted,
|
|
21816
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
21817
|
+
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
21818
|
+
});
|
|
21819
|
+
}
|
|
21820
|
+
};
|
|
21821
|
+
const handleSubChannelUpdated = async (subChannel) => {
|
|
21822
|
+
var _a, _b, _c, _d;
|
|
21823
|
+
const { channelId, subChannelId } = subChannel;
|
|
21824
|
+
/** Channel Case */
|
|
21825
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21826
|
+
'messagePreviewChannel',
|
|
21827
|
+
'get',
|
|
21828
|
+
channelId,
|
|
21829
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21830
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
21831
|
+
const subChannelCache = (_b = pullFromCache([
|
|
21832
|
+
'subChannel',
|
|
21833
|
+
'get',
|
|
21834
|
+
subChannelId,
|
|
21835
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21836
|
+
pushToCache(['messagePreviewChannel', 'get', channelId], Object.assign(Object.assign({}, messagePreviewChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
21837
|
+
}
|
|
21838
|
+
/** SubChannel Case */
|
|
21839
|
+
const messagePreviewSubChannelCache = (_c = pullFromCache([
|
|
21840
|
+
'messagePreviewSubChannel',
|
|
21841
|
+
'get',
|
|
21842
|
+
subChannelId,
|
|
21843
|
+
])) === null || _c === void 0 ? void 0 : _c.data;
|
|
21844
|
+
if (messagePreviewSubChannelCache &&
|
|
21845
|
+
new Date(messagePreviewSubChannelCache.updatedAt).valueOf() >
|
|
21846
|
+
new Date(subChannel.updatedAt).valueOf()) {
|
|
21847
|
+
const subChannelCache = (_d = pullFromCache([
|
|
21848
|
+
'subChannel',
|
|
21849
|
+
'get',
|
|
21850
|
+
subChannelId,
|
|
21851
|
+
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
21852
|
+
pushToCache(['messagePreviewSubChannel', 'get', subChannelId], Object.assign(Object.assign({}, messagePreviewSubChannelCache), { subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName, subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt }));
|
|
21853
|
+
}
|
|
21854
|
+
};
|
|
21855
|
+
|
|
21856
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
21857
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
21858
|
+
}
|
|
21859
|
+
|
|
21860
|
+
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21861
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
21862
|
+
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
21863
|
+
var _a;
|
|
21864
|
+
let { messagePreviewId } = channel;
|
|
21865
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
21866
|
+
'messagePreviewChannel',
|
|
21867
|
+
'get',
|
|
21868
|
+
channel.channelId,
|
|
21869
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21870
|
+
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
21871
|
+
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
21872
|
+
}
|
|
21873
|
+
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
21874
|
+
}
|
|
21875
|
+
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21876
|
+
ingestInCache({
|
|
21877
|
+
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
21878
|
+
});
|
|
21879
|
+
};
|
|
21880
|
+
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
21881
|
+
for (let i = 0; i < channels.length; i += 1) {
|
|
21882
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
21883
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
21884
|
+
let unreadCount = 0;
|
|
21885
|
+
let readToSegment = null;
|
|
21886
|
+
let lastMentionedSegment = null;
|
|
21887
|
+
let isMentioned = false;
|
|
21888
|
+
if (channelUser) {
|
|
21889
|
+
readToSegment = channelUser.readToSegment;
|
|
21890
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
21891
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
21892
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
21893
|
+
}
|
|
21894
|
+
const cacheChannelUnread = {
|
|
21895
|
+
channelId: channels[i].channelId,
|
|
21896
|
+
lastSegment: channels[i].messageCount,
|
|
21897
|
+
readToSegment,
|
|
21898
|
+
lastMentionedSegment,
|
|
21899
|
+
unreadCount,
|
|
21900
|
+
isMentioned,
|
|
21901
|
+
isDeleted: channels[i].isDeleted || false,
|
|
21902
|
+
};
|
|
21903
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
21904
|
+
}
|
|
21905
|
+
};
|
|
21906
|
+
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
21907
|
+
const client = getActiveClient();
|
|
21908
|
+
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
21909
|
+
if (options.isMessagePreviewUpdated &&
|
|
21910
|
+
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
21911
|
+
rawPayload.messagePreviews &&
|
|
21912
|
+
rawPayload.messagePreviews.length > 0) {
|
|
21913
|
+
updateChannelMessagePreviewCache(rawPayload);
|
|
21914
|
+
}
|
|
21915
|
+
if (client.useLegacyUnreadCount) {
|
|
21916
|
+
updateChannelUnread({
|
|
21917
|
+
channels: rawPayload.channels,
|
|
21918
|
+
channelUsers: rawPayload.channelUsers,
|
|
21919
|
+
currentUserId: client.userId,
|
|
21920
|
+
});
|
|
21921
|
+
}
|
|
21922
|
+
else {
|
|
21923
|
+
const markerIds = rawPayload.channels
|
|
21924
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
21925
|
+
.filter(isUnreadCountSupport)
|
|
21926
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
21927
|
+
if (markerIds.length > 0) {
|
|
21928
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
21929
|
+
preUpdateChannelCache(rawPayload, {
|
|
21930
|
+
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
21931
|
+
});
|
|
21932
|
+
try {
|
|
21933
|
+
await getChannelMarkers(markerIds);
|
|
21934
|
+
}
|
|
21935
|
+
catch (e) {
|
|
21936
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
21937
|
+
}
|
|
21938
|
+
}
|
|
21939
|
+
}
|
|
21940
|
+
// convert raw channel to internal channel
|
|
21941
|
+
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
21942
|
+
// convert raw channel user to membership (add user object)
|
|
21943
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
21944
|
+
return convertRawMembershipToMembership(channelUser);
|
|
21945
|
+
});
|
|
21946
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
21947
|
+
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
21948
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
21949
|
+
channels,
|
|
21950
|
+
channelUsers });
|
|
21951
|
+
};
|
|
21952
|
+
|
|
21953
|
+
/**
|
|
21954
|
+
* ```js
|
|
21955
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21956
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21957
|
+
* ```
|
|
21958
|
+
*
|
|
21959
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21960
|
+
*
|
|
21961
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21962
|
+
* @param page
|
|
21963
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21964
|
+
*
|
|
21965
|
+
* @category Channel API
|
|
21966
|
+
* @async
|
|
21967
|
+
* @private
|
|
21968
|
+
*/
|
|
21969
|
+
const getUserMessageFeedMakers = async (channelIds) => {
|
|
21970
|
+
const client = getActiveClient();
|
|
21971
|
+
client.log('channel/getUserMessageFeedMakers', channelIds);
|
|
21972
|
+
const { data } = await client.http.get(`/api/v1/markers/user-message-feed`, {
|
|
21973
|
+
params: {
|
|
21974
|
+
channelIds,
|
|
21975
|
+
},
|
|
21976
|
+
});
|
|
21977
|
+
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
21978
|
+
return data;
|
|
21979
|
+
};
|
|
21980
|
+
|
|
21981
|
+
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
21982
|
+
const client = getActiveClient();
|
|
21983
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
21984
|
+
// Marker service API uses channelInternalId as channelId
|
|
21985
|
+
const queryPayload = await getUserMessageFeedMakers(rawPayload.channels.map(({ channelInternalId }) => channelInternalId));
|
|
21986
|
+
const { feedMarkers, userFeedMarkers } = queryPayload;
|
|
21987
|
+
persistUnreadCountInfo({
|
|
21988
|
+
feedMarkers,
|
|
21989
|
+
userFeedMarkers,
|
|
21990
|
+
});
|
|
21991
|
+
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
21992
|
+
};
|
|
21993
|
+
|
|
21994
|
+
const getCachedMarker$2 = (entityId) => {
|
|
21995
|
+
var _a;
|
|
21996
|
+
const key = {
|
|
21997
|
+
entityId,
|
|
21998
|
+
userId: getActiveUser()._id,
|
|
21999
|
+
};
|
|
22000
|
+
return (_a = pullFromCache([
|
|
22001
|
+
'channelMarker',
|
|
22002
|
+
'get',
|
|
22003
|
+
getResolver('channelMarker')(key),
|
|
22004
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22005
|
+
};
|
|
22006
|
+
const getUnreadInfoCached$1 = (channelId) => {
|
|
22007
|
+
var _a;
|
|
22008
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22009
|
+
};
|
|
22010
|
+
/**
|
|
22011
|
+
* The function use to get value of hasMentioned or isMentioned field.
|
|
22012
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22013
|
+
*
|
|
22014
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22015
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22016
|
+
* If not found in the both cache, use `false` as defaul value.
|
|
22017
|
+
*/
|
|
22018
|
+
const getChannelIsMentioned = (channel, marker) => {
|
|
22019
|
+
var _a, _b, _c, _d;
|
|
22020
|
+
const client = getActiveClient();
|
|
22021
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22022
|
+
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22023
|
+
}
|
|
22024
|
+
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
22025
|
+
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
22026
|
+
: (_d = (_c = getCachedMarker$2(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22027
|
+
};
|
|
22028
|
+
|
|
22029
|
+
const getCachedMarker$1 = (entityId) => {
|
|
22030
|
+
var _a;
|
|
22031
|
+
const key = {
|
|
22032
|
+
entityId,
|
|
22033
|
+
userId: getActiveUser()._id,
|
|
22034
|
+
};
|
|
22035
|
+
return (_a = pullFromCache([
|
|
22036
|
+
'channelMarker',
|
|
22037
|
+
'get',
|
|
22038
|
+
getResolver('channelMarker')(key),
|
|
22039
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22040
|
+
};
|
|
22041
|
+
const getUnreadInfoCached = (channelId) => {
|
|
22042
|
+
var _a;
|
|
22043
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22044
|
+
};
|
|
22045
|
+
/**
|
|
22046
|
+
* The function use to get value of unreadCount field.
|
|
22047
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22048
|
+
*
|
|
22049
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22050
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
22051
|
+
* If not found in the both cache, use `0` as defaul value.
|
|
22052
|
+
*/
|
|
22053
|
+
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
22054
|
+
var _a, _b, _c, _d, _e;
|
|
22055
|
+
const client = getActiveClient();
|
|
22056
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22057
|
+
// Marker service API uses channelInternalId as channelId
|
|
22058
|
+
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22059
|
+
}
|
|
22060
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
22061
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
22062
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
22063
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
22064
|
+
return 0;
|
|
22065
|
+
}
|
|
22066
|
+
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
22067
|
+
};
|
|
22068
|
+
|
|
22069
|
+
const getLegacyChannelUnread = (channelId) => {
|
|
22070
|
+
var _a;
|
|
22071
|
+
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22072
|
+
};
|
|
22073
|
+
|
|
22074
|
+
const constructChannelDynamicValue = (channel) => {
|
|
22075
|
+
const client = getActiveClient();
|
|
22076
|
+
const rest = __rest(channel, ["messageCount"]);
|
|
22077
|
+
return shallowClone(rest, {
|
|
22078
|
+
get unreadCount() {
|
|
22079
|
+
var _a, _b;
|
|
22080
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22081
|
+
},
|
|
22082
|
+
get subChannelsUnreadCount() {
|
|
22083
|
+
return getSubChannelsUnreadCount(rest);
|
|
22084
|
+
},
|
|
22085
|
+
get isMentioned() {
|
|
22086
|
+
var _a, _b;
|
|
22087
|
+
if (client.useLegacyUnreadCount)
|
|
22088
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22089
|
+
return getChannelIsMentioned(rest);
|
|
22090
|
+
},
|
|
22091
|
+
});
|
|
22092
|
+
};
|
|
22093
|
+
|
|
20993
22094
|
const ANALYTIC_CACHE_KEY = ['analytic', 'normal-priority'];
|
|
20994
22095
|
const HIGH_PRIORITY_ANALYTIC_CACHE_KEY = ['analytic', 'high-priority'];
|
|
20995
22096
|
|
|
@@ -21289,20 +22390,6 @@ var AnalyticsEngine$1 = {
|
|
|
21289
22390
|
},
|
|
21290
22391
|
};
|
|
21291
22392
|
|
|
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
22393
|
class StoryComputedValue {
|
|
21307
22394
|
constructor(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt) {
|
|
21308
22395
|
this._syncingStoriesCount = 0;
|
|
@@ -21734,7 +22821,7 @@ const postLinkedObject = (post) => {
|
|
|
21734
22821
|
} });
|
|
21735
22822
|
};
|
|
21736
22823
|
|
|
21737
|
-
const getCachedMarker
|
|
22824
|
+
const getCachedMarker = (message) => {
|
|
21738
22825
|
var _a, _b;
|
|
21739
22826
|
const key = {
|
|
21740
22827
|
creatorId: 'creatorPrivateId' in message ? message.creatorPrivateId : message.creatorId,
|
|
@@ -21752,7 +22839,7 @@ const getMessageReadCount = (message, marker) => {
|
|
|
21752
22839
|
// Look in the marker param first
|
|
21753
22840
|
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
21754
22841
|
// If the marker param is not set, look in the cache
|
|
21755
|
-
getCachedMarker
|
|
22842
|
+
getCachedMarker(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
21756
22843
|
}; // and if not found in cache use default value `0`
|
|
21757
22844
|
|
|
21758
22845
|
/**
|
|
@@ -21995,31 +23082,6 @@ const markAsReadBySegment = async ({ subChannelId, readToSegment, }) => {
|
|
|
21995
23082
|
}
|
|
21996
23083
|
};
|
|
21997
23084
|
|
|
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
23085
|
class LegacyMessageReadReceiptSyncEngine {
|
|
22024
23086
|
constructor() {
|
|
22025
23087
|
this.isActive = true;
|
|
@@ -22218,1408 +23280,884 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
22218
23280
|
else {
|
|
22219
23281
|
// Remove oldest job when queue reach maximum capacity
|
|
22220
23282
|
this.jobQueue.shift();
|
|
22221
|
-
this.jobQueue.push(syncJob);
|
|
22222
|
-
}
|
|
22223
|
-
}
|
|
22224
|
-
removeJobFromQueue(item) {
|
|
22225
|
-
const index = this.jobQueue.indexOf(item);
|
|
22226
|
-
if (index > -1) {
|
|
22227
|
-
this.jobQueue.splice(index, 1);
|
|
22228
|
-
}
|
|
22229
|
-
}
|
|
22230
|
-
}
|
|
22231
|
-
let instance$3 = null;
|
|
22232
|
-
var LegacyReadReceiptSyncEngine = {
|
|
22233
|
-
getInstance: () => {
|
|
22234
|
-
if (!instance$3)
|
|
22235
|
-
instance$3 = new LegacyMessageReadReceiptSyncEngine();
|
|
22236
|
-
return instance$3;
|
|
22237
|
-
},
|
|
22238
|
-
};
|
|
22239
|
-
|
|
22240
|
-
const markReadMessage = (message) => {
|
|
22241
|
-
const client = getActiveClient();
|
|
22242
|
-
if (client.useLegacyUnreadCount) {
|
|
22243
|
-
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
22244
|
-
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
22245
|
-
}
|
|
22246
|
-
else {
|
|
22247
|
-
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
22248
|
-
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
22249
|
-
}
|
|
22250
|
-
};
|
|
22251
|
-
|
|
22252
|
-
const messageLinkedObject = (message) => {
|
|
22253
|
-
const rest = __rest(message, ["creatorPrivateId"]);
|
|
22254
|
-
return Object.assign(Object.assign({}, rest), { get readCount() {
|
|
22255
|
-
return getMessageReadCount(message).readCount;
|
|
22256
|
-
},
|
|
22257
|
-
get deliveredCount() {
|
|
22258
|
-
return getMessageReadCount(message).deliveredCount;
|
|
22259
|
-
},
|
|
22260
|
-
get creator() {
|
|
22261
|
-
var _a;
|
|
22262
|
-
return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22263
|
-
}, markRead: () => markReadMessage(message) });
|
|
22264
|
-
};
|
|
22265
|
-
|
|
22266
|
-
const reactorLinkedObject = (reactor) => {
|
|
22267
|
-
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
22268
|
-
var _a;
|
|
22269
|
-
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22270
|
-
if (!user)
|
|
22271
|
-
return undefined;
|
|
22272
|
-
return userLinkedObject(user);
|
|
22273
|
-
} });
|
|
22274
|
-
};
|
|
22275
|
-
|
|
22276
|
-
/**
|
|
22277
|
-
* ```js
|
|
22278
|
-
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
22279
|
-
* const success = await ChannelRepository.markAsRead('channelId')
|
|
22280
|
-
* ```
|
|
22281
|
-
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
22282
|
-
*
|
|
22283
|
-
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
22284
|
-
* @returns A success boolean if the {@link Amity.Channel} was mark read
|
|
22285
|
-
*
|
|
22286
|
-
* @category Channel API
|
|
22287
|
-
* @async
|
|
22288
|
-
*/
|
|
22289
|
-
const markAsRead = async (channelId) => {
|
|
22290
|
-
const client = getActiveClient();
|
|
22291
|
-
client.log('channel/markAsRead', channelId);
|
|
22292
|
-
const { data } = await client.http.put(`/api/v1/markers/channels/${channelId}/mark-read`);
|
|
22293
|
-
const { userMarkers, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
|
|
22294
|
-
const cachedAt = client.cache && Date.now();
|
|
22295
|
-
const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22296
|
-
const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22297
|
-
if (client.cache)
|
|
22298
|
-
ingestInCache(Object.assign({ userMarkers, userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
|
|
22299
|
-
fireEvent('local.channelMarker.updated', {
|
|
22300
|
-
userEntityMarkers: channelMarkers,
|
|
22301
|
-
});
|
|
22302
|
-
fireEvent('local.subChannelMarker.updated', {
|
|
22303
|
-
userFeedMarkers: subChannelMarkers,
|
|
22304
|
-
});
|
|
22305
|
-
return true;
|
|
22306
|
-
};
|
|
22307
|
-
|
|
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
|
-
const channelLinkedObject = (channel) => {
|
|
22327
|
-
return shallowClone(channel, {
|
|
22328
|
-
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
22329
|
-
});
|
|
22330
|
-
};
|
|
22331
|
-
|
|
22332
|
-
const adLinkedObject = (ad) => {
|
|
22333
|
-
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
22334
|
-
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
22335
|
-
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
22336
|
-
markAsSeen: (placement) => {
|
|
22337
|
-
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
22338
|
-
},
|
|
22339
|
-
markLinkAsClicked: (placement) => {
|
|
22340
|
-
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
22341
|
-
},
|
|
22342
|
-
}, get advertiser() {
|
|
22343
|
-
var _a, _b;
|
|
22344
|
-
const advertiserData = (_a = pullFromCache([
|
|
22345
|
-
'advertiser',
|
|
22346
|
-
'get',
|
|
22347
|
-
ad.advertiserId,
|
|
22348
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22349
|
-
if (!advertiserData)
|
|
22350
|
-
return;
|
|
22351
|
-
const avatarFile = (_b = pullFromCache([
|
|
22352
|
-
'file',
|
|
22353
|
-
'get',
|
|
22354
|
-
advertiserData.avatarFileId,
|
|
22355
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22356
|
-
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
22357
|
-
},
|
|
22358
|
-
get image1_1() {
|
|
22359
|
-
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
22360
|
-
if (!cacheData)
|
|
22361
|
-
return undefined;
|
|
22362
|
-
return cacheData.data || undefined;
|
|
22363
|
-
},
|
|
22364
|
-
get image9_16() {
|
|
22365
|
-
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
22366
|
-
if (!cacheData)
|
|
22367
|
-
return undefined;
|
|
22368
|
-
return cacheData.data || undefined;
|
|
22369
|
-
} });
|
|
22370
|
-
};
|
|
22371
|
-
|
|
22372
|
-
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22373
|
-
var _a;
|
|
22374
|
-
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
22375
|
-
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
22376
|
-
var _a;
|
|
22377
|
-
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
22378
|
-
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
22379
|
-
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
22380
|
-
get post() {
|
|
22381
|
-
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
22382
|
-
return;
|
|
22383
|
-
return postLinkedObject(postCached.data);
|
|
22384
|
-
},
|
|
22385
|
-
get target() {
|
|
22386
|
-
const pinTarget = pullFromCache([
|
|
22387
|
-
'pinTarget',
|
|
22388
|
-
'get',
|
|
22389
|
-
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
22390
|
-
]);
|
|
22391
|
-
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
22392
|
-
return;
|
|
22393
|
-
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
22394
|
-
} });
|
|
22395
|
-
};
|
|
22396
|
-
|
|
22397
|
-
const notificationTrayLinkedObject = (noti) => {
|
|
22398
|
-
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
22399
|
-
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
22400
|
-
.filter(isNonNullable)
|
|
22401
|
-
.map(({ data }) => data)
|
|
22402
|
-
.map(user => userLinkedObject(user)) });
|
|
22403
|
-
};
|
|
22404
|
-
|
|
22405
|
-
/* begin_public_function
|
|
22406
|
-
id: invitation.createInvitations
|
|
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
|
|
22426
|
-
*/
|
|
22427
|
-
const createInvitations = async (bundle) => {
|
|
22428
|
-
const client = getActiveClient();
|
|
22429
|
-
client.log('invitation/createInvitations', bundle);
|
|
22430
|
-
const { data } = await client.http.post('/api/v1/invitations', bundle);
|
|
22431
|
-
const cachedAt = client.cache && Date.now();
|
|
22432
|
-
if (client.cache)
|
|
22433
|
-
ingestInCache(data, { cachedAt });
|
|
22434
|
-
fireEvent('local.invitation.created', data);
|
|
22435
|
-
return {
|
|
22436
|
-
data: data.invitations,
|
|
22437
|
-
cachedAt,
|
|
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
|
|
22455
|
-
*
|
|
22456
|
-
* @category Invitation API
|
|
22457
|
-
* @async
|
|
22458
|
-
*/
|
|
22459
|
-
const acceptInvitation = async (invitationId) => {
|
|
22460
|
-
var _a;
|
|
22461
|
-
const client = getActiveClient();
|
|
22462
|
-
client.log('invitation/acceptInvitation', invitationId);
|
|
22463
|
-
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
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;
|
|
22474
|
-
};
|
|
22475
|
-
/* end_public_function */
|
|
22476
|
-
|
|
22477
|
-
/* begin_public_function
|
|
22478
|
-
id: invitation.reject
|
|
22479
|
-
*/
|
|
22480
|
-
/**
|
|
22481
|
-
* ```js
|
|
22482
|
-
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
22483
|
-
* const isRejected = await rejectInvitation(invitationId)
|
|
22484
|
-
* ```
|
|
22485
|
-
*
|
|
22486
|
-
* Rejects a {@link Amity.Invitation} object
|
|
22487
|
-
*
|
|
22488
|
-
* @param invitationId the {@link Amity.Invitation} to reject
|
|
22489
|
-
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
22490
|
-
*
|
|
22491
|
-
* @category Invitation API
|
|
22492
|
-
* @async
|
|
22493
|
-
*/
|
|
22494
|
-
const rejectInvitation = async (invitationId) => {
|
|
22495
|
-
var _a;
|
|
22496
|
-
const client = getActiveClient();
|
|
22497
|
-
client.log('invitation/rejectInvitation', invitationId);
|
|
22498
|
-
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
22499
|
-
const invitation = (_a = pullFromCache([
|
|
22500
|
-
'invitation',
|
|
22501
|
-
'get',
|
|
22502
|
-
invitationId,
|
|
22503
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22504
|
-
if (invitation) {
|
|
22505
|
-
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
22506
|
-
fireEvent('local.invitation.updated', { invitations: [invitation] });
|
|
22507
|
-
}
|
|
22508
|
-
return data.success;
|
|
22509
|
-
};
|
|
22510
|
-
/* end_public_function */
|
|
22511
|
-
|
|
22512
|
-
/* begin_public_function
|
|
22513
|
-
id: invitation.cancel
|
|
22514
|
-
*/
|
|
22515
|
-
/**
|
|
22516
|
-
* ```js
|
|
22517
|
-
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
22518
|
-
* const isCanceled = await cancelInvitation(invitationId)
|
|
22519
|
-
* ```
|
|
22520
|
-
*
|
|
22521
|
-
* Cancels a {@link Amity.Invitation} object
|
|
22522
|
-
*
|
|
22523
|
-
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
22524
|
-
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
22525
|
-
*
|
|
22526
|
-
* @category Invitation API
|
|
22527
|
-
* @async
|
|
22528
|
-
*/
|
|
22529
|
-
const cancelInvitation = async (invitationId) => {
|
|
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) => {
|
|
22587
|
-
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);
|
|
23283
|
+
this.jobQueue.push(syncJob);
|
|
23284
|
+
}
|
|
23285
|
+
}
|
|
23286
|
+
removeJobFromQueue(item) {
|
|
23287
|
+
const index = this.jobQueue.indexOf(item);
|
|
23288
|
+
if (index > -1) {
|
|
23289
|
+
this.jobQueue.splice(index, 1);
|
|
23290
|
+
}
|
|
23291
|
+
}
|
|
23292
|
+
}
|
|
23293
|
+
let instance$3 = null;
|
|
23294
|
+
var LegacyReadReceiptSyncEngine = {
|
|
23295
|
+
getInstance: () => {
|
|
23296
|
+
if (!instance$3)
|
|
23297
|
+
instance$3 = new LegacyMessageReadReceiptSyncEngine();
|
|
23298
|
+
return instance$3;
|
|
23299
|
+
},
|
|
22672
23300
|
};
|
|
22673
23301
|
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22680
|
-
|
|
22681
|
-
|
|
22682
|
-
|
|
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 */);
|
|
23302
|
+
const markReadMessage = (message) => {
|
|
23303
|
+
const client = getActiveClient();
|
|
23304
|
+
if (client.useLegacyUnreadCount) {
|
|
23305
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
23306
|
+
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
23307
|
+
}
|
|
23308
|
+
else {
|
|
23309
|
+
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
23310
|
+
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
22706
23311
|
}
|
|
22707
23312
|
};
|
|
22708
23313
|
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
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
|
-
const client = getActiveClient();
|
|
22726
|
-
client.log('channel/getMessageMarkers', messageIds);
|
|
22727
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
22728
|
-
params: {
|
|
22729
|
-
messageIds,
|
|
23314
|
+
const messageLinkedObject = (message) => {
|
|
23315
|
+
const rest = __rest(message, ["creatorPrivateId"]);
|
|
23316
|
+
return Object.assign(Object.assign({}, rest), { get readCount() {
|
|
23317
|
+
return getMessageReadCount(message).readCount;
|
|
22730
23318
|
},
|
|
22731
|
-
|
|
22732
|
-
|
|
22733
|
-
|
|
22734
|
-
|
|
22735
|
-
|
|
22736
|
-
|
|
22737
|
-
|
|
22738
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22739
|
-
return { data: contentMarkers, cachedAt };
|
|
23319
|
+
get deliveredCount() {
|
|
23320
|
+
return getMessageReadCount(message).deliveredCount;
|
|
23321
|
+
},
|
|
23322
|
+
get creator() {
|
|
23323
|
+
var _a;
|
|
23324
|
+
return (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23325
|
+
}, markRead: () => markReadMessage(message) });
|
|
22740
23326
|
};
|
|
22741
23327
|
|
|
22742
|
-
const
|
|
22743
|
-
|
|
22744
|
-
|
|
22745
|
-
|
|
22746
|
-
|
|
22747
|
-
|
|
22748
|
-
|
|
22749
|
-
|
|
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
|
-
});
|
|
22777
|
-
}
|
|
23328
|
+
const reactorLinkedObject = (reactor) => {
|
|
23329
|
+
return Object.assign(Object.assign({}, reactor), { get user() {
|
|
23330
|
+
var _a;
|
|
23331
|
+
const user = (_a = pullFromCache(['user', 'get', reactor.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23332
|
+
if (!user)
|
|
23333
|
+
return undefined;
|
|
23334
|
+
return userLinkedObject(user);
|
|
23335
|
+
} });
|
|
22778
23336
|
};
|
|
22779
23337
|
|
|
22780
23338
|
/**
|
|
22781
23339
|
* ```js
|
|
22782
|
-
* import {
|
|
22783
|
-
* const
|
|
23340
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
23341
|
+
* const success = await ChannelRepository.markAsRead('channelId')
|
|
22784
23342
|
* ```
|
|
23343
|
+
* Updating all {@link Amity.SubChannel} in specify {@link Amity.Channel} as read
|
|
22785
23344
|
*
|
|
22786
|
-
*
|
|
22787
|
-
*
|
|
22788
|
-
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
22789
|
-
* @param page
|
|
22790
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
23345
|
+
* @param channelId the ID of to specify {@link Amity.Channel}
|
|
23346
|
+
* @returns A success boolean if the {@link Amity.Channel} was mark read
|
|
22791
23347
|
*
|
|
22792
23348
|
* @category Channel API
|
|
22793
23349
|
* @async
|
|
22794
|
-
* @private
|
|
22795
23350
|
*/
|
|
22796
|
-
const
|
|
22797
|
-
const client = getActiveClient();
|
|
22798
|
-
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
22799
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
22800
|
-
params: {
|
|
22801
|
-
messageFeedIds,
|
|
22802
|
-
options: {
|
|
22803
|
-
token: toToken(page, 'skiplimit'),
|
|
22804
|
-
},
|
|
22805
|
-
},
|
|
22806
|
-
});
|
|
22807
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22808
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
22809
|
-
// if consistent mode is enabled, persist the unread count info to the cache
|
|
22810
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22811
|
-
persistUnreadCountInfo({
|
|
22812
|
-
feedMarkers: feedMarkersPayload,
|
|
22813
|
-
userFeedMarkers: userFeedMarkersPayload,
|
|
22814
|
-
});
|
|
22815
|
-
}
|
|
22816
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22817
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22818
|
-
const cachedAt = client.cache && Date.now();
|
|
22819
|
-
if (client.cache)
|
|
22820
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
22821
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
22822
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
22823
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22824
|
-
const nextPage = toPage(paging.next);
|
|
22825
|
-
const prevPage = toPage(paging.previous);
|
|
22826
|
-
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
22827
|
-
};
|
|
22828
|
-
|
|
22829
|
-
const getUserMarker = async () => {
|
|
23351
|
+
const markAsRead = async (channelId) => {
|
|
22830
23352
|
const client = getActiveClient();
|
|
22831
|
-
client.log('channel/
|
|
22832
|
-
const { data
|
|
22833
|
-
const { userMarkers } =
|
|
23353
|
+
client.log('channel/markAsRead', channelId);
|
|
23354
|
+
const { data } = await client.http.put(`/api/v1/markers/channels/${channelId}/mark-read`);
|
|
23355
|
+
const { userMarkers, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = data, rest = __rest(data, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
|
|
22834
23356
|
const cachedAt = client.cache && Date.now();
|
|
23357
|
+
const channelMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
23358
|
+
const subChannelMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22835
23359
|
if (client.cache)
|
|
22836
|
-
ingestInCache({ userMarkers }, { cachedAt });
|
|
22837
|
-
fireEvent('local.
|
|
22838
|
-
|
|
22839
|
-
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
22843
|
-
|
|
22844
|
-
}, undefined);
|
|
22845
|
-
return { data: latestUserMarker, cachedAt };
|
|
23360
|
+
ingestInCache(Object.assign({ userMarkers, userEntityMarkers: channelMarkers, userFeedMarkers: subChannelMarkers }, rest), { cachedAt });
|
|
23361
|
+
fireEvent('local.channelMarker.updated', {
|
|
23362
|
+
userEntityMarkers: channelMarkers,
|
|
23363
|
+
});
|
|
23364
|
+
fireEvent('local.subChannelMarker.updated', {
|
|
23365
|
+
userFeedMarkers: subChannelMarkers,
|
|
23366
|
+
});
|
|
23367
|
+
return true;
|
|
22846
23368
|
};
|
|
22847
23369
|
|
|
22848
|
-
|
|
22849
|
-
|
|
22850
|
-
|
|
22851
|
-
|
|
22852
|
-
*/
|
|
22853
|
-
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
22854
|
-
const client = getActiveClient();
|
|
22855
|
-
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22856
|
-
// '[]' in cases where the new reaction is the first one
|
|
22857
|
-
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22858
|
-
// add myReactions to the payload
|
|
22859
|
-
Object.assign(payload, { myReactions });
|
|
22860
|
-
// check if there are any updates to the reactions
|
|
22861
|
-
const latestReaction = reactors[0];
|
|
22862
|
-
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22863
|
-
if (!isLatestReactionMine) {
|
|
22864
|
-
return;
|
|
22865
|
-
}
|
|
22866
|
-
// new reaction added
|
|
22867
|
-
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22868
|
-
Object.assign(payload, {
|
|
22869
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22870
|
-
});
|
|
22871
|
-
}
|
|
22872
|
-
// existing reaction removed
|
|
22873
|
-
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
22874
|
-
Object.assign(payload, {
|
|
22875
|
-
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22876
|
-
});
|
|
22877
|
-
}
|
|
23370
|
+
const channelLinkedObject = (channel) => {
|
|
23371
|
+
return shallowClone(channel, {
|
|
23372
|
+
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
23373
|
+
});
|
|
22878
23374
|
};
|
|
22879
23375
|
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
|
|
22883
|
-
|
|
22884
|
-
|
|
22885
|
-
|
|
22886
|
-
|
|
22887
|
-
|
|
22888
|
-
|
|
22889
|
-
|
|
22890
|
-
|
|
22891
|
-
|
|
22892
|
-
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
|
|
22898
|
-
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
const cachedUnreadCount = (_a = pullFromCache([
|
|
22906
|
-
'subChannelUnreadInfo',
|
|
22907
|
-
'get',
|
|
22908
|
-
subChannelId,
|
|
22909
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22910
|
-
if (cachedUnreadCount) {
|
|
22911
|
-
return cachedUnreadCount.isMentioned;
|
|
22912
|
-
}
|
|
22913
|
-
return false;
|
|
22914
|
-
}
|
|
22915
|
-
const key = {
|
|
22916
|
-
entityId: channelId,
|
|
22917
|
-
feedId: subChannelId,
|
|
22918
|
-
userId: getActiveUser()._id,
|
|
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;
|
|
22928
|
-
}
|
|
22929
|
-
// and if not found in cache use default value `false`
|
|
22930
|
-
return false;
|
|
22931
|
-
}
|
|
22932
|
-
|
|
22933
|
-
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
22934
|
-
var _a, _b;
|
|
22935
|
-
// Look for `unreadCount` in the marker param first
|
|
22936
|
-
if (marker) {
|
|
22937
|
-
return marker.unreadCount;
|
|
22938
|
-
}
|
|
22939
|
-
const client = getActiveClient();
|
|
22940
|
-
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22941
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22942
|
-
const cachedUnreadCount = (_a = pullFromCache([
|
|
22943
|
-
'subChannelUnreadInfo',
|
|
22944
|
-
'get',
|
|
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;
|
|
22965
|
-
}
|
|
22966
|
-
// and if not found in cache use default value `0`
|
|
22967
|
-
return 0;
|
|
22968
|
-
}
|
|
22969
|
-
|
|
22970
|
-
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
22971
|
-
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
22972
|
-
function convertFromRaw$2(_a) {
|
|
22973
|
-
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"]);
|
|
22974
|
-
return Object.assign(Object.assign({ get unreadCount() {
|
|
22975
|
-
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
23376
|
+
const adLinkedObject = (ad) => {
|
|
23377
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
23378
|
+
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
23379
|
+
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
23380
|
+
markAsSeen: (placement) => {
|
|
23381
|
+
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
23382
|
+
},
|
|
23383
|
+
markLinkAsClicked: (placement) => {
|
|
23384
|
+
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
23385
|
+
},
|
|
23386
|
+
}, get advertiser() {
|
|
23387
|
+
var _a, _b;
|
|
23388
|
+
const advertiserData = (_a = pullFromCache([
|
|
23389
|
+
'advertiser',
|
|
23390
|
+
'get',
|
|
23391
|
+
ad.advertiserId,
|
|
23392
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23393
|
+
if (!advertiserData)
|
|
23394
|
+
return;
|
|
23395
|
+
const avatarFile = (_b = pullFromCache([
|
|
23396
|
+
'file',
|
|
23397
|
+
'get',
|
|
23398
|
+
advertiserData.avatarFileId,
|
|
23399
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
23400
|
+
return Object.assign(Object.assign({}, advertiserData), { avatar: avatarFile });
|
|
22976
23401
|
},
|
|
22977
|
-
get
|
|
22978
|
-
|
|
23402
|
+
get image1_1() {
|
|
23403
|
+
const cacheData = pullFromCache(['file', 'get', image11]);
|
|
23404
|
+
if (!cacheData)
|
|
23405
|
+
return undefined;
|
|
23406
|
+
return cacheData.data || undefined;
|
|
22979
23407
|
},
|
|
22980
|
-
get
|
|
22981
|
-
|
|
22982
|
-
|
|
22983
|
-
|
|
23408
|
+
get image9_16() {
|
|
23409
|
+
const cacheData = pullFromCache(['file', 'get', image916]);
|
|
23410
|
+
if (!cacheData)
|
|
23411
|
+
return undefined;
|
|
23412
|
+
return cacheData.data || undefined;
|
|
23413
|
+
} });
|
|
23414
|
+
};
|
|
22984
23415
|
|
|
22985
|
-
const
|
|
22986
|
-
var _a, _b, _c;
|
|
22987
|
-
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;
|
|
22988
|
-
if (localMessage) {
|
|
22989
|
-
return Object.assign(Object.assign(Object.assign({}, localMessage), payload), {
|
|
22990
|
-
// NOTE: referenceId is missing in the some payload event. If we have local message data with referenceId, use it instead.
|
|
22991
|
-
referenceId: (_c = localMessage.referenceId) !== null && _c !== void 0 ? _c : payload.referenceId });
|
|
22992
|
-
}
|
|
22993
|
-
return payload;
|
|
22994
|
-
};
|
|
22995
|
-
function convertFromRaw$1(message, reactors, event) {
|
|
23416
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
22996
23417
|
var _a;
|
|
22997
|
-
const
|
|
22998
|
-
const
|
|
22999
|
-
|
|
23000
|
-
|
|
23001
|
-
|
|
23002
|
-
}
|
|
23003
|
-
|
|
23004
|
-
|
|
23005
|
-
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
|
|
23011
|
-
|
|
23012
|
-
|
|
23013
|
-
|
|
23014
|
-
|
|
23015
|
-
|
|
23016
|
-
|
|
23017
|
-
|
|
23018
|
-
|
|
23019
|
-
}
|
|
23020
|
-
return { type: 'user', userIds: mention.userPublicIds };
|
|
23021
|
-
});
|
|
23022
|
-
}
|
|
23023
|
-
if (reactors && reactors.length && event) {
|
|
23024
|
-
// mqtt event
|
|
23025
|
-
prepareMessagePayloadForCache(out, reactors, event);
|
|
23026
|
-
}
|
|
23027
|
-
return out;
|
|
23028
|
-
}
|
|
23029
|
-
const preUpdateMessageCache = (rawPayload) => {
|
|
23030
|
-
ingestInCache({
|
|
23031
|
-
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
23032
|
-
});
|
|
23033
|
-
};
|
|
23034
|
-
const DEBOUNCE_TIME = 2000;
|
|
23035
|
-
const currentDebounceMap = {};
|
|
23036
|
-
const prepareMessagePayload = async (payload, event) => {
|
|
23037
|
-
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
23038
|
-
if (markerIds.length > 0) {
|
|
23039
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
23040
|
-
preUpdateMessageCache(payload);
|
|
23041
|
-
const markerIdsKey = markerIds.join('');
|
|
23042
|
-
if (currentDebounceMap[markerIdsKey]) {
|
|
23043
|
-
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
23044
|
-
}
|
|
23045
|
-
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
23046
|
-
try {
|
|
23047
|
-
getMessageMarkers(markerIds);
|
|
23048
|
-
}
|
|
23049
|
-
catch (_error) {
|
|
23050
|
-
// do nothing
|
|
23051
|
-
}
|
|
23052
|
-
}, DEBOUNCE_TIME);
|
|
23053
|
-
}
|
|
23054
|
-
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
23055
|
-
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
23056
|
-
if (messageFeeds && messageFeeds.length > 0) {
|
|
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
|
-
});
|
|
23064
|
-
}
|
|
23065
|
-
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
23066
|
-
};
|
|
23067
|
-
function convertParams(_a) {
|
|
23068
|
-
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
23069
|
-
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
23070
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
23071
|
-
}
|
|
23072
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
23073
|
-
}
|
|
23074
|
-
function convertQueryParams$1(_a) {
|
|
23075
|
-
var { sortBy, subChannelId, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
23076
|
-
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
23077
|
-
sortBy,
|
|
23078
|
-
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
23079
|
-
around: aroundMessageId,
|
|
23080
|
-
} });
|
|
23081
|
-
if (includingTags) {
|
|
23082
|
-
out.includeTags = includingTags;
|
|
23083
|
-
}
|
|
23084
|
-
if (type) {
|
|
23085
|
-
out.dataType = type;
|
|
23086
|
-
}
|
|
23087
|
-
if (excludingTags) {
|
|
23088
|
-
out.excludeTags = excludingTags;
|
|
23089
|
-
}
|
|
23090
|
-
return out;
|
|
23091
|
-
}
|
|
23418
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
23419
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
23420
|
+
var _a;
|
|
23421
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
23422
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
23423
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
23424
|
+
get post() {
|
|
23425
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
23426
|
+
return;
|
|
23427
|
+
return postLinkedObject(postCached.data);
|
|
23428
|
+
},
|
|
23429
|
+
get target() {
|
|
23430
|
+
const pinTarget = pullFromCache([
|
|
23431
|
+
'pinTarget',
|
|
23432
|
+
'get',
|
|
23433
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
23434
|
+
]);
|
|
23435
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
23436
|
+
return;
|
|
23437
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
23438
|
+
} });
|
|
23439
|
+
};
|
|
23092
23440
|
|
|
23093
|
-
const
|
|
23441
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
23442
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
23443
|
+
.map(({ publicId }) => pullFromCache(['user', 'get', publicId]))
|
|
23444
|
+
.filter(isNonNullable)
|
|
23445
|
+
.map(({ data }) => data)
|
|
23446
|
+
.map(user => userLinkedObject(user)) });
|
|
23447
|
+
};
|
|
23448
|
+
|
|
23449
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
23450
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
23451
|
+
};
|
|
23452
|
+
|
|
23453
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
23454
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
23455
|
+
};
|
|
23456
|
+
|
|
23457
|
+
/* begin_public_function
|
|
23458
|
+
id: invitation.createInvitations
|
|
23459
|
+
*/
|
|
23094
23460
|
/**
|
|
23095
|
-
*
|
|
23461
|
+
* ```js
|
|
23462
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
23463
|
+
* const created = await createInvitations({
|
|
23464
|
+
* type: string,
|
|
23465
|
+
* targetType: string,
|
|
23466
|
+
* targetId: string,
|
|
23467
|
+
* userIds: string[]
|
|
23468
|
+
* }))
|
|
23469
|
+
* ```
|
|
23470
|
+
*
|
|
23471
|
+
* Creates an {@link Amity.Invitation}
|
|
23472
|
+
*
|
|
23473
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
23474
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
23475
|
+
*
|
|
23476
|
+
* @category Invitation API
|
|
23477
|
+
* @async
|
|
23096
23478
|
*/
|
|
23097
|
-
const
|
|
23098
|
-
const
|
|
23099
|
-
|
|
23100
|
-
|
|
23101
|
-
|
|
23479
|
+
const createInvitations = async (bundle) => {
|
|
23480
|
+
const client = getActiveClient();
|
|
23481
|
+
client.log('invitation/createInvitations', bundle);
|
|
23482
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
23483
|
+
const data = prepareInvitationPayload(payload);
|
|
23484
|
+
const cachedAt = client.cache && Date.now();
|
|
23485
|
+
if (client.cache)
|
|
23486
|
+
ingestInCache(data, { cachedAt });
|
|
23487
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
23488
|
+
return {
|
|
23489
|
+
data: data.invitations,
|
|
23490
|
+
cachedAt,
|
|
23491
|
+
};
|
|
23102
23492
|
};
|
|
23103
|
-
|
|
23104
|
-
|
|
23105
|
-
|
|
23106
|
-
|
|
23107
|
-
|
|
23108
|
-
|
|
23109
|
-
|
|
23110
|
-
|
|
23111
|
-
|
|
23112
|
-
|
|
23113
|
-
|
|
23114
|
-
|
|
23115
|
-
|
|
23493
|
+
/* end_public_function */
|
|
23494
|
+
|
|
23495
|
+
/* begin_public_function
|
|
23496
|
+
id: invitation.accept
|
|
23497
|
+
*/
|
|
23498
|
+
/**
|
|
23499
|
+
* ```js
|
|
23500
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
23501
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
23502
|
+
* ```
|
|
23503
|
+
*
|
|
23504
|
+
* Accepts a {@link Amity.Invitation} object
|
|
23505
|
+
*
|
|
23506
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
23507
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
23508
|
+
*
|
|
23509
|
+
* @category Invitation API
|
|
23510
|
+
* @async
|
|
23511
|
+
*/
|
|
23512
|
+
const acceptInvitation = async (invitationId) => {
|
|
23513
|
+
var _a;
|
|
23514
|
+
const client = getActiveClient();
|
|
23515
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
23516
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
23517
|
+
const invitation = (_a = pullFromCache([
|
|
23518
|
+
'invitation',
|
|
23519
|
+
'get',
|
|
23520
|
+
invitationId,
|
|
23521
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23522
|
+
if (invitation) {
|
|
23523
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
23524
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
23116
23525
|
}
|
|
23117
|
-
|
|
23118
|
-
// attach marker to sub channel
|
|
23119
|
-
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
23120
|
-
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
23121
|
-
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
23122
|
-
messages });
|
|
23526
|
+
return data.success;
|
|
23123
23527
|
};
|
|
23124
|
-
|
|
23125
|
-
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
23126
|
-
const out = Object.assign({}, rest);
|
|
23127
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
23128
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
23129
|
-
}
|
|
23130
|
-
return out;
|
|
23131
|
-
}
|
|
23528
|
+
/* end_public_function */
|
|
23132
23529
|
|
|
23530
|
+
/* begin_public_function
|
|
23531
|
+
id: invitation.reject
|
|
23532
|
+
*/
|
|
23133
23533
|
/**
|
|
23134
23534
|
* ```js
|
|
23135
|
-
* import {
|
|
23136
|
-
* const
|
|
23535
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
23536
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
23137
23537
|
* ```
|
|
23138
23538
|
*
|
|
23139
|
-
*
|
|
23539
|
+
* Rejects a {@link Amity.Invitation} object
|
|
23140
23540
|
*
|
|
23141
|
-
* @param
|
|
23142
|
-
* @returns the
|
|
23541
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
23542
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
23143
23543
|
*
|
|
23144
|
-
* @category
|
|
23544
|
+
* @category Invitation API
|
|
23145
23545
|
* @async
|
|
23146
23546
|
*/
|
|
23147
|
-
const
|
|
23547
|
+
const rejectInvitation = async (invitationId) => {
|
|
23548
|
+
var _a;
|
|
23148
23549
|
const client = getActiveClient();
|
|
23149
|
-
client.log('
|
|
23150
|
-
|
|
23151
|
-
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
|
|
23157
|
-
|
|
23158
|
-
|
|
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;
|
|
23550
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
23551
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
23552
|
+
const invitation = (_a = pullFromCache([
|
|
23553
|
+
'invitation',
|
|
23554
|
+
'get',
|
|
23555
|
+
invitationId,
|
|
23556
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23557
|
+
if (invitation) {
|
|
23558
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
23559
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
23168
23560
|
}
|
|
23561
|
+
return data.success;
|
|
23169
23562
|
};
|
|
23563
|
+
/* end_public_function */
|
|
23564
|
+
|
|
23565
|
+
/* begin_public_function
|
|
23566
|
+
id: invitation.cancel
|
|
23567
|
+
*/
|
|
23170
23568
|
/**
|
|
23171
23569
|
* ```js
|
|
23172
|
-
* import {
|
|
23173
|
-
* const
|
|
23570
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
23571
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
23174
23572
|
* ```
|
|
23175
23573
|
*
|
|
23176
|
-
*
|
|
23574
|
+
* Cancels a {@link Amity.Invitation} object
|
|
23177
23575
|
*
|
|
23178
|
-
* @param
|
|
23179
|
-
* @returns the
|
|
23576
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
23577
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
23180
23578
|
*
|
|
23181
|
-
* @category
|
|
23579
|
+
* @category Invitation API
|
|
23580
|
+
* @async
|
|
23182
23581
|
*/
|
|
23183
|
-
|
|
23582
|
+
const cancelInvitation = async (invitationId) => {
|
|
23583
|
+
var _a;
|
|
23184
23584
|
const client = getActiveClient();
|
|
23185
|
-
client.log('
|
|
23186
|
-
|
|
23187
|
-
|
|
23188
|
-
|
|
23189
|
-
|
|
23190
|
-
|
|
23191
|
-
|
|
23192
|
-
|
|
23193
|
-
|
|
23194
|
-
|
|
23585
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
23586
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
23587
|
+
const invitation = (_a = pullFromCache([
|
|
23588
|
+
'invitation',
|
|
23589
|
+
'get',
|
|
23590
|
+
invitationId,
|
|
23591
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23592
|
+
if (invitation) {
|
|
23593
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
23594
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
23595
|
+
}
|
|
23596
|
+
return data.success;
|
|
23597
|
+
};
|
|
23598
|
+
/* end_public_function */
|
|
23599
|
+
|
|
23600
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
23601
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
23195
23602
|
};
|
|
23196
23603
|
|
|
23197
|
-
const
|
|
23198
|
-
return
|
|
23604
|
+
const invitationLinkedObject = (invitation) => {
|
|
23605
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
23606
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
23607
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23608
|
+
return userLinkedObject(cacheData.data);
|
|
23609
|
+
return undefined;
|
|
23610
|
+
},
|
|
23611
|
+
get createdBy() {
|
|
23612
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
23613
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23614
|
+
return userLinkedObject(cacheData.data);
|
|
23615
|
+
return undefined;
|
|
23616
|
+
},
|
|
23617
|
+
get target() {
|
|
23618
|
+
if (invitation.targetType === 'community') {
|
|
23619
|
+
const cacheData = pullFromCache([
|
|
23620
|
+
'community',
|
|
23621
|
+
'get',
|
|
23622
|
+
invitation.targetId,
|
|
23623
|
+
]);
|
|
23624
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23625
|
+
return cacheData.data;
|
|
23626
|
+
return undefined;
|
|
23627
|
+
}
|
|
23628
|
+
return undefined;
|
|
23629
|
+
}, accept: async () => {
|
|
23630
|
+
await acceptInvitation(invitation._id);
|
|
23631
|
+
}, reject: async () => {
|
|
23632
|
+
await rejectInvitation(invitation._id);
|
|
23633
|
+
}, cancel: async () => {
|
|
23634
|
+
await cancelInvitation(invitation._id);
|
|
23635
|
+
} });
|
|
23199
23636
|
};
|
|
23200
23637
|
|
|
23201
|
-
|
|
23638
|
+
/* begin_public_function
|
|
23639
|
+
id: invitation.get
|
|
23640
|
+
*/
|
|
23641
|
+
/**
|
|
23642
|
+
* ```js
|
|
23643
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
23644
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
23645
|
+
* ```
|
|
23646
|
+
*
|
|
23647
|
+
* Get a {@link Amity.Invitation} object
|
|
23648
|
+
*
|
|
23649
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
23650
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
23651
|
+
* @returns A {@link Amity.Invitation} object
|
|
23652
|
+
*
|
|
23653
|
+
* @category Invitation API
|
|
23654
|
+
* @async
|
|
23655
|
+
*/
|
|
23656
|
+
const getInvitation = async (targetType, targetId) => {
|
|
23202
23657
|
const client = getActiveClient();
|
|
23203
|
-
|
|
23658
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
23659
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
23660
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
23661
|
+
const cachedAt = client.cache && Date.now();
|
|
23662
|
+
if (client.cache)
|
|
23663
|
+
ingestInCache(data, { cachedAt });
|
|
23664
|
+
return {
|
|
23665
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
23666
|
+
cachedAt,
|
|
23667
|
+
};
|
|
23204
23668
|
};
|
|
23205
|
-
|
|
23206
|
-
|
|
23207
|
-
|
|
23208
|
-
|
|
23209
|
-
|
|
23669
|
+
/* end_public_function */
|
|
23670
|
+
|
|
23671
|
+
var InvitationActionsEnum;
|
|
23672
|
+
(function (InvitationActionsEnum) {
|
|
23673
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
23674
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
23675
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
23676
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
23677
|
+
|
|
23678
|
+
class PaginationController {
|
|
23679
|
+
constructor(queryParams) {
|
|
23680
|
+
const { http } = getActiveClient();
|
|
23681
|
+
this.queryParams = queryParams;
|
|
23682
|
+
this.http = http;
|
|
23210
23683
|
}
|
|
23211
|
-
|
|
23212
|
-
|
|
23213
|
-
const isLastestMessageOnSubchannel = (message) => {
|
|
23214
|
-
var _a;
|
|
23215
|
-
const cache = (_a = pullFromCache([
|
|
23216
|
-
'messagePreviewSubChannel',
|
|
23217
|
-
'get',
|
|
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,
|
|
23247
|
-
});
|
|
23248
|
-
return;
|
|
23684
|
+
loadFirstPage() {
|
|
23685
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
23249
23686
|
}
|
|
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
|
-
});
|
|
23687
|
+
loadNextPage() {
|
|
23688
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
23300
23689
|
}
|
|
23301
|
-
|
|
23302
|
-
|
|
23303
|
-
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
23304
|
-
if (isLastestMessageOnChannel(message)) {
|
|
23305
|
-
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
23306
|
-
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
23307
|
-
channelId,
|
|
23308
|
-
creatorId,
|
|
23309
|
-
messagePreviewId,
|
|
23310
|
-
createdAt,
|
|
23311
|
-
updatedAt,
|
|
23312
|
-
subChannelId,
|
|
23313
|
-
data,
|
|
23314
|
-
dataType,
|
|
23315
|
-
segment,
|
|
23316
|
-
isDeleted,
|
|
23317
|
-
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
23318
|
-
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
23319
|
-
});
|
|
23690
|
+
loadPreviousPage() {
|
|
23691
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
23320
23692
|
}
|
|
23321
|
-
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23325
|
-
|
|
23326
|
-
|
|
23327
|
-
|
|
23328
|
-
|
|
23329
|
-
|
|
23330
|
-
'
|
|
23331
|
-
|
|
23332
|
-
|
|
23333
|
-
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
|
|
23341
|
-
|
|
23342
|
-
subChannelId,
|
|
23343
|
-
data,
|
|
23344
|
-
dataType,
|
|
23345
|
-
segment,
|
|
23346
|
-
isDeleted,
|
|
23347
|
-
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
23348
|
-
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
23349
|
-
});
|
|
23693
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
23694
|
+
var _a, _b, _c, _d;
|
|
23695
|
+
if (direction === 'prev' && !this.previousToken)
|
|
23696
|
+
return;
|
|
23697
|
+
if (direction === 'next' && !this.nextToken)
|
|
23698
|
+
return;
|
|
23699
|
+
let token;
|
|
23700
|
+
if (direction === 'prev')
|
|
23701
|
+
token = this.previousToken;
|
|
23702
|
+
if (direction === 'next')
|
|
23703
|
+
token = this.nextToken;
|
|
23704
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
23705
|
+
if (direction === 'first') {
|
|
23706
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
23707
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
23708
|
+
}
|
|
23709
|
+
if (direction === 'prev')
|
|
23710
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
23711
|
+
if (direction === 'next')
|
|
23712
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
23713
|
+
return queryResponse;
|
|
23350
23714
|
}
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
var _a, _b, _c, _d;
|
|
23354
|
-
const { channelId, subChannelId } = subChannel;
|
|
23355
|
-
/** Channel Case */
|
|
23356
|
-
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
23357
|
-
'messagePreviewChannel',
|
|
23358
|
-
'get',
|
|
23359
|
-
channelId,
|
|
23360
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23361
|
-
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.subChannelId) === subChannelId) {
|
|
23362
|
-
const subChannelCache = (_b = pullFromCache([
|
|
23363
|
-
'subChannel',
|
|
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 }));
|
|
23715
|
+
getNextToken() {
|
|
23716
|
+
return this.nextToken;
|
|
23368
23717
|
}
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
|
|
23375
|
-
|
|
23376
|
-
|
|
23377
|
-
|
|
23378
|
-
const
|
|
23379
|
-
|
|
23380
|
-
|
|
23381
|
-
|
|
23382
|
-
|
|
23383
|
-
|
|
23718
|
+
getPrevToken() {
|
|
23719
|
+
return this.previousToken;
|
|
23720
|
+
}
|
|
23721
|
+
}
|
|
23722
|
+
|
|
23723
|
+
class InvitationsPaginationController extends PaginationController {
|
|
23724
|
+
async getRequest(queryParams, token) {
|
|
23725
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23726
|
+
const options = token ? { token } : { limit };
|
|
23727
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
23728
|
+
return data;
|
|
23729
|
+
}
|
|
23730
|
+
}
|
|
23731
|
+
|
|
23732
|
+
class QueryStreamController {
|
|
23733
|
+
constructor(query, cacheKey) {
|
|
23734
|
+
this.query = query;
|
|
23735
|
+
this.cacheKey = cacheKey;
|
|
23736
|
+
}
|
|
23737
|
+
}
|
|
23738
|
+
|
|
23739
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
23740
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23741
|
+
super(query, cacheKey);
|
|
23742
|
+
this.notifyChange = notifyChange;
|
|
23743
|
+
this.preparePayload = preparePayload;
|
|
23744
|
+
}
|
|
23745
|
+
async saveToMainDB(response) {
|
|
23746
|
+
const processedPayload = await this.preparePayload(response);
|
|
23747
|
+
const client = getActiveClient();
|
|
23748
|
+
const cachedAt = client.cache && Date.now();
|
|
23749
|
+
if (client.cache) {
|
|
23750
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23751
|
+
}
|
|
23752
|
+
}
|
|
23753
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23754
|
+
var _a, _b;
|
|
23755
|
+
if (refresh) {
|
|
23756
|
+
pushToCache(this.cacheKey, {
|
|
23757
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
23758
|
+
});
|
|
23759
|
+
}
|
|
23760
|
+
else {
|
|
23761
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23762
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23763
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23764
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
23765
|
+
] }));
|
|
23766
|
+
}
|
|
23767
|
+
}
|
|
23768
|
+
reactor(action) {
|
|
23769
|
+
return (invitations) => {
|
|
23770
|
+
var _a;
|
|
23771
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23772
|
+
if (!collection)
|
|
23773
|
+
return;
|
|
23774
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
23775
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
23776
|
+
if (!isExist)
|
|
23777
|
+
return;
|
|
23778
|
+
}
|
|
23779
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
23780
|
+
collection.data = [
|
|
23781
|
+
...new Set([
|
|
23782
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
23783
|
+
...collection.data,
|
|
23784
|
+
]),
|
|
23785
|
+
];
|
|
23786
|
+
}
|
|
23787
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
23788
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
23789
|
+
}
|
|
23790
|
+
pushToCache(this.cacheKey, collection);
|
|
23791
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23792
|
+
};
|
|
23793
|
+
}
|
|
23794
|
+
subscribeRTE(createSubscriber) {
|
|
23795
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23384
23796
|
}
|
|
23385
|
-
};
|
|
23386
|
-
|
|
23387
|
-
function convertRawUserToInternalUser(rawUser) {
|
|
23388
|
-
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
23389
23797
|
}
|
|
23390
23798
|
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
23394
|
-
var _a;
|
|
23395
|
-
let { messagePreviewId } = channel;
|
|
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;
|
|
23403
|
-
}
|
|
23404
|
-
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
23799
|
+
function isObject(value) {
|
|
23800
|
+
return typeof value === 'object' && value !== null;
|
|
23405
23801
|
}
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
|
|
23802
|
+
/**
|
|
23803
|
+
* convert all object getter property to static value
|
|
23804
|
+
*/
|
|
23805
|
+
const convertGetterPropsToStatic = (obj) => {
|
|
23806
|
+
if (!isObject(obj)) {
|
|
23807
|
+
return obj;
|
|
23808
|
+
}
|
|
23809
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23810
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
23811
|
+
if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
|
|
23812
|
+
return [key, descriptor.get.call(obj)];
|
|
23813
|
+
}
|
|
23814
|
+
return [key, value];
|
|
23409
23815
|
});
|
|
23816
|
+
return Object.fromEntries(entries);
|
|
23410
23817
|
};
|
|
23411
|
-
const
|
|
23412
|
-
|
|
23413
|
-
|
|
23414
|
-
|
|
23415
|
-
|
|
23416
|
-
|
|
23417
|
-
|
|
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;
|
|
23818
|
+
const removeFunctionProperties = (obj) => {
|
|
23819
|
+
if (!isObject(obj)) {
|
|
23820
|
+
return obj;
|
|
23821
|
+
}
|
|
23822
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
23823
|
+
if (typeof value === 'function') {
|
|
23824
|
+
return [key, undefined];
|
|
23424
23825
|
}
|
|
23425
|
-
|
|
23426
|
-
|
|
23427
|
-
|
|
23428
|
-
|
|
23429
|
-
|
|
23430
|
-
|
|
23431
|
-
|
|
23432
|
-
|
|
23433
|
-
|
|
23434
|
-
|
|
23826
|
+
return [key, value];
|
|
23827
|
+
});
|
|
23828
|
+
return Object.fromEntries(entries);
|
|
23829
|
+
};
|
|
23830
|
+
|
|
23831
|
+
class PaginationNoPageController {
|
|
23832
|
+
constructor(queryParams) {
|
|
23833
|
+
const { http } = getActiveClient();
|
|
23834
|
+
this.queryParams = queryParams;
|
|
23835
|
+
this.http = http;
|
|
23435
23836
|
}
|
|
23436
|
-
|
|
23437
|
-
const
|
|
23438
|
-
|
|
23439
|
-
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
23440
|
-
if (options.isMessagePreviewUpdated &&
|
|
23441
|
-
networkPreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */ &&
|
|
23442
|
-
rawPayload.messagePreviews &&
|
|
23443
|
-
rawPayload.messagePreviews.length > 0) {
|
|
23444
|
-
updateChannelMessagePreviewCache(rawPayload);
|
|
23837
|
+
async onFetch() {
|
|
23838
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
23839
|
+
return queryResponse;
|
|
23445
23840
|
}
|
|
23446
|
-
|
|
23447
|
-
|
|
23448
|
-
|
|
23449
|
-
|
|
23450
|
-
|
|
23451
|
-
|
|
23841
|
+
}
|
|
23842
|
+
|
|
23843
|
+
class LiveCollectionController {
|
|
23844
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
23845
|
+
this.paginationController = paginationController;
|
|
23846
|
+
this.queryStreamId = queryStreamId;
|
|
23847
|
+
this.cacheKey = cacheKey;
|
|
23848
|
+
this.callback = callback;
|
|
23452
23849
|
}
|
|
23453
|
-
|
|
23454
|
-
|
|
23455
|
-
|
|
23456
|
-
.
|
|
23457
|
-
|
|
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,
|
|
23462
|
-
});
|
|
23463
|
-
try {
|
|
23464
|
-
await getChannelMarkers(markerIds);
|
|
23850
|
+
async refresh() {
|
|
23851
|
+
try {
|
|
23852
|
+
let result;
|
|
23853
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
23854
|
+
result = await this.paginationController.onFetch();
|
|
23465
23855
|
}
|
|
23466
|
-
|
|
23467
|
-
|
|
23856
|
+
else {
|
|
23857
|
+
result = await this.paginationController.loadFirstPage();
|
|
23468
23858
|
}
|
|
23859
|
+
if (!result)
|
|
23860
|
+
return;
|
|
23861
|
+
await this.persistModel(result);
|
|
23862
|
+
this.persistQueryStream({
|
|
23863
|
+
response: result,
|
|
23864
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23865
|
+
refresh: true,
|
|
23866
|
+
});
|
|
23867
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23868
|
+
}
|
|
23869
|
+
catch (e) {
|
|
23870
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23469
23871
|
}
|
|
23470
23872
|
}
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
|
|
23479
|
-
|
|
23480
|
-
|
|
23481
|
-
|
|
23482
|
-
}
|
|
23873
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
23874
|
+
this.setup();
|
|
23875
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
23876
|
+
if (initial) {
|
|
23877
|
+
this.refresh();
|
|
23878
|
+
}
|
|
23879
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
23880
|
+
this.loadPrevPage();
|
|
23881
|
+
}
|
|
23882
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
23883
|
+
this.loadNextPage();
|
|
23884
|
+
}
|
|
23885
|
+
}
|
|
23886
|
+
async loadNextPage() {
|
|
23887
|
+
try {
|
|
23888
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
23889
|
+
return;
|
|
23890
|
+
const result = await this.paginationController.loadNextPage();
|
|
23891
|
+
if (!result)
|
|
23892
|
+
return;
|
|
23893
|
+
await this.persistModel(result);
|
|
23894
|
+
this.persistQueryStream({
|
|
23895
|
+
response: result,
|
|
23896
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
23897
|
+
});
|
|
23898
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23899
|
+
}
|
|
23900
|
+
catch (e) {
|
|
23901
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23902
|
+
}
|
|
23903
|
+
}
|
|
23904
|
+
async loadPrevPage() {
|
|
23905
|
+
try {
|
|
23906
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
23907
|
+
return;
|
|
23908
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
23909
|
+
if (!result)
|
|
23910
|
+
return;
|
|
23911
|
+
await this.persistModel(result);
|
|
23912
|
+
this.persistQueryStream({
|
|
23913
|
+
response: result,
|
|
23914
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
23915
|
+
});
|
|
23916
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
23917
|
+
}
|
|
23918
|
+
catch (e) {
|
|
23919
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
23920
|
+
}
|
|
23921
|
+
}
|
|
23922
|
+
shouldNotify(data) {
|
|
23923
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
23924
|
+
if (isEqual(this.snapshot, newData))
|
|
23925
|
+
return false;
|
|
23926
|
+
this.snapshot = newData;
|
|
23927
|
+
return true;
|
|
23928
|
+
}
|
|
23929
|
+
getCacheKey() {
|
|
23930
|
+
return this.cacheKey;
|
|
23931
|
+
}
|
|
23932
|
+
}
|
|
23483
23933
|
|
|
23484
23934
|
/**
|
|
23485
23935
|
* ```js
|
|
23486
|
-
* import {
|
|
23487
|
-
* const
|
|
23936
|
+
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
23937
|
+
* const dispose = onLocalInvitationCreated(data => {
|
|
23938
|
+
* // ...
|
|
23939
|
+
* })
|
|
23488
23940
|
* ```
|
|
23489
23941
|
*
|
|
23490
|
-
*
|
|
23942
|
+
* Fired when an {@link Amity.InvitationPayload} has been created
|
|
23491
23943
|
*
|
|
23492
|
-
* @param
|
|
23493
|
-
* @
|
|
23494
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
23944
|
+
* @param callback The function to call when the event was fired
|
|
23945
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23495
23946
|
*
|
|
23496
|
-
* @category
|
|
23497
|
-
* @async
|
|
23498
|
-
* @private
|
|
23947
|
+
* @category Invitation Events
|
|
23499
23948
|
*/
|
|
23500
|
-
const
|
|
23949
|
+
const onLocalInvitationCreated = (callback) => {
|
|
23501
23950
|
const client = getActiveClient();
|
|
23502
|
-
|
|
23503
|
-
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23507
|
-
}
|
|
23508
|
-
fireEvent('local.userMessageFeedMarker.fetched', { userMessageFeedMarker: data });
|
|
23509
|
-
return data;
|
|
23951
|
+
const disposers = [
|
|
23952
|
+
createEventSubscriber(client, 'onLocalInvitationCreated', 'local.invitation.created', payload => callback(payload)),
|
|
23953
|
+
];
|
|
23954
|
+
return () => {
|
|
23955
|
+
disposers.forEach(fn => fn());
|
|
23956
|
+
};
|
|
23510
23957
|
};
|
|
23511
23958
|
|
|
23512
|
-
|
|
23959
|
+
/**
|
|
23960
|
+
* ```js
|
|
23961
|
+
* import { onLocalInvitationUpdated } from '@amityco/ts-sdk'
|
|
23962
|
+
* const dispose = onLocalInvitationUpdated(data => {
|
|
23963
|
+
* // ...
|
|
23964
|
+
* })
|
|
23965
|
+
* ```
|
|
23966
|
+
*
|
|
23967
|
+
* Fired when an {@link Amity.InvitationPayload} has been updated
|
|
23968
|
+
*
|
|
23969
|
+
* @param callback The function to call when the event was fired
|
|
23970
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23971
|
+
*
|
|
23972
|
+
* @category Invitation Events
|
|
23973
|
+
*/
|
|
23974
|
+
const onLocalInvitationUpdated = (callback) => {
|
|
23513
23975
|
const client = getActiveClient();
|
|
23514
|
-
|
|
23515
|
-
|
|
23516
|
-
|
|
23517
|
-
|
|
23518
|
-
|
|
23519
|
-
|
|
23520
|
-
userFeedMarkers,
|
|
23521
|
-
});
|
|
23522
|
-
client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
|
|
23976
|
+
const disposers = [
|
|
23977
|
+
createEventSubscriber(client, 'onLocalInvitationUpdated', 'local.invitation.updated', payload => callback(payload)),
|
|
23978
|
+
];
|
|
23979
|
+
return () => {
|
|
23980
|
+
disposers.forEach(fn => fn());
|
|
23981
|
+
};
|
|
23523
23982
|
};
|
|
23524
23983
|
|
|
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
23984
|
/**
|
|
23542
|
-
*
|
|
23543
|
-
*
|
|
23985
|
+
* ```js
|
|
23986
|
+
* import { onLocalInvitationDeleted } from '@amityco/ts-sdk'
|
|
23987
|
+
* const dispose = onLocalInvitationDeleted(data => {
|
|
23988
|
+
* // ...
|
|
23989
|
+
* })
|
|
23990
|
+
* ```
|
|
23544
23991
|
*
|
|
23545
|
-
*
|
|
23546
|
-
*
|
|
23547
|
-
*
|
|
23992
|
+
* Fired when an {@link Amity.InvitationPayload} has been deleted
|
|
23993
|
+
*
|
|
23994
|
+
* @param callback The function to call when the event was fired
|
|
23995
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23996
|
+
*
|
|
23997
|
+
* @category Invitation Events
|
|
23548
23998
|
*/
|
|
23549
|
-
const
|
|
23550
|
-
var _a, _b, _c, _d;
|
|
23999
|
+
const onLocalInvitationDeleted = (callback) => {
|
|
23551
24000
|
const client = getActiveClient();
|
|
23552
|
-
|
|
23553
|
-
|
|
23554
|
-
|
|
23555
|
-
return (
|
|
23556
|
-
|
|
23557
|
-
|
|
24001
|
+
const disposers = [
|
|
24002
|
+
createEventSubscriber(client, 'onLocalInvitationDeleted', 'local.invitation.deleted', payload => callback(payload)),
|
|
24003
|
+
];
|
|
24004
|
+
return () => {
|
|
24005
|
+
disposers.forEach(fn => fn());
|
|
24006
|
+
};
|
|
23558
24007
|
};
|
|
23559
24008
|
|
|
23560
|
-
|
|
23561
|
-
|
|
23562
|
-
|
|
23563
|
-
|
|
23564
|
-
|
|
23565
|
-
|
|
23566
|
-
|
|
23567
|
-
|
|
23568
|
-
|
|
23569
|
-
|
|
23570
|
-
|
|
23571
|
-
|
|
23572
|
-
|
|
23573
|
-
|
|
23574
|
-
|
|
23575
|
-
|
|
24009
|
+
class InvitationsLiveCollectionController extends LiveCollectionController {
|
|
24010
|
+
constructor(query, callback) {
|
|
24011
|
+
const queryStreamId = hash(query);
|
|
24012
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
24013
|
+
const paginationController = new InvitationsPaginationController(query);
|
|
24014
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24015
|
+
this.query = query;
|
|
24016
|
+
this.queryStreamController = new InvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareInvitationPayload);
|
|
24017
|
+
this.callback = callback.bind(this);
|
|
24018
|
+
this.loadPage({ initial: true });
|
|
24019
|
+
}
|
|
24020
|
+
setup() {
|
|
24021
|
+
var _a;
|
|
24022
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24023
|
+
if (!collection) {
|
|
24024
|
+
pushToCache(this.cacheKey, {
|
|
24025
|
+
data: [],
|
|
24026
|
+
params: this.query,
|
|
24027
|
+
});
|
|
24028
|
+
}
|
|
24029
|
+
}
|
|
24030
|
+
async persistModel(queryPayload) {
|
|
24031
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24032
|
+
}
|
|
24033
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24034
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24035
|
+
}
|
|
24036
|
+
startSubscription() {
|
|
24037
|
+
return this.queryStreamController.subscribeRTE([
|
|
24038
|
+
{
|
|
24039
|
+
fn: onLocalInvitationCreated,
|
|
24040
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
24041
|
+
},
|
|
24042
|
+
{
|
|
24043
|
+
fn: onLocalInvitationUpdated,
|
|
24044
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
24045
|
+
},
|
|
24046
|
+
{
|
|
24047
|
+
fn: onLocalInvitationDeleted,
|
|
24048
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
24049
|
+
},
|
|
24050
|
+
]);
|
|
24051
|
+
}
|
|
24052
|
+
notifyChange({ origin, loading, error }) {
|
|
24053
|
+
var _a, _b;
|
|
24054
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24055
|
+
if (!collection)
|
|
24056
|
+
return;
|
|
24057
|
+
const data = this.applyFilter((_b = collection.data
|
|
24058
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
24059
|
+
.filter(isNonNullable)
|
|
24060
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
24061
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24062
|
+
return;
|
|
24063
|
+
this.callback({
|
|
24064
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24065
|
+
data,
|
|
24066
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24067
|
+
loading,
|
|
24068
|
+
error,
|
|
24069
|
+
});
|
|
24070
|
+
}
|
|
24071
|
+
applyFilter(data) {
|
|
24072
|
+
let invitations = data;
|
|
24073
|
+
if (this.query.targetId) {
|
|
24074
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
24075
|
+
}
|
|
24076
|
+
if (this.query.statuses) {
|
|
24077
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
24078
|
+
}
|
|
24079
|
+
if (this.query.targetType) {
|
|
24080
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
24081
|
+
}
|
|
24082
|
+
if (this.query.type) {
|
|
24083
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
24084
|
+
}
|
|
24085
|
+
const sortFn = (() => {
|
|
24086
|
+
switch (this.query.sortBy) {
|
|
24087
|
+
case 'firstCreated':
|
|
24088
|
+
return sortByFirstCreated;
|
|
24089
|
+
case 'lastCreated':
|
|
24090
|
+
return sortByLastCreated;
|
|
24091
|
+
default:
|
|
24092
|
+
return sortByLastCreated;
|
|
24093
|
+
}
|
|
24094
|
+
})();
|
|
24095
|
+
invitations = invitations.sort(sortFn);
|
|
24096
|
+
return invitations;
|
|
24097
|
+
}
|
|
24098
|
+
}
|
|
24099
|
+
|
|
23576
24100
|
/**
|
|
23577
|
-
*
|
|
23578
|
-
*
|
|
24101
|
+
* Get invitations
|
|
24102
|
+
*
|
|
24103
|
+
* @param params the query parameters
|
|
24104
|
+
* @param callback the callback to be called when the invitations are updated
|
|
24105
|
+
* @returns invitations
|
|
24106
|
+
*
|
|
24107
|
+
* @category Invitation Live Collection
|
|
23579
24108
|
*
|
|
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
24109
|
*/
|
|
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;
|
|
24110
|
+
const getInvitations = (params, callback, config) => {
|
|
24111
|
+
const { log, cache } = getActiveClient();
|
|
24112
|
+
if (!cache) {
|
|
24113
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23596
24114
|
}
|
|
23597
|
-
|
|
24115
|
+
const timestamp = Date.now();
|
|
24116
|
+
log(`getInvitations: (tmpid: ${timestamp}) > listen`);
|
|
24117
|
+
const invitationsLiveCollection = new InvitationsLiveCollectionController(params, callback);
|
|
24118
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
24119
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
24120
|
+
disposers.push(() => {
|
|
24121
|
+
dropFromCache(cacheKey);
|
|
24122
|
+
});
|
|
24123
|
+
return () => {
|
|
24124
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
24125
|
+
disposers.forEach(fn => fn());
|
|
24126
|
+
};
|
|
23598
24127
|
};
|
|
23599
24128
|
|
|
23600
|
-
const
|
|
23601
|
-
|
|
23602
|
-
|
|
24129
|
+
const communityLinkedObject = (community) => {
|
|
24130
|
+
return Object.assign(Object.assign({}, community), { createInvitations: async (userIds) => {
|
|
24131
|
+
await createInvitations({
|
|
24132
|
+
type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
|
|
24133
|
+
targetType: 'community',
|
|
24134
|
+
targetId: community.communityId,
|
|
24135
|
+
userIds,
|
|
24136
|
+
});
|
|
24137
|
+
}, getMemberInvitations: (params, callback) => {
|
|
24138
|
+
return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
|
|
24139
|
+
}, getInvitation: async () => {
|
|
24140
|
+
const { data } = await getInvitation('community', community.communityId);
|
|
24141
|
+
return data;
|
|
24142
|
+
} });
|
|
23603
24143
|
};
|
|
23604
24144
|
|
|
23605
|
-
const
|
|
23606
|
-
|
|
23607
|
-
|
|
23608
|
-
|
|
23609
|
-
|
|
23610
|
-
|
|
23611
|
-
|
|
23612
|
-
|
|
23613
|
-
|
|
23614
|
-
|
|
23615
|
-
|
|
23616
|
-
|
|
23617
|
-
|
|
23618
|
-
|
|
23619
|
-
|
|
23620
|
-
|
|
23621
|
-
},
|
|
23622
|
-
});
|
|
24145
|
+
const LinkedObject = {
|
|
24146
|
+
ad: adLinkedObject,
|
|
24147
|
+
comment: commentLinkedObject,
|
|
24148
|
+
post: postLinkedObject,
|
|
24149
|
+
user: userLinkedObject,
|
|
24150
|
+
category: categoryLinkedObject,
|
|
24151
|
+
stream: streamLinkedObject,
|
|
24152
|
+
story: storyLinkedObject,
|
|
24153
|
+
storyTarget: storyTargetLinkedObject,
|
|
24154
|
+
message: messageLinkedObject,
|
|
24155
|
+
reactor: reactorLinkedObject,
|
|
24156
|
+
channel: channelLinkedObject,
|
|
24157
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
24158
|
+
notificationTray: notificationTrayLinkedObject,
|
|
24159
|
+
community: communityLinkedObject,
|
|
24160
|
+
invitation: invitationLinkedObject,
|
|
23623
24161
|
};
|
|
23624
24162
|
|
|
23625
24163
|
const constructChannelObject = (channel) => {
|
|
@@ -26341,38 +26879,6 @@ const onMessageMarked = (callback) => {
|
|
|
26341
26879
|
return createEventSubscriber(client, 'messageMarker/onMessageMarked', 'marker.marked-message', filter);
|
|
26342
26880
|
};
|
|
26343
26881
|
|
|
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
26882
|
/**
|
|
26377
26883
|
*
|
|
26378
26884
|
* ```js
|
|
@@ -26986,51 +27492,6 @@ const onLocalFollowRequestAccepted = (callback) => createLocalFollowEventSubscri
|
|
|
26986
27492
|
|
|
26987
27493
|
const onLocalFollowRequestDeclined = (callback) => createLocalFollowEventSubscriber('local.follow.requestDeclined', callback);
|
|
26988
27494
|
|
|
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
27495
|
class FollowerPaginationController extends PaginationController {
|
|
27035
27496
|
async getRequest(queryParams, token) {
|
|
27036
27497
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, userId } = queryParams, params = __rest(queryParams, ["limit", "userId"]);
|
|
@@ -27044,13 +27505,6 @@ class FollowerPaginationController extends PaginationController {
|
|
|
27044
27505
|
}
|
|
27045
27506
|
}
|
|
27046
27507
|
|
|
27047
|
-
class QueryStreamController {
|
|
27048
|
-
constructor(query, cacheKey) {
|
|
27049
|
-
this.query = query;
|
|
27050
|
-
this.cacheKey = cacheKey;
|
|
27051
|
-
}
|
|
27052
|
-
}
|
|
27053
|
-
|
|
27054
27508
|
var EnumFollowActions;
|
|
27055
27509
|
(function (EnumFollowActions) {
|
|
27056
27510
|
EnumFollowActions["OnRequested"] = "onRequested";
|
|
@@ -27118,109 +27572,6 @@ class FollowerQueryStreamController extends QueryStreamController {
|
|
|
27118
27572
|
}
|
|
27119
27573
|
}
|
|
27120
27574
|
|
|
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
27575
|
const onFollowerUserDeleted = ({ userId }) => (callback) => {
|
|
27225
27576
|
const client = getActiveClient();
|
|
27226
27577
|
const filter = (data) => {
|
|
@@ -34819,12 +35170,15 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34819
35170
|
* @category Community API
|
|
34820
35171
|
* @async
|
|
34821
35172
|
*/
|
|
34822
|
-
const getCommunities$1 = async (communityIds) => {
|
|
35173
|
+
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
34823
35174
|
const client = getActiveClient();
|
|
34824
35175
|
client.log('community/getCommunities', communityIds);
|
|
34825
35176
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
34826
35177
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
34827
|
-
params: {
|
|
35178
|
+
params: {
|
|
35179
|
+
communityIds,
|
|
35180
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35181
|
+
},
|
|
34828
35182
|
});
|
|
34829
35183
|
const data = prepareCommunityPayload(payload);
|
|
34830
35184
|
const cachedAt = client.cache && Date.now();
|
|
@@ -34911,7 +35265,7 @@ const createCommunity = async (bundle) => {
|
|
|
34911
35265
|
/**
|
|
34912
35266
|
* ```js
|
|
34913
35267
|
* import { updateCommunity } from '@amityco/ts-sdk'
|
|
34914
|
-
* const updated = await updateCommunity(communityId, { displayName: 'foobar' })
|
|
35268
|
+
* const updated = await updateCommunity(communityId, { displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
34915
35269
|
* ```
|
|
34916
35270
|
*
|
|
34917
35271
|
* Updates an {@link Amity.Community}
|
|
@@ -34995,7 +35349,7 @@ getCommunity$1.locally = (communityId) => {
|
|
|
34995
35349
|
if (!cached)
|
|
34996
35350
|
return;
|
|
34997
35351
|
return {
|
|
34998
|
-
data: cached.data,
|
|
35352
|
+
data: LinkedObject.community(cached.data),
|
|
34999
35353
|
cachedAt: cached.cachedAt,
|
|
35000
35354
|
};
|
|
35001
35355
|
};
|
|
@@ -42720,34 +43074,204 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
42720
43074
|
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
42721
43075
|
});
|
|
42722
43076
|
|
|
43077
|
+
class MyInvitationsPaginationController extends PaginationController {
|
|
43078
|
+
async getRequest(queryParams, token) {
|
|
43079
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
43080
|
+
const options = token ? { token } : { limit };
|
|
43081
|
+
const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
43082
|
+
await getCommunities$1(data.invitations.map(invitation => invitation.targetId));
|
|
43083
|
+
return data;
|
|
43084
|
+
}
|
|
43085
|
+
}
|
|
43086
|
+
|
|
43087
|
+
class MyInvitationsQueryStreamController extends QueryStreamController {
|
|
43088
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
43089
|
+
super(query, cacheKey);
|
|
43090
|
+
this.notifyChange = notifyChange;
|
|
43091
|
+
this.preparePayload = preparePayload;
|
|
43092
|
+
}
|
|
43093
|
+
async saveToMainDB(response) {
|
|
43094
|
+
const processedPayload = await this.preparePayload(response);
|
|
43095
|
+
const client = getActiveClient();
|
|
43096
|
+
const cachedAt = client.cache && Date.now();
|
|
43097
|
+
if (client.cache) {
|
|
43098
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
43099
|
+
}
|
|
43100
|
+
}
|
|
43101
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
43102
|
+
var _a, _b;
|
|
43103
|
+
if (refresh) {
|
|
43104
|
+
pushToCache(this.cacheKey, {
|
|
43105
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
43106
|
+
});
|
|
43107
|
+
}
|
|
43108
|
+
else {
|
|
43109
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43110
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
43111
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
43112
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
43113
|
+
] }));
|
|
43114
|
+
}
|
|
43115
|
+
}
|
|
43116
|
+
reactor(action) {
|
|
43117
|
+
return (invitations) => {
|
|
43118
|
+
var _a;
|
|
43119
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43120
|
+
if (!collection)
|
|
43121
|
+
return;
|
|
43122
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
43123
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
43124
|
+
if (!isExist)
|
|
43125
|
+
return;
|
|
43126
|
+
}
|
|
43127
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
43128
|
+
const client = getActiveClient();
|
|
43129
|
+
const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
|
|
43130
|
+
collection.data = [
|
|
43131
|
+
...new Set([
|
|
43132
|
+
...myInvitations.map(invitation => invitation.invitationId),
|
|
43133
|
+
...collection.data,
|
|
43134
|
+
]),
|
|
43135
|
+
];
|
|
43136
|
+
}
|
|
43137
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
43138
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
43139
|
+
}
|
|
43140
|
+
pushToCache(this.cacheKey, collection);
|
|
43141
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
43142
|
+
};
|
|
43143
|
+
}
|
|
43144
|
+
subscribeRTE(createSubscriber) {
|
|
43145
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
43146
|
+
}
|
|
43147
|
+
}
|
|
43148
|
+
|
|
43149
|
+
class MyInvitationsLiveCollectionController extends LiveCollectionController {
|
|
43150
|
+
constructor(query, callback) {
|
|
43151
|
+
const queryStreamId = hash(query);
|
|
43152
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
43153
|
+
const paginationController = new MyInvitationsPaginationController(query);
|
|
43154
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
43155
|
+
this.query = query;
|
|
43156
|
+
this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
|
|
43157
|
+
this.callback = callback.bind(this);
|
|
43158
|
+
this.loadPage({ initial: true });
|
|
43159
|
+
}
|
|
43160
|
+
setup() {
|
|
43161
|
+
var _a;
|
|
43162
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43163
|
+
if (!collection) {
|
|
43164
|
+
pushToCache(this.cacheKey, {
|
|
43165
|
+
data: [],
|
|
43166
|
+
params: this.query,
|
|
43167
|
+
});
|
|
43168
|
+
}
|
|
43169
|
+
}
|
|
43170
|
+
async persistModel(queryPayload) {
|
|
43171
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
43172
|
+
}
|
|
43173
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
43174
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
43175
|
+
}
|
|
43176
|
+
startSubscription() {
|
|
43177
|
+
return this.queryStreamController.subscribeRTE([
|
|
43178
|
+
{
|
|
43179
|
+
fn: onLocalInvitationCreated,
|
|
43180
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
43181
|
+
},
|
|
43182
|
+
{
|
|
43183
|
+
fn: onLocalInvitationUpdated,
|
|
43184
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
43185
|
+
},
|
|
43186
|
+
{
|
|
43187
|
+
fn: onLocalInvitationDeleted,
|
|
43188
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
43189
|
+
},
|
|
43190
|
+
]);
|
|
43191
|
+
}
|
|
43192
|
+
notifyChange({ origin, loading, error }) {
|
|
43193
|
+
var _a, _b;
|
|
43194
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43195
|
+
if (!collection)
|
|
43196
|
+
return;
|
|
43197
|
+
const data = this.applyFilter((_b = collection.data
|
|
43198
|
+
.map(id => pullFromCache(['invitation', 'get', id]))
|
|
43199
|
+
.filter(isNonNullable)
|
|
43200
|
+
.map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
|
|
43201
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
43202
|
+
return;
|
|
43203
|
+
this.callback({
|
|
43204
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
43205
|
+
data,
|
|
43206
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
43207
|
+
loading,
|
|
43208
|
+
error,
|
|
43209
|
+
});
|
|
43210
|
+
}
|
|
43211
|
+
applyFilter(data) {
|
|
43212
|
+
let invitations = data;
|
|
43213
|
+
if (this.query.targetId) {
|
|
43214
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
43215
|
+
}
|
|
43216
|
+
if (this.query.statuses) {
|
|
43217
|
+
invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
|
|
43218
|
+
}
|
|
43219
|
+
if (this.query.targetType) {
|
|
43220
|
+
invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
|
|
43221
|
+
}
|
|
43222
|
+
if (this.query.type) {
|
|
43223
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
43224
|
+
}
|
|
43225
|
+
const sortFn = (() => {
|
|
43226
|
+
switch (this.query.sortBy) {
|
|
43227
|
+
case 'firstCreated':
|
|
43228
|
+
return sortByFirstCreated;
|
|
43229
|
+
case 'lastCreated':
|
|
43230
|
+
return sortByLastCreated;
|
|
43231
|
+
default:
|
|
43232
|
+
return sortByLastCreated;
|
|
43233
|
+
}
|
|
43234
|
+
})();
|
|
43235
|
+
invitations = invitations.sort(sortFn);
|
|
43236
|
+
return invitations;
|
|
43237
|
+
}
|
|
43238
|
+
}
|
|
43239
|
+
|
|
42723
43240
|
/**
|
|
42724
|
-
*
|
|
42725
|
-
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
42726
|
-
* const dispose = onLocalInvitationCreated(data => {
|
|
42727
|
-
* // ...
|
|
42728
|
-
* })
|
|
42729
|
-
* ```
|
|
43241
|
+
* Get my community invitations
|
|
42730
43242
|
*
|
|
42731
|
-
*
|
|
43243
|
+
* @param params the query parameters
|
|
43244
|
+
* @param callback the callback to be called when the invitations are fetched
|
|
43245
|
+
* @returns invitations
|
|
42732
43246
|
*
|
|
42733
|
-
* @
|
|
42734
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
43247
|
+
* @category My Community Invitations Live Collection
|
|
42735
43248
|
*
|
|
42736
|
-
* @category Invitation Events
|
|
42737
43249
|
*/
|
|
42738
|
-
const
|
|
42739
|
-
const
|
|
42740
|
-
|
|
42741
|
-
|
|
42742
|
-
|
|
43250
|
+
const getMyCommunityInvitations = (params, callback, config) => {
|
|
43251
|
+
const { log, cache } = getActiveClient();
|
|
43252
|
+
if (!cache) {
|
|
43253
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
43254
|
+
}
|
|
43255
|
+
const timestamp = Date.now();
|
|
43256
|
+
log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
|
|
43257
|
+
const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
|
|
43258
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
43259
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
43260
|
+
disposers.push(() => {
|
|
43261
|
+
dropFromCache(cacheKey);
|
|
43262
|
+
});
|
|
42743
43263
|
return () => {
|
|
43264
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
42744
43265
|
disposers.forEach(fn => fn());
|
|
42745
43266
|
};
|
|
42746
43267
|
};
|
|
42747
43268
|
|
|
42748
43269
|
var index = /*#__PURE__*/Object.freeze({
|
|
42749
43270
|
__proto__: null,
|
|
42750
|
-
onLocalInvitationCreated: onLocalInvitationCreated
|
|
43271
|
+
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
43272
|
+
onLocalInvitationUpdated: onLocalInvitationUpdated,
|
|
43273
|
+
onLocalInvitationDeleted: onLocalInvitationDeleted,
|
|
43274
|
+
getMyCommunityInvitations: getMyCommunityInvitations
|
|
42751
43275
|
});
|
|
42752
43276
|
|
|
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 };
|
|
43277
|
+
export { API_REGIONS, index$2 as AdRepository, index$a as CategoryRepository, index$e as ChannelRepository, index$n as Client, index$8 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$b as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$k as FileRepository, FileType, index as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, index$4 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$i as MessageRepository, index$5 as PollRepository, PostContentType, index$7 as PostRepository, index$j as ReactionRepository, index$3 as StoryRepository, index$6 as StreamRepository, index$h as SubChannelRepository, SubscriptionLevels, index$l as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$1 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|