@amityco/ts-sdk 0.0.1-beta.42.2 → 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/getChannels.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/comment/api/getComments.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +1931 -1159
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1901 -1160
- 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/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/tests/getPosts.test.d.ts +2 -0
- package/dist/post/api/tests/getPosts.test.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/comment.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 +21 -5
- 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 +3 -3
- 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 +22 -14
- 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/getComments.ts +20 -4
- package/src/comment/api/tests/getComments.test.ts +12 -1
- 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/post/api/getPosts.ts +20 -4
- package/src/post/api/tests/getPosts.test.ts +18 -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/comment.ts +2 -2
- 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 +42 -2
- package/src/utils/tests/dummy/post.ts +1 -1
- 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
|
*
|
|
@@ -22120,100 +23313,6 @@ const dispatchReactable = (referenceType, model) => {
|
|
|
22120
23313
|
fireEvent('comment.updated', { comments: [model] });
|
|
22121
23314
|
};
|
|
22122
23315
|
|
|
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
|
-
}
|
|
22216
|
-
|
|
22217
23316
|
/* begin_public_function
|
|
22218
23317
|
id: message.get
|
|
22219
23318
|
*/
|
|
@@ -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})
|
|
@@ -22836,10 +23955,22 @@ const getPosts = async (postIds) => {
|
|
|
22836
23955
|
const client = getActiveClient();
|
|
22837
23956
|
client.log('post/getPosts', postIds);
|
|
22838
23957
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
22839
|
-
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
23958
|
+
let payload;
|
|
23959
|
+
try {
|
|
23960
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23961
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
23962
|
+
params: { postIds: encodedPostIds },
|
|
23963
|
+
});
|
|
23964
|
+
payload = response.data;
|
|
23965
|
+
}
|
|
23966
|
+
catch (error) {
|
|
23967
|
+
postIds.forEach(postId => {
|
|
23968
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23969
|
+
pushToTombstone('post', postId);
|
|
23970
|
+
}
|
|
23971
|
+
});
|
|
23972
|
+
throw error;
|
|
23973
|
+
}
|
|
22843
23974
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22844
23975
|
const cachedAt = client.cache && Date.now();
|
|
22845
23976
|
if (client.cache)
|
|
@@ -24014,10 +25145,22 @@ const getComments = async (commentIds) => {
|
|
|
24014
25145
|
const client = getActiveClient();
|
|
24015
25146
|
client.log('comment/getComments', commentIds);
|
|
24016
25147
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
24017
|
-
|
|
24018
|
-
|
|
24019
|
-
|
|
24020
|
-
|
|
25148
|
+
let data;
|
|
25149
|
+
try {
|
|
25150
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
25151
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
25152
|
+
params: { commentIds: encodedCommentIds },
|
|
25153
|
+
});
|
|
25154
|
+
data = response.data;
|
|
25155
|
+
}
|
|
25156
|
+
catch (error) {
|
|
25157
|
+
commentIds.forEach(commentId => {
|
|
25158
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
25159
|
+
pushToTombstone('comment', commentId);
|
|
25160
|
+
}
|
|
25161
|
+
});
|
|
25162
|
+
throw error;
|
|
25163
|
+
}
|
|
24021
25164
|
const cachedAt = client.cache && Date.now();
|
|
24022
25165
|
if (client.cache)
|
|
24023
25166
|
ingestInCache(data, { cachedAt });
|
|
@@ -24950,9 +26093,9 @@ const onReactionAdded = (referenceType, referenceId, callback) => {
|
|
|
24950
26093
|
*/
|
|
24951
26094
|
if (referenceType === 'message') {
|
|
24952
26095
|
const client = getActiveClient();
|
|
24953
|
-
const filter = (rawPayload) => {
|
|
26096
|
+
const filter = async (rawPayload) => {
|
|
24954
26097
|
var _a;
|
|
24955
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26098
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
24956
26099
|
const cached = pullFromCache([
|
|
24957
26100
|
'message',
|
|
24958
26101
|
'get',
|
|
@@ -24997,9 +26140,9 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
|
|
|
24997
26140
|
};
|
|
24998
26141
|
if (referenceType === 'message') {
|
|
24999
26142
|
const client = getActiveClient();
|
|
25000
|
-
const filter = (rawPayload) => {
|
|
26143
|
+
const filter = async (rawPayload) => {
|
|
25001
26144
|
var _a;
|
|
25002
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26145
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25003
26146
|
const cached = pullFromCache([
|
|
25004
26147
|
'message',
|
|
25005
26148
|
'get',
|
|
@@ -25044,8 +26187,8 @@ const onReactorAdded = (referenceType, referenceId, callback) => {
|
|
|
25044
26187
|
}
|
|
25045
26188
|
};
|
|
25046
26189
|
if (referenceType === 'message') {
|
|
25047
|
-
const filter = (rawPayload) => {
|
|
25048
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26190
|
+
const filter = async (rawPayload) => {
|
|
26191
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25049
26192
|
if (!payload.messages[0].latestReaction)
|
|
25050
26193
|
return;
|
|
25051
26194
|
const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType, userDisplayName } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType", "userDisplayName"]);
|
|
@@ -25106,8 +26249,8 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
25106
26249
|
}
|
|
25107
26250
|
};
|
|
25108
26251
|
if (referenceType === 'message') {
|
|
25109
|
-
const filter = (rawPayload) => {
|
|
25110
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26252
|
+
const filter = async (rawPayload) => {
|
|
26253
|
+
const payload = await prepareMessagePayload(rawPayload);
|
|
25111
26254
|
if (!payload.messages[0].latestReaction)
|
|
25112
26255
|
return;
|
|
25113
26256
|
const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType"]);
|
|
@@ -25293,7 +26436,8 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
25293
26436
|
const { data: payload } = await client.http.post(getAPIUrl());
|
|
25294
26437
|
if (client.cache) {
|
|
25295
26438
|
if (referenceType === 'message') {
|
|
25296
|
-
|
|
26439
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
26440
|
+
ingestInCache(messagePayload);
|
|
25297
26441
|
}
|
|
25298
26442
|
else if (referenceType === 'post') {
|
|
25299
26443
|
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
@@ -25339,7 +26483,8 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
25339
26483
|
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
25340
26484
|
if (client.cache) {
|
|
25341
26485
|
if (referenceType === 'message') {
|
|
25342
|
-
|
|
26486
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
26487
|
+
ingestInCache(messagePayload);
|
|
25343
26488
|
}
|
|
25344
26489
|
else if (referenceType === 'post') {
|
|
25345
26490
|
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
@@ -25386,37 +26531,60 @@ const isReportedByMe = async (referenceType, referenceId) => {
|
|
|
25386
26531
|
};
|
|
25387
26532
|
/* end_public_function */
|
|
25388
26533
|
|
|
25389
|
-
|
|
25390
|
-
|
|
25391
|
-
|
|
25392
|
-
|
|
25393
|
-
|
|
25394
|
-
|
|
25395
|
-
|
|
25396
|
-
cached = pullFromCache(['channel', 'get', rawChannel.channelId]);
|
|
25397
|
-
// eslint-disable-next-line no-empty
|
|
25398
|
-
}
|
|
25399
|
-
catch (_a) { }
|
|
25400
|
-
if (cached) {
|
|
25401
|
-
return {
|
|
25402
|
-
defaultSubChannelHasUnreadMention: cached.data.defaultSubChannelHasUnreadMention,
|
|
25403
|
-
defaultSubChannelUnreadCount: cached.data.defaultSubChannelUnreadCount,
|
|
25404
|
-
localReadToSegment: cached.data.localReadToSegment,
|
|
25405
|
-
localLastMentionSegment: cached.data.localLastMentionSegment,
|
|
25406
|
-
};
|
|
25407
|
-
}
|
|
25408
|
-
return {
|
|
25409
|
-
defaultSubChannelHasUnreadMention: false,
|
|
25410
|
-
defaultSubChannelUnreadCount: 0,
|
|
25411
|
-
// @ts-ignore
|
|
25412
|
-
localReadToSegment: rawChannel.messageCount > 0 ? rawChannel.messageCount - 1 : 0,
|
|
25413
|
-
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,
|
|
25414
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() });
|
|
25415
26563
|
}
|
|
25416
|
-
const prepareChannelPayload = (rawPayload) => {
|
|
25417
|
-
|
|
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
|
|
25418
26585
|
const channelUsers = withUsers(rawPayload.channelUsers);
|
|
25419
|
-
return Object.assign(Object.assign({}, rawPayload), { channels,
|
|
26586
|
+
return Object.assign(Object.assign({}, rawPayload), { channels,
|
|
26587
|
+
channelUsers });
|
|
25420
26588
|
};
|
|
25421
26589
|
|
|
25422
26590
|
/* begin_public_function
|
|
@@ -25443,7 +26611,7 @@ const queryChannels = async (query) => {
|
|
|
25443
26611
|
// safe decapsulation
|
|
25444
26612
|
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 }, displayName, membership } = _a, params = __rest(_a, ["page", "displayName", "membership"]);
|
|
25445
26613
|
// API-FIX: parameters should be querystring.
|
|
25446
|
-
// API-FIX: backend
|
|
26614
|
+
// API-FIX: backend doesn't answer Amity.Response
|
|
25447
26615
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
25448
26616
|
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
25449
26617
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
@@ -25451,7 +26619,7 @@ const queryChannels = async (query) => {
|
|
|
25451
26619
|
} }),
|
|
25452
26620
|
});
|
|
25453
26621
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
25454
|
-
const data = prepareChannelPayload(payload);
|
|
26622
|
+
const data = await prepareChannelPayload(payload);
|
|
25455
26623
|
const { channels } = data;
|
|
25456
26624
|
const cachedAt = client.cache && Date.now();
|
|
25457
26625
|
if (client.cache) {
|
|
@@ -25520,11 +26688,23 @@ const getChannels = async (channelIds) => {
|
|
|
25520
26688
|
const client = getActiveClient();
|
|
25521
26689
|
client.log('channel/getChannels', channelIds);
|
|
25522
26690
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
25523
|
-
|
|
25524
|
-
|
|
25525
|
-
|
|
25526
|
-
|
|
25527
|
-
|
|
26691
|
+
let payload;
|
|
26692
|
+
try {
|
|
26693
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
26694
|
+
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
26695
|
+
params: { channelIds: encodedChannelIds },
|
|
26696
|
+
});
|
|
26697
|
+
payload = response.data;
|
|
26698
|
+
}
|
|
26699
|
+
catch (error) {
|
|
26700
|
+
channelIds.forEach(channelId => {
|
|
26701
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
26702
|
+
pushToTombstone('channel', channelId);
|
|
26703
|
+
}
|
|
26704
|
+
});
|
|
26705
|
+
throw error;
|
|
26706
|
+
}
|
|
26707
|
+
const data = await prepareChannelPayload(payload);
|
|
25528
26708
|
const cachedAt = client.cache && Date.now();
|
|
25529
26709
|
if (client.cache)
|
|
25530
26710
|
ingestInCache(data, { cachedAt });
|
|
@@ -25589,7 +26769,7 @@ const getChannel = async (channelId) => {
|
|
|
25589
26769
|
let data;
|
|
25590
26770
|
try {
|
|
25591
26771
|
const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
25592
|
-
data = prepareChannelPayload(payload);
|
|
26772
|
+
data = await prepareChannelPayload(payload);
|
|
25593
26773
|
}
|
|
25594
26774
|
catch (error) {
|
|
25595
26775
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -25661,7 +26841,7 @@ const createChannel = async (bundle) => {
|
|
|
25661
26841
|
else {
|
|
25662
26842
|
payload = await client.http.post('/api/v3/channels', bundle);
|
|
25663
26843
|
}
|
|
25664
|
-
const data = prepareChannelPayload(payload.data);
|
|
26844
|
+
const data = await prepareChannelPayload(payload.data);
|
|
25665
26845
|
const cachedAt = client.cache && Date.now();
|
|
25666
26846
|
if (client.cache)
|
|
25667
26847
|
ingestInCache(data, { cachedAt });
|
|
@@ -25695,7 +26875,7 @@ const updateChannel = async (channelId, patch) => {
|
|
|
25695
26875
|
const client = getActiveClient();
|
|
25696
26876
|
client.log('channel/updateChannel', channelId, patch);
|
|
25697
26877
|
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
25698
|
-
const data = prepareChannelPayload(payload);
|
|
26878
|
+
const data = await prepareChannelPayload(payload);
|
|
25699
26879
|
const cachedAt = client.cache && Date.now();
|
|
25700
26880
|
if (client.cache)
|
|
25701
26881
|
ingestInCache(data, { cachedAt });
|
|
@@ -25751,7 +26931,7 @@ const joinChannel = async (channelId) => {
|
|
|
25751
26931
|
const client = getActiveClient();
|
|
25752
26932
|
client.log('channel/joinChannel', channelId);
|
|
25753
26933
|
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
25754
|
-
const data = prepareChannelPayload(payload);
|
|
26934
|
+
const data = await prepareChannelPayload(payload);
|
|
25755
26935
|
if (client.cache)
|
|
25756
26936
|
ingestInCache(data);
|
|
25757
26937
|
const { channelUsers } = data;
|
|
@@ -25780,7 +26960,7 @@ const leaveChannel = async (channelId) => {
|
|
|
25780
26960
|
const client = getActiveClient();
|
|
25781
26961
|
client.log('channel/leaveChannel', channelId);
|
|
25782
26962
|
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
25783
|
-
const data = prepareChannelPayload(payload);
|
|
26963
|
+
const data = await prepareChannelPayload(payload);
|
|
25784
26964
|
if (client.cache)
|
|
25785
26965
|
ingestInCache(data);
|
|
25786
26966
|
const { channelUsers } = data;
|
|
@@ -25815,7 +26995,7 @@ const queryChannelMembers = async (query) => {
|
|
|
25815
26995
|
} }),
|
|
25816
26996
|
});
|
|
25817
26997
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
25818
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26998
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
25819
26999
|
const { channelUsers } = preparedPayload;
|
|
25820
27000
|
const cachedAt = client.cache && Date.now();
|
|
25821
27001
|
if (client.cache) {
|
|
@@ -25906,7 +27086,7 @@ const addChannelMembers = async (channelId, userIds) => {
|
|
|
25906
27086
|
* should fire event for each user that was added
|
|
25907
27087
|
*/
|
|
25908
27088
|
userIds.forEach(id => fireEvent('channel.membersAdded', Object.assign(Object.assign({}, payload), { channelUsers: payload.channelUsers.filter(u => u.userId === id) })));
|
|
25909
|
-
const data = prepareChannelPayload(payload);
|
|
27089
|
+
const data = await prepareChannelPayload(payload);
|
|
25910
27090
|
if (client.cache)
|
|
25911
27091
|
ingestInCache(data);
|
|
25912
27092
|
const { channelUsers } = data;
|
|
@@ -25940,7 +27120,7 @@ const removeChannelMembers = async (channelId, userIds) => {
|
|
|
25940
27120
|
* should fire event for each user that was removed
|
|
25941
27121
|
*/
|
|
25942
27122
|
userIds.forEach(id => fireEvent('channel.membersRemoved', Object.assign(Object.assign({}, payload), { channelUsers: payload.channelUsers.filter(u => u.userId === id) })));
|
|
25943
|
-
const data = prepareChannelPayload(payload);
|
|
27123
|
+
const data = await prepareChannelPayload(payload);
|
|
25944
27124
|
if (client.cache)
|
|
25945
27125
|
ingestInCache(data);
|
|
25946
27126
|
const { channelUsers } = data;
|
|
@@ -25971,7 +27151,7 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
25971
27151
|
const client = getActiveClient();
|
|
25972
27152
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
|
|
25973
27153
|
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
25974
|
-
const data = prepareChannelPayload(payload);
|
|
27154
|
+
const data = await prepareChannelPayload(payload);
|
|
25975
27155
|
if (client.cache)
|
|
25976
27156
|
ingestInCache(data);
|
|
25977
27157
|
const { channelUsers } = data;
|
|
@@ -26002,7 +27182,7 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
26002
27182
|
const client = getActiveClient();
|
|
26003
27183
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
26004
27184
|
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
26005
|
-
const data = prepareChannelPayload(payload);
|
|
27185
|
+
const data = await prepareChannelPayload(payload);
|
|
26006
27186
|
if (client.cache)
|
|
26007
27187
|
ingestInCache(data);
|
|
26008
27188
|
const { channelUsers } = data;
|
|
@@ -26033,7 +27213,7 @@ const banChannelMembers = async (channelId, userIds) => {
|
|
|
26033
27213
|
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
26034
27214
|
userIds,
|
|
26035
27215
|
});
|
|
26036
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27216
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26037
27217
|
const { channelUsers } = preparedPayload;
|
|
26038
27218
|
const cachedAt = client.cache && Date.now();
|
|
26039
27219
|
if (client.cache)
|
|
@@ -26068,7 +27248,7 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
26068
27248
|
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
26069
27249
|
userIds,
|
|
26070
27250
|
});
|
|
26071
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27251
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26072
27252
|
const cachedAt = client.cache && Date.now();
|
|
26073
27253
|
if (client.cache)
|
|
26074
27254
|
ingestInCache(preparedPayload, { cachedAt });
|
|
@@ -26080,88 +27260,6 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
26080
27260
|
};
|
|
26081
27261
|
/* end_public_function */
|
|
26082
27262
|
|
|
26083
|
-
/* begin_public_function
|
|
26084
|
-
id: channel.start_reading
|
|
26085
|
-
*/
|
|
26086
|
-
/**
|
|
26087
|
-
* ```js
|
|
26088
|
-
* import { startReading } from '@amityco/ts-sdk'
|
|
26089
|
-
* const success = await startReading('foo')
|
|
26090
|
-
* ```
|
|
26091
|
-
*
|
|
26092
|
-
* Mark all messages as read and start reading message inside channel
|
|
26093
|
-
*
|
|
26094
|
-
* @param subChannelId - The channel ID to start reading.
|
|
26095
|
-
* @param userId - The user ID of channel member.
|
|
26096
|
-
* @return A success boolean if the channel reading of the sub channel had begun.
|
|
26097
|
-
*
|
|
26098
|
-
* @category Message API
|
|
26099
|
-
* @async
|
|
26100
|
-
*/
|
|
26101
|
-
const startReading = async (subChannelId, userId = getActiveClient().userId) => {
|
|
26102
|
-
const client = getActiveClient();
|
|
26103
|
-
client.log('message/startReading', { subChannelId });
|
|
26104
|
-
const subChannel = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
26105
|
-
if (!subChannel) {
|
|
26106
|
-
return;
|
|
26107
|
-
}
|
|
26108
|
-
const { channelId } = subChannel.data;
|
|
26109
|
-
const channel = pullFromCache(['channel', 'get', channelId]);
|
|
26110
|
-
if (!channel || channel.data.defaultSubChannelId !== subChannelId) {
|
|
26111
|
-
return;
|
|
26112
|
-
}
|
|
26113
|
-
const update = Object.assign(Object.assign({}, channel.data), {
|
|
26114
|
-
// @ts-ignore
|
|
26115
|
-
localReading: true, defaultSubChannelUnreadCount: 0, defaultSubChannelHasUnreadMention: false });
|
|
26116
|
-
pushToCache(['channel', 'get', channelId], update);
|
|
26117
|
-
client.emitter.emit('local.channel.updated', { channels: [update] });
|
|
26118
|
-
const result = await synchronousWSCall(client, 'channel.startReading', {
|
|
26119
|
-
channelId,
|
|
26120
|
-
});
|
|
26121
|
-
return !!result;
|
|
26122
|
-
};
|
|
26123
|
-
/* end_public_function */
|
|
26124
|
-
|
|
26125
|
-
/* begin_public_function
|
|
26126
|
-
id: channel.stop_reading
|
|
26127
|
-
*/
|
|
26128
|
-
/**
|
|
26129
|
-
* ```js
|
|
26130
|
-
* import { stopReading } from '@amityco/ts-sdk'
|
|
26131
|
-
* const success = await stopReading('foo')
|
|
26132
|
-
* ```
|
|
26133
|
-
*
|
|
26134
|
-
* Stop reading message inside channel
|
|
26135
|
-
*
|
|
26136
|
-
* @param subChannelId - The channel ID to stop reading.
|
|
26137
|
-
* @return A success boolean if the sub channel reading was halted.
|
|
26138
|
-
*
|
|
26139
|
-
* @category Message API
|
|
26140
|
-
* @async
|
|
26141
|
-
*/
|
|
26142
|
-
const stopReading = async (subChannelId) => {
|
|
26143
|
-
const client = getActiveClient();
|
|
26144
|
-
client.log('message/stopReading', { subChannelId });
|
|
26145
|
-
const subChannel = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
26146
|
-
if (!subChannel) {
|
|
26147
|
-
return;
|
|
26148
|
-
}
|
|
26149
|
-
const { channelId } = subChannel.data;
|
|
26150
|
-
const channel = pullFromCache(['channel', 'get', channelId]);
|
|
26151
|
-
if (!channel || channel.data.defaultSubChannelId !== subChannelId) {
|
|
26152
|
-
return;
|
|
26153
|
-
}
|
|
26154
|
-
const update = Object.assign(Object.assign({}, channel.data), {
|
|
26155
|
-
// @ts-ignore
|
|
26156
|
-
localReading: false });
|
|
26157
|
-
pushToCache(['channel', 'get', channelId], update);
|
|
26158
|
-
const result = await synchronousWSCall(client, 'channel.stopReading', {
|
|
26159
|
-
channelId,
|
|
26160
|
-
});
|
|
26161
|
-
return !!result;
|
|
26162
|
-
};
|
|
26163
|
-
/* end_public_function */
|
|
26164
|
-
|
|
26165
27263
|
/**
|
|
26166
27264
|
* ```js
|
|
26167
27265
|
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
@@ -26170,602 +27268,345 @@ const stopReading = async (subChannelId) => {
|
|
|
26170
27268
|
* })
|
|
26171
27269
|
* ```
|
|
26172
27270
|
*
|
|
26173
|
-
* Fired when any {@link Amity.Channel} have been created
|
|
26174
|
-
*
|
|
26175
|
-
* @param callback The function to call when the event was fired
|
|
26176
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26177
|
-
*
|
|
26178
|
-
* @category Channel Events
|
|
26179
|
-
*/
|
|
26180
|
-
const onChannelCreated = (callback) => {
|
|
26181
|
-
const client = getActiveClient();
|
|
26182
|
-
const filter = (payload) => {
|
|
26183
|
-
const data = prepareChannelPayload(payload);
|
|
26184
|
-
ingestInCache(data);
|
|
26185
|
-
callback(data.channels[0]);
|
|
26186
|
-
};
|
|
26187
|
-
return createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
26188
|
-
};
|
|
26189
|
-
|
|
26190
|
-
/**
|
|
26191
|
-
* ```js
|
|
26192
|
-
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
26193
|
-
* const dispose = onChannelUpdated(channel => {
|
|
26194
|
-
* // ...
|
|
26195
|
-
* })
|
|
26196
|
-
* ```
|
|
26197
|
-
*
|
|
26198
|
-
* Fired when any {@link Amity.Channel} have been updated
|
|
26199
|
-
*
|
|
26200
|
-
* @param callback The function to call when the event was fired
|
|
26201
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26202
|
-
*
|
|
26203
|
-
* @category Channel Events
|
|
26204
|
-
*/
|
|
26205
|
-
const onChannelUpdated = (callback) => {
|
|
26206
|
-
const client = getActiveClient();
|
|
26207
|
-
const filter = (payload) => {
|
|
26208
|
-
const data = prepareChannelPayload(payload);
|
|
26209
|
-
ingestInCache(data);
|
|
26210
|
-
callback(data.channels[0]);
|
|
26211
|
-
};
|
|
26212
|
-
const disposers = [
|
|
26213
|
-
createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter),
|
|
26214
|
-
createEventSubscriber(client, 'local.channel.updated', 'local.channel.updated', payload => callback(payload.channels[0])),
|
|
26215
|
-
];
|
|
26216
|
-
return () => {
|
|
26217
|
-
disposers.forEach(fn => fn());
|
|
26218
|
-
};
|
|
26219
|
-
};
|
|
26220
|
-
|
|
26221
|
-
/**
|
|
26222
|
-
* ```js
|
|
26223
|
-
* import { onChannelDeleted } from '@amityco/ts-sdk'
|
|
26224
|
-
* const dispose = onChannelDeleted(channel => {
|
|
26225
|
-
* // ...
|
|
26226
|
-
* })
|
|
26227
|
-
* ```
|
|
26228
|
-
*
|
|
26229
|
-
* Fired when any {@link Amity.Channel} have been deleted
|
|
26230
|
-
*
|
|
26231
|
-
* @param callback The function to call when the event was fired
|
|
26232
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26233
|
-
*
|
|
26234
|
-
* @category Channel Events
|
|
26235
|
-
*/
|
|
26236
|
-
const onChannelDeleted = (callback) => {
|
|
26237
|
-
const client = getActiveClient();
|
|
26238
|
-
const filter = (payload) => {
|
|
26239
|
-
const data = prepareChannelPayload(payload);
|
|
26240
|
-
ingestInCache(data);
|
|
26241
|
-
callback(data.channels[0]);
|
|
26242
|
-
};
|
|
26243
|
-
return createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
26244
|
-
};
|
|
26245
|
-
|
|
26246
|
-
/**
|
|
26247
|
-
* ```js
|
|
26248
|
-
* import { onChannelJoined } from '@amityco/ts-sdk'
|
|
26249
|
-
* const dispose = onChannelJoined((channel, member) => {
|
|
26250
|
-
* // ...
|
|
26251
|
-
* })
|
|
26252
|
-
* ```
|
|
26253
|
-
*
|
|
26254
|
-
* Fired when any {@link Amity.Channel} was joined
|
|
26255
|
-
*
|
|
26256
|
-
* @param callback The function to call when the event was fired
|
|
26257
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26258
|
-
*
|
|
26259
|
-
* @category Channel Events
|
|
26260
|
-
*/
|
|
26261
|
-
const onChannelJoined = (callback) => {
|
|
26262
|
-
const client = getActiveClient();
|
|
26263
|
-
const filter = (payload) => {
|
|
26264
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26265
|
-
const { channels, channelUsers } = preparedPayload;
|
|
26266
|
-
ingestInCache(preparedPayload);
|
|
26267
|
-
callback(channels[0], channelUsers[0]);
|
|
26268
|
-
};
|
|
26269
|
-
return createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
26270
|
-
};
|
|
26271
|
-
|
|
26272
|
-
/**
|
|
26273
|
-
* ```js
|
|
26274
|
-
* import { onChannelLeft } from '@amityco/ts-sdk'
|
|
26275
|
-
* const dispose = onChannelLeft((channel, member) => {
|
|
26276
|
-
* // ...
|
|
26277
|
-
* })
|
|
26278
|
-
* ```
|
|
26279
|
-
*
|
|
26280
|
-
* Fired when any {@link Amity.Channel} was left
|
|
26281
|
-
*
|
|
26282
|
-
* @param callback The function to call when the event was fired
|
|
26283
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26284
|
-
*
|
|
26285
|
-
* @category Channel Events
|
|
26286
|
-
*/
|
|
26287
|
-
const onChannelLeft = (callback) => {
|
|
26288
|
-
const client = getActiveClient();
|
|
26289
|
-
const filter = (payload) => {
|
|
26290
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
26291
|
-
const { channels, channelUsers } = preparedPayload;
|
|
26292
|
-
ingestInCache(preparedPayload);
|
|
26293
|
-
callback(channels[0], channelUsers[0]);
|
|
26294
|
-
};
|
|
26295
|
-
return createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
26296
|
-
};
|
|
26297
|
-
|
|
26298
|
-
/**
|
|
26299
|
-
* ```js
|
|
26300
|
-
* import { onChannelMuted } from '@amityco/ts-sdk'
|
|
26301
|
-
* const dispose = onChannelMuted(channel => {
|
|
26302
|
-
* // ...
|
|
26303
|
-
* })
|
|
26304
|
-
* ```
|
|
26305
|
-
*
|
|
26306
|
-
* Fired when any {@link Amity.Channel} have been muted
|
|
27271
|
+
* Fired when any {@link Amity.Channel} have been created
|
|
26307
27272
|
*
|
|
26308
27273
|
* @param callback The function to call when the event was fired
|
|
26309
27274
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26310
27275
|
*
|
|
26311
27276
|
* @category Channel Events
|
|
26312
27277
|
*/
|
|
26313
|
-
const
|
|
27278
|
+
const onChannelCreated = (callback) => {
|
|
26314
27279
|
const client = getActiveClient();
|
|
26315
|
-
const filter = (payload) => {
|
|
26316
|
-
const data = prepareChannelPayload(payload);
|
|
27280
|
+
const filter = async (payload) => {
|
|
27281
|
+
const data = await prepareChannelPayload(payload);
|
|
26317
27282
|
ingestInCache(data);
|
|
26318
27283
|
callback(data.channels[0]);
|
|
26319
27284
|
};
|
|
26320
|
-
return createEventSubscriber(client, '
|
|
27285
|
+
return createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
26321
27286
|
};
|
|
26322
27287
|
|
|
26323
27288
|
/**
|
|
26324
27289
|
* ```js
|
|
26325
|
-
* import {
|
|
26326
|
-
* const dispose =
|
|
27290
|
+
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
27291
|
+
* const dispose = onChannelUpdated(channel => {
|
|
26327
27292
|
* // ...
|
|
26328
27293
|
* })
|
|
26329
27294
|
* ```
|
|
26330
27295
|
*
|
|
26331
|
-
* Fired when any {@link Amity.
|
|
27296
|
+
* Fired when any {@link Amity.Channel} have been updated
|
|
26332
27297
|
*
|
|
26333
27298
|
* @param callback The function to call when the event was fired
|
|
26334
27299
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26335
27300
|
*
|
|
26336
27301
|
* @category Channel Events
|
|
26337
27302
|
*/
|
|
26338
|
-
const
|
|
27303
|
+
const onChannelUpdated = (callback) => {
|
|
26339
27304
|
const client = getActiveClient();
|
|
26340
|
-
const filter = (payload) => {
|
|
26341
|
-
const
|
|
26342
|
-
|
|
26343
|
-
|
|
26344
|
-
|
|
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());
|
|
26345
27328
|
};
|
|
26346
|
-
return createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
26347
27329
|
};
|
|
26348
27330
|
|
|
26349
27331
|
/**
|
|
26350
27332
|
* ```js
|
|
26351
|
-
* import {
|
|
26352
|
-
* const dispose =
|
|
27333
|
+
* import { onChannelDeleted } from '@amityco/ts-sdk'
|
|
27334
|
+
* const dispose = onChannelDeleted(channel => {
|
|
26353
27335
|
* // ...
|
|
26354
27336
|
* })
|
|
26355
27337
|
* ```
|
|
26356
27338
|
*
|
|
26357
|
-
* Fired when any {@link Amity.
|
|
27339
|
+
* Fired when any {@link Amity.Channel} have been deleted
|
|
26358
27340
|
*
|
|
26359
27341
|
* @param callback The function to call when the event was fired
|
|
26360
27342
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26361
27343
|
*
|
|
26362
27344
|
* @category Channel Events
|
|
26363
27345
|
*/
|
|
26364
|
-
const
|
|
27346
|
+
const onChannelDeleted = (callback) => {
|
|
26365
27347
|
const client = getActiveClient();
|
|
26366
|
-
const filter = (payload) => {
|
|
26367
|
-
const
|
|
26368
|
-
|
|
26369
|
-
|
|
26370
|
-
callback(channels[0], channelUsers[0]);
|
|
27348
|
+
const filter = async (payload) => {
|
|
27349
|
+
const data = await prepareChannelPayload(payload);
|
|
27350
|
+
ingestInCache(data);
|
|
27351
|
+
callback(data.channels[0]);
|
|
26371
27352
|
};
|
|
26372
|
-
return createEventSubscriber(client, '
|
|
27353
|
+
return createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
26373
27354
|
};
|
|
26374
27355
|
|
|
26375
27356
|
/**
|
|
26376
27357
|
* ```js
|
|
26377
|
-
* import {
|
|
26378
|
-
* const dispose =
|
|
27358
|
+
* import { onChannelJoined } from '@amityco/ts-sdk'
|
|
27359
|
+
* const dispose = onChannelJoined((channel, member) => {
|
|
26379
27360
|
* // ...
|
|
26380
27361
|
* })
|
|
26381
27362
|
* ```
|
|
26382
27363
|
*
|
|
26383
|
-
* Fired when any {@link Amity.
|
|
27364
|
+
* Fired when any {@link Amity.Channel} was joined
|
|
26384
27365
|
*
|
|
26385
27366
|
* @param callback The function to call when the event was fired
|
|
26386
27367
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26387
27368
|
*
|
|
26388
27369
|
* @category Channel Events
|
|
26389
27370
|
*/
|
|
26390
|
-
const
|
|
27371
|
+
const onChannelJoined = (callback) => {
|
|
26391
27372
|
const client = getActiveClient();
|
|
26392
|
-
const filter = (payload) => {
|
|
26393
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27373
|
+
const filter = async (payload) => {
|
|
27374
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26394
27375
|
const { channels, channelUsers } = preparedPayload;
|
|
26395
27376
|
ingestInCache(preparedPayload);
|
|
26396
|
-
callback(channels[0], channelUsers
|
|
27377
|
+
callback(channels[0], channelUsers[0]);
|
|
26397
27378
|
};
|
|
26398
|
-
return createEventSubscriber(client, '
|
|
27379
|
+
return createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
26399
27380
|
};
|
|
26400
27381
|
|
|
26401
27382
|
/**
|
|
26402
27383
|
* ```js
|
|
26403
|
-
* import {
|
|
26404
|
-
* const dispose =
|
|
27384
|
+
* import { onChannelLeft } from '@amityco/ts-sdk'
|
|
27385
|
+
* const dispose = onChannelLeft((channel, member) => {
|
|
26405
27386
|
* // ...
|
|
26406
27387
|
* })
|
|
26407
27388
|
* ```
|
|
26408
27389
|
*
|
|
26409
|
-
* Fired when any {@link Amity.
|
|
27390
|
+
* Fired when any {@link Amity.Channel} was left
|
|
26410
27391
|
*
|
|
26411
27392
|
* @param callback The function to call when the event was fired
|
|
26412
27393
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26413
27394
|
*
|
|
26414
27395
|
* @category Channel Events
|
|
26415
27396
|
*/
|
|
26416
|
-
const
|
|
27397
|
+
const onChannelLeft = (callback) => {
|
|
26417
27398
|
const client = getActiveClient();
|
|
26418
|
-
const filter = (payload) => {
|
|
26419
|
-
const preparedPayload = prepareChannelPayload(payload);
|
|
27399
|
+
const filter = async (payload) => {
|
|
27400
|
+
const preparedPayload = await prepareChannelPayload(payload);
|
|
26420
27401
|
const { channels, channelUsers } = preparedPayload;
|
|
26421
27402
|
ingestInCache(preparedPayload);
|
|
26422
|
-
callback(channels[0], channelUsers
|
|
26423
|
-
};
|
|
26424
|
-
return createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
26425
|
-
};
|
|
26426
|
-
|
|
26427
|
-
/**
|
|
26428
|
-
* ```js
|
|
26429
|
-
* import { observeChannel } from '@amityco/ts-sdk'
|
|
26430
|
-
*
|
|
26431
|
-
* let channel = {}
|
|
26432
|
-
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
26433
|
-
* ```
|
|
26434
|
-
*
|
|
26435
|
-
* Observe all mutation on a given {@link Amity.Channel}
|
|
26436
|
-
*
|
|
26437
|
-
* @param channelId the ID of the channel to observe
|
|
26438
|
-
* @param callback the function to call when new data are available
|
|
26439
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channel
|
|
26440
|
-
*
|
|
26441
|
-
* @category Channel Observer
|
|
26442
|
-
*/
|
|
26443
|
-
const observeChannel = (channelId, callback) => {
|
|
26444
|
-
const { log } = getActiveClient();
|
|
26445
|
-
const timestamp = Date.now();
|
|
26446
|
-
log(`observeChannel(tmpid: ${timestamp}) > listen`);
|
|
26447
|
-
// wrapper function to make sure
|
|
26448
|
-
const router = (result, action) => {
|
|
26449
|
-
var _a, _b, _c;
|
|
26450
|
-
// filter function
|
|
26451
|
-
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
|
|
26452
|
-
return;
|
|
26453
|
-
if (callback instanceof Function)
|
|
26454
|
-
return callback(result);
|
|
26455
|
-
if (action !== 'onFetch')
|
|
26456
|
-
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, result);
|
|
26457
|
-
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, result);
|
|
26458
|
-
};
|
|
26459
|
-
const disposers = [];
|
|
26460
|
-
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')));
|
|
26461
|
-
runQuery(createQuery(getChannel, channelId), result => result.data && router(result, 'onFetch'));
|
|
26462
|
-
return () => {
|
|
26463
|
-
log(`observeChannel(tmpid: ${timestamp}) > dispose`);
|
|
26464
|
-
disposers.forEach(fn => fn());
|
|
26465
|
-
};
|
|
26466
|
-
};
|
|
26467
|
-
|
|
26468
|
-
/**
|
|
26469
|
-
* ```js
|
|
26470
|
-
* import { observeChannels } from '@amityco/ts-sdk'
|
|
26471
|
-
*
|
|
26472
|
-
* let channels = []
|
|
26473
|
-
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
26474
|
-
* ```
|
|
26475
|
-
*
|
|
26476
|
-
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
26477
|
-
*
|
|
26478
|
-
* @param callback the function to call when new data are available
|
|
26479
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
26480
|
-
*
|
|
26481
|
-
* @category Channel Observer
|
|
26482
|
-
*/
|
|
26483
|
-
const observeChannels = (callback) => {
|
|
26484
|
-
const { log } = getActiveClient();
|
|
26485
|
-
const timestamp = Date.now();
|
|
26486
|
-
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
26487
|
-
const disposers = [];
|
|
26488
|
-
const router = (channel, action) => {
|
|
26489
|
-
var _a, _b;
|
|
26490
|
-
if (callback instanceof Function)
|
|
26491
|
-
return callback(channel);
|
|
26492
|
-
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
26493
|
-
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
26494
|
-
};
|
|
26495
|
-
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')));
|
|
26496
|
-
return () => {
|
|
26497
|
-
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
26498
|
-
disposers.forEach(fn => fn());
|
|
26499
|
-
};
|
|
26500
|
-
};
|
|
26501
|
-
|
|
26502
|
-
function hasMention(model, userId) {
|
|
26503
|
-
var _a, _b;
|
|
26504
|
-
const channelMention = (_a = model === null || model === void 0 ? void 0 : model.mentionees) === null || _a === void 0 ? void 0 : _a.find(x => x.type === 'channel');
|
|
26505
|
-
if (channelMention) {
|
|
26506
|
-
return true;
|
|
26507
|
-
}
|
|
26508
|
-
const userMention = (_b = model === null || model === void 0 ? void 0 : model.mentionees) === null || _b === void 0 ? void 0 : _b.find(x => x.type === 'user');
|
|
26509
|
-
if (userMention) {
|
|
26510
|
-
return userMention.userIds.includes(userId);
|
|
26511
|
-
}
|
|
26512
|
-
return false;
|
|
26513
|
-
}
|
|
26514
|
-
function isCollectionOutdated(collection, newItem, action) {
|
|
26515
|
-
const key = identifyModelKey(newItem);
|
|
26516
|
-
// @ts-ignore
|
|
26517
|
-
const item = collection.find(x => x[key] === newItem[key]);
|
|
26518
|
-
if (item) {
|
|
26519
|
-
return hasUpdates(item, newItem);
|
|
26520
|
-
}
|
|
26521
|
-
return action === 'onCreate';
|
|
26522
|
-
}
|
|
26523
|
-
function merge(collection1, collection2) {
|
|
26524
|
-
const temp = [...collection1, ...collection2];
|
|
26525
|
-
if (temp.length === 0) {
|
|
26526
|
-
return [];
|
|
26527
|
-
}
|
|
26528
|
-
const key = identifyModelKey(temp[0]);
|
|
26529
|
-
const map = new Map();
|
|
26530
|
-
// @ts-ignore
|
|
26531
|
-
temp.forEach(x => map.set(x[key], x));
|
|
26532
|
-
return Array.from(map.values());
|
|
26533
|
-
}
|
|
26534
|
-
|
|
26535
|
-
/**
|
|
26536
|
-
* ```js
|
|
26537
|
-
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
26538
|
-
* const dispose = onMessageCreated(message => {
|
|
26539
|
-
* // ...
|
|
26540
|
-
* })
|
|
26541
|
-
* ```
|
|
26542
|
-
*
|
|
26543
|
-
* Fired when an {@link Amity.Message} has been created
|
|
26544
|
-
*
|
|
26545
|
-
* @param callback The function to call when the event was fired
|
|
26546
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26547
|
-
*
|
|
26548
|
-
* @category Message Events
|
|
26549
|
-
*/
|
|
26550
|
-
const onMessageCreated = (callback) => {
|
|
26551
|
-
const client = getActiveClient();
|
|
26552
|
-
const filter = (rawPayload) => {
|
|
26553
|
-
const payload = prepareMessagePayload(rawPayload);
|
|
26554
|
-
const message = payload.messages[0];
|
|
26555
|
-
const cached = pullFromCache(['channel', 'get', message.channelId]);
|
|
26556
|
-
if (cached && cached.data.defaultSubChannelId === message.subChannelId) {
|
|
26557
|
-
let update;
|
|
26558
|
-
// @ts-ignore
|
|
26559
|
-
if (cached.data.localReading) {
|
|
26560
|
-
update = Object.assign(Object.assign({}, cached.data), { localReadToSegment: message.channelSegment, localLastMentionSegment: hasMention(message, client.userId)
|
|
26561
|
-
? message.channelSegment
|
|
26562
|
-
: cached.data.localLastMentionSegment, messageCount: message.channelSegment, lastActivity: message.createdAt, updatedAt: message.createdAt });
|
|
26563
|
-
}
|
|
26564
|
-
else {
|
|
26565
|
-
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 });
|
|
26566
|
-
}
|
|
26567
|
-
pushToCache(['channel', 'get', message.channelId], update);
|
|
26568
|
-
client.emitter.emit('local.channel.updated', { channels: [update] });
|
|
26569
|
-
}
|
|
26570
|
-
ingestInCache(payload);
|
|
26571
|
-
callback(message);
|
|
26572
|
-
};
|
|
26573
|
-
const disposers = [
|
|
26574
|
-
createEventSubscriber(client, 'message/onMessageCreated', 'message.created', filter),
|
|
26575
|
-
createEventSubscriber(client, 'local.message.created', 'local.message.created', payload => callback(payload.messages[0])),
|
|
26576
|
-
];
|
|
26577
|
-
return () => {
|
|
26578
|
-
disposers.forEach(fn => fn());
|
|
27403
|
+
callback(channels[0], channelUsers[0]);
|
|
26579
27404
|
};
|
|
27405
|
+
return createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
26580
27406
|
};
|
|
26581
27407
|
|
|
26582
27408
|
/**
|
|
26583
27409
|
* ```js
|
|
26584
|
-
* import {
|
|
26585
|
-
* const dispose =
|
|
27410
|
+
* import { onChannelMuted } from '@amityco/ts-sdk'
|
|
27411
|
+
* const dispose = onChannelMuted(channel => {
|
|
26586
27412
|
* // ...
|
|
26587
27413
|
* })
|
|
26588
27414
|
* ```
|
|
26589
27415
|
*
|
|
26590
|
-
* Fired when
|
|
27416
|
+
* Fired when any {@link Amity.Channel} have been muted
|
|
26591
27417
|
*
|
|
26592
27418
|
* @param callback The function to call when the event was fired
|
|
26593
27419
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26594
27420
|
*
|
|
26595
|
-
* @category
|
|
27421
|
+
* @category Channel Events
|
|
26596
27422
|
*/
|
|
26597
|
-
const
|
|
27423
|
+
const onChannelMuted = (callback) => {
|
|
26598
27424
|
const client = getActiveClient();
|
|
26599
|
-
const filter = (
|
|
26600
|
-
const
|
|
26601
|
-
ingestInCache(
|
|
26602
|
-
callback(
|
|
26603
|
-
};
|
|
26604
|
-
const disposers = [
|
|
26605
|
-
createEventSubscriber(client, 'message/onMessageUpdated', 'message.updated', filter),
|
|
26606
|
-
createEventSubscriber(client, 'local.message.updated', 'local.message.updated', payload => callback(payload.messages[0])),
|
|
26607
|
-
];
|
|
26608
|
-
return () => {
|
|
26609
|
-
disposers.forEach(fn => fn());
|
|
27425
|
+
const filter = async (payload) => {
|
|
27426
|
+
const data = await prepareChannelPayload(payload);
|
|
27427
|
+
ingestInCache(data);
|
|
27428
|
+
callback(data.channels[0]);
|
|
26610
27429
|
};
|
|
27430
|
+
return createEventSubscriber(client, 'onChannelMuted', 'channel.setMuted', filter);
|
|
26611
27431
|
};
|
|
26612
27432
|
|
|
26613
27433
|
/**
|
|
26614
27434
|
* ```js
|
|
26615
|
-
* import {
|
|
26616
|
-
* const dispose =
|
|
27435
|
+
* import { onChannelMemberAdded } from '@amityco/ts-sdk'
|
|
27436
|
+
* const dispose = onChannelMemberAdded((channel, member) => {
|
|
26617
27437
|
* // ...
|
|
26618
27438
|
* })
|
|
26619
27439
|
* ```
|
|
26620
27440
|
*
|
|
26621
|
-
* Fired when
|
|
27441
|
+
* Fired when any {@link Amity.User} has been added to any {@link Amity.Channel}
|
|
26622
27442
|
*
|
|
26623
27443
|
* @param callback The function to call when the event was fired
|
|
26624
27444
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26625
27445
|
*
|
|
26626
|
-
* @category
|
|
27446
|
+
* @category Channel Events
|
|
26627
27447
|
*/
|
|
26628
|
-
const
|
|
27448
|
+
const onChannelMemberAdded = (callback) => {
|
|
26629
27449
|
const client = getActiveClient();
|
|
26630
|
-
const filter = (
|
|
26631
|
-
const
|
|
26632
|
-
|
|
26633
|
-
|
|
26634
|
-
|
|
26635
|
-
const disposers = [
|
|
26636
|
-
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
26637
|
-
createEventSubscriber(client, 'local.message.deleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
26638
|
-
];
|
|
26639
|
-
return () => {
|
|
26640
|
-
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'));
|
|
26641
27455
|
};
|
|
27456
|
+
return createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
26642
27457
|
};
|
|
26643
27458
|
|
|
26644
27459
|
/**
|
|
26645
27460
|
* ```js
|
|
26646
|
-
* import {
|
|
26647
|
-
* const dispose =
|
|
27461
|
+
* import { onChannelMemberRemoved } from '@amityco/ts-sdk'
|
|
27462
|
+
* const dispose = onChannelMemberRemoved((channel, member) => {
|
|
26648
27463
|
* // ...
|
|
26649
27464
|
* })
|
|
26650
27465
|
* ```
|
|
26651
27466
|
*
|
|
26652
|
-
* Fired when
|
|
27467
|
+
* Fired when any {@link Amity.User} has been removed from any {@link Amity.Channel}
|
|
26653
27468
|
*
|
|
26654
27469
|
* @param callback The function to call when the event was fired
|
|
26655
27470
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26656
27471
|
*
|
|
26657
|
-
* @category
|
|
27472
|
+
* @category Channel Events
|
|
26658
27473
|
*/
|
|
26659
|
-
const
|
|
27474
|
+
const onChannelMemberRemoved = (callback) => {
|
|
26660
27475
|
const client = getActiveClient();
|
|
26661
|
-
const filter = (
|
|
26662
|
-
const
|
|
26663
|
-
|
|
26664
|
-
|
|
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]);
|
|
26665
27481
|
};
|
|
26666
|
-
return createEventSubscriber(client, '
|
|
27482
|
+
return createEventSubscriber(client, 'onChannelMemberRemoved', 'channel.membersRemoved', filter);
|
|
26667
27483
|
};
|
|
26668
27484
|
|
|
26669
27485
|
/**
|
|
26670
27486
|
* ```js
|
|
26671
|
-
* import {
|
|
26672
|
-
* const dispose =
|
|
27487
|
+
* import { onChannelMemberBanned } from '@amityco/ts-sdk'
|
|
27488
|
+
* const dispose = onChannelMemberBanned((channel, member) => {
|
|
26673
27489
|
* // ...
|
|
26674
27490
|
* })
|
|
26675
27491
|
* ```
|
|
26676
27492
|
*
|
|
26677
|
-
* Fired when
|
|
27493
|
+
* Fired when any {@link Amity.User} has been banned from any {@link Amity.Channel}
|
|
26678
27494
|
*
|
|
26679
27495
|
* @param callback The function to call when the event was fired
|
|
26680
27496
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26681
27497
|
*
|
|
26682
|
-
* @category
|
|
27498
|
+
* @category Channel Events
|
|
26683
27499
|
*/
|
|
26684
|
-
const
|
|
27500
|
+
const onChannelMemberBanned = (callback) => {
|
|
26685
27501
|
const client = getActiveClient();
|
|
26686
|
-
const filter = (
|
|
26687
|
-
const
|
|
26688
|
-
|
|
26689
|
-
|
|
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'));
|
|
26690
27507
|
};
|
|
26691
|
-
return createEventSubscriber(client, '
|
|
27508
|
+
return createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
26692
27509
|
};
|
|
26693
27510
|
|
|
26694
27511
|
/**
|
|
26695
27512
|
* ```js
|
|
26696
|
-
* import {
|
|
26697
|
-
* const dispose =
|
|
27513
|
+
* import { onChannelMemberUnbanned } from '@amityco/ts-sdk'
|
|
27514
|
+
* const dispose = onChannelMemberUnbanned((channel, member) => {
|
|
26698
27515
|
* // ...
|
|
26699
27516
|
* })
|
|
26700
27517
|
* ```
|
|
26701
27518
|
*
|
|
26702
|
-
* Fired when
|
|
27519
|
+
* Fired when any {@link Amity.User} has been unbanned from any {@link Amity.Channel}
|
|
26703
27520
|
*
|
|
26704
27521
|
* @param callback The function to call when the event was fired
|
|
26705
27522
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
26706
27523
|
*
|
|
26707
|
-
* @category
|
|
27524
|
+
* @category Channel Events
|
|
26708
27525
|
*/
|
|
26709
|
-
const
|
|
27526
|
+
const onChannelMemberUnbanned = (callback) => {
|
|
26710
27527
|
const client = getActiveClient();
|
|
26711
|
-
const filter = (
|
|
26712
|
-
const
|
|
26713
|
-
|
|
26714
|
-
|
|
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'));
|
|
26715
27533
|
};
|
|
26716
|
-
return createEventSubscriber(client, '
|
|
27534
|
+
return createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
26717
27535
|
};
|
|
26718
27536
|
|
|
26719
27537
|
/**
|
|
26720
27538
|
* ```js
|
|
26721
|
-
* import {
|
|
27539
|
+
* import { observeChannel } from '@amityco/ts-sdk'
|
|
26722
27540
|
*
|
|
26723
|
-
*
|
|
26724
|
-
*
|
|
26725
|
-
* });
|
|
27541
|
+
* let channel = {}
|
|
27542
|
+
* const dispose = observeChannel(channelId, ({ data }) => channel = data)
|
|
26726
27543
|
* ```
|
|
26727
27544
|
*
|
|
26728
|
-
*
|
|
27545
|
+
* Observe all mutation on a given {@link Amity.Channel}
|
|
26729
27546
|
*
|
|
26730
|
-
* @param
|
|
26731
|
-
* @
|
|
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
|
|
26732
27550
|
*
|
|
26733
|
-
* @category
|
|
27551
|
+
* @category Channel Observer
|
|
26734
27552
|
*/
|
|
26735
|
-
const
|
|
26736
|
-
const
|
|
26737
|
-
const
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
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());
|
|
26741
27575
|
};
|
|
26742
|
-
return createEventSubscriber(client, 'onMessageReactionAdded', 'message.reactionAdded', filter);
|
|
26743
27576
|
};
|
|
26744
27577
|
|
|
26745
27578
|
/**
|
|
26746
27579
|
* ```js
|
|
26747
|
-
* import {
|
|
27580
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
26748
27581
|
*
|
|
26749
|
-
*
|
|
26750
|
-
*
|
|
26751
|
-
* });
|
|
27582
|
+
* let channels = []
|
|
27583
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
26752
27584
|
* ```
|
|
26753
27585
|
*
|
|
26754
|
-
*
|
|
27586
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
26755
27587
|
*
|
|
26756
|
-
* @param callback
|
|
26757
|
-
* @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
|
|
26758
27590
|
*
|
|
26759
|
-
* @category
|
|
27591
|
+
* @category Channel Observer
|
|
26760
27592
|
*/
|
|
26761
|
-
const
|
|
26762
|
-
const
|
|
26763
|
-
const
|
|
26764
|
-
|
|
26765
|
-
|
|
26766
|
-
|
|
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());
|
|
26767
27609
|
};
|
|
26768
|
-
return createEventSubscriber(client, 'onMessageReactionRemoved', 'message.reactionRemoved', filter);
|
|
26769
27610
|
};
|
|
26770
27611
|
|
|
26771
27612
|
/**
|
|
@@ -27042,22 +27883,6 @@ const liveChannelMembers = (params, callback, config) => {
|
|
|
27042
27883
|
};
|
|
27043
27884
|
};
|
|
27044
27885
|
|
|
27045
|
-
function convertFromRaw(_a) {
|
|
27046
|
-
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"]);
|
|
27047
|
-
return Object.assign(Object.assign({}, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId });
|
|
27048
|
-
}
|
|
27049
|
-
const prepareSubChannelPayload = (payload) => {
|
|
27050
|
-
return Object.assign(Object.assign({}, payload), { messageFeeds: payload.messageFeeds.map(convertFromRaw) });
|
|
27051
|
-
};
|
|
27052
|
-
function convertQueryParams(_a) {
|
|
27053
|
-
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
27054
|
-
const out = Object.assign({}, rest);
|
|
27055
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
27056
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
27057
|
-
}
|
|
27058
|
-
return out;
|
|
27059
|
-
}
|
|
27060
|
-
|
|
27061
27886
|
/* begin_public_function
|
|
27062
27887
|
id: subchannel.query
|
|
27063
27888
|
*/
|
|
@@ -27085,7 +27910,7 @@ const querySubChannels = async (query) => {
|
|
|
27085
27910
|
} }),
|
|
27086
27911
|
});
|
|
27087
27912
|
const _b = response.data, { paging } = _b, payload = __rest(_b, ["paging"]);
|
|
27088
|
-
const data = prepareSubChannelPayload(payload);
|
|
27913
|
+
const data = await prepareSubChannelPayload(payload);
|
|
27089
27914
|
const subChannels = data.messageFeeds;
|
|
27090
27915
|
const cachedAt = client.cache && Date.now();
|
|
27091
27916
|
if (client.cache) {
|
|
@@ -27161,7 +27986,7 @@ const getSubChannels = async (subChannelIds) => {
|
|
|
27161
27986
|
const response = await client.http.get('/api/v5/message-feeds/list', {
|
|
27162
27987
|
params: { messageFeedIds: subChannelIds.map(encodeURIComponent) },
|
|
27163
27988
|
});
|
|
27164
|
-
const data = prepareSubChannelPayload(response.data);
|
|
27989
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27165
27990
|
const cachedAt = client.cache && Date.now();
|
|
27166
27991
|
if (client.cache)
|
|
27167
27992
|
ingestInCache(data, { cachedAt });
|
|
@@ -27226,7 +28051,7 @@ const getSubChannel = async (subChannelId) => {
|
|
|
27226
28051
|
isInTombstone('subChannel', subChannelId);
|
|
27227
28052
|
try {
|
|
27228
28053
|
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
27229
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28054
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27230
28055
|
const cachedAt = client.cache && Date.now();
|
|
27231
28056
|
if (client.cache)
|
|
27232
28057
|
ingestInCache(data, { cachedAt });
|
|
@@ -27295,7 +28120,7 @@ const createSubChannel = async (bundle) => {
|
|
|
27295
28120
|
channelId: bundle.channelId,
|
|
27296
28121
|
name: bundle.displayName,
|
|
27297
28122
|
});
|
|
27298
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28123
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27299
28124
|
const cachedAt = client.cache && Date.now();
|
|
27300
28125
|
if (client.cache)
|
|
27301
28126
|
ingestInCache(data, { cachedAt });
|
|
@@ -27329,7 +28154,7 @@ const updateSubChannel = async (subChannelId, patch) => {
|
|
|
27329
28154
|
const client = getActiveClient();
|
|
27330
28155
|
client.log('channel/updateSubChannel', subChannelId, patch);
|
|
27331
28156
|
const response = await client.http.put(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`, { name: patch.displayName });
|
|
27332
|
-
const data = prepareSubChannelPayload(response.data);
|
|
28157
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
27333
28158
|
const cachedAt = client.cache && Date.now();
|
|
27334
28159
|
if (client.cache)
|
|
27335
28160
|
ingestInCache(data, { cachedAt });
|
|
@@ -27377,87 +28202,6 @@ const deleteSubChannel = async (subChannelId, permanent = false) => {
|
|
|
27377
28202
|
};
|
|
27378
28203
|
/* end_public_function */
|
|
27379
28204
|
|
|
27380
|
-
/**
|
|
27381
|
-
* ```js
|
|
27382
|
-
* import { onChannelSubCreated } from '@amityco/ts-sdk'
|
|
27383
|
-
* const dispose = onSubChannelCreated(subChannel => {
|
|
27384
|
-
* // ...
|
|
27385
|
-
* })
|
|
27386
|
-
* ```
|
|
27387
|
-
*
|
|
27388
|
-
* Fired when any {@link Amity.SubChannel} have been created
|
|
27389
|
-
*
|
|
27390
|
-
* @param callback The function to call when the event was fired
|
|
27391
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27392
|
-
*
|
|
27393
|
-
* @category Channel Events
|
|
27394
|
-
*/
|
|
27395
|
-
const onSubChannelCreated = (callback) => {
|
|
27396
|
-
const client = getActiveClient();
|
|
27397
|
-
const filter = (rawPayload) => {
|
|
27398
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27399
|
-
ingestInCache(payload);
|
|
27400
|
-
callback(payload.messageFeeds[0]);
|
|
27401
|
-
};
|
|
27402
|
-
return createEventSubscriber(client, 'onSubChannelCreated', 'message-feed.created', filter);
|
|
27403
|
-
};
|
|
27404
|
-
|
|
27405
|
-
/**
|
|
27406
|
-
* ```js
|
|
27407
|
-
* import { onSubChannelUpdated } from '@amityco/ts-sdk'
|
|
27408
|
-
* const dispose = onSubChannelUpdated(subChannel => {
|
|
27409
|
-
* // ...
|
|
27410
|
-
* })
|
|
27411
|
-
* ```
|
|
27412
|
-
*
|
|
27413
|
-
* Fired when any {@link Amity.SubChannel} have been updated
|
|
27414
|
-
*
|
|
27415
|
-
* @param callback The function to call when the event was fired
|
|
27416
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27417
|
-
*
|
|
27418
|
-
* @category Channel Events
|
|
27419
|
-
*/
|
|
27420
|
-
const onSubChannelUpdated = (callback) => {
|
|
27421
|
-
const client = getActiveClient();
|
|
27422
|
-
const filter = (rawPayload) => {
|
|
27423
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27424
|
-
ingestInCache(payload);
|
|
27425
|
-
callback(payload.messageFeeds[0]);
|
|
27426
|
-
};
|
|
27427
|
-
return createEventSubscriber(client, 'onSubChannelUpdated', 'message-feed.updated', filter);
|
|
27428
|
-
};
|
|
27429
|
-
|
|
27430
|
-
/**
|
|
27431
|
-
* ```js
|
|
27432
|
-
* import { onSubChannelDeleted } from '@amityco/ts-sdk'
|
|
27433
|
-
* const dispose = onSubChannelDeleted(subChannel => {
|
|
27434
|
-
* // ...
|
|
27435
|
-
* })
|
|
27436
|
-
* ```
|
|
27437
|
-
*
|
|
27438
|
-
* Fired when any {@link Amity.SubChannel} have been deleted
|
|
27439
|
-
*
|
|
27440
|
-
* @param callback The function to call when the event was fired
|
|
27441
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27442
|
-
*
|
|
27443
|
-
* @category Channel Events
|
|
27444
|
-
*/
|
|
27445
|
-
const onSubChannelDeleted = (callback) => {
|
|
27446
|
-
const client = getActiveClient();
|
|
27447
|
-
const filter = (rawPayload) => {
|
|
27448
|
-
const payload = prepareSubChannelPayload(rawPayload);
|
|
27449
|
-
ingestInCache(payload);
|
|
27450
|
-
callback(payload.messageFeeds[0]);
|
|
27451
|
-
};
|
|
27452
|
-
const disposers = [
|
|
27453
|
-
createEventSubscriber(client, 'onSubChannelDeleted', 'message-feed.deleted', filter),
|
|
27454
|
-
createEventSubscriber(client, 'local.message-feed.deleted', 'local.message-feed.deleted', payload => callback(payload.messageFeeds[0])),
|
|
27455
|
-
];
|
|
27456
|
-
return () => {
|
|
27457
|
-
disposers.forEach(fn => fn());
|
|
27458
|
-
};
|
|
27459
|
-
};
|
|
27460
|
-
|
|
27461
28205
|
/** @hidden */
|
|
27462
28206
|
const onSubChannelFetched = (callback) => {
|
|
27463
28207
|
return createEventSubscriber(getActiveClient(), 'onSubChannelFetched', 'local.message-feed.fetched', payload => callback(payload.messageFeeds[0]));
|
|
@@ -27490,6 +28234,27 @@ const liveSubChannel = (subChannelId, callback) => {
|
|
|
27490
28234
|
]);
|
|
27491
28235
|
};
|
|
27492
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
|
+
|
|
27493
28258
|
/**
|
|
27494
28259
|
* ```js
|
|
27495
28260
|
* import { liveSubChannels } from '@amityco/ts-sdk';
|
|
@@ -27574,30 +28339,6 @@ const liveSubChannels = (params, callback, config) => {
|
|
|
27574
28339
|
};
|
|
27575
28340
|
};
|
|
27576
28341
|
|
|
27577
|
-
/**
|
|
27578
|
-
* ```js
|
|
27579
|
-
* import { onMessageFetched } from '@amityco/ts-sdk'
|
|
27580
|
-
* const dispose = onMessageFetched(message => {
|
|
27581
|
-
* // ...
|
|
27582
|
-
* })
|
|
27583
|
-
* ```
|
|
27584
|
-
*
|
|
27585
|
-
* Fired when an {@link Amity.Message} has been fetched
|
|
27586
|
-
*
|
|
27587
|
-
* @param callback The function to call when the event was fired
|
|
27588
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27589
|
-
*
|
|
27590
|
-
* @category Message Events
|
|
27591
|
-
*/
|
|
27592
|
-
const onMessageFetched = (callback) => {
|
|
27593
|
-
const client = getActiveClient();
|
|
27594
|
-
const filter = (payload) => {
|
|
27595
|
-
ingestInCache(payload);
|
|
27596
|
-
callback(payload.messages[0]);
|
|
27597
|
-
};
|
|
27598
|
-
return createEventSubscriber(client, 'message/onMessageFetched', 'local.message.fetched', filter);
|
|
27599
|
-
};
|
|
27600
|
-
|
|
27601
28342
|
/**
|
|
27602
28343
|
* ```js
|
|
27603
28344
|
* import { liveMessage } from '@amityco/ts-sdk';
|
|
@@ -30602,6 +31343,7 @@ exports.CommunityPostSettings = CommunityPostSettings;
|
|
|
30602
31343
|
exports.ContentFeedType = ContentFeedType;
|
|
30603
31344
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
30604
31345
|
exports.FileType = FileType;
|
|
31346
|
+
exports.MARKER_INCLUDED_SUB_CHANNEL_TYPE = MARKER_INCLUDED_SUB_CHANNEL_TYPE;
|
|
30605
31347
|
exports.MessageContentType = MessageContentType;
|
|
30606
31348
|
exports.PostContentType = PostContentType;
|
|
30607
31349
|
exports.VERSION = VERSION;
|
|
@@ -30619,6 +31361,8 @@ exports.backupCache = backupCache;
|
|
|
30619
31361
|
exports.banChannelMembers = banChannelMembers;
|
|
30620
31362
|
exports.closePoll = closePoll;
|
|
30621
31363
|
exports.connectClient = connectClient;
|
|
31364
|
+
exports.convertFromRaw = convertFromRaw$1;
|
|
31365
|
+
exports.convertQueryParams = convertQueryParams;
|
|
30622
31366
|
exports.createChannel = createChannel;
|
|
30623
31367
|
exports.createClient = createClient;
|
|
30624
31368
|
exports.createComment = createComment;
|
|
@@ -30658,8 +31402,10 @@ exports.filterByPropEquality = filterByPropEquality;
|
|
|
30658
31402
|
exports.filterByPropInclusion = filterByPropInclusion;
|
|
30659
31403
|
exports.follow = follow;
|
|
30660
31404
|
exports.getActiveClient = getActiveClient;
|
|
31405
|
+
exports.getActiveUser = getActiveUser;
|
|
30661
31406
|
exports.getCategory = getCategory;
|
|
30662
31407
|
exports.getChannel = getChannel;
|
|
31408
|
+
exports.getChannelMarkers = getChannelMarkers;
|
|
30663
31409
|
exports.getChannelTopic = getChannelTopic;
|
|
30664
31410
|
exports.getChannels = getChannels;
|
|
30665
31411
|
exports.getComment = getComment;
|
|
@@ -30671,7 +31417,9 @@ exports.getCommunityTopic = getCommunityTopic;
|
|
|
30671
31417
|
exports.getFeedSettings = getFeedSettings;
|
|
30672
31418
|
exports.getFile = getFile;
|
|
30673
31419
|
exports.getFollowInfo = getFollowInfo;
|
|
31420
|
+
exports.getMarkerSyncEvents = getMarkerSyncEvents;
|
|
30674
31421
|
exports.getMessage = getMessage;
|
|
31422
|
+
exports.getMessageMarkers = getMessageMarkers;
|
|
30675
31423
|
exports.getMessageTopic = getMessageTopic;
|
|
30676
31424
|
exports.getMessages = getMessages;
|
|
30677
31425
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
@@ -30688,10 +31436,14 @@ exports.getSmartFeedMessageTopic = getSmartFeedMessageTopic;
|
|
|
30688
31436
|
exports.getSmartFeedSubChannelTopic = getSmartFeedSubChannelTopic;
|
|
30689
31437
|
exports.getStream = getStream;
|
|
30690
31438
|
exports.getSubChannel = getSubChannel;
|
|
31439
|
+
exports.getSubChannelMarkers = getSubChannelMarkers;
|
|
30691
31440
|
exports.getSubChannelTopic = getSubChannelTopic;
|
|
30692
31441
|
exports.getSubChannels = getSubChannels;
|
|
30693
31442
|
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
31443
|
+
exports.getTotalUnreadCount = getTotalUnreadCount;
|
|
31444
|
+
exports.getUnreadCount = getUnreadCount$1;
|
|
30694
31445
|
exports.getUser = getUser;
|
|
31446
|
+
exports.getUserMarker = getUserMarker;
|
|
30695
31447
|
exports.getUserTopic = getUserTopic;
|
|
30696
31448
|
exports.getUsers = getUsers;
|
|
30697
31449
|
exports.isAfterBefore = isAfterBefore;
|
|
@@ -30706,6 +31458,7 @@ exports.isOffline = isOffline;
|
|
|
30706
31458
|
exports.isPaged = isPaged;
|
|
30707
31459
|
exports.isReportedByMe = isReportedByMe;
|
|
30708
31460
|
exports.isSkip = isSkip;
|
|
31461
|
+
exports.isUnreadCountSupport = isUnreadCountSupport$1;
|
|
30709
31462
|
exports.joinChannel = joinChannel;
|
|
30710
31463
|
exports.joinCommunity = joinCommunity;
|
|
30711
31464
|
exports.leaveChannel = leaveChannel;
|
|
@@ -30731,6 +31484,9 @@ exports.liveSubChannel = liveSubChannel;
|
|
|
30731
31484
|
exports.liveSubChannels = liveSubChannels;
|
|
30732
31485
|
exports.liveUser = liveUser;
|
|
30733
31486
|
exports.liveUsers = liveUsers;
|
|
31487
|
+
exports.markAsDelivered = markAsDelivered;
|
|
31488
|
+
exports.markerSync = markerSync;
|
|
31489
|
+
exports.markerSyncTrigger = markerSyncTrigger;
|
|
30734
31490
|
exports.mergeInCache = mergeInCache;
|
|
30735
31491
|
exports.observeChannel = observeChannel;
|
|
30736
31492
|
exports.observeChannels = observeChannels;
|
|
@@ -30751,6 +31507,7 @@ exports.onChannelCreated = onChannelCreated;
|
|
|
30751
31507
|
exports.onChannelDeleted = onChannelDeleted;
|
|
30752
31508
|
exports.onChannelJoined = onChannelJoined;
|
|
30753
31509
|
exports.onChannelLeft = onChannelLeft;
|
|
31510
|
+
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
30754
31511
|
exports.onChannelMemberAdded = onChannelMemberAdded;
|
|
30755
31512
|
exports.onChannelMemberBanned = onChannelMemberBanned;
|
|
30756
31513
|
exports.onChannelMemberRemoved = onChannelMemberRemoved;
|
|
@@ -30779,6 +31536,7 @@ exports.onCommunityUserRoleAdded = onCommunityUserRoleAdded;
|
|
|
30779
31536
|
exports.onCommunityUserRoleRemoved = onCommunityUserRoleRemoved;
|
|
30780
31537
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
30781
31538
|
exports.onConnectionError = onConnectionError;
|
|
31539
|
+
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
30782
31540
|
exports.onFollowInfoUpdated = onFollowInfoUpdated;
|
|
30783
31541
|
exports.onFollowRequestAccepted = onFollowRequestAccepted;
|
|
30784
31542
|
exports.onFollowRequestCanceled = onFollowRequestCanceled;
|
|
@@ -30787,8 +31545,10 @@ exports.onFollowerDeleted = onFollowerDeleted;
|
|
|
30787
31545
|
exports.onFollowerRequested = onFollowerRequested;
|
|
30788
31546
|
exports.onMessageCreated = onMessageCreated;
|
|
30789
31547
|
exports.onMessageDeleted = onMessageDeleted;
|
|
31548
|
+
exports.onMessageFetched = onMessageFetched;
|
|
30790
31549
|
exports.onMessageFlagCleared = onMessageFlagCleared;
|
|
30791
31550
|
exports.onMessageFlagged = onMessageFlagged;
|
|
31551
|
+
exports.onMessageMarkerFetched = onMessageMarkerFetched;
|
|
30792
31552
|
exports.onMessageReactionAdded = onMessageReactionAdded;
|
|
30793
31553
|
exports.onMessageReactionRemoved = onMessageReactionRemoved;
|
|
30794
31554
|
exports.onMessageUnflagged = onMessageUnflagged;
|
|
@@ -30814,15 +31574,20 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
30814
31574
|
exports.onStreamStopped = onStreamStopped;
|
|
30815
31575
|
exports.onSubChannelCreated = onSubChannelCreated;
|
|
30816
31576
|
exports.onSubChannelDeleted = onSubChannelDeleted;
|
|
31577
|
+
exports.onSubChannelMarkerFetched = onSubChannelMarkerFetched;
|
|
31578
|
+
exports.onSubChannelMarkerUpdated = onSubChannelMarkerUpdated;
|
|
30817
31579
|
exports.onSubChannelUpdated = onSubChannelUpdated;
|
|
30818
31580
|
exports.onUserDeleted = onUserDeleted;
|
|
30819
31581
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
30820
31582
|
exports.onUserFlagged = onUserFlagged;
|
|
30821
31583
|
exports.onUserFollowed = onUserFollowed;
|
|
31584
|
+
exports.onUserMarkerFetched = onUserMarkerFetched;
|
|
30822
31585
|
exports.onUserUnflagged = onUserUnflagged;
|
|
30823
31586
|
exports.onUserUnfollowed = onUserUnfollowed;
|
|
30824
31587
|
exports.onUserUpdated = onUserUpdated;
|
|
31588
|
+
exports.prepareSubChannelPayload = prepareSubChannelPayload;
|
|
30825
31589
|
exports.pullFromCache = pullFromCache;
|
|
31590
|
+
exports.pushMarkerSyncEvent = pushMarkerSyncEvent;
|
|
30826
31591
|
exports.pushToCache = pushToCache;
|
|
30827
31592
|
exports.queryCache = queryCache;
|
|
30828
31593
|
exports.queryCategories = queryCategories;
|
|
@@ -30850,6 +31615,8 @@ exports.removeReaction = removeReaction;
|
|
|
30850
31615
|
exports.renewal = renewal;
|
|
30851
31616
|
exports.restoreCache = restoreCache;
|
|
30852
31617
|
exports.runQuery = runQuery;
|
|
31618
|
+
exports.setActiveUser = setActiveUser;
|
|
31619
|
+
exports.setMarkerSyncEvents = setMarkerSyncEvents;
|
|
30853
31620
|
exports.sortByChannelSegment = sortByChannelSegment;
|
|
30854
31621
|
exports.sortByDisplayName = sortByDisplayName;
|
|
30855
31622
|
exports.sortByFirstCreated = sortByFirstCreated;
|
|
@@ -30858,7 +31625,11 @@ exports.sortByLastCreated = sortByLastCreated;
|
|
|
30858
31625
|
exports.sortByName = sortByName;
|
|
30859
31626
|
exports.sortBySegmentNumber = sortBySegmentNumber;
|
|
30860
31627
|
exports.startReading = startReading;
|
|
31628
|
+
exports.startReadingAPI = startReadingAPI;
|
|
31629
|
+
exports.startUnreadSync = startUnreadSync;
|
|
30861
31630
|
exports.stopReading = stopReading;
|
|
31631
|
+
exports.stopReadingAPI = stopReadingAPI;
|
|
31632
|
+
exports.stopUnreadSyncing = stopUnreadSyncing;
|
|
30862
31633
|
exports.subscribeTopic = subscribeTopic;
|
|
30863
31634
|
exports.toPage = toPage;
|
|
30864
31635
|
exports.toPageRaw = toPageRaw;
|
|
@@ -30872,6 +31643,7 @@ exports.updateMessage = updateMessage;
|
|
|
30872
31643
|
exports.updatePost = updatePost;
|
|
30873
31644
|
exports.updateStream = updateStream;
|
|
30874
31645
|
exports.updateSubChannel = updateSubChannel;
|
|
31646
|
+
exports.updateSubChannelMarker = updateSubChannelMarker;
|
|
30875
31647
|
exports.updateUser = updateUser;
|
|
30876
31648
|
exports.upsertInCache = upsertInCache;
|
|
30877
31649
|
exports.votePoll = votePoll;
|