@amityco/ts-sdk 6.2.0 → 6.2.1-0cf9bee.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/@types/core/events.d.ts +1 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +4 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/marker.d.ts +2 -1
- package/dist/@types/domains/marker.d.ts.map +1 -1
- package/dist/channelRepsitory/api/createChannel.d.ts +1 -1
- package/dist/channelRepsitory/api/markAsRead.d.ts +1 -1
- package/dist/channelRepsitory/api/muteChannel.d.ts.map +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/communityRepository/{communityModeration → communityMembership}/api/addMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/api/index.d.ts +3 -0
- package/dist/communityRepository/communityMembership/api/index.d.ts.map +1 -0
- package/dist/communityRepository/{communityModeration → communityMembership}/api/removeMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/api/tests/addMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/api/tests/removeMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/index.d.ts +1 -0
- package/dist/communityRepository/communityMembership/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/banMembers.d.ts +16 -0
- package/dist/communityRepository/communityModeration/api/banMembers.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/index.d.ts +2 -2
- package/dist/communityRepository/communityModeration/api/index.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/test/banMembers.test.d.ts +2 -0
- package/dist/communityRepository/communityModeration/api/test/banMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/test/unbanMembers.test.d.ts +2 -0
- package/dist/communityRepository/communityModeration/api/test/unbanMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts +16 -0
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +1 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/core/transports/mqtt.d.ts +1 -1
- package/dist/core/transports/mqtt.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +36 -0
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -0
- package/dist/feedRepository/api/index.d.ts +1 -0
- package/dist/feedRepository/api/index.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/test/getCustomRankingGlobalFeed.test.d.ts +2 -0
- package/dist/feedRepository/api/test/getCustomRankingGlobalFeed.test.d.ts.map +1 -0
- package/dist/fileRepository/api/index.d.ts +3 -3
- package/dist/fileRepository/api/test/uploadFile.test.d.ts +2 -0
- package/dist/fileRepository/api/test/uploadFile.test.d.ts.map +1 -0
- package/dist/fileRepository/api/test/uploadImage.test.d.ts +2 -0
- package/dist/fileRepository/api/test/uploadImage.test.d.ts.map +1 -0
- package/dist/fileRepository/api/test/uploadVideo.test.d.ts +2 -0
- package/dist/fileRepository/api/test/uploadVideo.test.d.ts.map +1 -0
- package/dist/fileRepository/api/{createFile.d.ts → uploadFile.d.ts} +4 -4
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -0
- package/dist/fileRepository/api/{createImage.d.ts → uploadImage.d.ts} +4 -4
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -0
- package/dist/fileRepository/api/{createVideo.d.ts → uploadVideo.d.ts} +5 -5
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -0
- package/dist/index.cjs.js +795 -193
- package/dist/index.esm.js +794 -194
- package/dist/index.umd.js +4 -4
- package/dist/marker/events/index.d.ts +1 -0
- package/dist/marker/events/index.d.ts.map +1 -1
- package/dist/marker/events/onFeedlMarkerUpdated.d.ts +17 -0
- package/dist/marker/events/onFeedlMarkerUpdated.d.ts.map +1 -0
- package/dist/messageRepository/api/createMessage.d.ts +1 -1
- package/dist/messageRepository/api/editMessage.d.ts +38 -0
- package/dist/messageRepository/api/editMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/flagMessage.d.ts +14 -0
- package/dist/messageRepository/api/flagMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/index.d.ts +5 -1
- package/dist/messageRepository/api/index.d.ts.map +1 -1
- package/dist/messageRepository/api/isMessageFlaggedByMe.d.ts +14 -0
- package/dist/messageRepository/api/isMessageFlaggedByMe.d.ts.map +1 -0
- package/dist/messageRepository/api/markAsDelivered.d.ts +2 -2
- package/dist/messageRepository/api/{deleteMessage.d.ts → softDeleteMessage.d.ts} +6 -6
- package/dist/messageRepository/api/softDeleteMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/editMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/editMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/flagMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/flagMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/unflagMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/unflagMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/unflagMessage.d.ts +14 -0
- package/dist/messageRepository/api/unflagMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/updateMessage.d.ts.map +1 -1
- package/dist/postRepository/api/deletePost.d.ts +1 -1
- package/dist/postRepository/api/deletePost.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +24 -0
- package/dist/postRepository/api/editPost.d.ts.map +1 -0
- package/dist/postRepository/api/flagPost.d.ts +14 -0
- package/dist/postRepository/api/flagPost.d.ts.map +1 -0
- package/dist/postRepository/api/hardDeletePost.d.ts +16 -0
- package/dist/postRepository/api/hardDeletePost.d.ts.map +1 -0
- package/dist/postRepository/api/index.d.ts +6 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/api/isPostFlaggedByMe.d.ts +14 -0
- package/dist/postRepository/api/isPostFlaggedByMe.d.ts.map +1 -0
- package/dist/postRepository/api/softDeletePost.d.ts +16 -0
- package/dist/postRepository/api/softDeletePost.d.ts.map +1 -0
- package/dist/postRepository/api/unflagPost.d.ts +14 -0
- package/dist/postRepository/api/unflagPost.d.ts.map +1 -0
- package/dist/postRepository/api/updatePost.d.ts.map +1 -1
- package/dist/subChannelRepository/api/startReadingAPI.d.ts.map +1 -1
- package/dist/subChannelRepository/api/stopReadingAPI.d.ts.map +1 -1
- package/dist/userRepository/api/flagUser.d.ts +14 -0
- package/dist/userRepository/api/flagUser.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +3 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts +14 -0
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts.map +1 -0
- package/dist/userRepository/{relationship/block/api → api}/queryBlockedUsers.d.ts +2 -2
- package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -0
- package/dist/userRepository/api/tests/flagUser.test.d.ts +2 -0
- package/dist/userRepository/api/tests/flagUser.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/queryBlockedUsers.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/unflagUser.test.d.ts +2 -0
- package/dist/userRepository/api/tests/unflagUser.test.d.ts.map +1 -0
- package/dist/userRepository/api/unflagUser.d.ts +14 -0
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers.d.ts +2 -0
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -0
- package/dist/userRepository/observers/index.d.ts +1 -0
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +1 -0
- package/src/@types/core/payload.ts +5 -0
- package/src/@types/domains/channel.ts +7 -2
- package/src/@types/domains/marker.ts +1 -0
- package/src/categoryRepository/observers/getCategories.ts +4 -4
- package/src/channelRepsitory/api/markAsRead.ts +1 -1
- package/src/channelRepsitory/api/muteChannel.ts +8 -0
- package/src/channelRepsitory/api/tests/muteChannel.test.ts +12 -0
- package/src/channelRepsitory/channelMembership/observers/getMembers.ts +6 -6
- package/src/channelRepsitory/observers/getChannels.ts +5 -5
- package/src/channelRepsitory/observers/tests/getChannels.test.ts +3 -9
- package/src/client/utils/markerSyncEngine.ts +2 -14
- package/src/commentRepository/observers/getComments.ts +5 -5
- package/src/communityRepository/communityMembership/api/index.ts +2 -0
- package/src/communityRepository/{communityModeration/api/test → communityMembership/api/tests}/addMembers.test.ts +1 -1
- package/src/communityRepository/{communityModeration/api/test → communityMembership/api/tests}/removeMembers.test.ts +1 -1
- package/src/communityRepository/communityMembership/index.ts +1 -0
- package/src/communityRepository/communityMembership/observers/getMembers.ts +6 -8
- package/src/communityRepository/communityModeration/api/banMembers.ts +50 -0
- package/src/communityRepository/communityModeration/api/index.ts +3 -2
- package/src/communityRepository/communityModeration/api/test/banMembers.test.ts +70 -0
- package/src/communityRepository/communityModeration/api/test/unbanMembers.test.ts +70 -0
- package/src/communityRepository/communityModeration/api/unbanMembers.ts +50 -0
- package/src/communityRepository/observers/getCommunities.ts +5 -5
- package/src/core/query/filtering.ts +22 -2
- package/src/core/query/sorting.ts +2 -4
- package/src/core/query/tests/filtering.test.ts +6 -0
- package/src/core/query/tests/runQuery.test.ts +3 -3
- package/src/core/transports/mqtt.ts +3 -2
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +117 -0
- package/src/feedRepository/api/index.ts +1 -0
- package/src/feedRepository/api/queryGlobalFeed.ts +12 -4
- package/src/feedRepository/api/test/getCustomRankingGlobalFeed.test.ts +130 -0
- package/src/feedRepository/api/test/queryGlobalFeed.test.ts +1 -15
- package/src/fileRepository/api/index.ts +3 -3
- package/src/fileRepository/api/test/uploadFile.test.ts +69 -0
- package/src/fileRepository/api/test/{createImage.test.ts → uploadImage.test.ts} +7 -7
- package/src/fileRepository/api/test/{createVideo.test.ts → uploadVideo.test.ts} +8 -8
- package/src/fileRepository/api/{createFile.ts → uploadFile.ts} +4 -6
- package/src/fileRepository/api/{createImage.ts → uploadImage.ts} +4 -6
- package/src/fileRepository/api/{createVideo.ts → uploadVideo.ts} +5 -7
- package/src/marker/events/index.ts +1 -0
- package/src/marker/events/onFeedlMarkerUpdated.ts +34 -0
- package/src/messageRepository/api/editMessage.ts +100 -0
- package/src/messageRepository/api/flagMessage.ts +40 -0
- package/src/messageRepository/api/index.ts +7 -1
- package/src/messageRepository/api/isMessageFlaggedByMe.ts +30 -0
- package/src/messageRepository/api/markAsDelivered.ts +2 -2
- package/src/messageRepository/api/{deleteMessage.ts → softDeleteMessage.ts} +8 -8
- package/src/messageRepository/api/tests/deleteMessage.test.ts +11 -11
- package/src/messageRepository/api/tests/{updateMessage.test.ts → editMessage.test.ts} +10 -10
- package/src/messageRepository/api/tests/flagMessage.test.ts +87 -0
- package/src/messageRepository/api/tests/unflagMessage.test.ts +87 -0
- package/src/messageRepository/api/unflagMessage.ts +40 -0
- package/src/messageRepository/api/updateMessage.ts +4 -0
- package/src/messageRepository/events/onMessageDeleted.ts +1 -1
- package/src/messageRepository/observers/getMessages.ts +5 -5
- package/src/postRepository/api/deletePost.ts +1 -7
- package/src/postRepository/api/editPost.ts +58 -0
- package/src/postRepository/api/flagPost.ts +38 -0
- package/src/postRepository/api/hardDeletePost.ts +30 -0
- package/src/postRepository/api/index.ts +8 -0
- package/src/postRepository/api/isPostFlaggedByMe.ts +33 -0
- package/src/postRepository/api/softDeletePost.ts +30 -0
- package/src/postRepository/api/unflagPost.ts +39 -0
- package/src/postRepository/api/updatePost.ts +4 -0
- package/src/postRepository/observers/getPosts.ts +5 -5
- package/src/reactionRepository/observers/getReactions.ts +4 -4
- package/src/report/api/createReport.ts +1 -1
- package/src/report/api/tests/createReport.test.ts +2 -62
- package/src/report/api/tests/deleteReport.test.ts +2 -62
- package/src/subChannelRepository/api/startReadingAPI.ts +13 -0
- package/src/subChannelRepository/api/stopReadingAPI.ts +13 -0
- package/src/userRepository/api/flagUser.ts +37 -0
- package/src/userRepository/api/index.ts +4 -0
- package/src/userRepository/api/isUserFlaggedByMe.ts +33 -0
- package/src/userRepository/{relationship/block/api → api}/queryBlockedUsers.ts +3 -2
- package/src/userRepository/api/tests/flagUser.test.ts +81 -0
- package/src/userRepository/{relationship/block/api → api}/tests/queryBlockedUsers.test.ts +1 -1
- package/src/userRepository/api/tests/unflagUser.test.ts +80 -0
- package/src/userRepository/api/unflagUser.ts +37 -0
- package/src/userRepository/observers/getBlockedUsers.ts +104 -0
- package/src/userRepository/observers/getUsers.ts +4 -4
- package/src/userRepository/observers/index.ts +1 -0
- package/src/userRepository/observers/tests/getUsers.test.ts +3 -9
- package/src/userRepository/relationship/block/observers/getBlockedUsers.ts +5 -96
- package/src/userRepository/relationship/follow/observers/getFollowers.ts +4 -4
- package/src/userRepository/relationship/follow/observers/getFollowings.ts +4 -4
- package/dist/communityRepository/communityModeration/api/test/addMembers.test.d.ts.map +0 -1
- package/dist/communityRepository/communityModeration/api/test/removeMembers.test.d.ts.map +0 -1
- package/dist/fileRepository/api/createFile.d.ts.map +0 -1
- package/dist/fileRepository/api/createImage.d.ts.map +0 -1
- package/dist/fileRepository/api/createVideo.d.ts.map +0 -1
- package/dist/fileRepository/api/test/createImage.test.d.ts +0 -2
- package/dist/fileRepository/api/test/createImage.test.d.ts.map +0 -1
- package/dist/fileRepository/api/test/createVideo.test.d.ts +0 -2
- package/dist/fileRepository/api/test/createVideo.test.d.ts.map +0 -1
- package/dist/messageRepository/api/deleteMessage.d.ts.map +0 -1
- package/dist/messageRepository/api/tests/updateMessage.test.d.ts +0 -2
- package/dist/messageRepository/api/tests/updateMessage.test.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/api/queryBlockedUsers.d.ts.map +0 -1
- package/dist/userRepository/relationship/block/api/tests/queryBlockedUsers.test.d.ts.map +0 -1
- /package/dist/communityRepository/{communityModeration → communityMembership}/api/addMembers.d.ts +0 -0
- /package/dist/communityRepository/{communityModeration → communityMembership}/api/removeMembers.d.ts +0 -0
- /package/dist/communityRepository/{communityModeration/api/test → communityMembership/api/tests}/addMembers.test.d.ts +0 -0
- /package/dist/communityRepository/{communityModeration/api/test → communityMembership/api/tests}/removeMembers.test.d.ts +0 -0
- /package/dist/userRepository/{relationship/block/api → api}/tests/queryBlockedUsers.test.d.ts +0 -0
- /package/src/communityRepository/{communityModeration → communityMembership}/api/addMembers.ts +0 -0
- /package/src/communityRepository/{communityModeration → communityMembership}/api/removeMembers.ts +0 -0
package/dist/index.cjs.js
CHANGED
|
@@ -1081,8 +1081,15 @@ const dropFromCache = (key, exact = false) => {
|
|
|
1081
1081
|
*
|
|
1082
1082
|
* @hidden
|
|
1083
1083
|
*/
|
|
1084
|
-
const filterByPropEquality = (collection, key, value) =>
|
|
1084
|
+
const filterByPropEquality = (collection, key, value) => value !== undefined
|
|
1085
|
+
? collection.filter(item => JSON.stringify(item[key]) === JSON.stringify(value))
|
|
1086
|
+
: collection;
|
|
1085
1087
|
const filterByPropInclusion = (collection, key, value) => (value !== undefined ? collection.filter(item => value.includes(item[key])) : collection);
|
|
1088
|
+
const filterByPropIntersection = (collection, key, values) => {
|
|
1089
|
+
if (!(values === null || values === void 0 ? void 0 : values.length))
|
|
1090
|
+
return collection;
|
|
1091
|
+
return collection.filter(item => Array.isArray(item[key]) && values.some(value => item[key].includes(value)));
|
|
1092
|
+
};
|
|
1086
1093
|
/**
|
|
1087
1094
|
* Filter a channel collection by membership of the userId
|
|
1088
1095
|
*
|
|
@@ -1216,7 +1223,11 @@ const filterByPostDataTypes = (collection, dataTypes) => {
|
|
|
1216
1223
|
* @hidden
|
|
1217
1224
|
*/
|
|
1218
1225
|
const filterBySearchTerm = (collection, searchTerm) => {
|
|
1219
|
-
|
|
1226
|
+
/*
|
|
1227
|
+
* Search term should match regardless of the case.
|
|
1228
|
+
* Hence, the flag "i", is passed to the created regex
|
|
1229
|
+
*/
|
|
1230
|
+
const containsMatcher = new RegExp(searchTerm, 'i');
|
|
1220
1231
|
return collection.filter(m => {
|
|
1221
1232
|
var _a;
|
|
1222
1233
|
if (m.userId.match(containsMatcher))
|
|
@@ -1239,11 +1250,7 @@ const sortByDisplayName = ({ displayName: a }, { displayName: b }) => {
|
|
|
1239
1250
|
/**
|
|
1240
1251
|
* Alphabetic sorting of objects having a name
|
|
1241
1252
|
*/
|
|
1242
|
-
const sortByName = ({ name: a }, { name: b }) =>
|
|
1243
|
-
if (a === b)
|
|
1244
|
-
return 0;
|
|
1245
|
-
return a < b ? -1 : 1;
|
|
1246
|
-
};
|
|
1253
|
+
const sortByName = ({ name: a }, { name: b }) => a.localeCompare(b);
|
|
1247
1254
|
/**
|
|
1248
1255
|
* Sorting a collection by their apparition order (oldest first)
|
|
1249
1256
|
*/
|
|
@@ -20504,7 +20511,8 @@ const createMqttTransport = (endpoint) => {
|
|
|
20504
20511
|
? new ASCError(error.message, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */)
|
|
20505
20512
|
: // TODO throw the actual error, once BE can tell us the actual error code
|
|
20506
20513
|
new ASCUnknownError(800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
20507
|
-
|
|
20514
|
+
// Use warning lv instead of error lv to prevent misunderstanding of user
|
|
20515
|
+
console.warn(`Failed to subscribe to topic ${topic}`, ascError);
|
|
20508
20516
|
callback === null || callback === void 0 ? void 0 : callback(ascError);
|
|
20509
20517
|
}
|
|
20510
20518
|
else {
|
|
@@ -21889,6 +21897,29 @@ const onFeedMarkerFetched = (callback) => {
|
|
|
21889
21897
|
return createEventSubscriber(client, 'feedMarker/onFeedMarkerFetched', 'local.feedMarker.fetched', filter);
|
|
21890
21898
|
};
|
|
21891
21899
|
|
|
21900
|
+
/**
|
|
21901
|
+
* ```js
|
|
21902
|
+
* import { onFeedMarkerUpdated } from '@amityco/ts-sdk'
|
|
21903
|
+
* const dispose = onFeedMarkerUpdated(feedMarker => {
|
|
21904
|
+
* // ...
|
|
21905
|
+
* })
|
|
21906
|
+
* ```
|
|
21907
|
+
*
|
|
21908
|
+
* Fired when an {@link Amity.FeedMarker} has been updated
|
|
21909
|
+
*
|
|
21910
|
+
* @param callback The function to call when the event was fired
|
|
21911
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
21912
|
+
*
|
|
21913
|
+
* @category FeedMarker Events
|
|
21914
|
+
*/
|
|
21915
|
+
const onFeedMarkerUpdated = (callback) => {
|
|
21916
|
+
const client = getActiveClient();
|
|
21917
|
+
const filter = (payload) => {
|
|
21918
|
+
callback(payload.feedMarkers[0]);
|
|
21919
|
+
};
|
|
21920
|
+
return createEventSubscriber(client, 'feedMarker/onFeedMarkerUpdated', 'marker.feed-updated', filter);
|
|
21921
|
+
};
|
|
21922
|
+
|
|
21892
21923
|
/**
|
|
21893
21924
|
* ```js
|
|
21894
21925
|
* import { onUserMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -22248,7 +22279,7 @@ const onMessageDeleted = (callback) => {
|
|
|
22248
22279
|
};
|
|
22249
22280
|
const disposers = [
|
|
22250
22281
|
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
22251
|
-
createEventSubscriber(client, '
|
|
22282
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
22252
22283
|
];
|
|
22253
22284
|
return () => {
|
|
22254
22285
|
disposers.forEach(fn => fn());
|
|
@@ -22583,9 +22614,14 @@ const startReadingAPI = async (messageFeedId) => {
|
|
|
22583
22614
|
const client = getActiveClient();
|
|
22584
22615
|
client.log('channel/startReadingAPI', messageFeedId);
|
|
22585
22616
|
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/start-reading`);
|
|
22617
|
+
const { userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers } = payload;
|
|
22586
22618
|
const cachedAt = client.cache && Date.now();
|
|
22587
22619
|
if (client.cache)
|
|
22588
22620
|
ingestInCache(payload, { cachedAt });
|
|
22621
|
+
feedMarkerReducer('local.feedMarker.fetched', feedMarkers);
|
|
22622
|
+
channelMarkerReducer('local.channelMarker.fetched', userEntityMarkers);
|
|
22623
|
+
subChannelMarkerReducer('local.subChannelMarker.fetched', userFeedMarkers);
|
|
22624
|
+
userMarkerReducer('local.userMarker.fetched', userMarkers);
|
|
22589
22625
|
return true;
|
|
22590
22626
|
};
|
|
22591
22627
|
|
|
@@ -22608,9 +22644,14 @@ const stopReadingAPI = async (messageFeedId) => {
|
|
|
22608
22644
|
const client = getActiveClient();
|
|
22609
22645
|
client.log('channel/stopReadingAPI', messageFeedId);
|
|
22610
22646
|
const { data: payload } = await client.http.post(`/api/v1/markers/message-feeds/${messageFeedId}/stop-reading`);
|
|
22647
|
+
const { userEntityMarkers, userFeedMarkers, feedMarkers, userMarkers } = payload;
|
|
22611
22648
|
const cachedAt = client.cache && Date.now();
|
|
22612
22649
|
if (client.cache)
|
|
22613
22650
|
ingestInCache(payload, { cachedAt });
|
|
22651
|
+
feedMarkerReducer('local.feedMarker.fetched', feedMarkers);
|
|
22652
|
+
channelMarkerReducer('local.channelMarker.fetched', userEntityMarkers);
|
|
22653
|
+
subChannelMarkerReducer('local.subChannelMarker.fetched', userFeedMarkers);
|
|
22654
|
+
userMarkerReducer('local.userMarker.fetched', userMarkers);
|
|
22614
22655
|
return true;
|
|
22615
22656
|
};
|
|
22616
22657
|
|
|
@@ -22811,7 +22852,6 @@ const onSubChannelDeleted = (callback) => {
|
|
|
22811
22852
|
};
|
|
22812
22853
|
};
|
|
22813
22854
|
|
|
22814
|
-
const FORCE_SYNC_INTERVAL_TIME = 8000;
|
|
22815
22855
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
22816
22856
|
let clearSyncTrigger;
|
|
22817
22857
|
let disposers = [];
|
|
@@ -22890,19 +22930,7 @@ const registerEventListeners = () => {
|
|
|
22890
22930
|
},
|
|
22891
22931
|
// only trigger sync from remote events to prevent an unread count equal `-1`
|
|
22892
22932
|
// when an optimistic message creation is performed.
|
|
22893
|
-
false), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */)),
|
|
22894
|
-
// In real-world use, we've encountered some cases where BE returns empty result
|
|
22895
|
-
// even if a marker changes in the database, causing the SDK to mistakenly believe that
|
|
22896
|
-
// no changes have been made in the database and end the sync prematurely.
|
|
22897
|
-
// Did miss update the unread count
|
|
22898
|
-
//
|
|
22899
|
-
// We found that some time BE loads were too high, causing the calculation
|
|
22900
|
-
// marker not to finish within the sync time, so it returned an empty value.
|
|
22901
|
-
//
|
|
22902
|
-
// Therefore, solve this problem by creating a second interval loop that
|
|
22903
|
-
// runs every 8 seconds regardless of whether an event occurs or not so that
|
|
22904
|
-
// the unread count is always updated in case of an error like the above.
|
|
22905
|
-
setIntervalTask(() => events.push("force sync" /* Amity.MarkerSyncEvent.FORCE_SYNC */), FORCE_SYNC_INTERVAL_TIME));
|
|
22933
|
+
false), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */)), onFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)));
|
|
22906
22934
|
};
|
|
22907
22935
|
const unRegisterEventListeners = () => {
|
|
22908
22936
|
disposers.forEach(fn => fn());
|
|
@@ -23008,8 +23036,8 @@ const unBlockUser = async (userId) => {
|
|
|
23008
23036
|
|
|
23009
23037
|
/**
|
|
23010
23038
|
* ```js
|
|
23011
|
-
* import {
|
|
23012
|
-
* const { data: users, prevPage, nextPage, total } = await queryBlockedUsers({ page: Amity.PageRaw, limit: number })
|
|
23039
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
23040
|
+
* const { data: users, prevPage, nextPage, total } = await UserRepository.queryBlockedUsers({ page: Amity.PageRaw, limit: number })
|
|
23013
23041
|
* ```
|
|
23014
23042
|
*
|
|
23015
23043
|
* @param query The query parameters
|
|
@@ -23084,7 +23112,7 @@ queryBlockedUsers.locally = (query = {}) => {
|
|
|
23084
23112
|
};
|
|
23085
23113
|
|
|
23086
23114
|
/* eslint-disable no-use-before-define */
|
|
23087
|
-
const getBlockedUsers = (params, callback, config) => {
|
|
23115
|
+
const getBlockedUsers$1 = (params, callback, config) => {
|
|
23088
23116
|
const { log, cache } = getActiveClient();
|
|
23089
23117
|
if (!cache) {
|
|
23090
23118
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
@@ -23116,15 +23144,15 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
23116
23144
|
* observers
|
|
23117
23145
|
*};
|
|
23118
23146
|
*/
|
|
23119
|
-
const onFetch = () => {
|
|
23147
|
+
const onFetch = (initial = false) => {
|
|
23120
23148
|
var _a, _b;
|
|
23121
23149
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23122
23150
|
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23123
|
-
if (users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
23151
|
+
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
23124
23152
|
return;
|
|
23125
23153
|
const query = createQuery(queryBlockedUsers, {
|
|
23126
23154
|
limit,
|
|
23127
|
-
token: toToken(collection === null || collection === void 0 ? void 0 : collection.params.page, 'afterbeforeraw'),
|
|
23155
|
+
token: toToken(!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined, 'afterbeforeraw'),
|
|
23128
23156
|
});
|
|
23129
23157
|
runQuery(query,
|
|
23130
23158
|
// @ts-ignore
|
|
@@ -23145,7 +23173,7 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
23145
23173
|
disposers.push(() => {
|
|
23146
23174
|
// @TODO -> update once observers added
|
|
23147
23175
|
});
|
|
23148
|
-
onFetch();
|
|
23176
|
+
onFetch(true);
|
|
23149
23177
|
return () => {
|
|
23150
23178
|
log(`getCategories(tmpid: ${timestamp}) > dispose`);
|
|
23151
23179
|
disposers.forEach(fn => fn());
|
|
@@ -23153,6 +23181,12 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
23153
23181
|
};
|
|
23154
23182
|
};
|
|
23155
23183
|
|
|
23184
|
+
/* eslint-disable no-use-before-define */
|
|
23185
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
23186
|
+
console.log('Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead.');
|
|
23187
|
+
return getBlockedUsers$1(params, callback, config);
|
|
23188
|
+
};
|
|
23189
|
+
|
|
23156
23190
|
/* begin_public_function
|
|
23157
23191
|
id: user.relationship.follow
|
|
23158
23192
|
*/
|
|
@@ -23780,13 +23814,13 @@ const getFollowers = (params, callback, config) => {
|
|
|
23780
23814
|
pushToCache(cacheKey, collection);
|
|
23781
23815
|
responder(collection);
|
|
23782
23816
|
};
|
|
23783
|
-
const onFetch = () => {
|
|
23784
|
-
var _a, _b, _c, _d
|
|
23817
|
+
const onFetch = (initial = false) => {
|
|
23818
|
+
var _a, _b, _c, _d;
|
|
23785
23819
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23786
23820
|
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23787
|
-
if (followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
23821
|
+
if (!initial && followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
23788
23822
|
return;
|
|
23789
|
-
const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (
|
|
23823
|
+
const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
23790
23824
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
23791
23825
|
const data = {
|
|
23792
23826
|
loading,
|
|
@@ -23802,7 +23836,7 @@ const getFollowers = (params, callback, config) => {
|
|
|
23802
23836
|
}, queryOptions(policy));
|
|
23803
23837
|
};
|
|
23804
23838
|
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
23805
|
-
onFetch();
|
|
23839
|
+
onFetch(true);
|
|
23806
23840
|
return () => {
|
|
23807
23841
|
log(`getFollowers(tmpid: ${timestamp}) > dispose`);
|
|
23808
23842
|
disposers.forEach(fn => fn());
|
|
@@ -23904,13 +23938,13 @@ const getFollowings = (params, callback, config) => {
|
|
|
23904
23938
|
pushToCache(cacheKey, collection);
|
|
23905
23939
|
responder(collection);
|
|
23906
23940
|
};
|
|
23907
|
-
const onFetch = () => {
|
|
23908
|
-
var _a, _b, _c, _d
|
|
23941
|
+
const onFetch = (initial = false) => {
|
|
23942
|
+
var _a, _b, _c, _d;
|
|
23909
23943
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23910
23944
|
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23911
|
-
if (followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
23945
|
+
if (!initial && followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
23912
23946
|
return;
|
|
23913
|
-
const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (
|
|
23947
|
+
const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
23914
23948
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
23915
23949
|
const data = {
|
|
23916
23950
|
loading,
|
|
@@ -23926,7 +23960,7 @@ const getFollowings = (params, callback, config) => {
|
|
|
23926
23960
|
}, queryOptions(policy));
|
|
23927
23961
|
};
|
|
23928
23962
|
disposers.push(onFollowerRequested(realtimeRouter('onRequested')), onFollowRequestAccepted(realtimeRouter('onAccepted')), onFollowRequestDeclined(realtimeRouter('onDeclined')), onFollowRequestCanceled(realtimeRouter('onCanceled')), onUserFollowed(realtimeRouter('onFollowed')), onUserUnfollowed(realtimeRouter('onUnfollowed')), onFollowerDeleted(realtimeRouter('onDeleted')));
|
|
23929
|
-
onFetch();
|
|
23963
|
+
onFetch(true);
|
|
23930
23964
|
return () => {
|
|
23931
23965
|
log(`getFollowings(tmpid: ${timestamp}) > dispose`);
|
|
23932
23966
|
disposers.forEach(fn => fn());
|
|
@@ -24092,6 +24126,86 @@ const updateUser = async (userId, patch) => {
|
|
|
24092
24126
|
};
|
|
24093
24127
|
/* end_public_function */
|
|
24094
24128
|
|
|
24129
|
+
/* begin_public_function
|
|
24130
|
+
id: user.flag
|
|
24131
|
+
*/
|
|
24132
|
+
/**
|
|
24133
|
+
* ```js
|
|
24134
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
24135
|
+
* const flagged = await UserRepository.flagUser('userId')
|
|
24136
|
+
* ```
|
|
24137
|
+
*
|
|
24138
|
+
* @param userId The ID of the user to add a be flagged
|
|
24139
|
+
* @returns the created report result
|
|
24140
|
+
*
|
|
24141
|
+
* @category User API
|
|
24142
|
+
* @async
|
|
24143
|
+
* */
|
|
24144
|
+
const flagUser = async (userId) => {
|
|
24145
|
+
const client = getActiveClient();
|
|
24146
|
+
client.log('user/flagUser', userId);
|
|
24147
|
+
const { data: payload } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
24148
|
+
if (client.cache) {
|
|
24149
|
+
ingestInCache(payload);
|
|
24150
|
+
}
|
|
24151
|
+
fireEvent('user.flagged', payload);
|
|
24152
|
+
return !!payload;
|
|
24153
|
+
};
|
|
24154
|
+
/* end_public_function */
|
|
24155
|
+
|
|
24156
|
+
/* begin_public_function
|
|
24157
|
+
id: user.unflag
|
|
24158
|
+
*/
|
|
24159
|
+
/**
|
|
24160
|
+
* ```js
|
|
24161
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
24162
|
+
* const unflagged = await UserRepository.unflagUser('post', postId)
|
|
24163
|
+
* ```
|
|
24164
|
+
*
|
|
24165
|
+
* @param userId The ID of the user to unflag
|
|
24166
|
+
* @returns the deleted report result
|
|
24167
|
+
*
|
|
24168
|
+
* @category User API
|
|
24169
|
+
* @async
|
|
24170
|
+
* */
|
|
24171
|
+
const unflagUser = async (userId) => {
|
|
24172
|
+
const client = getActiveClient();
|
|
24173
|
+
client.log('user/unflag', userId);
|
|
24174
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
24175
|
+
if (client.cache) {
|
|
24176
|
+
ingestInCache(payload);
|
|
24177
|
+
}
|
|
24178
|
+
fireEvent('user.unflagged', payload);
|
|
24179
|
+
return !!payload;
|
|
24180
|
+
};
|
|
24181
|
+
/* end_public_function */
|
|
24182
|
+
|
|
24183
|
+
/* begin_public_function
|
|
24184
|
+
id: user.check_flag_by_me
|
|
24185
|
+
*/
|
|
24186
|
+
/**
|
|
24187
|
+
* ```js
|
|
24188
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
24189
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe('post', postId)
|
|
24190
|
+
* ```
|
|
24191
|
+
*
|
|
24192
|
+
* @param userId The ID of the thing to check a report to.
|
|
24193
|
+
* @returns `true` if the report is created by me, `false` if doesn't.
|
|
24194
|
+
*
|
|
24195
|
+
* @category Report API
|
|
24196
|
+
* @async
|
|
24197
|
+
* */
|
|
24198
|
+
const isUserFlaggedByMe = async (userId) => {
|
|
24199
|
+
var _a, _b;
|
|
24200
|
+
const client = getActiveClient();
|
|
24201
|
+
client.log('user/isUserFlaggedByMe', userId);
|
|
24202
|
+
const { result, isFlagByMe } = (_a = (await synchronousWSCall(client, 'user.isFlagByMe', {
|
|
24203
|
+
userId,
|
|
24204
|
+
}))) !== null && _a !== void 0 ? _a : {};
|
|
24205
|
+
return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
|
|
24206
|
+
};
|
|
24207
|
+
/* end_public_function */
|
|
24208
|
+
|
|
24095
24209
|
/**
|
|
24096
24210
|
* ```js
|
|
24097
24211
|
* import { onUserUpdated } from '@amityco/ts-sdk'
|
|
@@ -24416,13 +24530,13 @@ const getUsers = (params, callback, config) => {
|
|
|
24416
24530
|
pushToCache(cacheKey, collection);
|
|
24417
24531
|
responder(collection);
|
|
24418
24532
|
};
|
|
24419
|
-
const onFetch = () => {
|
|
24533
|
+
const onFetch = (initial = false) => {
|
|
24420
24534
|
var _a, _b, _c;
|
|
24421
24535
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24422
24536
|
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24423
|
-
if (users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
24537
|
+
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
24424
24538
|
return;
|
|
24425
|
-
const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
24539
|
+
const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
24426
24540
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
24427
24541
|
const data = {
|
|
24428
24542
|
loading,
|
|
@@ -24438,7 +24552,7 @@ const getUsers = (params, callback, config) => {
|
|
|
24438
24552
|
}, queryOptions(policy));
|
|
24439
24553
|
};
|
|
24440
24554
|
disposers.push(onUserUpdated(realtimeRouter()), onUserDeleted(realtimeRouter()), onUserFlagged(realtimeRouter()), onUserUnflagged(realtimeRouter()), onUserFlagCleared(realtimeRouter()));
|
|
24441
|
-
onFetch();
|
|
24555
|
+
onFetch(true);
|
|
24442
24556
|
return () => {
|
|
24443
24557
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
24444
24558
|
disposers.forEach(fn => fn());
|
|
@@ -24491,6 +24605,9 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
24491
24605
|
Relationship: index$h,
|
|
24492
24606
|
getUserByIds: getUserByIds,
|
|
24493
24607
|
updateUser: updateUser,
|
|
24608
|
+
flagUser: flagUser,
|
|
24609
|
+
unflagUser: unflagUser,
|
|
24610
|
+
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
24494
24611
|
onUserUpdated: onUserUpdated,
|
|
24495
24612
|
onUserDeleted: onUserDeleted,
|
|
24496
24613
|
onUserFlagged: onUserFlagged,
|
|
@@ -24498,7 +24615,8 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
24498
24615
|
onUserFlagCleared: onUserFlagCleared,
|
|
24499
24616
|
getUser: getUser,
|
|
24500
24617
|
getUsers: getUsers,
|
|
24501
|
-
observeUser: observeUser
|
|
24618
|
+
observeUser: observeUser,
|
|
24619
|
+
getBlockedUsers: getBlockedUsers$1
|
|
24502
24620
|
});
|
|
24503
24621
|
|
|
24504
24622
|
/* begin_public_function
|
|
@@ -24565,8 +24683,8 @@ getFile.locally = (fileId) => {
|
|
|
24565
24683
|
*/
|
|
24566
24684
|
/**
|
|
24567
24685
|
* ```js
|
|
24568
|
-
* import {
|
|
24569
|
-
* const created = await
|
|
24686
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
24687
|
+
* const created = await FileRepository.uploadFile(formData)
|
|
24570
24688
|
* ```
|
|
24571
24689
|
*
|
|
24572
24690
|
* Creates an {@link Amity.File}
|
|
@@ -24578,9 +24696,9 @@ getFile.locally = (fileId) => {
|
|
|
24578
24696
|
* @category File API
|
|
24579
24697
|
* @async
|
|
24580
24698
|
*/
|
|
24581
|
-
const
|
|
24699
|
+
const uploadFile = async (formData, onProgress) => {
|
|
24582
24700
|
const client = getActiveClient();
|
|
24583
|
-
client.log('file/
|
|
24701
|
+
client.log('file/uploadFile', formData);
|
|
24584
24702
|
if (!formData.getAll('files').length)
|
|
24585
24703
|
throw new Error('The formData object must have a `files` key.');
|
|
24586
24704
|
const headers = 'getHeaders' in formData
|
|
@@ -24602,8 +24720,7 @@ const createFile = async (formData, onProgress) => {
|
|
|
24602
24720
|
cachedAt,
|
|
24603
24721
|
};
|
|
24604
24722
|
};
|
|
24605
|
-
/* end_public_function */
|
|
24606
|
-
// TODO: consider doing local creation with URL.createObjectURL()
|
|
24723
|
+
/* end_public_function */
|
|
24607
24724
|
|
|
24608
24725
|
/* begin_public_function
|
|
24609
24726
|
id: file.delete
|
|
@@ -24648,8 +24765,8 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
24648
24765
|
*/
|
|
24649
24766
|
/**
|
|
24650
24767
|
* ```js
|
|
24651
|
-
* import {
|
|
24652
|
-
* const created = await
|
|
24768
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
24769
|
+
* const created = await FileRepository.uploadVideo(formData)
|
|
24653
24770
|
* ```
|
|
24654
24771
|
*
|
|
24655
24772
|
* Creates an {@link Amity.File<'video'>}
|
|
@@ -24657,14 +24774,14 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
24657
24774
|
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
24658
24775
|
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
24659
24776
|
* @param onProgress The callback to track the upload progress
|
|
24660
|
-
* @returns The newly
|
|
24777
|
+
* @returns The newly uploaded {@link Amity.File<'video'>}
|
|
24661
24778
|
*
|
|
24662
24779
|
* @category File API
|
|
24663
24780
|
* @async
|
|
24664
24781
|
*/
|
|
24665
|
-
const
|
|
24782
|
+
const uploadVideo = async (formData, feedType, onProgress) => {
|
|
24666
24783
|
const client = getActiveClient();
|
|
24667
|
-
client.log('file/
|
|
24784
|
+
client.log('file/uploadVideo', formData);
|
|
24668
24785
|
if (!formData.getAll('files').length)
|
|
24669
24786
|
throw new Error('The formData object must have a `files` key.');
|
|
24670
24787
|
if (feedType) {
|
|
@@ -24689,16 +24806,15 @@ const createVideo = async (formData, feedType, onProgress) => {
|
|
|
24689
24806
|
cachedAt,
|
|
24690
24807
|
};
|
|
24691
24808
|
};
|
|
24692
|
-
/* end_public_function */
|
|
24693
|
-
// TODO: consider doing local creation with URL.createObjectURL()
|
|
24809
|
+
/* end_public_function */
|
|
24694
24810
|
|
|
24695
24811
|
/* begin_public_function
|
|
24696
24812
|
id: file.upload.image
|
|
24697
24813
|
*/
|
|
24698
24814
|
/**
|
|
24699
24815
|
* ```js
|
|
24700
|
-
* import {
|
|
24701
|
-
* const created = await
|
|
24816
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
24817
|
+
* const created = await FileRepository.uploadImage(formData)
|
|
24702
24818
|
* ```
|
|
24703
24819
|
*
|
|
24704
24820
|
* Creates an {@link Amity.File<'image'>}
|
|
@@ -24710,9 +24826,9 @@ const createVideo = async (formData, feedType, onProgress) => {
|
|
|
24710
24826
|
* @category File API
|
|
24711
24827
|
* @async
|
|
24712
24828
|
*/
|
|
24713
|
-
const
|
|
24829
|
+
const uploadImage = async (formData, onProgress) => {
|
|
24714
24830
|
const client = getActiveClient();
|
|
24715
|
-
client.log('file/
|
|
24831
|
+
client.log('file/uploadImage', formData);
|
|
24716
24832
|
if (!formData.getAll('files').length)
|
|
24717
24833
|
throw new Error('The formData object must have a `files` key.');
|
|
24718
24834
|
const headers = 'getHeaders' in formData
|
|
@@ -24734,8 +24850,7 @@ const createImage = async (formData, onProgress) => {
|
|
|
24734
24850
|
cachedAt,
|
|
24735
24851
|
};
|
|
24736
24852
|
};
|
|
24737
|
-
/* end_public_function */
|
|
24738
|
-
// TODO: consider doing local creation with URL.createObjectURL()
|
|
24853
|
+
/* end_public_function */
|
|
24739
24854
|
|
|
24740
24855
|
/**
|
|
24741
24856
|
* ```js
|
|
@@ -24778,11 +24893,11 @@ const observeFile = (fileId, callback) => {
|
|
|
24778
24893
|
var index$f = /*#__PURE__*/Object.freeze({
|
|
24779
24894
|
__proto__: null,
|
|
24780
24895
|
getFile: getFile,
|
|
24781
|
-
|
|
24896
|
+
uploadFile: uploadFile,
|
|
24782
24897
|
deleteFile: deleteFile,
|
|
24783
24898
|
fileUrlWithSize: fileUrlWithSize,
|
|
24784
|
-
|
|
24785
|
-
|
|
24899
|
+
uploadVideo: uploadVideo,
|
|
24900
|
+
uploadImage: uploadImage,
|
|
24786
24901
|
observeFile: observeFile
|
|
24787
24902
|
});
|
|
24788
24903
|
|
|
@@ -26047,13 +26162,13 @@ const getReactions = (params, callback, config) => {
|
|
|
26047
26162
|
pushToCache(cacheKey, collection);
|
|
26048
26163
|
responder(collection);
|
|
26049
26164
|
};
|
|
26050
|
-
const onFetch = () => {
|
|
26051
|
-
var _a, _b, _c, _d
|
|
26165
|
+
const onFetch = (initial = false) => {
|
|
26166
|
+
var _a, _b, _c, _d;
|
|
26052
26167
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26053
26168
|
const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26054
|
-
if (reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26169
|
+
if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26055
26170
|
return;
|
|
26056
|
-
const query = createQuery(queryReactions, Object.assign(Object.assign({}, queryParams), { page: (
|
|
26171
|
+
const query = createQuery(queryReactions, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
26057
26172
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26058
26173
|
const data = {
|
|
26059
26174
|
loading,
|
|
@@ -26071,7 +26186,7 @@ const getReactions = (params, callback, config) => {
|
|
|
26071
26186
|
}, queryOptions(policy));
|
|
26072
26187
|
};
|
|
26073
26188
|
disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, realtimeRouter('onRemoved')));
|
|
26074
|
-
onFetch();
|
|
26189
|
+
onFetch(true);
|
|
26075
26190
|
return () => {
|
|
26076
26191
|
log(`liveReactions(tmpid: ${timestamp}) > dispose`);
|
|
26077
26192
|
disposers.forEach(fn => fn());
|
|
@@ -26114,7 +26229,7 @@ var REFERENCE_TYPES = {
|
|
|
26114
26229
|
};
|
|
26115
26230
|
|
|
26116
26231
|
/* begin_public_function
|
|
26117
|
-
id:
|
|
26232
|
+
id: message.flag, post.flag, comment.flag
|
|
26118
26233
|
*/
|
|
26119
26234
|
/**
|
|
26120
26235
|
* ```js
|
|
@@ -26556,6 +26671,8 @@ const MUTE_FOREVER = -1;
|
|
|
26556
26671
|
const muteChannel = async (channelId, mutePeriod = MUTE_FOREVER) => {
|
|
26557
26672
|
const client = getActiveClient();
|
|
26558
26673
|
client.log('channel/muteChannel', channelId);
|
|
26674
|
+
if (mutePeriod !== MUTE_FOREVER && mutePeriod < 0)
|
|
26675
|
+
throw new ASCError(`Mute Period can only be positive numbers or ${MUTE_FOREVER}(mute forever)`, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
26559
26676
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/mute`, { mutePeriod });
|
|
26560
26677
|
const { success } = data;
|
|
26561
26678
|
return success;
|
|
@@ -26595,7 +26712,7 @@ const unmuteChannel = async (channelId) => {
|
|
|
26595
26712
|
|
|
26596
26713
|
/**
|
|
26597
26714
|
* ```js
|
|
26598
|
-
* import {
|
|
26715
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
26599
26716
|
* const success = await ChannelRepository.markAsRead('channelId')
|
|
26600
26717
|
* ```
|
|
26601
26718
|
*
|
|
@@ -27115,13 +27232,13 @@ const getChannels = (params, callback, config) => {
|
|
|
27115
27232
|
pushToCache(cacheKey, collection);
|
|
27116
27233
|
responder(collection);
|
|
27117
27234
|
};
|
|
27118
|
-
const onFetch = () => {
|
|
27235
|
+
const onFetch = (initial = false) => {
|
|
27119
27236
|
var _a, _b, _c;
|
|
27120
27237
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27121
27238
|
const channels = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27122
|
-
if (channels.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27239
|
+
if (!initial && channels.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27123
27240
|
return;
|
|
27124
|
-
const query = createQuery(queryChannels, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
27241
|
+
const query = createQuery(queryChannels, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
27125
27242
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27126
27243
|
const data = {
|
|
27127
27244
|
loading,
|
|
@@ -27137,11 +27254,11 @@ const getChannels = (params, callback, config) => {
|
|
|
27137
27254
|
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
27138
27255
|
};
|
|
27139
27256
|
disposers.push(onChannelCreated(realtimeRouter()), onChannelDeleted(realtimeRouter()), onChannelUpdated(realtimeRouter()), onChannelMuted(realtimeRouter()), onChannelJoined(realtimeRouter()), onChannelLeft(realtimeRouter()), onChannelMemberAdded(realtimeRouter()), onChannelMemberRemoved(realtimeRouter()), onMessageCreated(() => null));
|
|
27140
|
-
onFetch();
|
|
27257
|
+
onFetch(true);
|
|
27258
|
+
dropFromCache(cacheKey);
|
|
27141
27259
|
return () => {
|
|
27142
27260
|
log(`getChannels(tmpid: ${timestamp}) > dispose`);
|
|
27143
27261
|
disposers.forEach(fn => fn());
|
|
27144
|
-
dropFromCache(cacheKey);
|
|
27145
27262
|
};
|
|
27146
27263
|
};
|
|
27147
27264
|
/* end_public_function */
|
|
@@ -27341,7 +27458,7 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
27341
27458
|
.map(id => pullFromCache(['channelUsers', 'get', id]))
|
|
27342
27459
|
.filter(Boolean)
|
|
27343
27460
|
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
27344
|
-
channelMembers =
|
|
27461
|
+
channelMembers = filterByPropIntersection(channelMembers, 'roles', params.roles);
|
|
27345
27462
|
if (params.memberships) {
|
|
27346
27463
|
/*
|
|
27347
27464
|
* even though membership includes muted as a possible value
|
|
@@ -27393,13 +27510,13 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
27393
27510
|
pushToCache(cacheKey, collection);
|
|
27394
27511
|
responder(collection);
|
|
27395
27512
|
};
|
|
27396
|
-
const onFetch = () => {
|
|
27513
|
+
const onFetch = (initial = false) => {
|
|
27397
27514
|
var _a, _b, _c;
|
|
27398
27515
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27399
27516
|
const channelMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27400
|
-
if (channelMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27517
|
+
if (!initial && channelMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27401
27518
|
return;
|
|
27402
|
-
const query = createQuery(queryChannelMembers, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
27519
|
+
const query = createQuery(queryChannelMembers, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
27403
27520
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
27404
27521
|
const data = {
|
|
27405
27522
|
loading,
|
|
@@ -27415,7 +27532,7 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
27415
27532
|
}, queryOptions(policy));
|
|
27416
27533
|
};
|
|
27417
27534
|
disposers.push(onChannelJoined(realtimeRouter()), onChannelLeft(realtimeRouter()), onChannelMemberAdded(realtimeRouter()), onChannelMemberRemoved(realtimeRouter()), onChannelMemberBanned(realtimeRouter()), onChannelMemberUnbanned(realtimeRouter()));
|
|
27418
|
-
onFetch();
|
|
27535
|
+
onFetch(true);
|
|
27419
27536
|
return () => {
|
|
27420
27537
|
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
27421
27538
|
disposers.forEach(fn => fn());
|
|
@@ -27509,7 +27626,7 @@ const removeRole = async (channelId, roleId, userIds) => {
|
|
|
27509
27626
|
* @category Channel API
|
|
27510
27627
|
* @async
|
|
27511
27628
|
* */
|
|
27512
|
-
const banMembers = async (channelId, userIds) => {
|
|
27629
|
+
const banMembers$1 = async (channelId, userIds) => {
|
|
27513
27630
|
const client = getActiveClient();
|
|
27514
27631
|
client.log('channel/banMembers', { userIds, channelId });
|
|
27515
27632
|
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
@@ -27544,7 +27661,7 @@ const banMembers = async (channelId, userIds) => {
|
|
|
27544
27661
|
* @category Channel API
|
|
27545
27662
|
* @async
|
|
27546
27663
|
* */
|
|
27547
|
-
const unbanMembers = async (channelId, userIds) => {
|
|
27664
|
+
const unbanMembers$1 = async (channelId, userIds) => {
|
|
27548
27665
|
const client = getActiveClient();
|
|
27549
27666
|
client.log('channel/unbanMembers', { userIds, channelId });
|
|
27550
27667
|
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
@@ -27566,8 +27683,8 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
27566
27683
|
__proto__: null,
|
|
27567
27684
|
addRole: addRole,
|
|
27568
27685
|
removeRole: removeRole,
|
|
27569
|
-
banMembers: banMembers,
|
|
27570
|
-
unbanMembers: unbanMembers
|
|
27686
|
+
banMembers: banMembers$1,
|
|
27687
|
+
unbanMembers: unbanMembers$1
|
|
27571
27688
|
});
|
|
27572
27689
|
|
|
27573
27690
|
var index$b = /*#__PURE__*/Object.freeze({
|
|
@@ -27794,6 +27911,7 @@ createMessage.optimistically = (_a) => {
|
|
|
27794
27911
|
const updateMessage = async (messageId, patch) => {
|
|
27795
27912
|
const client = getActiveClient();
|
|
27796
27913
|
client.log('message/updateMessage', patch);
|
|
27914
|
+
console.warn('MessageRepository.updateMessage will be replaced with MessageRepository.editMessage');
|
|
27797
27915
|
const { data: payload } = await client.http.put(`/api/v5/messages/${encodeURIComponent(messageId)}`, convertParams(patch));
|
|
27798
27916
|
const data = await prepareMessagePayload(payload);
|
|
27799
27917
|
const cachedAt = client.cache && Date.now();
|
|
@@ -27841,13 +27959,83 @@ updateMessage.optimistically = (messageId, patch) => {
|
|
|
27841
27959
|
};
|
|
27842
27960
|
/* end_public_function */
|
|
27843
27961
|
|
|
27962
|
+
/* begin_public_function
|
|
27963
|
+
id: message.edit
|
|
27964
|
+
*/
|
|
27965
|
+
/**
|
|
27966
|
+
* ```js
|
|
27967
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
27968
|
+
* const updated = await MessageRepository.editMessage(messageId, {
|
|
27969
|
+
* data: { text: 'hello world' }
|
|
27970
|
+
* })
|
|
27971
|
+
* ```
|
|
27972
|
+
*
|
|
27973
|
+
* Updates an {@link Amity.Message}
|
|
27974
|
+
*
|
|
27975
|
+
* @param messageId The ID of the {@link Amity.Message} to edit
|
|
27976
|
+
* @param patch The patch data to apply
|
|
27977
|
+
* @returns the updated {@link Amity.Message} object
|
|
27978
|
+
*
|
|
27979
|
+
* @category Message API
|
|
27980
|
+
* @async
|
|
27981
|
+
*/
|
|
27982
|
+
const editMessage = async (messageId, patch) => {
|
|
27983
|
+
const client = getActiveClient();
|
|
27984
|
+
client.log('message/editMessage', patch);
|
|
27985
|
+
const { data: payload } = await client.http.put(`/api/v5/messages/${encodeURIComponent(messageId)}`, convertParams(patch));
|
|
27986
|
+
const data = await prepareMessagePayload(payload);
|
|
27987
|
+
const cachedAt = client.cache && Date.now();
|
|
27988
|
+
if (client.cache)
|
|
27989
|
+
ingestInCache(data, { cachedAt });
|
|
27990
|
+
const { messages } = data;
|
|
27991
|
+
fireEvent('local.message.updated', { messages });
|
|
27992
|
+
return {
|
|
27993
|
+
data: messages.find(message => message.messageId === messageId),
|
|
27994
|
+
cachedAt,
|
|
27995
|
+
};
|
|
27996
|
+
};
|
|
27997
|
+
/**
|
|
27998
|
+
* ```js
|
|
27999
|
+
* import { editMessage } from '@amityco/ts-sdk'
|
|
28000
|
+
* const updated = editMessage.optimistically('foobar', {
|
|
28001
|
+
* data: { text: 'hello world' }
|
|
28002
|
+
* })
|
|
28003
|
+
* ```
|
|
28004
|
+
*
|
|
28005
|
+
* Updates an {@link Amity.Message} in cache
|
|
28006
|
+
*
|
|
28007
|
+
* @param messageId The ID of the {@link Amity.Message} to edit
|
|
28008
|
+
* @param patch The patch data to apply
|
|
28009
|
+
* @returns the updated {@link Amity.Message} object
|
|
28010
|
+
*
|
|
28011
|
+
* @category Message API
|
|
28012
|
+
*/
|
|
28013
|
+
editMessage.optimistically = (messageId, patch) => {
|
|
28014
|
+
const client = getActiveClient();
|
|
28015
|
+
client.log('message/editMessage.optimistically', patch);
|
|
28016
|
+
if (!client.cache)
|
|
28017
|
+
return;
|
|
28018
|
+
const message = pullFromCache(['message', 'get', messageId]);
|
|
28019
|
+
if (!message)
|
|
28020
|
+
return;
|
|
28021
|
+
const cachedAt = -1;
|
|
28022
|
+
const edited = Object.assign(Object.assign(Object.assign({}, message.data), patch), { updatedAt: new Date().toISOString() });
|
|
28023
|
+
upsertInCache(['message', 'get', messageId], edited, { cachedAt });
|
|
28024
|
+
fireEvent('local.message.updated', { messages: [edited] });
|
|
28025
|
+
return {
|
|
28026
|
+
data: edited,
|
|
28027
|
+
cachedAt,
|
|
28028
|
+
};
|
|
28029
|
+
};
|
|
28030
|
+
/* end_public_function */
|
|
28031
|
+
|
|
27844
28032
|
/* begin_public_function
|
|
27845
28033
|
id: message.soft_delete
|
|
27846
28034
|
*/
|
|
27847
28035
|
/**
|
|
27848
28036
|
* ```js
|
|
27849
|
-
* import {
|
|
27850
|
-
* const success = await
|
|
28037
|
+
* import { softDeleteMessage } from '@amityco/ts-sdk'
|
|
28038
|
+
* const success = await softDeleteMessage('foobar')
|
|
27851
28039
|
* ```
|
|
27852
28040
|
*
|
|
27853
28041
|
* Delete a {@link Amity.Message}
|
|
@@ -27858,9 +28046,9 @@ updateMessage.optimistically = (messageId, patch) => {
|
|
|
27858
28046
|
* @category Message API
|
|
27859
28047
|
* @async
|
|
27860
28048
|
*/
|
|
27861
|
-
const
|
|
28049
|
+
const softDeleteMessage = async (messageId) => {
|
|
27862
28050
|
const client = getActiveClient();
|
|
27863
|
-
client.log('message/
|
|
28051
|
+
client.log('message/softDeleteMessage', messageId);
|
|
27864
28052
|
// API-FIX: This endpoint has not been implemented yet.
|
|
27865
28053
|
await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}`);
|
|
27866
28054
|
const deleted = await getMessage$1(messageId);
|
|
@@ -27869,8 +28057,8 @@ const deleteMessage = async (messageId) => {
|
|
|
27869
28057
|
};
|
|
27870
28058
|
/**
|
|
27871
28059
|
* ```js
|
|
27872
|
-
* import {
|
|
27873
|
-
* const success =
|
|
28060
|
+
* import { softDeleteMessage } from '@amityco/ts-sdk'
|
|
28061
|
+
* const success = softDeleteMessage.optimistically('foobar')
|
|
27874
28062
|
* ```
|
|
27875
28063
|
*
|
|
27876
28064
|
* Deletes a {@link Amity.Message}
|
|
@@ -27880,9 +28068,9 @@ const deleteMessage = async (messageId) => {
|
|
|
27880
28068
|
*
|
|
27881
28069
|
* @category Message API
|
|
27882
28070
|
*/
|
|
27883
|
-
|
|
28071
|
+
softDeleteMessage.optimistically = (messageId) => {
|
|
27884
28072
|
const client = getActiveClient();
|
|
27885
|
-
client.log('message/
|
|
28073
|
+
client.log('message/softDeleteMessage.optimistically', messageId);
|
|
27886
28074
|
const message = pullFromCache(['message', 'get', messageId]);
|
|
27887
28075
|
if (!message)
|
|
27888
28076
|
return;
|
|
@@ -27899,8 +28087,8 @@ deleteMessage.optimistically = (messageId) => {
|
|
|
27899
28087
|
|
|
27900
28088
|
/**
|
|
27901
28089
|
* ```js
|
|
27902
|
-
* import {
|
|
27903
|
-
* const success = await markAsDelivered('subChannelId', 'messageId')
|
|
28090
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
28091
|
+
* const success = await MessageRepository.markAsDelivered('subChannelId', 'messageId')
|
|
27904
28092
|
* ```
|
|
27905
28093
|
*
|
|
27906
28094
|
* Update `deliveredToSegment` in {@link Amity.SubChannelMarker}
|
|
@@ -28084,6 +28272,85 @@ getDeliveredUsers.locally = (query) => {
|
|
|
28084
28272
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
28085
28273
|
};
|
|
28086
28274
|
|
|
28275
|
+
/* begin_public_function
|
|
28276
|
+
id: message.flag
|
|
28277
|
+
*/
|
|
28278
|
+
/**
|
|
28279
|
+
* ```js
|
|
28280
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
28281
|
+
* const flagged = await MessageRepository.flagMessage(messageId)
|
|
28282
|
+
* ```
|
|
28283
|
+
*
|
|
28284
|
+
* @param messageId of the message to flag
|
|
28285
|
+
* @returns the created report result
|
|
28286
|
+
*
|
|
28287
|
+
* @category Message API
|
|
28288
|
+
* @async
|
|
28289
|
+
* */
|
|
28290
|
+
const flagMessage = async (messageId) => {
|
|
28291
|
+
const client = getActiveClient();
|
|
28292
|
+
client.log('message/flag', messageId);
|
|
28293
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
|
|
28294
|
+
if (client.cache) {
|
|
28295
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
28296
|
+
ingestInCache(messagePayload);
|
|
28297
|
+
}
|
|
28298
|
+
fireEvent('message.flagged', payload);
|
|
28299
|
+
return !!payload;
|
|
28300
|
+
};
|
|
28301
|
+
/* end_public_function */
|
|
28302
|
+
|
|
28303
|
+
/* begin_public_function
|
|
28304
|
+
id: message.unflag
|
|
28305
|
+
*/
|
|
28306
|
+
/**
|
|
28307
|
+
* ```js
|
|
28308
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
28309
|
+
* const unflagged = await MessageRepository.unflag(messageId)
|
|
28310
|
+
* ```
|
|
28311
|
+
*
|
|
28312
|
+
* @param messageId of the message to unflag
|
|
28313
|
+
* @returns boolean to indicate success
|
|
28314
|
+
*
|
|
28315
|
+
* @category Report API
|
|
28316
|
+
* @async
|
|
28317
|
+
* */
|
|
28318
|
+
const unflagMessage = async (messageId) => {
|
|
28319
|
+
const client = getActiveClient();
|
|
28320
|
+
client.log('message/unflag', messageId);
|
|
28321
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
|
|
28322
|
+
if (client.cache) {
|
|
28323
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
28324
|
+
ingestInCache(messagePayload);
|
|
28325
|
+
}
|
|
28326
|
+
fireEvent('message.unflagged', payload);
|
|
28327
|
+
return !!payload;
|
|
28328
|
+
};
|
|
28329
|
+
/* end_public_function */
|
|
28330
|
+
|
|
28331
|
+
/* begin_public_function
|
|
28332
|
+
id: message.check_flag_by_me
|
|
28333
|
+
*/
|
|
28334
|
+
/**
|
|
28335
|
+
* ```js
|
|
28336
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
28337
|
+
* const isReportedByMe = await MessageRepository.isMessageFlaggedByMe(messageId)
|
|
28338
|
+
* ```
|
|
28339
|
+
*
|
|
28340
|
+
* @param messageId of the message to check a report of.
|
|
28341
|
+
* @returns `true` if the report is created by me, `false` if doesn't.
|
|
28342
|
+
*
|
|
28343
|
+
* @category Report API
|
|
28344
|
+
* @async
|
|
28345
|
+
* */
|
|
28346
|
+
const isMessageFlaggedByMe = async (messageId) => {
|
|
28347
|
+
const client = getActiveClient();
|
|
28348
|
+
client.log('message/isMessageFlaggedByMe', messageId);
|
|
28349
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
|
|
28350
|
+
return data.result;
|
|
28351
|
+
};
|
|
28352
|
+
/* end_public_function */
|
|
28353
|
+
|
|
28087
28354
|
/* begin_public_function
|
|
28088
28355
|
id: message.get
|
|
28089
28356
|
*/
|
|
@@ -28229,16 +28496,15 @@ const getMessages = (params, callback, config) => {
|
|
|
28229
28496
|
return;
|
|
28230
28497
|
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
28231
28498
|
pushToCache(cacheKey, collection);
|
|
28232
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
28233
28499
|
responder(collection);
|
|
28234
28500
|
};
|
|
28235
|
-
const onFetch = () => {
|
|
28236
|
-
var _a, _b, _c, _d
|
|
28501
|
+
const onFetch = (initial = false) => {
|
|
28502
|
+
var _a, _b, _c, _d;
|
|
28237
28503
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28238
28504
|
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28239
|
-
if (messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
28505
|
+
if (!initial && messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
28240
28506
|
return;
|
|
28241
|
-
const query = createQuery(queryMessages, Object.assign(Object.assign({}, queryParams), { page: (
|
|
28507
|
+
const query = createQuery(queryMessages, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
28242
28508
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
28243
28509
|
const data = {
|
|
28244
28510
|
loading,
|
|
@@ -28254,7 +28520,8 @@ const getMessages = (params, callback, config) => {
|
|
|
28254
28520
|
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
28255
28521
|
};
|
|
28256
28522
|
disposers.push(onMessageFetched(realtimeRouter()), onMessageCreated(realtimeRouter()), onMessageUpdated(realtimeRouter()), onMessageDeleted(realtimeRouter()), onMessageFlagged(realtimeRouter()), onMessageUnflagged(realtimeRouter()), onMessageFlagCleared(realtimeRouter()), onMessageReactionAdded(realtimeRouter()), onMessageReactionRemoved(realtimeRouter()));
|
|
28257
|
-
onFetch();
|
|
28523
|
+
onFetch(true);
|
|
28524
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28258
28525
|
return () => {
|
|
28259
28526
|
log(`getMessages(tmpid: ${timestamp}) > dispose`);
|
|
28260
28527
|
disposers.forEach(fn => fn());
|
|
@@ -28352,10 +28619,14 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
28352
28619
|
getMessageByIds: getMessages$1,
|
|
28353
28620
|
createMessage: createMessage,
|
|
28354
28621
|
updateMessage: updateMessage,
|
|
28355
|
-
|
|
28622
|
+
editMessage: editMessage,
|
|
28623
|
+
softDeleteMessage: softDeleteMessage,
|
|
28356
28624
|
markAsDelivered: markAsDelivered,
|
|
28357
28625
|
getReadUsers: getReadUsers,
|
|
28358
28626
|
getDeliveredUsers: getDeliveredUsers,
|
|
28627
|
+
flagMessage: flagMessage,
|
|
28628
|
+
unflagMessage: unflagMessage,
|
|
28629
|
+
isMessageFlaggedByMe: isMessageFlaggedByMe,
|
|
28359
28630
|
onMessageCreated: onMessageCreated,
|
|
28360
28631
|
onMessageUpdated: onMessageUpdated,
|
|
28361
28632
|
onMessageDeleted: onMessageDeleted,
|
|
@@ -29735,13 +30006,13 @@ const getCommunities = (params, callback, config) => {
|
|
|
29735
30006
|
pushToCache(cacheKey, collection);
|
|
29736
30007
|
responder(collection);
|
|
29737
30008
|
};
|
|
29738
|
-
const onFetch = () => {
|
|
30009
|
+
const onFetch = (initial = false) => {
|
|
29739
30010
|
var _a, _b, _c;
|
|
29740
30011
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29741
30012
|
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
29742
|
-
if (communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30013
|
+
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
29743
30014
|
return;
|
|
29744
|
-
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30015
|
+
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
29745
30016
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
29746
30017
|
const data = {
|
|
29747
30018
|
loading,
|
|
@@ -29757,11 +30028,11 @@ const getCommunities = (params, callback, config) => {
|
|
|
29757
30028
|
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
29758
30029
|
};
|
|
29759
30030
|
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
29760
|
-
onFetch();
|
|
30031
|
+
onFetch(true);
|
|
30032
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
29761
30033
|
return () => {
|
|
29762
30034
|
log(`getCommunities(tmpid: ${timestamp}) > dispose`);
|
|
29763
30035
|
disposers.forEach(fn => fn());
|
|
29764
|
-
dropFromCache(cacheKey);
|
|
29765
30036
|
};
|
|
29766
30037
|
};
|
|
29767
30038
|
/* end_public_function */
|
|
@@ -29802,139 +30073,209 @@ const getCommunity = (communityId, callback) => {
|
|
|
29802
30073
|
/* end_public_function */
|
|
29803
30074
|
|
|
29804
30075
|
/* begin_public_function
|
|
29805
|
-
id: community.
|
|
30076
|
+
id: community.moderation.add_roles
|
|
29806
30077
|
*/
|
|
29807
30078
|
/**
|
|
29808
30079
|
* ```js
|
|
29809
30080
|
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29810
|
-
* const updated = await CommunityRepository.moderation.
|
|
30081
|
+
* const updated = await CommunityRepository.moderation.addRoles(communityId, ['foo', 'bar'])
|
|
29811
30082
|
* ```
|
|
29812
30083
|
*
|
|
29813
|
-
* Adds a list of {@link Amity.
|
|
30084
|
+
* Adds a list of {@link Amity.Role} to a list of {@link Amity.User} on a {@link Amity.Community}
|
|
29814
30085
|
*
|
|
29815
30086
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
29816
|
-
* @param
|
|
29817
|
-
* @
|
|
30087
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
30088
|
+
* @param userIds Array of IDs of the {@link Amity.User} to perform
|
|
30089
|
+
* @returns A success boolean if the {@link Amity.Role} were added to list of {@link Amity.User} in the {@link Amity.Community}
|
|
29818
30090
|
*
|
|
29819
30091
|
* @category Community API
|
|
29820
30092
|
* @async
|
|
29821
30093
|
*/
|
|
29822
|
-
const
|
|
30094
|
+
const addRoles = async (communityId, roleIds, userIds) => {
|
|
29823
30095
|
const client = getActiveClient();
|
|
29824
|
-
client.log('community/moderation/
|
|
29825
|
-
const { data: payload } = await client.http.post(`/api/
|
|
29826
|
-
fireEvent('community.userAdded', payload);
|
|
30096
|
+
client.log('community/moderation/addRoles', communityId, roleIds, userIds);
|
|
30097
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/users/roles`, { communityId, roles: roleIds, userIds });
|
|
29827
30098
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
29828
30099
|
if (client.cache)
|
|
29829
30100
|
ingestInCache(data);
|
|
29830
30101
|
const { communityUsers } = data;
|
|
29831
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
30102
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
30103
|
+
roleIds.some(role => communityUser.roles.includes(role)));
|
|
29832
30104
|
};
|
|
29833
30105
|
/* end_public_function */
|
|
29834
30106
|
|
|
29835
30107
|
/* begin_public_function
|
|
29836
|
-
id: community.
|
|
30108
|
+
id: community.moderation.remove_roles
|
|
29837
30109
|
*/
|
|
29838
30110
|
/**
|
|
29839
30111
|
* ```js
|
|
29840
30112
|
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29841
|
-
* const updated = await CommunityRepository.moderation.
|
|
30113
|
+
* const updated = await CommunityRepository.moderation.removeRoles(communityId, ['foo', 'bar'])
|
|
29842
30114
|
* ```
|
|
29843
30115
|
*
|
|
29844
|
-
* Removes a list of {@link Amity.
|
|
30116
|
+
* Removes a list of {@link Amity.Role} from a list of {@link Amity.User} on a {@link Amity.Community}
|
|
29845
30117
|
*
|
|
29846
|
-
* @param communityId The ID of the {@link Amity.Community} to
|
|
29847
|
-
* @param
|
|
29848
|
-
* @
|
|
30118
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
30119
|
+
* @param roleIds Array of IDs of the {@link Amity.Role} to apply
|
|
30120
|
+
* @param userIds Array of IDs of the {@link Amity.User} to perform
|
|
30121
|
+
* @returns A success boolean if the {@link Amity.Role} were removed from list of {@link Amity.User} in the {@link Amity.Community}
|
|
29849
30122
|
*
|
|
29850
30123
|
* @category Community API
|
|
29851
30124
|
* @async
|
|
29852
30125
|
*/
|
|
29853
|
-
const
|
|
30126
|
+
const removeRoles = async (communityId, roleIds, userIds) => {
|
|
29854
30127
|
const client = getActiveClient();
|
|
29855
|
-
client.log('community/moderation/
|
|
29856
|
-
const { data: payload } = await client.http.delete(`/api/
|
|
29857
|
-
fireEvent('community.userRemoved', payload);
|
|
30128
|
+
client.log('community/moderation/removeRoles', communityId, roleIds, userIds);
|
|
30129
|
+
const { data: payload } = await client.http.delete(`/api/v4/communities/${communityId}/users/roles`, { data: { communityId, roles: roleIds, userIds } });
|
|
29858
30130
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
29859
30131
|
if (client.cache)
|
|
29860
30132
|
ingestInCache(data);
|
|
29861
30133
|
const { communityUsers } = data;
|
|
29862
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
30134
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
30135
|
+
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
29863
30136
|
};
|
|
29864
30137
|
/* end_public_function */
|
|
29865
30138
|
|
|
29866
30139
|
/* begin_public_function
|
|
29867
|
-
id: community.moderation.
|
|
30140
|
+
id: community.moderation.ban_members
|
|
29868
30141
|
*/
|
|
29869
30142
|
/**
|
|
29870
30143
|
* ```js
|
|
29871
30144
|
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29872
|
-
*
|
|
30145
|
+
*
|
|
30146
|
+
* await CommunityRepository.Moderation.banMembers('communityId', ['userId1', 'userId2'])
|
|
29873
30147
|
* ```
|
|
29874
30148
|
*
|
|
29875
|
-
*
|
|
30149
|
+
* @param communityId of {@link Amity.Community} from which the users should be banned
|
|
30150
|
+
* @param userIds of the {@link Amity.User}'s to be banned
|
|
30151
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
30152
|
+
*
|
|
30153
|
+
* @category Community API
|
|
30154
|
+
* @async
|
|
30155
|
+
* */
|
|
30156
|
+
const banMembers = async (communityId, userIds) => {
|
|
30157
|
+
const client = getActiveClient();
|
|
30158
|
+
client.log('community/banMembers', { userIds, communityId });
|
|
30159
|
+
const { data: payload } = await client.http.put(`/api/v3/communities/${communityId}/users/ban`, {
|
|
30160
|
+
userIds,
|
|
30161
|
+
});
|
|
30162
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30163
|
+
const cachedAt = client.cache && Date.now();
|
|
30164
|
+
if (client.cache)
|
|
30165
|
+
ingestInCache(data, { cachedAt });
|
|
30166
|
+
const { communityUsers } = data;
|
|
30167
|
+
return {
|
|
30168
|
+
data: communityUsers.filter(u => userIds.includes(u.userId)),
|
|
30169
|
+
cachedAt,
|
|
30170
|
+
};
|
|
30171
|
+
};
|
|
30172
|
+
/* end_public_function */
|
|
30173
|
+
|
|
30174
|
+
/* begin_public_function
|
|
30175
|
+
id: community.moderation.unban_members
|
|
30176
|
+
*/
|
|
30177
|
+
/**
|
|
30178
|
+
* ```js
|
|
30179
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
30180
|
+
*
|
|
30181
|
+
* await CommunityRepository.Moderation.unbanMembers('communityId', ['userId1', 'userId2'])
|
|
30182
|
+
* ```
|
|
30183
|
+
*
|
|
30184
|
+
* @param communityId of {@link Amity.Community} from which the users should be unbanned
|
|
30185
|
+
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
30186
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
30187
|
+
*
|
|
30188
|
+
* @category Community API
|
|
30189
|
+
* @async
|
|
30190
|
+
* */
|
|
30191
|
+
const unbanMembers = async (communityId, userIds) => {
|
|
30192
|
+
const client = getActiveClient();
|
|
30193
|
+
client.log('community/unbanMembers', { userIds, communityId });
|
|
30194
|
+
const { data: payload } = await client.http.put(`/api/v3/communities/${communityId}/users/unban`, {
|
|
30195
|
+
userIds,
|
|
30196
|
+
});
|
|
30197
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30198
|
+
const cachedAt = client.cache && Date.now();
|
|
30199
|
+
if (client.cache)
|
|
30200
|
+
ingestInCache(data, { cachedAt });
|
|
30201
|
+
const { communityUsers } = data;
|
|
30202
|
+
return {
|
|
30203
|
+
data: communityUsers.filter(u => userIds.includes(u.userId)),
|
|
30204
|
+
cachedAt,
|
|
30205
|
+
};
|
|
30206
|
+
};
|
|
30207
|
+
/* end_public_function */
|
|
30208
|
+
|
|
30209
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
30210
|
+
__proto__: null,
|
|
30211
|
+
addRoles: addRoles,
|
|
30212
|
+
removeRoles: removeRoles,
|
|
30213
|
+
banMembers: banMembers,
|
|
30214
|
+
unbanMembers: unbanMembers
|
|
30215
|
+
});
|
|
30216
|
+
|
|
30217
|
+
/* begin_public_function
|
|
30218
|
+
id: community.membership.add_members
|
|
30219
|
+
*/
|
|
30220
|
+
/**
|
|
30221
|
+
* ```js
|
|
30222
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
30223
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
30224
|
+
* ```
|
|
30225
|
+
*
|
|
30226
|
+
* Adds a list of {@link Amity.User} to a {@link Amity.Community} to add users to
|
|
29876
30227
|
*
|
|
29877
30228
|
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
29878
|
-
* @param
|
|
29879
|
-
* @
|
|
29880
|
-
* @returns A success boolean if the {@link Amity.Role} were added to list of {@link Amity.User} in the {@link Amity.Community}
|
|
30229
|
+
* @param userIds The list of IDs {@link Amity.User} to add
|
|
30230
|
+
* @returns A success boolean if the {@link Amity.User} were added to the {@link Amity.Community}
|
|
29881
30231
|
*
|
|
29882
30232
|
* @category Community API
|
|
29883
30233
|
* @async
|
|
29884
30234
|
*/
|
|
29885
|
-
const
|
|
30235
|
+
const addMembers = async (communityId, userIds) => {
|
|
29886
30236
|
const client = getActiveClient();
|
|
29887
|
-
client.log('community/moderation/
|
|
29888
|
-
const { data: payload } = await client.http.post(`/api/
|
|
30237
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
30238
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
30239
|
+
fireEvent('community.userAdded', payload);
|
|
29889
30240
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
29890
30241
|
if (client.cache)
|
|
29891
30242
|
ingestInCache(data);
|
|
29892
30243
|
const { communityUsers } = data;
|
|
29893
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
29894
|
-
roleIds.some(role => communityUser.roles.includes(role)));
|
|
30244
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
29895
30245
|
};
|
|
29896
30246
|
/* end_public_function */
|
|
29897
30247
|
|
|
29898
30248
|
/* begin_public_function
|
|
29899
|
-
id: community.
|
|
30249
|
+
id: community.membership.remove_member
|
|
29900
30250
|
*/
|
|
29901
30251
|
/**
|
|
29902
30252
|
* ```js
|
|
29903
30253
|
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
29904
|
-
* const updated = await CommunityRepository.moderation.
|
|
30254
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
29905
30255
|
* ```
|
|
29906
30256
|
*
|
|
29907
|
-
* Removes a list of {@link Amity.
|
|
30257
|
+
* Removes a list of {@link Amity.User} from a {@link Amity.Community}
|
|
29908
30258
|
*
|
|
29909
|
-
* @param communityId The ID of the {@link Amity.Community} to
|
|
29910
|
-
* @param
|
|
29911
|
-
* @
|
|
29912
|
-
* @returns A success boolean if the {@link Amity.Role} were removed from list of {@link Amity.User} in the {@link Amity.Community}
|
|
30259
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
30260
|
+
* @param userIds The list of IDs {@link Amity.User} to remove
|
|
30261
|
+
* @returns A success boolean if the list of {@link Amity.User} were removed from the {@link Amity.Community}
|
|
29913
30262
|
*
|
|
29914
30263
|
* @category Community API
|
|
29915
30264
|
* @async
|
|
29916
30265
|
*/
|
|
29917
|
-
const
|
|
30266
|
+
const removeMembers = async (communityId, userIds) => {
|
|
29918
30267
|
const client = getActiveClient();
|
|
29919
|
-
client.log('community/moderation/
|
|
29920
|
-
const { data: payload } = await client.http.delete(`/api/
|
|
30268
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
30269
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
30270
|
+
fireEvent('community.userRemoved', payload);
|
|
29921
30271
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
29922
30272
|
if (client.cache)
|
|
29923
30273
|
ingestInCache(data);
|
|
29924
30274
|
const { communityUsers } = data;
|
|
29925
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
|
|
29926
|
-
!roleIds.some(role => communityUser.roles.includes(role)));
|
|
30275
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
29927
30276
|
};
|
|
29928
30277
|
/* end_public_function */
|
|
29929
30278
|
|
|
29930
|
-
var index$8 = /*#__PURE__*/Object.freeze({
|
|
29931
|
-
__proto__: null,
|
|
29932
|
-
addMembers: addMembers,
|
|
29933
|
-
removeMembers: removeMembers,
|
|
29934
|
-
addRoles: addRoles,
|
|
29935
|
-
removeRoles: removeRoles
|
|
29936
|
-
});
|
|
29937
|
-
|
|
29938
30279
|
/**
|
|
29939
30280
|
* ```js
|
|
29940
30281
|
* import { queryCommunityMembers } from '@amityco/ts-sdk'
|
|
@@ -30056,8 +30397,7 @@ const getMembers = (params, callback, config) => {
|
|
|
30056
30397
|
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
30057
30398
|
.filter(Boolean)
|
|
30058
30399
|
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
30059
|
-
|
|
30060
|
-
communityMembers = communityMembers.filter(c => { var _a; return (_a = c.roles) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.roles) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
30400
|
+
communityMembers = filterByPropIntersection(communityMembers, 'roles', params.roles);
|
|
30061
30401
|
if (params.membership) {
|
|
30062
30402
|
communityMembers = communityMembers.filter(({ communityMembership }) =>
|
|
30063
30403
|
// @ts-ignore
|
|
@@ -30092,13 +30432,13 @@ const getMembers = (params, callback, config) => {
|
|
|
30092
30432
|
pushToCache(cacheKey, collection);
|
|
30093
30433
|
responder(collection);
|
|
30094
30434
|
};
|
|
30095
|
-
const onFetch = () => {
|
|
30435
|
+
const onFetch = (initial = false) => {
|
|
30096
30436
|
var _a, _b, _c;
|
|
30097
30437
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30098
30438
|
const communityMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30099
|
-
if (communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30439
|
+
if (!initial && communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30100
30440
|
return;
|
|
30101
|
-
const query = createQuery(queryCommunityMembers, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30441
|
+
const query = createQuery(queryCommunityMembers, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30102
30442
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
30103
30443
|
const data = {
|
|
30104
30444
|
loading,
|
|
@@ -30116,7 +30456,7 @@ const getMembers = (params, callback, config) => {
|
|
|
30116
30456
|
}, queryOptions(policy));
|
|
30117
30457
|
};
|
|
30118
30458
|
disposers.push(onCommunityLeft(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityUserBanned(realtimeRouter()), onCommunityUserUnbanned(realtimeRouter()), onCommunityUserChanged(realtimeRouter()), onCommunityUserRoleAdded(realtimeRouter()), onCommunityUserRoleRemoved(realtimeRouter()));
|
|
30119
|
-
onFetch();
|
|
30459
|
+
onFetch(true);
|
|
30120
30460
|
return () => {
|
|
30121
30461
|
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
30122
30462
|
disposers.forEach(fn => fn());
|
|
@@ -30126,6 +30466,8 @@ const getMembers = (params, callback, config) => {
|
|
|
30126
30466
|
|
|
30127
30467
|
var index$7 = /*#__PURE__*/Object.freeze({
|
|
30128
30468
|
__proto__: null,
|
|
30469
|
+
addMembers: addMembers,
|
|
30470
|
+
removeMembers: removeMembers,
|
|
30129
30471
|
getMembers: getMembers,
|
|
30130
30472
|
onCommunityUserAdded: onCommunityUserAdded,
|
|
30131
30473
|
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
@@ -30350,13 +30692,13 @@ const getCategories = (params, callback, config) => {
|
|
|
30350
30692
|
* observers
|
|
30351
30693
|
*};
|
|
30352
30694
|
*/
|
|
30353
|
-
const onFetch = () => {
|
|
30695
|
+
const onFetch = (initial = false) => {
|
|
30354
30696
|
var _a, _b, _c;
|
|
30355
30697
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30356
30698
|
const categories = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30357
|
-
if (categories.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30699
|
+
if (!initial && categories.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
30358
30700
|
return;
|
|
30359
|
-
const query = createQuery(queryCategories, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30701
|
+
const query = createQuery(queryCategories, Object.assign(Object.assign({}, queryParams), { page: (_c = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _c !== void 0 ? _c : { limit } }));
|
|
30360
30702
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
30361
30703
|
const data = {
|
|
30362
30704
|
loading,
|
|
@@ -30374,7 +30716,7 @@ const getCategories = (params, callback, config) => {
|
|
|
30374
30716
|
disposers.push(() => {
|
|
30375
30717
|
// @TODO -> update once observers added
|
|
30376
30718
|
});
|
|
30377
|
-
onFetch();
|
|
30719
|
+
onFetch(true);
|
|
30378
30720
|
return () => {
|
|
30379
30721
|
log(`getCategories(tmpid: ${timestamp}) > dispose`);
|
|
30380
30722
|
disposers.forEach(fn => fn());
|
|
@@ -30409,7 +30751,12 @@ const queryGlobalFeed = async (query) => {
|
|
|
30409
30751
|
const client = getActiveClient();
|
|
30410
30752
|
client.log('feed/queryGlobalFeed', query);
|
|
30411
30753
|
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
30412
|
-
|
|
30754
|
+
/*
|
|
30755
|
+
* TODO: Remove useCustomRanking key from query
|
|
30756
|
+
*/
|
|
30757
|
+
if (useCustomRanking)
|
|
30758
|
+
console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');
|
|
30759
|
+
const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
|
|
30413
30760
|
params: Object.assign(Object.assign({}, params), { options: {
|
|
30414
30761
|
token: toToken(page, 'skiplimit'),
|
|
30415
30762
|
} }),
|
|
@@ -30423,7 +30770,7 @@ const queryGlobalFeed = async (query) => {
|
|
|
30423
30770
|
const cacheKey = [
|
|
30424
30771
|
'globalFeed',
|
|
30425
30772
|
'query',
|
|
30426
|
-
Object.assign(Object.assign({}, params), {
|
|
30773
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
30427
30774
|
];
|
|
30428
30775
|
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
30429
30776
|
}
|
|
@@ -30452,11 +30799,95 @@ queryGlobalFeed.locally = (query) => {
|
|
|
30452
30799
|
client.log('post/queryGlobalFeed.locally', query);
|
|
30453
30800
|
if (!client.cache)
|
|
30454
30801
|
return;
|
|
30455
|
-
const _c = query !== null && query !== void 0 ? query : {}, {
|
|
30802
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page } = _c, params = __rest(_c, ["page"]);
|
|
30456
30803
|
const queryKey = [
|
|
30457
30804
|
'globalFeed',
|
|
30458
30805
|
'query',
|
|
30459
|
-
Object.assign(Object.assign({}, params), {
|
|
30806
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
30807
|
+
];
|
|
30808
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
30809
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
30810
|
+
return;
|
|
30811
|
+
const posts = data.posts
|
|
30812
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
30813
|
+
.filter(Boolean)
|
|
30814
|
+
.map(({ data }) => data);
|
|
30815
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
30816
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
30817
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
30818
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
30819
|
+
: undefined;
|
|
30820
|
+
};
|
|
30821
|
+
|
|
30822
|
+
/* begin_public_function
|
|
30823
|
+
id: feed.query.custom_ranking_feed
|
|
30824
|
+
*/
|
|
30825
|
+
/**
|
|
30826
|
+
* ```js
|
|
30827
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
30828
|
+
* const posts = await FeedRepository.getCustomRankingGlobalFeed()
|
|
30829
|
+
* ```
|
|
30830
|
+
*
|
|
30831
|
+
* Queries a paginable list of {@link Amity.Post} objects
|
|
30832
|
+
*
|
|
30833
|
+
* @param query The query parameters
|
|
30834
|
+
* @returns A page of {@link Amity.Post} objects
|
|
30835
|
+
*
|
|
30836
|
+
* @category Feed API
|
|
30837
|
+
* @async
|
|
30838
|
+
* */
|
|
30839
|
+
const getCustomRankingGlobalFeed = async (query) => {
|
|
30840
|
+
const client = getActiveClient();
|
|
30841
|
+
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
30842
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
30843
|
+
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
30844
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
30845
|
+
token: toToken(page, 'skiplimit'),
|
|
30846
|
+
} }),
|
|
30847
|
+
});
|
|
30848
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
30849
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30850
|
+
const { posts } = data;
|
|
30851
|
+
const cachedAt = client.cache && Date.now();
|
|
30852
|
+
if (client.cache) {
|
|
30853
|
+
ingestInCache(data);
|
|
30854
|
+
const cacheKey = [
|
|
30855
|
+
'customGlobalFeed',
|
|
30856
|
+
'query',
|
|
30857
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
30858
|
+
];
|
|
30859
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
30860
|
+
}
|
|
30861
|
+
const nextPage = toPage(paging.next);
|
|
30862
|
+
const prevPage = toPage(paging.previous);
|
|
30863
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
30864
|
+
};
|
|
30865
|
+
/* end_public_function */
|
|
30866
|
+
/**
|
|
30867
|
+
* ```js
|
|
30868
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
30869
|
+
* const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
|
|
30870
|
+
* ```
|
|
30871
|
+
*
|
|
30872
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
30873
|
+
*
|
|
30874
|
+
* @param query The query parameters
|
|
30875
|
+
* @returns A page of {@link Amity.Post} objects
|
|
30876
|
+
*
|
|
30877
|
+
* @category Feed API
|
|
30878
|
+
* @async
|
|
30879
|
+
* */
|
|
30880
|
+
getCustomRankingGlobalFeed.locally = (query) => {
|
|
30881
|
+
var _a, _b;
|
|
30882
|
+
const client = getActiveClient();
|
|
30883
|
+
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
30884
|
+
if (!client.cache)
|
|
30885
|
+
return;
|
|
30886
|
+
const _c = query !== null && query !== void 0 ? query : {}, { page } = _c, params = __rest(_c, ["page"]);
|
|
30887
|
+
const queryKey = [
|
|
30888
|
+
'customGlobalFeed',
|
|
30889
|
+
'query',
|
|
30890
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
|
|
30460
30891
|
];
|
|
30461
30892
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
30462
30893
|
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
@@ -30474,7 +30905,8 @@ queryGlobalFeed.locally = (query) => {
|
|
|
30474
30905
|
|
|
30475
30906
|
var index$4 = /*#__PURE__*/Object.freeze({
|
|
30476
30907
|
__proto__: null,
|
|
30477
|
-
queryGlobalFeed: queryGlobalFeed
|
|
30908
|
+
queryGlobalFeed: queryGlobalFeed,
|
|
30909
|
+
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
30478
30910
|
});
|
|
30479
30911
|
|
|
30480
30912
|
/* begin_public_function
|
|
@@ -30621,6 +31053,7 @@ const createPost = async (bundle) => {
|
|
|
30621
31053
|
const updatePost = async (postId, patch) => {
|
|
30622
31054
|
const client = getActiveClient();
|
|
30623
31055
|
client.log('user/updatePost', patch);
|
|
31056
|
+
console.warn('Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.');
|
|
30624
31057
|
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
30625
31058
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
30626
31059
|
const cachedAt = client.cache && Date.now();
|
|
@@ -30636,8 +31069,42 @@ const updatePost = async (postId, patch) => {
|
|
|
30636
31069
|
/* end_public_function */
|
|
30637
31070
|
|
|
30638
31071
|
/* begin_public_function
|
|
30639
|
-
id: post.
|
|
31072
|
+
id: post.edit
|
|
30640
31073
|
*/
|
|
31074
|
+
/**
|
|
31075
|
+
* ```js
|
|
31076
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
31077
|
+
* const updated = await PostRepository.editPost(postId, {
|
|
31078
|
+
* data: { text: 'hello world' }
|
|
31079
|
+
* })
|
|
31080
|
+
* ```
|
|
31081
|
+
*
|
|
31082
|
+
* Updates an {@link Amity.Post}
|
|
31083
|
+
*
|
|
31084
|
+
* @param postId The ID of the {@link Amity.Post} to edit
|
|
31085
|
+
* @param patch The patch data to apply
|
|
31086
|
+
* @returns the updated {@link Amity.Post} object
|
|
31087
|
+
*
|
|
31088
|
+
* @category Post API
|
|
31089
|
+
* @async
|
|
31090
|
+
*/
|
|
31091
|
+
const editPost = async (postId, patch) => {
|
|
31092
|
+
const client = getActiveClient();
|
|
31093
|
+
client.log('user/editPost', patch);
|
|
31094
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
31095
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
31096
|
+
const cachedAt = client.cache && Date.now();
|
|
31097
|
+
if (client.cache)
|
|
31098
|
+
ingestInCache(data, { cachedAt });
|
|
31099
|
+
fireEvent('post.updated', data);
|
|
31100
|
+
const { posts } = data;
|
|
31101
|
+
return {
|
|
31102
|
+
data: posts.find(post => post.postId === postId),
|
|
31103
|
+
cachedAt,
|
|
31104
|
+
};
|
|
31105
|
+
};
|
|
31106
|
+
/* end_public_function */
|
|
31107
|
+
|
|
30641
31108
|
/**
|
|
30642
31109
|
* ```js
|
|
30643
31110
|
* import { deletePost } from '@amityco/ts-sdk'
|
|
@@ -30649,14 +31116,12 @@ const updatePost = async (postId, patch) => {
|
|
|
30649
31116
|
* @param postId The {@link Amity.Post} ID to delete
|
|
30650
31117
|
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
30651
31118
|
*
|
|
30652
|
-
* @
|
|
31119
|
+
* @private
|
|
30653
31120
|
* @async
|
|
30654
31121
|
*/
|
|
30655
31122
|
const deletePost = async (postId, permanent = false) => {
|
|
30656
31123
|
const client = getActiveClient();
|
|
30657
|
-
client.log('post/deletePost', postId);
|
|
30658
31124
|
const post = await getPost$1(postId);
|
|
30659
|
-
// API-FIX: This endpoint has not been implemented yet.
|
|
30660
31125
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
30661
31126
|
params: {
|
|
30662
31127
|
postId,
|
|
@@ -30700,6 +31165,55 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
30700
31165
|
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
30701
31166
|
}
|
|
30702
31167
|
return deleted;
|
|
31168
|
+
};
|
|
31169
|
+
|
|
31170
|
+
/* begin_public_function
|
|
31171
|
+
id: post.soft_delete
|
|
31172
|
+
*/
|
|
31173
|
+
/**
|
|
31174
|
+
* ```js
|
|
31175
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
31176
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
31177
|
+
* ```
|
|
31178
|
+
*
|
|
31179
|
+
* Soft deletes a {@link Amity.Post}
|
|
31180
|
+
*
|
|
31181
|
+
* @param postId The {@link Amity.Post} ID to soft delete
|
|
31182
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
31183
|
+
*
|
|
31184
|
+
* @category Post API
|
|
31185
|
+
* @async
|
|
31186
|
+
*/
|
|
31187
|
+
const softDeletePost = async (postId) => {
|
|
31188
|
+
const client = getActiveClient();
|
|
31189
|
+
client.log('post/softDeletePost', postId);
|
|
31190
|
+
const softDeleted = await deletePost(postId, false);
|
|
31191
|
+
return softDeleted;
|
|
31192
|
+
};
|
|
31193
|
+
/* end_public_function */
|
|
31194
|
+
|
|
31195
|
+
/* begin_public_function
|
|
31196
|
+
id: post.hard_delete
|
|
31197
|
+
*/
|
|
31198
|
+
/**
|
|
31199
|
+
* ```js
|
|
31200
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
31201
|
+
* const success = await hardDeletePost('foobar')
|
|
31202
|
+
* ```
|
|
31203
|
+
*
|
|
31204
|
+
* Hard deletes a {@link Amity.Post}
|
|
31205
|
+
*
|
|
31206
|
+
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
31207
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
31208
|
+
*
|
|
31209
|
+
* @category Post API
|
|
31210
|
+
* @async
|
|
31211
|
+
*/
|
|
31212
|
+
const hardDeletePost = async (postId) => {
|
|
31213
|
+
const client = getActiveClient();
|
|
31214
|
+
client.log('post/hardDeletePost', postId);
|
|
31215
|
+
const hardDeleted = await deletePost(postId, true);
|
|
31216
|
+
return hardDeleted;
|
|
30703
31217
|
};
|
|
30704
31218
|
/* end_public_function */
|
|
30705
31219
|
|
|
@@ -30779,6 +31293,86 @@ const declinePost = async (postId) => {
|
|
|
30779
31293
|
};
|
|
30780
31294
|
/* end_public_function */
|
|
30781
31295
|
|
|
31296
|
+
/* begin_public_function
|
|
31297
|
+
id: post.flag
|
|
31298
|
+
*/
|
|
31299
|
+
/**
|
|
31300
|
+
* ```js
|
|
31301
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
31302
|
+
* const flagged = await PostRepository.flagPost(postId)
|
|
31303
|
+
* ```
|
|
31304
|
+
*
|
|
31305
|
+
* @param postId of the post to flag
|
|
31306
|
+
* @returns a boolean
|
|
31307
|
+
*
|
|
31308
|
+
* @category Post API
|
|
31309
|
+
* @async
|
|
31310
|
+
* */
|
|
31311
|
+
const flagPost = async (postId) => {
|
|
31312
|
+
const client = getActiveClient();
|
|
31313
|
+
client.log('post/flagPost', postId);
|
|
31314
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`);
|
|
31315
|
+
if (client.cache) {
|
|
31316
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
31317
|
+
}
|
|
31318
|
+
fireEvent('post.flagged', payload);
|
|
31319
|
+
return !!payload;
|
|
31320
|
+
};
|
|
31321
|
+
/* end_public_function */
|
|
31322
|
+
|
|
31323
|
+
/* begin_public_function
|
|
31324
|
+
id: post.unflag
|
|
31325
|
+
*/
|
|
31326
|
+
/**
|
|
31327
|
+
* ```js
|
|
31328
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
31329
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
31330
|
+
* ```
|
|
31331
|
+
*
|
|
31332
|
+
* @param postId of the post to unflag
|
|
31333
|
+
* @returns the unflag post result
|
|
31334
|
+
*
|
|
31335
|
+
* @category Post API
|
|
31336
|
+
* @async
|
|
31337
|
+
* */
|
|
31338
|
+
const unflagPost = async (postId) => {
|
|
31339
|
+
const client = getActiveClient();
|
|
31340
|
+
client.log('post/unflagPost', postId);
|
|
31341
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
31342
|
+
if (client.cache) {
|
|
31343
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
31344
|
+
}
|
|
31345
|
+
fireEvent('post.unflagged', payload);
|
|
31346
|
+
return !!payload;
|
|
31347
|
+
};
|
|
31348
|
+
/* end_public_function */
|
|
31349
|
+
|
|
31350
|
+
/* begin_public_function
|
|
31351
|
+
id: post.check_flag_by_me
|
|
31352
|
+
*/
|
|
31353
|
+
/**
|
|
31354
|
+
* ```js
|
|
31355
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
31356
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
31357
|
+
* ```
|
|
31358
|
+
*
|
|
31359
|
+
* @param postId of the post to check if flagged by current user
|
|
31360
|
+
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
31361
|
+
*
|
|
31362
|
+
* @category Post API
|
|
31363
|
+
* @async
|
|
31364
|
+
* */
|
|
31365
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
31366
|
+
var _a, _b;
|
|
31367
|
+
const client = getActiveClient();
|
|
31368
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
31369
|
+
const { result, isFlagByMe } = (_a = (await synchronousWSCall(client, 'v3/post.isflagbyme', {
|
|
31370
|
+
postId,
|
|
31371
|
+
}))) !== null && _a !== void 0 ? _a : {};
|
|
31372
|
+
return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
|
|
31373
|
+
};
|
|
31374
|
+
/* end_public_function */
|
|
31375
|
+
|
|
30782
31376
|
/**
|
|
30783
31377
|
* ```js
|
|
30784
31378
|
* import { PostRepository } from '@amityco/ts-sdk'
|
|
@@ -31069,16 +31663,15 @@ const getPosts = (params, callback, config) => {
|
|
|
31069
31663
|
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
31070
31664
|
}
|
|
31071
31665
|
pushToCache(cacheKey, collection);
|
|
31072
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
31073
31666
|
responder(collection);
|
|
31074
31667
|
};
|
|
31075
|
-
const onFetch = () => {
|
|
31076
|
-
var _a, _b, _c, _d
|
|
31668
|
+
const onFetch = (initial = false) => {
|
|
31669
|
+
var _a, _b, _c, _d;
|
|
31077
31670
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31078
31671
|
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31079
|
-
if (posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
31672
|
+
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
31080
31673
|
return;
|
|
31081
|
-
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { page: (
|
|
31674
|
+
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
31082
31675
|
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
31083
31676
|
const data = {
|
|
31084
31677
|
loading,
|
|
@@ -31094,7 +31687,8 @@ const getPosts = (params, callback, config) => {
|
|
|
31094
31687
|
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
31095
31688
|
};
|
|
31096
31689
|
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
31097
|
-
onFetch();
|
|
31690
|
+
onFetch(true);
|
|
31691
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
31098
31692
|
return () => {
|
|
31099
31693
|
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
31100
31694
|
disposers.forEach(fn => fn());
|
|
@@ -31107,9 +31701,15 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
31107
31701
|
getPostByIds: getPostByIds,
|
|
31108
31702
|
createPost: createPost,
|
|
31109
31703
|
updatePost: updatePost,
|
|
31704
|
+
editPost: editPost,
|
|
31110
31705
|
deletePost: deletePost,
|
|
31706
|
+
softDeletePost: softDeletePost,
|
|
31707
|
+
hardDeletePost: hardDeletePost,
|
|
31111
31708
|
approvePost: approvePost,
|
|
31112
31709
|
declinePost: declinePost,
|
|
31710
|
+
flagPost: flagPost,
|
|
31711
|
+
unflagPost: unflagPost,
|
|
31712
|
+
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
31113
31713
|
onPostCreated: onPostCreated,
|
|
31114
31714
|
onPostUpdated: onPostUpdated,
|
|
31115
31715
|
onPostDeleted: onPostDeleted,
|
|
@@ -31615,13 +32215,13 @@ const getComments = (params, callback, config) => {
|
|
|
31615
32215
|
pushToCache(cacheKey, collection);
|
|
31616
32216
|
responder(collection);
|
|
31617
32217
|
};
|
|
31618
|
-
const onFetch = () => {
|
|
31619
|
-
var _a, _b, _c, _d
|
|
32218
|
+
const onFetch = (initial = false) => {
|
|
32219
|
+
var _a, _b, _c, _d;
|
|
31620
32220
|
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
31621
32221
|
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
31622
|
-
if (comments.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
32222
|
+
if (!initial && comments.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
31623
32223
|
return;
|
|
31624
|
-
const query = createQuery(queryComments, Object.assign(Object.assign({}, queryParams), { page: (
|
|
32224
|
+
const query = createQuery(queryComments, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
|
|
31625
32225
|
runQuery(query, ({ data: result, error, loading, prevPage, nextPage }) => {
|
|
31626
32226
|
// depend on sortBy value we have two different pagination type
|
|
31627
32227
|
const page = queryParams.sortBy ? nextPage : prevPage;
|
|
@@ -31639,11 +32239,11 @@ const getComments = (params, callback, config) => {
|
|
|
31639
32239
|
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
31640
32240
|
};
|
|
31641
32241
|
disposers.push(onCommentCreated(realtimeRouter('onCreate')), onCommentUpdated(realtimeRouter('onUpdate')), onCommentDeleted(realtimeRouter('onDelete')), onCommentFlagged(realtimeRouter('onFlagged')), onCommentUnflagged(realtimeRouter('onUnflagged')), onCommentReactionAdded(realtimeRouter('onReactionAdded')), onCommentReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
31642
|
-
onFetch();
|
|
32242
|
+
onFetch(true);
|
|
32243
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
31643
32244
|
return () => {
|
|
31644
32245
|
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
31645
32246
|
disposers.forEach(fn => fn());
|
|
31646
|
-
dropFromCache(cacheKey);
|
|
31647
32247
|
};
|
|
31648
32248
|
};
|
|
31649
32249
|
/* end_public_function */
|
|
@@ -32357,6 +32957,7 @@ exports.filterByFeedType = filterByFeedType;
|
|
|
32357
32957
|
exports.filterByPostDataTypes = filterByPostDataTypes;
|
|
32358
32958
|
exports.filterByPropEquality = filterByPropEquality;
|
|
32359
32959
|
exports.filterByPropInclusion = filterByPropInclusion;
|
|
32960
|
+
exports.filterByPropIntersection = filterByPropIntersection;
|
|
32360
32961
|
exports.filterBySearchTerm = filterBySearchTerm;
|
|
32361
32962
|
exports.getChannelMarkers = getChannelMarkers;
|
|
32362
32963
|
exports.getChannelTopic = getChannelTopic;
|
|
@@ -32391,6 +32992,7 @@ exports.isSkip = isSkip;
|
|
|
32391
32992
|
exports.mergeInCache = mergeInCache;
|
|
32392
32993
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
32393
32994
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
32995
|
+
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|
|
32394
32996
|
exports.onMessageMarked = onMessageMarked;
|
|
32395
32997
|
exports.onMessageMarkerFetched = onMessageMarkerFetched;
|
|
32396
32998
|
exports.onSubChannelMarkerFetched = onSubChannelMarkerFetched;
|