@amityco/ts-sdk-react-native 6.35.2-412ed8b.0 → 6.35.2
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/.env +26 -26
- package/dist/index.cjs.js +864 -930
- package/dist/index.esm.js +791 -857
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/updateMessagePreviewFromMessage.d.ts +2 -0
- package/dist/messagePreview/utils/updateMessagePreviewFromMessage.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannel.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.d.ts +1 -0
- package/dist/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/utils/dateTime.d.ts +2 -0
- package/dist/utils/dateTime.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/messagePreview/utils/updateMessagePreviewFromMessage.ts +131 -94
- package/src/subChannelRepository/observers/getSubChannel.ts +8 -49
- package/src/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.ts +40 -105
- package/src/utils/dateTime.ts +3 -0
package/dist/index.esm.js
CHANGED
|
@@ -89,8 +89,8 @@ const PostContentType = Object.freeze({
|
|
|
89
89
|
|
|
90
90
|
function getVersion() {
|
|
91
91
|
try {
|
|
92
|
-
// the string ''v6.35.
|
|
93
|
-
return 'v6.35.
|
|
92
|
+
// the string ''v6.35.2-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
93
|
+
return 'v6.35.2-esm';
|
|
94
94
|
}
|
|
95
95
|
catch (error) {
|
|
96
96
|
return '__dev__';
|
|
@@ -22222,60 +22222,622 @@ function updateSubChannelCache(subChannelId, subChannel, params) {
|
|
|
22222
22222
|
shallowClone(subChannel, params));
|
|
22223
22223
|
}
|
|
22224
22224
|
|
|
22225
|
-
|
|
22226
|
-
|
|
22227
|
-
|
|
22228
|
-
|
|
22229
|
-
|
|
22230
|
-
|
|
22231
|
-
|
|
22232
|
-
|
|
22233
|
-
|
|
22234
|
-
|
|
22235
|
-
|
|
22236
|
-
|
|
22237
|
-
|
|
22238
|
-
|
|
22239
|
-
|
|
22240
|
-
|
|
22225
|
+
/**
|
|
22226
|
+
* ```js
|
|
22227
|
+
* import { isInTombstone } from '@amityco/ts-sdk-react-native'
|
|
22228
|
+
* const user = isInTombstone(["message", "messageId"])
|
|
22229
|
+
* ```
|
|
22230
|
+
*
|
|
22231
|
+
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
22232
|
+
* in cache and it's not expired means it's in tombstone
|
|
22233
|
+
* and we throw an Error
|
|
22234
|
+
*
|
|
22235
|
+
* @param model the model to check
|
|
22236
|
+
* @param modelId the object id to check
|
|
22237
|
+
* @returns the matching cache entry, or undefined.
|
|
22238
|
+
*
|
|
22239
|
+
* @category Cache API
|
|
22240
|
+
*/
|
|
22241
|
+
const isInTombstone = (model, modelId) => {
|
|
22242
|
+
const { log, cache } = getActiveClient();
|
|
22243
|
+
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
22244
|
+
if (!cache)
|
|
22245
|
+
return;
|
|
22246
|
+
log('cache/api/isInTombstone', key);
|
|
22247
|
+
const isInTombstone = pullFromCache(key);
|
|
22248
|
+
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
22249
|
+
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
22250
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22251
|
+
}
|
|
22252
|
+
};
|
|
22253
|
+
|
|
22254
|
+
/**
|
|
22255
|
+
* ```js
|
|
22256
|
+
* import { getMessageMarkers } from '@amityco/ts-sdk-react-native'
|
|
22257
|
+
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
22258
|
+
* ```
|
|
22259
|
+
*
|
|
22260
|
+
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
22261
|
+
*
|
|
22262
|
+
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
22263
|
+
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
22264
|
+
*
|
|
22265
|
+
* @category Channel API
|
|
22266
|
+
* @async
|
|
22267
|
+
* @private
|
|
22268
|
+
*/
|
|
22269
|
+
const getMessageMarkers = async (messageIds) => {
|
|
22270
|
+
const client = getActiveClient();
|
|
22271
|
+
client.log('channel/getMessageMarkers', messageIds);
|
|
22272
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
22273
|
+
params: {
|
|
22274
|
+
messageIds,
|
|
22275
|
+
},
|
|
22276
|
+
});
|
|
22277
|
+
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
22278
|
+
const cachedAt = client.cache && Date.now();
|
|
22279
|
+
if (client.cache)
|
|
22280
|
+
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
22281
|
+
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
22282
|
+
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
22283
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22284
|
+
return { data: contentMarkers, cachedAt };
|
|
22285
|
+
};
|
|
22286
|
+
|
|
22287
|
+
const persistUnreadCountInfo = (payload) => {
|
|
22288
|
+
const { feedMarkers, userFeedMarkers } = payload;
|
|
22289
|
+
// calculate sub channel unread info and channel unread info
|
|
22290
|
+
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
22291
|
+
const channelIds = [];
|
|
22292
|
+
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
22293
|
+
userFeedMarkers.forEach(userFeedMarker => {
|
|
22294
|
+
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
22295
|
+
if (!feedMarker)
|
|
22296
|
+
return;
|
|
22297
|
+
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
22298
|
+
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
22299
|
+
const subChannelUnreadInfo = {
|
|
22300
|
+
subChannelId: feedMarker.feedId,
|
|
22301
|
+
channelId: feedMarker.entityId,
|
|
22302
|
+
readToSegment: userFeedMarker.readToSegment,
|
|
22303
|
+
lastSegment: feedMarker.lastSegment,
|
|
22304
|
+
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
22305
|
+
unreadCount: Math.max(0, unreadCount),
|
|
22306
|
+
isMentioned: userFeedMarker.isMentioned,
|
|
22307
|
+
isDeleted: feedMarker.isDeleted,
|
|
22308
|
+
createdAt: userFeedMarker.createdAt,
|
|
22309
|
+
updatedAt: userFeedMarker.updatedAt,
|
|
22310
|
+
};
|
|
22311
|
+
// update sub channel unread info in cache
|
|
22312
|
+
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
22313
|
+
if (!channelIds.includes(feedMarker.entityId)) {
|
|
22314
|
+
channelIds.push(feedMarker.entityId);
|
|
22315
|
+
}
|
|
22316
|
+
}
|
|
22317
|
+
});
|
|
22318
|
+
// re-calculate channel unread info in cache
|
|
22319
|
+
channelIds.forEach(channelId => {
|
|
22320
|
+
reCalculateChannelUnreadInfo(channelId);
|
|
22321
|
+
});
|
|
22322
|
+
}
|
|
22323
|
+
};
|
|
22324
|
+
|
|
22325
|
+
/**
|
|
22326
|
+
* ```js
|
|
22327
|
+
* import { getSubChannelMarkers } from '@amityco/ts-sdk-react-native'
|
|
22328
|
+
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
22329
|
+
* ```
|
|
22330
|
+
*
|
|
22331
|
+
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
22332
|
+
*
|
|
22333
|
+
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
22334
|
+
* @param page
|
|
22335
|
+
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
22336
|
+
*
|
|
22337
|
+
* @category Channel API
|
|
22338
|
+
* @async
|
|
22339
|
+
* @private
|
|
22340
|
+
*/
|
|
22341
|
+
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
22342
|
+
const client = getActiveClient();
|
|
22343
|
+
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
22344
|
+
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
22345
|
+
params: {
|
|
22346
|
+
messageFeedIds,
|
|
22347
|
+
options: {
|
|
22348
|
+
token: toToken(page, 'skiplimit'),
|
|
22349
|
+
},
|
|
22350
|
+
},
|
|
22351
|
+
});
|
|
22352
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22353
|
+
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
22354
|
+
// if consistent mode is enabled, persist the unread count info to the cache
|
|
22355
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22356
|
+
persistUnreadCountInfo({
|
|
22357
|
+
feedMarkers: feedMarkersPayload,
|
|
22358
|
+
userFeedMarkers: userFeedMarkersPayload,
|
|
22359
|
+
});
|
|
22360
|
+
}
|
|
22361
|
+
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22362
|
+
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22363
|
+
const cachedAt = client.cache && Date.now();
|
|
22364
|
+
if (client.cache)
|
|
22365
|
+
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
22366
|
+
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
22367
|
+
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
22368
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22369
|
+
const nextPage = toPage(paging.next);
|
|
22370
|
+
const prevPage = toPage(paging.previous);
|
|
22371
|
+
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
22372
|
+
};
|
|
22373
|
+
|
|
22374
|
+
const getUserMarker = async () => {
|
|
22375
|
+
const client = getActiveClient();
|
|
22376
|
+
client.log('channel/getUserMarker');
|
|
22377
|
+
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
22378
|
+
const { userMarkers } = payload;
|
|
22379
|
+
const cachedAt = client.cache && Date.now();
|
|
22380
|
+
if (client.cache)
|
|
22381
|
+
ingestInCache({ userMarkers }, { cachedAt });
|
|
22382
|
+
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22383
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
22384
|
+
if (maxUserMarker == null ||
|
|
22385
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
22386
|
+
return userMarker;
|
|
22387
|
+
}
|
|
22388
|
+
return maxUserMarker;
|
|
22389
|
+
}, undefined);
|
|
22390
|
+
return { data: latestUserMarker, cachedAt };
|
|
22391
|
+
};
|
|
22392
|
+
|
|
22393
|
+
/** @hidden */
|
|
22394
|
+
/*
|
|
22395
|
+
* @param message payload from http request without myReactions
|
|
22396
|
+
* add myReactions to http response if the event was a reaction event
|
|
22397
|
+
*/
|
|
22398
|
+
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
22399
|
+
const client = getActiveClient();
|
|
22400
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22401
|
+
// '[]' in cases where the new reaction is the first one
|
|
22402
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22403
|
+
// add myReactions to the payload
|
|
22404
|
+
Object.assign(payload, { myReactions });
|
|
22405
|
+
// check if there are any updates to the reactions
|
|
22406
|
+
const latestReaction = reactors[0];
|
|
22407
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22408
|
+
if (!isLatestReactionMine) {
|
|
22409
|
+
return;
|
|
22410
|
+
}
|
|
22411
|
+
// new reaction added
|
|
22412
|
+
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22413
|
+
Object.assign(payload, {
|
|
22414
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22415
|
+
});
|
|
22416
|
+
}
|
|
22417
|
+
// existing reaction removed
|
|
22418
|
+
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
22419
|
+
Object.assign(payload, {
|
|
22420
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22421
|
+
});
|
|
22422
|
+
}
|
|
22423
|
+
};
|
|
22424
|
+
|
|
22425
|
+
/*
|
|
22426
|
+
* This is a simple utility that infers the value of isDeleted based on the
|
|
22427
|
+
* value of includeDeleted
|
|
22428
|
+
*
|
|
22429
|
+
* There are two important things to note here:
|
|
22430
|
+
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
22431
|
+
* the server
|
|
22432
|
+
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
22433
|
+
* param for queries) is false | undefined and want to disallow users to query
|
|
22434
|
+
* for deleted entities
|
|
22435
|
+
*
|
|
22436
|
+
* Although this is a very simple utility, it's only purpose is to keep things
|
|
22437
|
+
* DRY
|
|
22438
|
+
*/
|
|
22439
|
+
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
22440
|
+
|
|
22441
|
+
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
22442
|
+
var _a, _b;
|
|
22443
|
+
// Look for `unreadCount` in the marker param first
|
|
22444
|
+
if (marker) {
|
|
22445
|
+
return marker.hasMentioned;
|
|
22446
|
+
}
|
|
22447
|
+
const client = getActiveClient();
|
|
22448
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22449
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22450
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
22451
|
+
'subChannelUnreadInfo',
|
|
22241
22452
|
'get',
|
|
22242
22453
|
subChannelId,
|
|
22243
|
-
])) === null ||
|
|
22244
|
-
|
|
22245
|
-
|
|
22246
|
-
|
|
22247
|
-
|
|
22248
|
-
|
|
22249
|
-
|
|
22454
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22455
|
+
if (cachedUnreadCount) {
|
|
22456
|
+
return cachedUnreadCount.isMentioned;
|
|
22457
|
+
}
|
|
22458
|
+
return false;
|
|
22459
|
+
}
|
|
22460
|
+
const key = {
|
|
22461
|
+
entityId: channelId,
|
|
22462
|
+
feedId: subChannelId,
|
|
22463
|
+
userId: getActiveUser()._id,
|
|
22464
|
+
};
|
|
22465
|
+
// If the marker param is not set, look in the cache
|
|
22466
|
+
const cachedMarker = (_b = pullFromCache([
|
|
22467
|
+
'subChannelMarker',
|
|
22468
|
+
'get',
|
|
22469
|
+
getResolver('subChannelMarker')(key),
|
|
22470
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22471
|
+
if (cachedMarker) {
|
|
22472
|
+
return cachedMarker.hasMentioned;
|
|
22473
|
+
}
|
|
22474
|
+
// and if not found in cache use default value `false`
|
|
22475
|
+
return false;
|
|
22476
|
+
}
|
|
22477
|
+
|
|
22478
|
+
function getSubChannelUnreadCount(channelId, subChannelId, marker) {
|
|
22479
|
+
var _a, _b;
|
|
22480
|
+
// Look for `unreadCount` in the marker param first
|
|
22481
|
+
if (marker) {
|
|
22482
|
+
return marker.unreadCount;
|
|
22483
|
+
}
|
|
22484
|
+
const client = getActiveClient();
|
|
22485
|
+
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22486
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22487
|
+
const cachedUnreadCount = (_a = pullFromCache([
|
|
22488
|
+
'subChannelUnreadInfo',
|
|
22489
|
+
'get',
|
|
22250
22490
|
subChannelId,
|
|
22251
|
-
|
|
22252
|
-
|
|
22253
|
-
|
|
22254
|
-
|
|
22255
|
-
|
|
22256
|
-
|
|
22491
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22492
|
+
if (cachedUnreadCount) {
|
|
22493
|
+
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
22494
|
+
}
|
|
22495
|
+
return 0;
|
|
22496
|
+
}
|
|
22497
|
+
const key = {
|
|
22498
|
+
entityId: channelId,
|
|
22499
|
+
feedId: subChannelId,
|
|
22500
|
+
userId: getActiveUser()._id,
|
|
22501
|
+
};
|
|
22502
|
+
// If the marker param is not set, look in the cache
|
|
22503
|
+
const cachedMarker = (_b = pullFromCache([
|
|
22504
|
+
'subChannelMarker',
|
|
22505
|
+
'get',
|
|
22506
|
+
getResolver('subChannelMarker')(key),
|
|
22507
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22508
|
+
if (cachedMarker) {
|
|
22509
|
+
return cachedMarker.unreadCount;
|
|
22510
|
+
}
|
|
22511
|
+
// and if not found in cache use default value `0`
|
|
22512
|
+
return 0;
|
|
22513
|
+
}
|
|
22514
|
+
|
|
22515
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE$1 = ['broadcast', 'conversation', 'community'];
|
|
22516
|
+
const isUnreadCountSupport$2 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE$1.includes(channelType);
|
|
22517
|
+
function convertFromRaw$2(_a) {
|
|
22518
|
+
var { channelId, channelPublicId, channelType, childCount, creatorId, creatorPublicId, lastMessageId, lastMessageTimestamp, messageFeedId, name } = _a, rest = __rest(_a, ["channelId", "channelPublicId", "channelType", "childCount", "creatorId", "creatorPublicId", "lastMessageId", "lastMessageTimestamp", "messageFeedId", "name"]);
|
|
22519
|
+
return Object.assign(Object.assign({ get unreadCount() {
|
|
22520
|
+
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
22521
|
+
},
|
|
22522
|
+
get hasMentioned() {
|
|
22523
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
22524
|
+
},
|
|
22525
|
+
get isMentioned() {
|
|
22526
|
+
return getSubChannelIsMentioned(channelId, messageFeedId);
|
|
22527
|
+
} }, rest), { channelId: channelPublicId, creatorId: creatorPublicId, displayName: name, lastActivity: lastMessageTimestamp, latestMessageId: lastMessageId, messageCount: childCount, subChannelId: messageFeedId, isUnreadCountSupport: isUnreadCountSupport$2({ channelType }) });
|
|
22528
|
+
}
|
|
22529
|
+
|
|
22530
|
+
const addLocalReferenceId = (payload) => {
|
|
22531
|
+
const client = getActiveClient();
|
|
22532
|
+
const { objectSyncMap } = client;
|
|
22533
|
+
return Object.assign(Object.assign({}, payload), {
|
|
22534
|
+
/* NOTE: This logic is used to get local referenceId for each message.
|
|
22535
|
+
*
|
|
22536
|
+
* if messageId is a local reference id, use it as referenceId else get referenceId from objectSyncMap.
|
|
22537
|
+
* if find referenceId in objectSyncMap, this means this message is a local created message. The referenceId will be local reference id.
|
|
22538
|
+
* if cannot find referenceId in objectSyncMap, referenceId will be undefined.
|
|
22539
|
+
*
|
|
22540
|
+
* The referenceId is undefined means this message is not a local created message (optimistic creation message).
|
|
22541
|
+
*/
|
|
22542
|
+
referenceId: isLocalId(payload.messageId)
|
|
22543
|
+
? payload.messageId
|
|
22544
|
+
: objectSyncMap.get(payload.messageId) });
|
|
22545
|
+
};
|
|
22546
|
+
function convertFromRaw$1(message, reactors, event) {
|
|
22547
|
+
var _a;
|
|
22548
|
+
const messageWithReferenceId = addLocalReferenceId(message);
|
|
22549
|
+
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = messageWithReferenceId, rest = __rest(messageWithReferenceId, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
22550
|
+
let cache;
|
|
22551
|
+
if (referenceId) {
|
|
22552
|
+
cache = pullFromCache(['message', 'get', referenceId]);
|
|
22553
|
+
}
|
|
22554
|
+
if (!cache) {
|
|
22555
|
+
cache = pullFromCache(['message', 'get', messageId]);
|
|
22556
|
+
}
|
|
22557
|
+
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, creatorPrivateId: message.creatorId, reactions: reactions !== null && reactions !== void 0 ? reactions : {},
|
|
22558
|
+
/*
|
|
22559
|
+
* Previously, myReactions were added only if it was part of the payload.
|
|
22560
|
+
* So empty myReactions were not present. So I've edited the payload to add
|
|
22561
|
+
* a default for those cases.
|
|
22562
|
+
*
|
|
22563
|
+
* Check git blame for previous iteration
|
|
22564
|
+
*/
|
|
22565
|
+
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
22566
|
+
if (mentionedUsers) {
|
|
22567
|
+
out.mentionees = mentionedUsers.map(mention => {
|
|
22568
|
+
if (mention.type === 'channel') {
|
|
22569
|
+
return mention;
|
|
22570
|
+
}
|
|
22571
|
+
return { type: 'user', userIds: mention.userPublicIds };
|
|
22257
22572
|
});
|
|
22258
|
-
|
|
22259
|
-
|
|
22573
|
+
}
|
|
22574
|
+
if (reactors && reactors.length && event) {
|
|
22575
|
+
// mqtt event
|
|
22576
|
+
prepareMessagePayloadForCache(out, reactors, event);
|
|
22577
|
+
}
|
|
22578
|
+
return out;
|
|
22579
|
+
}
|
|
22580
|
+
const preUpdateMessageCache = (rawPayload) => {
|
|
22581
|
+
ingestInCache({
|
|
22582
|
+
messages: rawPayload.messages.map(message => convertFromRaw$1(message, rawPayload.reactions)),
|
|
22583
|
+
});
|
|
22584
|
+
};
|
|
22585
|
+
const DEBOUNCE_TIME = 2000;
|
|
22586
|
+
const currentDebounceMap = {};
|
|
22587
|
+
const prepareMessagePayload = async (payload, event) => {
|
|
22588
|
+
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
22589
|
+
if (markerIds.length > 0) {
|
|
22590
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
22591
|
+
preUpdateMessageCache(payload);
|
|
22592
|
+
const markerIdsKey = markerIds.join('');
|
|
22593
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
22594
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
22595
|
+
}
|
|
22596
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
22597
|
+
try {
|
|
22598
|
+
getMessageMarkers(markerIds);
|
|
22599
|
+
}
|
|
22600
|
+
catch (_error) {
|
|
22601
|
+
// do nothing
|
|
22602
|
+
}
|
|
22603
|
+
}, DEBOUNCE_TIME);
|
|
22604
|
+
}
|
|
22605
|
+
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
22606
|
+
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
22607
|
+
if (messageFeeds && messageFeeds.length > 0) {
|
|
22608
|
+
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
22609
|
+
var _a, _b;
|
|
22610
|
+
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
22611
|
+
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
22612
|
+
const _c = convertFromRaw$2(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "hasMentioned", "isMentioned"]);
|
|
22613
|
+
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
22260
22614
|
});
|
|
22261
22615
|
}
|
|
22262
|
-
|
|
22263
|
-
|
|
22264
|
-
|
|
22265
|
-
|
|
22616
|
+
return Object.assign(Object.assign({}, restPayload), { messages: payload.messages.map(m => convertFromRaw$1(m, payload.reactions, event)) });
|
|
22617
|
+
};
|
|
22618
|
+
function convertParams(_a) {
|
|
22619
|
+
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
22620
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
22621
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
22622
|
+
}
|
|
22623
|
+
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
22624
|
+
}
|
|
22625
|
+
function convertQueryParams$1(_a) {
|
|
22626
|
+
var { sortBy, subChannelId, tags, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "tags", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
22627
|
+
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
22628
|
+
sortBy,
|
|
22629
|
+
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
22630
|
+
around: aroundMessageId,
|
|
22631
|
+
} });
|
|
22632
|
+
if (tags) {
|
|
22633
|
+
out.includeTags = tags;
|
|
22634
|
+
}
|
|
22635
|
+
if (includingTags) {
|
|
22636
|
+
out.includeTags = includingTags;
|
|
22637
|
+
}
|
|
22638
|
+
if (type) {
|
|
22639
|
+
out.dataType = type;
|
|
22640
|
+
}
|
|
22641
|
+
if (excludingTags) {
|
|
22642
|
+
out.excludeTags = excludingTags;
|
|
22643
|
+
}
|
|
22644
|
+
return out;
|
|
22645
|
+
}
|
|
22646
|
+
|
|
22647
|
+
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
22648
|
+
/**
|
|
22649
|
+
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
22650
|
+
*/
|
|
22651
|
+
const isUnreadCountSupport$1 = ({ channelType }) => MARKER_INCLUDED_SUB_CHANNEL_TYPE.includes(channelType);
|
|
22652
|
+
const preUpdateSubChannelCache = (rawPayload) => {
|
|
22653
|
+
ingestInCache({
|
|
22654
|
+
messageFeeds: rawPayload.messageFeeds.map(messageFeed => convertFromRaw$2(messageFeed)),
|
|
22655
|
+
});
|
|
22656
|
+
};
|
|
22657
|
+
const prepareSubChannelPayload = async (rawPayload) => {
|
|
22658
|
+
const markerIds = rawPayload.messageFeeds
|
|
22659
|
+
.filter(isUnreadCountSupport$1)
|
|
22660
|
+
.map(({ messageFeedId }) => messageFeedId);
|
|
22661
|
+
if (markerIds.length > 0) {
|
|
22662
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
22663
|
+
preUpdateSubChannelCache(rawPayload);
|
|
22664
|
+
try {
|
|
22665
|
+
await getSubChannelMarkers(markerIds);
|
|
22666
|
+
}
|
|
22667
|
+
catch (e) {
|
|
22668
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
22669
|
+
}
|
|
22670
|
+
}
|
|
22671
|
+
updateSubChannelMessagePreviewCache(rawPayload);
|
|
22672
|
+
// attach marker to sub channel
|
|
22673
|
+
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
22674
|
+
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
22675
|
+
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
22676
|
+
messages });
|
|
22677
|
+
};
|
|
22678
|
+
function convertQueryParams(_a) {
|
|
22679
|
+
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
22680
|
+
const out = Object.assign({}, rest);
|
|
22681
|
+
if (excludeDefaultSubChannel !== undefined) {
|
|
22682
|
+
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
22683
|
+
}
|
|
22684
|
+
return out;
|
|
22685
|
+
}
|
|
22686
|
+
|
|
22687
|
+
/**
|
|
22688
|
+
* ```js
|
|
22689
|
+
* import { getSubChannel } from '@amityco/ts-sdk-react-native'
|
|
22690
|
+
* const subChannel = await getSubChannel('foobar')
|
|
22691
|
+
* ```
|
|
22692
|
+
*
|
|
22693
|
+
* Fetches a {@link Amity.SubChannel} object
|
|
22694
|
+
*
|
|
22695
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
22696
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
22697
|
+
*
|
|
22698
|
+
* @category Channel API
|
|
22699
|
+
* @async
|
|
22700
|
+
*/
|
|
22701
|
+
const getSubChannel$1 = async (subChannelId) => {
|
|
22702
|
+
const client = getActiveClient();
|
|
22703
|
+
client.log('channel/getSubChannel', subChannelId);
|
|
22704
|
+
isInTombstone('subChannel', subChannelId);
|
|
22705
|
+
try {
|
|
22706
|
+
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
22707
|
+
const data = await prepareSubChannelPayload(response.data);
|
|
22708
|
+
const cachedAt = client.cache && Date.now();
|
|
22709
|
+
if (client.cache)
|
|
22710
|
+
ingestInCache(data, { cachedAt });
|
|
22711
|
+
fireEvent('local.message-feed.fetched', data);
|
|
22712
|
+
return {
|
|
22713
|
+
data: data.messageFeeds[0],
|
|
22714
|
+
cachedAt,
|
|
22715
|
+
};
|
|
22716
|
+
}
|
|
22717
|
+
catch (error) {
|
|
22718
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22719
|
+
pushToTombstone('subChannel', subChannelId);
|
|
22720
|
+
}
|
|
22721
|
+
throw error;
|
|
22722
|
+
}
|
|
22723
|
+
};
|
|
22724
|
+
/**
|
|
22725
|
+
* ```js
|
|
22726
|
+
* import { getSubChannel } from '@amityco/ts-sdk-react-native'
|
|
22727
|
+
* const subChannel = getSubChannel.locally('foobar')
|
|
22728
|
+
* ```
|
|
22729
|
+
*
|
|
22730
|
+
* Fetches a {@link Amity.SubChannel} object from cache
|
|
22731
|
+
*
|
|
22732
|
+
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
22733
|
+
* @returns the associated {@link Amity.SubChannel} object
|
|
22734
|
+
*
|
|
22735
|
+
* @category Channel API
|
|
22736
|
+
*/
|
|
22737
|
+
getSubChannel$1.locally = (subChannelId) => {
|
|
22738
|
+
const client = getActiveClient();
|
|
22739
|
+
client.log('channel/getSubChannel.locally', subChannelId);
|
|
22740
|
+
if (!client.cache)
|
|
22741
|
+
return;
|
|
22742
|
+
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
22743
|
+
if (!cached)
|
|
22744
|
+
return;
|
|
22745
|
+
return {
|
|
22746
|
+
data: cached.data,
|
|
22747
|
+
cachedAt: cached.cachedAt,
|
|
22748
|
+
};
|
|
22749
|
+
};
|
|
22750
|
+
|
|
22751
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
22752
|
+
return new Date(dateString).getTime();
|
|
22753
|
+
};
|
|
22754
|
+
|
|
22755
|
+
const getMessagePreviewSetting$1 = async () => {
|
|
22756
|
+
const client = getActiveClient();
|
|
22757
|
+
return client.getMessagePreviewSetting(false);
|
|
22758
|
+
};
|
|
22759
|
+
const getSubChannelCache = async (subChannelId) => {
|
|
22760
|
+
var _a;
|
|
22761
|
+
let subChannelCache = (_a = pullFromCache(['subChannel', 'get', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22762
|
+
if (!subChannelCache) {
|
|
22763
|
+
subChannelCache = (await getSubChannel$1(subChannelId)).data;
|
|
22764
|
+
}
|
|
22765
|
+
return subChannelCache;
|
|
22766
|
+
};
|
|
22767
|
+
const isLastestMessageOnSubchannel = (message) => {
|
|
22768
|
+
var _a;
|
|
22769
|
+
const cache = (_a = pullFromCache([
|
|
22770
|
+
'messagePreviewSubChannel',
|
|
22771
|
+
'get',
|
|
22772
|
+
message.subChannelId,
|
|
22773
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22774
|
+
// The message payload from optimistic created event has no segment, so we check createdAt instead.
|
|
22775
|
+
return (!cache ||
|
|
22776
|
+
cache.segment <= message.channelSegment ||
|
|
22777
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
22778
|
+
};
|
|
22779
|
+
const isLastestMessageOnChannel = (message) => {
|
|
22780
|
+
var _a;
|
|
22781
|
+
const cache = (_a = pullFromCache([
|
|
22266
22782
|
'messagePreviewChannel',
|
|
22267
22783
|
'get',
|
|
22268
22784
|
message.channelId,
|
|
22269
|
-
])) === null ||
|
|
22270
|
-
|
|
22271
|
-
|
|
22272
|
-
|
|
22273
|
-
|
|
22274
|
-
|
|
22275
|
-
|
|
22276
|
-
|
|
22277
|
-
|
|
22278
|
-
|
|
22785
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22786
|
+
return (!cache ||
|
|
22787
|
+
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
22788
|
+
};
|
|
22789
|
+
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
22790
|
+
const messagePreviewSetting = await getMessagePreviewSetting$1();
|
|
22791
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
22792
|
+
// 1. get subChannel from cache, if not exist fetch from server
|
|
22793
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
22794
|
+
// 2. if messagePreviewSetting is NO_MESSAGE_PREVEIW, update only lastActiviy in subChannel cache
|
|
22795
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
22796
|
+
// 2.1 if the message is the latest message, update lastActivity to be createdAt in subChannel cache
|
|
22797
|
+
if (convertDateStringToTimestamp(subChannelCache.lastActivity) <
|
|
22798
|
+
convertDateStringToTimestamp(createdAt))
|
|
22799
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
22800
|
+
lastActivity: createdAt,
|
|
22801
|
+
});
|
|
22802
|
+
return;
|
|
22803
|
+
}
|
|
22804
|
+
// 3. if messagePreviewSetting is `NOT` NO_MESSAGE_PREVEIW, update messagePreviewSubChannel and subChannel cache
|
|
22805
|
+
// 3.1 check if the message is the latest message, if not ignore the message.
|
|
22806
|
+
if (!isLastestMessageOnSubchannel(message))
|
|
22807
|
+
return;
|
|
22808
|
+
// 3.2 if the message is the latest message, update messagePreviewSubChannel and subChannel cache
|
|
22809
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
22810
|
+
channelId,
|
|
22811
|
+
creatorId,
|
|
22812
|
+
messagePreviewId,
|
|
22813
|
+
createdAt,
|
|
22814
|
+
updatedAt,
|
|
22815
|
+
subChannelId,
|
|
22816
|
+
data,
|
|
22817
|
+
dataType,
|
|
22818
|
+
segment,
|
|
22819
|
+
isDeleted,
|
|
22820
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
22821
|
+
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
22822
|
+
});
|
|
22823
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
22824
|
+
lastActivity: createdAt,
|
|
22825
|
+
messagePreviewId,
|
|
22826
|
+
});
|
|
22827
|
+
};
|
|
22828
|
+
const handleMessageUpdatedOnSubChannel = async (message) => {
|
|
22829
|
+
var _a;
|
|
22830
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
22831
|
+
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
22832
|
+
'messagePreviewSubChannel',
|
|
22833
|
+
'get',
|
|
22834
|
+
message.subChannelId,
|
|
22835
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22836
|
+
// if messagePreviewSubChannel is not exist, ignore the message.
|
|
22837
|
+
if (messagePreviewSubChannelCache &&
|
|
22838
|
+
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
22839
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
22840
|
+
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
22279
22841
|
channelId,
|
|
22280
22842
|
creatorId,
|
|
22281
22843
|
messagePreviewId,
|
|
@@ -22286,38 +22848,16 @@ const handleMessageCreated = async (message) => {
|
|
|
22286
22848
|
dataType,
|
|
22287
22849
|
segment,
|
|
22288
22850
|
isDeleted,
|
|
22289
|
-
subChannelUpdatedAt: subChannelCache
|
|
22290
|
-
subChannelName:
|
|
22851
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
22852
|
+
subChannelName: messagePreviewSubChannelCache.subChannelName,
|
|
22291
22853
|
});
|
|
22292
22854
|
}
|
|
22293
22855
|
};
|
|
22294
|
-
const
|
|
22295
|
-
var _a, _b, _c, _d;
|
|
22856
|
+
const handleMessageCreated = async (message) => {
|
|
22296
22857
|
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
22297
|
-
|
|
22298
|
-
|
|
22299
|
-
|
|
22300
|
-
*/
|
|
22301
|
-
const messagePreviewSubChannelCache = (_a = pullFromCache([
|
|
22302
|
-
'messagePreviewSubChannel',
|
|
22303
|
-
'get',
|
|
22304
|
-
message.subChannelId,
|
|
22305
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22306
|
-
if (messagePreviewSubChannelCache &&
|
|
22307
|
-
messagePreviewSubChannelCache.messagePreviewId === message.messageId) {
|
|
22308
|
-
/**
|
|
22309
|
-
* subChannelCache not have messagePreviewId so update it directly
|
|
22310
|
-
* because this function allow only corresponding subChannel
|
|
22311
|
-
*/
|
|
22312
|
-
const subChannelCache = (_b = pullFromCache([
|
|
22313
|
-
'subChannel',
|
|
22314
|
-
'get',
|
|
22315
|
-
subChannelId,
|
|
22316
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22317
|
-
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
22318
|
-
messagePreviewId,
|
|
22319
|
-
});
|
|
22320
|
-
pushToCache(['messagePreviewSubChannel', 'get', message.subChannelId], {
|
|
22858
|
+
if (isLastestMessageOnChannel(message)) {
|
|
22859
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
22860
|
+
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
22321
22861
|
channelId,
|
|
22322
22862
|
creatorId,
|
|
22323
22863
|
messagePreviewId,
|
|
@@ -22328,25 +22868,25 @@ const handleMessageUpdated = async (message) => {
|
|
|
22328
22868
|
dataType,
|
|
22329
22869
|
segment,
|
|
22330
22870
|
isDeleted,
|
|
22331
|
-
subChannelUpdatedAt:
|
|
22871
|
+
subChannelUpdatedAt: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.updatedAt,
|
|
22332
22872
|
subChannelName: subChannelCache === null || subChannelCache === void 0 ? void 0 : subChannelCache.displayName,
|
|
22333
22873
|
});
|
|
22334
22874
|
}
|
|
22875
|
+
};
|
|
22876
|
+
const handleMessageUpdated = async (message) => {
|
|
22335
22877
|
/**
|
|
22336
22878
|
* Channel Case
|
|
22337
22879
|
*/
|
|
22338
|
-
|
|
22880
|
+
var _a;
|
|
22881
|
+
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
22882
|
+
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
22339
22883
|
'messagePreviewChannel',
|
|
22340
22884
|
'get',
|
|
22341
22885
|
message.channelId,
|
|
22342
|
-
])) === null ||
|
|
22886
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22343
22887
|
if (messagePreviewChannelCache &&
|
|
22344
22888
|
messagePreviewChannelCache.messagePreviewId === message.messageId) {
|
|
22345
|
-
const subChannelCache =
|
|
22346
|
-
'subChannel',
|
|
22347
|
-
'get',
|
|
22348
|
-
subChannelId,
|
|
22349
|
-
])) === null || _d === void 0 ? void 0 : _d.data;
|
|
22889
|
+
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
22350
22890
|
pushToCache(['messagePreviewChannel', 'get', message.channelId], {
|
|
22351
22891
|
channelId,
|
|
22352
22892
|
creatorId,
|
|
@@ -22358,8 +22898,8 @@ const handleMessageUpdated = async (message) => {
|
|
|
22358
22898
|
dataType,
|
|
22359
22899
|
segment,
|
|
22360
22900
|
isDeleted,
|
|
22361
|
-
subChannelUpdatedAt: subChannelCache
|
|
22362
|
-
subChannelName:
|
|
22901
|
+
subChannelUpdatedAt: subChannelCache.updatedAt,
|
|
22902
|
+
subChannelName: messagePreviewChannelCache.subChannelName,
|
|
22363
22903
|
});
|
|
22364
22904
|
}
|
|
22365
22905
|
};
|
|
@@ -22403,8 +22943,8 @@ function convertRawUserToInternalUser(rawUser) {
|
|
|
22403
22943
|
}
|
|
22404
22944
|
|
|
22405
22945
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
22406
|
-
const isUnreadCountSupport
|
|
22407
|
-
function convertFromRaw
|
|
22946
|
+
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
22947
|
+
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
22408
22948
|
var _a;
|
|
22409
22949
|
let { messagePreviewId } = channel;
|
|
22410
22950
|
const messagePreviewChannelCache = (_a = pullFromCache([
|
|
@@ -22415,11 +22955,11 @@ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true })
|
|
|
22415
22955
|
if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
|
|
22416
22956
|
messagePreviewId = messagePreviewChannelCache.messagePreviewId;
|
|
22417
22957
|
}
|
|
22418
|
-
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport
|
|
22958
|
+
return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport(channel), messagePreviewId });
|
|
22419
22959
|
}
|
|
22420
22960
|
const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
22421
22961
|
ingestInCache({
|
|
22422
|
-
channels: rawPayload.channels.map(channel => convertFromRaw
|
|
22962
|
+
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
22423
22963
|
});
|
|
22424
22964
|
};
|
|
22425
22965
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
@@ -22433,7 +22973,7 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22433
22973
|
}
|
|
22434
22974
|
const markerIds = rawPayload.channels
|
|
22435
22975
|
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
22436
|
-
.filter(isUnreadCountSupport
|
|
22976
|
+
.filter(isUnreadCountSupport)
|
|
22437
22977
|
.map(({ channelInternalId }) => channelInternalId);
|
|
22438
22978
|
if (markerIds.length > 0) {
|
|
22439
22979
|
// since the get markers method requires a channel cache to function with the reducer.
|
|
@@ -22446,7 +22986,7 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22446
22986
|
}
|
|
22447
22987
|
}
|
|
22448
22988
|
// attach marker to channel
|
|
22449
|
-
const channels = rawPayload.channels.map(payload => convertFromRaw
|
|
22989
|
+
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
22450
22990
|
// user marker to channel users
|
|
22451
22991
|
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
22452
22992
|
return convertRawMembershipToMembership(channelUser);
|
|
@@ -22486,44 +23026,6 @@ const getUserMessageFeedMakers = async (channelIds) => {
|
|
|
22486
23026
|
return data;
|
|
22487
23027
|
};
|
|
22488
23028
|
|
|
22489
|
-
const persistUnreadCountInfo = (payload) => {
|
|
22490
|
-
const { feedMarkers, userFeedMarkers } = payload;
|
|
22491
|
-
// calculate sub channel unread info and channel unread info
|
|
22492
|
-
if (feedMarkers.length > 0 && userFeedMarkers.length > 0) {
|
|
22493
|
-
const channelIds = [];
|
|
22494
|
-
const feedMarkerMap = new Map(feedMarkers.map(fm => [fm.feedId, fm]));
|
|
22495
|
-
userFeedMarkers.forEach(userFeedMarker => {
|
|
22496
|
-
const feedMarker = feedMarkerMap.get(userFeedMarker.feedId);
|
|
22497
|
-
if (!feedMarker)
|
|
22498
|
-
return;
|
|
22499
|
-
if (feedMarker.feedId === userFeedMarker.feedId) {
|
|
22500
|
-
const unreadCount = feedMarker.lastSegment - userFeedMarker.readToSegment;
|
|
22501
|
-
const subChannelUnreadInfo = {
|
|
22502
|
-
subChannelId: feedMarker.feedId,
|
|
22503
|
-
channelId: feedMarker.entityId,
|
|
22504
|
-
readToSegment: userFeedMarker.readToSegment,
|
|
22505
|
-
lastSegment: feedMarker.lastSegment,
|
|
22506
|
-
lastMentionSegment: userFeedMarker.lastMentionSegment,
|
|
22507
|
-
unreadCount: Math.max(0, unreadCount),
|
|
22508
|
-
isMentioned: userFeedMarker.isMentioned,
|
|
22509
|
-
isDeleted: feedMarker.isDeleted,
|
|
22510
|
-
createdAt: userFeedMarker.createdAt,
|
|
22511
|
-
updatedAt: userFeedMarker.updatedAt,
|
|
22512
|
-
};
|
|
22513
|
-
// update sub channel unread info in cache
|
|
22514
|
-
ingestInCache({ subChannelUnreadInfo: [subChannelUnreadInfo] });
|
|
22515
|
-
if (!channelIds.includes(feedMarker.entityId)) {
|
|
22516
|
-
channelIds.push(feedMarker.entityId);
|
|
22517
|
-
}
|
|
22518
|
-
}
|
|
22519
|
-
});
|
|
22520
|
-
// re-calculate channel unread info in cache
|
|
22521
|
-
channelIds.forEach(channelId => {
|
|
22522
|
-
reCalculateChannelUnreadInfo(channelId);
|
|
22523
|
-
});
|
|
22524
|
-
}
|
|
22525
|
-
};
|
|
22526
|
-
|
|
22527
23029
|
const prepareUnreadCountInfo = async (rawPayload) => {
|
|
22528
23030
|
const client = getActiveClient();
|
|
22529
23031
|
// if consistent mode is enabled, persist the unread count info to the cache
|
|
@@ -22558,551 +23060,156 @@ const getUnreadInfoCached$1 = (channelId) => {
|
|
|
22558
23060
|
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22559
23061
|
*
|
|
22560
23062
|
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22561
|
-
* If not, the function will return the value from the channelMarker cache.
|
|
22562
|
-
* If not found in the both cache, use `false` as defaul value.
|
|
22563
|
-
*/
|
|
22564
|
-
const getChannelIsMentioned = (channel, marker) => {
|
|
22565
|
-
var _a, _b, _c, _d;
|
|
22566
|
-
const client = getActiveClient();
|
|
22567
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22568
|
-
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22569
|
-
}
|
|
22570
|
-
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
22571
|
-
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
22572
|
-
: (_d = (_c = getCachedMarker$1(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22573
|
-
};
|
|
22574
|
-
|
|
22575
|
-
const getCachedMarker = (entityId) => {
|
|
22576
|
-
var _a;
|
|
22577
|
-
const key = {
|
|
22578
|
-
entityId,
|
|
22579
|
-
userId: getActiveUser()._id,
|
|
22580
|
-
};
|
|
22581
|
-
return (_a = pullFromCache([
|
|
22582
|
-
'channelMarker',
|
|
22583
|
-
'get',
|
|
22584
|
-
getResolver('channelMarker')(key),
|
|
22585
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22586
|
-
};
|
|
22587
|
-
const getUnreadInfoCached = (channelId) => {
|
|
22588
|
-
var _a;
|
|
22589
|
-
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22590
|
-
};
|
|
22591
|
-
/**
|
|
22592
|
-
* The function use to get value of unreadCount field.
|
|
22593
|
-
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
22594
|
-
*
|
|
22595
|
-
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
22596
|
-
* If not, the function will return the value from the channelMarker cache.
|
|
22597
|
-
* If not found in the both cache, use `0` as defaul value.
|
|
22598
|
-
*/
|
|
22599
|
-
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
22600
|
-
var _a, _b, _c, _d, _e;
|
|
22601
|
-
const client = getActiveClient();
|
|
22602
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22603
|
-
// Marker service API uses channelInternalId as channelId
|
|
22604
|
-
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22605
|
-
}
|
|
22606
|
-
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
22607
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
22608
|
-
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
22609
|
-
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
22610
|
-
return 0;
|
|
22611
|
-
}
|
|
22612
|
-
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
22613
|
-
};
|
|
22614
|
-
|
|
22615
|
-
const constructChannelDynamicValue = (channel) => {
|
|
22616
|
-
return shallowClone(channel, {
|
|
22617
|
-
get unreadCount() {
|
|
22618
|
-
return getSubChannelsUnreadCount(channel);
|
|
22619
|
-
},
|
|
22620
|
-
get hasMentioned() {
|
|
22621
|
-
return getChannelIsMentioned(channel);
|
|
22622
|
-
},
|
|
22623
|
-
get isMentioned() {
|
|
22624
|
-
return getChannelIsMentioned(channel);
|
|
22625
|
-
},
|
|
22626
|
-
get subChannelsUnreadCount() {
|
|
22627
|
-
return getSubChannelsUnreadCount(channel);
|
|
22628
|
-
},
|
|
22629
|
-
});
|
|
22630
|
-
};
|
|
22631
|
-
|
|
22632
|
-
/**
|
|
22633
|
-
* ```js
|
|
22634
|
-
* import { getChannelByIds } from '@amityco/ts-sdk-react-native'
|
|
22635
|
-
* const channels = await getChannelByIds(['foo', 'bar'])
|
|
22636
|
-
* ```
|
|
22637
|
-
*
|
|
22638
|
-
* Fetches a collection of {@link Amity.Channel} objects
|
|
22639
|
-
*
|
|
22640
|
-
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
22641
|
-
* @returns the associated collection of {@link Amity.Channel} objects
|
|
22642
|
-
*
|
|
22643
|
-
* @category Channel API
|
|
22644
|
-
* @async
|
|
22645
|
-
*/
|
|
22646
|
-
const getChannelByIds = async (channelIds) => {
|
|
22647
|
-
const client = getActiveClient();
|
|
22648
|
-
client.log('channel/getChannelByIds', channelIds);
|
|
22649
|
-
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
22650
|
-
let payload;
|
|
22651
|
-
try {
|
|
22652
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22653
|
-
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
22654
|
-
params: { channelIds: encodedChannelIds },
|
|
22655
|
-
});
|
|
22656
|
-
payload = response.data;
|
|
22657
|
-
}
|
|
22658
|
-
catch (error) {
|
|
22659
|
-
channelIds.forEach(channelId => {
|
|
22660
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22661
|
-
// NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
|
|
22662
|
-
pushToTombstone('channel', channelId);
|
|
22663
|
-
}
|
|
22664
|
-
});
|
|
22665
|
-
throw error;
|
|
22666
|
-
}
|
|
22667
|
-
const data = await prepareChannelPayload(payload);
|
|
22668
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22669
|
-
await prepareUnreadCountInfo(payload);
|
|
22670
|
-
}
|
|
22671
|
-
const cachedAt = client.cache && Date.now();
|
|
22672
|
-
if (client.cache)
|
|
22673
|
-
ingestInCache(data, { cachedAt });
|
|
22674
|
-
fireEvent('local.channel.fetched', data.channels);
|
|
22675
|
-
return {
|
|
22676
|
-
data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
|
|
22677
|
-
cachedAt,
|
|
22678
|
-
};
|
|
22679
|
-
};
|
|
22680
|
-
/**
|
|
22681
|
-
* ```js
|
|
22682
|
-
* import { getChannelByIds } from '@amityco/ts-sdk-react-native'
|
|
22683
|
-
* const channels = getChannelByIds.locally(['foo', 'bar']) ?? []
|
|
22684
|
-
* ```
|
|
22685
|
-
*
|
|
22686
|
-
* Fetches a collection of {@link Amity.Channel} objects from cache
|
|
22687
|
-
*
|
|
22688
|
-
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
22689
|
-
* @returns the associated collection of {@link Amity.Channel} objects
|
|
22690
|
-
*
|
|
22691
|
-
* @category Channel API
|
|
22692
|
-
*/
|
|
22693
|
-
getChannelByIds.locally = (channelIds) => {
|
|
22694
|
-
var _a, _b;
|
|
22695
|
-
const client = getActiveClient();
|
|
22696
|
-
client.log('channel/getChannelByIds.locally', channelIds);
|
|
22697
|
-
if (!client.cache)
|
|
22698
|
-
return;
|
|
22699
|
-
const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
22700
|
-
return channelIds.includes(data.channelPublicId);
|
|
22701
|
-
});
|
|
22702
|
-
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
22703
|
-
return;
|
|
22704
|
-
const channels = cached.map(({ data }) => data);
|
|
22705
|
-
const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
|
|
22706
|
-
return {
|
|
22707
|
-
data: channels.map(channel => LinkedObject.channel(channel)),
|
|
22708
|
-
cachedAt: oldest.cachedAt,
|
|
22709
|
-
};
|
|
22710
|
-
};
|
|
22711
|
-
|
|
22712
|
-
/**
|
|
22713
|
-
* ```js
|
|
22714
|
-
* import { getMessageMarkers } from '@amityco/ts-sdk-react-native'
|
|
22715
|
-
* const messageMarkers = await getMessageMarkers(['sch1', 'sch2'])
|
|
22716
|
-
* ```
|
|
22717
|
-
*
|
|
22718
|
-
* Fetches a list of {@link Amity.MessageMarker} by messageIds
|
|
22719
|
-
*
|
|
22720
|
-
* @param messageIds the feed IDs of the {@link Amity.RawMessage} marker to fetch
|
|
22721
|
-
* @returns A list of {@link Amity.MessageMarker} by messageIds
|
|
22722
|
-
*
|
|
22723
|
-
* @category Channel API
|
|
22724
|
-
* @async
|
|
22725
|
-
* @private
|
|
22726
|
-
*/
|
|
22727
|
-
const getMessageMarkers = async (messageIds) => {
|
|
22728
|
-
const client = getActiveClient();
|
|
22729
|
-
client.log('channel/getMessageMarkers', messageIds);
|
|
22730
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/messages`, {
|
|
22731
|
-
params: {
|
|
22732
|
-
messageIds,
|
|
22733
|
-
},
|
|
22734
|
-
});
|
|
22735
|
-
const { contentMarkers, feedMarkers, userMarkers } = queryPayload;
|
|
22736
|
-
const cachedAt = client.cache && Date.now();
|
|
22737
|
-
if (client.cache)
|
|
22738
|
-
ingestInCache({ contentMarkers, feedMarkers, userMarkers }, { cachedAt });
|
|
22739
|
-
fireEvent('local.feedMarker.fetched', { feedMarkers });
|
|
22740
|
-
fireEvent('local.messageMarker.fetched', { contentMarkers });
|
|
22741
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22742
|
-
return { data: contentMarkers, cachedAt };
|
|
22743
|
-
};
|
|
22744
|
-
|
|
22745
|
-
/**
|
|
22746
|
-
* ```js
|
|
22747
|
-
* import { getSubChannelMarkers } from '@amityco/ts-sdk-react-native'
|
|
22748
|
-
* const subChannelMarkers = await getSubChannelMarkers(['sch1', 'sch2'])
|
|
22749
|
-
* ```
|
|
22750
|
-
*
|
|
22751
|
-
* Fetches a paginable list of {@link Amity.SubChannelMarker} objects
|
|
22752
|
-
*
|
|
22753
|
-
* @param messageFeedIds the feed IDs of the {@link Amity.RawSubChannel} marker to fetch
|
|
22754
|
-
* @param page
|
|
22755
|
-
* @returns A page of {@link Amity.SubChannelMarker} objects
|
|
22756
|
-
*
|
|
22757
|
-
* @category Channel API
|
|
22758
|
-
* @async
|
|
22759
|
-
* @private
|
|
22760
|
-
*/
|
|
22761
|
-
const getSubChannelMarkers = async (messageFeedIds, page = { limit: 100 }) => {
|
|
22762
|
-
const client = getActiveClient();
|
|
22763
|
-
client.log('channel/getSubChannelMarkers', messageFeedIds, page);
|
|
22764
|
-
const { data: queryPayload } = await client.http.get(`/api/v1/markers/message-feeds`, {
|
|
22765
|
-
params: {
|
|
22766
|
-
messageFeedIds,
|
|
22767
|
-
options: {
|
|
22768
|
-
token: toToken(page, 'skiplimit'),
|
|
22769
|
-
},
|
|
22770
|
-
},
|
|
22771
|
-
});
|
|
22772
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22773
|
-
const { userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload, userMarkers, feedMarkers: feedMarkersPayload, } = payload;
|
|
22774
|
-
// if consistent mode is enabled, persist the unread count info to the cache
|
|
22775
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22776
|
-
persistUnreadCountInfo({
|
|
22777
|
-
feedMarkers: feedMarkersPayload,
|
|
22778
|
-
userFeedMarkers: userFeedMarkersPayload,
|
|
22779
|
-
});
|
|
22780
|
-
}
|
|
22781
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
22782
|
-
const userFeedMarkers = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
22783
|
-
const cachedAt = client.cache && Date.now();
|
|
22784
|
-
if (client.cache)
|
|
22785
|
-
ingestInCache({ userEntityMarkers, userFeedMarkers, userMarkers }, { cachedAt });
|
|
22786
|
-
fireEvent('local.channelMarker.fetched', { userEntityMarkers });
|
|
22787
|
-
fireEvent('local.subChannelMarker.fetched', { userFeedMarkers });
|
|
22788
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22789
|
-
const nextPage = toPage(paging.next);
|
|
22790
|
-
const prevPage = toPage(paging.previous);
|
|
22791
|
-
return { data: userFeedMarkers, cachedAt, prevPage, nextPage };
|
|
22792
|
-
};
|
|
22793
|
-
|
|
22794
|
-
const getUserMarker = async () => {
|
|
22795
|
-
const client = getActiveClient();
|
|
22796
|
-
client.log('channel/getUserMarker');
|
|
22797
|
-
const { data: payload } = await client.http.get(`/api/v1/markers/userMarker`);
|
|
22798
|
-
const { userMarkers } = payload;
|
|
22799
|
-
const cachedAt = client.cache && Date.now();
|
|
22800
|
-
if (client.cache)
|
|
22801
|
-
ingestInCache({ userMarkers }, { cachedAt });
|
|
22802
|
-
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
22803
|
-
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
22804
|
-
if (maxUserMarker == null ||
|
|
22805
|
-
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
22806
|
-
return userMarker;
|
|
22807
|
-
}
|
|
22808
|
-
return maxUserMarker;
|
|
22809
|
-
}, undefined);
|
|
22810
|
-
return { data: latestUserMarker, cachedAt };
|
|
22811
|
-
};
|
|
22812
|
-
|
|
22813
|
-
/** @hidden */
|
|
22814
|
-
/*
|
|
22815
|
-
* @param message payload from http request without myReactions
|
|
22816
|
-
* add myReactions to http response if the event was a reaction event
|
|
22817
|
-
*/
|
|
22818
|
-
const prepareMessagePayloadForCache = (payload, reactors, event) => {
|
|
22819
|
-
const client = getActiveClient();
|
|
22820
|
-
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22821
|
-
// '[]' in cases where the new reaction is the first one
|
|
22822
|
-
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22823
|
-
// add myReactions to the payload
|
|
22824
|
-
Object.assign(payload, { myReactions });
|
|
22825
|
-
// check if there are any updates to the reactions
|
|
22826
|
-
const latestReaction = reactors[0];
|
|
22827
|
-
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22828
|
-
if (!isLatestReactionMine) {
|
|
22829
|
-
return;
|
|
22830
|
-
}
|
|
22831
|
-
// new reaction added
|
|
22832
|
-
if (event === 'message.reactionAdded' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22833
|
-
Object.assign(payload, {
|
|
22834
|
-
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22835
|
-
});
|
|
22836
|
-
}
|
|
22837
|
-
// existing reaction removed
|
|
22838
|
-
if (event === 'message.reactionRemoved' && myReactions.includes(latestReaction.reactionName)) {
|
|
22839
|
-
Object.assign(payload, {
|
|
22840
|
-
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22841
|
-
});
|
|
22842
|
-
}
|
|
22843
|
-
};
|
|
22844
|
-
|
|
22845
|
-
/*
|
|
22846
|
-
* This is a simple utility that infers the value of isDeleted based on the
|
|
22847
|
-
* value of includeDeleted
|
|
22848
|
-
*
|
|
22849
|
-
* There are two important things to note here:
|
|
22850
|
-
* 1. `includeDeleted` is purely client side query param and not recognized by
|
|
22851
|
-
* the server
|
|
22852
|
-
* 2. The only values we wish to expose with regards to `isDeleted` (the server
|
|
22853
|
-
* param for queries) is false | undefined and want to disallow users to query
|
|
22854
|
-
* for deleted entities
|
|
22855
|
-
*
|
|
22856
|
-
* Although this is a very simple utility, it's only purpose is to keep things
|
|
22857
|
-
* DRY
|
|
22858
|
-
*/
|
|
22859
|
-
const inferIsDeleted = (includeDeleted) => includeDeleted === true ? undefined : false;
|
|
22860
|
-
|
|
22861
|
-
function getSubChannelIsMentioned(channelId, subChannelId, marker) {
|
|
22862
|
-
var _a, _b;
|
|
22863
|
-
// Look for `unreadCount` in the marker param first
|
|
22864
|
-
if (marker) {
|
|
22865
|
-
return marker.hasMentioned;
|
|
22866
|
-
}
|
|
22867
|
-
const client = getActiveClient();
|
|
22868
|
-
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22869
|
-
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22870
|
-
const cachedUnreadCount = (_a = pullFromCache([
|
|
22871
|
-
'subChannelUnreadInfo',
|
|
22872
|
-
'get',
|
|
22873
|
-
subChannelId,
|
|
22874
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22875
|
-
if (cachedUnreadCount) {
|
|
22876
|
-
return cachedUnreadCount.isMentioned;
|
|
22877
|
-
}
|
|
22878
|
-
return false;
|
|
23063
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
23064
|
+
* If not found in the both cache, use `false` as defaul value.
|
|
23065
|
+
*/
|
|
23066
|
+
const getChannelIsMentioned = (channel, marker) => {
|
|
23067
|
+
var _a, _b, _c, _d;
|
|
23068
|
+
const client = getActiveClient();
|
|
23069
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
23070
|
+
return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
22879
23071
|
}
|
|
23072
|
+
return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
|
|
23073
|
+
? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
|
|
23074
|
+
: (_d = (_c = getCachedMarker$1(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
23075
|
+
};
|
|
23076
|
+
|
|
23077
|
+
const getCachedMarker = (entityId) => {
|
|
23078
|
+
var _a;
|
|
22880
23079
|
const key = {
|
|
22881
|
-
entityId
|
|
22882
|
-
feedId: subChannelId,
|
|
23080
|
+
entityId,
|
|
22883
23081
|
userId: getActiveUser()._id,
|
|
22884
23082
|
};
|
|
22885
|
-
|
|
22886
|
-
|
|
22887
|
-
'subChannelMarker',
|
|
23083
|
+
return (_a = pullFromCache([
|
|
23084
|
+
'channelMarker',
|
|
22888
23085
|
'get',
|
|
22889
|
-
getResolver('
|
|
22890
|
-
])) === null ||
|
|
22891
|
-
|
|
22892
|
-
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
|
|
22898
|
-
function
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
23086
|
+
getResolver('channelMarker')(key),
|
|
23087
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23088
|
+
};
|
|
23089
|
+
const getUnreadInfoCached = (channelId) => {
|
|
23090
|
+
var _a;
|
|
23091
|
+
return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23092
|
+
};
|
|
23093
|
+
/**
|
|
23094
|
+
* The function use to get value of unreadCount field.
|
|
23095
|
+
* function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
|
|
23096
|
+
*
|
|
23097
|
+
* If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
|
|
23098
|
+
* If not, the function will return the value from the channelMarker cache.
|
|
23099
|
+
* If not found in the both cache, use `0` as defaul value.
|
|
23100
|
+
*/
|
|
23101
|
+
const getSubChannelsUnreadCount = (channel, marker) => {
|
|
23102
|
+
var _a, _b, _c, _d, _e;
|
|
22904
23103
|
const client = getActiveClient();
|
|
22905
|
-
// If consistent mode is enabled, look in the SubChannelUnreadCountInfo cache
|
|
22906
23104
|
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
'get',
|
|
22910
|
-
subChannelId,
|
|
22911
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22912
|
-
if (cachedUnreadCount) {
|
|
22913
|
-
return cachedUnreadCount.isDeleted ? 0 : cachedUnreadCount.unreadCount;
|
|
22914
|
-
}
|
|
22915
|
-
return 0;
|
|
23105
|
+
// Marker service API uses channelInternalId as channelId
|
|
23106
|
+
return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
22916
23107
|
}
|
|
22917
|
-
|
|
22918
|
-
|
|
22919
|
-
|
|
22920
|
-
|
|
22921
|
-
|
|
22922
|
-
// If the marker param is not set, look in the cache
|
|
22923
|
-
const cachedMarker = (_b = pullFromCache([
|
|
22924
|
-
'subChannelMarker',
|
|
22925
|
-
'get',
|
|
22926
|
-
getResolver('subChannelMarker')(key),
|
|
22927
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22928
|
-
if (cachedMarker) {
|
|
22929
|
-
return cachedMarker.unreadCount;
|
|
23108
|
+
if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
|
|
23109
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to
|
|
23110
|
+
// leave the channel because currently backend can't handle this, so every time a user is banned
|
|
23111
|
+
// from a channel or the channel is deleted the channel's unread count will reset to zero
|
|
23112
|
+
return 0;
|
|
22930
23113
|
}
|
|
22931
|
-
|
|
22932
|
-
|
|
22933
|
-
}
|
|
23114
|
+
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
23115
|
+
};
|
|
22934
23116
|
|
|
22935
|
-
const
|
|
22936
|
-
|
|
22937
|
-
|
|
22938
|
-
|
|
22939
|
-
return Object.assign(Object.assign({ get unreadCount() {
|
|
22940
|
-
return getSubChannelUnreadCount(channelId, messageFeedId);
|
|
23117
|
+
const constructChannelDynamicValue = (channel) => {
|
|
23118
|
+
return shallowClone(channel, {
|
|
23119
|
+
get unreadCount() {
|
|
23120
|
+
return getSubChannelsUnreadCount(channel);
|
|
22941
23121
|
},
|
|
22942
23122
|
get hasMentioned() {
|
|
22943
|
-
return
|
|
23123
|
+
return getChannelIsMentioned(channel);
|
|
22944
23124
|
},
|
|
22945
23125
|
get isMentioned() {
|
|
22946
|
-
return
|
|
22947
|
-
}
|
|
22948
|
-
|
|
23126
|
+
return getChannelIsMentioned(channel);
|
|
23127
|
+
},
|
|
23128
|
+
get subChannelsUnreadCount() {
|
|
23129
|
+
return getSubChannelsUnreadCount(channel);
|
|
23130
|
+
},
|
|
23131
|
+
});
|
|
23132
|
+
};
|
|
22949
23133
|
|
|
22950
|
-
|
|
23134
|
+
/**
|
|
23135
|
+
* ```js
|
|
23136
|
+
* import { getChannelByIds } from '@amityco/ts-sdk-react-native'
|
|
23137
|
+
* const channels = await getChannelByIds(['foo', 'bar'])
|
|
23138
|
+
* ```
|
|
23139
|
+
*
|
|
23140
|
+
* Fetches a collection of {@link Amity.Channel} objects
|
|
23141
|
+
*
|
|
23142
|
+
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
23143
|
+
* @returns the associated collection of {@link Amity.Channel} objects
|
|
23144
|
+
*
|
|
23145
|
+
* @category Channel API
|
|
23146
|
+
* @async
|
|
23147
|
+
*/
|
|
23148
|
+
const getChannelByIds = async (channelIds) => {
|
|
22951
23149
|
const client = getActiveClient();
|
|
22952
|
-
|
|
22953
|
-
|
|
22954
|
-
|
|
22955
|
-
|
|
22956
|
-
|
|
22957
|
-
|
|
22958
|
-
|
|
22959
|
-
*
|
|
22960
|
-
* The referenceId is undefined means this message is not a local created message (optimistic creation message).
|
|
22961
|
-
*/
|
|
22962
|
-
referenceId: isLocalId(payload.messageId)
|
|
22963
|
-
? payload.messageId
|
|
22964
|
-
: objectSyncMap.get(payload.messageId) });
|
|
22965
|
-
};
|
|
22966
|
-
function convertFromRaw(message, reactors, event) {
|
|
22967
|
-
var _a;
|
|
22968
|
-
const messageWithReferenceId = addLocalReferenceId(message);
|
|
22969
|
-
const { channelPublicId, childCount, creatorPublicId, mentionedUsers, messageFeedId, myReactions, reactionCount, reactions, referenceId, segment, messageId, creatorId } = messageWithReferenceId, rest = __rest(messageWithReferenceId, ["channelPublicId", "childCount", "creatorPublicId", "mentionedUsers", "messageFeedId", "myReactions", "reactionCount", "reactions", "referenceId", "segment", "messageId", "creatorId"]);
|
|
22970
|
-
let cache;
|
|
22971
|
-
if (referenceId) {
|
|
22972
|
-
cache = pullFromCache(['message', 'get', referenceId]);
|
|
22973
|
-
}
|
|
22974
|
-
if (!cache) {
|
|
22975
|
-
cache = pullFromCache(['message', 'get', messageId]);
|
|
22976
|
-
}
|
|
22977
|
-
const out = Object.assign(Object.assign({}, rest), { messageId, channelId: channelPublicId, channelSegment: segment, childrenNumber: childCount, creatorId: creatorPublicId, creatorPrivateId: message.creatorId, reactions: reactions !== null && reactions !== void 0 ? reactions : {},
|
|
22978
|
-
/*
|
|
22979
|
-
* Previously, myReactions were added only if it was part of the payload.
|
|
22980
|
-
* So empty myReactions were not present. So I've edited the payload to add
|
|
22981
|
-
* a default for those cases.
|
|
22982
|
-
*
|
|
22983
|
-
* Check git blame for previous iteration
|
|
22984
|
-
*/
|
|
22985
|
-
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
22986
|
-
if (mentionedUsers) {
|
|
22987
|
-
out.mentionees = mentionedUsers.map(mention => {
|
|
22988
|
-
if (mention.type === 'channel') {
|
|
22989
|
-
return mention;
|
|
22990
|
-
}
|
|
22991
|
-
return { type: 'user', userIds: mention.userPublicIds };
|
|
23150
|
+
client.log('channel/getChannelByIds', channelIds);
|
|
23151
|
+
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
23152
|
+
let payload;
|
|
23153
|
+
try {
|
|
23154
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23155
|
+
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
23156
|
+
params: { channelIds: encodedChannelIds },
|
|
22992
23157
|
});
|
|
23158
|
+
payload = response.data;
|
|
22993
23159
|
}
|
|
22994
|
-
|
|
22995
|
-
|
|
22996
|
-
|
|
22997
|
-
|
|
22998
|
-
|
|
22999
|
-
}
|
|
23000
|
-
const preUpdateMessageCache = (rawPayload) => {
|
|
23001
|
-
ingestInCache({
|
|
23002
|
-
messages: rawPayload.messages.map(message => convertFromRaw(message, rawPayload.reactions)),
|
|
23003
|
-
});
|
|
23004
|
-
};
|
|
23005
|
-
const DEBOUNCE_TIME = 2000;
|
|
23006
|
-
const currentDebounceMap = {};
|
|
23007
|
-
const prepareMessagePayload = async (payload, event) => {
|
|
23008
|
-
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
23009
|
-
if (markerIds.length > 0) {
|
|
23010
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
23011
|
-
preUpdateMessageCache(payload);
|
|
23012
|
-
const markerIdsKey = markerIds.join('');
|
|
23013
|
-
if (currentDebounceMap[markerIdsKey]) {
|
|
23014
|
-
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
23015
|
-
}
|
|
23016
|
-
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
23017
|
-
try {
|
|
23018
|
-
getMessageMarkers(markerIds);
|
|
23019
|
-
}
|
|
23020
|
-
catch (_error) {
|
|
23021
|
-
// do nothing
|
|
23160
|
+
catch (error) {
|
|
23161
|
+
channelIds.forEach(channelId => {
|
|
23162
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23163
|
+
// NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
|
|
23164
|
+
pushToTombstone('channel', channelId);
|
|
23022
23165
|
}
|
|
23023
|
-
}, DEBOUNCE_TIME);
|
|
23024
|
-
}
|
|
23025
|
-
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
23026
|
-
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
23027
|
-
if (messageFeeds && messageFeeds.length > 0) {
|
|
23028
|
-
messageFeeds === null || messageFeeds === void 0 ? void 0 : messageFeeds.forEach(messageFeed => {
|
|
23029
|
-
var _a, _b;
|
|
23030
|
-
const subChannelCache = (_b = (_a = pullFromCache(['subChannel', 'get', messageFeed.messageFeedId])) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
23031
|
-
// exclude getter properties from existing subChannel cache, update only other properties to existing subChannel cache
|
|
23032
|
-
const _c = convertFromRaw$1(messageFeed), restSubChannel = __rest(_c, ["unreadCount", "hasMentioned", "isMentioned"]);
|
|
23033
|
-
updateSubChannelCache(messageFeed.messageFeedId, subChannelCache, restSubChannel);
|
|
23034
23166
|
});
|
|
23167
|
+
throw error;
|
|
23035
23168
|
}
|
|
23036
|
-
|
|
23037
|
-
|
|
23038
|
-
|
|
23039
|
-
var { subChannelId, mentionees, dataType, data } = _a, rest = __rest(_a, ["subChannelId", "mentionees", "dataType", "data"]);
|
|
23040
|
-
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
23041
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data: Object.assign({ caption: '' }, data) }, rest);
|
|
23042
|
-
}
|
|
23043
|
-
return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data }, rest);
|
|
23044
|
-
}
|
|
23045
|
-
function convertQueryParams$1(_a) {
|
|
23046
|
-
var { sortBy, subChannelId, tags, includingTags, excludingTags, includeDeleted, aroundMessageId, limit, type } = _a, rest = __rest(_a, ["sortBy", "subChannelId", "tags", "includingTags", "excludingTags", "includeDeleted", "aroundMessageId", "limit", "type"]);
|
|
23047
|
-
const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: inferIsDeleted(includeDeleted), options: {
|
|
23048
|
-
sortBy,
|
|
23049
|
-
limit: limit || COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
23050
|
-
around: aroundMessageId,
|
|
23051
|
-
} });
|
|
23052
|
-
if (tags) {
|
|
23053
|
-
out.includeTags = tags;
|
|
23054
|
-
}
|
|
23055
|
-
if (includingTags) {
|
|
23056
|
-
out.includeTags = includingTags;
|
|
23057
|
-
}
|
|
23058
|
-
if (type) {
|
|
23059
|
-
out.dataType = type;
|
|
23060
|
-
}
|
|
23061
|
-
if (excludingTags) {
|
|
23062
|
-
out.excludeTags = excludingTags;
|
|
23169
|
+
const data = await prepareChannelPayload(payload);
|
|
23170
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
23171
|
+
await prepareUnreadCountInfo(payload);
|
|
23063
23172
|
}
|
|
23064
|
-
|
|
23065
|
-
|
|
23066
|
-
|
|
23067
|
-
|
|
23173
|
+
const cachedAt = client.cache && Date.now();
|
|
23174
|
+
if (client.cache)
|
|
23175
|
+
ingestInCache(data, { cachedAt });
|
|
23176
|
+
fireEvent('local.channel.fetched', data.channels);
|
|
23177
|
+
return {
|
|
23178
|
+
data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
|
|
23179
|
+
cachedAt,
|
|
23180
|
+
};
|
|
23181
|
+
};
|
|
23068
23182
|
/**
|
|
23069
|
-
*
|
|
23183
|
+
* ```js
|
|
23184
|
+
* import { getChannelByIds } from '@amityco/ts-sdk-react-native'
|
|
23185
|
+
* const channels = getChannelByIds.locally(['foo', 'bar']) ?? []
|
|
23186
|
+
* ```
|
|
23187
|
+
*
|
|
23188
|
+
* Fetches a collection of {@link Amity.Channel} objects from cache
|
|
23189
|
+
*
|
|
23190
|
+
* @param channelIds the IDs of the {@link Amity.Channel} to fetch
|
|
23191
|
+
* @returns the associated collection of {@link Amity.Channel} objects
|
|
23192
|
+
*
|
|
23193
|
+
* @category Channel API
|
|
23070
23194
|
*/
|
|
23071
|
-
|
|
23072
|
-
|
|
23073
|
-
|
|
23074
|
-
|
|
23195
|
+
getChannelByIds.locally = (channelIds) => {
|
|
23196
|
+
var _a, _b;
|
|
23197
|
+
const client = getActiveClient();
|
|
23198
|
+
client.log('channel/getChannelByIds.locally', channelIds);
|
|
23199
|
+
if (!client.cache)
|
|
23200
|
+
return;
|
|
23201
|
+
const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
23202
|
+
return channelIds.includes(data.channelPublicId);
|
|
23075
23203
|
});
|
|
23076
|
-
|
|
23077
|
-
|
|
23078
|
-
const
|
|
23079
|
-
|
|
23080
|
-
|
|
23081
|
-
|
|
23082
|
-
|
|
23083
|
-
|
|
23084
|
-
|
|
23085
|
-
await getSubChannelMarkers(markerIds);
|
|
23086
|
-
}
|
|
23087
|
-
catch (e) {
|
|
23088
|
-
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
23089
|
-
}
|
|
23090
|
-
}
|
|
23091
|
-
updateSubChannelMessagePreviewCache(rawPayload);
|
|
23092
|
-
// attach marker to sub channel
|
|
23093
|
-
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$1);
|
|
23094
|
-
const messages = rawPayload.messages.map(m => convertFromRaw(m));
|
|
23095
|
-
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
23096
|
-
messages });
|
|
23097
|
-
};
|
|
23098
|
-
function convertQueryParams(_a) {
|
|
23099
|
-
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
23100
|
-
const out = Object.assign({}, rest);
|
|
23101
|
-
if (excludeDefaultSubChannel !== undefined) {
|
|
23102
|
-
out.excludeDefaultMessageFeed = excludeDefaultSubChannel;
|
|
23103
|
-
}
|
|
23104
|
-
return out;
|
|
23105
|
-
}
|
|
23204
|
+
if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
|
|
23205
|
+
return;
|
|
23206
|
+
const channels = cached.map(({ data }) => data);
|
|
23207
|
+
const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
|
|
23208
|
+
return {
|
|
23209
|
+
data: channels.map(channel => LinkedObject.channel(channel)),
|
|
23210
|
+
cachedAt: oldest.cachedAt,
|
|
23211
|
+
};
|
|
23212
|
+
};
|
|
23106
23213
|
|
|
23107
23214
|
class SessionWatcher {
|
|
23108
23215
|
constructor() {
|
|
@@ -23186,99 +23293,6 @@ const onOnline = (callback) => {
|
|
|
23186
23293
|
return () => console.error('Unsupported environment');
|
|
23187
23294
|
};
|
|
23188
23295
|
|
|
23189
|
-
/**
|
|
23190
|
-
* ```js
|
|
23191
|
-
* import { isInTombstone } from '@amityco/ts-sdk-react-native'
|
|
23192
|
-
* const user = isInTombstone(["message", "messageId"])
|
|
23193
|
-
* ```
|
|
23194
|
-
*
|
|
23195
|
-
* Checks if the {@link Amity.TombstoneCacheOptions} exists
|
|
23196
|
-
* in cache and it's not expired means it's in tombstone
|
|
23197
|
-
* and we throw an Error
|
|
23198
|
-
*
|
|
23199
|
-
* @param model the model to check
|
|
23200
|
-
* @param modelId the object id to check
|
|
23201
|
-
* @returns the matching cache entry, or undefined.
|
|
23202
|
-
*
|
|
23203
|
-
* @category Cache API
|
|
23204
|
-
*/
|
|
23205
|
-
const isInTombstone = (model, modelId) => {
|
|
23206
|
-
const { log, cache } = getActiveClient();
|
|
23207
|
-
const key = [model, CACHE_KEY_TOMBSTONE, modelId];
|
|
23208
|
-
if (!cache)
|
|
23209
|
-
return;
|
|
23210
|
-
log('cache/api/isInTombstone', key);
|
|
23211
|
-
const isInTombstone = pullFromCache(key);
|
|
23212
|
-
const { lifeSpan } = queryOptions('cache_then_server', CACHE_LIFESPAN_TOMBSTONE);
|
|
23213
|
-
if (isInTombstone && isFresh(isInTombstone.data, lifeSpan)) {
|
|
23214
|
-
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
23215
|
-
}
|
|
23216
|
-
};
|
|
23217
|
-
|
|
23218
|
-
/**
|
|
23219
|
-
* ```js
|
|
23220
|
-
* import { getSubChannel } from '@amityco/ts-sdk-react-native'
|
|
23221
|
-
* const subChannel = await getSubChannel('foobar')
|
|
23222
|
-
* ```
|
|
23223
|
-
*
|
|
23224
|
-
* Fetches a {@link Amity.SubChannel} object
|
|
23225
|
-
*
|
|
23226
|
-
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
23227
|
-
* @returns the associated {@link Amity.SubChannel} object
|
|
23228
|
-
*
|
|
23229
|
-
* @category Channel API
|
|
23230
|
-
* @async
|
|
23231
|
-
*/
|
|
23232
|
-
const getSubChannel$1 = async (subChannelId) => {
|
|
23233
|
-
const client = getActiveClient();
|
|
23234
|
-
client.log('channel/getSubChannel', subChannelId);
|
|
23235
|
-
isInTombstone('subChannel', subChannelId);
|
|
23236
|
-
try {
|
|
23237
|
-
const response = await client.http.get(`/api/v5/message-feeds/${encodeURIComponent(subChannelId)}`);
|
|
23238
|
-
const data = await prepareSubChannelPayload(response.data);
|
|
23239
|
-
const cachedAt = client.cache && Date.now();
|
|
23240
|
-
if (client.cache)
|
|
23241
|
-
ingestInCache(data, { cachedAt });
|
|
23242
|
-
fireEvent('local.message-feed.fetched', data);
|
|
23243
|
-
return {
|
|
23244
|
-
data: data.messageFeeds[0],
|
|
23245
|
-
cachedAt,
|
|
23246
|
-
};
|
|
23247
|
-
}
|
|
23248
|
-
catch (error) {
|
|
23249
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23250
|
-
pushToTombstone('subChannel', subChannelId);
|
|
23251
|
-
}
|
|
23252
|
-
throw error;
|
|
23253
|
-
}
|
|
23254
|
-
};
|
|
23255
|
-
/**
|
|
23256
|
-
* ```js
|
|
23257
|
-
* import { getSubChannel } from '@amityco/ts-sdk-react-native'
|
|
23258
|
-
* const subChannel = getSubChannel.locally('foobar')
|
|
23259
|
-
* ```
|
|
23260
|
-
*
|
|
23261
|
-
* Fetches a {@link Amity.SubChannel} object from cache
|
|
23262
|
-
*
|
|
23263
|
-
* @param subChannelId the ID of the {@link Amity.SubChannel} to fetch
|
|
23264
|
-
* @returns the associated {@link Amity.SubChannel} object
|
|
23265
|
-
*
|
|
23266
|
-
* @category Channel API
|
|
23267
|
-
*/
|
|
23268
|
-
getSubChannel$1.locally = (subChannelId) => {
|
|
23269
|
-
const client = getActiveClient();
|
|
23270
|
-
client.log('channel/getSubChannel.locally', subChannelId);
|
|
23271
|
-
if (!client.cache)
|
|
23272
|
-
return;
|
|
23273
|
-
const cached = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
23274
|
-
if (!cached)
|
|
23275
|
-
return;
|
|
23276
|
-
return {
|
|
23277
|
-
data: cached.data,
|
|
23278
|
-
cachedAt: cached.cachedAt,
|
|
23279
|
-
};
|
|
23280
|
-
};
|
|
23281
|
-
|
|
23282
23296
|
/**
|
|
23283
23297
|
* ```js
|
|
23284
23298
|
* import { SubChannel } from '@amityco/ts-sdk-react-native'
|
|
@@ -25160,7 +25174,7 @@ const registerEventListeners = () => {
|
|
|
25160
25174
|
}), onMessageCreatedMqtt(message => {
|
|
25161
25175
|
// only conversation, community and broadcast types can sync
|
|
25162
25176
|
const client = getActiveClient();
|
|
25163
|
-
if (isUnreadCountSupport(message) && message.creatorId !== client.userId)
|
|
25177
|
+
if (isUnreadCountSupport$1(message) && message.creatorId !== client.userId)
|
|
25164
25178
|
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
25165
25179
|
}), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
25166
25180
|
/*
|
|
@@ -33103,7 +33117,7 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
33103
33117
|
getMessages: getMessages,
|
|
33104
33118
|
observeMessage: observeMessage,
|
|
33105
33119
|
observeMessages: observeMessages,
|
|
33106
|
-
convertFromRaw: convertFromRaw,
|
|
33120
|
+
convertFromRaw: convertFromRaw$1,
|
|
33107
33121
|
prepareMessagePayload: prepareMessagePayload,
|
|
33108
33122
|
convertParams: convertParams,
|
|
33109
33123
|
convertQueryParams: convertQueryParams$1,
|
|
@@ -33201,52 +33215,18 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
33201
33215
|
});
|
|
33202
33216
|
},
|
|
33203
33217
|
convertEventPayload((callback) => {
|
|
33204
|
-
|
|
33205
|
-
var _a;
|
|
33206
|
-
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33207
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
33208
|
-
return;
|
|
33209
|
-
await handleMessageCreated(message);
|
|
33218
|
+
return onMessageCreatedMqtt(async (message) => {
|
|
33210
33219
|
if (message.subChannelId !== subChannelId)
|
|
33211
33220
|
return;
|
|
33212
|
-
|
|
33213
|
-
'subChannel',
|
|
33214
|
-
'get',
|
|
33215
|
-
subChannelId,
|
|
33216
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33217
|
-
if (!subChannel)
|
|
33218
|
-
return;
|
|
33219
|
-
updateSubChannelCache(message.subChannelId, subChannel, {
|
|
33220
|
-
messagePreviewId: message.messageId,
|
|
33221
|
-
});
|
|
33222
|
-
};
|
|
33223
|
-
return onMessageCreatedMqtt(async (message) => {
|
|
33224
|
-
await updateMessagePreview(message);
|
|
33221
|
+
await handleMessageCreatedOnSubChannel(message);
|
|
33225
33222
|
callback(message);
|
|
33226
33223
|
});
|
|
33227
33224
|
}, 'subChannelId', 'subChannel'),
|
|
33228
33225
|
convertEventPayload((callback) => {
|
|
33229
|
-
|
|
33230
|
-
var _a;
|
|
33231
|
-
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33232
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
33233
|
-
return;
|
|
33234
|
-
await handleMessageCreated(message);
|
|
33226
|
+
return onMessageCreatedLocal(async (message) => {
|
|
33235
33227
|
if (message.subChannelId !== subChannelId)
|
|
33236
33228
|
return;
|
|
33237
|
-
|
|
33238
|
-
'subChannel',
|
|
33239
|
-
'get',
|
|
33240
|
-
subChannelId,
|
|
33241
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33242
|
-
if (!subChannel)
|
|
33243
|
-
return;
|
|
33244
|
-
updateSubChannelCache(message.subChannelId, subChannel, {
|
|
33245
|
-
messagePreviewId: message.messageId,
|
|
33246
|
-
});
|
|
33247
|
-
};
|
|
33248
|
-
return onMessageCreatedLocal(async (message) => {
|
|
33249
|
-
await updateMessagePreview(message);
|
|
33229
|
+
await handleMessageCreatedOnSubChannel(message);
|
|
33250
33230
|
callback(message);
|
|
33251
33231
|
});
|
|
33252
33232
|
}, 'subChannelId', 'subChannel'),
|
|
@@ -33257,7 +33237,7 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
33257
33237
|
return;
|
|
33258
33238
|
if (message.subChannelId !== subChannelId)
|
|
33259
33239
|
return;
|
|
33260
|
-
|
|
33240
|
+
handleMessageUpdatedOnSubChannel(message);
|
|
33261
33241
|
callback(message);
|
|
33262
33242
|
// TODO: messageFeeds on onMessageUpdated event does not have messagePreviewId and it will save before that cause messagePreview
|
|
33263
33243
|
};
|
|
@@ -33271,7 +33251,7 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
33271
33251
|
if (message.subChannelId !== subChannelId)
|
|
33272
33252
|
return;
|
|
33273
33253
|
if (messagePreviewSetting === "message-preview-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_INCLUDE_DELETED */)
|
|
33274
|
-
await
|
|
33254
|
+
await handleMessageUpdatedOnSubChannel(message);
|
|
33275
33255
|
if (messagePreviewSetting ===
|
|
33276
33256
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
33277
33257
|
await getSubChannel$1(message.subChannelId);
|
|
@@ -33395,15 +33375,15 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33395
33375
|
{
|
|
33396
33376
|
fn: callback => {
|
|
33397
33377
|
return onSubChannelUpdated(async (subChannel) => {
|
|
33398
|
-
|
|
33399
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33400
|
-
if (!collection || !collection.data.includes(subChannel.subChannelId))
|
|
33378
|
+
if (!this.isRelatedCollection(subChannel.subChannelId))
|
|
33401
33379
|
return;
|
|
33402
33380
|
const client = getActiveClient();
|
|
33403
33381
|
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33404
33382
|
if (messagePreviewSetting !== "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */) {
|
|
33405
33383
|
const messagePreview = getSubChannelMessagePreview(subChannel.subChannelId);
|
|
33406
|
-
if ((messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.subChannelId) === subChannel.subChannelId
|
|
33384
|
+
if ((messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.subChannelId) === subChannel.subChannelId &&
|
|
33385
|
+
convertDateStringToTimestamp(subChannel.updatedAt) >
|
|
33386
|
+
convertDateStringToTimestamp(messagePreview.subChannelUpdatedAt)) {
|
|
33407
33387
|
pushToCache(['messagePreviewSubChannel', 'get', subChannel.subChannelId], Object.assign(Object.assign({}, messagePreview), { subChannelName: subChannel.displayName, subChannelUpdatedAt: subChannel.updatedAt }));
|
|
33408
33388
|
}
|
|
33409
33389
|
}
|
|
@@ -33413,76 +33393,27 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33413
33393
|
action: 'onUpdate',
|
|
33414
33394
|
},
|
|
33415
33395
|
{
|
|
33416
|
-
fn: callback => {
|
|
33417
|
-
const updateMessagePreview = async (message) => {
|
|
33418
|
-
const client = getActiveClient();
|
|
33419
|
-
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33420
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
33421
|
-
return;
|
|
33422
|
-
handleMessageCreated(message);
|
|
33423
|
-
};
|
|
33396
|
+
fn: convertEventPayload((callback) => {
|
|
33424
33397
|
return onMessageCreatedMqtt(async (message) => {
|
|
33425
|
-
|
|
33426
|
-
const cacheData = pullFromCache([
|
|
33427
|
-
'subChannel',
|
|
33428
|
-
'get',
|
|
33429
|
-
message.subChannelId,
|
|
33430
|
-
]);
|
|
33431
|
-
if (!cacheData)
|
|
33432
|
-
return;
|
|
33433
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33434
|
-
if (!collection || !collection.data.includes(message.subChannelId))
|
|
33435
|
-
return;
|
|
33436
|
-
await updateMessagePreview(message);
|
|
33437
|
-
const subChannelCache = (_b = pullFromCache([
|
|
33438
|
-
'subChannel',
|
|
33439
|
-
'get',
|
|
33440
|
-
message.subChannelId,
|
|
33441
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
33442
|
-
if (!subChannelCache)
|
|
33398
|
+
if (!this.isRelatedCollection(message.subChannelId))
|
|
33443
33399
|
return;
|
|
33444
|
-
|
|
33445
|
-
|
|
33446
|
-
|
|
33447
|
-
});
|
|
33448
|
-
callback(Object.assign(Object.assign({}, cacheData.data), { messagePreviewId: message.messageId, subChannelId: message.subChannelId, lastActivity: message.createdAt }));
|
|
33400
|
+
// Update related cache including message preview and subChannel cache (lastActivity, messagePreviewId)
|
|
33401
|
+
await handleMessageCreatedOnSubChannel(message);
|
|
33402
|
+
callback(message);
|
|
33449
33403
|
});
|
|
33450
|
-
},
|
|
33404
|
+
}, 'subChannelId', 'subChannel'),
|
|
33451
33405
|
action: 'onUpdate',
|
|
33452
33406
|
},
|
|
33453
33407
|
{
|
|
33454
|
-
fn: callback => {
|
|
33408
|
+
fn: convertEventPayload((callback) => {
|
|
33455
33409
|
return onMessageCreatedLocal(async (message) => {
|
|
33456
|
-
|
|
33457
|
-
const cacheData = pullFromCache([
|
|
33458
|
-
'subChannel',
|
|
33459
|
-
'get',
|
|
33460
|
-
message.subChannelId,
|
|
33461
|
-
]);
|
|
33462
|
-
if (!cacheData)
|
|
33463
|
-
return;
|
|
33464
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33465
|
-
if (!collection || !collection.data.includes(message.subChannelId))
|
|
33466
|
-
return;
|
|
33467
|
-
const client = getActiveClient();
|
|
33468
|
-
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33469
|
-
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
33470
|
-
return;
|
|
33471
|
-
handleMessageCreated(message);
|
|
33472
|
-
const subChannelCache = (_b = pullFromCache([
|
|
33473
|
-
'subChannel',
|
|
33474
|
-
'get',
|
|
33475
|
-
message.subChannelId,
|
|
33476
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
33477
|
-
if (!subChannelCache)
|
|
33410
|
+
if (!this.isRelatedCollection(message.subChannelId))
|
|
33478
33411
|
return;
|
|
33479
|
-
|
|
33480
|
-
|
|
33481
|
-
|
|
33482
|
-
});
|
|
33483
|
-
callback(Object.assign(Object.assign({}, cacheData.data), { messagePreviewId: message.messageId, subChannelId: message.subChannelId, lastActivity: message.createdAt }));
|
|
33412
|
+
// Update related cache including message preview and subChannel cache (lastActivity, messagePreviewId)
|
|
33413
|
+
await handleMessageCreatedOnSubChannel(message);
|
|
33414
|
+
callback(message);
|
|
33484
33415
|
});
|
|
33485
|
-
},
|
|
33416
|
+
}, 'subChannelId', 'subChannel'),
|
|
33486
33417
|
action: 'onUpdate',
|
|
33487
33418
|
},
|
|
33488
33419
|
{
|
|
@@ -33515,7 +33446,7 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33515
33446
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33516
33447
|
if (!collection || !collection.data.includes(message.subChannelId))
|
|
33517
33448
|
return;
|
|
33518
|
-
|
|
33449
|
+
handleMessageUpdatedOnSubChannel(message);
|
|
33519
33450
|
callback(message);
|
|
33520
33451
|
};
|
|
33521
33452
|
return onMessageUpdated(updateMessagePreview);
|
|
@@ -33525,20 +33456,18 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33525
33456
|
{
|
|
33526
33457
|
fn: convertEventPayload((callback) => {
|
|
33527
33458
|
const updateMessagePreview = async (message) => {
|
|
33528
|
-
var _a;
|
|
33529
33459
|
const client = getActiveClient();
|
|
33530
33460
|
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
33531
33461
|
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
33532
33462
|
return;
|
|
33533
|
-
|
|
33534
|
-
if (!collection || !collection.data.includes(message.subChannelId))
|
|
33463
|
+
if (!this.isRelatedCollection(message.subChannelId))
|
|
33535
33464
|
return;
|
|
33536
33465
|
if (messagePreviewSetting ===
|
|
33537
33466
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
33538
33467
|
await getSubChannel$1(message.subChannelId);
|
|
33539
33468
|
}
|
|
33540
33469
|
else {
|
|
33541
|
-
await
|
|
33470
|
+
await handleMessageUpdatedOnSubChannel(message);
|
|
33542
33471
|
}
|
|
33543
33472
|
callback(message);
|
|
33544
33473
|
};
|
|
@@ -33580,6 +33509,11 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33580
33509
|
subChannels.sort(sortByLastActivity);
|
|
33581
33510
|
return subChannels;
|
|
33582
33511
|
}
|
|
33512
|
+
isRelatedCollection(subChannelId) {
|
|
33513
|
+
var _a;
|
|
33514
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33515
|
+
return collection && collection.data.includes(subChannelId);
|
|
33516
|
+
}
|
|
33583
33517
|
}
|
|
33584
33518
|
|
|
33585
33519
|
/* eslint-disable no-use-before-define */
|
|
@@ -35095,8 +35029,8 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
35095
35029
|
getChannel: getChannel,
|
|
35096
35030
|
getChannels: getChannels,
|
|
35097
35031
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
35098
|
-
isUnreadCountSupport: isUnreadCountSupport
|
|
35099
|
-
convertFromRaw: convertFromRaw
|
|
35032
|
+
isUnreadCountSupport: isUnreadCountSupport,
|
|
35033
|
+
convertFromRaw: convertFromRaw,
|
|
35100
35034
|
preUpdateChannelCache: preUpdateChannelCache,
|
|
35101
35035
|
prepareChannelPayload: prepareChannelPayload
|
|
35102
35036
|
});
|
|
@@ -41519,7 +41453,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
41519
41453
|
getPoll: getPoll
|
|
41520
41454
|
});
|
|
41521
41455
|
|
|
41522
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
41456
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
41523
41457
|
/*
|
|
41524
41458
|
* The crypto algorithm used for importing key and signing string
|
|
41525
41459
|
*/
|