@amityco/ts-sdk 7.1.1-e887d15f.0 → 7.2.1-56aa34e.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/domains/channel.d.ts +2 -2
- 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/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +20 -0
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +1 -0
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +1 -0
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +1 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +223 -24
- package/dist/index.esm.js +223 -24
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/channel.ts +2 -2
- package/src/@types/domains/client.ts +1 -0
- package/src/channelRepository/events/onChannelDeleted.ts +9 -2
- package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
- package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
- package/src/channelRepository/observers/index.ts +1 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +21 -10
- package/src/client/api/createClient.ts +4 -1
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +5 -1
- package/src/client/utils/endpoints.ts +1 -0
- package/src/client/utils/setClientToken.ts +8 -0
- package/src/commentRepository/events/utils.ts +73 -0
- package/src/fileRepository/api/uploadFile.ts +1 -1
- package/src/fileRepository/api/uploadImage.ts +1 -1
- package/src/fileRepository/api/uploadVideo.ts +1 -1
- package/src/messageRepository/events/onMessageCreated.ts +19 -9
- package/src/messageRepository/observers/getMessage.ts +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
|
|
|
87
87
|
|
|
88
88
|
function getVersion() {
|
|
89
89
|
try {
|
|
90
|
-
// the string ''v7.
|
|
91
|
-
return 'v7.
|
|
90
|
+
// the string ''v7.2.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
91
|
+
return 'v7.2.0-esm';
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
94
|
return '__dev__';
|
|
@@ -1547,6 +1547,7 @@ const API_REGIONS = {
|
|
|
1547
1547
|
};
|
|
1548
1548
|
const URLS = {
|
|
1549
1549
|
http: 'https://apix.{region}.amity.co',
|
|
1550
|
+
upload: 'https://upload.{region}.amity.co',
|
|
1550
1551
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1551
1552
|
};
|
|
1552
1553
|
function computeUrl(type, region) {
|
|
@@ -21820,7 +21821,9 @@ class MessageReadReceiptSyncEngine {
|
|
|
21820
21821
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
21821
21822
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
21822
21823
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21823
|
-
if (channelUnread
|
|
21824
|
+
if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
|
|
21825
|
+
channelUnread &&
|
|
21826
|
+
segment > channelUnread.readToSegment) {
|
|
21824
21827
|
channelUnread.readToSegment = segment;
|
|
21825
21828
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
21826
21829
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -23153,19 +23156,27 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
23153
23156
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
23154
23157
|
for (let i = 0; i < channels.length; i += 1) {
|
|
23155
23158
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
23156
|
-
const
|
|
23157
|
-
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
23159
|
+
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
23160
|
+
let unreadCount = 0;
|
|
23161
|
+
let readToSegment = null;
|
|
23162
|
+
let lastMentionedSegment = null;
|
|
23163
|
+
let isMentioned = false;
|
|
23164
|
+
if (channelUser) {
|
|
23165
|
+
readToSegment = channelUser.readToSegment;
|
|
23166
|
+
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
23167
|
+
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
23168
|
+
isMentioned = lastMentionedSegment > readToSegment;
|
|
23169
|
+
}
|
|
23170
|
+
const cacheChannelUnread = {
|
|
23161
23171
|
channelId: channels[i].channelId,
|
|
23162
23172
|
lastSegment: channels[i].messageCount,
|
|
23163
23173
|
readToSegment,
|
|
23164
23174
|
lastMentionedSegment,
|
|
23165
|
-
unreadCount
|
|
23166
|
-
isMentioned
|
|
23167
|
-
isDeleted: channels[i].isDeleted,
|
|
23168
|
-
}
|
|
23175
|
+
unreadCount,
|
|
23176
|
+
isMentioned,
|
|
23177
|
+
isDeleted: channels[i].isDeleted || false,
|
|
23178
|
+
};
|
|
23179
|
+
pushToCache(cacheKey, cacheChannelUnread);
|
|
23169
23180
|
}
|
|
23170
23181
|
};
|
|
23171
23182
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
@@ -23965,6 +23976,12 @@ const setClientToken = async (params) => {
|
|
|
23965
23976
|
isGlobalBanned: false,
|
|
23966
23977
|
isUserDeleted: false,
|
|
23967
23978
|
};
|
|
23979
|
+
client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
23980
|
+
client.upload.defaults.metadata = {
|
|
23981
|
+
tokenExpiry: expiresAt,
|
|
23982
|
+
isGlobalBanned: false,
|
|
23983
|
+
isUserDeleted: false,
|
|
23984
|
+
};
|
|
23968
23985
|
// manually setup the token for ws transport
|
|
23969
23986
|
if (client.ws)
|
|
23970
23987
|
client.ws.io.opts.query = { token: accessToken };
|
|
@@ -24017,7 +24034,11 @@ const onChannelDeleted = (callback) => {
|
|
|
24017
24034
|
deleteChannelUnreadByChannelId(channel.channelId);
|
|
24018
24035
|
}
|
|
24019
24036
|
else if (isLegacyUnreadCount) {
|
|
24020
|
-
|
|
24037
|
+
const cacheKey = ['channelUnread', 'get', channel.channelId];
|
|
24038
|
+
const cache = pullFromCache(cacheKey);
|
|
24039
|
+
if (cache) {
|
|
24040
|
+
pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
|
|
24041
|
+
}
|
|
24021
24042
|
}
|
|
24022
24043
|
});
|
|
24023
24044
|
ingestInCache(data);
|
|
@@ -25004,7 +25025,10 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
25004
25025
|
'get',
|
|
25005
25026
|
message.channelId,
|
|
25006
25027
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25007
|
-
if (!channelUnread ||
|
|
25028
|
+
if (!channelUnread ||
|
|
25029
|
+
channelUnread.lastSegment >= message.segment ||
|
|
25030
|
+
typeof channelUnread.readToSegment !== 'number' ||
|
|
25031
|
+
typeof channelUnread.lastMentionedSegment !== 'number')
|
|
25008
25032
|
return;
|
|
25009
25033
|
const lastSegment = message.segment;
|
|
25010
25034
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -25013,10 +25037,12 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
25013
25037
|
client.userId &&
|
|
25014
25038
|
mention.userPublicIds.includes(client.userId)));
|
|
25015
25039
|
});
|
|
25016
|
-
const
|
|
25040
|
+
const lastMentionedSegment = isMentionedInMessage
|
|
25017
25041
|
? message.segment
|
|
25018
|
-
: channelUnread.
|
|
25019
|
-
|
|
25042
|
+
: channelUnread.lastMentionedSegment;
|
|
25043
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
|
|
25044
|
+
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
25045
|
+
fireEvent('local.channelUnread.updated', updatedChannelUnread);
|
|
25020
25046
|
});
|
|
25021
25047
|
}
|
|
25022
25048
|
// Update in cache
|
|
@@ -25673,15 +25699,17 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
25673
25699
|
* @category Client API
|
|
25674
25700
|
* */
|
|
25675
25701
|
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
25676
|
-
var _a, _b;
|
|
25702
|
+
var _a, _b, _c;
|
|
25677
25703
|
const log = createLogger(debugSession);
|
|
25678
25704
|
log('client/api/createClient', {
|
|
25679
25705
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
25680
25706
|
apiRegion,
|
|
25681
25707
|
});
|
|
25682
25708
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
25683
|
-
const
|
|
25709
|
+
const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
|
|
25710
|
+
const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
|
|
25684
25711
|
const http = createHttpTransport(httpEndpoint);
|
|
25712
|
+
const upload = createHttpTransport(uploadEndpoint);
|
|
25685
25713
|
let ws;
|
|
25686
25714
|
let mqtt;
|
|
25687
25715
|
if (rteEnabled) {
|
|
@@ -25712,6 +25740,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25712
25740
|
http,
|
|
25713
25741
|
ws,
|
|
25714
25742
|
mqtt,
|
|
25743
|
+
upload,
|
|
25715
25744
|
emitter,
|
|
25716
25745
|
/*
|
|
25717
25746
|
* Session Components
|
|
@@ -25741,7 +25770,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25741
25770
|
return activeClient;
|
|
25742
25771
|
setActiveClient(client);
|
|
25743
25772
|
}
|
|
25744
|
-
catch (
|
|
25773
|
+
catch (_d) {
|
|
25745
25774
|
setActiveClient(client);
|
|
25746
25775
|
}
|
|
25747
25776
|
return client;
|
|
@@ -28530,7 +28559,7 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
28530
28559
|
const headers = 'getHeaders' in formData
|
|
28531
28560
|
? formData.getHeaders()
|
|
28532
28561
|
: { 'content-type': 'multipart/form-data' };
|
|
28533
|
-
const { data } = await client.
|
|
28562
|
+
const { data } = await client.upload.post('/api/v4/files', formData, {
|
|
28534
28563
|
headers,
|
|
28535
28564
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28536
28565
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28620,7 +28649,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
28620
28649
|
const headers = 'getHeaders' in formData
|
|
28621
28650
|
? formData.getHeaders()
|
|
28622
28651
|
: { 'content-type': 'multipart/form-data' };
|
|
28623
|
-
const { data } = await client.
|
|
28652
|
+
const { data } = await client.upload.post('/api/v4/videos', formData, {
|
|
28624
28653
|
headers,
|
|
28625
28654
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28626
28655
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -28668,7 +28697,7 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28668
28697
|
const headers = 'getHeaders' in formData
|
|
28669
28698
|
? formData.getHeaders()
|
|
28670
28699
|
: { 'content-type': 'multipart/form-data' };
|
|
28671
|
-
const { data } = await client.
|
|
28700
|
+
const { data } = await client.upload.post('/api/v4/images', formData, {
|
|
28672
28701
|
headers,
|
|
28673
28702
|
onUploadProgress({ loaded, total = 100 }) {
|
|
28674
28703
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -29753,6 +29782,29 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29753
29782
|
}
|
|
29754
29783
|
}
|
|
29755
29784
|
}
|
|
29785
|
+
}
|
|
29786
|
+
if (['comment.deleted'].includes(event)) {
|
|
29787
|
+
// NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
|
|
29788
|
+
if (event === 'comment.deleted' && comment.data.userId === client.userId)
|
|
29789
|
+
return;
|
|
29790
|
+
if (comments[0].parentId) {
|
|
29791
|
+
const parentComment = pullFromCache([
|
|
29792
|
+
'comment',
|
|
29793
|
+
'get',
|
|
29794
|
+
comments[0].parentId,
|
|
29795
|
+
]);
|
|
29796
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29797
|
+
// Remove deleted comment in parent childComment if still exists
|
|
29798
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
29799
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
29800
|
+
...new Set([
|
|
29801
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
29802
|
+
]),
|
|
29803
|
+
] });
|
|
29804
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29805
|
+
}
|
|
29806
|
+
}
|
|
29807
|
+
}
|
|
29756
29808
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29757
29809
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29758
29810
|
}
|
|
@@ -29765,7 +29817,7 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29765
29817
|
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
29766
29818
|
const client = getActiveClient();
|
|
29767
29819
|
const filter = (payload) => {
|
|
29768
|
-
var _a;
|
|
29820
|
+
var _a, _b;
|
|
29769
29821
|
if (!client.cache) {
|
|
29770
29822
|
// TODO: here we are missing specific properties here!
|
|
29771
29823
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
@@ -29808,6 +29860,38 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
29808
29860
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29809
29861
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29810
29862
|
}
|
|
29863
|
+
if (['local.comment.deleted'].includes(event)) {
|
|
29864
|
+
if (comments[0].parentId) {
|
|
29865
|
+
const parentComment = pullFromCache([
|
|
29866
|
+
'comment',
|
|
29867
|
+
'get',
|
|
29868
|
+
comments[0].parentId,
|
|
29869
|
+
]);
|
|
29870
|
+
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29871
|
+
// Remove deleted comment in parent childComment if still exists
|
|
29872
|
+
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
29873
|
+
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
29874
|
+
...new Set([
|
|
29875
|
+
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
29876
|
+
]),
|
|
29877
|
+
] });
|
|
29878
|
+
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
29879
|
+
setTimeout(() => {
|
|
29880
|
+
// NOTE: This is workaround solution for emitting event not work properly.
|
|
29881
|
+
fireEvent('comment.updated', {
|
|
29882
|
+
comments: [newParentComment],
|
|
29883
|
+
commentChildren: [],
|
|
29884
|
+
files: [],
|
|
29885
|
+
users: [],
|
|
29886
|
+
communityUsers: [],
|
|
29887
|
+
});
|
|
29888
|
+
}, 200);
|
|
29889
|
+
}
|
|
29890
|
+
}
|
|
29891
|
+
}
|
|
29892
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
29893
|
+
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
29894
|
+
}
|
|
29811
29895
|
callback(LinkedObject.comment(comment.data));
|
|
29812
29896
|
}
|
|
29813
29897
|
}
|
|
@@ -33676,6 +33760,120 @@ const getChannels = (params, callback, config) => {
|
|
|
33676
33760
|
};
|
|
33677
33761
|
/* end_public_function */
|
|
33678
33762
|
|
|
33763
|
+
/**
|
|
33764
|
+
*
|
|
33765
|
+
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
33766
|
+
*
|
|
33767
|
+
* @returns the {@link Amity.UserUnread} objects
|
|
33768
|
+
*
|
|
33769
|
+
* @category Channel API
|
|
33770
|
+
* @async
|
|
33771
|
+
*/
|
|
33772
|
+
const getTotalChannelsUnread$1 = () => {
|
|
33773
|
+
var _a;
|
|
33774
|
+
const client = getActiveClient();
|
|
33775
|
+
client.log('channel/getTotalChannelsUnread.locally');
|
|
33776
|
+
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
33777
|
+
return !data.isDeleted;
|
|
33778
|
+
})) || [];
|
|
33779
|
+
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
33780
|
+
acc.unreadCount += data.unreadCount;
|
|
33781
|
+
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
33782
|
+
return acc;
|
|
33783
|
+
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
33784
|
+
const cachedAt = client.cache && Date.now();
|
|
33785
|
+
return {
|
|
33786
|
+
data: totalChannelsUnread,
|
|
33787
|
+
cachedAt,
|
|
33788
|
+
};
|
|
33789
|
+
};
|
|
33790
|
+
|
|
33791
|
+
/* begin_public_function
|
|
33792
|
+
id: totalChannelsUnread.get
|
|
33793
|
+
*/
|
|
33794
|
+
/**
|
|
33795
|
+
* ```js
|
|
33796
|
+
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
33797
|
+
*
|
|
33798
|
+
* let totalChannelsUnread;
|
|
33799
|
+
*
|
|
33800
|
+
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
33801
|
+
* unread = response.data;
|
|
33802
|
+
* });
|
|
33803
|
+
* ```
|
|
33804
|
+
*
|
|
33805
|
+
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
33806
|
+
*
|
|
33807
|
+
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
33808
|
+
*
|
|
33809
|
+
* @category User Unread Live Object
|
|
33810
|
+
*
|
|
33811
|
+
*/
|
|
33812
|
+
const getTotalChannelsUnread = (callback) => {
|
|
33813
|
+
const { _id: userId } = getActiveUser();
|
|
33814
|
+
if (!userId)
|
|
33815
|
+
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
33816
|
+
const { log, cache } = getActiveClient();
|
|
33817
|
+
if (!cache) {
|
|
33818
|
+
console.log('For using Live Object feature you need to enable Cache!');
|
|
33819
|
+
}
|
|
33820
|
+
const timestamp = Date.now();
|
|
33821
|
+
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
33822
|
+
const disposers = [];
|
|
33823
|
+
let isUnsyncedModel = false; // for messages
|
|
33824
|
+
let model;
|
|
33825
|
+
const dispatcher = (data) => {
|
|
33826
|
+
const { data: userUnread } = data;
|
|
33827
|
+
const callbackModel = userUnread
|
|
33828
|
+
? {
|
|
33829
|
+
unreadCount: userUnread.unreadCount,
|
|
33830
|
+
isMentioned: userUnread.isMentioned,
|
|
33831
|
+
}
|
|
33832
|
+
: undefined;
|
|
33833
|
+
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
33834
|
+
callback({
|
|
33835
|
+
data: callbackModel
|
|
33836
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
33837
|
+
loading: data.loading,
|
|
33838
|
+
error: data.error,
|
|
33839
|
+
});
|
|
33840
|
+
};
|
|
33841
|
+
const realtimeRouter = (userUnread) => {
|
|
33842
|
+
if (isEqual(model, userUnread))
|
|
33843
|
+
return;
|
|
33844
|
+
dispatcher({
|
|
33845
|
+
loading: false,
|
|
33846
|
+
data: userUnread,
|
|
33847
|
+
});
|
|
33848
|
+
};
|
|
33849
|
+
const onFetch = () => {
|
|
33850
|
+
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
33851
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
33852
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
33853
|
+
dispatcher({
|
|
33854
|
+
data,
|
|
33855
|
+
origin,
|
|
33856
|
+
loading: false,
|
|
33857
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
33858
|
+
});
|
|
33859
|
+
isUnsyncedModel = true;
|
|
33860
|
+
disposers.forEach(fn => fn());
|
|
33861
|
+
}
|
|
33862
|
+
else if (!isUnsyncedModel) {
|
|
33863
|
+
dispatcher({ loading, data, origin, error });
|
|
33864
|
+
}
|
|
33865
|
+
if (error) {
|
|
33866
|
+
disposers.forEach(fn => fn());
|
|
33867
|
+
}
|
|
33868
|
+
});
|
|
33869
|
+
};
|
|
33870
|
+
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
33871
|
+
onFetch();
|
|
33872
|
+
return () => {
|
|
33873
|
+
disposers.forEach(fn => fn());
|
|
33874
|
+
};
|
|
33875
|
+
};
|
|
33876
|
+
|
|
33679
33877
|
/* begin_public_function
|
|
33680
33878
|
id: channel.member.add
|
|
33681
33879
|
*/
|
|
@@ -34279,6 +34477,7 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
34279
34477
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
34280
34478
|
getChannel: getChannel,
|
|
34281
34479
|
getChannels: getChannels,
|
|
34480
|
+
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
34282
34481
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
34283
34482
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
34284
34483
|
convertFromRaw: convertFromRaw,
|