@amityco/ts-sdk 7.19.0 → 7.19.1-0d42b83a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +2 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +7 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +20 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +16 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/notificationSettings.d.ts +101 -0
- package/dist/@types/domains/notificationSettings.d.ts.map +1 -0
- package/dist/@types/index.d.ts +2 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channelRepository/api/archiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/archiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts +13 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts.map +1 -0
- package/dist/channelRepository/api/index.d.ts +3 -0
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/api/unarchiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/unarchiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/updateChannel.d.ts +1 -1
- package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/banMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/muteMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unmuteMembers.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +2 -0
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelArchived.d.ts +10 -0
- package/dist/channelRepository/events/onChannelArchived.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelUnarchived.d.ts +11 -0
- package/dist/channelRepository/events/onChannelUnarchived.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts +12 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts +11 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts +13 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts +20 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts +2 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/notifications.d.ts +27 -0
- package/dist/client/api/notifications.d.ts.map +1 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts +2 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts.map +1 -0
- package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +738 -8
- package/dist/index.esm.js +739 -9
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +1 -0
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts +12 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts +10 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts +8 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts +2 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts +24 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts.map +1 -0
- package/dist/reactionRepository/internalApi/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/internalApi/removeReaction.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -74,6 +74,13 @@ exports.FileAccessTypeEnum = void 0;
|
|
|
74
74
|
FileAccessTypeEnum["NETWORK"] = "network";
|
|
75
75
|
})(exports.FileAccessTypeEnum || (exports.FileAccessTypeEnum = {}));
|
|
76
76
|
|
|
77
|
+
exports.AmityChannelNotificationModeEnum = void 0;
|
|
78
|
+
(function (AmityChannelNotificationModeEnum) {
|
|
79
|
+
AmityChannelNotificationModeEnum["Default"] = "default";
|
|
80
|
+
AmityChannelNotificationModeEnum["Silent"] = "silent";
|
|
81
|
+
AmityChannelNotificationModeEnum["Subscribe"] = "subscribe";
|
|
82
|
+
})(exports.AmityChannelNotificationModeEnum || (exports.AmityChannelNotificationModeEnum = {}));
|
|
83
|
+
|
|
77
84
|
const CommunityPostSettings = Object.freeze({
|
|
78
85
|
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
79
86
|
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
@@ -255,6 +262,39 @@ exports.AnalyticsSourceTypeEnum = void 0;
|
|
|
255
262
|
AnalyticsSourceTypeEnum["ROOM"] = "room";
|
|
256
263
|
})(exports.AnalyticsSourceTypeEnum || (exports.AnalyticsSourceTypeEnum = {}));
|
|
257
264
|
|
|
265
|
+
exports.UserNotificationModuleNameEnum = void 0;
|
|
266
|
+
(function (UserNotificationModuleNameEnum) {
|
|
267
|
+
UserNotificationModuleNameEnum["CHAT"] = "chat";
|
|
268
|
+
UserNotificationModuleNameEnum["SOCIAL"] = "social";
|
|
269
|
+
UserNotificationModuleNameEnum["VIDEO_STREAMING"] = "video-streaming";
|
|
270
|
+
})(exports.UserNotificationModuleNameEnum || (exports.UserNotificationModuleNameEnum = {}));
|
|
271
|
+
exports.CommunityNotificationEventNameEnum = void 0;
|
|
272
|
+
(function (CommunityNotificationEventNameEnum) {
|
|
273
|
+
CommunityNotificationEventNameEnum["POST_CREATED"] = "post.created";
|
|
274
|
+
CommunityNotificationEventNameEnum["POST_REACTED"] = "post.reacted";
|
|
275
|
+
CommunityNotificationEventNameEnum["COMMENT_CREATED"] = "comment.created";
|
|
276
|
+
CommunityNotificationEventNameEnum["COMMENT_REPLIED"] = "comment.replied";
|
|
277
|
+
CommunityNotificationEventNameEnum["COMMENT_REACTED"] = "comment.reacted";
|
|
278
|
+
CommunityNotificationEventNameEnum["STORY_CREATED"] = "story.created";
|
|
279
|
+
CommunityNotificationEventNameEnum["STORY_REACTED"] = "story.reacted";
|
|
280
|
+
CommunityNotificationEventNameEnum["STORY_COMMENT_CREATED"] = "story-comment.created";
|
|
281
|
+
CommunityNotificationEventNameEnum["LIVESTREAM_START"] = "video-streaming.didStart";
|
|
282
|
+
})(exports.CommunityNotificationEventNameEnum || (exports.CommunityNotificationEventNameEnum = {}));
|
|
283
|
+
exports.NotificationSettingsLevelEnum = void 0;
|
|
284
|
+
(function (NotificationSettingsLevelEnum) {
|
|
285
|
+
NotificationSettingsLevelEnum["USER"] = "user";
|
|
286
|
+
NotificationSettingsLevelEnum["COMMUNITY"] = "community";
|
|
287
|
+
NotificationSettingsLevelEnum["CHANNEL"] = "channel";
|
|
288
|
+
})(exports.NotificationSettingsLevelEnum || (exports.NotificationSettingsLevelEnum = {}));
|
|
289
|
+
/**
|
|
290
|
+
* `NOT` variant is intentionally excluded from public API (internal server-side use only).
|
|
291
|
+
*/
|
|
292
|
+
exports.NotificationRolesFilterTypeEnum = void 0;
|
|
293
|
+
(function (NotificationRolesFilterTypeEnum) {
|
|
294
|
+
NotificationRolesFilterTypeEnum["ALL"] = "all";
|
|
295
|
+
NotificationRolesFilterTypeEnum["ONLY"] = "only";
|
|
296
|
+
})(exports.NotificationRolesFilterTypeEnum || (exports.NotificationRolesFilterTypeEnum = {}));
|
|
297
|
+
|
|
258
298
|
function getVersion() {
|
|
259
299
|
try {
|
|
260
300
|
// the string ''v7.19.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -667,6 +707,7 @@ const idResolvers = {
|
|
|
667
707
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
668
708
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
669
709
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
710
|
+
archivedChannel: ({ channelId }) => channelId,
|
|
670
711
|
message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
|
|
671
712
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
672
713
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
@@ -730,6 +771,7 @@ const PAYLOAD2MODEL = {
|
|
|
730
771
|
channels: 'channel',
|
|
731
772
|
messageFeeds: 'subChannel',
|
|
732
773
|
channelUsers: 'channelUsers',
|
|
774
|
+
archives: 'archivedChannel',
|
|
733
775
|
messages: 'message',
|
|
734
776
|
messagePreviewChannel: 'messagePreviewChannel',
|
|
735
777
|
messagePreviewSubChannel: 'messagePreviewSubChannel',
|
|
@@ -6678,7 +6720,7 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6678
6720
|
const client = getActiveClient();
|
|
6679
6721
|
const filter = async (payload) => {
|
|
6680
6722
|
const { channels, channelUsers } = payload;
|
|
6681
|
-
|
|
6723
|
+
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
6682
6724
|
};
|
|
6683
6725
|
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
|
|
6684
6726
|
}
|
|
@@ -6686,6 +6728,39 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6686
6728
|
return () => dispose$1(callback);
|
|
6687
6729
|
};
|
|
6688
6730
|
|
|
6731
|
+
/**
|
|
6732
|
+
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
6733
|
+
*
|
|
6734
|
+
* @param callback The function to call when the event was fired
|
|
6735
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
6736
|
+
*
|
|
6737
|
+
* @category Channel Events
|
|
6738
|
+
*/
|
|
6739
|
+
const onChannelArchived = (callback) => {
|
|
6740
|
+
const client = getActiveClient();
|
|
6741
|
+
const filter = async (payload) => {
|
|
6742
|
+
callback(payload);
|
|
6743
|
+
};
|
|
6744
|
+
return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
|
|
6745
|
+
};
|
|
6746
|
+
|
|
6747
|
+
/**
|
|
6748
|
+
* Fired when a previously archived {@link Amity.Channel} has been unarchived
|
|
6749
|
+
* by the active user.
|
|
6750
|
+
*
|
|
6751
|
+
* @param callback The function to call when the event was fired
|
|
6752
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
6753
|
+
*
|
|
6754
|
+
* @category Channel Events
|
|
6755
|
+
*/
|
|
6756
|
+
const onChannelUnarchived = (callback) => {
|
|
6757
|
+
const client = getActiveClient();
|
|
6758
|
+
const filter = async (payload) => {
|
|
6759
|
+
callback(payload);
|
|
6760
|
+
};
|
|
6761
|
+
return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
|
|
6762
|
+
};
|
|
6763
|
+
|
|
6689
6764
|
const callbacks = [];
|
|
6690
6765
|
let mainDisposer = null;
|
|
6691
6766
|
const dispose = (cb) => {
|
|
@@ -6799,6 +6874,17 @@ const channelLinkedObject = (channel) => {
|
|
|
6799
6874
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
6800
6875
|
previewMembers,
|
|
6801
6876
|
myMembership: (callback) => getMyMembership(channel.channelId, callback),
|
|
6877
|
+
get avatar() {
|
|
6878
|
+
var _a;
|
|
6879
|
+
if (!channel.avatarFileId)
|
|
6880
|
+
return undefined;
|
|
6881
|
+
const avatar = (_a = pullFromCache([
|
|
6882
|
+
'file',
|
|
6883
|
+
'get',
|
|
6884
|
+
`${channel.avatarFileId}`,
|
|
6885
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6886
|
+
return avatar;
|
|
6887
|
+
},
|
|
6802
6888
|
});
|
|
6803
6889
|
};
|
|
6804
6890
|
|
|
@@ -8161,9 +8247,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
8161
8247
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
8162
8248
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
8163
8249
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8164
|
-
if (
|
|
8165
|
-
channelUnread
|
|
8166
|
-
segment > channelUnread.readToSegment) {
|
|
8250
|
+
if (channelUnread &&
|
|
8251
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
8167
8252
|
channelUnread.readToSegment = segment;
|
|
8168
8253
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
8169
8254
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -10788,6 +10873,140 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
10788
10873
|
client.accessTokenHandler = accessTokenHandler;
|
|
10789
10874
|
};
|
|
10790
10875
|
|
|
10876
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
10877
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
10878
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
10879
|
+
}
|
|
10880
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
10881
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
10882
|
+
}
|
|
10883
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ALL };
|
|
10884
|
+
}
|
|
10885
|
+
function serializeRolesFilter(rolesFilter) {
|
|
10886
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === exports.NotificationRolesFilterTypeEnum.ONLY) {
|
|
10887
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
10888
|
+
}
|
|
10889
|
+
return { listenFromRoleIds: [] };
|
|
10890
|
+
}
|
|
10891
|
+
class ChannelNotifications {
|
|
10892
|
+
constructor(channelId) {
|
|
10893
|
+
this.channelId = channelId;
|
|
10894
|
+
}
|
|
10895
|
+
async enable() {
|
|
10896
|
+
const client = getActiveClient();
|
|
10897
|
+
const body = {
|
|
10898
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
10899
|
+
channelId: this.channelId,
|
|
10900
|
+
isPushNotifiable: true,
|
|
10901
|
+
};
|
|
10902
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10903
|
+
}
|
|
10904
|
+
async disable() {
|
|
10905
|
+
const client = getActiveClient();
|
|
10906
|
+
const body = {
|
|
10907
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
10908
|
+
channelId: this.channelId,
|
|
10909
|
+
isPushNotifiable: false,
|
|
10910
|
+
};
|
|
10911
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10912
|
+
}
|
|
10913
|
+
async getSettings() {
|
|
10914
|
+
const client = getActiveClient();
|
|
10915
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
10916
|
+
return { isEnabled: data.isPushNotifiable };
|
|
10917
|
+
}
|
|
10918
|
+
}
|
|
10919
|
+
class UserNotifications {
|
|
10920
|
+
async enable(modules) {
|
|
10921
|
+
var _a;
|
|
10922
|
+
const client = getActiveClient();
|
|
10923
|
+
const notifiableEvents = (_a = modules === null || modules === void 0 ? void 0 : modules.map(module => (Object.assign({ moduleName: module.moduleName, isPushNotifiable: module.isEnabled }, serializeRolesFilter(module.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
|
|
10924
|
+
const body = {
|
|
10925
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
10926
|
+
isPushNotifiable: true,
|
|
10927
|
+
notifiableEvents,
|
|
10928
|
+
};
|
|
10929
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10930
|
+
}
|
|
10931
|
+
async disableAllNotifications() {
|
|
10932
|
+
const client = getActiveClient();
|
|
10933
|
+
const body = {
|
|
10934
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
10935
|
+
isPushNotifiable: false,
|
|
10936
|
+
notifiableEvents: [],
|
|
10937
|
+
};
|
|
10938
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10939
|
+
}
|
|
10940
|
+
async getSettings() {
|
|
10941
|
+
var _a;
|
|
10942
|
+
const client = getActiveClient();
|
|
10943
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.USER}`);
|
|
10944
|
+
const validModuleNames = Object.values(exports.UserNotificationModuleNameEnum);
|
|
10945
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
10946
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
10947
|
+
.map(e => ({
|
|
10948
|
+
moduleName: e.moduleName,
|
|
10949
|
+
isEnabled: e.isPushNotifiable,
|
|
10950
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
10951
|
+
}));
|
|
10952
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
10953
|
+
}
|
|
10954
|
+
}
|
|
10955
|
+
class CommunityNotifications {
|
|
10956
|
+
constructor(communityId) {
|
|
10957
|
+
this.communityId = communityId;
|
|
10958
|
+
}
|
|
10959
|
+
async enable(events) {
|
|
10960
|
+
var _a;
|
|
10961
|
+
const client = getActiveClient();
|
|
10962
|
+
const notifiableEvents = (_a = events === null || events === void 0 ? void 0 : events.map(event => (Object.assign({ moduleName: exports.UserNotificationModuleNameEnum.SOCIAL, name: event.eventName, isPushNotifiable: event.isEnabled }, serializeRolesFilter(event.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
|
|
10963
|
+
const body = {
|
|
10964
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
10965
|
+
communityId: this.communityId,
|
|
10966
|
+
isPushNotifiable: true,
|
|
10967
|
+
notifiableEvents,
|
|
10968
|
+
};
|
|
10969
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10970
|
+
}
|
|
10971
|
+
async disable() {
|
|
10972
|
+
const client = getActiveClient();
|
|
10973
|
+
const body = {
|
|
10974
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
10975
|
+
communityId: this.communityId,
|
|
10976
|
+
isPushNotifiable: false,
|
|
10977
|
+
notifiableEvents: [],
|
|
10978
|
+
};
|
|
10979
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
10980
|
+
}
|
|
10981
|
+
async getSettings() {
|
|
10982
|
+
var _a;
|
|
10983
|
+
const client = getActiveClient();
|
|
10984
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
10985
|
+
const validEventNames = Object.values(exports.CommunityNotificationEventNameEnum);
|
|
10986
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
10987
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
10988
|
+
.map(e => ({
|
|
10989
|
+
eventName: e.name,
|
|
10990
|
+
isEnabled: e.isPushNotifiable,
|
|
10991
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
10992
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
10993
|
+
}));
|
|
10994
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
10995
|
+
}
|
|
10996
|
+
}
|
|
10997
|
+
class Notifications {
|
|
10998
|
+
user() {
|
|
10999
|
+
return new UserNotifications();
|
|
11000
|
+
}
|
|
11001
|
+
community(communityId) {
|
|
11002
|
+
return new CommunityNotifications(communityId);
|
|
11003
|
+
}
|
|
11004
|
+
channel(channelId) {
|
|
11005
|
+
return new ChannelNotifications(channelId);
|
|
11006
|
+
}
|
|
11007
|
+
}
|
|
11008
|
+
const notifications = () => new Notifications();
|
|
11009
|
+
|
|
10791
11010
|
/**
|
|
10792
11011
|
* ```js
|
|
10793
11012
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -11168,6 +11387,8 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11168
11387
|
getCurrentUserType: getCurrentUserType,
|
|
11169
11388
|
setCurrentUserType: setCurrentUserType,
|
|
11170
11389
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
11390
|
+
getChatSettings: getChatSettings,
|
|
11391
|
+
notifications: notifications,
|
|
11171
11392
|
onConnectionError: onConnectionError,
|
|
11172
11393
|
onClientDisconnected: onClientDisconnected,
|
|
11173
11394
|
onClientBanned: onClientBanned,
|
|
@@ -13203,7 +13424,7 @@ const getWatchSessionStorage = () => {
|
|
|
13203
13424
|
return storageInstance;
|
|
13204
13425
|
};
|
|
13205
13426
|
|
|
13206
|
-
const privateKey = "
|
|
13427
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
13207
13428
|
/*
|
|
13208
13429
|
* The crypto algorithm used for importing key and signing string
|
|
13209
13430
|
*/
|
|
@@ -14714,6 +14935,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
14714
14935
|
});
|
|
14715
14936
|
return true;
|
|
14716
14937
|
}
|
|
14938
|
+
if (referenceType === 'message') {
|
|
14939
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
14940
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
14941
|
+
return true;
|
|
14942
|
+
}
|
|
14717
14943
|
}
|
|
14718
14944
|
return true;
|
|
14719
14945
|
};
|
|
@@ -14792,7 +15018,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14792
15018
|
return true;
|
|
14793
15019
|
}
|
|
14794
15020
|
if (referenceType === 'story') {
|
|
14795
|
-
fireEvent('local.story.
|
|
15021
|
+
fireEvent('local.story.reactionRemoved', {
|
|
14796
15022
|
story: updatedModel,
|
|
14797
15023
|
reactor: {
|
|
14798
15024
|
userId: client.userId,
|
|
@@ -14802,6 +15028,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14802
15028
|
});
|
|
14803
15029
|
return true;
|
|
14804
15030
|
}
|
|
15031
|
+
if (referenceType === 'message') {
|
|
15032
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15033
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15034
|
+
return true;
|
|
15035
|
+
}
|
|
14805
15036
|
}
|
|
14806
15037
|
return true;
|
|
14807
15038
|
};
|
|
@@ -17725,7 +17956,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17725
17956
|
return true;
|
|
17726
17957
|
}
|
|
17727
17958
|
if (referenceType === 'story') {
|
|
17728
|
-
fireEvent('local.story.
|
|
17959
|
+
fireEvent('local.story.reactionRemoved', {
|
|
17729
17960
|
story: updatedModel,
|
|
17730
17961
|
reactor: {
|
|
17731
17962
|
userId: client.userId,
|
|
@@ -19309,6 +19540,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
19309
19540
|
};
|
|
19310
19541
|
/* end_public_function */
|
|
19311
19542
|
|
|
19543
|
+
/* begin_public_function
|
|
19544
|
+
id: channel.archive
|
|
19545
|
+
*/
|
|
19546
|
+
/**
|
|
19547
|
+
* ```js
|
|
19548
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
19549
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
19550
|
+
* ```
|
|
19551
|
+
*
|
|
19552
|
+
* Archive a {@link Amity.Channel}.
|
|
19553
|
+
*
|
|
19554
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
19555
|
+
* @returns A success boolean
|
|
19556
|
+
*
|
|
19557
|
+
* @category Channel API
|
|
19558
|
+
* @async
|
|
19559
|
+
*/
|
|
19560
|
+
const archiveChannel = async (channelId) => {
|
|
19561
|
+
const client = getActiveClient();
|
|
19562
|
+
client.log('channel/archiveChannel', channelId);
|
|
19563
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
19564
|
+
const archive = {
|
|
19565
|
+
channelId,
|
|
19566
|
+
archivedAt: new Date().toISOString(),
|
|
19567
|
+
};
|
|
19568
|
+
if (client.cache) {
|
|
19569
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
19570
|
+
}
|
|
19571
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
19572
|
+
};
|
|
19573
|
+
/* end_public_function */
|
|
19574
|
+
|
|
19575
|
+
/* begin_public_function
|
|
19576
|
+
id: channel.unarchive
|
|
19577
|
+
*/
|
|
19578
|
+
/**
|
|
19579
|
+
* ```js
|
|
19580
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
19581
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
19582
|
+
* ```
|
|
19583
|
+
*
|
|
19584
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
19585
|
+
*
|
|
19586
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
19587
|
+
* @returns A success boolean
|
|
19588
|
+
*
|
|
19589
|
+
* @category Channel API
|
|
19590
|
+
* @async
|
|
19591
|
+
*/
|
|
19592
|
+
const unarchiveChannel = async (channelId) => {
|
|
19593
|
+
var _a;
|
|
19594
|
+
const client = getActiveClient();
|
|
19595
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
19596
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
19597
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
19598
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
19599
|
+
channelId,
|
|
19600
|
+
archivedAt: new Date().toISOString(),
|
|
19601
|
+
};
|
|
19602
|
+
if (client.cache) {
|
|
19603
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
19604
|
+
}
|
|
19605
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
19606
|
+
};
|
|
19607
|
+
/* end_public_function */
|
|
19608
|
+
|
|
19609
|
+
/* begin_public_function
|
|
19610
|
+
id: channel.archive.ids
|
|
19611
|
+
*/
|
|
19612
|
+
/**
|
|
19613
|
+
* ```js
|
|
19614
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
19615
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
19616
|
+
* ```
|
|
19617
|
+
*
|
|
19618
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
19619
|
+
*
|
|
19620
|
+
* @category Channel API
|
|
19621
|
+
* @async
|
|
19622
|
+
*/
|
|
19623
|
+
const getArchivedChannelIds = async () => {
|
|
19624
|
+
var _a;
|
|
19625
|
+
const client = getActiveClient();
|
|
19626
|
+
client.log('channel/getArchivedChannelIds');
|
|
19627
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
19628
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
19629
|
+
if (client.cache) {
|
|
19630
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
19631
|
+
archives.forEach(archive => {
|
|
19632
|
+
if (!archive.channelId)
|
|
19633
|
+
return;
|
|
19634
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
19635
|
+
});
|
|
19636
|
+
}
|
|
19637
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
19638
|
+
};
|
|
19639
|
+
/* end_public_function */
|
|
19640
|
+
|
|
19312
19641
|
/**
|
|
19313
19642
|
* ```js
|
|
19314
19643
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -20687,6 +21016,160 @@ const getMessages = (params, callback, config) => {
|
|
|
20687
21016
|
};
|
|
20688
21017
|
/* end_public_function */
|
|
20689
21018
|
|
|
21019
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
21020
|
+
async getRequest(queryParams, token) {
|
|
21021
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
21022
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
21023
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
21024
|
+
params: {
|
|
21025
|
+
query,
|
|
21026
|
+
exactMatch,
|
|
21027
|
+
channelId,
|
|
21028
|
+
messageFeedId,
|
|
21029
|
+
userIds,
|
|
21030
|
+
tags,
|
|
21031
|
+
types,
|
|
21032
|
+
options,
|
|
21033
|
+
},
|
|
21034
|
+
});
|
|
21035
|
+
return queryResponse;
|
|
21036
|
+
}
|
|
21037
|
+
}
|
|
21038
|
+
|
|
21039
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
21040
|
+
constructor(query, cacheKey, notifyChange) {
|
|
21041
|
+
super(query, cacheKey);
|
|
21042
|
+
this.notifyChange = notifyChange;
|
|
21043
|
+
}
|
|
21044
|
+
async saveToMainDB(response) {
|
|
21045
|
+
var _a;
|
|
21046
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
21047
|
+
const client = getActiveClient();
|
|
21048
|
+
const cachedAt = client.cache && Date.now();
|
|
21049
|
+
if (client.cache) {
|
|
21050
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21051
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21052
|
+
response.channels.forEach(channel => {
|
|
21053
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
21054
|
+
});
|
|
21055
|
+
}
|
|
21056
|
+
}
|
|
21057
|
+
}
|
|
21058
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21059
|
+
var _a, _b;
|
|
21060
|
+
if (refresh) {
|
|
21061
|
+
pushToCache(this.cacheKey, {
|
|
21062
|
+
data: response.messages.map(getResolver('message')),
|
|
21063
|
+
});
|
|
21064
|
+
return;
|
|
21065
|
+
}
|
|
21066
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21067
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21068
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
21069
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
21070
|
+
? [...new Set([...incoming, ...existing])]
|
|
21071
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
21072
|
+
}
|
|
21073
|
+
}
|
|
21074
|
+
|
|
21075
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
21076
|
+
constructor(query, callback) {
|
|
21077
|
+
const queryStreamId = hash__default["default"](query);
|
|
21078
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
21079
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
21080
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21081
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
21082
|
+
this.callback = callback.bind(this);
|
|
21083
|
+
this.loadPage({ initial: true });
|
|
21084
|
+
}
|
|
21085
|
+
startSubscription() {
|
|
21086
|
+
return [];
|
|
21087
|
+
}
|
|
21088
|
+
notifyChange({ origin, loading, error }) {
|
|
21089
|
+
var _a, _b;
|
|
21090
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21091
|
+
if (!collection)
|
|
21092
|
+
return;
|
|
21093
|
+
const data = (_b = collection.data
|
|
21094
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
21095
|
+
.filter(isNonNullable)
|
|
21096
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
21097
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
21098
|
+
return;
|
|
21099
|
+
this.callback({
|
|
21100
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
21101
|
+
data,
|
|
21102
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
21103
|
+
loading,
|
|
21104
|
+
error,
|
|
21105
|
+
});
|
|
21106
|
+
}
|
|
21107
|
+
setup() {
|
|
21108
|
+
var _a;
|
|
21109
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21110
|
+
if (!collection) {
|
|
21111
|
+
pushToCache(this.cacheKey, {
|
|
21112
|
+
data: [],
|
|
21113
|
+
params: {},
|
|
21114
|
+
});
|
|
21115
|
+
}
|
|
21116
|
+
}
|
|
21117
|
+
async persistModel(response) {
|
|
21118
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
21119
|
+
}
|
|
21120
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
21121
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
21122
|
+
}
|
|
21123
|
+
}
|
|
21124
|
+
|
|
21125
|
+
/* begin_public_function
|
|
21126
|
+
id: message.search
|
|
21127
|
+
*/
|
|
21128
|
+
/**
|
|
21129
|
+
* ```js
|
|
21130
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
21131
|
+
*
|
|
21132
|
+
* let messages = [];
|
|
21133
|
+
*
|
|
21134
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
21135
|
+
* { query: 'hello' },
|
|
21136
|
+
* response => merge(messages, response.data),
|
|
21137
|
+
* );
|
|
21138
|
+
* ```
|
|
21139
|
+
*
|
|
21140
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
21141
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
21142
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
21143
|
+
*
|
|
21144
|
+
* @param params Search parameters. `query` is required.
|
|
21145
|
+
* @param callback Called whenever new data are available.
|
|
21146
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
21147
|
+
*
|
|
21148
|
+
* @category Message Live Collection
|
|
21149
|
+
*/
|
|
21150
|
+
const searchMessage = (params, callback) => {
|
|
21151
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
21152
|
+
throw new Error('Query is required for message search');
|
|
21153
|
+
}
|
|
21154
|
+
const { log, cache } = getActiveClient();
|
|
21155
|
+
if (!cache) {
|
|
21156
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
21157
|
+
}
|
|
21158
|
+
const timestamp = Date.now();
|
|
21159
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
21160
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
21161
|
+
const disposers = controller.startSubscription();
|
|
21162
|
+
const cacheKey = controller.getCacheKey();
|
|
21163
|
+
disposers.push(() => {
|
|
21164
|
+
dropFromCache(cacheKey);
|
|
21165
|
+
});
|
|
21166
|
+
return () => {
|
|
21167
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
21168
|
+
disposers.forEach(fn => fn());
|
|
21169
|
+
};
|
|
21170
|
+
};
|
|
21171
|
+
/* end_public_function */
|
|
21172
|
+
|
|
20690
21173
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
20691
21174
|
__proto__: null,
|
|
20692
21175
|
createMessage: createMessage,
|
|
@@ -20712,6 +21195,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
20712
21195
|
onMessageFetched: onMessageFetched,
|
|
20713
21196
|
getMessage: getMessage,
|
|
20714
21197
|
getMessages: getMessages,
|
|
21198
|
+
searchMessage: searchMessage,
|
|
20715
21199
|
convertFromRaw: convertFromRaw$1,
|
|
20716
21200
|
prepareMessagePayload: prepareMessagePayload,
|
|
20717
21201
|
convertParams: convertParams,
|
|
@@ -21559,6 +22043,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21559
22043
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
21560
22044
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
21561
22045
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
22046
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
21562
22047
|
].includes(action)) {
|
|
21563
22048
|
if (Array.isArray(payload)) {
|
|
21564
22049
|
collection.data = [
|
|
@@ -21568,6 +22053,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21568
22053
|
else
|
|
21569
22054
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
21570
22055
|
}
|
|
22056
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
22057
|
+
const ids = Array.isArray(payload)
|
|
22058
|
+
? payload.map(getResolver('channel'))
|
|
22059
|
+
: [getResolver('channel')(payload)];
|
|
22060
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
22061
|
+
}
|
|
21571
22062
|
pushToCache(this.cacheKey, collection);
|
|
21572
22063
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21573
22064
|
};
|
|
@@ -21834,6 +22325,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21834
22325
|
},
|
|
21835
22326
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
21836
22327
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
22328
|
+
{
|
|
22329
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
22330
|
+
const channels = payload.archives
|
|
22331
|
+
.map(archive => {
|
|
22332
|
+
var _a;
|
|
22333
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22334
|
+
})
|
|
22335
|
+
.filter((c) => Boolean(c));
|
|
22336
|
+
if (channels.length > 0)
|
|
22337
|
+
reactor(channels);
|
|
22338
|
+
}),
|
|
22339
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
22340
|
+
},
|
|
22341
|
+
{
|
|
22342
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
22343
|
+
const channels = payload.archives
|
|
22344
|
+
.map(archive => {
|
|
22345
|
+
var _a;
|
|
22346
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22347
|
+
})
|
|
22348
|
+
.filter((c) => Boolean(c));
|
|
22349
|
+
if (channels.length > 0)
|
|
22350
|
+
reactor(channels);
|
|
22351
|
+
}),
|
|
22352
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
22353
|
+
},
|
|
21837
22354
|
{
|
|
21838
22355
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
21839
22356
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -22187,6 +22704,192 @@ const getTotalChannelsUnread = (callback) => {
|
|
|
22187
22704
|
};
|
|
22188
22705
|
};
|
|
22189
22706
|
|
|
22707
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
22708
|
+
async getRequest(queryParams, token) {
|
|
22709
|
+
var _a, _b;
|
|
22710
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
22711
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
22712
|
+
if (pageIndex === 0) {
|
|
22713
|
+
await getArchivedChannelIds();
|
|
22714
|
+
}
|
|
22715
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
22716
|
+
const archives = cached
|
|
22717
|
+
.map(entry => entry.data)
|
|
22718
|
+
.slice()
|
|
22719
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
22720
|
+
const start = pageIndex * limit;
|
|
22721
|
+
const end = start + limit;
|
|
22722
|
+
const slice = archives.slice(start, end);
|
|
22723
|
+
const hasMore = end < archives.length;
|
|
22724
|
+
if (slice.length > 0) {
|
|
22725
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
22726
|
+
}
|
|
22727
|
+
return {
|
|
22728
|
+
archives: slice,
|
|
22729
|
+
paging: {
|
|
22730
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
22731
|
+
previous: undefined,
|
|
22732
|
+
},
|
|
22733
|
+
};
|
|
22734
|
+
}
|
|
22735
|
+
}
|
|
22736
|
+
|
|
22737
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
22738
|
+
constructor(query, cacheKey, notifyChange) {
|
|
22739
|
+
super(query, cacheKey);
|
|
22740
|
+
this.notifyChange = notifyChange;
|
|
22741
|
+
}
|
|
22742
|
+
async saveToMainDB(_response) {
|
|
22743
|
+
//
|
|
22744
|
+
}
|
|
22745
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
22746
|
+
var _a, _b;
|
|
22747
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
22748
|
+
if (refresh) {
|
|
22749
|
+
pushToCache(this.cacheKey, {
|
|
22750
|
+
data: channelIds,
|
|
22751
|
+
params: {},
|
|
22752
|
+
});
|
|
22753
|
+
return;
|
|
22754
|
+
}
|
|
22755
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22756
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22757
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
22758
|
+
? [...new Set([...channelIds, ...existing])]
|
|
22759
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
22760
|
+
}
|
|
22761
|
+
reactor(action) {
|
|
22762
|
+
return (channelIds) => {
|
|
22763
|
+
var _a;
|
|
22764
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22765
|
+
if (!collection)
|
|
22766
|
+
return;
|
|
22767
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
22768
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
22769
|
+
collection.data = [...channelIds, ...filtered];
|
|
22770
|
+
}
|
|
22771
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
22772
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
22773
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
22774
|
+
}
|
|
22775
|
+
pushToCache(this.cacheKey, collection);
|
|
22776
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
22777
|
+
};
|
|
22778
|
+
}
|
|
22779
|
+
subscribeRTE(createSubscriber) {
|
|
22780
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
22781
|
+
}
|
|
22782
|
+
}
|
|
22783
|
+
|
|
22784
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
22785
|
+
constructor(query, callback) {
|
|
22786
|
+
const queryStreamId = hash__default["default"](query);
|
|
22787
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
22788
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
22789
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22790
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
22791
|
+
this.callback = callback.bind(this);
|
|
22792
|
+
this.loadPage({ initial: true });
|
|
22793
|
+
}
|
|
22794
|
+
setup() {
|
|
22795
|
+
var _a;
|
|
22796
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22797
|
+
if (!collection) {
|
|
22798
|
+
pushToCache(this.cacheKey, {
|
|
22799
|
+
data: [],
|
|
22800
|
+
params: {},
|
|
22801
|
+
});
|
|
22802
|
+
}
|
|
22803
|
+
}
|
|
22804
|
+
async persistModel(response) {
|
|
22805
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
22806
|
+
}
|
|
22807
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22808
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22809
|
+
}
|
|
22810
|
+
startSubscription() {
|
|
22811
|
+
return this.queryStreamController.subscribeRTE([
|
|
22812
|
+
{
|
|
22813
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
22814
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
22815
|
+
},
|
|
22816
|
+
{
|
|
22817
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
22818
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
22819
|
+
},
|
|
22820
|
+
{
|
|
22821
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
22822
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
22823
|
+
},
|
|
22824
|
+
{
|
|
22825
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
22826
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
22827
|
+
},
|
|
22828
|
+
]);
|
|
22829
|
+
}
|
|
22830
|
+
notifyChange({ origin, loading, error }) {
|
|
22831
|
+
var _a, _b;
|
|
22832
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22833
|
+
if (!collection)
|
|
22834
|
+
return;
|
|
22835
|
+
const data = (_b = collection.data
|
|
22836
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
22837
|
+
.filter((entry) => Boolean(entry))
|
|
22838
|
+
.map(({ data: channel }) => channel)
|
|
22839
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
22840
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22841
|
+
return;
|
|
22842
|
+
this.callback({
|
|
22843
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22844
|
+
data,
|
|
22845
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22846
|
+
loading,
|
|
22847
|
+
error,
|
|
22848
|
+
});
|
|
22849
|
+
}
|
|
22850
|
+
}
|
|
22851
|
+
|
|
22852
|
+
/* begin_public_function
|
|
22853
|
+
id: channel.archive.collection
|
|
22854
|
+
*/
|
|
22855
|
+
/**
|
|
22856
|
+
* ```js
|
|
22857
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
22858
|
+
*
|
|
22859
|
+
* let channels = []
|
|
22860
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
22861
|
+
* ```
|
|
22862
|
+
*
|
|
22863
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
22864
|
+
*
|
|
22865
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
22866
|
+
* archive list takes no other filters).
|
|
22867
|
+
* @param callback the function to call when new data are available
|
|
22868
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
22869
|
+
* stop observing.
|
|
22870
|
+
*
|
|
22871
|
+
* @category Channel Live Collection
|
|
22872
|
+
*/
|
|
22873
|
+
const getArchivedChannels = (params, callback) => {
|
|
22874
|
+
const { log, cache } = getActiveClient();
|
|
22875
|
+
if (!cache) {
|
|
22876
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
22877
|
+
}
|
|
22878
|
+
const timestamp = Date.now();
|
|
22879
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
22880
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
22881
|
+
const disposers = controller.startSubscription();
|
|
22882
|
+
const cacheKey = controller.getCacheKey();
|
|
22883
|
+
disposers.push(() => {
|
|
22884
|
+
dropFromCache(cacheKey);
|
|
22885
|
+
});
|
|
22886
|
+
return () => {
|
|
22887
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
22888
|
+
disposers.forEach(fn => fn());
|
|
22889
|
+
};
|
|
22890
|
+
};
|
|
22891
|
+
/* end_public_function */
|
|
22892
|
+
|
|
22190
22893
|
/* begin_public_function
|
|
22191
22894
|
id: channel.member.add
|
|
22192
22895
|
*/
|
|
@@ -22318,7 +23021,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
22318
23021
|
channelId: this.query.channelId,
|
|
22319
23022
|
userId: channelMember.userId,
|
|
22320
23023
|
});
|
|
22321
|
-
|
|
23024
|
+
const membershipFilter = this.query.memberships;
|
|
23025
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
23026
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
22322
23027
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
22323
23028
|
}
|
|
22324
23029
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -22654,6 +23359,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
22654
23359
|
const cachedAt = client.cache && Date.now();
|
|
22655
23360
|
if (client.cache)
|
|
22656
23361
|
ingestInCache(preparedPayload, { cachedAt });
|
|
23362
|
+
fireEvent('channel.banned', payload);
|
|
22657
23363
|
return {
|
|
22658
23364
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
22659
23365
|
cachedAt,
|
|
@@ -22688,6 +23394,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
22688
23394
|
const cachedAt = client.cache && Date.now();
|
|
22689
23395
|
if (client.cache)
|
|
22690
23396
|
ingestInCache(preparedPayload, { cachedAt });
|
|
23397
|
+
fireEvent('channel.unbanned', payload);
|
|
22691
23398
|
const { channelUsers } = preparedPayload;
|
|
22692
23399
|
return {
|
|
22693
23400
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -22716,6 +23423,7 @@ const MUTE_FOREVER = -1;
|
|
|
22716
23423
|
* @async
|
|
22717
23424
|
* */
|
|
22718
23425
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
23426
|
+
var _a;
|
|
22719
23427
|
const client = getActiveClient();
|
|
22720
23428
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
22721
23429
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -22723,6 +23431,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22723
23431
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
22724
23432
|
});
|
|
22725
23433
|
const { success } = data;
|
|
23434
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
23435
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
23436
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
23437
|
+
fireEvent('channel.setMutedUsers', {
|
|
23438
|
+
channelId,
|
|
23439
|
+
userIds,
|
|
23440
|
+
muteTimeout,
|
|
23441
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
23442
|
+
});
|
|
22726
23443
|
return success;
|
|
22727
23444
|
};
|
|
22728
23445
|
/* end_public_function */
|
|
@@ -22745,6 +23462,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22745
23462
|
* @async
|
|
22746
23463
|
* */
|
|
22747
23464
|
const unmuteMembers = async (channelId, userIds) => {
|
|
23465
|
+
var _a;
|
|
22748
23466
|
const client = getActiveClient();
|
|
22749
23467
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
22750
23468
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -22752,6 +23470,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22752
23470
|
mutePeriod: 0,
|
|
22753
23471
|
});
|
|
22754
23472
|
const { success } = data;
|
|
23473
|
+
fireEvent('channel.setMutedUsers', {
|
|
23474
|
+
channelId,
|
|
23475
|
+
userIds,
|
|
23476
|
+
muteTimeout: new Date(0).toISOString(),
|
|
23477
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
23478
|
+
});
|
|
22755
23479
|
return success;
|
|
22756
23480
|
};
|
|
22757
23481
|
/* end_public_function */
|
|
@@ -22778,6 +23502,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22778
23502
|
leaveChannel: leaveChannel,
|
|
22779
23503
|
muteChannel: muteChannel,
|
|
22780
23504
|
unmuteChannel: unmuteChannel,
|
|
23505
|
+
archiveChannel: archiveChannel,
|
|
23506
|
+
unarchiveChannel: unarchiveChannel,
|
|
23507
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
22781
23508
|
onChannelCreated: onChannelCreated,
|
|
22782
23509
|
onChannelUpdated: onChannelUpdated,
|
|
22783
23510
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -22790,9 +23517,12 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22790
23517
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
22791
23518
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
22792
23519
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
23520
|
+
onChannelArchived: onChannelArchived,
|
|
23521
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
22793
23522
|
getChannel: getChannel,
|
|
22794
23523
|
getChannels: getChannels,
|
|
22795
23524
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
23525
|
+
getArchivedChannels: getArchivedChannels,
|
|
22796
23526
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
22797
23527
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22798
23528
|
convertFromRaw: convertFromRaw,
|