@amityco/ts-sdk 0.0.1-beta.42.3 → 0.0.1-beta.43
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 +11 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/marker.d.ts +37 -0
- package/dist/@types/core/marker.d.ts.map +1 -0
- package/dist/@types/core/model.d.ts +10 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +44 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -8
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/marker.d.ts +15 -0
- package/dist/@types/domains/marker.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +3 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +3 -0
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +2 -0
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/channel/api/index.d.ts +0 -2
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/utils/index.d.ts +1 -2
- package/dist/channel/utils/index.d.ts.map +1 -1
- package/dist/channel/utils/prepareChannelPayload.d.ts +6 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts +5 -1
- package/dist/channel/utils/tests/prepareChannelPayload.test.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +2 -2
- package/dist/client/api/activeUser.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/markerSync.d.ts +21 -0
- package/dist/client/api/markerSync.d.ts.map +1 -0
- package/dist/client/observers/getTotalUnreadCount.d.ts +18 -0
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -0
- package/dist/client/observers/index.d.ts +2 -0
- package/dist/client/observers/index.d.ts.map +1 -0
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts +2 -0
- package/dist/client/observers/tests/getTotalUnreadCount.test.d.ts.map +1 -0
- package/dist/client/utils/index.d.ts +2 -0
- package/dist/client/utils/index.d.ts.map +1 -0
- package/dist/client/utils/markerSyncEngine.d.ts +46 -0
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1921 -1185
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1891 -1186
- package/dist/index.umd.js +4 -4
- package/dist/marker/api/getChannelMarkers.d.ts +18 -0
- package/dist/marker/api/getChannelMarkers.d.ts.map +1 -0
- package/dist/marker/api/getMessageMarkers.d.ts +18 -0
- package/dist/marker/api/getMessageMarkers.d.ts.map +1 -0
- package/dist/marker/api/getSubChannelMarkers.d.ts +18 -0
- package/dist/marker/api/getSubChannelMarkers.d.ts.map +1 -0
- package/dist/marker/api/getUserMarker.d.ts +8 -0
- package/dist/marker/api/getUserMarker.d.ts.map +1 -0
- package/dist/marker/api/index.d.ts +5 -0
- package/dist/marker/api/index.d.ts.map +1 -0
- package/dist/marker/api/tests/getChannelMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getChannelMarkers.test.d.ts.map +1 -0
- package/dist/marker/api/tests/getMessageMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getMessageMarkers.test.d.ts.map +1 -0
- package/dist/marker/api/tests/getSubChannelMarkers.test.d.ts +2 -0
- package/dist/marker/api/tests/getSubChannelMarkers.test.d.ts.map +1 -0
- package/dist/marker/events/index.d.ts +7 -0
- package/dist/marker/events/index.d.ts.map +1 -0
- package/dist/marker/events/onChannelMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onChannelMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onFeedlMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onFeedlMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onMessageMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onMessageMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onSubChannelMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onSubChannelMarkerFetched.d.ts.map +1 -0
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts +17 -0
- package/dist/marker/events/onSubChannelMarkerUpdated.d.ts.map +1 -0
- package/dist/marker/events/onUserMarkerFetched.d.ts +17 -0
- package/dist/marker/events/onUserMarkerFetched.d.ts.map +1 -0
- package/dist/message/api/getMessage.d.ts.map +1 -1
- package/dist/message/api/getMessages.d.ts.map +1 -1
- package/dist/message/api/index.d.ts +1 -0
- package/dist/message/api/index.d.ts.map +1 -1
- package/dist/message/api/markAsDelivered.d.ts +17 -0
- package/dist/message/api/markAsDelivered.d.ts.map +1 -0
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/api/tests/markAsDelivered.test.d.ts +2 -0
- package/dist/message/api/tests/markAsDelivered.test.d.ts.map +1 -0
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/message/events/index.d.ts +1 -0
- package/dist/message/events/index.d.ts.map +1 -1
- package/dist/message/events/onMessageCreated.d.ts +2 -1
- package/dist/message/events/onMessageCreated.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/message/utils/index.d.ts +1 -18
- package/dist/message/utils/index.d.ts.map +1 -1
- package/dist/message/utils/prepareMessagePayload.d.ts +16 -0
- package/dist/message/utils/prepareMessagePayload.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/subChannel/api/getSubChannels.d.ts.map +1 -1
- package/dist/subChannel/api/index.d.ts +2 -0
- package/dist/subChannel/api/index.d.ts.map +1 -1
- package/dist/subChannel/api/startReadingAPI.d.ts +17 -0
- package/dist/subChannel/api/startReadingAPI.d.ts.map +1 -0
- package/dist/subChannel/api/stopReadingAPI.d.ts +17 -0
- package/dist/subChannel/api/stopReadingAPI.d.ts.map +1 -0
- package/dist/subChannel/events/onSubChannelUpdated.d.ts +1 -1
- package/dist/subChannel/events/onSubChannelUpdated.d.ts.map +1 -1
- package/dist/subChannel/observers/liveSubChannel.d.ts.map +1 -1
- package/dist/subChannel/utils/index.d.ts +2 -7
- package/dist/subChannel/utils/index.d.ts.map +1 -1
- package/dist/subChannel/utils/markReadEngine.d.ts +33 -0
- package/dist/subChannel/utils/markReadEngine.d.ts.map +1 -0
- package/dist/subChannel/utils/prepareSubChannelPayload.d.ts +15 -0
- package/dist/subChannel/utils/prepareSubChannelPayload.d.ts.map +1 -0
- package/dist/utils/liveObject.d.ts +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/client.d.ts +1 -0
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +4 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/marker.d.ts +6 -0
- package/dist/utils/tests/dummy/marker.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +2 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -1
- package/dist/utils/tests/dummy/subChannel.d.ts +1 -0
- package/dist/utils/tests/dummy/subChannel.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +13 -1
- package/src/@types/core/marker.ts +42 -0
- package/src/@types/core/model.ts +12 -0
- package/src/@types/core/payload.ts +52 -0
- package/src/@types/domains/channel.ts +5 -16
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/marker.ts +15 -0
- package/src/@types/domains/message.ts +3 -0
- package/src/@types/domains/partials.ts +4 -0
- package/src/@types/domains/subChannel.ts +2 -0
- package/src/channel/api/addChannelMembers.ts +1 -1
- package/src/channel/api/addChannelMembersRole.ts +1 -1
- package/src/channel/api/banChannelMembers.ts +1 -1
- package/src/channel/api/createChannel.ts +1 -1
- package/src/channel/api/getChannel.ts +1 -1
- package/src/channel/api/getChannels.ts +1 -1
- package/src/channel/api/index.ts +0 -3
- package/src/channel/api/joinChannel.ts +1 -1
- package/src/channel/api/leaveChannel.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +1 -1
- package/src/channel/api/queryChannels.ts +1 -1
- package/src/channel/api/removeChannelMembers.ts +1 -1
- package/src/channel/api/removeChannelMembersRole.ts +1 -1
- package/src/channel/api/tests/addChannelMembers.test.ts +16 -0
- package/src/channel/api/tests/createChannel.test.ts +29 -8
- package/src/channel/api/tests/getChannel.test.ts +11 -4
- package/src/channel/api/tests/getChannels.test.ts +20 -12
- package/src/channel/api/tests/queryChannelMembers.test.ts +13 -4
- package/src/channel/api/tests/queryChannels.test.ts +19 -9
- package/src/channel/api/unbanChannelMembers.ts +1 -1
- package/src/channel/api/updateChannel.ts +1 -1
- package/src/channel/events/onChannelCreated.ts +2 -2
- package/src/channel/events/onChannelDeleted.ts +4 -4
- package/src/channel/events/onChannelJoined.ts +2 -2
- package/src/channel/events/onChannelLeft.ts +2 -2
- package/src/channel/events/onChannelMemberAdded.ts +2 -2
- package/src/channel/events/onChannelMemberBanned.ts +3 -3
- package/src/channel/events/onChannelMemberRemoved.ts +2 -2
- package/src/channel/events/onChannelMemberUnbanned.ts +2 -2
- package/src/channel/events/onChannelMuted.ts +2 -2
- package/src/channel/events/onChannelUpdated.ts +25 -4
- package/src/channel/events/tests/onChannelCreated.test.ts +4 -1
- package/src/channel/events/tests/onChannelJoined.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberAdded.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberBanned.test.ts +4 -1
- package/src/channel/events/tests/onChannelMemberRemoved.test.ts +5 -1
- package/src/channel/events/tests/onChannelMemberUnbanned.test.ts +10 -10
- package/src/channel/events/tests/onChannelUpdated.test.ts +5 -1
- package/src/channel/observers/tests/liveChannelMembers.test.ts +5 -11
- package/src/channel/observers/tests/liveChannels.test.ts +21 -24
- package/src/channel/utils/index.ts +1 -57
- package/src/channel/utils/prepareChannelPayload.ts +91 -0
- package/src/channel/utils/tests/prepareChannelPayload.test.ts +102 -104
- package/src/client/api/activeUser.ts +2 -2
- package/src/client/api/connectClient.ts +2 -1
- package/src/client/api/index.ts +3 -0
- package/src/client/api/markerSync.ts +42 -0
- package/src/client/observers/getTotalUnreadCount.ts +52 -0
- package/src/client/observers/index.ts +1 -0
- package/src/client/observers/tests/getTotalUnreadCount.test.ts +126 -0
- package/src/client/utils/index.ts +1 -0
- package/src/client/utils/markerSyncEngine.ts +179 -0
- package/src/comment/api/tests/queryComments.test.ts +2 -2
- package/src/core/model/idResolvers.ts +7 -0
- package/src/core/model/identifyModel.ts +1 -1
- package/src/core/model/index.ts +6 -0
- package/src/core/tests/query/query/runQuery.test.ts +3 -1
- package/src/group/utils/withUser.ts +2 -2
- package/src/index.ts +6 -0
- package/src/marker/api/getChannelMarkers.ts +53 -0
- package/src/marker/api/getMessageMarkers.ts +54 -0
- package/src/marker/api/getSubChannelMarkers.ts +54 -0
- package/src/marker/api/getUserMarker.ts +47 -0
- package/src/marker/api/index.ts +4 -0
- package/src/marker/api/tests/getChannelMarkers.test.ts +109 -0
- package/src/marker/api/tests/getMessageMarkers.test.ts +114 -0
- package/src/marker/api/tests/getSubChannelMarkers.test.ts +116 -0
- package/src/marker/events/index.ts +10 -0
- package/src/marker/events/onChannelMarkerFetched.ts +34 -0
- package/src/marker/events/onFeedlMarkerFetched.ts +34 -0
- package/src/marker/events/onMessageMarkerFetched.ts +34 -0
- package/src/marker/events/onSubChannelMarkerFetched.ts +34 -0
- package/src/marker/events/onSubChannelMarkerUpdated.ts +34 -0
- package/src/marker/events/onUserMarkerFetched.ts +34 -0
- package/src/message/api/createMessage.ts +1 -1
- package/src/message/api/getMessage.ts +6 -5
- package/src/message/api/getMessages.ts +7 -6
- package/src/message/api/index.ts +1 -0
- package/src/message/api/markAsDelivered.ts +36 -0
- package/src/message/api/queryMessages.ts +8 -6
- package/src/message/api/tests/createMessage.test.ts +13 -4
- package/src/message/api/tests/getMessage.test.ts +12 -3
- package/src/message/api/tests/getMessages.test.ts +14 -5
- package/src/message/api/tests/markAsDelivered.test.ts +83 -0
- package/src/message/api/tests/queryMessages.test.ts +14 -3
- package/src/message/api/updateMessage.ts +8 -7
- package/src/message/events/index.ts +2 -0
- package/src/message/events/onMessageCreated.ts +14 -41
- package/src/message/events/onMessageDeleted.ts +2 -2
- package/src/message/events/onMessageFlagCleared.ts +2 -2
- package/src/message/events/onMessageFlagged.ts +2 -2
- package/src/message/events/onMessageReactionAdded.ts +2 -2
- package/src/message/events/onMessageReactionRemoved.ts +2 -2
- package/src/message/events/onMessageUnflagged.ts +2 -2
- package/src/message/events/onMessageUpdated.ts +27 -5
- package/src/message/tests/events.test.ts +4 -2
- package/src/message/tests/observers/liveMessage.test.ts +22 -10
- package/src/message/tests/observers/liveMessages.test.ts +25 -18
- package/src/message/utils/index.ts +1 -140
- package/src/message/utils/prepareMessagePayload.ts +182 -0
- package/src/reaction/events/onReactionAdded.ts +2 -2
- package/src/reaction/events/onReactionRemoved.ts +2 -2
- package/src/reaction/events/onReactorAdded.ts +2 -2
- package/src/reaction/events/onReactorRemoved.ts +2 -2
- package/src/report/api/createReport.ts +2 -1
- package/src/report/api/deleteReport.ts +2 -1
- package/src/subChannel/api/createSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannels.ts +2 -1
- package/src/subChannel/api/index.ts +3 -0
- package/src/subChannel/api/querySubChannels.ts +1 -1
- package/src/subChannel/api/startReadingAPI.ts +33 -0
- package/src/subChannel/api/stopReadingAPI.ts +33 -0
- package/src/subChannel/api/tests/createSubChannel.test.ts +6 -3
- package/src/subChannel/api/tests/deleteSubChannel.test.ts +7 -5
- package/src/subChannel/api/tests/getSubChannel.test.ts +6 -4
- package/src/subChannel/api/tests/getSubChannels.test.ts +6 -3
- package/src/subChannel/api/tests/updateSubChannel.test.ts +6 -3
- package/src/subChannel/api/updateSubChannel.ts +1 -1
- package/src/subChannel/events/onSubChannelCreated.ts +2 -2
- package/src/subChannel/events/onSubChannelDeleted.ts +2 -2
- package/src/subChannel/events/onSubChannelUpdated.ts +43 -4
- package/src/subChannel/observers/liveSubChannel.ts +2 -0
- package/src/subChannel/observers/tests/liveSubChannel.test.ts +15 -10
- package/src/subChannel/observers/tests/liveSubChannels.test.ts +21 -14
- package/src/subChannel/utils/index.ts +2 -50
- package/src/subChannel/utils/markReadEngine.ts +117 -0
- package/src/subChannel/utils/prepareSubChannelPayload.ts +132 -0
- package/src/utils/liveObject.ts +15 -4
- package/src/utils/tests/client.ts +3 -1
- package/src/utils/tests/dummy/channel.ts +38 -21
- package/src/utils/tests/dummy/index.ts +1 -0
- package/src/utils/tests/dummy/marker.ts +68 -0
- package/src/utils/tests/dummy/message.ts +43 -3
- package/src/utils/tests/dummy/subChannel.ts +16 -5
- package/src/utils/tests/utils.ts +4 -1
- package/dist/channel/api/startReading.d.ts +0 -17
- package/dist/channel/api/startReading.d.ts.map +0 -1
- package/dist/channel/api/stopReading.d.ts +0 -16
- package/dist/channel/api/stopReading.d.ts.map +0 -1
- package/dist/channel/api/tests/startReading.test.d.ts +0 -2
- package/dist/channel/api/tests/startReading.test.d.ts.map +0 -1
- package/dist/channel/api/tests/stopReading.test.d.ts +0 -2
- package/dist/channel/api/tests/stopReading.test.d.ts.map +0 -1
- package/src/channel/api/startReading.ts +0 -57
- package/src/channel/api/stopReading.ts +0 -53
- package/src/channel/api/tests/startReading.test.ts +0 -25
- package/src/channel/api/tests/stopReading.test.ts +0 -25
package/dist/index.cjs.js
CHANGED
|
@@ -95,8 +95,8 @@ const PostContentType = Object.freeze({
|
|
|
95
95
|
|
|
96
96
|
function getVersion() {
|
|
97
97
|
try {
|
|
98
|
-
// the string ''v0.0.1-beta.
|
|
99
|
-
return 'v0.0.1-beta.
|
|
98
|
+
// the string ''v0.0.1-beta.43-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
99
|
+
return 'v0.0.1-beta.43-cjs';
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
102
|
return '__dev__';
|
|
@@ -514,6 +514,11 @@ const idResolvers = {
|
|
|
514
514
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
515
515
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
516
516
|
message: ({ messageId }) => messageId,
|
|
517
|
+
channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
|
|
518
|
+
subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
|
|
519
|
+
messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
|
|
520
|
+
feedMarker: ({ feedId, entityId }) => `${feedId}#${entityId}`,
|
|
521
|
+
userMarker: ({ userId }) => userId,
|
|
517
522
|
community: ({ communityId }) => communityId,
|
|
518
523
|
category: ({ categoryId }) => categoryId,
|
|
519
524
|
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
@@ -614,6 +619,11 @@ const PAYLOAD2MODEL = {
|
|
|
614
619
|
messageFeeds: 'subChannel',
|
|
615
620
|
channelUsers: 'channelUsers',
|
|
616
621
|
messages: 'message',
|
|
622
|
+
userEntityMarkers: 'channelMarker',
|
|
623
|
+
userFeedMarkers: 'subChannelMarker',
|
|
624
|
+
contentMarkers: 'messageMarker',
|
|
625
|
+
feedMarkers: 'feedMarker',
|
|
626
|
+
userMarkers: 'userMarker',
|
|
617
627
|
communities: 'community',
|
|
618
628
|
categories: 'category',
|
|
619
629
|
communityUsers: 'communityUsers',
|
|
@@ -20530,6 +20540,57 @@ const setClientToken = async (params) => {
|
|
|
20530
20540
|
return { accessToken, users, refreshToken };
|
|
20531
20541
|
};
|
|
20532
20542
|
|
|
20543
|
+
/**
|
|
20544
|
+
* Ingest a payload (v3) into the cache
|
|
20545
|
+
*
|
|
20546
|
+
* @param payload a "backend v3" payload object
|
|
20547
|
+
* @param options caching options like cachedAt or offline
|
|
20548
|
+
*
|
|
20549
|
+
* @category Cache
|
|
20550
|
+
* @hidden
|
|
20551
|
+
*/
|
|
20552
|
+
const ingestInCache = (payload = {}, options) => {
|
|
20553
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
20554
|
+
const type = PAYLOAD2MODEL[key];
|
|
20555
|
+
if (!type)
|
|
20556
|
+
return;
|
|
20557
|
+
const resolver = getResolver(type);
|
|
20558
|
+
if (!resolver)
|
|
20559
|
+
return;
|
|
20560
|
+
models.forEach(model => {
|
|
20561
|
+
upsertInCache([type, 'get', resolver(model)], model, options);
|
|
20562
|
+
});
|
|
20563
|
+
});
|
|
20564
|
+
};
|
|
20565
|
+
|
|
20566
|
+
const createUserEventSubscriber = (event, callback) => {
|
|
20567
|
+
const client = getActiveClient();
|
|
20568
|
+
const filter = (payload) => {
|
|
20569
|
+
if (client.cache) {
|
|
20570
|
+
ingestInCache(payload);
|
|
20571
|
+
}
|
|
20572
|
+
callback(payload.users[0]);
|
|
20573
|
+
};
|
|
20574
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20575
|
+
};
|
|
20576
|
+
|
|
20577
|
+
/**
|
|
20578
|
+
* ```js
|
|
20579
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20580
|
+
* const dispose = onUserDeleted(user => {
|
|
20581
|
+
* // ...
|
|
20582
|
+
* })
|
|
20583
|
+
* ```
|
|
20584
|
+
*
|
|
20585
|
+
* Fired when a {@link Amity.User} has been deleted
|
|
20586
|
+
*
|
|
20587
|
+
* @param callback The function to call when the event was fired
|
|
20588
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20589
|
+
*
|
|
20590
|
+
* @category User Events
|
|
20591
|
+
*/
|
|
20592
|
+
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20593
|
+
|
|
20533
20594
|
/* begin_public_function
|
|
20534
20595
|
id: client.logout
|
|
20535
20596
|
*/
|
|
@@ -20584,57 +20645,6 @@ const disconnectClient = async () => {
|
|
|
20584
20645
|
};
|
|
20585
20646
|
/* end_public_function */
|
|
20586
20647
|
|
|
20587
|
-
/**
|
|
20588
|
-
* Ingest a payload (v3) into the cache
|
|
20589
|
-
*
|
|
20590
|
-
* @param payload a "backend v3" payload object
|
|
20591
|
-
* @param options caching options like cachedAt or offline
|
|
20592
|
-
*
|
|
20593
|
-
* @category Cache
|
|
20594
|
-
* @hidden
|
|
20595
|
-
*/
|
|
20596
|
-
const ingestInCache = (payload = {}, options) => {
|
|
20597
|
-
Object.entries(payload).forEach(([key, models]) => {
|
|
20598
|
-
const type = PAYLOAD2MODEL[key];
|
|
20599
|
-
if (!type)
|
|
20600
|
-
return;
|
|
20601
|
-
const resolver = getResolver(type);
|
|
20602
|
-
if (!resolver)
|
|
20603
|
-
return;
|
|
20604
|
-
models.forEach(model => {
|
|
20605
|
-
upsertInCache([type, 'get', resolver(model)], model, options);
|
|
20606
|
-
});
|
|
20607
|
-
});
|
|
20608
|
-
};
|
|
20609
|
-
|
|
20610
|
-
const createUserEventSubscriber = (event, callback) => {
|
|
20611
|
-
const client = getActiveClient();
|
|
20612
|
-
const filter = (payload) => {
|
|
20613
|
-
if (client.cache) {
|
|
20614
|
-
ingestInCache(payload);
|
|
20615
|
-
}
|
|
20616
|
-
callback(payload.users[0]);
|
|
20617
|
-
};
|
|
20618
|
-
return createEventSubscriber(client, event, event, filter);
|
|
20619
|
-
};
|
|
20620
|
-
|
|
20621
|
-
/**
|
|
20622
|
-
* ```js
|
|
20623
|
-
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20624
|
-
* const dispose = onUserDeleted(user => {
|
|
20625
|
-
* // ...
|
|
20626
|
-
* })
|
|
20627
|
-
* ```
|
|
20628
|
-
*
|
|
20629
|
-
* Fired when a {@link Amity.User} has been deleted
|
|
20630
|
-
*
|
|
20631
|
-
* @param callback The function to call when the event was fired
|
|
20632
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20633
|
-
*
|
|
20634
|
-
* @category User Events
|
|
20635
|
-
*/
|
|
20636
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20637
|
-
|
|
20638
20648
|
/**
|
|
20639
20649
|
* Terminates {@link Amity.Client} instance
|
|
20640
20650
|
*
|
|
@@ -21090,408 +21100,355 @@ const isConnected = () => {
|
|
|
21090
21100
|
|
|
21091
21101
|
/**
|
|
21092
21102
|
* ```js
|
|
21093
|
-
* import {
|
|
21094
|
-
* const
|
|
21103
|
+
* import { markerSync } from '@amityco/ts-sdk'
|
|
21104
|
+
* const success = await markerSync()
|
|
21095
21105
|
* ```
|
|
21096
21106
|
*
|
|
21097
|
-
*
|
|
21098
|
-
*
|
|
21099
|
-
*
|
|
21107
|
+
* Make all markers synced
|
|
21108
|
+
* * If response is empty means that the sync has ended.
|
|
21109
|
+
* * If response is not empty, the sync has not ended. You must call markerSync
|
|
21110
|
+
* again to continue syncing.
|
|
21100
21111
|
*
|
|
21101
|
-
* @
|
|
21102
|
-
* @param modelId the object id to check
|
|
21103
|
-
* @returns the matching cache entry, or undefined.
|
|
21112
|
+
* @return {hasMore} A success boolean if the marker sync was ended.
|
|
21104
21113
|
*
|
|
21105
|
-
* @category
|
|
21114
|
+
* @category Marker API
|
|
21115
|
+
* @async
|
|
21116
|
+
* @private
|
|
21106
21117
|
*/
|
|
21107
|
-
const
|
|
21108
|
-
const
|
|
21109
|
-
|
|
21110
|
-
|
|
21111
|
-
|
|
21112
|
-
|
|
21113
|
-
|
|
21114
|
-
|
|
21115
|
-
|
|
21116
|
-
|
|
21117
|
-
}
|
|
21118
|
+
const markerSync = async () => {
|
|
21119
|
+
const client = getActiveClient();
|
|
21120
|
+
client.log('channel/markerSync');
|
|
21121
|
+
const { data: payload } = await client.http.post(`/api/v1/markers/sync`);
|
|
21122
|
+
const { userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers } = payload;
|
|
21123
|
+
const cachedAt = client.cache && Date.now();
|
|
21124
|
+
if (client.cache)
|
|
21125
|
+
ingestInCache(payload, { cachedAt });
|
|
21126
|
+
feedMarkers.length && fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
21127
|
+
userEntityMarkers.length && fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21128
|
+
userFeedMarkers.length && fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
21129
|
+
userMarkers.length && fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21130
|
+
return {
|
|
21131
|
+
hasMore: payload.feedMarkers.length > 0,
|
|
21132
|
+
};
|
|
21118
21133
|
};
|
|
21119
21134
|
|
|
21135
|
+
/******************************************************************************
|
|
21136
|
+
Copyright (c) Microsoft Corporation.
|
|
21137
|
+
|
|
21138
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
21139
|
+
purpose with or without fee is hereby granted.
|
|
21140
|
+
|
|
21141
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
21142
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21143
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21144
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21145
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21146
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21147
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
21148
|
+
***************************************************************************** */
|
|
21149
|
+
|
|
21150
|
+
function __rest(s, e) {
|
|
21151
|
+
var t = {};
|
|
21152
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
21153
|
+
t[p] = s[p];
|
|
21154
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21155
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
21156
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
21157
|
+
t[p[i]] = s[p[i]];
|
|
21158
|
+
}
|
|
21159
|
+
return t;
|
|
21160
|
+
}
|
|
21161
|
+
|
|
21120
21162
|
/**
|
|
21121
21163
|
* ```js
|
|
21122
|
-
* import {
|
|
21123
|
-
*
|
|
21164
|
+
* import { getChannelMarker } from '@amityco/ts-sdk'
|
|
21165
|
+
* const channelMarkers = await getChannelMarkers(['ch1', 'ch2'])
|
|
21124
21166
|
* ```
|
|
21125
21167
|
*
|
|
21126
|
-
*
|
|
21127
|
-
* {@link Amity.Cache} from a given {@link Amity.CacheKey}
|
|
21168
|
+
* Fetches a paginable list of {@link Amity.ChannelMarker} objects
|
|
21128
21169
|
*
|
|
21129
|
-
* @param
|
|
21130
|
-
* @param
|
|
21170
|
+
* @param channelIds the IDs of the {@link Amity.RawChannel} marker to fetch
|
|
21171
|
+
* @param page
|
|
21172
|
+
* @returns A page of {@link Amity.ChannelMarker} objects
|
|
21131
21173
|
*
|
|
21132
|
-
* @category
|
|
21133
|
-
* @
|
|
21174
|
+
* @category Channel API
|
|
21175
|
+
* @async
|
|
21176
|
+
* @private
|
|
21134
21177
|
*/
|
|
21135
|
-
const
|
|
21136
|
-
const
|
|
21137
|
-
|
|
21138
|
-
const data =
|
|
21139
|
-
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
21143
|
-
|
|
21178
|
+
const getChannelMarkers = async (channelIds, page = { limit: 100 }) => {
|
|
21179
|
+
const client = getActiveClient();
|
|
21180
|
+
client.log('channel/getChannelMarkers', channelIds, page);
|
|
21181
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/channels`, {
|
|
21182
|
+
params: {
|
|
21183
|
+
channelIds,
|
|
21184
|
+
options: {
|
|
21185
|
+
token: toToken(page, 'skiplimit'),
|
|
21186
|
+
},
|
|
21187
|
+
},
|
|
21188
|
+
});
|
|
21189
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21190
|
+
const { userEntityMarkers, userMarkers } = payload;
|
|
21191
|
+
const cachedAt = client.cache && Date.now();
|
|
21192
|
+
if (client.cache)
|
|
21193
|
+
ingestInCache(payload, { cachedAt });
|
|
21194
|
+
userEntityMarkers.length && fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21195
|
+
userMarkers.length && fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21196
|
+
const nextPage = toPage(paging.next);
|
|
21197
|
+
const prevPage = toPage(paging.previous);
|
|
21198
|
+
return { data: userEntityMarkers, cachedAt, prevPage, nextPage };
|
|
21144
21199
|
};
|
|
21145
21200
|
|
|
21146
|
-
/* begin_public_function
|
|
21147
|
-
id: user.get
|
|
21148
|
-
*/
|
|
21149
21201
|
/**
|
|
21150
21202
|
* ```js
|
|
21151
|
-
* import {
|
|
21152
|
-
* const
|
|
21203
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk'
|
|
21204
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
21153
21205
|
* ```
|
|
21154
21206
|
*
|
|
21155
|
-
* Fetches a {@link Amity.
|
|
21207
|
+
* Fetches a paginable list of {@link Amity.MessageMarker} objects
|
|
21156
21208
|
*
|
|
21157
|
-
* @param
|
|
21158
|
-
* @
|
|
21209
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
21210
|
+
* @param page
|
|
21211
|
+
* @returns A page of {@link Amity.MessageMarker} objects
|
|
21159
21212
|
*
|
|
21160
|
-
* @category
|
|
21213
|
+
* @category Channel API
|
|
21161
21214
|
* @async
|
|
21215
|
+
* @private
|
|
21162
21216
|
*/
|
|
21163
|
-
const
|
|
21217
|
+
const getMessageMarkers = async (messageIds, page = { limit: 100 }) => {
|
|
21164
21218
|
const client = getActiveClient();
|
|
21165
|
-
client.log('
|
|
21166
|
-
|
|
21167
|
-
|
|
21168
|
-
|
|
21169
|
-
|
|
21170
|
-
|
|
21171
|
-
|
|
21172
|
-
|
|
21173
|
-
|
|
21174
|
-
}
|
|
21175
|
-
|
|
21176
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
21177
|
-
pushToTombstone('user', userId);
|
|
21178
|
-
}
|
|
21179
|
-
throw error;
|
|
21180
|
-
}
|
|
21219
|
+
client.log('channel/getMessageMarkers', messageIds, page);
|
|
21220
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
21221
|
+
params: {
|
|
21222
|
+
messageIds,
|
|
21223
|
+
options: {
|
|
21224
|
+
token: toToken(page, 'skiplimit'),
|
|
21225
|
+
},
|
|
21226
|
+
},
|
|
21227
|
+
});
|
|
21228
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21229
|
+
const { contentMarkers, feedMarkers, userMarkers } = payload;
|
|
21181
21230
|
const cachedAt = client.cache && Date.now();
|
|
21182
21231
|
if (client.cache)
|
|
21183
|
-
ingestInCache(
|
|
21184
|
-
|
|
21185
|
-
fireEvent('
|
|
21186
|
-
|
|
21187
|
-
|
|
21188
|
-
|
|
21189
|
-
};
|
|
21190
|
-
};
|
|
21191
|
-
|
|
21232
|
+
ingestInCache(payload, { cachedAt });
|
|
21233
|
+
feedMarkers.length && fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
21234
|
+
contentMarkers.length && fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
21235
|
+
userMarkers.length && fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21236
|
+
const nextPage = toPage(paging.next);
|
|
21237
|
+
const prevPage = toPage(paging.previous);
|
|
21238
|
+
return { data: contentMarkers, cachedAt, prevPage, nextPage };
|
|
21239
|
+
};
|
|
21240
|
+
|
|
21192
21241
|
/**
|
|
21193
21242
|
* ```js
|
|
21194
|
-
* import {
|
|
21195
|
-
* const
|
|
21243
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
21244
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
21196
21245
|
* ```
|
|
21197
21246
|
*
|
|
21198
|
-
* Fetches a {@link Amity.
|
|
21247
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
21199
21248
|
*
|
|
21200
|
-
* @param
|
|
21201
|
-
* @
|
|
21249
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
21250
|
+
* @param page
|
|
21251
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
21202
21252
|
*
|
|
21203
|
-
* @category
|
|
21253
|
+
* @category Channel API
|
|
21254
|
+
* @async
|
|
21255
|
+
* @private
|
|
21204
21256
|
*/
|
|
21205
|
-
|
|
21257
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
21206
21258
|
const client = getActiveClient();
|
|
21207
|
-
client.log('
|
|
21208
|
-
|
|
21259
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
21260
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
21261
|
+
params: {
|
|
21262
|
+
messageFeedIds,
|
|
21263
|
+
options: {
|
|
21264
|
+
token: toToken(page, 'skiplimit'),
|
|
21265
|
+
},
|
|
21266
|
+
},
|
|
21267
|
+
});
|
|
21268
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
21269
|
+
const { userEntityMarkers, userFeedMarkers, userMarkers } = payload;
|
|
21270
|
+
const cachedAt = client.cache && Date.now();
|
|
21271
|
+
if (client.cache)
|
|
21272
|
+
ingestInCache(payload, { cachedAt });
|
|
21273
|
+
userEntityMarkers.length && fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
21274
|
+
userFeedMarkers.length && fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
21275
|
+
userMarkers.length && fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21276
|
+
const nextPage = toPage(paging.next);
|
|
21277
|
+
const prevPage = toPage(paging.previous);
|
|
21278
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
21209
21279
|
};
|
|
21210
21280
|
|
|
21211
|
-
|
|
21212
|
-
|
|
21213
|
-
*/
|
|
21214
|
-
/**
|
|
21215
|
-
* ```js
|
|
21216
|
-
* import { getUsers } from '@amityco/ts-sdk'
|
|
21217
|
-
* const { data: users } = await getUsers(['foo', 'bar'])
|
|
21218
|
-
* ```
|
|
21219
|
-
*
|
|
21220
|
-
* Fetches a collection of {@link Amity.User} objects
|
|
21221
|
-
*
|
|
21222
|
-
* @param userIds the IDs of the {@link Amity.User} to fetch
|
|
21223
|
-
* @returns the associated collection of {@link Amity.User} objects
|
|
21224
|
-
*
|
|
21225
|
-
* @category User API
|
|
21226
|
-
* @async
|
|
21227
|
-
*/
|
|
21228
|
-
const getUsers = async (userIds) => {
|
|
21281
|
+
const locally = () => {
|
|
21282
|
+
var _a, _b;
|
|
21229
21283
|
const client = getActiveClient();
|
|
21230
|
-
|
|
21231
|
-
|
|
21232
|
-
|
|
21233
|
-
|
|
21234
|
-
|
|
21235
|
-
|
|
21284
|
+
const user = getActiveUser();
|
|
21285
|
+
client.log('marker/getUserMarker.locally');
|
|
21286
|
+
const { _id: userId } = user;
|
|
21287
|
+
if (!userId)
|
|
21288
|
+
throw new ASCError('The userId has not been defined in active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
21289
|
+
const createdTime = new Date().toISOString();
|
|
21236
21290
|
const cachedAt = client.cache && Date.now();
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21291
|
+
const data = (_b = (_a = pullFromCache([
|
|
21292
|
+
'userMarker',
|
|
21293
|
+
'get',
|
|
21294
|
+
getResolver('userMarker')({ userId }),
|
|
21295
|
+
])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {
|
|
21296
|
+
userId,
|
|
21297
|
+
unreadCount: 0,
|
|
21298
|
+
lastSyncAt: createdTime,
|
|
21299
|
+
createdAt: createdTime,
|
|
21300
|
+
updatedAt: createdTime,
|
|
21301
|
+
};
|
|
21240
21302
|
return {
|
|
21241
|
-
data
|
|
21303
|
+
data,
|
|
21242
21304
|
cachedAt,
|
|
21243
21305
|
};
|
|
21244
21306
|
};
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
* const { data: users } = getUsers.locally!(['foo', 'bar'])
|
|
21249
|
-
* ```
|
|
21250
|
-
*
|
|
21251
|
-
* Fetches a collection of {@link Amity.User} objects from cache
|
|
21252
|
-
*
|
|
21253
|
-
* @param userIds the IDs of the {@link Amity.User} to fetch
|
|
21254
|
-
* @returns the associated collection of {@link Amity.User} objects
|
|
21255
|
-
*
|
|
21256
|
-
* @category User API
|
|
21257
|
-
*/
|
|
21258
|
-
getUsers.locally = (userIds) => {
|
|
21259
|
-
var _a;
|
|
21260
|
-
const client = getActiveClient();
|
|
21261
|
-
client.log('user/getUsers.locally', userIds);
|
|
21262
|
-
if (!client.cache)
|
|
21263
|
-
return;
|
|
21264
|
-
const cached = userIds
|
|
21265
|
-
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
21266
|
-
.filter(Boolean);
|
|
21267
|
-
const users = cached.map(({ data }) => data);
|
|
21268
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
21269
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < userIds.length)
|
|
21270
|
-
return;
|
|
21271
|
-
return {
|
|
21272
|
-
data: users,
|
|
21273
|
-
cachedAt: oldest.cachedAt,
|
|
21274
|
-
};
|
|
21275
|
-
};
|
|
21276
|
-
|
|
21277
|
-
/******************************************************************************
|
|
21278
|
-
Copyright (c) Microsoft Corporation.
|
|
21279
|
-
|
|
21280
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
21281
|
-
purpose with or without fee is hereby granted.
|
|
21282
|
-
|
|
21283
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
21284
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21285
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21286
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21287
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21288
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21289
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
21290
|
-
***************************************************************************** */
|
|
21291
|
-
|
|
21292
|
-
function __rest(s, e) {
|
|
21293
|
-
var t = {};
|
|
21294
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
21295
|
-
t[p] = s[p];
|
|
21296
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21297
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
21298
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
21299
|
-
t[p[i]] = s[p[i]];
|
|
21300
|
-
}
|
|
21301
|
-
return t;
|
|
21302
|
-
}
|
|
21303
|
-
|
|
21304
|
-
/* begin_public_function
|
|
21305
|
-
id: user.query, user.search
|
|
21306
|
-
*/
|
|
21307
|
-
/**
|
|
21308
|
-
* ```js
|
|
21309
|
-
* import { queryUsers } from '@amityco/ts-sdk'
|
|
21310
|
-
* const { data: users, prevPage, nextPage } = await queryUsers({ displayName: 'foo' })
|
|
21311
|
-
* ```
|
|
21312
|
-
*
|
|
21313
|
-
* Queries a paginable list of {@link Amity.User} objects
|
|
21314
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
21315
|
-
*
|
|
21316
|
-
* @param query The query parameters
|
|
21317
|
-
* @returns A page of {@link Amity.User} objects
|
|
21318
|
-
*
|
|
21319
|
-
* @category User API
|
|
21320
|
-
* @async
|
|
21321
|
-
*/
|
|
21322
|
-
const queryUsers = async (query = {}) => {
|
|
21323
|
-
const client = getActiveClient();
|
|
21324
|
-
client.log('user/queryUsers', query);
|
|
21325
|
-
const { page = { limit: 10 }, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
21326
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
21327
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
21328
|
-
sortBy, options: {
|
|
21329
|
-
token: toToken(page, 'skiplimit'),
|
|
21330
|
-
} }),
|
|
21331
|
-
});
|
|
21332
|
-
// unpacking
|
|
21333
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21334
|
-
const { users } = payload;
|
|
21335
|
-
const cachedAt = client.cache && Date.now();
|
|
21336
|
-
if (client.cache) {
|
|
21337
|
-
ingestInCache(payload, { cachedAt });
|
|
21338
|
-
/*
|
|
21339
|
-
* using query as cache key over params because if the keyword, filter, sort
|
|
21340
|
-
* change the API will NOT cache results, when it should
|
|
21341
|
-
*/
|
|
21342
|
-
const cacheKey = ['user', 'query', Object.assign(Object.assign({}, query), { options: Object.assign({}, page) })];
|
|
21343
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
21344
|
-
}
|
|
21345
|
-
fireEvent('user.fetched', data);
|
|
21346
|
-
const prevPage = toPage(paging.previous);
|
|
21347
|
-
const nextPage = toPage(paging.next);
|
|
21348
|
-
return { data: users, cachedAt, prevPage, nextPage };
|
|
21307
|
+
const getUserMarker = () => {
|
|
21308
|
+
// API-FIX: backend should implement user marker get API
|
|
21309
|
+
return Promise.resolve(locally());
|
|
21349
21310
|
};
|
|
21350
|
-
|
|
21311
|
+
getUserMarker.locally = locally;
|
|
21312
|
+
|
|
21351
21313
|
/**
|
|
21352
21314
|
* ```js
|
|
21353
|
-
* import {
|
|
21354
|
-
* const
|
|
21315
|
+
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
21316
|
+
* const dispose = onChannelMarkerFetched(channelMarker => {
|
|
21317
|
+
* // ...
|
|
21318
|
+
* })
|
|
21355
21319
|
* ```
|
|
21356
21320
|
*
|
|
21357
|
-
*
|
|
21358
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
21321
|
+
* Fired when an {@link Amity.ChannelMarker} has been fetched
|
|
21359
21322
|
*
|
|
21360
|
-
* @param
|
|
21361
|
-
* @returns
|
|
21323
|
+
* @param callback The function to call when the event was fired
|
|
21324
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21362
21325
|
*
|
|
21363
|
-
* @category
|
|
21326
|
+
* @category ChannelMarker Events
|
|
21364
21327
|
*/
|
|
21365
|
-
|
|
21366
|
-
var _a, _b, _c;
|
|
21328
|
+
const onChannelMarkerFetched = (callback) => {
|
|
21367
21329
|
const client = getActiveClient();
|
|
21368
|
-
|
|
21369
|
-
|
|
21370
|
-
|
|
21371
|
-
|
|
21372
|
-
const cacheKey = [
|
|
21373
|
-
'user',
|
|
21374
|
-
'query',
|
|
21375
|
-
Object.assign(Object.assign({}, query), { options: Object.assign({}, page) }),
|
|
21376
|
-
];
|
|
21377
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
21378
|
-
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
21379
|
-
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
21380
|
-
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
21381
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
21382
|
-
? { data: users, cachedAt, prevPage, nextPage }
|
|
21383
|
-
: undefined;
|
|
21330
|
+
const filter = (payload) => {
|
|
21331
|
+
callback(payload.userEntityMarkers[0]);
|
|
21332
|
+
};
|
|
21333
|
+
return createEventSubscriber(client, 'channelMarker/onChannelMarkerFetched', 'local.channelMarker.fetched', filter);
|
|
21384
21334
|
};
|
|
21385
21335
|
|
|
21386
|
-
/* begin_public_function
|
|
21387
|
-
id: client.update_user
|
|
21388
|
-
*/
|
|
21389
21336
|
/**
|
|
21390
21337
|
* ```js
|
|
21391
|
-
* import {
|
|
21392
|
-
* const
|
|
21338
|
+
* import { onSubChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
21339
|
+
* const dispose = onSubChannelMarkerFetched(subChannelMarker => {
|
|
21340
|
+
* // ...
|
|
21341
|
+
* })
|
|
21393
21342
|
* ```
|
|
21394
21343
|
*
|
|
21395
|
-
*
|
|
21344
|
+
* Fired when an {@link Amity.SubChannelMarker} has been fetched
|
|
21396
21345
|
*
|
|
21397
|
-
* @param
|
|
21398
|
-
* @
|
|
21399
|
-
* @returns the updated {@link Amity.User} object
|
|
21346
|
+
* @param callback The function to call when the event was fired
|
|
21347
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21400
21348
|
*
|
|
21401
|
-
* @category
|
|
21402
|
-
* @async
|
|
21349
|
+
* @category SubChannelMarker Events
|
|
21403
21350
|
*/
|
|
21404
|
-
const
|
|
21351
|
+
const onSubChannelMarkerFetched = (callback) => {
|
|
21405
21352
|
const client = getActiveClient();
|
|
21406
|
-
|
|
21407
|
-
|
|
21408
|
-
/*
|
|
21409
|
-
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
21410
|
-
`/api/v3/users/${userId}`, patch,
|
|
21411
|
-
)
|
|
21412
|
-
*/
|
|
21413
|
-
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
21414
|
-
const cachedAt = client.cache && Date.now();
|
|
21415
|
-
if (client.cache)
|
|
21416
|
-
ingestInCache(data, { cachedAt });
|
|
21417
|
-
const { users } = data;
|
|
21418
|
-
fireEvent('user.updated', data);
|
|
21419
|
-
return {
|
|
21420
|
-
data: users.find(user => user.userId === userId),
|
|
21421
|
-
cachedAt,
|
|
21353
|
+
const filter = (payload) => {
|
|
21354
|
+
callback(payload.userFeedMarkers[0]);
|
|
21422
21355
|
};
|
|
21423
|
-
|
|
21424
|
-
|
|
21356
|
+
return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerFetched', 'local.subChannelMarker.fetched', filter);
|
|
21357
|
+
};
|
|
21425
21358
|
|
|
21426
21359
|
/**
|
|
21427
21360
|
* ```js
|
|
21428
|
-
* import {
|
|
21429
|
-
* const dispose =
|
|
21361
|
+
* import { onSubChannelMarkerUpdated } from '@amityco/ts-sdk'
|
|
21362
|
+
* const dispose = onSubChannelMarkerUpdated(subChannelMarker => {
|
|
21430
21363
|
* // ...
|
|
21431
21364
|
* })
|
|
21432
21365
|
* ```
|
|
21433
21366
|
*
|
|
21434
|
-
* Fired when
|
|
21367
|
+
* Fired when an {@link Amity.SubChannelMarker} has been updated
|
|
21435
21368
|
*
|
|
21436
21369
|
* @param callback The function to call when the event was fired
|
|
21437
21370
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21438
21371
|
*
|
|
21439
|
-
* @category
|
|
21372
|
+
* @category SubChannelMarker Events
|
|
21440
21373
|
*/
|
|
21441
|
-
const
|
|
21374
|
+
const onSubChannelMarkerUpdated = (callback) => {
|
|
21375
|
+
const client = getActiveClient();
|
|
21376
|
+
const filter = (payload) => {
|
|
21377
|
+
callback(payload.userFeedMarkers[0]);
|
|
21378
|
+
};
|
|
21379
|
+
return createEventSubscriber(client, 'subChannelMarker/onSubChannelMarkerUpdated', 'local.subChannelMarker.updated', filter);
|
|
21380
|
+
};
|
|
21442
21381
|
|
|
21443
21382
|
/**
|
|
21444
21383
|
* ```js
|
|
21445
|
-
* import {
|
|
21446
|
-
* const dispose =
|
|
21384
|
+
* import { onFeedMarkerFetched } from '@amityco/ts-sdk'
|
|
21385
|
+
* const dispose = onFeedMarkerFetched(feedMarker => {
|
|
21447
21386
|
* // ...
|
|
21448
21387
|
* })
|
|
21449
21388
|
* ```
|
|
21450
21389
|
*
|
|
21451
|
-
* Fired when
|
|
21390
|
+
* Fired when an {@link Amity.FeedMarker} has been fetched
|
|
21452
21391
|
*
|
|
21453
21392
|
* @param callback The function to call when the event was fired
|
|
21454
21393
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21455
21394
|
*
|
|
21456
|
-
* @category
|
|
21395
|
+
* @category FeedMarker Events
|
|
21457
21396
|
*/
|
|
21458
|
-
const
|
|
21397
|
+
const onFeedMarkerFetched = (callback) => {
|
|
21398
|
+
const client = getActiveClient();
|
|
21399
|
+
const filter = (payload) => {
|
|
21400
|
+
callback(payload.feedMarkers[0]);
|
|
21401
|
+
};
|
|
21402
|
+
return createEventSubscriber(client, 'feedMarker/onFeedMarkerFetched', 'local.feedMarker.fetched', filter);
|
|
21403
|
+
};
|
|
21459
21404
|
|
|
21460
21405
|
/**
|
|
21461
21406
|
* ```js
|
|
21462
|
-
* import {
|
|
21463
|
-
* const dispose =
|
|
21407
|
+
* import { onUserMarkerFetched } from '@amityco/ts-sdk'
|
|
21408
|
+
* const dispose = onUserMarkerFetched(userMarker => {
|
|
21464
21409
|
* // ...
|
|
21465
21410
|
* })
|
|
21466
21411
|
* ```
|
|
21467
21412
|
*
|
|
21468
|
-
* Fired when
|
|
21413
|
+
* Fired when an {@link Amity.UserMarker} has been fetched
|
|
21469
21414
|
*
|
|
21470
21415
|
* @param callback The function to call when the event was fired
|
|
21471
21416
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21472
21417
|
*
|
|
21473
|
-
* @category
|
|
21418
|
+
* @category UserMarker Events
|
|
21474
21419
|
*/
|
|
21475
|
-
const
|
|
21420
|
+
const onUserMarkerFetched = (callback) => {
|
|
21421
|
+
const client = getActiveClient();
|
|
21422
|
+
const filter = (payload) => {
|
|
21423
|
+
callback(payload.userMarkers[0]);
|
|
21424
|
+
};
|
|
21425
|
+
return createEventSubscriber(client, 'userMarker/onUserMarkerFetched', 'local.userMarker.fetched', filter);
|
|
21426
|
+
};
|
|
21476
21427
|
|
|
21477
21428
|
/**
|
|
21478
21429
|
* ```js
|
|
21479
|
-
* import {
|
|
21480
|
-
* const dispose =
|
|
21430
|
+
* import { onMessageMarkerFetched } from '@amityco/ts-sdk'
|
|
21431
|
+
* const dispose = onMessageMarkerFetched(messageMarker => {
|
|
21481
21432
|
* // ...
|
|
21482
21433
|
* })
|
|
21483
21434
|
* ```
|
|
21484
21435
|
*
|
|
21485
|
-
* Fired when
|
|
21436
|
+
* Fired when an {@link Amity.MessageMarker} has been fetched
|
|
21486
21437
|
*
|
|
21487
21438
|
* @param callback The function to call when the event was fired
|
|
21488
21439
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21489
21440
|
*
|
|
21490
|
-
* @category
|
|
21441
|
+
* @category MessageMarker Events
|
|
21491
21442
|
*/
|
|
21492
|
-
const
|
|
21443
|
+
const onMessageMarkerFetched = (callback) => {
|
|
21444
|
+
const client = getActiveClient();
|
|
21445
|
+
const filter = (payload) => {
|
|
21446
|
+
callback(payload.contentMarkers[0]);
|
|
21447
|
+
};
|
|
21448
|
+
return createEventSubscriber(client, 'messageMarker/onMessageMarkerFetched', 'local.messageMarker.fetched', filter);
|
|
21449
|
+
};
|
|
21493
21450
|
|
|
21494
|
-
const liveObject = (id, callback, key, fetcher, eventHandlers) => {
|
|
21451
|
+
const liveObject = (id, callback, key, fetcher, eventHandlers, callbackDataSelector = data => data, callbackFilter) => {
|
|
21495
21452
|
const { cache } = getActiveClient();
|
|
21496
21453
|
if (!cache) {
|
|
21497
21454
|
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
@@ -21500,8 +21457,11 @@ const liveObject = (id, callback, key, fetcher, eventHandlers) => {
|
|
|
21500
21457
|
let isUnsyncedModel = false; // for messages
|
|
21501
21458
|
const disposers = [];
|
|
21502
21459
|
const dispatcher = (data) => {
|
|
21503
|
-
|
|
21504
|
-
|
|
21460
|
+
const { data: newModel } = data, rest = __rest(data, ["data"]);
|
|
21461
|
+
if (!callbackFilter || callbackFilter(newModel, model)) {
|
|
21462
|
+
callback(Object.assign({ data: callbackDataSelector(newModel) }, rest));
|
|
21463
|
+
}
|
|
21464
|
+
model = newModel;
|
|
21505
21465
|
};
|
|
21506
21466
|
const realtimeRouter = (eventModel) => {
|
|
21507
21467
|
if (id !== eventModel[key]) {
|
|
@@ -21545,22 +21505,1255 @@ const liveObject = (id, callback, key, fetcher, eventHandlers) => {
|
|
|
21545
21505
|
|
|
21546
21506
|
/**
|
|
21547
21507
|
* ```js
|
|
21548
|
-
* import {
|
|
21549
|
-
*
|
|
21550
|
-
*
|
|
21551
|
-
*
|
|
21508
|
+
* import { getTotalUnreadCount } from '@amityco/ts-sdk';
|
|
21509
|
+
*
|
|
21510
|
+
* const unsubscribe = getTotalUnreadCount(response => {
|
|
21511
|
+
* totalUnreadCount = response.data;
|
|
21512
|
+
* });
|
|
21552
21513
|
* ```
|
|
21553
21514
|
*
|
|
21554
|
-
*
|
|
21515
|
+
* Observe current user's unread count from {@link Amity.UserMarker}
|
|
21555
21516
|
*
|
|
21556
|
-
* @param callback
|
|
21557
|
-
* @returns
|
|
21517
|
+
* @param callback the function to call when new data are available
|
|
21518
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
|
|
21558
21519
|
*
|
|
21559
|
-
* @category
|
|
21520
|
+
* @category Message Live Object
|
|
21560
21521
|
*/
|
|
21561
|
-
const
|
|
21522
|
+
const getTotalUnreadCount = (callback) => {
|
|
21523
|
+
const { _id: userId } = getActiveUser();
|
|
21524
|
+
if (!userId)
|
|
21525
|
+
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
21526
|
+
const callbackPayloadSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
21527
|
+
// based on the mobile specs, unreadCount will not trigger observer when userMarker
|
|
21528
|
+
// is re-fetched, so apply this filter to ensure the behavior is the same.
|
|
21529
|
+
const callbackFilter = (newModel, oldModel) => (newModel === null || newModel === void 0 ? void 0 : newModel.unreadCount) !== (oldModel === null || oldModel === void 0 ? void 0 : oldModel.unreadCount);
|
|
21530
|
+
return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], callbackPayloadSelector, callbackFilter);
|
|
21531
|
+
};
|
|
21562
21532
|
|
|
21563
|
-
/**
|
|
21533
|
+
/** @hidden */
|
|
21534
|
+
/*
|
|
21535
|
+
* @param message payload from http request without myReactions
|
|
21536
|
+
* add myReactions to http response if the event was a reaction event
|
|
21537
|
+
*/
|
|
21538
|
+
const prepareMessagePayloadForCache = (payload) => {
|
|
21539
|
+
const client = getActiveClient();
|
|
21540
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
21541
|
+
// '[]' in cases where the new reaction is the first one
|
|
21542
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
21543
|
+
// add myReactions to the payload
|
|
21544
|
+
Object.assign(payload, { myReactions });
|
|
21545
|
+
// check if there are any updates to the reactions
|
|
21546
|
+
const latestReaction = payload === null || payload === void 0 ? void 0 : payload.latestReaction;
|
|
21547
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
21548
|
+
if (!isLatestReactionMine) {
|
|
21549
|
+
return;
|
|
21550
|
+
}
|
|
21551
|
+
// new reaction added
|
|
21552
|
+
if (latestReaction.eventName === 'add' && !myReactions.includes(latestReaction.reactionName)) {
|
|
21553
|
+
Object.assign(payload, {
|
|
21554
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
21555
|
+
});
|
|
21556
|
+
}
|
|
21557
|
+
// existing reaction removed
|
|
21558
|
+
if (latestReaction.eventName === 'remove' && myReactions.includes(latestReaction.reactionName)) {
|
|
21559
|
+
Object.assign(payload, {
|
|
21560
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
21561
|
+
});
|
|
21562
|
+
}
|
|
21563
|
+
};
|
|
21564
|
+
|
|
21565
|
+
const getCachedMarker$1 = (message) => {
|
|
21566
|
+
var _a, _b;
|
|
21567
|
+
const key = {
|
|
21568
|
+
creatorId: message.creatorId,
|
|
21569
|
+
feedId: (_a = message.messageFeedId) !== null && _a !== void 0 ? _a : message.subChannelId,
|
|
21570
|
+
contentId: message.messageId,
|
|
21571
|
+
};
|
|
21572
|
+
return (_b = pullFromCache([
|
|
21573
|
+
'messageMarker',
|
|
21574
|
+
'get',
|
|
21575
|
+
getResolver('messageMarker')(key),
|
|
21576
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
21577
|
+
};
|
|
21578
|
+
const getReadCount = (message, marker) => {
|
|
21579
|
+
var _a;
|
|
21580
|
+
// Look in the marker param first
|
|
21581
|
+
return (_a = marker !== null && marker !== void 0 ? marker :
|
|
21582
|
+
// If the marker param is not set, look in the cache
|
|
21583
|
+
getCachedMarker$1(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
21584
|
+
}; // and if not found in cache use default value `0`
|
|
21585
|
+
function convertFromRaw$2(message, marker) {
|
|
21586
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId } = message, rest = __rest(message, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId"]);
|
|
21587
|
+
const { readCount, deliveredCount } = getReadCount(message, marker);
|
|
21588
|
+
let cache;
|
|
21589
|
+
if (referenceId) {
|
|
21590
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
21591
|
+
}
|
|
21592
|
+
if (!cache) {
|
|
21593
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
21594
|
+
}
|
|
21595
|
+
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, reactions: reactions !== null && reactions !== void 0 ? reactions : {}, reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, readCount,
|
|
21596
|
+
deliveredCount });
|
|
21597
|
+
if (mentionedUsers) {
|
|
21598
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
21599
|
+
if (mention.type === 'channel') {
|
|
21600
|
+
return mention;
|
|
21601
|
+
}
|
|
21602
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
21603
|
+
});
|
|
21604
|
+
}
|
|
21605
|
+
if (myReactions) {
|
|
21606
|
+
// http response
|
|
21607
|
+
out.myReactions = myReactions;
|
|
21608
|
+
}
|
|
21609
|
+
else {
|
|
21610
|
+
// mqtt event
|
|
21611
|
+
prepareMessagePayloadForCache(out);
|
|
21612
|
+
}
|
|
21613
|
+
return out;
|
|
21614
|
+
}
|
|
21615
|
+
function updateMessageMarker(message, marker) {
|
|
21616
|
+
const { readCount, deliveredCount } = getReadCount(message, marker);
|
|
21617
|
+
return Object.assign(Object.assign({}, message), { readCount,
|
|
21618
|
+
deliveredCount, updatedAt: new Date().toISOString() });
|
|
21619
|
+
}
|
|
21620
|
+
const prepareMessagePayload = async (payload) => {
|
|
21621
|
+
// make a fetch marker to prepare it for merging with the raw message payload.
|
|
21622
|
+
let markers = [];
|
|
21623
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
21624
|
+
if (markerIds.length > 0)
|
|
21625
|
+
// from the spec, allow marker fetch to fail
|
|
21626
|
+
try {
|
|
21627
|
+
({ data: markers } = await getMessageMarkers(markerIds));
|
|
21628
|
+
}
|
|
21629
|
+
catch (e) {
|
|
21630
|
+
// empty block
|
|
21631
|
+
}
|
|
21632
|
+
return Object.assign(Object.assign({}, payload), { messages: payload.messages.map(message => {
|
|
21633
|
+
const marker = markers === null || markers === void 0 ? void 0 : markers.find(({ contentId }) => contentId === message.messageId);
|
|
21634
|
+
return convertFromRaw$2(message, marker);
|
|
21635
|
+
}) });
|
|
21636
|
+
};
|
|
21637
|
+
function convertParams(_a) {
|
|
21638
|
+
var { subChannelId, mentionees } = _a, rest = __rest(_a, ["subChannelId", "mentionees"]);
|
|
21639
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees }, rest);
|
|
21640
|
+
}
|
|
21641
|
+
function convertQueryParams$1(_a) {
|
|
21642
|
+
var { page, sortBy, subChannelId, tags, includeDeleted } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags", "includeDeleted"]);
|
|
21643
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: includeDeleted === false ? false : undefined, options: { token: toToken(page || { limit: 10 }, 'afterbeforeraw') } });
|
|
21644
|
+
if (sortBy !== undefined) {
|
|
21645
|
+
out.options.sortBy = sortBy;
|
|
21646
|
+
}
|
|
21647
|
+
if (tags) {
|
|
21648
|
+
out.includeTags = tags;
|
|
21649
|
+
}
|
|
21650
|
+
return out;
|
|
21651
|
+
}
|
|
21652
|
+
|
|
21653
|
+
/**
|
|
21654
|
+
* ```js
|
|
21655
|
+
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
21656
|
+
* const dispose = onMessageCreated(message => {
|
|
21657
|
+
* // ...
|
|
21658
|
+
* })
|
|
21659
|
+
* ```
|
|
21660
|
+
*
|
|
21661
|
+
* Fired when an {@link Amity.Message} has been created
|
|
21662
|
+
*
|
|
21663
|
+
* @param callback The function to call when the event was fired
|
|
21664
|
+
* @param local Trigger when an event occurs from a local event or not
|
|
21665
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21666
|
+
*
|
|
21667
|
+
* @category Message Events
|
|
21668
|
+
*/
|
|
21669
|
+
const onMessageCreated = (callback, local = true) => {
|
|
21670
|
+
const client = getActiveClient();
|
|
21671
|
+
const filter = async (rawPayload) => {
|
|
21672
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21673
|
+
const message = payload.messages[0];
|
|
21674
|
+
ingestInCache(payload);
|
|
21675
|
+
callback(message);
|
|
21676
|
+
};
|
|
21677
|
+
const disposers = [
|
|
21678
|
+
createEventSubscriber(client, 'message/onMessageCreated', 'message.created', filter),
|
|
21679
|
+
];
|
|
21680
|
+
if (local) {
|
|
21681
|
+
createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', payload => callback(payload.messages[0]));
|
|
21682
|
+
}
|
|
21683
|
+
return () => {
|
|
21684
|
+
disposers.forEach(fn => fn());
|
|
21685
|
+
};
|
|
21686
|
+
};
|
|
21687
|
+
|
|
21688
|
+
/**
|
|
21689
|
+
* ```js
|
|
21690
|
+
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
21691
|
+
* const dispose = onMessageUpdated(message => {
|
|
21692
|
+
* // ...
|
|
21693
|
+
* })
|
|
21694
|
+
* ```
|
|
21695
|
+
*
|
|
21696
|
+
* Fired when an {@link Amity.Message} has been updated
|
|
21697
|
+
*
|
|
21698
|
+
* @param callback The function to call when the event was fired
|
|
21699
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21700
|
+
*
|
|
21701
|
+
* @category Message Events
|
|
21702
|
+
*/
|
|
21703
|
+
const onMessageUpdated = (callback) => {
|
|
21704
|
+
const client = getActiveClient();
|
|
21705
|
+
const filter = async (rawPayload) => {
|
|
21706
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21707
|
+
ingestInCache(payload);
|
|
21708
|
+
callback(payload.messages[0]);
|
|
21709
|
+
};
|
|
21710
|
+
const messageMarkerChangeHandler = async (rawPayload) => {
|
|
21711
|
+
var _a;
|
|
21712
|
+
const marker = rawPayload.contentMarkers[0];
|
|
21713
|
+
const cacheKey = ['message', 'get', marker.contentId];
|
|
21714
|
+
const message = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21715
|
+
if (!message)
|
|
21716
|
+
return;
|
|
21717
|
+
const updated = updateMessageMarker(message, marker);
|
|
21718
|
+
upsertInCache(cacheKey, updated);
|
|
21719
|
+
callback(updated);
|
|
21720
|
+
};
|
|
21721
|
+
const disposers = [
|
|
21722
|
+
createEventSubscriber(client, 'onMessageUpdated', 'message.updated', filter),
|
|
21723
|
+
createEventSubscriber(client, 'onMessageUpdated', 'local.message.updated', payload => callback(payload.messages[0])),
|
|
21724
|
+
createEventSubscriber(client, 'onMessageUpdated', 'local.messageMarker.fetched', messageMarkerChangeHandler),
|
|
21725
|
+
];
|
|
21726
|
+
return () => {
|
|
21727
|
+
disposers.forEach(fn => fn());
|
|
21728
|
+
};
|
|
21729
|
+
};
|
|
21730
|
+
|
|
21731
|
+
/**
|
|
21732
|
+
* ```js
|
|
21733
|
+
* import { onMessageDeleted } from '@amityco/ts-sdk'
|
|
21734
|
+
* const dispose = onMessageDeleted(message => {
|
|
21735
|
+
* // ...
|
|
21736
|
+
* })
|
|
21737
|
+
* ```
|
|
21738
|
+
*
|
|
21739
|
+
* Fired when an {@link Amity.Message} was deleted
|
|
21740
|
+
*
|
|
21741
|
+
* @param callback The function to call when the event was fired
|
|
21742
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21743
|
+
*
|
|
21744
|
+
* @category Message Events
|
|
21745
|
+
*/
|
|
21746
|
+
const onMessageDeleted = (callback) => {
|
|
21747
|
+
const client = getActiveClient();
|
|
21748
|
+
const filter = async (rawPayload) => {
|
|
21749
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21750
|
+
ingestInCache(payload);
|
|
21751
|
+
callback(payload.messages[0]);
|
|
21752
|
+
};
|
|
21753
|
+
const disposers = [
|
|
21754
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
21755
|
+
createEventSubscriber(client, 'local.message.deleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
21756
|
+
];
|
|
21757
|
+
return () => {
|
|
21758
|
+
disposers.forEach(fn => fn());
|
|
21759
|
+
};
|
|
21760
|
+
};
|
|
21761
|
+
|
|
21762
|
+
/**
|
|
21763
|
+
* ```js
|
|
21764
|
+
* import { onMessageFlagged } from '@amityco/ts-sdk'
|
|
21765
|
+
* const dispose = onMessageFlagged(message => {
|
|
21766
|
+
* // ...
|
|
21767
|
+
* })
|
|
21768
|
+
* ```
|
|
21769
|
+
*
|
|
21770
|
+
* Fired when a {@link Amity.Message} has been flagged
|
|
21771
|
+
*
|
|
21772
|
+
* @param callback The function to call when the event was fired
|
|
21773
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21774
|
+
*
|
|
21775
|
+
* @category Message Events
|
|
21776
|
+
*/
|
|
21777
|
+
const onMessageFlagged = (callback) => {
|
|
21778
|
+
const client = getActiveClient();
|
|
21779
|
+
const filter = async (rawPayload) => {
|
|
21780
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21781
|
+
ingestInCache(payload);
|
|
21782
|
+
callback(payload.messages[0]);
|
|
21783
|
+
};
|
|
21784
|
+
return createEventSubscriber(client, 'onMessageFlagged', 'message.flagged', filter);
|
|
21785
|
+
};
|
|
21786
|
+
|
|
21787
|
+
/**
|
|
21788
|
+
* ```js
|
|
21789
|
+
* import { onMessageUnflagged } from '@amityco/ts-sdk'
|
|
21790
|
+
* const dispose = onMessageUnflagged(message => {
|
|
21791
|
+
* // ...
|
|
21792
|
+
* })
|
|
21793
|
+
* ```
|
|
21794
|
+
*
|
|
21795
|
+
* Fired when a flag has been removed from a {@link Amity.Message}
|
|
21796
|
+
*
|
|
21797
|
+
* @param callback The function to call when the event was fired
|
|
21798
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21799
|
+
*
|
|
21800
|
+
* @category Message Events
|
|
21801
|
+
*/
|
|
21802
|
+
const onMessageUnflagged = (callback) => {
|
|
21803
|
+
const client = getActiveClient();
|
|
21804
|
+
const filter = async (rawPayload) => {
|
|
21805
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21806
|
+
ingestInCache(payload);
|
|
21807
|
+
callback(payload.messages[0]);
|
|
21808
|
+
};
|
|
21809
|
+
return createEventSubscriber(client, 'onMessageUnflagged', 'message.unflagged', filter);
|
|
21810
|
+
};
|
|
21811
|
+
|
|
21812
|
+
/**
|
|
21813
|
+
* ```js
|
|
21814
|
+
* import { onMessageFlagCleared } from '@amityco/ts-sdk'
|
|
21815
|
+
* const dispose = onMessageFlagCleared(message => {
|
|
21816
|
+
* // ...
|
|
21817
|
+
* })
|
|
21818
|
+
* ```
|
|
21819
|
+
*
|
|
21820
|
+
* Fired when flags have been cleared for a {@link Amity.Message}
|
|
21821
|
+
*
|
|
21822
|
+
* @param callback The function to call when the event was fired
|
|
21823
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21824
|
+
*
|
|
21825
|
+
* @category Message Events
|
|
21826
|
+
*/
|
|
21827
|
+
const onMessageFlagCleared = (callback) => {
|
|
21828
|
+
const client = getActiveClient();
|
|
21829
|
+
const filter = async (rawPayload) => {
|
|
21830
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21831
|
+
ingestInCache(payload);
|
|
21832
|
+
callback(payload.messages[0]);
|
|
21833
|
+
};
|
|
21834
|
+
return createEventSubscriber(client, 'onMessageFlagCleared', 'message.flagCleared', filter);
|
|
21835
|
+
};
|
|
21836
|
+
|
|
21837
|
+
/**
|
|
21838
|
+
* ```js
|
|
21839
|
+
* import { onMessageReactionAdded } from '@amityco/ts-sdk';
|
|
21840
|
+
*
|
|
21841
|
+
* const unsubscribe = onMessageReactionAdded(message => {
|
|
21842
|
+
* // ...
|
|
21843
|
+
* });
|
|
21844
|
+
* ```
|
|
21845
|
+
*
|
|
21846
|
+
* Fired when a {@link Amity.Message} has been reacted
|
|
21847
|
+
*
|
|
21848
|
+
* @param callback The function to call when the event was fired
|
|
21849
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21850
|
+
*
|
|
21851
|
+
* @category Post Events
|
|
21852
|
+
*/
|
|
21853
|
+
const onMessageReactionAdded = (callback) => {
|
|
21854
|
+
const client = getActiveClient();
|
|
21855
|
+
const filter = async (rawPayload) => {
|
|
21856
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21857
|
+
ingestInCache(payload);
|
|
21858
|
+
callback(payload.messages[0]);
|
|
21859
|
+
};
|
|
21860
|
+
return createEventSubscriber(client, 'onMessageReactionAdded', 'message.reactionAdded', filter);
|
|
21861
|
+
};
|
|
21862
|
+
|
|
21863
|
+
/**
|
|
21864
|
+
* ```js
|
|
21865
|
+
* import { onMessageReactionRemoved } from '@amityco/ts-sdk';
|
|
21866
|
+
*
|
|
21867
|
+
* const unsubscribe = onMessageReactionRemoved(message => {
|
|
21868
|
+
* // ...
|
|
21869
|
+
* });
|
|
21870
|
+
* ```
|
|
21871
|
+
*
|
|
21872
|
+
* Fired when a reaction has been removed from a {@link Amity.Message}
|
|
21873
|
+
*
|
|
21874
|
+
* @param callback The function to call when the event was fired
|
|
21875
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21876
|
+
*
|
|
21877
|
+
* @category Post Events
|
|
21878
|
+
*/
|
|
21879
|
+
const onMessageReactionRemoved = (callback) => {
|
|
21880
|
+
const client = getActiveClient();
|
|
21881
|
+
const filter = async (rawPayload) => {
|
|
21882
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
21883
|
+
ingestInCache(payload);
|
|
21884
|
+
callback(payload.messages[0]);
|
|
21885
|
+
};
|
|
21886
|
+
return createEventSubscriber(client, 'onMessageReactionRemoved', 'message.reactionRemoved', filter);
|
|
21887
|
+
};
|
|
21888
|
+
|
|
21889
|
+
/**
|
|
21890
|
+
* ```js
|
|
21891
|
+
* import { onMessageFetched } from '@amityco/ts-sdk'
|
|
21892
|
+
* const dispose = onMessageFetched(message => {
|
|
21893
|
+
* // ...
|
|
21894
|
+
* })
|
|
21895
|
+
* ```
|
|
21896
|
+
*
|
|
21897
|
+
* Fired when an {@link Amity.Message} has been fetched
|
|
21898
|
+
*
|
|
21899
|
+
* @param callback The function to call when the event was fired
|
|
21900
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21901
|
+
*
|
|
21902
|
+
* @category Message Events
|
|
21903
|
+
*/
|
|
21904
|
+
const onMessageFetched = (callback) => {
|
|
21905
|
+
const client = getActiveClient();
|
|
21906
|
+
const filter = (payload) => {
|
|
21907
|
+
ingestInCache(payload);
|
|
21908
|
+
callback(payload.messages[0]);
|
|
21909
|
+
};
|
|
21910
|
+
return createEventSubscriber(client, 'message/onMessageFetched', 'local.message.fetched', filter);
|
|
21911
|
+
};
|
|
21912
|
+
|
|
21913
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21914
|
+
/**
|
|
21915
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
21916
|
+
*/
|
|
21917
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
21918
|
+
function getUnreadCount$1(channelId, subChannelId, marker) {
|
|
21919
|
+
var _a;
|
|
21920
|
+
// Look for `unreadCount` in the marker param first
|
|
21921
|
+
if (marker) {
|
|
21922
|
+
return marker.unreadCount;
|
|
21923
|
+
}
|
|
21924
|
+
const key = {
|
|
21925
|
+
entityId: channelId,
|
|
21926
|
+
feedId: subChannelId,
|
|
21927
|
+
userId: getActiveUser()._id,
|
|
21928
|
+
};
|
|
21929
|
+
// If the marker param is not set, look in the cache
|
|
21930
|
+
const cachedMarker = (_a = pullFromCache([
|
|
21931
|
+
'subChannelMarker',
|
|
21932
|
+
'get',
|
|
21933
|
+
getResolver('subChannelMarker')(key),
|
|
21934
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21935
|
+
if (cachedMarker) {
|
|
21936
|
+
return cachedMarker.unreadCount;
|
|
21937
|
+
}
|
|
21938
|
+
// and if not found in cache use default value `0`
|
|
21939
|
+
return 0;
|
|
21940
|
+
}
|
|
21941
|
+
function convertFromRaw$1(_a, marker) {
|
|
21942
|
+
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"]);
|
|
21943
|
+
return Object.assign(Object.assign({}, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$1({ channelType }), unreadCount: getUnreadCount$1(channelId, messageFeedId, marker) });
|
|
21944
|
+
}
|
|
21945
|
+
function updateSubChannelMarker(subChannel, marker) {
|
|
21946
|
+
return Object.assign(Object.assign({}, subChannel), { unreadCount: getUnreadCount$1(subChannel.channelId, subChannel.subChannelId, marker), updatedAt: new Date().toISOString() });
|
|
21947
|
+
}
|
|
21948
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
21949
|
+
// make a fetch marker to prepare it for merging with the raw channel payload.
|
|
21950
|
+
let markers = [];
|
|
21951
|
+
const markerIds = rawPayload.messageFeeds
|
|
21952
|
+
.filter(isUnreadCountSupport$1)
|
|
21953
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
21954
|
+
if (markerIds.length > 0)
|
|
21955
|
+
// from the spec, allow marker fetch to fail
|
|
21956
|
+
try {
|
|
21957
|
+
({ data: markers } = await getSubChannelMarkers(markerIds));
|
|
21958
|
+
}
|
|
21959
|
+
catch (e) {
|
|
21960
|
+
// empty block
|
|
21961
|
+
}
|
|
21962
|
+
// attach marker to sub channel
|
|
21963
|
+
const messageFeeds = rawPayload.messageFeeds.map(messageFeed => {
|
|
21964
|
+
const marker = markers === null || markers === void 0 ? void 0 : markers.find(({ feedId }) => feedId === messageFeed.messageFeedId);
|
|
21965
|
+
return convertFromRaw$1(messageFeed, marker);
|
|
21966
|
+
});
|
|
21967
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds });
|
|
21968
|
+
};
|
|
21969
|
+
function convertQueryParams(_a) {
|
|
21970
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
21971
|
+
const out = Object.assign({}, rest);
|
|
21972
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
21973
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
21974
|
+
}
|
|
21975
|
+
return out;
|
|
21976
|
+
}
|
|
21977
|
+
|
|
21978
|
+
/**
|
|
21979
|
+
* ```js
|
|
21980
|
+
* import { SubChannel } from '@amityco/ts-sdk'
|
|
21981
|
+
* const success = await SubChannel('foo')
|
|
21982
|
+
* ```
|
|
21983
|
+
*
|
|
21984
|
+
* Mark all messages as read and start reading message inside channel
|
|
21985
|
+
*
|
|
21986
|
+
* @param messageFeedId - The sub channel ID to start reading.
|
|
21987
|
+
* @return A success boolean if reading of the sub channel had begun.
|
|
21988
|
+
*
|
|
21989
|
+
* @category Channel API
|
|
21990
|
+
* @async
|
|
21991
|
+
* @private
|
|
21992
|
+
*/
|
|
21993
|
+
const startReadingAPI = async (messageFeedId) => {
|
|
21994
|
+
const client = getActiveClient();
|
|
21995
|
+
client.log('channel/startReadingAPI', messageFeedId);
|
|
21996
|
+
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
|
|
21997
|
+
const cachedAt = client.cache && Date.now();
|
|
21998
|
+
if (client.cache)
|
|
21999
|
+
ingestInCache(payload, { cachedAt });
|
|
22000
|
+
return true;
|
|
22001
|
+
};
|
|
22002
|
+
|
|
22003
|
+
/**
|
|
22004
|
+
* ```js
|
|
22005
|
+
* import { stopReading } from '@amityco/ts-sdk'
|
|
22006
|
+
* const success = await stopReading('foo')
|
|
22007
|
+
* ```
|
|
22008
|
+
*
|
|
22009
|
+
* Mark all messages as read and stop reading message inside channel
|
|
22010
|
+
*
|
|
22011
|
+
* @param messageFeedId - The sub channel ID to stop reading.
|
|
22012
|
+
* @return A success boolean if reading of the sub channel had begun.
|
|
22013
|
+
*
|
|
22014
|
+
* @category Channel API
|
|
22015
|
+
* @async
|
|
22016
|
+
* @private
|
|
22017
|
+
*/
|
|
22018
|
+
const stopReadingAPI = async (messageFeedId) => {
|
|
22019
|
+
const client = getActiveClient();
|
|
22020
|
+
client.log('channel/stopReadingAPI', messageFeedId);
|
|
22021
|
+
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
|
|
22022
|
+
const cachedAt = client.cache && Date.now();
|
|
22023
|
+
if (client.cache)
|
|
22024
|
+
ingestInCache(payload, { cachedAt });
|
|
22025
|
+
return true;
|
|
22026
|
+
};
|
|
22027
|
+
|
|
22028
|
+
let disposers$1 = [];
|
|
22029
|
+
const isReadingMap = {};
|
|
22030
|
+
const updateReadToSegment = (message) => {
|
|
22031
|
+
var _a;
|
|
22032
|
+
if (!isReadingMap[message.subChannelId])
|
|
22033
|
+
return;
|
|
22034
|
+
const client = getActiveClient();
|
|
22035
|
+
if (!client.cache)
|
|
22036
|
+
return;
|
|
22037
|
+
const key = {
|
|
22038
|
+
entityId: message.channelId,
|
|
22039
|
+
feedId: message.subChannelId,
|
|
22040
|
+
userId: getActiveUser()._id,
|
|
22041
|
+
};
|
|
22042
|
+
const currentValue = (_a = pullFromCache([
|
|
22043
|
+
'subChannelMarker',
|
|
22044
|
+
'get',
|
|
22045
|
+
getResolver('subChannelMarker')(key),
|
|
22046
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22047
|
+
if (!currentValue)
|
|
22048
|
+
return;
|
|
22049
|
+
const userFeedMarkers = [Object.assign(Object.assign({}, currentValue), { readToSegment: message.channelSegment })];
|
|
22050
|
+
fireEvent('local.subChannelMarker.updated', { userFeedMarkers });
|
|
22051
|
+
};
|
|
22052
|
+
/**
|
|
22053
|
+
* the event callback when app is back to online
|
|
22054
|
+
*/
|
|
22055
|
+
const onOnline$1 = () => {
|
|
22056
|
+
const callback = () => {
|
|
22057
|
+
// Start reading the reading subChannel again when resume from offline state
|
|
22058
|
+
Object.entries(isReadingMap).forEach(([subChannelId, isReading]) => {
|
|
22059
|
+
if (isReading)
|
|
22060
|
+
startReadingAPI(subChannelId);
|
|
22061
|
+
});
|
|
22062
|
+
};
|
|
22063
|
+
window.addEventListener('online', callback);
|
|
22064
|
+
return () => window.removeEventListener('online', callback);
|
|
22065
|
+
};
|
|
22066
|
+
const registerEventListeners$1 = () => {
|
|
22067
|
+
disposers$1.push(onOnline$1(), onMessageCreated(updateReadToSegment));
|
|
22068
|
+
};
|
|
22069
|
+
const unRegisterEventListeners$1 = () => {
|
|
22070
|
+
disposers$1.forEach(fn => fn());
|
|
22071
|
+
disposers$1 = [];
|
|
22072
|
+
};
|
|
22073
|
+
/* begin_public_function
|
|
22074
|
+
id: channel.start_reading
|
|
22075
|
+
*/
|
|
22076
|
+
/**
|
|
22077
|
+
* ```js
|
|
22078
|
+
* import { startReading } from '@amityco/ts-sdk'
|
|
22079
|
+
* const success = await startReading('foo')
|
|
22080
|
+
* ```
|
|
22081
|
+
*
|
|
22082
|
+
* Set local reading state of channel to `true` and then call mark all
|
|
22083
|
+
* messages as read API.
|
|
22084
|
+
*
|
|
22085
|
+
* @param subChannelId - The sub channel ID to start reading.
|
|
22086
|
+
* @return A success boolean if reading of the sub channel had begun.
|
|
22087
|
+
*
|
|
22088
|
+
* @category Channel API
|
|
22089
|
+
* @async
|
|
22090
|
+
*/
|
|
22091
|
+
const startReading = (subChannelId) => {
|
|
22092
|
+
isReadingMap[subChannelId] = true;
|
|
22093
|
+
if (disposers$1.length === 0) {
|
|
22094
|
+
registerEventListeners$1();
|
|
22095
|
+
}
|
|
22096
|
+
return startReadingAPI(subChannelId);
|
|
22097
|
+
};
|
|
22098
|
+
/* end_public_function */
|
|
22099
|
+
/* begin_public_function
|
|
22100
|
+
id: channel.stop_reading
|
|
22101
|
+
*/
|
|
22102
|
+
/**
|
|
22103
|
+
* ```js
|
|
22104
|
+
* import { stopReading } from '@amityco/ts-sdk'
|
|
22105
|
+
* const success = await stopReading('foo')
|
|
22106
|
+
* ```
|
|
22107
|
+
*
|
|
22108
|
+
* Set local reading state of channel to `false` and then call mark all
|
|
22109
|
+
* messages as unread API.
|
|
22110
|
+
*
|
|
22111
|
+
* @param subChannelId - The sub channel ID to stop reading.
|
|
22112
|
+
* @return A success boolean if reading of the sub channel had begun.
|
|
22113
|
+
*
|
|
22114
|
+
* @category Channel API
|
|
22115
|
+
* @async
|
|
22116
|
+
*/
|
|
22117
|
+
const stopReading = (subChannelId) => {
|
|
22118
|
+
isReadingMap[subChannelId] = false;
|
|
22119
|
+
unRegisterEventListeners$1();
|
|
22120
|
+
return stopReadingAPI(subChannelId);
|
|
22121
|
+
};
|
|
22122
|
+
/* end_public_function */
|
|
22123
|
+
|
|
22124
|
+
/**
|
|
22125
|
+
* ```js
|
|
22126
|
+
* import { onChannelSubCreated } from '@amityco/ts-sdk'
|
|
22127
|
+
* const dispose = onSubChannelCreated(subChannel => {
|
|
22128
|
+
* // ...
|
|
22129
|
+
* })
|
|
22130
|
+
* ```
|
|
22131
|
+
*
|
|
22132
|
+
* Fired when any {@link Amity.SubChannel} have been created
|
|
22133
|
+
*
|
|
22134
|
+
* @param callback The function to call when the event was fired
|
|
22135
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22136
|
+
*
|
|
22137
|
+
* @category Channel Events
|
|
22138
|
+
*/
|
|
22139
|
+
const onSubChannelCreated = (callback) => {
|
|
22140
|
+
const client = getActiveClient();
|
|
22141
|
+
const filter = async (rawPayload) => {
|
|
22142
|
+
const payload = await prepareSubChannelPayload(rawPayload);
|
|
22143
|
+
ingestInCache(payload);
|
|
22144
|
+
callback(payload.messageFeeds[0]);
|
|
22145
|
+
};
|
|
22146
|
+
return createEventSubscriber(client, 'onSubChannelCreated', 'message-feed.created', filter);
|
|
22147
|
+
};
|
|
22148
|
+
|
|
22149
|
+
/**
|
|
22150
|
+
* ```js
|
|
22151
|
+
* import { onSubChannelUpdated } from '@amityco/ts-sdk'
|
|
22152
|
+
* const dispose = onSubChannelUpdated(subChannel => {
|
|
22153
|
+
* // ...
|
|
22154
|
+
* })
|
|
22155
|
+
* ```
|
|
22156
|
+
*
|
|
22157
|
+
* Fired when any {@link Amity.SubChannel} have been updated
|
|
22158
|
+
*
|
|
22159
|
+
* @param callback The function to call when the event was fired
|
|
22160
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22161
|
+
*
|
|
22162
|
+
* @category Channel Events
|
|
22163
|
+
*/
|
|
22164
|
+
const onSubChannelUpdated = (callback) => {
|
|
22165
|
+
const client = getActiveClient();
|
|
22166
|
+
const subChannelChangeHandler = async (rawPayload) => {
|
|
22167
|
+
const payload = await prepareSubChannelPayload(rawPayload);
|
|
22168
|
+
ingestInCache(payload);
|
|
22169
|
+
callback(payload.messageFeeds[0]);
|
|
22170
|
+
};
|
|
22171
|
+
const subChannelMarkerChangeHandler = async (rawPayload) => {
|
|
22172
|
+
var _a;
|
|
22173
|
+
const marker = rawPayload.userFeedMarkers[0];
|
|
22174
|
+
const cacheKey = ['subChannel', 'get', marker.feedId];
|
|
22175
|
+
const subChannel = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22176
|
+
if (!subChannel)
|
|
22177
|
+
return;
|
|
22178
|
+
const updated = updateSubChannelMarker(subChannel, marker);
|
|
22179
|
+
upsertInCache(cacheKey, updated);
|
|
22180
|
+
callback(updated);
|
|
22181
|
+
};
|
|
22182
|
+
const disposers = [
|
|
22183
|
+
createEventSubscriber(client, 'onSubChannelUpdated', 'message-feed.updated', subChannelChangeHandler),
|
|
22184
|
+
createEventSubscriber(client, 'onSubChannelUpdated', 'local.subChannelMarker.fetched', subChannelMarkerChangeHandler),
|
|
22185
|
+
createEventSubscriber(client, 'onSubChannelUpdated', 'local.subChannelMarker.updated', subChannelMarkerChangeHandler),
|
|
22186
|
+
];
|
|
22187
|
+
return () => {
|
|
22188
|
+
disposers.forEach(fn => fn());
|
|
22189
|
+
};
|
|
22190
|
+
};
|
|
22191
|
+
|
|
22192
|
+
/**
|
|
22193
|
+
* ```js
|
|
22194
|
+
* import { onSubChannelDeleted } from '@amityco/ts-sdk'
|
|
22195
|
+
* const dispose = onSubChannelDeleted(subChannel => {
|
|
22196
|
+
* // ...
|
|
22197
|
+
* })
|
|
22198
|
+
* ```
|
|
22199
|
+
*
|
|
22200
|
+
* Fired when any {@link Amity.SubChannel} have been deleted
|
|
22201
|
+
*
|
|
22202
|
+
* @param callback The function to call when the event was fired
|
|
22203
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22204
|
+
*
|
|
22205
|
+
* @category Channel Events
|
|
22206
|
+
*/
|
|
22207
|
+
const onSubChannelDeleted = (callback) => {
|
|
22208
|
+
const client = getActiveClient();
|
|
22209
|
+
const filter = async (rawPayload) => {
|
|
22210
|
+
const payload = await prepareSubChannelPayload(rawPayload);
|
|
22211
|
+
ingestInCache(payload);
|
|
22212
|
+
callback(payload.messageFeeds[0]);
|
|
22213
|
+
};
|
|
22214
|
+
const disposers = [
|
|
22215
|
+
createEventSubscriber(client, 'onSubChannelDeleted', 'message-feed.deleted', filter),
|
|
22216
|
+
createEventSubscriber(client, 'local.message-feed.deleted', 'local.message-feed.deleted', payload => callback(payload.messageFeeds[0])),
|
|
22217
|
+
];
|
|
22218
|
+
return () => {
|
|
22219
|
+
disposers.forEach(fn => fn());
|
|
22220
|
+
};
|
|
22221
|
+
};
|
|
22222
|
+
|
|
22223
|
+
const FORCE_SYNC_INTERVAL_TIME = 8000;
|
|
22224
|
+
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
22225
|
+
let clearSyncTrigger;
|
|
22226
|
+
let disposers = [];
|
|
22227
|
+
let isWaitingForResponse = false;
|
|
22228
|
+
/**
|
|
22229
|
+
* list of conditions that make timer still trigger the syncing process.
|
|
22230
|
+
* If it's empty, it means sync is stopped.
|
|
22231
|
+
* if it's not empty, sync will resume.
|
|
22232
|
+
*/
|
|
22233
|
+
let events = [];
|
|
22234
|
+
/**
|
|
22235
|
+
* get current marker sync event list
|
|
22236
|
+
* @private
|
|
22237
|
+
*/
|
|
22238
|
+
const getMarkerSyncEvents = () => events;
|
|
22239
|
+
/**
|
|
22240
|
+
* set marker sync events
|
|
22241
|
+
* @private
|
|
22242
|
+
*/
|
|
22243
|
+
const setMarkerSyncEvents = (newEvents) => {
|
|
22244
|
+
events = newEvents;
|
|
22245
|
+
};
|
|
22246
|
+
/**
|
|
22247
|
+
* push new event to marker sync events
|
|
22248
|
+
* @private
|
|
22249
|
+
*/
|
|
22250
|
+
const pushMarkerSyncEvent = (event) => events.push(event);
|
|
22251
|
+
/**
|
|
22252
|
+
* interval task
|
|
22253
|
+
* @private
|
|
22254
|
+
*/
|
|
22255
|
+
const markerSyncTrigger = async (markerSync) => {
|
|
22256
|
+
if (isWaitingForResponse) {
|
|
22257
|
+
// waiting for the response no need to make another API call
|
|
22258
|
+
return;
|
|
22259
|
+
}
|
|
22260
|
+
if (events.length === 0) {
|
|
22261
|
+
// no event that require to call marker sync API
|
|
22262
|
+
return;
|
|
22263
|
+
}
|
|
22264
|
+
isWaitingForResponse = true;
|
|
22265
|
+
// any past events are considered processed here.
|
|
22266
|
+
// however during waiting for the response, RTE could add the new message event;
|
|
22267
|
+
// which will make the engine trigger another call next round.
|
|
22268
|
+
events = [];
|
|
22269
|
+
const response = await markerSync();
|
|
22270
|
+
if (response.hasMore) {
|
|
22271
|
+
events.push("has_more" /* Amity.MarkerSyncEvent.HAS_MORE */);
|
|
22272
|
+
}
|
|
22273
|
+
// eslint-disable-next-line require-atomic-updates
|
|
22274
|
+
isWaitingForResponse = false;
|
|
22275
|
+
};
|
|
22276
|
+
/**
|
|
22277
|
+
* the event callback when app is back to online
|
|
22278
|
+
*/
|
|
22279
|
+
const onOnline = () => {
|
|
22280
|
+
// should add RESUME to the event to trigger marker syncing again
|
|
22281
|
+
const callback = () => events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
|
|
22282
|
+
window.addEventListener('online', callback);
|
|
22283
|
+
return () => window.removeEventListener('online', callback);
|
|
22284
|
+
};
|
|
22285
|
+
const setIntervalTask = (handler, timeout) => {
|
|
22286
|
+
const timer = setInterval(handler, timeout);
|
|
22287
|
+
return () => clearInterval(timer);
|
|
22288
|
+
};
|
|
22289
|
+
const registerEventListeners = () => {
|
|
22290
|
+
// based on the tech spec design, we designed a fetch marker in case of these events
|
|
22291
|
+
// - new message
|
|
22292
|
+
// - create channel
|
|
22293
|
+
// - remove channel
|
|
22294
|
+
// - app going to online again after offline
|
|
22295
|
+
disposers.push(onOnline(), onMessageCreated(message => {
|
|
22296
|
+
// only conversation, community and broadcast types can sync
|
|
22297
|
+
if (isUnreadCountSupport$1(message))
|
|
22298
|
+
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
22299
|
+
},
|
|
22300
|
+
// only trigger sync from remote events to prevent an unread count equal `-1`
|
|
22301
|
+
// when an optimistic message creation is performed.
|
|
22302
|
+
false), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */)),
|
|
22303
|
+
// In real-world use, we've encountered some cases where BE returns empty result
|
|
22304
|
+
// even if a marker changes in the database, causing the SDK to mistakenly believe that
|
|
22305
|
+
// no changes have been made in the database and end the sync prematurely.
|
|
22306
|
+
// Did miss update the unread count
|
|
22307
|
+
//
|
|
22308
|
+
// We found that some time BE loads were too high, causing the calculation
|
|
22309
|
+
// marker not to finish within the sync time, so it returned an empty value.
|
|
22310
|
+
//
|
|
22311
|
+
// Therefore, solve this problem by creating a second interval loop that
|
|
22312
|
+
// runs every 8 seconds regardless of whether an event occurs or not so that
|
|
22313
|
+
// the unread count is always updated in case of an error like the above.
|
|
22314
|
+
setIntervalTask(() => events.push("force sync" /* Amity.MarkerSyncEvent.FORCE_SYNC */), FORCE_SYNC_INTERVAL_TIME));
|
|
22315
|
+
};
|
|
22316
|
+
const unRegisterEventListeners = () => {
|
|
22317
|
+
disposers.forEach(fn => fn());
|
|
22318
|
+
disposers = [];
|
|
22319
|
+
};
|
|
22320
|
+
/**
|
|
22321
|
+
```js
|
|
22322
|
+
* import { startUnreadSync } from '@amityco/ts-sdk'
|
|
22323
|
+
* startUnreadSync()
|
|
22324
|
+
* ```
|
|
22325
|
+
*
|
|
22326
|
+
* start syncing to keep feed markers, channel markers and user makers cache
|
|
22327
|
+
* update to the server.
|
|
22328
|
+
*
|
|
22329
|
+
* @category Marker API
|
|
22330
|
+
*/
|
|
22331
|
+
const startUnreadSync = () => {
|
|
22332
|
+
pushMarkerSyncEvent("start syncing" /* Amity.MarkerSyncEvent.START_SYNCING */);
|
|
22333
|
+
if (!clearSyncTrigger) {
|
|
22334
|
+
// it is possible to repeatedly call the API when multiple events occur at the same time.
|
|
22335
|
+
// This is very burdensome to the BE Server, so we have an interval loop for
|
|
22336
|
+
// grouping every event that occurs within 2 seconds into a single API call.
|
|
22337
|
+
//
|
|
22338
|
+
// interval loop is also useful for fetching large results. Because if the result
|
|
22339
|
+
// is more than 20 records, the API will split the result into multiple pages
|
|
22340
|
+
// and the SDK will need to fetch it repeatedly until all the results are available.
|
|
22341
|
+
// So we need an interval loop for repeat fetch.
|
|
22342
|
+
clearSyncTrigger = setIntervalTask(() => markerSyncTrigger(markerSync), SYNC_TRIGGER_INTERVAL_TIME);
|
|
22343
|
+
}
|
|
22344
|
+
registerEventListeners();
|
|
22345
|
+
};
|
|
22346
|
+
/**
|
|
22347
|
+
```js
|
|
22348
|
+
* import { stopUnreadSyncing } from '@amityco/ts-sdk'
|
|
22349
|
+
* stopUnreadSyncing()
|
|
22350
|
+
* ```
|
|
22351
|
+
*
|
|
22352
|
+
* stop unread syncing
|
|
22353
|
+
*
|
|
22354
|
+
* @category Marker API
|
|
22355
|
+
*/
|
|
22356
|
+
const stopUnreadSyncing = () => {
|
|
22357
|
+
clearSyncTrigger === null || clearSyncTrigger === void 0 ? void 0 : clearSyncTrigger();
|
|
22358
|
+
clearSyncTrigger = undefined;
|
|
22359
|
+
setMarkerSyncEvents([]);
|
|
22360
|
+
unRegisterEventListeners();
|
|
22361
|
+
};
|
|
22362
|
+
|
|
22363
|
+
/**
|
|
22364
|
+
* ```js
|
|
22365
|
+
* import { isInTombstone } from '@amityco/ts-sdk'
|
|
22366
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
22367
|
+
* ```
|
|
22368
|
+
*
|
|
22369
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
22370
|
+
* in cache and it's not expired means it's in tombstone
|
|
22371
|
+
* and we throw an Error
|
|
22372
|
+
*
|
|
22373
|
+
* @param model the model to check
|
|
22374
|
+
* @param modelId the object id to check
|
|
22375
|
+
* @returns the matching cache entry, or undefined.
|
|
22376
|
+
*
|
|
22377
|
+
* @category Cache API
|
|
22378
|
+
*/
|
|
22379
|
+
const isInTombstone = (model, modelId) => {
|
|
22380
|
+
const { log, cache } = getActiveClient();
|
|
22381
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
22382
|
+
if (!cache)
|
|
22383
|
+
return;
|
|
22384
|
+
log('cache/api/isInTombstone', key);
|
|
22385
|
+
const isInTombstone = pullFromCache(key);
|
|
22386
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
22387
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
22388
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22389
|
+
}
|
|
22390
|
+
};
|
|
22391
|
+
|
|
22392
|
+
/**
|
|
22393
|
+
* ```js
|
|
22394
|
+
* import { pushToTombstone } from '@amityco/ts-sdk'
|
|
22395
|
+
* pushToTombstone(["message", "messageId"], { cachedAt: Date.now() })
|
|
22396
|
+
* ```
|
|
22397
|
+
*
|
|
22398
|
+
* Removes an existing {@link Amity.CacheEntry} from the {@link Amity.Client}'s
|
|
22399
|
+
* {@link Amity.Cache} from a given {@link Amity.CacheKey}
|
|
22400
|
+
*
|
|
22401
|
+
* @param model the model to remove and push to Tombstone
|
|
22402
|
+
* @param modelId the related model id
|
|
22403
|
+
*
|
|
22404
|
+
* @category Cache API
|
|
22405
|
+
* @hidden
|
|
22406
|
+
*/
|
|
22407
|
+
const pushToTombstone = (model, modelId) => {
|
|
22408
|
+
const { log, cache } = getActiveClient();
|
|
22409
|
+
const cacheKey = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
22410
|
+
const data = { cachedAt: Date.now() };
|
|
22411
|
+
if (!cache)
|
|
22412
|
+
return;
|
|
22413
|
+
log('cache/api/pushToTombstone', { cacheKey, data });
|
|
22414
|
+
dropFromCache([model, CACHE_KEY_GET, modelId], true);
|
|
22415
|
+
pushToCache(cacheKey, data);
|
|
22416
|
+
};
|
|
22417
|
+
|
|
22418
|
+
/* begin_public_function
|
|
22419
|
+
id: user.get
|
|
22420
|
+
*/
|
|
22421
|
+
/**
|
|
22422
|
+
* ```js
|
|
22423
|
+
* import { getUser } from '@amityco/ts-sdk'
|
|
22424
|
+
* const { data: user } = await getUser('foobar')
|
|
22425
|
+
* ```
|
|
22426
|
+
*
|
|
22427
|
+
* Fetches a {@link Amity.User} object
|
|
22428
|
+
*
|
|
22429
|
+
* @param userId the ID of the {@link Amity.User} to fetch
|
|
22430
|
+
* @returns the associated {@link Amity.User} object
|
|
22431
|
+
*
|
|
22432
|
+
* @category User API
|
|
22433
|
+
* @async
|
|
22434
|
+
*/
|
|
22435
|
+
const getUser = async (userId, isLive = false) => {
|
|
22436
|
+
const client = getActiveClient();
|
|
22437
|
+
client.log('user/getUser', userId);
|
|
22438
|
+
if (!isLive) {
|
|
22439
|
+
console.log('getUser will be deprecated on 25th November 2022, please use liveUser instead.');
|
|
22440
|
+
}
|
|
22441
|
+
isInTombstone('user', userId);
|
|
22442
|
+
let data;
|
|
22443
|
+
try {
|
|
22444
|
+
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
22445
|
+
data = response.data;
|
|
22446
|
+
}
|
|
22447
|
+
catch (error) {
|
|
22448
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22449
|
+
pushToTombstone('user', userId);
|
|
22450
|
+
}
|
|
22451
|
+
throw error;
|
|
22452
|
+
}
|
|
22453
|
+
const cachedAt = client.cache && Date.now();
|
|
22454
|
+
if (client.cache)
|
|
22455
|
+
ingestInCache(data, { cachedAt });
|
|
22456
|
+
const { users } = data;
|
|
22457
|
+
fireEvent('user.fetched', data);
|
|
22458
|
+
return {
|
|
22459
|
+
data: users.find(user => user.userId === userId),
|
|
22460
|
+
cachedAt,
|
|
22461
|
+
};
|
|
22462
|
+
};
|
|
22463
|
+
/* end_public_function */
|
|
22464
|
+
/**
|
|
22465
|
+
* ```js
|
|
22466
|
+
* import { getUser } from '@amityco/ts-sdk'
|
|
22467
|
+
* const { data: user } = getUser.locally('foobar')
|
|
22468
|
+
* ```
|
|
22469
|
+
*
|
|
22470
|
+
* Fetches a {@link Amity.User} object from cache
|
|
22471
|
+
*
|
|
22472
|
+
* @param userId the ID of the {@link Amity.User} to fetch
|
|
22473
|
+
* @returns the associated {@link Amity.User} object
|
|
22474
|
+
*
|
|
22475
|
+
* @category User API
|
|
22476
|
+
*/
|
|
22477
|
+
getUser.locally = (userId) => {
|
|
22478
|
+
const client = getActiveClient();
|
|
22479
|
+
client.log('user/getUser.locally', userId);
|
|
22480
|
+
return client.cache && pullFromCache(['user', 'get', userId]);
|
|
22481
|
+
};
|
|
22482
|
+
|
|
22483
|
+
/* begin_public_function
|
|
22484
|
+
id: user.get_by_ids
|
|
22485
|
+
*/
|
|
22486
|
+
/**
|
|
22487
|
+
* ```js
|
|
22488
|
+
* import { getUsers } from '@amityco/ts-sdk'
|
|
22489
|
+
* const { data: users } = await getUsers(['foo', 'bar'])
|
|
22490
|
+
* ```
|
|
22491
|
+
*
|
|
22492
|
+
* Fetches a collection of {@link Amity.User} objects
|
|
22493
|
+
*
|
|
22494
|
+
* @param userIds the IDs of the {@link Amity.User} to fetch
|
|
22495
|
+
* @returns the associated collection of {@link Amity.User} objects
|
|
22496
|
+
*
|
|
22497
|
+
* @category User API
|
|
22498
|
+
* @async
|
|
22499
|
+
*/
|
|
22500
|
+
const getUsers = async (userIds) => {
|
|
22501
|
+
const client = getActiveClient();
|
|
22502
|
+
client.log('user/getUsers', userIds);
|
|
22503
|
+
const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
|
|
22504
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22505
|
+
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
22506
|
+
params: { userIds: encodedUserIds },
|
|
22507
|
+
});
|
|
22508
|
+
const cachedAt = client.cache && Date.now();
|
|
22509
|
+
if (client.cache)
|
|
22510
|
+
ingestInCache(data, { cachedAt });
|
|
22511
|
+
fireEvent('user.fetched', data);
|
|
22512
|
+
return {
|
|
22513
|
+
data: data.users,
|
|
22514
|
+
cachedAt,
|
|
22515
|
+
};
|
|
22516
|
+
};
|
|
22517
|
+
/**
|
|
22518
|
+
* ```js
|
|
22519
|
+
* import { getUsers } from '@amityco/ts-sdk'
|
|
22520
|
+
* const { data: users } = getUsers.locally!(['foo', 'bar'])
|
|
22521
|
+
* ```
|
|
22522
|
+
*
|
|
22523
|
+
* Fetches a collection of {@link Amity.User} objects from cache
|
|
22524
|
+
*
|
|
22525
|
+
* @param userIds the IDs of the {@link Amity.User} to fetch
|
|
22526
|
+
* @returns the associated collection of {@link Amity.User} objects
|
|
22527
|
+
*
|
|
22528
|
+
* @category User API
|
|
22529
|
+
*/
|
|
22530
|
+
getUsers.locally = (userIds) => {
|
|
22531
|
+
var _a;
|
|
22532
|
+
const client = getActiveClient();
|
|
22533
|
+
client.log('user/getUsers.locally', userIds);
|
|
22534
|
+
if (!client.cache)
|
|
22535
|
+
return;
|
|
22536
|
+
const cached = userIds
|
|
22537
|
+
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
22538
|
+
.filter(Boolean);
|
|
22539
|
+
const users = cached.map(({ data }) => data);
|
|
22540
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
22541
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < userIds.length)
|
|
22542
|
+
return;
|
|
22543
|
+
return {
|
|
22544
|
+
data: users,
|
|
22545
|
+
cachedAt: oldest.cachedAt,
|
|
22546
|
+
};
|
|
22547
|
+
};
|
|
22548
|
+
|
|
22549
|
+
/* begin_public_function
|
|
22550
|
+
id: user.query, user.search
|
|
22551
|
+
*/
|
|
22552
|
+
/**
|
|
22553
|
+
* ```js
|
|
22554
|
+
* import { queryUsers } from '@amityco/ts-sdk'
|
|
22555
|
+
* const { data: users, prevPage, nextPage } = await queryUsers({ displayName: 'foo' })
|
|
22556
|
+
* ```
|
|
22557
|
+
*
|
|
22558
|
+
* Queries a paginable list of {@link Amity.User} objects
|
|
22559
|
+
* Search is performed by displayName such as `.startsWith(search)`
|
|
22560
|
+
*
|
|
22561
|
+
* @param query The query parameters
|
|
22562
|
+
* @returns A page of {@link Amity.User} objects
|
|
22563
|
+
*
|
|
22564
|
+
* @category User API
|
|
22565
|
+
* @async
|
|
22566
|
+
*/
|
|
22567
|
+
const queryUsers = async (query = {}) => {
|
|
22568
|
+
const client = getActiveClient();
|
|
22569
|
+
client.log('user/queryUsers', query);
|
|
22570
|
+
const { page = { limit: 10 }, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "displayName", "filter", "sortBy"]);
|
|
22571
|
+
const { data } = await client.http.get(`/api/v3/users`, {
|
|
22572
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
22573
|
+
sortBy, options: {
|
|
22574
|
+
token: toToken(page, 'skiplimit'),
|
|
22575
|
+
} }),
|
|
22576
|
+
});
|
|
22577
|
+
// unpacking
|
|
22578
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
22579
|
+
const { users } = payload;
|
|
22580
|
+
const cachedAt = client.cache && Date.now();
|
|
22581
|
+
if (client.cache) {
|
|
22582
|
+
ingestInCache(payload, { cachedAt });
|
|
22583
|
+
/*
|
|
22584
|
+
* using query as cache key over params because if the keyword, filter, sort
|
|
22585
|
+
* change the API will NOT cache results, when it should
|
|
22586
|
+
*/
|
|
22587
|
+
const cacheKey = ['user', 'query', Object.assign(Object.assign({}, query), { options: Object.assign({}, page) })];
|
|
22588
|
+
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
22589
|
+
}
|
|
22590
|
+
fireEvent('user.fetched', data);
|
|
22591
|
+
const prevPage = toPage(paging.previous);
|
|
22592
|
+
const nextPage = toPage(paging.next);
|
|
22593
|
+
return { data: users, cachedAt, prevPage, nextPage };
|
|
22594
|
+
};
|
|
22595
|
+
/* end_public_function */
|
|
22596
|
+
/**
|
|
22597
|
+
* ```js
|
|
22598
|
+
* import { queryUsers } from '@amityco/ts-sdk'
|
|
22599
|
+
* const { data: users } = queryUsers.locally({ keyword: 'foo' })
|
|
22600
|
+
* ```
|
|
22601
|
+
*
|
|
22602
|
+
* Queries a paginable list of {@link Amity.User} objects from cache
|
|
22603
|
+
* Search is performed by displayName such as `.startsWith(search)`
|
|
22604
|
+
*
|
|
22605
|
+
* @param query The query parameters
|
|
22606
|
+
* @returns A page of {@link Amity.User} objects
|
|
22607
|
+
*
|
|
22608
|
+
* @category User API
|
|
22609
|
+
*/
|
|
22610
|
+
queryUsers.locally = (query = {}) => {
|
|
22611
|
+
var _a, _b, _c;
|
|
22612
|
+
const client = getActiveClient();
|
|
22613
|
+
client.log('user/queryUsers.locally', query);
|
|
22614
|
+
if (!client.cache)
|
|
22615
|
+
return;
|
|
22616
|
+
const { page = { limit: 10 } } = query !== null && query !== void 0 ? query : {};
|
|
22617
|
+
const cacheKey = [
|
|
22618
|
+
'user',
|
|
22619
|
+
'query',
|
|
22620
|
+
Object.assign(Object.assign({}, query), { options: Object.assign({}, page) }),
|
|
22621
|
+
];
|
|
22622
|
+
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
22623
|
+
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
22624
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
22625
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
22626
|
+
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
22627
|
+
? { data: users, cachedAt, prevPage, nextPage }
|
|
22628
|
+
: undefined;
|
|
22629
|
+
};
|
|
22630
|
+
|
|
22631
|
+
/* begin_public_function
|
|
22632
|
+
id: client.update_user
|
|
22633
|
+
*/
|
|
22634
|
+
/**
|
|
22635
|
+
* ```js
|
|
22636
|
+
* import { updateUser } from '@amityco/ts-sdk'
|
|
22637
|
+
* const updated = await updateUser(userId, { displayName: 'foobar' })
|
|
22638
|
+
* ```
|
|
22639
|
+
*
|
|
22640
|
+
* Updates an {@link Amity.User}
|
|
22641
|
+
*
|
|
22642
|
+
* @param userId The ID of the {@link Amity.User} to update
|
|
22643
|
+
* @param patch The patch data to apply
|
|
22644
|
+
* @returns the updated {@link Amity.User} object
|
|
22645
|
+
*
|
|
22646
|
+
* @category User API
|
|
22647
|
+
* @async
|
|
22648
|
+
*/
|
|
22649
|
+
const updateUser = async (userId, patch) => {
|
|
22650
|
+
const client = getActiveClient();
|
|
22651
|
+
client.log('user/updateUser', userId, patch);
|
|
22652
|
+
// API-FIX: Endpoint is malformed, userId should be a url param.
|
|
22653
|
+
/*
|
|
22654
|
+
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
22655
|
+
`/api/v3/users/${userId}`, patch,
|
|
22656
|
+
)
|
|
22657
|
+
*/
|
|
22658
|
+
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
22659
|
+
const cachedAt = client.cache && Date.now();
|
|
22660
|
+
if (client.cache)
|
|
22661
|
+
ingestInCache(data, { cachedAt });
|
|
22662
|
+
const { users } = data;
|
|
22663
|
+
fireEvent('user.updated', data);
|
|
22664
|
+
return {
|
|
22665
|
+
data: users.find(user => user.userId === userId),
|
|
22666
|
+
cachedAt,
|
|
22667
|
+
};
|
|
22668
|
+
};
|
|
22669
|
+
/* end_public_function */
|
|
22670
|
+
|
|
22671
|
+
/**
|
|
22672
|
+
* ```js
|
|
22673
|
+
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
22674
|
+
* const dispose = onUserUpdated(user => {
|
|
22675
|
+
* // ...
|
|
22676
|
+
* })
|
|
22677
|
+
* ```
|
|
22678
|
+
*
|
|
22679
|
+
* Fired when a {@link Amity.User} has been updated
|
|
22680
|
+
*
|
|
22681
|
+
* @param callback The function to call when the event was fired
|
|
22682
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22683
|
+
*
|
|
22684
|
+
* @category User Events
|
|
22685
|
+
*/
|
|
22686
|
+
const onUserUpdated = (callback) => createUserEventSubscriber('user.updated', callback);
|
|
22687
|
+
|
|
22688
|
+
/**
|
|
22689
|
+
* ```js
|
|
22690
|
+
* import { onUserFlagged } from '@amityco/ts-sdk'
|
|
22691
|
+
* const dispose = onUserFlagged(user => {
|
|
22692
|
+
* // ...
|
|
22693
|
+
* })
|
|
22694
|
+
* ```
|
|
22695
|
+
*
|
|
22696
|
+
* Fired when a {@link Amity.User} has been flagged
|
|
22697
|
+
*
|
|
22698
|
+
* @param callback The function to call when the event was fired
|
|
22699
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22700
|
+
*
|
|
22701
|
+
* @category User Events
|
|
22702
|
+
*/
|
|
22703
|
+
const onUserFlagged = (callback) => createUserEventSubscriber('user.flagged', callback);
|
|
22704
|
+
|
|
22705
|
+
/**
|
|
22706
|
+
* ```js
|
|
22707
|
+
* import { onUserUnflagged } from '@amityco/ts-sdk'
|
|
22708
|
+
* const dispose = onUserUnflagged(user => {
|
|
22709
|
+
* // ...
|
|
22710
|
+
* })
|
|
22711
|
+
* ```
|
|
22712
|
+
*
|
|
22713
|
+
* Fired when a flag has been removed from a {@link Amity.User}
|
|
22714
|
+
*
|
|
22715
|
+
* @param callback The function to call when the event was fired
|
|
22716
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22717
|
+
*
|
|
22718
|
+
* @category User Events
|
|
22719
|
+
*/
|
|
22720
|
+
const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged', callback);
|
|
22721
|
+
|
|
22722
|
+
/**
|
|
22723
|
+
* ```js
|
|
22724
|
+
* import { onUserFlagCleared } from '@amityco/ts-sdk'
|
|
22725
|
+
* const dispose = onUserFlagCleared(user => {
|
|
22726
|
+
* // ...
|
|
22727
|
+
* })
|
|
22728
|
+
* ```
|
|
22729
|
+
*
|
|
22730
|
+
* Fired when flags have been cleared for a {@link Amity.User}
|
|
22731
|
+
*
|
|
22732
|
+
* @param callback The function to call when the event was fired
|
|
22733
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22734
|
+
*
|
|
22735
|
+
* @category User Events
|
|
22736
|
+
*/
|
|
22737
|
+
const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
|
|
22738
|
+
|
|
22739
|
+
/**
|
|
22740
|
+
* ```js
|
|
22741
|
+
* import { onUserFetched } from '@amityco/ts-sdk'
|
|
22742
|
+
* const dispose = onUserFetched(user => {
|
|
22743
|
+
* // ...
|
|
22744
|
+
* })
|
|
22745
|
+
* ```
|
|
22746
|
+
*
|
|
22747
|
+
* Fired when a {@link Amity.User} has been fetched
|
|
22748
|
+
*
|
|
22749
|
+
* @param callback The function to call when the event was fired
|
|
22750
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22751
|
+
*
|
|
22752
|
+
* @category User Events
|
|
22753
|
+
*/
|
|
22754
|
+
const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', callback);
|
|
22755
|
+
|
|
22756
|
+
/**
|
|
21564
22757
|
* ```js
|
|
21565
22758
|
* import { liveUser } from '@amityco/ts-sdk';
|
|
21566
22759
|
*
|
|
@@ -22080,139 +23273,45 @@ const getRole = async (roleId) => {
|
|
|
22080
23273
|
cachedAt,
|
|
22081
23274
|
};
|
|
22082
23275
|
};
|
|
22083
|
-
/**
|
|
22084
|
-
* ```js
|
|
22085
|
-
* import { getRole } from '@amityco/ts-sdk'
|
|
22086
|
-
* const role = getRole.locally('foobar')
|
|
22087
|
-
* ```
|
|
22088
|
-
*
|
|
22089
|
-
* Fetches a {@link Amity.Role} object from cache
|
|
22090
|
-
*
|
|
22091
|
-
* @param roleId the ID of the {@link Amity.Role} to fetch
|
|
22092
|
-
* @returns the associated {@link Amity.Role} object
|
|
22093
|
-
*
|
|
22094
|
-
* @category Role API
|
|
22095
|
-
*/
|
|
22096
|
-
getRole.locally = (roleId) => {
|
|
22097
|
-
const client = getActiveClient();
|
|
22098
|
-
client.log('role/getRole.locally', roleId);
|
|
22099
|
-
if (!client.cache)
|
|
22100
|
-
return;
|
|
22101
|
-
const cached = pullFromCache(['role', 'get', roleId]);
|
|
22102
|
-
if (!cached)
|
|
22103
|
-
return;
|
|
22104
|
-
return {
|
|
22105
|
-
data: cached.data,
|
|
22106
|
-
cachedAt: cached.cachedAt,
|
|
22107
|
-
};
|
|
22108
|
-
};
|
|
22109
|
-
|
|
22110
|
-
/** @hidden */
|
|
22111
|
-
const dispatchReactable = (referenceType, model) => {
|
|
22112
|
-
if (referenceType === 'message')
|
|
22113
|
-
// @ts-ignore: refactor later
|
|
22114
|
-
fireEvent('local.message.updated', { messages: [model] });
|
|
22115
|
-
else if (referenceType === 'post')
|
|
22116
|
-
// @ts-ignore: refactor later
|
|
22117
|
-
fireEvent('post.updated', { posts: [model] });
|
|
22118
|
-
else if (referenceType === 'comment')
|
|
22119
|
-
// @ts-ignore: refactor later
|
|
22120
|
-
fireEvent('comment.updated', { comments: [model] });
|
|
22121
|
-
};
|
|
22122
|
-
|
|
22123
|
-
/** @hidden */
|
|
22124
|
-
/*
|
|
22125
|
-
* @param message payload from http request without myReactions
|
|
22126
|
-
* add myReactions to http response if the event was a reaction event
|
|
22127
|
-
*/
|
|
22128
|
-
const prepareMessagePayloadForCache = (payload) => {
|
|
22129
|
-
const client = getActiveClient();
|
|
22130
|
-
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22131
|
-
// '[]' in cases where the new reaction is the first one
|
|
22132
|
-
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22133
|
-
// add myReactions to the payload
|
|
22134
|
-
Object.assign(payload, { myReactions });
|
|
22135
|
-
// check if there are any updates to the reactions
|
|
22136
|
-
const latestReaction = payload === null || payload === void 0 ? void 0 : payload.latestReaction;
|
|
22137
|
-
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22138
|
-
if (!isLatestReactionMine) {
|
|
22139
|
-
return;
|
|
22140
|
-
}
|
|
22141
|
-
// new reaction added
|
|
22142
|
-
if (latestReaction.eventName === 'add' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22143
|
-
Object.assign(payload, {
|
|
22144
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22145
|
-
});
|
|
22146
|
-
}
|
|
22147
|
-
// existing reaction removed
|
|
22148
|
-
if (latestReaction.eventName === 'remove' && myReactions.includes(latestReaction.reactionName)) {
|
|
22149
|
-
Object.assign(payload, {
|
|
22150
|
-
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22151
|
-
});
|
|
22152
|
-
}
|
|
22153
|
-
};
|
|
22154
|
-
|
|
22155
|
-
function convertFromRaw$2(_a) {
|
|
22156
|
-
var { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment } = _a, rest = __rest(_a, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment"]);
|
|
22157
|
-
let cache;
|
|
22158
|
-
if (referenceId) {
|
|
22159
|
-
try {
|
|
22160
|
-
cache = pullFromCache(['message', 'get', referenceId]);
|
|
22161
|
-
// eslint-disable-next-line no-empty
|
|
22162
|
-
}
|
|
22163
|
-
catch (_b) { }
|
|
22164
|
-
}
|
|
22165
|
-
if (!cache) {
|
|
22166
|
-
try {
|
|
22167
|
-
cache = pullFromCache(['message', 'get', rest.messageId]);
|
|
22168
|
-
// eslint-disable-next-line no-empty
|
|
22169
|
-
}
|
|
22170
|
-
catch (_c) { }
|
|
22171
|
-
}
|
|
22172
|
-
const out = Object.assign(Object.assign({}, rest), { channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, reactions: reactions !== null && reactions !== void 0 ? reactions : {}, reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : rest.messageId });
|
|
22173
|
-
if (mentionedUsers) {
|
|
22174
|
-
out.mentionees = mentionedUsers.map(mention => {
|
|
22175
|
-
if (mention.type === 'channel') {
|
|
22176
|
-
return mention;
|
|
22177
|
-
}
|
|
22178
|
-
return { type: 'user', userIds: mention.userPublicIds };
|
|
22179
|
-
});
|
|
22180
|
-
}
|
|
22181
|
-
if (myReactions) {
|
|
22182
|
-
// http response
|
|
22183
|
-
out.myReactions = myReactions;
|
|
22184
|
-
}
|
|
22185
|
-
else {
|
|
22186
|
-
// mqtt event
|
|
22187
|
-
try {
|
|
22188
|
-
prepareMessagePayloadForCache(out);
|
|
22189
|
-
// eslint-disable-next-line no-empty
|
|
22190
|
-
}
|
|
22191
|
-
catch (_d) { }
|
|
22192
|
-
}
|
|
22193
|
-
return out;
|
|
22194
|
-
}
|
|
22195
|
-
const prepareMessagePayload = (payload) => {
|
|
22196
|
-
return Object.assign(Object.assign({}, payload), { messages: payload.messages.map(convertFromRaw$2) });
|
|
22197
|
-
};
|
|
22198
|
-
const convertResponseFromRaw = (response) => {
|
|
22199
|
-
return Object.assign(Object.assign({}, response), { data: Object.assign(Object.assign({}, response.data), { messages: response.data.messages.map(convertFromRaw$2) }) });
|
|
22200
|
-
};
|
|
22201
|
-
function convertParams(_a) {
|
|
22202
|
-
var { subChannelId, mentionees } = _a, rest = __rest(_a, ["subChannelId", "mentionees"]);
|
|
22203
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees }, rest);
|
|
22204
|
-
}
|
|
22205
|
-
function convertQueryParams$1(_a) {
|
|
22206
|
-
var { page, sortBy, subChannelId, tags, includeDeleted } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags", "includeDeleted"]);
|
|
22207
|
-
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: includeDeleted === false ? false : undefined, options: { token: toToken(page || { limit: 10 }, 'afterbeforeraw') } });
|
|
22208
|
-
if (sortBy !== undefined) {
|
|
22209
|
-
out.options.sortBy = sortBy;
|
|
22210
|
-
}
|
|
22211
|
-
if (tags) {
|
|
22212
|
-
out.includeTags = tags;
|
|
22213
|
-
}
|
|
22214
|
-
return out;
|
|
22215
|
-
}
|
|
23276
|
+
/**
|
|
23277
|
+
* ```js
|
|
23278
|
+
* import { getRole } from '@amityco/ts-sdk'
|
|
23279
|
+
* const role = getRole.locally('foobar')
|
|
23280
|
+
* ```
|
|
23281
|
+
*
|
|
23282
|
+
* Fetches a {@link Amity.Role} object from cache
|
|
23283
|
+
*
|
|
23284
|
+
* @param roleId the ID of the {@link Amity.Role} to fetch
|
|
23285
|
+
* @returns the associated {@link Amity.Role} object
|
|
23286
|
+
*
|
|
23287
|
+
* @category Role API
|
|
23288
|
+
*/
|
|
23289
|
+
getRole.locally = (roleId) => {
|
|
23290
|
+
const client = getActiveClient();
|
|
23291
|
+
client.log('role/getRole.locally', roleId);
|
|
23292
|
+
if (!client.cache)
|
|
23293
|
+
return;
|
|
23294
|
+
const cached = pullFromCache(['role', 'get', roleId]);
|
|
23295
|
+
if (!cached)
|
|
23296
|
+
return;
|
|
23297
|
+
return {
|
|
23298
|
+
data: cached.data,
|
|
23299
|
+
cachedAt: cached.cachedAt,
|
|
23300
|
+
};
|
|
23301
|
+
};
|
|
23302
|
+
|
|
23303
|
+
/** @hidden */
|
|
23304
|
+
const dispatchReactable = (referenceType, model) => {
|
|
23305
|
+
if (referenceType === 'message')
|
|
23306
|
+
// @ts-ignore: refactor later
|
|
23307
|
+
fireEvent('local.message.updated', { messages: [model] });
|
|
23308
|
+
else if (referenceType === 'post')
|
|
23309
|
+
// @ts-ignore: refactor later
|
|
23310
|
+
fireEvent('post.updated', { posts: [model] });
|
|
23311
|
+
else if (referenceType === 'comment')
|
|
23312
|
+
// @ts-ignore: refactor later
|
|
23313
|
+
fireEvent('comment.updated', { comments: [model] });
|
|
23314
|
+
};
|
|
22216
23315
|
|
|
22217
23316
|
/* begin_public_function
|
|
22218
23317
|
id: message.get
|
|
@@ -22241,10 +23340,8 @@ const getMessage = async (messageId, isLive = false) => {
|
|
|
22241
23340
|
let data;
|
|
22242
23341
|
try {
|
|
22243
23342
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22244
|
-
const
|
|
22245
|
-
|
|
22246
|
-
.then(convertResponseFromRaw);
|
|
22247
|
-
data = response.data;
|
|
23343
|
+
const { data: payload } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
23344
|
+
data = await prepareMessagePayload(payload);
|
|
22248
23345
|
}
|
|
22249
23346
|
catch (error) {
|
|
22250
23347
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -22307,11 +23404,10 @@ getMessage.locally = (messageId) => {
|
|
|
22307
23404
|
const getMessages = async (messageIds) => {
|
|
22308
23405
|
const client = getActiveClient();
|
|
22309
23406
|
client.log('message/getMessages', messageIds);
|
|
22310
|
-
const { data } = await client.http
|
|
22311
|
-
.get(`/api/v5/messages/list`, {
|
|
23407
|
+
const { data: payload } = await client.http.get(`/api/v5/messages/list`, {
|
|
22312
23408
|
params: { messageIds: messageIds.map(encodeURIComponent) },
|
|
22313
|
-
})
|
|
22314
|
-
|
|
23409
|
+
});
|
|
23410
|
+
const data = await prepareMessagePayload(payload);
|
|
22315
23411
|
const cachedAt = client.cache && Date.now();
|
|
22316
23412
|
if (client.cache)
|
|
22317
23413
|
ingestInCache(data, { cachedAt });
|
|
@@ -22379,12 +23475,11 @@ const queryMessages = async (query) => {
|
|
|
22379
23475
|
// API-FIX: backend should answer Amity.Response (2)
|
|
22380
23476
|
// API-FIX: pagination should not be indexed on channelSegment (3)
|
|
22381
23477
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<Amity.MessagePayload>>>(
|
|
22382
|
-
const
|
|
22383
|
-
.get(`/api/v5/messages`, { params })
|
|
22384
|
-
.then(convertResponseFromRaw);
|
|
23478
|
+
const { data: queryPayload } = await client.http.get(`/api/v5/messages`, { params });
|
|
22385
23479
|
// API-FIX: backend should answer Amity.Response (2)
|
|
22386
23480
|
// const { paging, messages } = unwrapPayload(data)
|
|
22387
|
-
const
|
|
23481
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
23482
|
+
const data = await prepareMessagePayload(payload);
|
|
22388
23483
|
const { messages } = data;
|
|
22389
23484
|
const cachedAt = client.cache && Date.now();
|
|
22390
23485
|
if (client.cache) {
|
|
@@ -22469,7 +23564,7 @@ const createMessage = async (bundle) => {
|
|
|
22469
23564
|
const referenceId = bundle.referenceId || uniqueId || getLocalId();
|
|
22470
23565
|
uniqueId = undefined;
|
|
22471
23566
|
const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
|
|
22472
|
-
const data = prepareMessagePayload(payload);
|
|
23567
|
+
const data = await prepareMessagePayload(payload);
|
|
22473
23568
|
const { messages } = data;
|
|
22474
23569
|
const cachedAt = client.cache && Date.now();
|
|
22475
23570
|
if (client.cache) {
|
|
@@ -22561,9 +23656,8 @@ createMessage.optimistically = (_a) => {
|
|
|
22561
23656
|
const updateMessage = async (messageId, patch) => {
|
|
22562
23657
|
const client = getActiveClient();
|
|
22563
23658
|
client.log('message/updateMessage', patch);
|
|
22564
|
-
const { data } = await client.http
|
|
22565
|
-
|
|
22566
|
-
.then(convertResponseFromRaw);
|
|
23659
|
+
const { data: payload } = await client.http.put(`/api/v5/messages/${encodeURIComponent(messageId)}`, convertParams(patch));
|
|
23660
|
+
const data = await prepareMessagePayload(payload);
|
|
22567
23661
|
const cachedAt = client.cache && Date.now();
|
|
22568
23662
|
if (client.cache)
|
|
22569
23663
|
ingestInCache(data, { cachedAt });
|
|
@@ -22665,6 +23759,31 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
22665
23759
|
};
|
|
22666
23760
|
/* end_public_function */
|
|
22667
23761
|
|
|
23762
|
+
/**
|
|
23763
|
+
* ```js
|
|
23764
|
+
* import { markAsDelivered } from '@amityco/ts-sdk'
|
|
23765
|
+
* const success = await markAsDelivered('subChannelId', 'messageId')
|
|
23766
|
+
* ```
|
|
23767
|
+
*
|
|
23768
|
+
* Update `deliveredToSegment` in {@link Amity.SubChannelMarker}
|
|
23769
|
+
*
|
|
23770
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} of message
|
|
23771
|
+
* @param messageId the ID of the {@link Amity.Message} to mark delivered
|
|
23772
|
+
* @returns A success boolean if the {@link Amity.SubChannel} was updated
|
|
23773
|
+
*
|
|
23774
|
+
* @category Message API
|
|
23775
|
+
* @async
|
|
23776
|
+
*/
|
|
23777
|
+
const markAsDelivered = async (subChannelId, messageId) => {
|
|
23778
|
+
const client = getActiveClient();
|
|
23779
|
+
client.log('message/markAsDelivered', subChannelId, messageId);
|
|
23780
|
+
const { data } = await client.http.put(`/api/v1/markers/message-feeds/${subChannelId}/mark-delivering`, { messageId });
|
|
23781
|
+
const cachedAt = client.cache && Date.now();
|
|
23782
|
+
if (client.cache)
|
|
23783
|
+
ingestInCache(data, { cachedAt });
|
|
23784
|
+
return true;
|
|
23785
|
+
};
|
|
23786
|
+
|
|
22668
23787
|
/**
|
|
22669
23788
|
* Attach user object to membership model
|
|
22670
23789
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -24974,9 +26093,9 @@ const onReactionAdded = (referenceType, referenceId, callback) => {
|
|
|
24974
26093
|
*/
|
|
24975
26094
|
if (referenceType === 'message') {
|
|
24976
26095
|
const client = getActiveClient();
|
|
24977
|
-
const filter = (rawPayload) => {
|
|
26096
|
+
const filter = async (rawPayload) => {
|
|
24978
26097
|
var _a;
|
|
24979
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26098
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
24980
26099
|
const cached = pullFromCache([
|
|
24981
26100
|
'message',
|
|
24982
26101
|
'get',
|
|
@@ -25021,9 +26140,9 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
|
25021
26140
|
};
|
|
25022
26141
|
if (referenceType === 'message') {
|
|
25023
26142
|
const client = getActiveClient();
|
|
25024
|
-
const filter = (rawPayload) => {
|
|
26143
|
+
const filter = async (rawPayload) => {
|
|
25025
26144
|
var _a;
|
|
25026
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26145
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25027
26146
|
const cached = pullFromCache([
|
|
25028
26147
|
'message',
|
|
25029
26148
|
'get',
|
|
@@ -25068,8 +26187,8 @@ const onReactorAdded = (referenceType, referenceId, callback) => {
|
|
|
25068
26187
|
}
|
|
25069
26188
|
};
|
|
25070
26189
|
if (referenceType === 'message') {
|
|
25071
|
-
const filter = (rawPayload) => {
|
|
25072
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26190
|
+
const filter = async (rawPayload) => {
|
|
26191
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25073
26192
|
if (!payload.messages[0].latestReaction)
|
|
25074
26193
|
return;
|
|
25075
26194
|
const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType, userDisplayName } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType", "userDisplayName"]);
|
|
@@ -25130,8 +26249,8 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
25130
26249
|
}
|
|
25131
26250
|
};
|
|
25132
26251
|
if (referenceType === 'message') {
|
|
25133
|
-
const filter = (rawPayload) => {
|
|
25134
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26252
|
+
const filter = async (rawPayload) => {
|
|
26253
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25135
26254
|
if (!payload.messages[0].latestReaction)
|
|
25136
26255
|
return;
|
|
25137
26256
|
const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType"]);
|
|
@@ -25317,7 +26436,8 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
25317
26436
|
const { data: payload } = await client.http.post(getAPIUrl());
|
|
25318
26437
|
if (client.cache) {
|
|
25319
26438
|
if (referenceType === 'message') {
|
|
25320
|
-
|
|
26439
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
26440
|
+
ingestInCache(messagePayload);
|
|
25321
26441
|
}
|
|
25322
26442
|
else if (referenceType === 'post') {
|
|
25323
26443
|
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
@@ -25363,7 +26483,8 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
25363
26483
|
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
25364
26484
|
if (client.cache) {
|
|
25365
26485
|
if (referenceType === 'message') {
|
|
25366
|
-
|
|
26486
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
26487
|
+
ingestInCache(messagePayload);
|
|
25367
26488
|
}
|
|
25368
26489
|
else if (referenceType === 'post') {
|
|
25369
26490
|
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
@@ -25410,37 +26531,60 @@ const isReportedByMe = async (referenceType, referenceId) => {
|
|
|
25410
26531
|
};
|
|
25411
26532
|
/* end_public_function */
|
|
25412
26533
|
|
|
25413
|
-
|
|
25414
|
-
|
|
25415
|
-
|
|
25416
|
-
|
|
25417
|
-
|
|
25418
|
-
|
|
25419
|
-
|
|
25420
|
-
cached = pullFromCache(['channel', 'get', rawChannel.channelId]);
|
|
25421
|
-
// eslint-disable-next-line no-empty
|
|
25422
|
-
}
|
|
25423
|
-
catch (_a) { }
|
|
25424
|
-
if (cached) {
|
|
25425
|
-
return {
|
|
25426
|
-
defaultSubChannelHasUnreadMention: cached.data.defaultSubChannelHasUnreadMention,
|
|
25427
|
-
defaultSubChannelUnreadCount: cached.data.defaultSubChannelUnreadCount,
|
|
25428
|
-
localReadToSegment: cached.data.localReadToSegment,
|
|
25429
|
-
localLastMentionSegment: cached.data.localLastMentionSegment,
|
|
25430
|
-
};
|
|
25431
|
-
}
|
|
25432
|
-
return {
|
|
25433
|
-
defaultSubChannelHasUnreadMention: false,
|
|
25434
|
-
defaultSubChannelUnreadCount: 0,
|
|
25435
|
-
// @ts-ignore
|
|
25436
|
-
localReadToSegment: rawChannel.messageCount > 0 ? rawChannel.messageCount - 1 : 0,
|
|
25437
|
-
localLastMentionSegment: 0,
|
|
26534
|
+
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
26535
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
26536
|
+
const getCachedMarker = (entityId) => {
|
|
26537
|
+
var _a;
|
|
26538
|
+
const key = {
|
|
26539
|
+
entityId,
|
|
26540
|
+
userId: getActiveUser()._id,
|
|
25438
26541
|
};
|
|
26542
|
+
return (_a = pullFromCache([
|
|
26543
|
+
'channelMarker',
|
|
26544
|
+
'get',
|
|
26545
|
+
getResolver('channelMarker')(key),
|
|
26546
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26547
|
+
};
|
|
26548
|
+
const getUnreadCount = (channel, marker) => {
|
|
26549
|
+
var _a, _b, _c;
|
|
26550
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
26551
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
26552
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
26553
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
26554
|
+
return 0;
|
|
26555
|
+
}
|
|
26556
|
+
return (_c = (_a = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _a !== void 0 ? _a : (_b = getCachedMarker(channel.channelId)) === null || _b === void 0 ? void 0 : _b.unreadCount) !== null && _c !== void 0 ? _c : 0;
|
|
26557
|
+
};
|
|
26558
|
+
function convertFromRaw(channel, marker) {
|
|
26559
|
+
return Object.assign(Object.assign({}, channel), { isUnreadCountSupport: isUnreadCountSupport(channel), unreadCount: getUnreadCount(channel, marker) });
|
|
26560
|
+
}
|
|
26561
|
+
function updateChannelMarker(channel, marker) {
|
|
26562
|
+
return Object.assign(Object.assign({}, channel), { unreadCount: getUnreadCount(channel, marker), updatedAt: new Date().toISOString() });
|
|
25439
26563
|
}
|
|
25440
|
-
const prepareChannelPayload = (rawPayload) => {
|
|
25441
|
-
|
|
26564
|
+
const prepareChannelPayload = async (rawPayload) => {
|
|
26565
|
+
// make a fetch marker to prepare it for merging with the raw channel payload.
|
|
26566
|
+
let markers = [];
|
|
26567
|
+
const markerIds = rawPayload.channels
|
|
26568
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
26569
|
+
.filter(isUnreadCountSupport)
|
|
26570
|
+
.map(({ channelId }) => channelId);
|
|
26571
|
+
if (markerIds.length > 0)
|
|
26572
|
+
// from the spec, allow marker fetch to fail
|
|
26573
|
+
try {
|
|
26574
|
+
({ data: markers } = await getChannelMarkers(markerIds));
|
|
26575
|
+
}
|
|
26576
|
+
catch (e) {
|
|
26577
|
+
// empty block
|
|
26578
|
+
}
|
|
26579
|
+
// attach marker to channel
|
|
26580
|
+
const channels = rawPayload.channels.map(channel => {
|
|
26581
|
+
const marker = markers === null || markers === void 0 ? void 0 : markers.find(({ entityId }) => entityId === channel.channelId);
|
|
26582
|
+
return convertFromRaw(channel, marker);
|
|
26583
|
+
});
|
|
26584
|
+
// user marker to channel users
|
|
25442
26585
|
const channelUsers = withUsers(rawPayload.channelUsers);
|
|
25443
|
-
return Object.assign(Object.assign({}, rawPayload), { channels,
|
|
26586
|
+
return Object.assign(Object.assign({}, rawPayload), { channels,
|
|
26587
|
+
channelUsers });
|
|
25444
26588
|
};
|
|
25445
26589
|
|
|
25446
26590
|
/* begin_public_function
|
|
@@ -25475,7 +26619,7 @@ const queryChannels = async (query) => {
|
|
|
25475
26619
|
} }),
|
|
25476
26620
|
});
|
|
25477
26621
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
25478
|
-
const data = prepareChannelPayload(payload);
|
|
26622
|
+
const data = await prepareChannelPayload(payload);
|
|
25479
26623
|
const { channels } = data;
|
|
25480
26624
|
const cachedAt = client.cache && Date.now();
|
|
25481
26625
|
if (client.cache) {
|
|
@@ -25560,7 +26704,7 @@ const getChannels = async (channelIds) => {
|
|
|
25560
26704
|
});
|
|
25561
26705
|
throw error;
|
|
25562
26706
|
}
|
|
25563
|
-
const data = prepareChannelPayload(payload);
|
|
26707
|
+
const data = await prepareChannelPayload(payload);
|
|
25564
26708
|
const cachedAt = client.cache && Date.now();
|
|
25565
26709
|
if (client.cache)
|
|
25566
26710
|
ingestInCache(data, { cachedAt });
|
|
@@ -25625,7 +26769,7 @@ const getChannel = async (channelId) => {
|
|
|
25625
26769
|
let data;
|
|
25626
26770
|
try {
|
|
25627
26771
|
const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
25628
|
-
data = prepareChannelPayload(payload);
|
|
26772
|
+
data = await prepareChannelPayload(payload);
|
|
25629
26773
|
}
|
|
25630
26774
|
catch (error) {
|
|
25631
26775
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -25697,7 +26841,7 @@ const createChannel = async (bundle) => {
|
|
|
25697
26841
|
else {
|
|
25698
26842
|
payload = await client.http.post('/api/v3/channels', bundle);
|
|
25699
26843
|
}
|
|
25700
|
-
const data = prepareChannelPayload(payload.data);
|
|
26844
|
+
const data = await prepareChannelPayload(payload.data);
|
|
25701
26845
|
const cachedAt = client.cache && Date.now();
|
|
25702
26846
|
if (client.cache)
|
|
25703
26847
|
ingestInCache(data, { cachedAt });
|
|
@@ -25731,7 +26875,7 @@ const updateChannel = async (channelId, patch) => {
|
|
|
25731
26875
|
const client = getActiveClient();
|
|
25732
26876
|
client.log('channel/updateChannel', channelId, patch);
|
|
25733
26877
|
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
25734
|
-
const data = prepareChannelPayload(payload);
|
|
26878
|
+
const data = await prepareChannelPayload(payload);
|
|
25735
26879
|
const cachedAt = client.cache && Date.now();
|
|
25736
26880
|
if (client.cache)
|
|
25737
26881
|
ingestInCache(data, { cachedAt });
|
|
@@ -25787,7 +26931,7 @@ const joinChannel = async (channelId) => {
|
|
|
25787
26931
|
const client = getActiveClient();
|
|
25788
26932
|
client.log('channel/joinChannel', channelId);
|
|
25789
26933
|
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
25790
|
-
const data = prepareChannelPayload(payload);
|
|
26934
|
+
const data = await prepareChannelPayload(payload);
|
|
25791
26935
|
if (client.cache)
|
|
25792
26936
|
ingestInCache(data);
|
|
25793
26937
|
const { channelUsers } = data;
|
|
@@ -25816,7 +26960,7 @@ const leaveChannel = async (channelId) => {
|
|
|
25816
26960
|
const client = getActiveClient();
|
|
25817
26961
|
client.log('channel/leaveChannel', channelId);
|
|
25818
26962
|
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
25819
|
-
const data = prepareChannelPayload(payload);
|
|
26963
|
+
const data = await prepareChannelPayload(payload);
|
|
25820
26964
|
if (client.cache)
|
|
25821
26965
|
ingestInCache(data);
|
|
25822
26966
|
const { channelUsers } = data;
|
|
@@ -25851,7 +26995,7 @@ const queryChannelMembers = async (query) => {
|
|
|
25851
26995
|
} }),
|
|
25852
26996
|
});
|
|
25853
26997
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
25854
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26998
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
25855
26999
|
const { channelUsers } = preparedPayload;
|
|
25856
27000
|
const cachedAt = client.cache && Date.now();
|
|
25857
27001
|
if (client.cache) {
|
|
@@ -25942,7 +27086,7 @@ const addChannelMembers = async (channelId, userIds) => {
|
|
|
25942
27086
|
* should fire event for each user that was added
|
|
25943
27087
|
*/
|
|
25944
27088
|
userIds.forEach(id => fireEvent('channel.membersAdded', Object.assign(Object.assign({}, payload), { channelUsers: payload.channelUsers.filter(u => u.userId === id) })));
|
|
25945
|
-
const data = prepareChannelPayload(payload);
|
|
27089
|
+
const data = await prepareChannelPayload(payload);
|
|
25946
27090
|
if (client.cache)
|
|
25947
27091
|
ingestInCache(data);
|
|
25948
27092
|
const { channelUsers } = data;
|
|
@@ -25976,7 +27120,7 @@ const removeChannelMembers = async (channelId, userIds) => {
|
|
|
25976
27120
|
* should fire event for each user that was removed
|
|
25977
27121
|
*/
|
|
25978
27122
|
userIds.forEach(id => fireEvent('channel.membersRemoved', Object.assign(Object.assign({}, payload), { channelUsers: payload.channelUsers.filter(u => u.userId === id) })));
|
|
25979
|
-
const data = prepareChannelPayload(payload);
|
|
27123
|
+
const data = await prepareChannelPayload(payload);
|
|
25980
27124
|
if (client.cache)
|
|
25981
27125
|
ingestInCache(data);
|
|
25982
27126
|
const { channelUsers } = data;
|
|
@@ -26007,7 +27151,7 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
26007
27151
|
const client = getActiveClient();
|
|
26008
27152
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
|
|
26009
27153
|
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
26010
|
-
const data = prepareChannelPayload(payload);
|
|
27154
|
+
const data = await prepareChannelPayload(payload);
|
|
26011
27155
|
if (client.cache)
|
|
26012
27156
|
ingestInCache(data);
|
|
26013
27157
|
const { channelUsers } = data;
|
|
@@ -26038,7 +27182,7 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
26038
27182
|
const client = getActiveClient();
|
|
26039
27183
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
26040
27184
|
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
26041
|
-
const data = prepareChannelPayload(payload);
|
|
27185
|
+
const data = await prepareChannelPayload(payload);
|
|
26042
27186
|
if (client.cache)
|
|
26043
27187
|
ingestInCache(data);
|
|
26044
27188
|
const { channelUsers } = data;
|
|
@@ -26069,7 +27213,7 @@ const banChannelMembers = async (channelId, userIds) => {
|
|
|
26069
27213
|
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
26070
27214
|
userIds,
|
|
26071
27215
|
});
|
|
26072
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27216
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26073
27217
|
const { channelUsers } = preparedPayload;
|
|
26074
27218
|
const cachedAt = client.cache && Date.now();
|
|
26075
27219
|
if (client.cache)
|
|
@@ -26104,7 +27248,7 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
26104
27248
|
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
26105
27249
|
userIds,
|
|
26106
27250
|
});
|
|
26107
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27251
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26108
27252
|
const cachedAt = client.cache && Date.now();
|
|
26109
27253
|
if (client.cache)
|
|
26110
27254
|
ingestInCache(preparedPayload, { cachedAt });
|
|
@@ -26116,88 +27260,6 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
26116
27260
|
};
|
|
26117
27261
|
/* end_public_function */
|
|
26118
27262
|
|
|
26119
|
-
/* begin_public_function
|
|
26120
|
-
id: channel.start_reading
|
|
26121
|
-
*/
|
|
26122
|
-
/**
|
|
26123
|
-
* ```js
|
|
26124
|
-
* import { startReading } from '@amityco/ts-sdk'
|
|
26125
|
-
* const success = await startReading('foo')
|
|
26126
|
-
* ```
|
|
26127
|
-
*
|
|
26128
|
-
* Mark all messages as read and start reading message inside channel
|
|
26129
|
-
*
|
|
26130
|
-
* @param subChannelId - The channel ID to start reading.
|
|
26131
|
-
* @param userId - The user ID of channel member.
|
|
26132
|
-
* @return A success boolean if the channel reading of the sub channel had begun.
|
|
26133
|
-
*
|
|
26134
|
-
* @category Message API
|
|
26135
|
-
* @async
|
|
26136
|
-
*/
|
|
26137
|
-
const startReading = async (subChannelId, userId = getActiveClient().userId) => {
|
|
26138
|
-
const client = getActiveClient();
|
|
26139
|
-
client.log('message/startReading', { subChannelId });
|
|
26140
|
-
const subChannel = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
26141
|
-
if (!subChannel) {
|
|
26142
|
-
return;
|
|
26143
|
-
}
|
|
26144
|
-
const { channelId } = subChannel.data;
|
|
26145
|
-
const channel = pullFromCache(['channel', 'get', channelId]);
|
|
26146
|
-
if (!channel || channel.data.defaultSubChannelId !== subChannelId) {
|
|
26147
|
-
return;
|
|
26148
|
-
}
|
|
26149
|
-
const update = Object.assign(Object.assign({}, channel.data), {
|
|
26150
|
-
// @ts-ignore
|
|
26151
|
-
localReading: true, defaultSubChannelUnreadCount: 0, defaultSubChannelHasUnreadMention: false });
|
|
26152
|
-
pushToCache(['channel', 'get', channelId], update);
|
|
26153
|
-
client.emitter.emit('local.channel.updated', { channels: [update] });
|
|
26154
|
-
const result = await synchronousWSCall(client, 'channel.startReading', {
|
|
26155
|
-
channelId,
|
|
26156
|
-
});
|
|
26157
|
-
return !!result;
|
|
26158
|
-
};
|
|
26159
|
-
/* end_public_function */
|
|
26160
|
-
|
|
26161
|
-
/* begin_public_function
|
|
26162
|
-
id: channel.stop_reading
|
|
26163
|
-
*/
|
|
26164
|
-
/**
|
|
26165
|
-
* ```js
|
|
26166
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
26167
|
-
* const success = await stopReading('foo')
|
|
26168
|
-
* ```
|
|
26169
|
-
*
|
|
26170
|
-
* Stop reading message inside channel
|
|
26171
|
-
*
|
|
26172
|
-
* @param subChannelId - The channel ID to stop reading.
|
|
26173
|
-
* @return A success boolean if the sub channel reading was halted.
|
|
26174
|
-
*
|
|
26175
|
-
* @category Message API
|
|
26176
|
-
* @async
|
|
26177
|
-
*/
|
|
26178
|
-
const stopReading = async (subChannelId) => {
|
|
26179
|
-
const client = getActiveClient();
|
|
26180
|
-
client.log('message/stopReading', { subChannelId });
|
|
26181
|
-
const subChannel = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
26182
|
-
if (!subChannel) {
|
|
26183
|
-
return;
|
|
26184
|
-
}
|
|
26185
|
-
const { channelId } = subChannel.data;
|
|
26186
|
-
const channel = pullFromCache(['channel', 'get', channelId]);
|
|
26187
|
-
if (!channel || channel.data.defaultSubChannelId !== subChannelId) {
|
|
26188
|
-
return;
|
|
26189
|
-
}
|
|
26190
|
-
const update = Object.assign(Object.assign({}, channel.data), {
|
|
26191
|
-
// @ts-ignore
|
|
26192
|
-
localReading: false });
|
|
26193
|
-
pushToCache(['channel', 'get', channelId], update);
|
|
26194
|
-
const result = await synchronousWSCall(client, 'channel.stopReading', {
|
|
26195
|
-
channelId,
|
|
26196
|
-
});
|
|
26197
|
-
return !!result;
|
|
26198
|
-
};
|
|
26199
|
-
/* end_public_function */
|
|
26200
|
-
|
|
26201
27263
|
/**
|
|
26202
27264
|
* ```js
|
|
26203
27265
|
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
@@ -26206,602 +27268,345 @@ const stopReading = async (subChannelId) => {
|
|
|
26206
27268
|
* })
|
|
26207
27269
|
* ```
|
|
26208
27270
|
*
|
|
26209
|
-
* Fired when any {@link Amity.Channel} have been created
|
|
26210
|
-
*
|
|
26211
|
-
* @param callback The function to call when the event was fired
|
|
26212
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26213
|
-
*
|
|
26214
|
-
* @category Channel Events
|
|
26215
|
-
*/
|
|
26216
|
-
const onChannelCreated = (callback) => {
|
|
26217
|
-
const client = getActiveClient();
|
|
26218
|
-
const filter = (payload) => {
|
|
26219
|
-
const data = prepareChannelPayload(payload);
|
|
26220
|
-
ingestInCache(data);
|
|
26221
|
-
callback(data.channels[0]);
|
|
26222
|
-
};
|
|
26223
|
-
return createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
26224
|
-
};
|
|
26225
|
-
|
|
26226
|
-
/**
|
|
26227
|
-
* ```js
|
|
26228
|
-
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
26229
|
-
* const dispose = onChannelUpdated(channel => {
|
|
26230
|
-
* // ...
|
|
26231
|
-
* })
|
|
26232
|
-
* ```
|
|
26233
|
-
*
|
|
26234
|
-
* Fired when any {@link Amity.Channel} have been updated
|
|
26235
|
-
*
|
|
26236
|
-
* @param callback The function to call when the event was fired
|
|
26237
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26238
|
-
*
|
|
26239
|
-
* @category Channel Events
|
|
26240
|
-
*/
|
|
26241
|
-
const onChannelUpdated = (callback) => {
|
|
26242
|
-
const client = getActiveClient();
|
|
26243
|
-
const filter = (payload) => {
|
|
26244
|
-
const data = prepareChannelPayload(payload);
|
|
26245
|
-
ingestInCache(data);
|
|
26246
|
-
callback(data.channels[0]);
|
|
26247
|
-
};
|
|
26248
|
-
const disposers = [
|
|
26249
|
-
createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter),
|
|
26250
|
-
createEventSubscriber(client, 'local.channel.updated', 'local.channel.updated', payload => callback(payload.channels[0])),
|
|
26251
|
-
];
|
|
26252
|
-
return () => {
|
|
26253
|
-
disposers.forEach(fn => fn());
|
|
26254
|
-
};
|
|
26255
|
-
};
|
|
26256
|
-
|
|
26257
|
-
/**
|
|
26258
|
-
* ```js
|
|
26259
|
-
* import { onChannelDeleted } from '@amityco/ts-sdk'
|
|
26260
|
-
* const dispose = onChannelDeleted(channel => {
|
|
26261
|
-
* // ...
|
|
26262
|
-
* })
|
|
26263
|
-
* ```
|
|
26264
|
-
*
|
|
26265
|
-
* Fired when any {@link Amity.Channel} have been deleted
|
|
26266
|
-
*
|
|
26267
|
-
* @param callback The function to call when the event was fired
|
|
26268
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26269
|
-
*
|
|
26270
|
-
* @category Channel Events
|
|
26271
|
-
*/
|
|
26272
|
-
const onChannelDeleted = (callback) => {
|
|
26273
|
-
const client = getActiveClient();
|
|
26274
|
-
const filter = (payload) => {
|
|
26275
|
-
const data = prepareChannelPayload(payload);
|
|
26276
|
-
ingestInCache(data);
|
|
26277
|
-
callback(data.channels[0]);
|
|
26278
|
-
};
|
|
26279
|
-
return createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
26280
|
-
};
|
|
26281
|
-
|
|
26282
|
-
/**
|
|
26283
|
-
* ```js
|
|
26284
|
-
* import { onChannelJoined } from '@amityco/ts-sdk'
|
|
26285
|
-
* const dispose = onChannelJoined((channel, member) => {
|
|
26286
|
-
* // ...
|
|
26287
|
-
* })
|
|
26288
|
-
* ```
|
|
26289
|
-
*
|
|
26290
|
-
* Fired when any {@link Amity.Channel} was joined
|
|
26291
|
-
*
|
|
26292
|
-
* @param callback The function to call when the event was fired
|
|
26293
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26294
|
-
*
|
|
26295
|
-
* @category Channel Events
|
|
26296
|
-
*/
|
|
26297
|
-
const onChannelJoined = (callback) => {
|
|
26298
|
-
const client = getActiveClient();
|
|
26299
|
-
const filter = (payload) => {
|
|
26300
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26301
|
-
const { channels, channelUsers } = preparedPayload;
|
|
26302
|
-
ingestInCache(preparedPayload);
|
|
26303
|
-
callback(channels[0], channelUsers[0]);
|
|
26304
|
-
};
|
|
26305
|
-
return createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
26306
|
-
};
|
|
26307
|
-
|
|
26308
|
-
/**
|
|
26309
|
-
* ```js
|
|
26310
|
-
* import { onChannelLeft } from '@amityco/ts-sdk'
|
|
26311
|
-
* const dispose = onChannelLeft((channel, member) => {
|
|
26312
|
-
* // ...
|
|
26313
|
-
* })
|
|
26314
|
-
* ```
|
|
26315
|
-
*
|
|
26316
|
-
* Fired when any {@link Amity.Channel} was left
|
|
26317
|
-
*
|
|
26318
|
-
* @param callback The function to call when the event was fired
|
|
26319
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26320
|
-
*
|
|
26321
|
-
* @category Channel Events
|
|
26322
|
-
*/
|
|
26323
|
-
const onChannelLeft = (callback) => {
|
|
26324
|
-
const client = getActiveClient();
|
|
26325
|
-
const filter = (payload) => {
|
|
26326
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26327
|
-
const { channels, channelUsers } = preparedPayload;
|
|
26328
|
-
ingestInCache(preparedPayload);
|
|
26329
|
-
callback(channels[0], channelUsers[0]);
|
|
26330
|
-
};
|
|
26331
|
-
return createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
26332
|
-
};
|
|
26333
|
-
|
|
26334
|
-
/**
|
|
26335
|
-
* ```js
|
|
26336
|
-
* import { onChannelMuted } from '@amityco/ts-sdk'
|
|
26337
|
-
* const dispose = onChannelMuted(channel => {
|
|
26338
|
-
* // ...
|
|
26339
|
-
* })
|
|
26340
|
-
* ```
|
|
26341
|
-
*
|
|
26342
|
-
* Fired when any {@link Amity.Channel} have been muted
|
|
27271
|
+
* Fired when any {@link Amity.Channel} have been created
|
|
26343
27272
|
*
|
|
26344
27273
|
* @param callback The function to call when the event was fired
|
|
26345
27274
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26346
27275
|
*
|
|
26347
27276
|
* @category Channel Events
|
|
26348
27277
|
*/
|
|
26349
|
-
const
|
|
27278
|
+
const onChannelCreated = (callback) => {
|
|
26350
27279
|
const client = getActiveClient();
|
|
26351
|
-
const filter = (payload) => {
|
|
26352
|
-
const data = prepareChannelPayload(payload);
|
|
27280
|
+
const filter = async (payload) => {
|
|
27281
|
+
const data = await prepareChannelPayload(payload);
|
|
26353
27282
|
ingestInCache(data);
|
|
26354
27283
|
callback(data.channels[0]);
|
|
26355
27284
|
};
|
|
26356
|
-
return createEventSubscriber(client, '
|
|
27285
|
+
return createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
26357
27286
|
};
|
|
26358
27287
|
|
|
26359
27288
|
/**
|
|
26360
27289
|
* ```js
|
|
26361
|
-
* import {
|
|
26362
|
-
* const dispose =
|
|
27290
|
+
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
27291
|
+
* const dispose = onChannelUpdated(channel => {
|
|
26363
27292
|
* // ...
|
|
26364
27293
|
* })
|
|
26365
27294
|
* ```
|
|
26366
27295
|
*
|
|
26367
|
-
* Fired when any {@link Amity.
|
|
27296
|
+
* Fired when any {@link Amity.Channel} have been updated
|
|
26368
27297
|
*
|
|
26369
27298
|
* @param callback The function to call when the event was fired
|
|
26370
27299
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26371
27300
|
*
|
|
26372
27301
|
* @category Channel Events
|
|
26373
27302
|
*/
|
|
26374
|
-
const
|
|
27303
|
+
const onChannelUpdated = (callback) => {
|
|
26375
27304
|
const client = getActiveClient();
|
|
26376
|
-
const filter = (payload) => {
|
|
26377
|
-
const
|
|
26378
|
-
|
|
26379
|
-
|
|
26380
|
-
|
|
27305
|
+
const filter = async (payload) => {
|
|
27306
|
+
const data = await prepareChannelPayload(payload);
|
|
27307
|
+
ingestInCache(data);
|
|
27308
|
+
callback(data.channels[0]);
|
|
27309
|
+
};
|
|
27310
|
+
const channelMarkerChangeHandler = async (rawPayload) => {
|
|
27311
|
+
var _a;
|
|
27312
|
+
const marker = rawPayload.userEntityMarkers[0];
|
|
27313
|
+
const cacheKey = ['channel', 'get', marker.entityId];
|
|
27314
|
+
const channel = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27315
|
+
if (!channel)
|
|
27316
|
+
return;
|
|
27317
|
+
const updated = updateChannelMarker(channel, marker);
|
|
27318
|
+
upsertInCache(cacheKey, updated);
|
|
27319
|
+
callback(updated);
|
|
27320
|
+
};
|
|
27321
|
+
const disposers = [
|
|
27322
|
+
createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter),
|
|
27323
|
+
createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callback(payload.channels[0])),
|
|
27324
|
+
createEventSubscriber(client, 'onChannelUpdated', 'local.channelMarker.fetched', channelMarkerChangeHandler),
|
|
27325
|
+
];
|
|
27326
|
+
return () => {
|
|
27327
|
+
disposers.forEach(fn => fn());
|
|
26381
27328
|
};
|
|
26382
|
-
return createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
26383
27329
|
};
|
|
26384
27330
|
|
|
26385
27331
|
/**
|
|
26386
27332
|
* ```js
|
|
26387
|
-
* import {
|
|
26388
|
-
* const dispose =
|
|
27333
|
+
* import { onChannelDeleted } from '@amityco/ts-sdk'
|
|
27334
|
+
* const dispose = onChannelDeleted(channel => {
|
|
26389
27335
|
* // ...
|
|
26390
27336
|
* })
|
|
26391
27337
|
* ```
|
|
26392
27338
|
*
|
|
26393
|
-
* Fired when any {@link Amity.
|
|
27339
|
+
* Fired when any {@link Amity.Channel} have been deleted
|
|
26394
27340
|
*
|
|
26395
27341
|
* @param callback The function to call when the event was fired
|
|
26396
27342
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26397
27343
|
*
|
|
26398
27344
|
* @category Channel Events
|
|
26399
27345
|
*/
|
|
26400
|
-
const
|
|
27346
|
+
const onChannelDeleted = (callback) => {
|
|
26401
27347
|
const client = getActiveClient();
|
|
26402
|
-
const filter = (payload) => {
|
|
26403
|
-
const
|
|
26404
|
-
|
|
26405
|
-
|
|
26406
|
-
callback(channels[0], channelUsers[0]);
|
|
27348
|
+
const filter = async (payload) => {
|
|
27349
|
+
const data = await prepareChannelPayload(payload);
|
|
27350
|
+
ingestInCache(data);
|
|
27351
|
+
callback(data.channels[0]);
|
|
26407
27352
|
};
|
|
26408
|
-
return createEventSubscriber(client, '
|
|
27353
|
+
return createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
26409
27354
|
};
|
|
26410
27355
|
|
|
26411
27356
|
/**
|
|
26412
27357
|
* ```js
|
|
26413
|
-
* import {
|
|
26414
|
-
* const dispose =
|
|
27358
|
+
* import { onChannelJoined } from '@amityco/ts-sdk'
|
|
27359
|
+
* const dispose = onChannelJoined((channel, member) => {
|
|
26415
27360
|
* // ...
|
|
26416
27361
|
* })
|
|
26417
27362
|
* ```
|
|
26418
27363
|
*
|
|
26419
|
-
* Fired when any {@link Amity.
|
|
27364
|
+
* Fired when any {@link Amity.Channel} was joined
|
|
26420
27365
|
*
|
|
26421
27366
|
* @param callback The function to call when the event was fired
|
|
26422
27367
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26423
27368
|
*
|
|
26424
27369
|
* @category Channel Events
|
|
26425
27370
|
*/
|
|
26426
|
-
const
|
|
27371
|
+
const onChannelJoined = (callback) => {
|
|
26427
27372
|
const client = getActiveClient();
|
|
26428
|
-
const filter = (payload) => {
|
|
26429
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27373
|
+
const filter = async (payload) => {
|
|
27374
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26430
27375
|
const { channels, channelUsers } = preparedPayload;
|
|
26431
27376
|
ingestInCache(preparedPayload);
|
|
26432
|
-
callback(channels[0], channelUsers
|
|
27377
|
+
callback(channels[0], channelUsers[0]);
|
|
26433
27378
|
};
|
|
26434
|
-
return createEventSubscriber(client, '
|
|
27379
|
+
return createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
26435
27380
|
};
|
|
26436
27381
|
|
|
26437
27382
|
/**
|
|
26438
27383
|
* ```js
|
|
26439
|
-
* import {
|
|
26440
|
-
* const dispose =
|
|
27384
|
+
* import { onChannelLeft } from '@amityco/ts-sdk'
|
|
27385
|
+
* const dispose = onChannelLeft((channel, member) => {
|
|
26441
27386
|
* // ...
|
|
26442
27387
|
* })
|
|
26443
27388
|
* ```
|
|
26444
27389
|
*
|
|
26445
|
-
* Fired when any {@link Amity.
|
|
27390
|
+
* Fired when any {@link Amity.Channel} was left
|
|
26446
27391
|
*
|
|
26447
27392
|
* @param callback The function to call when the event was fired
|
|
26448
27393
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26449
27394
|
*
|
|
26450
27395
|
* @category Channel Events
|
|
26451
27396
|
*/
|
|
26452
|
-
const
|
|
27397
|
+
const onChannelLeft = (callback) => {
|
|
26453
27398
|
const client = getActiveClient();
|
|
26454
|
-
const filter = (payload) => {
|
|
26455
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27399
|
+
const filter = async (payload) => {
|
|
27400
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26456
27401
|
const { channels, channelUsers } = preparedPayload;
|
|
26457
27402
|
ingestInCache(preparedPayload);
|
|
26458
|
-
callback(channels[0], channelUsers
|
|
26459
|
-
};
|
|
26460
|
-
return createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
26461
|
-
};
|
|
26462
|
-
|
|
26463
|
-
/**
|
|
26464
|
-
* ```js
|
|
26465
|
-
* import { observeChannel } from '@amityco/ts-sdk'
|
|
26466
|
-
*
|
|
26467
|
-
* let channel = {}
|
|
26468
|
-
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
26469
|
-
* ```
|
|
26470
|
-
*
|
|
26471
|
-
* Observe all mutation on a given {@link Amity.Channel}
|
|
26472
|
-
*
|
|
26473
|
-
* @param channelId the ID of the channel to observe
|
|
26474
|
-
* @param callback the function to call when new data are available
|
|
26475
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
26476
|
-
*
|
|
26477
|
-
* @category Channel Observer
|
|
26478
|
-
*/
|
|
26479
|
-
const observeChannel = (channelId, callback) => {
|
|
26480
|
-
const { log } = getActiveClient();
|
|
26481
|
-
const timestamp = Date.now();
|
|
26482
|
-
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
26483
|
-
// wrapper function to make sure
|
|
26484
|
-
const router = (result, action) => {
|
|
26485
|
-
var _a, _b, _c;
|
|
26486
|
-
// filter function
|
|
26487
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
26488
|
-
return;
|
|
26489
|
-
if (callback instanceof Function)
|
|
26490
|
-
return callback(result);
|
|
26491
|
-
if (action !== 'onFetch')
|
|
26492
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
26493
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
26494
|
-
};
|
|
26495
|
-
const disposers = [];
|
|
26496
|
-
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, 'onMute')), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')));
|
|
26497
|
-
runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
|
|
26498
|
-
return () => {
|
|
26499
|
-
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
26500
|
-
disposers.forEach(fn => fn());
|
|
26501
|
-
};
|
|
26502
|
-
};
|
|
26503
|
-
|
|
26504
|
-
/**
|
|
26505
|
-
* ```js
|
|
26506
|
-
* import { observeChannels } from '@amityco/ts-sdk'
|
|
26507
|
-
*
|
|
26508
|
-
* let channels = []
|
|
26509
|
-
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
26510
|
-
* ```
|
|
26511
|
-
*
|
|
26512
|
-
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
26513
|
-
*
|
|
26514
|
-
* @param callback the function to call when new data are available
|
|
26515
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
26516
|
-
*
|
|
26517
|
-
* @category Channel Observer
|
|
26518
|
-
*/
|
|
26519
|
-
const observeChannels = (callback) => {
|
|
26520
|
-
const { log } = getActiveClient();
|
|
26521
|
-
const timestamp = Date.now();
|
|
26522
|
-
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
26523
|
-
const disposers = [];
|
|
26524
|
-
const router = (channel, action) => {
|
|
26525
|
-
var _a, _b;
|
|
26526
|
-
if (callback instanceof Function)
|
|
26527
|
-
return callback(channel);
|
|
26528
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
26529
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
26530
|
-
};
|
|
26531
|
-
disposers.push(onChannelCreated(data => router(data, 'onCreate')), onChannelUpdated(data => router(data, 'onUpdate')), onChannelDeleted(data => router(data, 'onDelete')), onChannelJoined(data => router(data, 'onJoin')), onChannelLeft(data => router(data, 'onLeft')), onChannelMuted(data => router(data, 'onMute')), onChannelMemberAdded(data => router(data, 'onMemberAdded')), onChannelMemberRemoved(data => router(data, 'onMemberRemoved')));
|
|
26532
|
-
return () => {
|
|
26533
|
-
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
26534
|
-
disposers.forEach(fn => fn());
|
|
26535
|
-
};
|
|
26536
|
-
};
|
|
26537
|
-
|
|
26538
|
-
function hasMention(model, userId) {
|
|
26539
|
-
var _a, _b;
|
|
26540
|
-
const channelMention = (_a = model === null || model === void 0 ? void 0 : model.mentionees) === null || _a === void 0 ? void 0 : _a.find(x => x.type === 'channel');
|
|
26541
|
-
if (channelMention) {
|
|
26542
|
-
return true;
|
|
26543
|
-
}
|
|
26544
|
-
const userMention = (_b = model === null || model === void 0 ? void 0 : model.mentionees) === null || _b === void 0 ? void 0 : _b.find(x => x.type === 'user');
|
|
26545
|
-
if (userMention) {
|
|
26546
|
-
return userMention.userIds.includes(userId);
|
|
26547
|
-
}
|
|
26548
|
-
return false;
|
|
26549
|
-
}
|
|
26550
|
-
function isCollectionOutdated(collection, newItem, action) {
|
|
26551
|
-
const key = identifyModelKey(newItem);
|
|
26552
|
-
// @ts-ignore
|
|
26553
|
-
const item = collection.find(x => x[key] === newItem[key]);
|
|
26554
|
-
if (item) {
|
|
26555
|
-
return hasUpdates(item, newItem);
|
|
26556
|
-
}
|
|
26557
|
-
return action === 'onCreate';
|
|
26558
|
-
}
|
|
26559
|
-
function merge(collection1, collection2) {
|
|
26560
|
-
const temp = [...collection1, ...collection2];
|
|
26561
|
-
if (temp.length === 0) {
|
|
26562
|
-
return [];
|
|
26563
|
-
}
|
|
26564
|
-
const key = identifyModelKey(temp[0]);
|
|
26565
|
-
const map = new Map();
|
|
26566
|
-
// @ts-ignore
|
|
26567
|
-
temp.forEach(x => map.set(x[key], x));
|
|
26568
|
-
return Array.from(map.values());
|
|
26569
|
-
}
|
|
26570
|
-
|
|
26571
|
-
/**
|
|
26572
|
-
* ```js
|
|
26573
|
-
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
26574
|
-
* const dispose = onMessageCreated(message => {
|
|
26575
|
-
* // ...
|
|
26576
|
-
* })
|
|
26577
|
-
* ```
|
|
26578
|
-
*
|
|
26579
|
-
* Fired when an {@link Amity.Message} has been created
|
|
26580
|
-
*
|
|
26581
|
-
* @param callback The function to call when the event was fired
|
|
26582
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26583
|
-
*
|
|
26584
|
-
* @category Message Events
|
|
26585
|
-
*/
|
|
26586
|
-
const onMessageCreated = (callback) => {
|
|
26587
|
-
const client = getActiveClient();
|
|
26588
|
-
const filter = (rawPayload) => {
|
|
26589
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26590
|
-
const message = payload.messages[0];
|
|
26591
|
-
const cached = pullFromCache(['channel', 'get', message.channelId]);
|
|
26592
|
-
if (cached && cached.data.defaultSubChannelId === message.subChannelId) {
|
|
26593
|
-
let update;
|
|
26594
|
-
// @ts-ignore
|
|
26595
|
-
if (cached.data.localReading) {
|
|
26596
|
-
update = Object.assign(Object.assign({}, cached.data), { localReadToSegment: message.channelSegment, localLastMentionSegment: hasMention(message, client.userId)
|
|
26597
|
-
? message.channelSegment
|
|
26598
|
-
: cached.data.localLastMentionSegment, messageCount: message.channelSegment, lastActivity: message.createdAt, updatedAt: message.createdAt });
|
|
26599
|
-
}
|
|
26600
|
-
else {
|
|
26601
|
-
update = Object.assign(Object.assign({}, cached.data), { defaultSubChannelHasUnreadMention: hasMention(message, client.userId) || cached.data.defaultSubChannelHasUnreadMention, defaultSubChannelUnreadCount: message.channelSegment - cached.data.localReadToSegment, lastActivity: message.createdAt, messageCount: message.channelSegment, updatedAt: message.createdAt });
|
|
26602
|
-
}
|
|
26603
|
-
pushToCache(['channel', 'get', message.channelId], update);
|
|
26604
|
-
client.emitter.emit('local.channel.updated', { channels: [update] });
|
|
26605
|
-
}
|
|
26606
|
-
ingestInCache(payload);
|
|
26607
|
-
callback(message);
|
|
26608
|
-
};
|
|
26609
|
-
const disposers = [
|
|
26610
|
-
createEventSubscriber(client, 'message/onMessageCreated', 'message.created', filter),
|
|
26611
|
-
createEventSubscriber(client, 'local.message.created', 'local.message.created', payload => callback(payload.messages[0])),
|
|
26612
|
-
];
|
|
26613
|
-
return () => {
|
|
26614
|
-
disposers.forEach(fn => fn());
|
|
27403
|
+
callback(channels[0], channelUsers[0]);
|
|
26615
27404
|
};
|
|
27405
|
+
return createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
26616
27406
|
};
|
|
26617
27407
|
|
|
26618
27408
|
/**
|
|
26619
27409
|
* ```js
|
|
26620
|
-
* import {
|
|
26621
|
-
* const dispose =
|
|
27410
|
+
* import { onChannelMuted } from '@amityco/ts-sdk'
|
|
27411
|
+
* const dispose = onChannelMuted(channel => {
|
|
26622
27412
|
* // ...
|
|
26623
27413
|
* })
|
|
26624
27414
|
* ```
|
|
26625
27415
|
*
|
|
26626
|
-
* Fired when
|
|
27416
|
+
* Fired when any {@link Amity.Channel} have been muted
|
|
26627
27417
|
*
|
|
26628
27418
|
* @param callback The function to call when the event was fired
|
|
26629
27419
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26630
27420
|
*
|
|
26631
|
-
* @category
|
|
27421
|
+
* @category Channel Events
|
|
26632
27422
|
*/
|
|
26633
|
-
const
|
|
27423
|
+
const onChannelMuted = (callback) => {
|
|
26634
27424
|
const client = getActiveClient();
|
|
26635
|
-
const filter = (
|
|
26636
|
-
const
|
|
26637
|
-
ingestInCache(
|
|
26638
|
-
callback(
|
|
26639
|
-
};
|
|
26640
|
-
const disposers = [
|
|
26641
|
-
createEventSubscriber(client, 'message/onMessageUpdated', 'message.updated', filter),
|
|
26642
|
-
createEventSubscriber(client, 'local.message.updated', 'local.message.updated', payload => callback(payload.messages[0])),
|
|
26643
|
-
];
|
|
26644
|
-
return () => {
|
|
26645
|
-
disposers.forEach(fn => fn());
|
|
27425
|
+
const filter = async (payload) => {
|
|
27426
|
+
const data = await prepareChannelPayload(payload);
|
|
27427
|
+
ingestInCache(data);
|
|
27428
|
+
callback(data.channels[0]);
|
|
26646
27429
|
};
|
|
27430
|
+
return createEventSubscriber(client, 'onChannelMuted', 'channel.setMuted', filter);
|
|
26647
27431
|
};
|
|
26648
27432
|
|
|
26649
27433
|
/**
|
|
26650
27434
|
* ```js
|
|
26651
|
-
* import {
|
|
26652
|
-
* const dispose =
|
|
27435
|
+
* import { onChannelMemberAdded } from '@amityco/ts-sdk'
|
|
27436
|
+
* const dispose = onChannelMemberAdded((channel, member) => {
|
|
26653
27437
|
* // ...
|
|
26654
27438
|
* })
|
|
26655
27439
|
* ```
|
|
26656
27440
|
*
|
|
26657
|
-
* Fired when
|
|
27441
|
+
* Fired when any {@link Amity.User} has been added to any {@link Amity.Channel}
|
|
26658
27442
|
*
|
|
26659
27443
|
* @param callback The function to call when the event was fired
|
|
26660
27444
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26661
27445
|
*
|
|
26662
|
-
* @category
|
|
27446
|
+
* @category Channel Events
|
|
26663
27447
|
*/
|
|
26664
|
-
const
|
|
27448
|
+
const onChannelMemberAdded = (callback) => {
|
|
26665
27449
|
const client = getActiveClient();
|
|
26666
|
-
const filter = (
|
|
26667
|
-
const
|
|
26668
|
-
|
|
26669
|
-
|
|
26670
|
-
|
|
26671
|
-
const disposers = [
|
|
26672
|
-
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
26673
|
-
createEventSubscriber(client, 'local.message.deleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
26674
|
-
];
|
|
26675
|
-
return () => {
|
|
26676
|
-
disposers.forEach(fn => fn());
|
|
27450
|
+
const filter = async (payload) => {
|
|
27451
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
27452
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27453
|
+
ingestInCache(preparedPayload);
|
|
27454
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'member'));
|
|
26677
27455
|
};
|
|
27456
|
+
return createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
26678
27457
|
};
|
|
26679
27458
|
|
|
26680
27459
|
/**
|
|
26681
27460
|
* ```js
|
|
26682
|
-
* import {
|
|
26683
|
-
* const dispose =
|
|
27461
|
+
* import { onChannelMemberRemoved } from '@amityco/ts-sdk'
|
|
27462
|
+
* const dispose = onChannelMemberRemoved((channel, member) => {
|
|
26684
27463
|
* // ...
|
|
26685
27464
|
* })
|
|
26686
27465
|
* ```
|
|
26687
27466
|
*
|
|
26688
|
-
* Fired when
|
|
27467
|
+
* Fired when any {@link Amity.User} has been removed from any {@link Amity.Channel}
|
|
26689
27468
|
*
|
|
26690
27469
|
* @param callback The function to call when the event was fired
|
|
26691
27470
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26692
27471
|
*
|
|
26693
|
-
* @category
|
|
27472
|
+
* @category Channel Events
|
|
26694
27473
|
*/
|
|
26695
|
-
const
|
|
27474
|
+
const onChannelMemberRemoved = (callback) => {
|
|
26696
27475
|
const client = getActiveClient();
|
|
26697
|
-
const filter = (
|
|
26698
|
-
const
|
|
26699
|
-
|
|
26700
|
-
|
|
27476
|
+
const filter = async (payload) => {
|
|
27477
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
27478
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27479
|
+
ingestInCache(preparedPayload);
|
|
27480
|
+
callback(channels[0], channelUsers[0]);
|
|
26701
27481
|
};
|
|
26702
|
-
return createEventSubscriber(client, '
|
|
27482
|
+
return createEventSubscriber(client, 'onChannelMemberRemoved', 'channel.membersRemoved', filter);
|
|
26703
27483
|
};
|
|
26704
27484
|
|
|
26705
27485
|
/**
|
|
26706
27486
|
* ```js
|
|
26707
|
-
* import {
|
|
26708
|
-
* const dispose =
|
|
27487
|
+
* import { onChannelMemberBanned } from '@amityco/ts-sdk'
|
|
27488
|
+
* const dispose = onChannelMemberBanned((channel, member) => {
|
|
26709
27489
|
* // ...
|
|
26710
27490
|
* })
|
|
26711
27491
|
* ```
|
|
26712
27492
|
*
|
|
26713
|
-
* Fired when
|
|
27493
|
+
* Fired when any {@link Amity.User} has been banned from any {@link Amity.Channel}
|
|
26714
27494
|
*
|
|
26715
27495
|
* @param callback The function to call when the event was fired
|
|
26716
27496
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26717
27497
|
*
|
|
26718
|
-
* @category
|
|
27498
|
+
* @category Channel Events
|
|
26719
27499
|
*/
|
|
26720
|
-
const
|
|
27500
|
+
const onChannelMemberBanned = (callback) => {
|
|
26721
27501
|
const client = getActiveClient();
|
|
26722
|
-
const filter = (
|
|
26723
|
-
const
|
|
26724
|
-
|
|
26725
|
-
|
|
27502
|
+
const filter = async (payload) => {
|
|
27503
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
27504
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27505
|
+
ingestInCache(preparedPayload);
|
|
27506
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'banned'));
|
|
26726
27507
|
};
|
|
26727
|
-
return createEventSubscriber(client, '
|
|
27508
|
+
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
26728
27509
|
};
|
|
26729
27510
|
|
|
26730
27511
|
/**
|
|
26731
27512
|
* ```js
|
|
26732
|
-
* import {
|
|
26733
|
-
* const dispose =
|
|
27513
|
+
* import { onChannelMemberUnbanned } from '@amityco/ts-sdk'
|
|
27514
|
+
* const dispose = onChannelMemberUnbanned((channel, member) => {
|
|
26734
27515
|
* // ...
|
|
26735
27516
|
* })
|
|
26736
27517
|
* ```
|
|
26737
27518
|
*
|
|
26738
|
-
* Fired when
|
|
27519
|
+
* Fired when any {@link Amity.User} has been unbanned from any {@link Amity.Channel}
|
|
26739
27520
|
*
|
|
26740
27521
|
* @param callback The function to call when the event was fired
|
|
26741
27522
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26742
27523
|
*
|
|
26743
|
-
* @category
|
|
27524
|
+
* @category Channel Events
|
|
26744
27525
|
*/
|
|
26745
|
-
const
|
|
27526
|
+
const onChannelMemberUnbanned = (callback) => {
|
|
26746
27527
|
const client = getActiveClient();
|
|
26747
|
-
const filter = (
|
|
26748
|
-
const
|
|
26749
|
-
|
|
26750
|
-
|
|
27528
|
+
const filter = async (payload) => {
|
|
27529
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
27530
|
+
const { channels, channelUsers } = preparedPayload;
|
|
27531
|
+
ingestInCache(preparedPayload);
|
|
27532
|
+
callback(channels[0], channelUsers.find(cu => cu.membership === 'none'));
|
|
26751
27533
|
};
|
|
26752
|
-
return createEventSubscriber(client, '
|
|
27534
|
+
return createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
26753
27535
|
};
|
|
26754
27536
|
|
|
26755
27537
|
/**
|
|
26756
27538
|
* ```js
|
|
26757
|
-
* import {
|
|
27539
|
+
* import { observeChannel } from '@amityco/ts-sdk'
|
|
26758
27540
|
*
|
|
26759
|
-
*
|
|
26760
|
-
*
|
|
26761
|
-
* });
|
|
27541
|
+
* let channel = {}
|
|
27542
|
+
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
26762
27543
|
* ```
|
|
26763
27544
|
*
|
|
26764
|
-
*
|
|
27545
|
+
* Observe all mutation on a given {@link Amity.Channel}
|
|
26765
27546
|
*
|
|
26766
|
-
* @param
|
|
26767
|
-
* @
|
|
27547
|
+
* @param channelId the ID of the channel to observe
|
|
27548
|
+
* @param callback the function to call when new data are available
|
|
27549
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
26768
27550
|
*
|
|
26769
|
-
* @category
|
|
27551
|
+
* @category Channel Observer
|
|
26770
27552
|
*/
|
|
26771
|
-
const
|
|
26772
|
-
const
|
|
26773
|
-
const
|
|
26774
|
-
|
|
26775
|
-
|
|
26776
|
-
|
|
27553
|
+
const observeChannel = (channelId, callback) => {
|
|
27554
|
+
const { log } = getActiveClient();
|
|
27555
|
+
const timestamp = Date.now();
|
|
27556
|
+
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
27557
|
+
// wrapper function to make sure
|
|
27558
|
+
const router = (result, action) => {
|
|
27559
|
+
var _a, _b, _c;
|
|
27560
|
+
// filter function
|
|
27561
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
27562
|
+
return;
|
|
27563
|
+
if (callback instanceof Function)
|
|
27564
|
+
return callback(result);
|
|
27565
|
+
if (action !== 'onFetch')
|
|
27566
|
+
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
27567
|
+
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
27568
|
+
};
|
|
27569
|
+
const disposers = [];
|
|
27570
|
+
disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, 'onJoin')), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, 'onLeft')), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, 'onMute')), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, 'onMemberAdded')), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, 'onMemberRemoved')));
|
|
27571
|
+
runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
|
|
27572
|
+
return () => {
|
|
27573
|
+
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
27574
|
+
disposers.forEach(fn => fn());
|
|
26777
27575
|
};
|
|
26778
|
-
return createEventSubscriber(client, 'onMessageReactionAdded', 'message.reactionAdded', filter);
|
|
26779
27576
|
};
|
|
26780
27577
|
|
|
26781
27578
|
/**
|
|
26782
27579
|
* ```js
|
|
26783
|
-
* import {
|
|
27580
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
26784
27581
|
*
|
|
26785
|
-
*
|
|
26786
|
-
*
|
|
26787
|
-
* });
|
|
27582
|
+
* let channels = []
|
|
27583
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
26788
27584
|
* ```
|
|
26789
27585
|
*
|
|
26790
|
-
*
|
|
27586
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
26791
27587
|
*
|
|
26792
|
-
* @param callback
|
|
26793
|
-
* @returns
|
|
27588
|
+
* @param callback the function to call when new data are available
|
|
27589
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
26794
27590
|
*
|
|
26795
|
-
* @category
|
|
27591
|
+
* @category Channel Observer
|
|
26796
27592
|
*/
|
|
26797
|
-
const
|
|
26798
|
-
const
|
|
26799
|
-
const
|
|
26800
|
-
|
|
26801
|
-
|
|
26802
|
-
|
|
27593
|
+
const observeChannels = (callback) => {
|
|
27594
|
+
const { log } = getActiveClient();
|
|
27595
|
+
const timestamp = Date.now();
|
|
27596
|
+
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
27597
|
+
const disposers = [];
|
|
27598
|
+
const router = (channel, action) => {
|
|
27599
|
+
var _a, _b;
|
|
27600
|
+
if (callback instanceof Function)
|
|
27601
|
+
return callback(channel);
|
|
27602
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
27603
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
27604
|
+
};
|
|
27605
|
+
disposers.push(onChannelCreated(data => router(data, 'onCreate')), onChannelUpdated(data => router(data, 'onUpdate')), onChannelDeleted(data => router(data, 'onDelete')), onChannelJoined(data => router(data, 'onJoin')), onChannelLeft(data => router(data, 'onLeft')), onChannelMuted(data => router(data, 'onMute')), onChannelMemberAdded(data => router(data, 'onMemberAdded')), onChannelMemberRemoved(data => router(data, 'onMemberRemoved')));
|
|
27606
|
+
return () => {
|
|
27607
|
+
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
27608
|
+
disposers.forEach(fn => fn());
|
|
26803
27609
|
};
|
|
26804
|
-
return createEventSubscriber(client, 'onMessageReactionRemoved', 'message.reactionRemoved', filter);
|
|
26805
27610
|
};
|
|
26806
27611
|
|
|
26807
27612
|
/**
|
|
@@ -27078,22 +27883,6 @@ const liveChannelMembers = (params, callback, config) => {
|
|
|
27078
27883
|
};
|
|
27079
27884
|
};
|
|
27080
27885
|
|
|
27081
|
-
function convertFromRaw(_a) {
|
|
27082
|
-
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"]);
|
|
27083
|
-
return Object.assign(Object.assign({}, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId });
|
|
27084
|
-
}
|
|
27085
|
-
const prepareSubChannelPayload = (payload) => {
|
|
27086
|
-
return Object.assign(Object.assign({}, payload), { messageFeeds: payload.messageFeeds.map(convertFromRaw) });
|
|
27087
|
-
};
|
|
27088
|
-
function convertQueryParams(_a) {
|
|
27089
|
-
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
27090
|
-
const out = Object.assign({}, rest);
|
|
27091
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
27092
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
27093
|
-
}
|
|
27094
|
-
return out;
|
|
27095
|
-
}
|
|
27096
|
-
|
|
27097
27886
|
/* begin_public_function
|
|
27098
27887
|
id: subchannel.query
|
|
27099
27888
|
*/
|
|
@@ -27121,7 +27910,7 @@ const querySubChannels = async (query) => {
|
|
|
27121
27910
|
} }),
|
|
27122
27911
|
});
|
|
27123
27912
|
const _b = response.data, { paging } = _b, payload = __rest(_b, ["paging"]);
|
|
27124
|
-
const data = prepareSubChannelPayload(payload);
|
|
27913
|
+
const data = await prepareSubChannelPayload(payload);
|
|
27125
27914
|
const subChannels = data.messageFeeds;
|
|
27126
27915
|
const cachedAt = client.cache && Date.now();
|
|
27127
27916
|
if (client.cache) {
|
|
@@ -27197,7 +27986,7 @@ const getSubChannels = async (subChannelIds) => {
|
|
|
27197
27986
|
const response = await client.http.get('/api/v5/message-feeds/list', {
|
|
27198
27987
|
params: { messageFeedIds: subChannelIds.map(encodeURIComponent) },
|
|
27199
27988
|
});
|
|
27200
|
-
const data = prepareSubChannelPayload(response.data);
|
|
27989
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27201
27990
|
const cachedAt = client.cache && Date.now();
|
|
27202
27991
|
if (client.cache)
|
|
27203
27992
|
ingestInCache(data, { cachedAt });
|
|
@@ -27262,7 +28051,7 @@ const getSubChannel = async (subChannelId) => {
|
|
|
27262
28051
|
isInTombstone('subChannel', subChannelId);
|
|
27263
28052
|
try {
|
|
27264
28053
|
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
27265
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28054
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27266
28055
|
const cachedAt = client.cache && Date.now();
|
|
27267
28056
|
if (client.cache)
|
|
27268
28057
|
ingestInCache(data, { cachedAt });
|
|
@@ -27331,7 +28120,7 @@ const createSubChannel = async (bundle) => {
|
|
|
27331
28120
|
channelId: bundle.channelId,
|
|
27332
28121
|
name: bundle.displayName,
|
|
27333
28122
|
});
|
|
27334
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28123
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27335
28124
|
const cachedAt = client.cache && Date.now();
|
|
27336
28125
|
if (client.cache)
|
|
27337
28126
|
ingestInCache(data, { cachedAt });
|
|
@@ -27365,7 +28154,7 @@ const updateSubChannel = async (subChannelId, patch) => {
|
|
|
27365
28154
|
const client = getActiveClient();
|
|
27366
28155
|
client.log('channel/updateSubChannel', subChannelId, patch);
|
|
27367
28156
|
const response = await client.http.put(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`, { name: patch.displayName });
|
|
27368
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28157
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27369
28158
|
const cachedAt = client.cache && Date.now();
|
|
27370
28159
|
if (client.cache)
|
|
27371
28160
|
ingestInCache(data, { cachedAt });
|
|
@@ -27413,87 +28202,6 @@ const deleteSubChannel = async (subChannelId, permanent = false) => {
|
|
|
27413
28202
|
};
|
|
27414
28203
|
/* end_public_function */
|
|
27415
28204
|
|
|
27416
|
-
/**
|
|
27417
|
-
* ```js
|
|
27418
|
-
* import { onChannelSubCreated } from '@amityco/ts-sdk'
|
|
27419
|
-
* const dispose = onSubChannelCreated(subChannel => {
|
|
27420
|
-
* // ...
|
|
27421
|
-
* })
|
|
27422
|
-
* ```
|
|
27423
|
-
*
|
|
27424
|
-
* Fired when any {@link Amity.SubChannel} have been created
|
|
27425
|
-
*
|
|
27426
|
-
* @param callback The function to call when the event was fired
|
|
27427
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27428
|
-
*
|
|
27429
|
-
* @category Channel Events
|
|
27430
|
-
*/
|
|
27431
|
-
const onSubChannelCreated = (callback) => {
|
|
27432
|
-
const client = getActiveClient();
|
|
27433
|
-
const filter = (rawPayload) => {
|
|
27434
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27435
|
-
ingestInCache(payload);
|
|
27436
|
-
callback(payload.messageFeeds[0]);
|
|
27437
|
-
};
|
|
27438
|
-
return createEventSubscriber(client, 'onSubChannelCreated', 'message-feed.created', filter);
|
|
27439
|
-
};
|
|
27440
|
-
|
|
27441
|
-
/**
|
|
27442
|
-
* ```js
|
|
27443
|
-
* import { onSubChannelUpdated } from '@amityco/ts-sdk'
|
|
27444
|
-
* const dispose = onSubChannelUpdated(subChannel => {
|
|
27445
|
-
* // ...
|
|
27446
|
-
* })
|
|
27447
|
-
* ```
|
|
27448
|
-
*
|
|
27449
|
-
* Fired when any {@link Amity.SubChannel} have been updated
|
|
27450
|
-
*
|
|
27451
|
-
* @param callback The function to call when the event was fired
|
|
27452
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27453
|
-
*
|
|
27454
|
-
* @category Channel Events
|
|
27455
|
-
*/
|
|
27456
|
-
const onSubChannelUpdated = (callback) => {
|
|
27457
|
-
const client = getActiveClient();
|
|
27458
|
-
const filter = (rawPayload) => {
|
|
27459
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27460
|
-
ingestInCache(payload);
|
|
27461
|
-
callback(payload.messageFeeds[0]);
|
|
27462
|
-
};
|
|
27463
|
-
return createEventSubscriber(client, 'onSubChannelUpdated', 'message-feed.updated', filter);
|
|
27464
|
-
};
|
|
27465
|
-
|
|
27466
|
-
/**
|
|
27467
|
-
* ```js
|
|
27468
|
-
* import { onSubChannelDeleted } from '@amityco/ts-sdk'
|
|
27469
|
-
* const dispose = onSubChannelDeleted(subChannel => {
|
|
27470
|
-
* // ...
|
|
27471
|
-
* })
|
|
27472
|
-
* ```
|
|
27473
|
-
*
|
|
27474
|
-
* Fired when any {@link Amity.SubChannel} have been deleted
|
|
27475
|
-
*
|
|
27476
|
-
* @param callback The function to call when the event was fired
|
|
27477
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27478
|
-
*
|
|
27479
|
-
* @category Channel Events
|
|
27480
|
-
*/
|
|
27481
|
-
const onSubChannelDeleted = (callback) => {
|
|
27482
|
-
const client = getActiveClient();
|
|
27483
|
-
const filter = (rawPayload) => {
|
|
27484
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27485
|
-
ingestInCache(payload);
|
|
27486
|
-
callback(payload.messageFeeds[0]);
|
|
27487
|
-
};
|
|
27488
|
-
const disposers = [
|
|
27489
|
-
createEventSubscriber(client, 'onSubChannelDeleted', 'message-feed.deleted', filter),
|
|
27490
|
-
createEventSubscriber(client, 'local.message-feed.deleted', 'local.message-feed.deleted', payload => callback(payload.messageFeeds[0])),
|
|
27491
|
-
];
|
|
27492
|
-
return () => {
|
|
27493
|
-
disposers.forEach(fn => fn());
|
|
27494
|
-
};
|
|
27495
|
-
};
|
|
27496
|
-
|
|
27497
28205
|
/** @hidden */
|
|
27498
28206
|
const onSubChannelFetched = (callback) => {
|
|
27499
28207
|
return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
|
|
@@ -27526,6 +28234,27 @@ const liveSubChannel = (subChannelId, callback) => {
|
|
|
27526
28234
|
]);
|
|
27527
28235
|
};
|
|
27528
28236
|
|
|
28237
|
+
function isCollectionOutdated(collection, newItem, action) {
|
|
28238
|
+
const key = identifyModelKey(newItem);
|
|
28239
|
+
// @ts-ignore
|
|
28240
|
+
const item = collection.find(x => x[key] === newItem[key]);
|
|
28241
|
+
if (item) {
|
|
28242
|
+
return hasUpdates(item, newItem);
|
|
28243
|
+
}
|
|
28244
|
+
return action === 'onCreate';
|
|
28245
|
+
}
|
|
28246
|
+
function merge(collection1, collection2) {
|
|
28247
|
+
const temp = [...collection1, ...collection2];
|
|
28248
|
+
if (temp.length === 0) {
|
|
28249
|
+
return [];
|
|
28250
|
+
}
|
|
28251
|
+
const key = identifyModelKey(temp[0]);
|
|
28252
|
+
const map = new Map();
|
|
28253
|
+
// @ts-ignore
|
|
28254
|
+
temp.forEach(x => map.set(x[key], x));
|
|
28255
|
+
return Array.from(map.values());
|
|
28256
|
+
}
|
|
28257
|
+
|
|
27529
28258
|
/**
|
|
27530
28259
|
* ```js
|
|
27531
28260
|
* import { liveSubChannels } from '@amityco/ts-sdk';
|
|
@@ -27610,30 +28339,6 @@ const liveSubChannels = (params, callback, config) => {
|
|
|
27610
28339
|
};
|
|
27611
28340
|
};
|
|
27612
28341
|
|
|
27613
|
-
/**
|
|
27614
|
-
* ```js
|
|
27615
|
-
* import { onMessageFetched } from '@amityco/ts-sdk'
|
|
27616
|
-
* const dispose = onMessageFetched(message => {
|
|
27617
|
-
* // ...
|
|
27618
|
-
* })
|
|
27619
|
-
* ```
|
|
27620
|
-
*
|
|
27621
|
-
* Fired when an {@link Amity.Message} has been fetched
|
|
27622
|
-
*
|
|
27623
|
-
* @param callback The function to call when the event was fired
|
|
27624
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27625
|
-
*
|
|
27626
|
-
* @category Message Events
|
|
27627
|
-
*/
|
|
27628
|
-
const onMessageFetched = (callback) => {
|
|
27629
|
-
const client = getActiveClient();
|
|
27630
|
-
const filter = (payload) => {
|
|
27631
|
-
ingestInCache(payload);
|
|
27632
|
-
callback(payload.messages[0]);
|
|
27633
|
-
};
|
|
27634
|
-
return createEventSubscriber(client, 'message/onMessageFetched', 'local.message.fetched', filter);
|
|
27635
|
-
};
|
|
27636
|
-
|
|
27637
28342
|
/**
|
|
27638
28343
|
* ```js
|
|
27639
28344
|
* import { liveMessage } from '@amityco/ts-sdk';
|
|
@@ -30638,6 +31343,7 @@ exports.CommunityPostSettings = CommunityPostSettings;
|
|
|
30638
31343
|
exports.ContentFeedType = ContentFeedType;
|
|
30639
31344
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
30640
31345
|
exports.FileType = FileType;
|
|
31346
|
+
exports.MARKER_INCLUDED_SUB_CHANNEL_TYPE = MARKER_INCLUDED_SUB_CHANNEL_TYPE;
|
|
30641
31347
|
exports.MessageContentType = MessageContentType;
|
|
30642
31348
|
exports.PostContentType = PostContentType;
|
|
30643
31349
|
exports.VERSION = VERSION;
|
|
@@ -30655,6 +31361,8 @@ exports.backupCache = backupCache;
|
|
|
30655
31361
|
exports.banChannelMembers = banChannelMembers;
|
|
30656
31362
|
exports.closePoll = closePoll;
|
|
30657
31363
|
exports.connectClient = connectClient;
|
|
31364
|
+
exports.convertFromRaw = convertFromRaw$1;
|
|
31365
|
+
exports.convertQueryParams = convertQueryParams;
|
|
30658
31366
|
exports.createChannel = createChannel;
|
|
30659
31367
|
exports.createClient = createClient;
|
|
30660
31368
|
exports.createComment = createComment;
|
|
@@ -30694,8 +31402,10 @@ exports.filterByPropEquality = filterByPropEquality;
|
|
|
30694
31402
|
exports.filterByPropInclusion = filterByPropInclusion;
|
|
30695
31403
|
exports.follow = follow;
|
|
30696
31404
|
exports.getActiveClient = getActiveClient;
|
|
31405
|
+
exports.getActiveUser = getActiveUser;
|
|
30697
31406
|
exports.getCategory = getCategory;
|
|
30698
31407
|
exports.getChannel = getChannel;
|
|
31408
|
+
exports.getChannelMarkers = getChannelMarkers;
|
|
30699
31409
|
exports.getChannelTopic = getChannelTopic;
|
|
30700
31410
|
exports.getChannels = getChannels;
|
|
30701
31411
|
exports.getComment = getComment;
|
|
@@ -30707,7 +31417,9 @@ exports.getCommunityTopic = getCommunityTopic;
|
|
|
30707
31417
|
exports.getFeedSettings = getFeedSettings;
|
|
30708
31418
|
exports.getFile = getFile;
|
|
30709
31419
|
exports.getFollowInfo = getFollowInfo;
|
|
31420
|
+
exports.getMarkerSyncEvents = getMarkerSyncEvents;
|
|
30710
31421
|
exports.getMessage = getMessage;
|
|
31422
|
+
exports.getMessageMarkers = getMessageMarkers;
|
|
30711
31423
|
exports.getMessageTopic = getMessageTopic;
|
|
30712
31424
|
exports.getMessages = getMessages;
|
|
30713
31425
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
@@ -30724,10 +31436,14 @@ exports.getSmartFeedMessageTopic = getSmartFeedMessageTopic;
|
|
|
30724
31436
|
exports.getSmartFeedSubChannelTopic = getSmartFeedSubChannelTopic;
|
|
30725
31437
|
exports.getStream = getStream;
|
|
30726
31438
|
exports.getSubChannel = getSubChannel;
|
|
31439
|
+
exports.getSubChannelMarkers = getSubChannelMarkers;
|
|
30727
31440
|
exports.getSubChannelTopic = getSubChannelTopic;
|
|
30728
31441
|
exports.getSubChannels = getSubChannels;
|
|
30729
31442
|
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
31443
|
+
exports.getTotalUnreadCount = getTotalUnreadCount;
|
|
31444
|
+
exports.getUnreadCount = getUnreadCount$1;
|
|
30730
31445
|
exports.getUser = getUser;
|
|
31446
|
+
exports.getUserMarker = getUserMarker;
|
|
30731
31447
|
exports.getUserTopic = getUserTopic;
|
|
30732
31448
|
exports.getUsers = getUsers;
|
|
30733
31449
|
exports.isAfterBefore = isAfterBefore;
|
|
@@ -30742,6 +31458,7 @@ exports.isOffline = isOffline;
|
|
|
30742
31458
|
exports.isPaged = isPaged;
|
|
30743
31459
|
exports.isReportedByMe = isReportedByMe;
|
|
30744
31460
|
exports.isSkip = isSkip;
|
|
31461
|
+
exports.isUnreadCountSupport = isUnreadCountSupport$1;
|
|
30745
31462
|
exports.joinChannel = joinChannel;
|
|
30746
31463
|
exports.joinCommunity = joinCommunity;
|
|
30747
31464
|
exports.leaveChannel = leaveChannel;
|
|
@@ -30767,6 +31484,9 @@ exports.liveSubChannel = liveSubChannel;
|
|
|
30767
31484
|
exports.liveSubChannels = liveSubChannels;
|
|
30768
31485
|
exports.liveUser = liveUser;
|
|
30769
31486
|
exports.liveUsers = liveUsers;
|
|
31487
|
+
exports.markAsDelivered = markAsDelivered;
|
|
31488
|
+
exports.markerSync = markerSync;
|
|
31489
|
+
exports.markerSyncTrigger = markerSyncTrigger;
|
|
30770
31490
|
exports.mergeInCache = mergeInCache;
|
|
30771
31491
|
exports.observeChannel = observeChannel;
|
|
30772
31492
|
exports.observeChannels = observeChannels;
|
|
@@ -30787,6 +31507,7 @@ exports.onChannelCreated = onChannelCreated;
|
|
|
30787
31507
|
exports.onChannelDeleted = onChannelDeleted;
|
|
30788
31508
|
exports.onChannelJoined = onChannelJoined;
|
|
30789
31509
|
exports.onChannelLeft = onChannelLeft;
|
|
31510
|
+
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
30790
31511
|
exports.onChannelMemberAdded = onChannelMemberAdded;
|
|
30791
31512
|
exports.onChannelMemberBanned = onChannelMemberBanned;
|
|
30792
31513
|
exports.onChannelMemberRemoved = onChannelMemberRemoved;
|
|
@@ -30815,6 +31536,7 @@ exports.onCommunityUserRoleAdded = onCommunityUserRoleAdded;
|
|
|
30815
31536
|
exports.onCommunityUserRoleRemoved = onCommunityUserRoleRemoved;
|
|
30816
31537
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
30817
31538
|
exports.onConnectionError = onConnectionError;
|
|
31539
|
+
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
30818
31540
|
exports.onFollowInfoUpdated = onFollowInfoUpdated;
|
|
30819
31541
|
exports.onFollowRequestAccepted = onFollowRequestAccepted;
|
|
30820
31542
|
exports.onFollowRequestCanceled = onFollowRequestCanceled;
|
|
@@ -30823,8 +31545,10 @@ exports.onFollowerDeleted = onFollowerDeleted;
|
|
|
30823
31545
|
exports.onFollowerRequested = onFollowerRequested;
|
|
30824
31546
|
exports.onMessageCreated = onMessageCreated;
|
|
30825
31547
|
exports.onMessageDeleted = onMessageDeleted;
|
|
31548
|
+
exports.onMessageFetched = onMessageFetched;
|
|
30826
31549
|
exports.onMessageFlagCleared = onMessageFlagCleared;
|
|
30827
31550
|
exports.onMessageFlagged = onMessageFlagged;
|
|
31551
|
+
exports.onMessageMarkerFetched = onMessageMarkerFetched;
|
|
30828
31552
|
exports.onMessageReactionAdded = onMessageReactionAdded;
|
|
30829
31553
|
exports.onMessageReactionRemoved = onMessageReactionRemoved;
|
|
30830
31554
|
exports.onMessageUnflagged = onMessageUnflagged;
|
|
@@ -30850,15 +31574,20 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
30850
31574
|
exports.onStreamStopped = onStreamStopped;
|
|
30851
31575
|
exports.onSubChannelCreated = onSubChannelCreated;
|
|
30852
31576
|
exports.onSubChannelDeleted = onSubChannelDeleted;
|
|
31577
|
+
exports.onSubChannelMarkerFetched = onSubChannelMarkerFetched;
|
|
31578
|
+
exports.onSubChannelMarkerUpdated = onSubChannelMarkerUpdated;
|
|
30853
31579
|
exports.onSubChannelUpdated = onSubChannelUpdated;
|
|
30854
31580
|
exports.onUserDeleted = onUserDeleted;
|
|
30855
31581
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
30856
31582
|
exports.onUserFlagged = onUserFlagged;
|
|
30857
31583
|
exports.onUserFollowed = onUserFollowed;
|
|
31584
|
+
exports.onUserMarkerFetched = onUserMarkerFetched;
|
|
30858
31585
|
exports.onUserUnflagged = onUserUnflagged;
|
|
30859
31586
|
exports.onUserUnfollowed = onUserUnfollowed;
|
|
30860
31587
|
exports.onUserUpdated = onUserUpdated;
|
|
31588
|
+
exports.prepareSubChannelPayload = prepareSubChannelPayload;
|
|
30861
31589
|
exports.pullFromCache = pullFromCache;
|
|
31590
|
+
exports.pushMarkerSyncEvent = pushMarkerSyncEvent;
|
|
30862
31591
|
exports.pushToCache = pushToCache;
|
|
30863
31592
|
exports.queryCache = queryCache;
|
|
30864
31593
|
exports.queryCategories = queryCategories;
|
|
@@ -30886,6 +31615,8 @@ exports.removeReaction = removeReaction;
|
|
|
30886
31615
|
exports.renewal = renewal;
|
|
30887
31616
|
exports.restoreCache = restoreCache;
|
|
30888
31617
|
exports.runQuery = runQuery;
|
|
31618
|
+
exports.setActiveUser = setActiveUser;
|
|
31619
|
+
exports.setMarkerSyncEvents = setMarkerSyncEvents;
|
|
30889
31620
|
exports.sortByChannelSegment = sortByChannelSegment;
|
|
30890
31621
|
exports.sortByDisplayName = sortByDisplayName;
|
|
30891
31622
|
exports.sortByFirstCreated = sortByFirstCreated;
|
|
@@ -30894,7 +31625,11 @@ exports.sortByLastCreated = sortByLastCreated;
|
|
|
30894
31625
|
exports.sortByName = sortByName;
|
|
30895
31626
|
exports.sortBySegmentNumber = sortBySegmentNumber;
|
|
30896
31627
|
exports.startReading = startReading;
|
|
31628
|
+
exports.startReadingAPI = startReadingAPI;
|
|
31629
|
+
exports.startUnreadSync = startUnreadSync;
|
|
30897
31630
|
exports.stopReading = stopReading;
|
|
31631
|
+
exports.stopReadingAPI = stopReadingAPI;
|
|
31632
|
+
exports.stopUnreadSyncing = stopUnreadSyncing;
|
|
30898
31633
|
exports.subscribeTopic = subscribeTopic;
|
|
30899
31634
|
exports.toPage = toPage;
|
|
30900
31635
|
exports.toPageRaw = toPageRaw;
|
|
@@ -30908,6 +31643,7 @@ exports.updateMessage = updateMessage;
|
|
|
30908
31643
|
exports.updatePost = updatePost;
|
|
30909
31644
|
exports.updateStream = updateStream;
|
|
30910
31645
|
exports.updateSubChannel = updateSubChannel;
|
|
31646
|
+
exports.updateSubChannelMarker = updateSubChannelMarker;
|
|
30911
31647
|
exports.updateUser = updateUser;
|
|
30912
31648
|
exports.upsertInCache = upsertInCache;
|
|
30913
31649
|
exports.votePoll = votePoll;
|