@amityco/ts-sdk 7.27.1 → 7.27.2-1232423.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +5 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +26 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +10 -4
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +3 -1
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +18 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +27 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/curatedContent.d.ts +25 -0
- package/dist/@types/domains/curatedContent.d.ts.map +1 -0
- package/dist/@types/domains/pinnedMessage.d.ts +43 -0
- package/dist/@types/domains/pinnedMessage.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +11 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +3 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +3 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +3 -0
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +2 -0
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts +22 -0
- package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts +22 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMessagePinned.d.ts +24 -0
- package/dist/channelRepository/events/onChannelMessagePinned.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts +21 -0
- package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts +12 -0
- package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleAdded.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleAdded.test.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleRemoved.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleRemoved.test.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getMyMembership.d.ts.map +1 -1
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/utils/applyChannelRolePayload.d.ts +21 -0
- package/dist/channelRepository/utils/applyChannelRolePayload.d.ts.map +1 -0
- package/dist/channelRepository/utils/index.d.ts +2 -0
- package/dist/channelRepository/utils/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts +24 -0
- package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts.map +1 -0
- package/dist/client/api/createClient.d.ts +5 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getSocialSettings.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/client/api/tests/getSocialSettings.test.d.ts +2 -0
- package/dist/client/api/tests/getSocialSettings.test.d.ts.map +1 -0
- package/dist/commentRepository/api/approveComment.d.ts +17 -0
- package/dist/commentRepository/api/approveComment.d.ts.map +1 -0
- package/dist/commentRepository/api/createComment.d.ts +12 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/declineComment.d.ts +18 -0
- package/dist/commentRepository/api/declineComment.d.ts.map +1 -0
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/api/index.d.ts +2 -0
- package/dist/commentRepository/api/index.d.ts.map +1 -1
- package/dist/commentRepository/api/tests/approveComment.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/approveComment.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/createComment.optimistic.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/createComment.optimistic.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/declineComment.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/declineComment.test.d.ts.map +1 -0
- package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
- package/dist/commentRepository/events/index.d.ts +1 -0
- package/dist/commentRepository/events/index.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentApproved.d.ts +17 -0
- package/dist/commentRepository/events/onCommentApproved.d.ts.map +1 -0
- package/dist/commentRepository/events/tests/onCommentApproved.test.d.ts +2 -0
- package/dist/commentRepository/events/tests/onCommentApproved.test.d.ts.map +1 -0
- package/dist/commentRepository/events/tests/onCommentCreated.count.test.d.ts +2 -0
- package/dist/commentRepository/events/tests/onCommentCreated.count.test.d.ts.map +1 -0
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getCommentReviewQueue/LiveCollectionController.d.ts +13 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/LiveCollectionController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/PaginationController.d.ts +5 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/PaginationController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/QueryStreamController.d.ts +15 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/QueryStreamController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue.d.ts +22 -0
- package/dist/commentRepository/observers/getCommentReviewQueue.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts +1 -1
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/CommentQueryStreamController.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/enums.d.ts +1 -0
- package/dist/commentRepository/observers/getComments/enums.d.ts.map +1 -1
- package/dist/commentRepository/observers/index.d.ts +1 -0
- package/dist/commentRepository/observers/index.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/integrations/getCommentReviewQueue.integration.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/integrations/getCommentReviewQueue.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/utils/approval.d.ts +49 -0
- package/dist/commentRepository/utils/approval.d.ts.map +1 -0
- package/dist/commentRepository/utils/payload.d.ts +6 -0
- package/dist/commentRepository/utils/payload.d.ts.map +1 -1
- package/dist/commentRepository/utils/tests/approval.test.d.ts +2 -0
- package/dist/commentRepository/utils/tests/approval.test.d.ts.map +1 -0
- package/dist/commentRepository/utils/tests/payload.test.d.ts +2 -0
- package/dist/commentRepository/utils/tests/payload.test.d.ts.map +1 -0
- package/dist/communityRepository/api/createCommunity.d.ts +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/core/device.d.ts +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/tests/device.test.d.ts +2 -0
- package/dist/core/tests/device.test.d.ts.map +1 -0
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/core/transports/utils.d.ts +8 -0
- package/dist/core/transports/utils.d.ts.map +1 -1
- package/dist/curatedContentRepository/api/getPool.d.ts +2 -0
- package/dist/curatedContentRepository/api/getPool.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/index.d.ts +2 -0
- package/dist/curatedContentRepository/api/index.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/tests/getPool.test.d.ts +2 -0
- package/dist/curatedContentRepository/api/tests/getPool.test.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/tests/integration/getPool.integration.test.d.ts +2 -0
- package/dist/curatedContentRepository/api/tests/integration/getPool.integration.test.d.ts.map +1 -0
- package/dist/curatedContentRepository/index.d.ts +2 -0
- package/dist/curatedContentRepository/index.d.ts.map +1 -0
- package/dist/index.cjs.js +1742 -477
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1717 -453
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/index.d.ts +2 -0
- package/dist/messageRepository/api/index.d.ts.map +1 -1
- package/dist/messageRepository/api/pinMessage.d.ts +29 -0
- package/dist/messageRepository/api/pinMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/pinMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/pinMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/unpinMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/unpinMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/unpinMessage.d.ts +28 -0
- package/dist/messageRepository/api/unpinMessage.d.ts.map +1 -0
- package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts +13 -0
- package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ApproveTask.d.ts +16 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ApproveTask.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts +25 -1
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts.map +1 -1
- package/dist/postRepository/utils/PostCommentCountEngine/postCommentCountEngineOnLoginHandler.d.ts +9 -0
- package/dist/postRepository/utils/PostCommentCountEngine/postCommentCountEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/getLocalCommentCount.test.d.ts +2 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/getLocalCommentCount.test.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/pendingAuthoredComments.test.d.ts +2 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/pendingAuthoredComments.test.d.ts.map +1 -0
- package/dist/postRepository/utils/latestComments.d.ts +10 -0
- package/dist/postRepository/utils/latestComments.d.ts.map +1 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/postRepository/utils/tests/latestComments.test.d.ts +2 -0
- package/dist/postRepository/utils/tests/latestComments.test.d.ts.map +1 -0
- package/dist/postRepository/utils/tests/payload.test.d.ts +2 -0
- package/dist/postRepository/utils/tests/payload.test.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/curatedContentTopicLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/curatedContentTopicLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/messageLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/tests/postLinkedObject.test.d.ts +2 -0
- package/dist/utils/linkedObject/tests/postLinkedObject.test.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts +1 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/pinnedMessage.d.ts +2 -0
- package/dist/utils/tests/dummy/pinnedMessage.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs.js
CHANGED
|
@@ -7,8 +7,9 @@ var mitt = require('mitt');
|
|
|
7
7
|
var debug = require('debug');
|
|
8
8
|
var axios = require('axios');
|
|
9
9
|
var HttpAgent = require('agentkeepalive');
|
|
10
|
-
var mqtt = require('mqtt');
|
|
11
10
|
var uuid$1 = require('react-native-uuid');
|
|
11
|
+
var mqtt = require('mqtt');
|
|
12
|
+
var uaParserJs = require('ua-parser-js');
|
|
12
13
|
var jwtDecode = require('jwt-decode');
|
|
13
14
|
var hash = require('object-hash');
|
|
14
15
|
var Hls = require('hls.js');
|
|
@@ -19,8 +20,8 @@ var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
|
19
20
|
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
|
|
20
21
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
21
22
|
var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
|
|
22
|
-
var mqtt__default = /*#__PURE__*/_interopDefaultLegacy(mqtt);
|
|
23
23
|
var uuid__default = /*#__PURE__*/_interopDefaultLegacy(uuid$1);
|
|
24
|
+
var mqtt__default = /*#__PURE__*/_interopDefaultLegacy(mqtt);
|
|
24
25
|
var jwtDecode__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecode);
|
|
25
26
|
var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
|
|
26
27
|
var Hls__default = /*#__PURE__*/_interopDefaultLegacy(Hls);
|
|
@@ -341,6 +342,7 @@ function getVersion() {
|
|
|
341
342
|
const VERSION = getVersion();
|
|
342
343
|
|
|
343
344
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
345
|
+
const LATEST_COMMENTS_LIMIT = 5;
|
|
344
346
|
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
345
347
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
346
348
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
@@ -356,7 +358,11 @@ const YEAR = 365 * DAY;
|
|
|
356
358
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
357
359
|
const API_ENDPOINTS = {
|
|
358
360
|
forYouFeed: '/api/v1/feeds/for-you',
|
|
361
|
+
commentReviewQueue: (communityId) => `/api/v3/communities/${encodeURIComponent(communityId)}/comments/review-queue`,
|
|
359
362
|
};
|
|
363
|
+
// The review-queue route defaults to 10, not the SDK-wide page size, and caps at 100
|
|
364
|
+
const COMMENT_REVIEW_QUEUE_DEFAULT_PAGINATION_SIZE = 10;
|
|
365
|
+
const COMMENT_REVIEW_QUEUE_MAX_PAGINATION_SIZE = 100;
|
|
360
366
|
|
|
361
367
|
// cache constants
|
|
362
368
|
const CACHE_KEY_GET = 'get';
|
|
@@ -1953,6 +1959,8 @@ function computeUrl(type, region) {
|
|
|
1953
1959
|
return URLS[type].replace('{region}', region);
|
|
1954
1960
|
}
|
|
1955
1961
|
|
|
1962
|
+
const uuid = () => uuid__default["default"].v4().toString();
|
|
1963
|
+
|
|
1956
1964
|
/**
|
|
1957
1965
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
1958
1966
|
*
|
|
@@ -1977,6 +1985,24 @@ const unwrapPayload = (response) => {
|
|
|
1977
1985
|
// unjust, but helps force uncast "T | undefined" to allow deconstruction without warnings
|
|
1978
1986
|
return undefined;
|
|
1979
1987
|
};
|
|
1988
|
+
/**
|
|
1989
|
+
* Builds a hex string of `bytes` length from the SDK's uuid helper (a v4 UUID is
|
|
1990
|
+
* 16 bytes / 32 hex chars once hyphens are removed) — avoids a new crypto dependency.
|
|
1991
|
+
*/
|
|
1992
|
+
const randomHex = (bytes) => {
|
|
1993
|
+
let hex = '';
|
|
1994
|
+
while (hex.length < bytes * 2)
|
|
1995
|
+
hex += uuid().replace(/-/g, '');
|
|
1996
|
+
return hex.slice(0, bytes * 2);
|
|
1997
|
+
};
|
|
1998
|
+
/**
|
|
1999
|
+
* W3C Trace Context `traceparent`: `version-<16-byte trace-id>-<8-byte span-id>-<flags>`.
|
|
2000
|
+
* The SDK is the trace originator, so it mints a fresh trace + span id per request; flags `01` = sampled.
|
|
2001
|
+
*
|
|
2002
|
+
* @category Transport
|
|
2003
|
+
* @hidden
|
|
2004
|
+
*/
|
|
2005
|
+
const generateTraceparent = () => `00-${randomHex(16)}-${randomHex(8)}-01`;
|
|
1980
2006
|
|
|
1981
2007
|
class NetworkActivitiesWatcher {
|
|
1982
2008
|
constructor() {
|
|
@@ -2101,6 +2127,10 @@ const createHttpTransport = (endpoint) => {
|
|
|
2101
2127
|
});
|
|
2102
2128
|
instance.defaults.withCredentials = false;
|
|
2103
2129
|
instance.interceptors.request.use(config => {
|
|
2130
|
+
// Request tracing — set on every outbound request (login included), never persisted.
|
|
2131
|
+
// Must run before the session-url early-return below so /api/v5/sessions carries them too.
|
|
2132
|
+
config.headers.set('x-request-id', uuid());
|
|
2133
|
+
config.headers.set('traceparent', generateTraceparent());
|
|
2104
2134
|
// do not check expiration for token creation url
|
|
2105
2135
|
if (config.url === '/api/v5/sessions') {
|
|
2106
2136
|
return config;
|
|
@@ -2144,20 +2174,28 @@ const createHttpTransport = (endpoint) => {
|
|
|
2144
2174
|
});
|
|
2145
2175
|
return response;
|
|
2146
2176
|
}, error => {
|
|
2147
|
-
var _a, _b, _c;
|
|
2177
|
+
var _a, _b, _c, _d;
|
|
2148
2178
|
const { response } = error;
|
|
2149
2179
|
// handle unauthorized request
|
|
2150
2180
|
if ((response === null || response === void 0 ? void 0 : response.data.code) === 400100 /* Amity.ServerError.UNAUTHORIZED */) {
|
|
2151
2181
|
fireEvent('tokenTerminated', "terminated" /* Amity.SessionStates.TERMINATED */);
|
|
2152
2182
|
}
|
|
2183
|
+
// handle globally banned user. The realtime `user.didGlobalBan` event can be missed
|
|
2184
|
+
// (e.g. MQTT dropped before delivery), so mirror the 400100 handling above and fire
|
|
2185
|
+
// the same virtual event the login subscriptions already listen to. That terminates
|
|
2186
|
+
// the session with `TokenTerminationReason.GLOBAL_BAN` and notifies `onClientBanned`
|
|
2187
|
+
// consumers, instead of leaving the session `established` with a revoked token.
|
|
2188
|
+
if (((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.code) === 400312 /* Amity.ServerError.GLOBAL_BAN */) {
|
|
2189
|
+
fireEvent('user.didGlobalBan', { users: [], files: [] });
|
|
2190
|
+
}
|
|
2153
2191
|
// handle visitor daily usage limit exceeded
|
|
2154
|
-
if (((
|
|
2192
|
+
if (((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.code) === 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */) {
|
|
2155
2193
|
throttledFireVisitorUsageLimit();
|
|
2156
2194
|
throw new ASCError('Visitor usage limit exceeded', 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
2157
2195
|
}
|
|
2158
2196
|
// if it's an error with status in the response payload,
|
|
2159
2197
|
// then it's an expected error.
|
|
2160
|
-
if ((
|
|
2198
|
+
if ((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.status) {
|
|
2161
2199
|
unwrapPayload(response === null || response === void 0 ? void 0 : response.data);
|
|
2162
2200
|
}
|
|
2163
2201
|
// as on request cancellation error is returned
|
|
@@ -2165,7 +2203,7 @@ const createHttpTransport = (endpoint) => {
|
|
|
2165
2203
|
throw error;
|
|
2166
2204
|
}
|
|
2167
2205
|
// unexpected error.
|
|
2168
|
-
throw new Error((
|
|
2206
|
+
throw new Error((_d = response === null || response === void 0 ? void 0 : response.data) !== null && _d !== void 0 ? _d : error);
|
|
2169
2207
|
});
|
|
2170
2208
|
instance.defaults.paramsSerializer = {
|
|
2171
2209
|
encode: params => encodeURIComponent(params),
|
|
@@ -2363,8 +2401,6 @@ const getItem = async (key) => {
|
|
|
2363
2401
|
});
|
|
2364
2402
|
};
|
|
2365
2403
|
|
|
2366
|
-
const uuid = () => uuid__default["default"].v4().toString();
|
|
2367
|
-
|
|
2368
2404
|
// TODO: find a way to uniquely identify the device
|
|
2369
2405
|
let tabIndex = 0;
|
|
2370
2406
|
// This logic is running on browser only
|
|
@@ -2424,22 +2460,60 @@ const getMQTTClientId = async (userId) => {
|
|
|
2424
2460
|
};
|
|
2425
2461
|
/** @hidden */
|
|
2426
2462
|
const getDeviceModel = () => {
|
|
2427
|
-
var _a
|
|
2463
|
+
var _a;
|
|
2428
2464
|
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
2429
2465
|
return safeProcess.versions.node;
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2466
|
+
return undefined;
|
|
2467
|
+
};
|
|
2468
|
+
const hasNavigator = () => typeof navigator !== 'undefined' && !!navigator;
|
|
2469
|
+
const getLocale = () => (hasNavigator() ? navigator.language : undefined);
|
|
2470
|
+
const getTimezone = () => {
|
|
2471
|
+
try {
|
|
2472
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2473
|
+
}
|
|
2474
|
+
catch (_a) {
|
|
2475
|
+
return undefined;
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
const getNetworkType = () => {
|
|
2479
|
+
var _a;
|
|
2480
|
+
if (!hasNavigator())
|
|
2481
|
+
return undefined;
|
|
2482
|
+
return (_a = navigator.connection) === null || _a === void 0 ? void 0 : _a.effectiveType;
|
|
2483
|
+
};
|
|
2484
|
+
const isNode = () => { var _a; return !!((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node); };
|
|
2485
|
+
const parseUserAgent = () => {
|
|
2486
|
+
if (!hasNavigator() || !navigator.userAgent)
|
|
2487
|
+
return {};
|
|
2488
|
+
const { os, browser, device } = new uaParserJs.UAParser(navigator.userAgent).getResult();
|
|
2489
|
+
const result = {};
|
|
2490
|
+
if (os.name)
|
|
2491
|
+
result.osName = os.name;
|
|
2492
|
+
if (os.version)
|
|
2493
|
+
result.osVersion = os.version;
|
|
2494
|
+
if (browser.name)
|
|
2495
|
+
result.browserName = browser.name;
|
|
2496
|
+
if (browser.version)
|
|
2497
|
+
result.browserVersion = browser.version;
|
|
2498
|
+
if (device.type === 'tablet')
|
|
2499
|
+
result.deviceType = 'tablet';
|
|
2500
|
+
else if (device.type === 'mobile')
|
|
2501
|
+
result.deviceType = 'mobile';
|
|
2502
|
+
else
|
|
2503
|
+
result.deviceType = 'desktop';
|
|
2504
|
+
return result;
|
|
2433
2505
|
};
|
|
2434
2506
|
/** @hidden */
|
|
2435
2507
|
const getDeviceInfo = () => {
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2508
|
+
var _a;
|
|
2509
|
+
let client;
|
|
2510
|
+
try {
|
|
2511
|
+
client = getActiveClient();
|
|
2512
|
+
}
|
|
2513
|
+
catch (_b) {
|
|
2514
|
+
client = undefined;
|
|
2515
|
+
}
|
|
2516
|
+
return Object.assign({ kind: isNode() ? 'node' : 'web', model: getDeviceModel(), sdkVersion: VERSION, product: (_a = client === null || client === void 0 ? void 0 : client.product) !== null && _a !== void 0 ? _a : 'sdk', uikitVersion: client === null || client === void 0 ? void 0 : client.uikitVersion, appId: client === null || client === void 0 ? void 0 : client.appId, appVersion: client === null || client === void 0 ? void 0 : client.appVersion, locale: getLocale(), timezone: getTimezone(), networkType: getNetworkType() }, parseUserAgent());
|
|
2443
2517
|
};
|
|
2444
2518
|
|
|
2445
2519
|
/* eslint-disable no-console */
|
|
@@ -3851,6 +3925,95 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
3851
3925
|
channelUsers });
|
|
3852
3926
|
};
|
|
3853
3927
|
|
|
3928
|
+
const channelCacheKey = (channel) => [
|
|
3929
|
+
'channel',
|
|
3930
|
+
'get',
|
|
3931
|
+
getResolver('channel')(channel),
|
|
3932
|
+
];
|
|
3933
|
+
/**
|
|
3934
|
+
* Find a cached channel by any of its ids (internal, public, or `channelId`).
|
|
3935
|
+
*
|
|
3936
|
+
* The channel cache is keyed by the channel internal id (see `idResolvers.channel`), but
|
|
3937
|
+
* realtime payloads reference channels by different ids: pin events carry the **public**
|
|
3938
|
+
* id, messages carry `channelId`. Try the cheap direct lookup first, then scan.
|
|
3939
|
+
*/
|
|
3940
|
+
const findCachedChannelByAnyId = (id) => {
|
|
3941
|
+
var _a, _b, _c;
|
|
3942
|
+
if (!id)
|
|
3943
|
+
return undefined;
|
|
3944
|
+
const direct = (_a = pullFromCache(['channel', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3945
|
+
if (direct)
|
|
3946
|
+
return direct;
|
|
3947
|
+
return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === id || data.channelPublicId === id || data.channelId === id)) === null || _c === void 0 ? void 0 : _c.data;
|
|
3948
|
+
};
|
|
3949
|
+
/**
|
|
3950
|
+
* Resolve the cached channel a `channel.messagePinned` / `channel.messageUnpinned` event
|
|
3951
|
+
* refers to. `data.channelId` is the channel public id; a pinned message body (present on
|
|
3952
|
+
* `messagePinned` only) also carries the internal id, which is the direct cache key.
|
|
3953
|
+
*/
|
|
3954
|
+
const findCachedChannelForPin = (payload) => {
|
|
3955
|
+
var _a, _b;
|
|
3956
|
+
return (_b = findCachedChannelByAnyId((_a = payload.pinnedMessage) === null || _a === void 0 ? void 0 : _a.channelId)) !== null && _b !== void 0 ? _b : findCachedChannelByAnyId(payload.channelId);
|
|
3957
|
+
};
|
|
3958
|
+
/**
|
|
3959
|
+
* Write a new pin snapshot (or `null` to clear) on a cached channel and ingest any
|
|
3960
|
+
* users delivered with it (the pin author and the message author), so the banner can
|
|
3961
|
+
* render a byline without a second fetch.
|
|
3962
|
+
*
|
|
3963
|
+
* Every `messagePinned` payload is a full snapshot — "this is the pin now" — so the last
|
|
3964
|
+
* one received always wins; there is no merging with the previous pin.
|
|
3965
|
+
*/
|
|
3966
|
+
const updatePinnedMessageCache = (channel, pinnedMessage, users) => {
|
|
3967
|
+
if (users && users.length > 0) {
|
|
3968
|
+
ingestInCache({ users: users.map(convertRawUserToInternalUser) });
|
|
3969
|
+
}
|
|
3970
|
+
const updated = Object.assign(Object.assign({}, channel), { pinnedMessage });
|
|
3971
|
+
pushToCache(channelCacheKey(channel), updated);
|
|
3972
|
+
return updated;
|
|
3973
|
+
};
|
|
3974
|
+
|
|
3975
|
+
/**
|
|
3976
|
+
* Applies a `channel.roleAdded` / `channel.roleRemoved` realtime payload to the cache.
|
|
3977
|
+
*
|
|
3978
|
+
* The event names every member the role request affected together with the
|
|
3979
|
+
* roles and channel-scoped permissions each of them is left holding. That is a
|
|
3980
|
+
* full state, not a delta, so it is written straight over the cached membership.
|
|
3981
|
+
*
|
|
3982
|
+
* Members the SDK has not fetched yet are skipped: the payload does not carry
|
|
3983
|
+
* enough to build a full {@link Amity.Membership} and the live collections only
|
|
3984
|
+
* emit rows that already exist in cache.
|
|
3985
|
+
*
|
|
3986
|
+
* @param payload the `data` of the realtime event
|
|
3987
|
+
* @returns the refreshed channel (when resolvable) and the updated cached memberships
|
|
3988
|
+
*
|
|
3989
|
+
* @hidden
|
|
3990
|
+
*/
|
|
3991
|
+
const applyChannelRolePayload = (payload) => {
|
|
3992
|
+
var _a, _b, _c;
|
|
3993
|
+
const { channelId, users = [], channels = [] } = payload;
|
|
3994
|
+
const rawChannel = (_a = channels.find(channel => channel.channelId === channelId)) !== null && _a !== void 0 ? _a : channels[0];
|
|
3995
|
+
let channel;
|
|
3996
|
+
if (rawChannel) {
|
|
3997
|
+
const channelKey = ['channel', 'get', getResolver('channel')(rawChannel)];
|
|
3998
|
+
// the role event does not touch message previews, keep whatever preview is cached
|
|
3999
|
+
const converted = convertFromRaw(rawChannel, { isMessagePreviewUpdated: false });
|
|
4000
|
+
upsertInCache(channelKey, converted);
|
|
4001
|
+
channel = (_c = (_b = pullFromCache(channelKey)) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : converted;
|
|
4002
|
+
}
|
|
4003
|
+
const members = [];
|
|
4004
|
+
users.forEach(({ userId, roles, permissions }) => {
|
|
4005
|
+
var _a, _b, _c;
|
|
4006
|
+
const memberKey = ['channelUsers', 'get', getResolver('channelUsers')({ channelId, userId })];
|
|
4007
|
+
const cached = (_a = pullFromCache(memberKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
4008
|
+
if (!cached)
|
|
4009
|
+
return;
|
|
4010
|
+
const updated = Object.assign(Object.assign({}, cached), { roles, permissions });
|
|
4011
|
+
pushToCache(memberKey, updated);
|
|
4012
|
+
members.push((_c = (_b = pullFromCache(memberKey)) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : updated);
|
|
4013
|
+
});
|
|
4014
|
+
return { channel, members };
|
|
4015
|
+
};
|
|
4016
|
+
|
|
3854
4017
|
/**
|
|
3855
4018
|
* ```js
|
|
3856
4019
|
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
@@ -4036,32 +4199,6 @@ const channelMemberLinkedObject = (channelMember) => {
|
|
|
4036
4199
|
} });
|
|
4037
4200
|
};
|
|
4038
4201
|
|
|
4039
|
-
/**
|
|
4040
|
-
*
|
|
4041
|
-
* get current user's membership data
|
|
4042
|
-
*
|
|
4043
|
-
* @returns the {@link Amity.Membership<'channel'>} objects
|
|
4044
|
-
*
|
|
4045
|
-
* @category Channel API
|
|
4046
|
-
* @async
|
|
4047
|
-
*/
|
|
4048
|
-
const getMyMembership$1 = (channelId) => {
|
|
4049
|
-
const client = getActiveClient();
|
|
4050
|
-
client.log('channel/getMyMembership.locally');
|
|
4051
|
-
const cacheChannelUser = pullFromCache([
|
|
4052
|
-
'channelUsers',
|
|
4053
|
-
'get',
|
|
4054
|
-
`${channelId}#${client.userId}`,
|
|
4055
|
-
]);
|
|
4056
|
-
if (!cacheChannelUser) {
|
|
4057
|
-
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
4058
|
-
}
|
|
4059
|
-
return {
|
|
4060
|
-
data: cacheChannelUser.data,
|
|
4061
|
-
cachedAt: cacheChannelUser.cachedAt,
|
|
4062
|
-
};
|
|
4063
|
-
};
|
|
4064
|
-
|
|
4065
4202
|
/**
|
|
4066
4203
|
* ```js
|
|
4067
4204
|
* import { isEqual } from '~/utils/isEqual'
|
|
@@ -4132,55 +4269,81 @@ function isEqual(x, y) {
|
|
|
4132
4269
|
}));
|
|
4133
4270
|
}
|
|
4134
4271
|
|
|
4135
|
-
|
|
4272
|
+
/**
|
|
4273
|
+
*
|
|
4274
|
+
* get current user's membership data
|
|
4275
|
+
*
|
|
4276
|
+
* @returns the {@link Amity.Membership<'channel'>} objects
|
|
4277
|
+
*
|
|
4278
|
+
* @category Channel API
|
|
4279
|
+
* @async
|
|
4280
|
+
*/
|
|
4281
|
+
const getMyMembership$1 = (channelId) => {
|
|
4282
|
+
const client = getActiveClient();
|
|
4283
|
+
client.log('channel/getMyMembership.locally');
|
|
4284
|
+
const cacheChannelUser = pullFromCache([
|
|
4285
|
+
'channelUsers',
|
|
4286
|
+
'get',
|
|
4287
|
+
`${channelId}#${client.userId}`,
|
|
4288
|
+
]);
|
|
4289
|
+
if (!cacheChannelUser) {
|
|
4290
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
4291
|
+
}
|
|
4292
|
+
return {
|
|
4293
|
+
data: cacheChannelUser.data,
|
|
4294
|
+
cachedAt: cacheChannelUser.cachedAt,
|
|
4295
|
+
};
|
|
4296
|
+
};
|
|
4297
|
+
|
|
4298
|
+
const callbacks$e = [];
|
|
4136
4299
|
let mainDisposer$b = null;
|
|
4137
|
-
const dispose$
|
|
4138
|
-
const index = callbacks$
|
|
4300
|
+
const dispose$e = (cb) => {
|
|
4301
|
+
const index = callbacks$e.indexOf(cb);
|
|
4139
4302
|
if (index > -1) {
|
|
4140
|
-
callbacks$
|
|
4303
|
+
callbacks$e.splice(index, 1);
|
|
4141
4304
|
}
|
|
4142
|
-
if (callbacks$
|
|
4305
|
+
if (callbacks$e.length === 0) {
|
|
4143
4306
|
mainDisposer$b === null || mainDisposer$b === void 0 ? void 0 : mainDisposer$b();
|
|
4144
4307
|
}
|
|
4145
4308
|
};
|
|
4146
4309
|
const onChannelCreated = (callback) => {
|
|
4147
|
-
if (callbacks$
|
|
4310
|
+
if (callbacks$e.length === 0) {
|
|
4148
4311
|
const client = getActiveClient();
|
|
4149
4312
|
const filter = async (payload) => {
|
|
4150
4313
|
const data = await prepareChannelPayload(payload);
|
|
4151
4314
|
ingestInCache(data);
|
|
4152
|
-
callbacks$
|
|
4315
|
+
callbacks$e.forEach(cb => cb(data.channels[0]));
|
|
4153
4316
|
};
|
|
4154
4317
|
mainDisposer$b = createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
4155
4318
|
}
|
|
4156
|
-
callbacks$
|
|
4157
|
-
return () => dispose$
|
|
4319
|
+
callbacks$e.push(callback);
|
|
4320
|
+
return () => dispose$e(callback);
|
|
4158
4321
|
};
|
|
4159
4322
|
|
|
4160
|
-
const callbacks$
|
|
4161
|
-
const mainDisposers = [];
|
|
4162
|
-
const dispose$
|
|
4163
|
-
const index = callbacks$
|
|
4323
|
+
const callbacks$d = [];
|
|
4324
|
+
const mainDisposers$2 = [];
|
|
4325
|
+
const dispose$d = (cb) => {
|
|
4326
|
+
const index = callbacks$d.indexOf(cb);
|
|
4164
4327
|
if (index > -1) {
|
|
4165
|
-
callbacks$
|
|
4328
|
+
callbacks$d.splice(index, 1);
|
|
4166
4329
|
}
|
|
4167
|
-
if (callbacks$
|
|
4168
|
-
mainDisposers.forEach(fn => fn());
|
|
4330
|
+
if (callbacks$d.length === 0) {
|
|
4331
|
+
mainDisposers$2.forEach(fn => fn());
|
|
4169
4332
|
}
|
|
4170
4333
|
};
|
|
4171
4334
|
const onChannelUpdated = (callback) => {
|
|
4172
4335
|
const client = getActiveClient();
|
|
4173
|
-
if (callbacks$
|
|
4336
|
+
if (callbacks$d.length === 0) {
|
|
4174
4337
|
const filter = async (payload) => {
|
|
4175
4338
|
const data = await prepareChannelPayload(payload);
|
|
4176
4339
|
ingestInCache(data);
|
|
4177
|
-
callbacks$
|
|
4340
|
+
callbacks$d.forEach(cb => cb(data.channels[0]));
|
|
4178
4341
|
};
|
|
4179
|
-
mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter));
|
|
4180
|
-
mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$
|
|
4342
|
+
mainDisposers$2.push(createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter));
|
|
4343
|
+
mainDisposers$2.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$d.forEach(cb => cb(payload.channels[0]))));
|
|
4181
4344
|
}
|
|
4182
|
-
callbacks$
|
|
4183
|
-
return () => dispose$
|
|
4345
|
+
callbacks$d.push(callback);
|
|
4346
|
+
return () => dispose$d(callback);
|
|
4184
4347
|
};
|
|
4185
4348
|
|
|
4186
4349
|
const addFlagIsDeletedSubChannelUnreadByChannelId = (channelId) => {
|
|
@@ -4203,19 +4366,19 @@ const deleteChannelUnreadByChannelId = (channelId) => {
|
|
|
4203
4366
|
}
|
|
4204
4367
|
};
|
|
4205
4368
|
|
|
4206
|
-
const callbacks$
|
|
4369
|
+
const callbacks$c = [];
|
|
4207
4370
|
let mainDisposer$a = null;
|
|
4208
|
-
const dispose$
|
|
4209
|
-
const index = callbacks$
|
|
4371
|
+
const dispose$c = (cb) => {
|
|
4372
|
+
const index = callbacks$c.indexOf(cb);
|
|
4210
4373
|
if (index > -1) {
|
|
4211
|
-
callbacks$
|
|
4374
|
+
callbacks$c.splice(index, 1);
|
|
4212
4375
|
}
|
|
4213
|
-
if (callbacks$
|
|
4376
|
+
if (callbacks$c.length === 0) {
|
|
4214
4377
|
mainDisposer$a === null || mainDisposer$a === void 0 ? void 0 : mainDisposer$a();
|
|
4215
4378
|
}
|
|
4216
4379
|
};
|
|
4217
4380
|
const onChannelDeleted = (callback) => {
|
|
4218
|
-
if (callbacks$
|
|
4381
|
+
if (callbacks$c.length === 0) {
|
|
4219
4382
|
const client = getActiveClient();
|
|
4220
4383
|
const filter = async (payload) => {
|
|
4221
4384
|
const data = await prepareChannelPayload(payload);
|
|
@@ -4235,53 +4398,53 @@ const onChannelDeleted = (callback) => {
|
|
|
4235
4398
|
}
|
|
4236
4399
|
});
|
|
4237
4400
|
ingestInCache(data);
|
|
4238
|
-
callbacks$
|
|
4401
|
+
callbacks$c.forEach(cb => cb(data.channels[0]));
|
|
4239
4402
|
};
|
|
4240
4403
|
mainDisposer$a = createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
4241
4404
|
}
|
|
4242
|
-
callbacks$
|
|
4243
|
-
return () => dispose$
|
|
4405
|
+
callbacks$c.push(callback);
|
|
4406
|
+
return () => dispose$c(callback);
|
|
4244
4407
|
};
|
|
4245
4408
|
|
|
4246
|
-
const callbacks$
|
|
4409
|
+
const callbacks$b = [];
|
|
4247
4410
|
let mainDisposer$9 = null;
|
|
4248
|
-
const dispose$
|
|
4249
|
-
const index = callbacks$
|
|
4411
|
+
const dispose$b = (cb) => {
|
|
4412
|
+
const index = callbacks$b.indexOf(cb);
|
|
4250
4413
|
if (index > -1) {
|
|
4251
|
-
callbacks$
|
|
4414
|
+
callbacks$b.splice(index, 1);
|
|
4252
4415
|
}
|
|
4253
|
-
if (callbacks$
|
|
4416
|
+
if (callbacks$b.length === 0) {
|
|
4254
4417
|
mainDisposer$9 === null || mainDisposer$9 === void 0 ? void 0 : mainDisposer$9();
|
|
4255
4418
|
}
|
|
4256
4419
|
};
|
|
4257
4420
|
const onChannelJoined = (callback) => {
|
|
4258
|
-
if (callbacks$
|
|
4421
|
+
if (callbacks$b.length === 0) {
|
|
4259
4422
|
const client = getActiveClient();
|
|
4260
4423
|
const filter = async (payload) => {
|
|
4261
4424
|
const preparedPayload = await prepareChannelPayload(payload);
|
|
4262
4425
|
const { channels, channelUsers } = preparedPayload;
|
|
4263
4426
|
ingestInCache(preparedPayload);
|
|
4264
|
-
callbacks$
|
|
4427
|
+
callbacks$b.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4265
4428
|
};
|
|
4266
4429
|
mainDisposer$9 = createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
4267
4430
|
}
|
|
4268
|
-
callbacks$
|
|
4269
|
-
return () => dispose$
|
|
4431
|
+
callbacks$b.push(callback);
|
|
4432
|
+
return () => dispose$b(callback);
|
|
4270
4433
|
};
|
|
4271
4434
|
|
|
4272
|
-
const callbacks$
|
|
4435
|
+
const callbacks$a = [];
|
|
4273
4436
|
let mainDisposer$8 = null;
|
|
4274
|
-
const dispose$
|
|
4275
|
-
const index = callbacks$
|
|
4437
|
+
const dispose$a = (cb) => {
|
|
4438
|
+
const index = callbacks$a.indexOf(cb);
|
|
4276
4439
|
if (index > -1) {
|
|
4277
|
-
callbacks$
|
|
4440
|
+
callbacks$a.splice(index, 1);
|
|
4278
4441
|
}
|
|
4279
|
-
if (callbacks$
|
|
4442
|
+
if (callbacks$a.length === 0) {
|
|
4280
4443
|
mainDisposer$8 === null || mainDisposer$8 === void 0 ? void 0 : mainDisposer$8();
|
|
4281
4444
|
}
|
|
4282
4445
|
};
|
|
4283
4446
|
const onChannelLeft = (callback) => {
|
|
4284
|
-
if (callbacks$
|
|
4447
|
+
if (callbacks$a.length === 0) {
|
|
4285
4448
|
const client = getActiveClient();
|
|
4286
4449
|
const filter = async (payload) => {
|
|
4287
4450
|
const { userId } = getActiveClient();
|
|
@@ -4305,27 +4468,27 @@ const onChannelLeft = (callback) => {
|
|
|
4305
4468
|
}
|
|
4306
4469
|
const { channels, channelUsers } = preparedPayload;
|
|
4307
4470
|
ingestInCache(preparedPayload);
|
|
4308
|
-
callbacks$
|
|
4471
|
+
callbacks$a.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4309
4472
|
};
|
|
4310
4473
|
mainDisposer$8 = createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
4311
4474
|
}
|
|
4312
|
-
callbacks$
|
|
4313
|
-
return () => dispose$
|
|
4475
|
+
callbacks$a.push(callback);
|
|
4476
|
+
return () => dispose$a(callback);
|
|
4314
4477
|
};
|
|
4315
4478
|
|
|
4316
|
-
const callbacks$
|
|
4479
|
+
const callbacks$9 = [];
|
|
4317
4480
|
let mainDisposer$7 = null;
|
|
4318
|
-
const dispose$
|
|
4319
|
-
const index = callbacks$
|
|
4481
|
+
const dispose$9 = (cb) => {
|
|
4482
|
+
const index = callbacks$9.indexOf(cb);
|
|
4320
4483
|
if (index > -1) {
|
|
4321
|
-
callbacks$
|
|
4484
|
+
callbacks$9.splice(index, 1);
|
|
4322
4485
|
}
|
|
4323
|
-
if (callbacks$
|
|
4486
|
+
if (callbacks$9.length === 0) {
|
|
4324
4487
|
mainDisposer$7 === null || mainDisposer$7 === void 0 ? void 0 : mainDisposer$7();
|
|
4325
4488
|
}
|
|
4326
4489
|
};
|
|
4327
4490
|
const onChannelSetMuted = (callback) => {
|
|
4328
|
-
if (callbacks$
|
|
4491
|
+
if (callbacks$9.length === 0) {
|
|
4329
4492
|
const client = getActiveClient();
|
|
4330
4493
|
const filter = async (payload) => {
|
|
4331
4494
|
var _a;
|
|
@@ -4340,24 +4503,124 @@ const onChannelSetMuted = (callback) => {
|
|
|
4340
4503
|
payload.channelId,
|
|
4341
4504
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4342
4505
|
if (channel) {
|
|
4343
|
-
callbacks$
|
|
4506
|
+
callbacks$9.forEach(cb => cb(channel));
|
|
4344
4507
|
}
|
|
4345
4508
|
};
|
|
4346
4509
|
mainDisposer$7 = createEventSubscriber(client, 'onChannelMute', 'channel.setMuted', filter);
|
|
4347
4510
|
}
|
|
4511
|
+
callbacks$9.push(callback);
|
|
4512
|
+
return () => dispose$9(callback);
|
|
4513
|
+
};
|
|
4514
|
+
|
|
4515
|
+
const callbacks$8 = [];
|
|
4516
|
+
let mainDisposer$6 = null;
|
|
4517
|
+
const dispose$8 = (cb) => {
|
|
4518
|
+
const index = callbacks$8.indexOf(cb);
|
|
4519
|
+
if (index > -1) {
|
|
4520
|
+
callbacks$8.splice(index, 1);
|
|
4521
|
+
}
|
|
4522
|
+
if (callbacks$8.length === 0) {
|
|
4523
|
+
mainDisposer$6 === null || mainDisposer$6 === void 0 ? void 0 : mainDisposer$6();
|
|
4524
|
+
}
|
|
4525
|
+
};
|
|
4526
|
+
/* begin_public_function
|
|
4527
|
+
id: channel.event.message_pinned
|
|
4528
|
+
*/
|
|
4529
|
+
/**
|
|
4530
|
+
* ```js
|
|
4531
|
+
* import { onChannelMessagePinned } from '@amityco/ts-sdk'
|
|
4532
|
+
* const dispose = onChannelMessagePinned(channel => {
|
|
4533
|
+
* // channel.pinnedMessage is the new pin
|
|
4534
|
+
* })
|
|
4535
|
+
* ```
|
|
4536
|
+
*
|
|
4537
|
+
* Fired when a message is pinned in a channel (the `channel.messagePinned` realtime
|
|
4538
|
+
* event). Pinning a different message while one is already pinned emits a single
|
|
4539
|
+
* `messagePinned` carrying the replacement — treat every payload as a full snapshot.
|
|
4540
|
+
*
|
|
4541
|
+
* The updated channel is written to cache before the callback runs, so
|
|
4542
|
+
* `ChannelRepository.getChannel` observers see `channel.pinnedMessage` change.
|
|
4543
|
+
*
|
|
4544
|
+
* @param callback The function to call when the event was fired
|
|
4545
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4546
|
+
*
|
|
4547
|
+
* @category Channel Events
|
|
4548
|
+
*/
|
|
4549
|
+
const onChannelMessagePinned = (callback) => {
|
|
4550
|
+
if (callbacks$8.length === 0) {
|
|
4551
|
+
const client = getActiveClient();
|
|
4552
|
+
const filter = (payload) => {
|
|
4553
|
+
var _a;
|
|
4554
|
+
const channel = findCachedChannelForPin(payload);
|
|
4555
|
+
if (!channel)
|
|
4556
|
+
return;
|
|
4557
|
+
const updated = updatePinnedMessageCache(channel, (_a = payload.pinnedMessage) !== null && _a !== void 0 ? _a : null, payload.users);
|
|
4558
|
+
callbacks$8.forEach(cb => cb(updated));
|
|
4559
|
+
};
|
|
4560
|
+
mainDisposer$6 = createEventSubscriber(client, 'onChannelMessagePinned', 'channel.messagePinned', filter);
|
|
4561
|
+
}
|
|
4562
|
+
callbacks$8.push(callback);
|
|
4563
|
+
return () => dispose$8(callback);
|
|
4564
|
+
};
|
|
4565
|
+
/* end_public_function */
|
|
4566
|
+
|
|
4567
|
+
const callbacks$7 = [];
|
|
4568
|
+
let mainDisposer$5 = null;
|
|
4569
|
+
const dispose$7 = (cb) => {
|
|
4570
|
+
const index = callbacks$7.indexOf(cb);
|
|
4571
|
+
if (index > -1) {
|
|
4572
|
+
callbacks$7.splice(index, 1);
|
|
4573
|
+
}
|
|
4574
|
+
if (callbacks$7.length === 0) {
|
|
4575
|
+
mainDisposer$5 === null || mainDisposer$5 === void 0 ? void 0 : mainDisposer$5();
|
|
4576
|
+
}
|
|
4577
|
+
};
|
|
4578
|
+
/* begin_public_function
|
|
4579
|
+
id: channel.event.message_unpinned
|
|
4580
|
+
*/
|
|
4581
|
+
/**
|
|
4582
|
+
* ```js
|
|
4583
|
+
* import { onChannelMessageUnpinned } from '@amityco/ts-sdk'
|
|
4584
|
+
* const dispose = onChannelMessageUnpinned(channel => {
|
|
4585
|
+
* // channel.pinnedMessage is now null
|
|
4586
|
+
* })
|
|
4587
|
+
* ```
|
|
4588
|
+
*
|
|
4589
|
+
* Fired when a channel's pinned message is removed (the `channel.messageUnpinned`
|
|
4590
|
+
* realtime event) — either by an explicit unpin or automatically by the server when the
|
|
4591
|
+
* pinned message is deleted or its author is banned from the channel / globally.
|
|
4592
|
+
*
|
|
4593
|
+
* @param callback The function to call when the event was fired
|
|
4594
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4595
|
+
*
|
|
4596
|
+
* @category Channel Events
|
|
4597
|
+
*/
|
|
4598
|
+
const onChannelMessageUnpinned = (callback) => {
|
|
4599
|
+
if (callbacks$7.length === 0) {
|
|
4600
|
+
const client = getActiveClient();
|
|
4601
|
+
const filter = (payload) => {
|
|
4602
|
+
const channel = findCachedChannelForPin(payload);
|
|
4603
|
+
if (!channel)
|
|
4604
|
+
return;
|
|
4605
|
+
const updated = updatePinnedMessageCache(channel, null);
|
|
4606
|
+
callbacks$7.forEach(cb => cb(updated));
|
|
4607
|
+
};
|
|
4608
|
+
mainDisposer$5 = createEventSubscriber(client, 'onChannelMessageUnpinned', 'channel.messageUnpinned', filter);
|
|
4609
|
+
}
|
|
4348
4610
|
callbacks$7.push(callback);
|
|
4349
4611
|
return () => dispose$7(callback);
|
|
4350
4612
|
};
|
|
4613
|
+
/* end_public_function */
|
|
4351
4614
|
|
|
4352
4615
|
const callbacks$6 = [];
|
|
4353
|
-
let mainDisposer$
|
|
4616
|
+
let mainDisposer$4 = null;
|
|
4354
4617
|
const dispose$6 = (cb) => {
|
|
4355
4618
|
const index = callbacks$6.indexOf(cb);
|
|
4356
4619
|
if (index > -1) {
|
|
4357
4620
|
callbacks$6.splice(index, 1);
|
|
4358
4621
|
}
|
|
4359
4622
|
if (callbacks$6.length === 0) {
|
|
4360
|
-
mainDisposer$
|
|
4623
|
+
mainDisposer$4 === null || mainDisposer$4 === void 0 ? void 0 : mainDisposer$4();
|
|
4361
4624
|
}
|
|
4362
4625
|
};
|
|
4363
4626
|
const onChannelMemberAdded = (callback) => {
|
|
@@ -4369,21 +4632,21 @@ const onChannelMemberAdded = (callback) => {
|
|
|
4369
4632
|
ingestInCache(preparedPayload);
|
|
4370
4633
|
callbacks$6.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'member')));
|
|
4371
4634
|
};
|
|
4372
|
-
mainDisposer$
|
|
4635
|
+
mainDisposer$4 = createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
4373
4636
|
}
|
|
4374
4637
|
callbacks$6.push(callback);
|
|
4375
4638
|
return () => dispose$6(callback);
|
|
4376
4639
|
};
|
|
4377
4640
|
|
|
4378
4641
|
const callbacks$5 = [];
|
|
4379
|
-
let mainDisposer$
|
|
4642
|
+
let mainDisposer$3 = null;
|
|
4380
4643
|
const dispose$5 = (cb) => {
|
|
4381
4644
|
const index = callbacks$5.indexOf(cb);
|
|
4382
4645
|
if (index > -1) {
|
|
4383
4646
|
callbacks$5.splice(index, 1);
|
|
4384
4647
|
}
|
|
4385
4648
|
if (callbacks$5.length === 0) {
|
|
4386
|
-
mainDisposer$
|
|
4649
|
+
mainDisposer$3 === null || mainDisposer$3 === void 0 ? void 0 : mainDisposer$3();
|
|
4387
4650
|
}
|
|
4388
4651
|
};
|
|
4389
4652
|
const onChannelMemberRemoved = (callback) => {
|
|
@@ -4395,21 +4658,21 @@ const onChannelMemberRemoved = (callback) => {
|
|
|
4395
4658
|
ingestInCache(preparedPayload);
|
|
4396
4659
|
callbacks$5.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4397
4660
|
};
|
|
4398
|
-
mainDisposer$
|
|
4661
|
+
mainDisposer$3 = createEventSubscriber(client, 'onChannelMemberRemoved', 'channel.membersRemoved', filter);
|
|
4399
4662
|
}
|
|
4400
4663
|
callbacks$5.push(callback);
|
|
4401
4664
|
return () => dispose$5(callback);
|
|
4402
4665
|
};
|
|
4403
4666
|
|
|
4404
4667
|
const callbacks$4 = [];
|
|
4405
|
-
let mainDisposer$
|
|
4668
|
+
let mainDisposer$2 = null;
|
|
4406
4669
|
const dispose$4 = (cb) => {
|
|
4407
4670
|
const index = callbacks$4.indexOf(cb);
|
|
4408
4671
|
if (index > -1) {
|
|
4409
4672
|
callbacks$4.splice(index, 1);
|
|
4410
4673
|
}
|
|
4411
4674
|
if (callbacks$4.length === 0) {
|
|
4412
|
-
mainDisposer$
|
|
4675
|
+
mainDisposer$2 === null || mainDisposer$2 === void 0 ? void 0 : mainDisposer$2();
|
|
4413
4676
|
}
|
|
4414
4677
|
};
|
|
4415
4678
|
const onChannelMemberBanned = (callback) => {
|
|
@@ -4429,20 +4692,20 @@ const onChannelMemberBanned = (callback) => {
|
|
|
4429
4692
|
ingestInCache(preparedPayload);
|
|
4430
4693
|
callbacks$4.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'banned')));
|
|
4431
4694
|
};
|
|
4432
|
-
mainDisposer$
|
|
4695
|
+
mainDisposer$2 = createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
4433
4696
|
callbacks$4.push(callback);
|
|
4434
4697
|
return () => dispose$4(callback);
|
|
4435
4698
|
};
|
|
4436
4699
|
|
|
4437
4700
|
const callbacks$3 = [];
|
|
4438
|
-
let mainDisposer$
|
|
4701
|
+
let mainDisposer$1 = null;
|
|
4439
4702
|
const dispose$3 = (cb) => {
|
|
4440
4703
|
const index = callbacks$3.indexOf(cb);
|
|
4441
4704
|
if (index > -1) {
|
|
4442
4705
|
callbacks$3.splice(index, 1);
|
|
4443
4706
|
}
|
|
4444
4707
|
if (callbacks$3.length === 0) {
|
|
4445
|
-
mainDisposer$
|
|
4708
|
+
mainDisposer$1 === null || mainDisposer$1 === void 0 ? void 0 : mainDisposer$1();
|
|
4446
4709
|
}
|
|
4447
4710
|
};
|
|
4448
4711
|
const onChannelMemberUnbanned = (callback) => {
|
|
@@ -4454,59 +4717,127 @@ const onChannelMemberUnbanned = (callback) => {
|
|
|
4454
4717
|
ingestInCache(preparedPayload);
|
|
4455
4718
|
callbacks$3.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'none')));
|
|
4456
4719
|
};
|
|
4457
|
-
mainDisposer$
|
|
4720
|
+
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
4458
4721
|
}
|
|
4459
4722
|
callbacks$3.push(callback);
|
|
4460
4723
|
return () => dispose$3(callback);
|
|
4461
4724
|
};
|
|
4462
4725
|
|
|
4463
4726
|
const callbacks$2 = [];
|
|
4464
|
-
|
|
4727
|
+
const mainDisposers$1 = [];
|
|
4465
4728
|
const dispose$2 = (cb) => {
|
|
4466
4729
|
const index = callbacks$2.indexOf(cb);
|
|
4467
4730
|
if (index > -1) {
|
|
4468
4731
|
callbacks$2.splice(index, 1);
|
|
4469
4732
|
}
|
|
4470
4733
|
if (callbacks$2.length === 0) {
|
|
4471
|
-
|
|
4734
|
+
mainDisposers$1.forEach(fn => fn());
|
|
4735
|
+
mainDisposers$1.length = 0;
|
|
4472
4736
|
}
|
|
4473
4737
|
};
|
|
4738
|
+
/* begin_public_function
|
|
4739
|
+
id: channel.event.member_role_added
|
|
4740
|
+
*/
|
|
4741
|
+
/**
|
|
4742
|
+
* ```js
|
|
4743
|
+
* import { onChannelMemberRoleAdded } from '@amityco/ts-sdk'
|
|
4744
|
+
* const dispose = onChannelMemberRoleAdded((channel, member) => {
|
|
4745
|
+
* // member.roles and member.permissions are the member's resulting state
|
|
4746
|
+
* })
|
|
4747
|
+
* ```
|
|
4748
|
+
*
|
|
4749
|
+
* Fired when a role is added to a member of a {@link Amity.Channel}, either by the
|
|
4750
|
+
* local `ChannelRepository.Moderation.addRole` call or by the `channel.roleAdded` realtime
|
|
4751
|
+
* event coming from any client or the admin console.
|
|
4752
|
+
*
|
|
4753
|
+
* The realtime event reaches every subscriber of the channel topic (see `getChannelTopic`),
|
|
4754
|
+
* not only the actor or the affected members. It carries the affected members' resulting
|
|
4755
|
+
* channel roles and channel-scoped permissions, which are written to cache before the
|
|
4756
|
+
* callback runs. The callback is invoked once per affected member already held in cache.
|
|
4757
|
+
*
|
|
4758
|
+
* @param callback The function to call when the event was fired
|
|
4759
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4760
|
+
*
|
|
4761
|
+
* @category Channel Events
|
|
4762
|
+
*/
|
|
4474
4763
|
const onChannelMemberRoleAdded = (callback) => {
|
|
4475
4764
|
if (callbacks$2.length === 0) {
|
|
4476
4765
|
const client = getActiveClient();
|
|
4477
|
-
const
|
|
4766
|
+
const onLocal = async (payload) => {
|
|
4478
4767
|
const { channels, channelUsers } = payload;
|
|
4479
4768
|
callbacks$2.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
4480
4769
|
};
|
|
4481
|
-
|
|
4770
|
+
const onRealtime = (payload) => {
|
|
4771
|
+
const { channel, members } = applyChannelRolePayload(payload);
|
|
4772
|
+
if (!channel)
|
|
4773
|
+
return;
|
|
4774
|
+
members.forEach(member => callbacks$2.forEach(cb => cb(channel, member)));
|
|
4775
|
+
};
|
|
4776
|
+
mainDisposers$1.push(createEventSubscriber(client, 'onChannelMemberRoleAdded', 'local.channel-moderator.role-added', onLocal));
|
|
4777
|
+
mainDisposers$1.push(createEventSubscriber(client, 'onChannelMemberRoleAdded', 'channel.roleAdded', onRealtime));
|
|
4482
4778
|
}
|
|
4483
4779
|
callbacks$2.push(callback);
|
|
4484
4780
|
return () => dispose$2(callback);
|
|
4485
4781
|
};
|
|
4782
|
+
/* end_public_function */
|
|
4486
4783
|
|
|
4487
4784
|
const callbacks$1 = [];
|
|
4488
|
-
|
|
4785
|
+
const mainDisposers = [];
|
|
4489
4786
|
const dispose$1 = (cb) => {
|
|
4490
4787
|
const index = callbacks$1.indexOf(cb);
|
|
4491
4788
|
if (index > -1) {
|
|
4492
4789
|
callbacks$1.splice(index, 1);
|
|
4493
4790
|
}
|
|
4494
4791
|
if (callbacks$1.length === 0) {
|
|
4495
|
-
|
|
4792
|
+
mainDisposers.forEach(fn => fn());
|
|
4793
|
+
mainDisposers.length = 0;
|
|
4496
4794
|
}
|
|
4497
4795
|
};
|
|
4796
|
+
/* begin_public_function
|
|
4797
|
+
id: channel.event.member_role_removed
|
|
4798
|
+
*/
|
|
4799
|
+
/**
|
|
4800
|
+
* ```js
|
|
4801
|
+
* import { onChannelMemberRoleRemoved } from '@amityco/ts-sdk'
|
|
4802
|
+
* const dispose = onChannelMemberRoleRemoved((channel, member) => {
|
|
4803
|
+
* // member.roles and member.permissions are the member's resulting state
|
|
4804
|
+
* })
|
|
4805
|
+
* ```
|
|
4806
|
+
*
|
|
4807
|
+
* Fired when a role is removed from a member of a {@link Amity.Channel}, either by the
|
|
4808
|
+
* local `ChannelRepository.Moderation.removeRole` call or by the `channel.roleRemoved` realtime
|
|
4809
|
+
* event coming from any client or the admin console.
|
|
4810
|
+
*
|
|
4811
|
+
* The realtime event reaches every subscriber of the channel topic (see `getChannelTopic`),
|
|
4812
|
+
* not only the actor or the affected members. It carries the affected members' resulting
|
|
4813
|
+
* channel roles and channel-scoped permissions, which are written to cache before the
|
|
4814
|
+
* callback runs. The callback is invoked once per affected member already held in cache.
|
|
4815
|
+
*
|
|
4816
|
+
* @param callback The function to call when the event was fired
|
|
4817
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4818
|
+
*
|
|
4819
|
+
* @category Channel Events
|
|
4820
|
+
*/
|
|
4498
4821
|
const onChannelMemberRoleRemoved = (callback) => {
|
|
4499
4822
|
if (callbacks$1.length === 0) {
|
|
4500
4823
|
const client = getActiveClient();
|
|
4501
|
-
const
|
|
4824
|
+
const onLocal = async (payload) => {
|
|
4502
4825
|
const { channels, channelUsers } = payload;
|
|
4503
4826
|
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
4504
4827
|
};
|
|
4505
|
-
|
|
4828
|
+
const onRealtime = (payload) => {
|
|
4829
|
+
const { channel, members } = applyChannelRolePayload(payload);
|
|
4830
|
+
if (!channel)
|
|
4831
|
+
return;
|
|
4832
|
+
members.forEach(member => callbacks$1.forEach(cb => cb(channel, member)));
|
|
4833
|
+
};
|
|
4834
|
+
mainDisposers.push(createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', onLocal));
|
|
4835
|
+
mainDisposers.push(createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'channel.roleRemoved', onRealtime));
|
|
4506
4836
|
}
|
|
4507
4837
|
callbacks$1.push(callback);
|
|
4508
4838
|
return () => dispose$1(callback);
|
|
4509
4839
|
};
|
|
4840
|
+
/* end_public_function */
|
|
4510
4841
|
|
|
4511
4842
|
/**
|
|
4512
4843
|
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
@@ -4630,6 +4961,8 @@ const getMyMembership = (channelId, callback) => {
|
|
|
4630
4961
|
disposers.push(onChannelMemberBanned(realtimeRouter));
|
|
4631
4962
|
disposers.push(onChannelMemberUnbanned(realtimeRouter));
|
|
4632
4963
|
disposers.push(onChannelSetUserMuted(realtimeRouter));
|
|
4964
|
+
disposers.push(onChannelMemberRoleAdded(realtimeRouter));
|
|
4965
|
+
disposers.push(onChannelMemberRoleRemoved(realtimeRouter));
|
|
4633
4966
|
onFetch();
|
|
4634
4967
|
return () => {
|
|
4635
4968
|
disposers.forEach(fn => fn());
|
|
@@ -5023,7 +5356,9 @@ const initializeMessagePreviewSetting = async () => {
|
|
|
5023
5356
|
const getSocialSettings = async () => {
|
|
5024
5357
|
const client = getActiveClient();
|
|
5025
5358
|
const { data } = await client.http.get(`/api/v3/network-settings/social`);
|
|
5026
|
-
return data.socialNetworkSetting
|
|
5359
|
+
return Object.assign(Object.assign({}, data.socialNetworkSetting), {
|
|
5360
|
+
// Networks that never set the comment edit switch allow the edit
|
|
5361
|
+
isAllowEditCommentWhenReviewingEnabled: data.socialNetworkSetting.isAllowEditCommentWhenReviewingEnabled });
|
|
5027
5362
|
};
|
|
5028
5363
|
|
|
5029
5364
|
/**
|
|
@@ -5709,6 +6044,32 @@ class AnalyticsEventCapturer {
|
|
|
5709
6044
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
5710
6045
|
});
|
|
5711
6046
|
}
|
|
6047
|
+
markCuratedContentWidgetAsViewed(topicId) {
|
|
6048
|
+
this.markAs({
|
|
6049
|
+
uniqueId: `curatedContentWidget.${topicId}`,
|
|
6050
|
+
contentId: topicId,
|
|
6051
|
+
contentType: "curated_content_widget" /* Amity.AnalyticEventContentType.CuratedContentWidget */,
|
|
6052
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
6053
|
+
});
|
|
6054
|
+
}
|
|
6055
|
+
markCuratedContentPostAsViewed(postId, topicId) {
|
|
6056
|
+
this.markAs({
|
|
6057
|
+
uniqueId: `curatedContentPost.${postId}.view`,
|
|
6058
|
+
contentId: postId,
|
|
6059
|
+
contentType: "curated_content_post" /* Amity.AnalyticEventContentType.CuratedContentPost */,
|
|
6060
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
6061
|
+
metadata: { topicId },
|
|
6062
|
+
});
|
|
6063
|
+
}
|
|
6064
|
+
markCuratedContentPostAsClicked(postId, topicId) {
|
|
6065
|
+
this.markAs({
|
|
6066
|
+
uniqueId: `curatedContentPost.${postId}.click`,
|
|
6067
|
+
contentId: postId,
|
|
6068
|
+
contentType: "curated_content_post" /* Amity.AnalyticEventContentType.CuratedContentPost */,
|
|
6069
|
+
activityType: "linkClicked" /* Amity.AnalyticEventActivityType.Click */,
|
|
6070
|
+
metadata: { topicId },
|
|
6071
|
+
});
|
|
6072
|
+
}
|
|
5712
6073
|
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
5713
6074
|
var _a;
|
|
5714
6075
|
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -5872,6 +6233,24 @@ class AnalyticsEngine {
|
|
|
5872
6233
|
this._eventCapturer.markPostAsViewed(postId);
|
|
5873
6234
|
}
|
|
5874
6235
|
}
|
|
6236
|
+
markCuratedContentWidgetAsViewed(topicId) {
|
|
6237
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6238
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6239
|
+
this._eventCapturer.markCuratedContentWidgetAsViewed(topicId);
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
markCuratedContentPostAsViewed(postId, topicId) {
|
|
6243
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6244
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6245
|
+
this._eventCapturer.markCuratedContentPostAsViewed(postId, topicId);
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
markCuratedContentPostAsClicked(postId, topicId) {
|
|
6249
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6250
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6251
|
+
this._eventCapturer.markCuratedContentPostAsClicked(postId, topicId);
|
|
6252
|
+
}
|
|
6253
|
+
}
|
|
5875
6254
|
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
5876
6255
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
5877
6256
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
@@ -7268,6 +7647,265 @@ class CursorController {
|
|
|
7268
7647
|
}
|
|
7269
7648
|
}
|
|
7270
7649
|
|
|
7650
|
+
class ResetTask {
|
|
7651
|
+
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
7652
|
+
this.postId = postId;
|
|
7653
|
+
this.latestCreatedAt = latestCreatedAt;
|
|
7654
|
+
this.serverCommentCount = serverCommentCount;
|
|
7655
|
+
}
|
|
7656
|
+
}
|
|
7657
|
+
|
|
7658
|
+
// Task to track comment creation
|
|
7659
|
+
class CreateTask {
|
|
7660
|
+
constructor(postId, commentId, createdAt) {
|
|
7661
|
+
this.postId = postId;
|
|
7662
|
+
this.commentId = commentId;
|
|
7663
|
+
this.createdAt = createdAt;
|
|
7664
|
+
}
|
|
7665
|
+
}
|
|
7666
|
+
|
|
7667
|
+
/**
|
|
7668
|
+
* A pending comment was approved and now counts publicly. Unlike `CreateTask` it carries no
|
|
7669
|
+
* `createdAt` and bypasses the age guard on purpose: the comment was written before the last post
|
|
7670
|
+
* payload (so its `createdAt` is old) but entered the server count only now. Same rule as iOS.
|
|
7671
|
+
*
|
|
7672
|
+
* Accepted trade-off (plan 40 §9): if a `ResetTask` that already includes this comment lands
|
|
7673
|
+
* between the approve response and the late `comment.approved` event, the count reads +1 until
|
|
7674
|
+
* the next server sync — the same self-correcting drift accepted for stale deletes.
|
|
7675
|
+
*/
|
|
7676
|
+
class ApproveTask {
|
|
7677
|
+
constructor(postId, commentId) {
|
|
7678
|
+
this.postId = postId;
|
|
7679
|
+
this.commentId = commentId;
|
|
7680
|
+
}
|
|
7681
|
+
}
|
|
7682
|
+
|
|
7683
|
+
// Task to track comment deletion
|
|
7684
|
+
class DeleteTask {
|
|
7685
|
+
constructor(postId, commentId) {
|
|
7686
|
+
this.postId = postId;
|
|
7687
|
+
this.commentId = commentId;
|
|
7688
|
+
}
|
|
7689
|
+
}
|
|
7690
|
+
|
|
7691
|
+
class CommentChange {
|
|
7692
|
+
constructor(latestCreatedAt, serverCommentCount) {
|
|
7693
|
+
this.latestCommentCreatedAt = latestCreatedAt;
|
|
7694
|
+
this.serverCommentCount = serverCommentCount;
|
|
7695
|
+
this.createdCommentIds = new Set();
|
|
7696
|
+
this.deletedCommentIds = new Set();
|
|
7697
|
+
}
|
|
7698
|
+
}
|
|
7699
|
+
|
|
7700
|
+
class PostCommentCountEngine {
|
|
7701
|
+
constructor() {
|
|
7702
|
+
this.isProcessing = false;
|
|
7703
|
+
this.tasks = [];
|
|
7704
|
+
this.commentChangeTracker = new Map();
|
|
7705
|
+
// Ids of the LOGGED-IN USER's own pending comments, per post. Survives ResetTask, so the
|
|
7706
|
+
// author's +1 does not vanish on the next post refresh; emptied only when the comment leaves
|
|
7707
|
+
// the pending state (approval hands it to createdCommentIds, decline/delete drops it).
|
|
7708
|
+
this.pendingAuthoredCommentIds = new Map();
|
|
7709
|
+
}
|
|
7710
|
+
queueCommentChangeTask(task) {
|
|
7711
|
+
this.tasks.push(task);
|
|
7712
|
+
if (!this.isProcessing) {
|
|
7713
|
+
this.processCommentChangeTask();
|
|
7714
|
+
}
|
|
7715
|
+
}
|
|
7716
|
+
addPendingAuthoredComment(postId, commentId, { publish = true } = {}) {
|
|
7717
|
+
var _a;
|
|
7718
|
+
const ids = (_a = this.pendingAuthoredCommentIds.get(postId)) !== null && _a !== void 0 ? _a : new Set();
|
|
7719
|
+
if (ids.has(commentId))
|
|
7720
|
+
return;
|
|
7721
|
+
ids.add(commentId);
|
|
7722
|
+
this.pendingAuthoredCommentIds.set(postId, ids);
|
|
7723
|
+
if (publish)
|
|
7724
|
+
this.publishIfTracked(postId);
|
|
7725
|
+
}
|
|
7726
|
+
removePendingAuthoredComment(postId, commentId, { publish = true } = {}) {
|
|
7727
|
+
const ids = this.pendingAuthoredCommentIds.get(postId);
|
|
7728
|
+
if (!(ids === null || ids === void 0 ? void 0 : ids.delete(commentId)))
|
|
7729
|
+
return false;
|
|
7730
|
+
if (ids.size === 0)
|
|
7731
|
+
this.pendingAuthoredCommentIds.delete(postId);
|
|
7732
|
+
if (publish)
|
|
7733
|
+
this.publishIfTracked(postId);
|
|
7734
|
+
return true;
|
|
7735
|
+
}
|
|
7736
|
+
/** Whether a post payload has seeded this post; without one every count is `0`. */
|
|
7737
|
+
hasTracker(postId) {
|
|
7738
|
+
return this.commentChangeTracker.has(postId);
|
|
7739
|
+
}
|
|
7740
|
+
isPendingAuthoredComment(postId, commentId) {
|
|
7741
|
+
var _a, _b;
|
|
7742
|
+
return (_b = (_a = this.pendingAuthoredCommentIds.get(postId)) === null || _a === void 0 ? void 0 : _a.has(commentId)) !== null && _b !== void 0 ? _b : false;
|
|
7743
|
+
}
|
|
7744
|
+
// Drops every per-post state. Called on logout / user switch.
|
|
7745
|
+
reset() {
|
|
7746
|
+
this.tasks = [];
|
|
7747
|
+
this.commentChangeTracker.clear();
|
|
7748
|
+
this.pendingAuthoredCommentIds.clear();
|
|
7749
|
+
}
|
|
7750
|
+
publishIfTracked(postId) {
|
|
7751
|
+
// Without a tracker there is no server figure to add to; the next ResetTask picks it up.
|
|
7752
|
+
if (!this.commentChangeTracker.has(postId))
|
|
7753
|
+
return;
|
|
7754
|
+
PostCommentCountEngine.publishUpdate(postId, this.getLocalCommentCount(postId, true));
|
|
7755
|
+
}
|
|
7756
|
+
processCommentChangeTask() {
|
|
7757
|
+
if (this.isProcessing) {
|
|
7758
|
+
return;
|
|
7759
|
+
}
|
|
7760
|
+
this.isProcessing = true;
|
|
7761
|
+
if (this.tasks.length === 0) {
|
|
7762
|
+
this.isProcessing = false;
|
|
7763
|
+
return;
|
|
7764
|
+
}
|
|
7765
|
+
// Process in capped batches, coalescing updates
|
|
7766
|
+
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
7767
|
+
const modifiedPostIds = new Set();
|
|
7768
|
+
batch.forEach(task => {
|
|
7769
|
+
let modified = false;
|
|
7770
|
+
if (task instanceof ResetTask) {
|
|
7771
|
+
modified = this.processResetTaskInternal(task);
|
|
7772
|
+
}
|
|
7773
|
+
else if (task instanceof CreateTask) {
|
|
7774
|
+
modified = this.processCreateTaskInternal(task);
|
|
7775
|
+
}
|
|
7776
|
+
else if (task instanceof ApproveTask) {
|
|
7777
|
+
modified = this.processApproveTaskInternal(task);
|
|
7778
|
+
}
|
|
7779
|
+
else if (task instanceof DeleteTask) {
|
|
7780
|
+
modified = this.processDeleteTaskInternal(task);
|
|
7781
|
+
}
|
|
7782
|
+
if (modified) {
|
|
7783
|
+
modifiedPostIds.add(task.postId);
|
|
7784
|
+
}
|
|
7785
|
+
});
|
|
7786
|
+
// Publish one update per modified post
|
|
7787
|
+
modifiedPostIds.forEach(postId => {
|
|
7788
|
+
PostCommentCountEngine.publishUpdate(postId, this.getLocalCommentCount(postId, true));
|
|
7789
|
+
});
|
|
7790
|
+
this.isProcessing = false;
|
|
7791
|
+
// Recurse if more tasks remain
|
|
7792
|
+
if (this.tasks.length > 0) {
|
|
7793
|
+
this.processCommentChangeTask();
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
processResetTaskInternal(task) {
|
|
7797
|
+
// Always creates/overwrites tracker
|
|
7798
|
+
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
7799
|
+
return true;
|
|
7800
|
+
}
|
|
7801
|
+
processCreateTaskInternal(task) {
|
|
7802
|
+
// The comment is public now: the author-local +1 hands over to the normal path, so the
|
|
7803
|
+
// count stays put instead of moving twice.
|
|
7804
|
+
const wasPendingAuthored = this.removePendingAuthoredComment(task.postId, task.commentId, {
|
|
7805
|
+
publish: false,
|
|
7806
|
+
});
|
|
7807
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7808
|
+
if (!tracker)
|
|
7809
|
+
return false; // No tracker, skip
|
|
7810
|
+
if (tracker.deletedCommentIds.delete(task.commentId))
|
|
7811
|
+
return true; // Re-approval cancels the earlier removal
|
|
7812
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
7813
|
+
return wasPendingAuthored; // Deduplication
|
|
7814
|
+
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
7815
|
+
return wasPendingAuthored; // Timestamp filtering
|
|
7816
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
7817
|
+
return true;
|
|
7818
|
+
}
|
|
7819
|
+
processApproveTaskInternal(task) {
|
|
7820
|
+
// The comment is public now: the author-local +1 hands over to the normal path, so the
|
|
7821
|
+
// count stays put instead of moving twice.
|
|
7822
|
+
const wasPendingAuthored = this.removePendingAuthoredComment(task.postId, task.commentId, {
|
|
7823
|
+
publish: false,
|
|
7824
|
+
});
|
|
7825
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7826
|
+
if (!tracker)
|
|
7827
|
+
return false; // No tracker, skip
|
|
7828
|
+
if (tracker.deletedCommentIds.delete(task.commentId))
|
|
7829
|
+
return true; // Re-approval cancels the earlier re-review removal
|
|
7830
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
7831
|
+
return wasPendingAuthored; // Approve response and comment.approved event dedupe by id
|
|
7832
|
+
// No timestamp filtering: approval is the moment the comment enters the count, not createdAt
|
|
7833
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
7834
|
+
return true;
|
|
7835
|
+
}
|
|
7836
|
+
processDeleteTaskInternal(task) {
|
|
7837
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7838
|
+
if (!tracker)
|
|
7839
|
+
return false; // No tracker, skip
|
|
7840
|
+
if (tracker.deletedCommentIds.has(task.commentId))
|
|
7841
|
+
return false; // Deduplication
|
|
7842
|
+
tracker.deletedCommentIds.add(task.commentId);
|
|
7843
|
+
return true;
|
|
7844
|
+
}
|
|
7845
|
+
/**
|
|
7846
|
+
* The count as this session sees it: the last server figure plus the local delta.
|
|
7847
|
+
*
|
|
7848
|
+
* `includePending` adds the logged-in user's own pending comments — the author's view. A
|
|
7849
|
+
* pending id is added only while the public delta does not already count it, so a comment
|
|
7850
|
+
* present in both sets counts once: a `comment.created` that arrives pending after the
|
|
7851
|
+
* `comment.approved` hand-over adds nothing, while an approved comment sent back to review
|
|
7852
|
+
* (created, deleted and pending all hold its id) keeps the author's +1.
|
|
7853
|
+
*
|
|
7854
|
+
* `0` for a post no payload has seeded yet; callers fall back to the post's own figure.
|
|
7855
|
+
*/
|
|
7856
|
+
getLocalCommentCount(postId, includePending = false) {
|
|
7857
|
+
var _a;
|
|
7858
|
+
const tracker = this.commentChangeTracker.get(postId);
|
|
7859
|
+
if (!tracker)
|
|
7860
|
+
return 0;
|
|
7861
|
+
const publicDelta = tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
7862
|
+
if (!includePending)
|
|
7863
|
+
return Math.max(0, tracker.serverCommentCount + publicDelta);
|
|
7864
|
+
let pendingExtra = 0;
|
|
7865
|
+
(_a = this.pendingAuthoredCommentIds.get(postId)) === null || _a === void 0 ? void 0 : _a.forEach(commentId => {
|
|
7866
|
+
const countedPublicly = tracker.createdCommentIds.has(commentId) && !tracker.deletedCommentIds.has(commentId);
|
|
7867
|
+
if (!countedPublicly)
|
|
7868
|
+
pendingExtra += 1;
|
|
7869
|
+
});
|
|
7870
|
+
return Math.max(0, tracker.serverCommentCount + publicDelta + pendingExtra);
|
|
7871
|
+
}
|
|
7872
|
+
static publishUpdate(postId, newCount) {
|
|
7873
|
+
var _a;
|
|
7874
|
+
const queryKey = ['post', 'get', postId];
|
|
7875
|
+
mergeInCache(queryKey, {
|
|
7876
|
+
localCommentCount: newCount,
|
|
7877
|
+
});
|
|
7878
|
+
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7879
|
+
if (!postPayload)
|
|
7880
|
+
return;
|
|
7881
|
+
fireEvent('local.post.updated', {
|
|
7882
|
+
posts: [postPayload],
|
|
7883
|
+
});
|
|
7884
|
+
}
|
|
7885
|
+
}
|
|
7886
|
+
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
7887
|
+
let instance$1;
|
|
7888
|
+
var PostCommentCountEngine$1 = {
|
|
7889
|
+
getInstance: () => {
|
|
7890
|
+
if (!instance$1) {
|
|
7891
|
+
instance$1 = new PostCommentCountEngine();
|
|
7892
|
+
}
|
|
7893
|
+
return instance$1;
|
|
7894
|
+
},
|
|
7895
|
+
};
|
|
7896
|
+
|
|
7897
|
+
/**
|
|
7898
|
+
* Comment-count state is per user — in particular the ids of the logged-in user's own pending
|
|
7899
|
+
* comments — so it must not survive a logout or a user switch.
|
|
7900
|
+
*
|
|
7901
|
+
* @category private
|
|
7902
|
+
*/
|
|
7903
|
+
const postCommentCountEngineOnLoginHandler = () => onSessionStateChange(state => {
|
|
7904
|
+
if (state === "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */ || state === "terminated" /* Amity.SessionStates.TERMINATED */) {
|
|
7905
|
+
PostCommentCountEngine$1.getInstance().reset();
|
|
7906
|
+
}
|
|
7907
|
+
});
|
|
7908
|
+
|
|
7271
7909
|
const EVENTS = [
|
|
7272
7910
|
'disconnected',
|
|
7273
7911
|
'error',
|
|
@@ -7457,7 +8095,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
7457
8095
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
7458
8096
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
7459
8097
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
7460
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
8098
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler());
|
|
7461
8099
|
if (client.useLegacyUnreadCount) {
|
|
7462
8100
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
7463
8101
|
}
|
|
@@ -8493,7 +9131,7 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
8493
9131
|
*
|
|
8494
9132
|
* @category Client API
|
|
8495
9133
|
* */
|
|
8496
|
-
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
9134
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, product, uikitVersion, appId, appVersion, } = {}) => {
|
|
8497
9135
|
var _a, _b, _c;
|
|
8498
9136
|
const log = createLogger(debugSession);
|
|
8499
9137
|
log('client/api/createClient', {
|
|
@@ -8522,6 +9160,10 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
8522
9160
|
const useLegacyUnreadCount = true;
|
|
8523
9161
|
const client = {
|
|
8524
9162
|
version: `${VERSION}`,
|
|
9163
|
+
product,
|
|
9164
|
+
uikitVersion,
|
|
9165
|
+
appId,
|
|
9166
|
+
appVersion,
|
|
8525
9167
|
apiKey,
|
|
8526
9168
|
/*
|
|
8527
9169
|
* SDK Components
|
|
@@ -8760,13 +9402,13 @@ class GlobalFileAccessType {
|
|
|
8760
9402
|
}
|
|
8761
9403
|
}
|
|
8762
9404
|
_GlobalFileAccessType_fileAccessType = new WeakMap();
|
|
8763
|
-
let instance
|
|
9405
|
+
let instance;
|
|
8764
9406
|
var GlobalFileAccessType$1 = {
|
|
8765
9407
|
getInstance: () => {
|
|
8766
|
-
if (!instance
|
|
8767
|
-
instance
|
|
9408
|
+
if (!instance) {
|
|
9409
|
+
instance = new GlobalFileAccessType();
|
|
8768
9410
|
}
|
|
8769
|
-
return instance
|
|
9411
|
+
return instance;
|
|
8770
9412
|
},
|
|
8771
9413
|
};
|
|
8772
9414
|
|
|
@@ -9603,7 +10245,7 @@ const getUserUnread = (callback) => {
|
|
|
9603
10245
|
};
|
|
9604
10246
|
};
|
|
9605
10247
|
|
|
9606
|
-
var index$
|
|
10248
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
9607
10249
|
__proto__: null,
|
|
9608
10250
|
getActiveClient: getActiveClient,
|
|
9609
10251
|
getActiveUser: getActiveUser,
|
|
@@ -10829,7 +11471,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
10829
11471
|
};
|
|
10830
11472
|
/* end_public_function */
|
|
10831
11473
|
|
|
10832
|
-
var index$
|
|
11474
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
10833
11475
|
__proto__: null,
|
|
10834
11476
|
blockUser: blockUser,
|
|
10835
11477
|
unBlockUser: unBlockUser,
|
|
@@ -12170,6 +12812,16 @@ const createChannel = async (bundle) => {
|
|
|
12170
12812
|
/* c8 ignore next */
|
|
12171
12813
|
isPublic: (bundle === null || bundle === void 0 ? void 0 : bundle.type) === 'community' ? isPublic : undefined }));
|
|
12172
12814
|
}
|
|
12815
|
+
// Fire the event locally, the same way createCommunity and createPost do.
|
|
12816
|
+
// Without it a running getChannels collection never inserts the new channel:
|
|
12817
|
+
// its query stream controller inserts an id only on OnCreate / OnJoin /
|
|
12818
|
+
// OnResolveChannel / OnUnarchived, and the first sent message arrives as an
|
|
12819
|
+
// OnUpdate, which only re-notifies. Reusing the MQTT event name means the
|
|
12820
|
+
// already-wired onChannelCreated -> OnCreate path does the insert, so the
|
|
12821
|
+
// list updates without a re-query. onChannelCreated re-runs
|
|
12822
|
+
// prepareChannelPayload + ingestInCache itself, so this is idempotent with
|
|
12823
|
+
// the ingest below.
|
|
12824
|
+
fireEvent('channel.created', payload.data);
|
|
12173
12825
|
const data = await prepareChannelPayload(payload.data);
|
|
12174
12826
|
const cachedAt = client.cache && Date.now();
|
|
12175
12827
|
if (client.cache)
|
|
@@ -12341,8 +12993,32 @@ const streamLinkedObject = (stream) => {
|
|
|
12341
12993
|
} });
|
|
12342
12994
|
};
|
|
12343
12995
|
|
|
12996
|
+
const KNOWN_APPROVAL_STATUSES = [
|
|
12997
|
+
"pending" /* Amity.CommentApprovalStatusEnum.Pending */,
|
|
12998
|
+
"approved" /* Amity.CommentApprovalStatusEnum.Approved */,
|
|
12999
|
+
"rejected" /* Amity.CommentApprovalStatusEnum.Rejected */,
|
|
13000
|
+
];
|
|
13001
|
+
/**
|
|
13002
|
+
* The server sends `approvalStatus` only while a comment is held for review or after it was
|
|
13003
|
+
* rejected. Absent, `null`, or an unrecognised value all resolve to `approved` — never to
|
|
13004
|
+
* `pending`, which would mark every comment written before the feature as unpublished.
|
|
13005
|
+
*/
|
|
13006
|
+
const resolveCommentApprovalStatus = (approvalStatus) => {
|
|
13007
|
+
if (approvalStatus && KNOWN_APPROVAL_STATUSES.includes(approvalStatus)) {
|
|
13008
|
+
return approvalStatus;
|
|
13009
|
+
}
|
|
13010
|
+
return "approved" /* Amity.CommentApprovalStatusEnum.Approved */;
|
|
13011
|
+
};
|
|
13012
|
+
const prepareComment = (comment) => (Object.assign(Object.assign(Object.assign({}, (comment.hasOwnProperty('myReactions') ? {} : { myReactions: [] })), comment), { approvalStatus: resolveCommentApprovalStatus(comment.approvalStatus) }));
|
|
13013
|
+
function prepareCommentPayload(commentPayload) {
|
|
13014
|
+
const { comments, commentChildren } = commentPayload;
|
|
13015
|
+
return Object.assign(Object.assign(Object.assign({}, commentPayload), { comments: comments.map(prepareComment) }), (commentChildren ? { commentChildren: commentChildren.map(prepareComment) } : {}));
|
|
13016
|
+
}
|
|
13017
|
+
|
|
12344
13018
|
const commentLinkedObject = (comment) => {
|
|
12345
|
-
return Object.assign(Object.assign({}, comment), {
|
|
13019
|
+
return Object.assign(Object.assign({}, comment), {
|
|
13020
|
+
// Non-optional on the public model: absent on the wire means approved
|
|
13021
|
+
approvalStatus: resolveCommentApprovalStatus(comment.approvalStatus), get target() {
|
|
12346
13022
|
const commentTypes = {
|
|
12347
13023
|
type: comment.targetType,
|
|
12348
13024
|
};
|
|
@@ -12550,7 +13226,7 @@ const getWatchSessionStorage = () => {
|
|
|
12550
13226
|
return storageInstance;
|
|
12551
13227
|
};
|
|
12552
13228
|
|
|
12553
|
-
const privateKey = "
|
|
13229
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
12554
13230
|
/*
|
|
12555
13231
|
* The crypto algorithm used for importing key and signing string
|
|
12556
13232
|
*/
|
|
@@ -12993,6 +13669,122 @@ const fileLinkedObject = (file) => {
|
|
|
12993
13669
|
return file;
|
|
12994
13670
|
};
|
|
12995
13671
|
|
|
13672
|
+
const isCommentPending = (comment) => resolveCommentApprovalStatus(comment.approvalStatus) === "pending" /* Amity.CommentApprovalStatusEnum.Pending */;
|
|
13673
|
+
const isCommentApproved = (comment) => resolveCommentApprovalStatus(comment.approvalStatus) === "approved" /* Amity.CommentApprovalStatusEnum.Approved */;
|
|
13674
|
+
// Only post and content references feed PostCommentCountEngine; story counts live on the story.
|
|
13675
|
+
const isCountedReference = (comment) => ['post', 'content'].includes(comment.referenceType);
|
|
13676
|
+
const isAuthoredByCurrentUser = (comment) => comment.userId === getActiveClient().userId;
|
|
13677
|
+
/**
|
|
13678
|
+
* Whether a comment on this reference would be held for review, read from the cached post's
|
|
13679
|
+
* community. `true` when that cannot be known — the post or its community is not cached yet.
|
|
13680
|
+
* A pending guess that turns out approved is corrected by the response and the comment then
|
|
13681
|
+
* enters the list; an approved guess that turns out pending has already been shown in a public
|
|
13682
|
+
* list with nothing to take it back out. Only shapes the optimistic object — the server
|
|
13683
|
+
* response is the authority on the actual status.
|
|
13684
|
+
*/
|
|
13685
|
+
const isCommentApprovalRequired = (bundle) => {
|
|
13686
|
+
var _a, _b;
|
|
13687
|
+
// Only comments on community posts are gated; every other reference is known-off
|
|
13688
|
+
if (bundle.referenceType !== 'post')
|
|
13689
|
+
return false;
|
|
13690
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
13691
|
+
if (!post)
|
|
13692
|
+
return true;
|
|
13693
|
+
// A user-feed post is known-off
|
|
13694
|
+
if (post.targetType !== 'community')
|
|
13695
|
+
return false;
|
|
13696
|
+
const community = (_b = pullFromCache([
|
|
13697
|
+
'community',
|
|
13698
|
+
'get',
|
|
13699
|
+
post.targetId,
|
|
13700
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
13701
|
+
if (!community)
|
|
13702
|
+
return true;
|
|
13703
|
+
return community.needApprovalOnCommentCreation === true;
|
|
13704
|
+
};
|
|
13705
|
+
/**
|
|
13706
|
+
* An approved comment arrived over realtime: one `CreateTask` carrying its own `createdAt`, so
|
|
13707
|
+
* the timestamp filter skips anything the last post payload already counted. The author's own
|
|
13708
|
+
* comment reaches here as an echo too; the engine de-duplicates it by id against the task the
|
|
13709
|
+
* create response queued.
|
|
13710
|
+
*/
|
|
13711
|
+
const applyCommentCreatedCount = (comment) => {
|
|
13712
|
+
if (!isCountedReference(comment))
|
|
13713
|
+
return;
|
|
13714
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(comment.referenceId, comment.commentId, comment.createdAt));
|
|
13715
|
+
};
|
|
13716
|
+
/**
|
|
13717
|
+
* The author's own pending comment counts in their view only. Recorded as separate engine state
|
|
13718
|
+
* so it survives a post refresh (`ResetTask`).
|
|
13719
|
+
*/
|
|
13720
|
+
const recordPendingAuthoredComment = (comment, options) => {
|
|
13721
|
+
if (!isCountedReference(comment) || !isAuthoredByCurrentUser(comment))
|
|
13722
|
+
return;
|
|
13723
|
+
PostCommentCountEngine$1.getInstance().addPendingAuthoredComment(comment.referenceId, comment.commentId, options);
|
|
13724
|
+
};
|
|
13725
|
+
/**
|
|
13726
|
+
* A pending comment was declined or deleted: it was never in the server count, so no
|
|
13727
|
+
* `DeleteTask` — only the author-local +1 goes away.
|
|
13728
|
+
*/
|
|
13729
|
+
const releasePendingAuthoredComment = (comment) => {
|
|
13730
|
+
if (!isCountedReference(comment))
|
|
13731
|
+
return;
|
|
13732
|
+
PostCommentCountEngine$1.getInstance().removePendingAuthoredComment(comment.referenceId, comment.commentId);
|
|
13733
|
+
};
|
|
13734
|
+
/**
|
|
13735
|
+
* Reveal: exactly one `ApproveTask`. The engine de-duplicates by comment id, so the approve
|
|
13736
|
+
* response and the `comment.approved` event may both call this. `ApproveTask` bypasses the age
|
|
13737
|
+
* guard on purpose — the comment was written before the last server sync but enters the public
|
|
13738
|
+
* count now — matching the iOS `ApproveTask` (plan 40 §9, guard off for approve).
|
|
13739
|
+
*/
|
|
13740
|
+
const applyCommentApprovedCount = (comment) => {
|
|
13741
|
+
if (!isCountedReference(comment))
|
|
13742
|
+
return;
|
|
13743
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ApproveTask(comment.referenceId, comment.commentId));
|
|
13744
|
+
};
|
|
13745
|
+
/**
|
|
13746
|
+
* Re-review: an approved comment edited back to pending leaves the public count once. The
|
|
13747
|
+
* author keeps their own +1 through the pending set, so their count does not move.
|
|
13748
|
+
*/
|
|
13749
|
+
const applyCommentReReviewCount = (comment) => {
|
|
13750
|
+
if (!isCountedReference(comment))
|
|
13751
|
+
return;
|
|
13752
|
+
recordPendingAuthoredComment(comment, { publish: false });
|
|
13753
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new DeleteTask(comment.referenceId, comment.commentId));
|
|
13754
|
+
};
|
|
13755
|
+
/** Adds a reply to its cached parent's `children` (and count) once. */
|
|
13756
|
+
const linkCommentToParent = (comment) => {
|
|
13757
|
+
var _a;
|
|
13758
|
+
if (!comment.parentId)
|
|
13759
|
+
return;
|
|
13760
|
+
const parentKey = ['comment', 'get', comment.parentId];
|
|
13761
|
+
const parent = (_a = pullFromCache(parentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13762
|
+
if (!parent || parent.children.includes(comment.commentId))
|
|
13763
|
+
return;
|
|
13764
|
+
pushToCache(parentKey, Object.assign(Object.assign({}, parent), { childrenNumber: parent.childrenNumber + 1, children: [...new Set([...parent.children, comment.commentId])] }));
|
|
13765
|
+
};
|
|
13766
|
+
/** Removes a reply from its cached parent's `children` (and count) once. */
|
|
13767
|
+
const unlinkCommentFromParent = (comment) => {
|
|
13768
|
+
var _a;
|
|
13769
|
+
if (!comment.parentId)
|
|
13770
|
+
return;
|
|
13771
|
+
const parentKey = ['comment', 'get', comment.parentId];
|
|
13772
|
+
const parent = (_a = pullFromCache(parentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
13773
|
+
if (!parent || !parent.children.includes(comment.commentId))
|
|
13774
|
+
return;
|
|
13775
|
+
pushToCache(parentKey, Object.assign(Object.assign({}, parent), { childrenNumber: parent.childrenNumber - 1, children: parent.children.filter(id => id !== comment.commentId) }));
|
|
13776
|
+
};
|
|
13777
|
+
|
|
13778
|
+
/**
|
|
13779
|
+
* The server's list is oldest → newest, so the newest ids are the last ones. Kept unique so the
|
|
13780
|
+
* create response, the local event and the realtime echo cannot each add the same comment.
|
|
13781
|
+
*/
|
|
13782
|
+
const capLatestCommentIds = (commentIds) => [...new Set(commentIds)].slice(-LATEST_COMMENTS_LIMIT);
|
|
13783
|
+
/** A comment belongs in the post preview only while it is cached, not deleted and public. */
|
|
13784
|
+
const isPreviewableComment = (comment) => comment !== undefined && !comment.isDeleted && isCommentApproved(comment);
|
|
13785
|
+
/** The post's preview list after one of the user's own top-level comments is created. */
|
|
13786
|
+
const appendLatestCommentId = (post, commentId) => { var _a; return capLatestCommentIds([...((_a = post.comments) !== null && _a !== void 0 ? _a : []), commentId]); };
|
|
13787
|
+
|
|
12996
13788
|
const postLinkedObject = (post) => {
|
|
12997
13789
|
return shallowClone(post, {
|
|
12998
13790
|
childrenPosts: post.children
|
|
@@ -13016,19 +13808,13 @@ const postLinkedObject = (post) => {
|
|
|
13016
13808
|
get latestComments() {
|
|
13017
13809
|
if (!post.comments)
|
|
13018
13810
|
return [];
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
13027
|
-
if (!commentCached)
|
|
13028
|
-
return null;
|
|
13029
|
-
return commentLinkedObject(commentCached);
|
|
13030
|
-
})
|
|
13031
|
-
.filter(Boolean) || []);
|
|
13811
|
+
// Same rule as the server's own list and as iOS: deleted and non-public comments are
|
|
13812
|
+
// dropped first, then the newest LATEST_COMMENTS_LIMIT remain
|
|
13813
|
+
return post.comments
|
|
13814
|
+
.map(commentId => { var _a; return (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
13815
|
+
.filter(isPreviewableComment)
|
|
13816
|
+
.slice(-LATEST_COMMENTS_LIMIT)
|
|
13817
|
+
.map(commentLinkedObject);
|
|
13032
13818
|
},
|
|
13033
13819
|
get creator() {
|
|
13034
13820
|
// The id is checked for a value, not just for presence: a payload can
|
|
@@ -13041,6 +13827,15 @@ const postLinkedObject = (post) => {
|
|
|
13041
13827
|
return undefined;
|
|
13042
13828
|
return userLinkedObject(cacheData.data);
|
|
13043
13829
|
},
|
|
13830
|
+
getLocalCommentCount(includePending = false) {
|
|
13831
|
+
var _a;
|
|
13832
|
+
const engine = PostCommentCountEngine$1.getInstance();
|
|
13833
|
+
// Before any payload has seeded the engine for this post there is no tracker; the
|
|
13834
|
+
// post's own figure is the best answer then.
|
|
13835
|
+
return engine.hasTracker(post.postId)
|
|
13836
|
+
? engine.getLocalCommentCount(post.postId, includePending)
|
|
13837
|
+
: (_a = post.localCommentCount) !== null && _a !== void 0 ? _a : post.commentsCount;
|
|
13838
|
+
},
|
|
13044
13839
|
get targetCommunity() {
|
|
13045
13840
|
var _a;
|
|
13046
13841
|
if (!post.targetId)
|
|
@@ -13405,7 +14200,8 @@ const messageLinkedObject = (message) => {
|
|
|
13405
14200
|
},
|
|
13406
14201
|
get creator() {
|
|
13407
14202
|
var _a;
|
|
13408
|
-
|
|
14203
|
+
const creator = (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
14204
|
+
return creator ? userLinkedObject(creator) : undefined;
|
|
13409
14205
|
}, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
|
|
13410
14206
|
};
|
|
13411
14207
|
|
|
@@ -14066,6 +14862,22 @@ const eventLinkedObject = (event) => {
|
|
|
14066
14862
|
} });
|
|
14067
14863
|
};
|
|
14068
14864
|
|
|
14865
|
+
const curatedContentTopicLinkedObject = (topic) => {
|
|
14866
|
+
return shallowClone(topic, {
|
|
14867
|
+
analytics: {
|
|
14868
|
+
markAsViewed: () => {
|
|
14869
|
+
AnalyticsEngine$1.getInstance().markCuratedContentWidgetAsViewed(topic.topicId);
|
|
14870
|
+
},
|
|
14871
|
+
markPostAsViewed: (postId) => {
|
|
14872
|
+
AnalyticsEngine$1.getInstance().markCuratedContentPostAsViewed(postId, topic.topicId);
|
|
14873
|
+
},
|
|
14874
|
+
markPostClick: (postId) => {
|
|
14875
|
+
AnalyticsEngine$1.getInstance().markCuratedContentPostAsClicked(postId, topic.topicId);
|
|
14876
|
+
},
|
|
14877
|
+
},
|
|
14878
|
+
});
|
|
14879
|
+
};
|
|
14880
|
+
|
|
14069
14881
|
const LinkedObject = {
|
|
14070
14882
|
file: fileLinkedObject,
|
|
14071
14883
|
ad: adLinkedObject,
|
|
@@ -14090,6 +14902,7 @@ const LinkedObject = {
|
|
|
14090
14902
|
eventResponse: eventResponseLinkedObject,
|
|
14091
14903
|
product: productLinkedObject,
|
|
14092
14904
|
poll: pollLinkedObject,
|
|
14905
|
+
curatedContentTopic: curatedContentTopicLinkedObject,
|
|
14093
14906
|
};
|
|
14094
14907
|
|
|
14095
14908
|
/* begin_public_function
|
|
@@ -15412,9 +16225,9 @@ var AmityUserSearchMatchType;
|
|
|
15412
16225
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
15413
16226
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
15414
16227
|
|
|
15415
|
-
var index$
|
|
16228
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
15416
16229
|
__proto__: null,
|
|
15417
|
-
Relationship: index$
|
|
16230
|
+
Relationship: index$s,
|
|
15418
16231
|
getUserByIds: getUserByIds,
|
|
15419
16232
|
updateUser: updateUser,
|
|
15420
16233
|
flagUser: flagUser,
|
|
@@ -15822,7 +16635,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
15822
16635
|
};
|
|
15823
16636
|
/* end_public_function */
|
|
15824
16637
|
|
|
15825
|
-
var index$
|
|
16638
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
15826
16639
|
__proto__: null,
|
|
15827
16640
|
getFile: getFile,
|
|
15828
16641
|
uploadFile: uploadFile,
|
|
@@ -16015,147 +16828,6 @@ getMessage$1.locally = (messageId) => {
|
|
|
16015
16828
|
};
|
|
16016
16829
|
};
|
|
16017
16830
|
|
|
16018
|
-
class ResetTask {
|
|
16019
|
-
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
16020
|
-
this.postId = postId;
|
|
16021
|
-
this.latestCreatedAt = latestCreatedAt;
|
|
16022
|
-
this.serverCommentCount = serverCommentCount;
|
|
16023
|
-
}
|
|
16024
|
-
}
|
|
16025
|
-
|
|
16026
|
-
// Task to track comment creation
|
|
16027
|
-
class CreateTask {
|
|
16028
|
-
constructor(postId, commentId, createdAt) {
|
|
16029
|
-
this.postId = postId;
|
|
16030
|
-
this.commentId = commentId;
|
|
16031
|
-
this.createdAt = createdAt;
|
|
16032
|
-
}
|
|
16033
|
-
}
|
|
16034
|
-
|
|
16035
|
-
// Task to track comment deletion
|
|
16036
|
-
class DeleteTask {
|
|
16037
|
-
constructor(postId, commentId) {
|
|
16038
|
-
this.postId = postId;
|
|
16039
|
-
this.commentId = commentId;
|
|
16040
|
-
}
|
|
16041
|
-
}
|
|
16042
|
-
|
|
16043
|
-
class CommentChange {
|
|
16044
|
-
constructor(latestCreatedAt, serverCommentCount) {
|
|
16045
|
-
this.latestCommentCreatedAt = latestCreatedAt;
|
|
16046
|
-
this.serverCommentCount = serverCommentCount;
|
|
16047
|
-
this.createdCommentIds = new Set();
|
|
16048
|
-
this.deletedCommentIds = new Set();
|
|
16049
|
-
}
|
|
16050
|
-
}
|
|
16051
|
-
|
|
16052
|
-
class PostCommentCountEngine {
|
|
16053
|
-
constructor() {
|
|
16054
|
-
this.isProcessing = false;
|
|
16055
|
-
this.tasks = [];
|
|
16056
|
-
this.commentChangeTracker = new Map();
|
|
16057
|
-
}
|
|
16058
|
-
queueCommentChangeTask(task) {
|
|
16059
|
-
this.tasks.push(task);
|
|
16060
|
-
if (!this.isProcessing) {
|
|
16061
|
-
this.processCommentChangeTask();
|
|
16062
|
-
}
|
|
16063
|
-
}
|
|
16064
|
-
processCommentChangeTask() {
|
|
16065
|
-
if (this.isProcessing) {
|
|
16066
|
-
return;
|
|
16067
|
-
}
|
|
16068
|
-
this.isProcessing = true;
|
|
16069
|
-
if (this.tasks.length === 0) {
|
|
16070
|
-
this.isProcessing = false;
|
|
16071
|
-
return;
|
|
16072
|
-
}
|
|
16073
|
-
// Process in capped batches, coalescing updates
|
|
16074
|
-
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
16075
|
-
const modifiedPostIds = new Set();
|
|
16076
|
-
batch.forEach(task => {
|
|
16077
|
-
let modified = false;
|
|
16078
|
-
if (task instanceof ResetTask) {
|
|
16079
|
-
modified = this.processResetTaskInternal(task);
|
|
16080
|
-
}
|
|
16081
|
-
else if (task instanceof CreateTask) {
|
|
16082
|
-
modified = this.processCreateTaskInternal(task);
|
|
16083
|
-
}
|
|
16084
|
-
else if (task instanceof DeleteTask) {
|
|
16085
|
-
modified = this.processDeleteTaskInternal(task);
|
|
16086
|
-
}
|
|
16087
|
-
if (modified) {
|
|
16088
|
-
modifiedPostIds.add(task.postId);
|
|
16089
|
-
}
|
|
16090
|
-
});
|
|
16091
|
-
// Publish one update per modified post
|
|
16092
|
-
modifiedPostIds.forEach(postId => {
|
|
16093
|
-
const count = this.computeCommentCount(postId);
|
|
16094
|
-
PostCommentCountEngine.publishUpdate(postId, count);
|
|
16095
|
-
});
|
|
16096
|
-
this.isProcessing = false;
|
|
16097
|
-
// Recurse if more tasks remain
|
|
16098
|
-
if (this.tasks.length > 0) {
|
|
16099
|
-
this.processCommentChangeTask();
|
|
16100
|
-
}
|
|
16101
|
-
}
|
|
16102
|
-
processResetTaskInternal(task) {
|
|
16103
|
-
// Always creates/overwrites tracker
|
|
16104
|
-
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
16105
|
-
return true;
|
|
16106
|
-
}
|
|
16107
|
-
processCreateTaskInternal(task) {
|
|
16108
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
16109
|
-
if (!tracker)
|
|
16110
|
-
return false; // No tracker, skip
|
|
16111
|
-
if (tracker.createdCommentIds.has(task.commentId))
|
|
16112
|
-
return false; // Deduplication
|
|
16113
|
-
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
16114
|
-
return false; // Timestamp filtering
|
|
16115
|
-
tracker.createdCommentIds.add(task.commentId);
|
|
16116
|
-
return true;
|
|
16117
|
-
}
|
|
16118
|
-
processDeleteTaskInternal(task) {
|
|
16119
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
16120
|
-
if (!tracker)
|
|
16121
|
-
return false; // No tracker, skip
|
|
16122
|
-
if (tracker.deletedCommentIds.has(task.commentId))
|
|
16123
|
-
return false; // Deduplication
|
|
16124
|
-
tracker.deletedCommentIds.add(task.commentId);
|
|
16125
|
-
return true;
|
|
16126
|
-
}
|
|
16127
|
-
computeCommentCount(postId) {
|
|
16128
|
-
const tracker = this.commentChangeTracker.get(postId);
|
|
16129
|
-
if (!tracker)
|
|
16130
|
-
return 0;
|
|
16131
|
-
const count = tracker.serverCommentCount + tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
16132
|
-
return Math.max(0, count);
|
|
16133
|
-
}
|
|
16134
|
-
static publishUpdate(postId, newCount) {
|
|
16135
|
-
var _a;
|
|
16136
|
-
const queryKey = ['post', 'get', postId];
|
|
16137
|
-
mergeInCache(queryKey, {
|
|
16138
|
-
localCommentCount: newCount,
|
|
16139
|
-
});
|
|
16140
|
-
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16141
|
-
if (!postPayload)
|
|
16142
|
-
return;
|
|
16143
|
-
fireEvent('local.post.updated', {
|
|
16144
|
-
posts: [postPayload],
|
|
16145
|
-
});
|
|
16146
|
-
}
|
|
16147
|
-
}
|
|
16148
|
-
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
16149
|
-
let instance;
|
|
16150
|
-
var PostCommentCountEngine$1 = {
|
|
16151
|
-
getInstance: () => {
|
|
16152
|
-
if (!instance) {
|
|
16153
|
-
instance = new PostCommentCountEngine();
|
|
16154
|
-
}
|
|
16155
|
-
return instance;
|
|
16156
|
-
},
|
|
16157
|
-
};
|
|
16158
|
-
|
|
16159
16831
|
const updateStreamReferences = (streams, streamId, postId) => {
|
|
16160
16832
|
if (!streamId)
|
|
16161
16833
|
return streams;
|
|
@@ -16175,7 +16847,7 @@ const preparePostPayload = (payload) => {
|
|
|
16175
16847
|
let mappedNewStream = [];
|
|
16176
16848
|
// feed type
|
|
16177
16849
|
const posts = postsData.map(post => {
|
|
16178
|
-
var _a, _b, _c
|
|
16850
|
+
var _a, _b, _c;
|
|
16179
16851
|
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
16180
16852
|
const childPosts = payload.postChildren.filter(children => children.parentPostId === post.postId);
|
|
16181
16853
|
if (childPosts.length > 0 && isAmityLivestreamPost(childPosts[0])) {
|
|
@@ -16194,7 +16866,11 @@ const preparePostPayload = (payload) => {
|
|
|
16194
16866
|
// Queue ResetTask for this post
|
|
16195
16867
|
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ResetTask(post.postId, latestCreatedAt, (_c = post.commentsCount) !== null && _c !== void 0 ? _c : 0));
|
|
16196
16868
|
return Object.assign(Object.assign({}, post), { childPosts,
|
|
16197
|
-
feedType,
|
|
16869
|
+
feedType,
|
|
16870
|
+
// The ResetTask above has just seeded the engine, so this is the server figure plus the
|
|
16871
|
+
// author's own pending comments. Reading `post.commentsCount` here instead would overwrite
|
|
16872
|
+
// that +1 in the cache on every refresh, since the ingest that follows merges this object.
|
|
16873
|
+
localCommentCount: PostCommentCountEngine$1.getInstance().getLocalCommentCount(post.postId, true), pinnedProductId: post === null || post === void 0 ? void 0 : post.pinnedProductId });
|
|
16198
16874
|
});
|
|
16199
16875
|
return Object.assign(Object.assign({}, postPayload), { postChildren, videoStreamings: mappedNewStream, posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
16200
16876
|
};
|
|
@@ -16947,62 +17623,67 @@ const onPostReactionRemoved = (callback) => {
|
|
|
16947
17623
|
return createEventSubscriber(client, 'post.removeReaction', 'post.removeReaction', filter);
|
|
16948
17624
|
};
|
|
16949
17625
|
|
|
17626
|
+
/**
|
|
17627
|
+
* `comment.created` fires while a comment is still pending, so delivery is not visibility. The
|
|
17628
|
+
* two side effects that make a comment public — the parent link that feeds the reply list and
|
|
17629
|
+
* the comment-count task — are gated here; `comment.approved` is the only reveal signal, and a
|
|
17630
|
+
* decline arrives as `comment.deleted`.
|
|
17631
|
+
*/
|
|
17632
|
+
const applyApprovalSideEffects = (event, comment, previous) => {
|
|
17633
|
+
switch (event) {
|
|
17634
|
+
case 'comment.created':
|
|
17635
|
+
if (isCommentPending(comment)) {
|
|
17636
|
+
recordPendingAuthoredComment(comment);
|
|
17637
|
+
}
|
|
17638
|
+
else {
|
|
17639
|
+
linkCommentToParent(comment);
|
|
17640
|
+
applyCommentCreatedCount(comment);
|
|
17641
|
+
}
|
|
17642
|
+
break;
|
|
17643
|
+
case 'comment.approved':
|
|
17644
|
+
linkCommentToParent(comment);
|
|
17645
|
+
applyCommentApprovedCount(comment);
|
|
17646
|
+
break;
|
|
17647
|
+
case 'comment.updated':
|
|
17648
|
+
// An effective edit in a gated community sends an approved comment back for review
|
|
17649
|
+
if (isCommentPending(comment) && previous && isCommentApproved(previous)) {
|
|
17650
|
+
unlinkCommentFromParent(comment);
|
|
17651
|
+
applyCommentReReviewCount(comment);
|
|
17652
|
+
}
|
|
17653
|
+
break;
|
|
17654
|
+
case 'comment.deleted':
|
|
17655
|
+
unlinkCommentFromParent(comment);
|
|
17656
|
+
// A pending comment was never counted, so its deletion (or decline) moves no count
|
|
17657
|
+
if (previous && isCommentPending(previous))
|
|
17658
|
+
releasePendingAuthoredComment(comment);
|
|
17659
|
+
break;
|
|
17660
|
+
}
|
|
17661
|
+
};
|
|
16950
17662
|
const createCommentEventSubscriber = (event, callback) => {
|
|
16951
17663
|
const client = getActiveClient();
|
|
16952
17664
|
const filter = (payload) => {
|
|
16953
|
-
var _a;
|
|
17665
|
+
var _a, _b;
|
|
16954
17666
|
if (!client.cache) {
|
|
16955
17667
|
// TODO: here we are missing specific properties here!
|
|
16956
17668
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
16957
17669
|
}
|
|
16958
17670
|
else {
|
|
16959
|
-
const
|
|
17671
|
+
const flagged = ['comment.flagged', 'comment.unflagged'].includes(event)
|
|
16960
17672
|
? prepareCommentFromFlaggedEvent(payload)
|
|
16961
17673
|
: payload;
|
|
16962
|
-
//
|
|
16963
|
-
|
|
17674
|
+
// Resolve `approvalStatus` before the merge: an absent value means approved and has to
|
|
17675
|
+
// overwrite a cached `pending`, which a plain merge would leave in place.
|
|
17676
|
+
const processed = prepareCommentPayload(flagged);
|
|
16964
17677
|
const { comments } = processed;
|
|
16965
17678
|
if (comments.length > 0) {
|
|
16966
|
-
const
|
|
16967
|
-
|
|
16968
|
-
|
|
16969
|
-
|
|
16970
|
-
|
|
16971
|
-
|
|
16972
|
-
if (comments[0].parentId) {
|
|
16973
|
-
const parentComment = pullFromCache([
|
|
16974
|
-
'comment',
|
|
16975
|
-
'get',
|
|
16976
|
-
comments[0].parentId,
|
|
16977
|
-
]);
|
|
16978
|
-
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
16979
|
-
// Skip to update parent childComment if current comment already exists
|
|
16980
|
-
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
16981
|
-
pushToCache(['comment', 'get', comments[0].parentId], Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] }));
|
|
16982
|
-
}
|
|
16983
|
-
}
|
|
16984
|
-
}
|
|
16985
|
-
}
|
|
17679
|
+
const commentKey = ['comment', 'get', comments[0].commentId];
|
|
17680
|
+
const previous = (_a = pullFromCache(commentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17681
|
+
// NOTE: The event data should be merge with existing cache rather than replace it
|
|
17682
|
+
ingestInCache(processed, undefined, false);
|
|
17683
|
+
const comment = pullFromCache(commentKey);
|
|
17684
|
+
applyApprovalSideEffects(event, comment.data, previous);
|
|
16986
17685
|
if (['comment.deleted'].includes(event)) {
|
|
16987
|
-
|
|
16988
|
-
const parentComment = pullFromCache([
|
|
16989
|
-
'comment',
|
|
16990
|
-
'get',
|
|
16991
|
-
comments[0].parentId,
|
|
16992
|
-
]);
|
|
16993
|
-
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
16994
|
-
// Remove deleted comment in parent childComment if still exists
|
|
16995
|
-
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
16996
|
-
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
16997
|
-
...new Set([
|
|
16998
|
-
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
16999
|
-
]),
|
|
17000
|
-
] });
|
|
17001
|
-
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
17002
|
-
}
|
|
17003
|
-
}
|
|
17004
|
-
}
|
|
17005
|
-
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17686
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17006
17687
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17007
17688
|
}
|
|
17008
17689
|
callback(LinkedObject.comment(comment.data));
|
|
@@ -17014,13 +17695,13 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
17014
17695
|
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
17015
17696
|
const client = getActiveClient();
|
|
17016
17697
|
const filter = (payload) => {
|
|
17017
|
-
var _a, _b, _c, _d
|
|
17698
|
+
var _a, _b, _c, _d;
|
|
17018
17699
|
if (!client.cache) {
|
|
17019
17700
|
// TODO: here we are missing specific properties here!
|
|
17020
17701
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
17021
17702
|
}
|
|
17022
17703
|
else {
|
|
17023
|
-
const processed = payload;
|
|
17704
|
+
const processed = prepareCommentPayload(payload);
|
|
17024
17705
|
ingestInCache(processed);
|
|
17025
17706
|
const { comments } = processed;
|
|
17026
17707
|
if (comments.length > 0) {
|
|
@@ -17029,7 +17710,9 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17029
17710
|
'get',
|
|
17030
17711
|
comments[0].commentId,
|
|
17031
17712
|
]);
|
|
17032
|
-
|
|
17713
|
+
// A pending comment is persisted for its author but never linked into the public
|
|
17714
|
+
// surfaces (parent reply list, post comment list)
|
|
17715
|
+
if (['local.comment.created'].includes(event) && isCommentApproved(comments[0])) {
|
|
17033
17716
|
if (comments[0].parentId) {
|
|
17034
17717
|
const parentComment = pullFromCache([
|
|
17035
17718
|
'comment',
|
|
@@ -17058,11 +17741,11 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17058
17741
|
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
17059
17742
|
const postCache = (_a = pullFromCache(postCacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17060
17743
|
if (postCache) {
|
|
17061
|
-
const updatedPostCache = Object.assign(Object.assign({}, postCache), { comments:
|
|
17744
|
+
const updatedPostCache = Object.assign(Object.assign({}, postCache), { comments: appendLatestCommentId(postCache, comments[0].commentId) });
|
|
17062
17745
|
pushToCache(postCacheKey, updatedPostCache);
|
|
17063
17746
|
}
|
|
17064
17747
|
}
|
|
17065
|
-
const queries = (
|
|
17748
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17066
17749
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17067
17750
|
}
|
|
17068
17751
|
if (['local.comment.deleted'].includes(event)) {
|
|
@@ -17096,13 +17779,13 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17096
17779
|
}
|
|
17097
17780
|
else {
|
|
17098
17781
|
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
17099
|
-
const postCache = (
|
|
17782
|
+
const postCache = (_c = pullFromCache(postCacheKey)) === null || _c === void 0 ? void 0 : _c.data;
|
|
17100
17783
|
if (postCache) {
|
|
17101
17784
|
const updatedPost = Object.assign(Object.assign({}, postCache), { comments: postCache === null || postCache === void 0 ? void 0 : postCache.comments.filter(commentId => { var _a; return commentId !== ((_a = comments[0]) === null || _a === void 0 ? void 0 : _a.commentId); }) });
|
|
17102
17785
|
pushToCache(postCacheKey, updatedPost);
|
|
17103
17786
|
}
|
|
17104
17787
|
}
|
|
17105
|
-
const queries = (
|
|
17788
|
+
const queries = (_d = queryCache(['comment', 'query'])) === null || _d === void 0 ? void 0 : _d.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17106
17789
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17107
17790
|
}
|
|
17108
17791
|
callback(LinkedObject.comment(comment.data));
|
|
@@ -17163,6 +17846,23 @@ const onCommentUpdated = (callback) => createCommentEventSubscriber('comment.upd
|
|
|
17163
17846
|
*/
|
|
17164
17847
|
const onCommentDeleted = (callback) => createCommentEventSubscriber('comment.deleted', callback);
|
|
17165
17848
|
|
|
17849
|
+
/**
|
|
17850
|
+
* ```js
|
|
17851
|
+
* import { onCommentApproved } from '@amityco/ts-sdk'
|
|
17852
|
+
* const dispose = onCommentApproved(comment => {
|
|
17853
|
+
* // ...
|
|
17854
|
+
* })
|
|
17855
|
+
* ```
|
|
17856
|
+
*
|
|
17857
|
+
* Fired when a {@link Amity.InternalComment} held for review has been approved
|
|
17858
|
+
*
|
|
17859
|
+
* @param callback The function to call when the event was fired
|
|
17860
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
17861
|
+
*
|
|
17862
|
+
* @category Comment Events
|
|
17863
|
+
*/
|
|
17864
|
+
const onCommentApproved = (callback) => createCommentEventSubscriber('comment.approved', callback);
|
|
17865
|
+
|
|
17166
17866
|
/**
|
|
17167
17867
|
* ```js
|
|
17168
17868
|
* import { onCommentFlagged } from '@amityco/ts-sdk'
|
|
@@ -17795,7 +18495,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
17795
18495
|
};
|
|
17796
18496
|
/* end_public_function */
|
|
17797
18497
|
|
|
17798
|
-
var index$
|
|
18498
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
17799
18499
|
__proto__: null,
|
|
17800
18500
|
addReaction: addReaction,
|
|
17801
18501
|
removeReaction: removeReaction,
|
|
@@ -17806,17 +18506,6 @@ var index$o = /*#__PURE__*/Object.freeze({
|
|
|
17806
18506
|
getReactions: getReactions$1
|
|
17807
18507
|
});
|
|
17808
18508
|
|
|
17809
|
-
function prepareCommentPayload(commentPayload) {
|
|
17810
|
-
const { comments } = commentPayload;
|
|
17811
|
-
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
17812
|
-
if (comment.hasOwnProperty('myReactions'))
|
|
17813
|
-
return comment;
|
|
17814
|
-
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
17815
|
-
// We need to put it with an empty array manually to make it show up in client side
|
|
17816
|
-
return Object.assign({ myReactions: [] }, comment);
|
|
17817
|
-
}) });
|
|
17818
|
-
}
|
|
17819
|
-
|
|
17820
18509
|
const createMessageReport = async ({ client, referenceId, }) => {
|
|
17821
18510
|
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
17822
18511
|
if (client.cache) {
|
|
@@ -18280,20 +18969,20 @@ const getArchivedChannelIds = async () => {
|
|
|
18280
18969
|
|
|
18281
18970
|
/**
|
|
18282
18971
|
* ```js
|
|
18283
|
-
* import {
|
|
18284
|
-
* const dispose =
|
|
18972
|
+
* import { onMessageDeleted } from '@amityco/ts-sdk'
|
|
18973
|
+
* const dispose = onMessageDeleted(message => {
|
|
18285
18974
|
* // ...
|
|
18286
18975
|
* })
|
|
18287
18976
|
* ```
|
|
18288
18977
|
*
|
|
18289
|
-
* Fired when an {@link Amity.Message}
|
|
18978
|
+
* Fired when an {@link Amity.Message} was deleted
|
|
18290
18979
|
*
|
|
18291
18980
|
* @param callback The function to call when the event was fired
|
|
18292
18981
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18293
18982
|
*
|
|
18294
18983
|
* @category Message Events
|
|
18295
18984
|
*/
|
|
18296
|
-
const
|
|
18985
|
+
const onMessageDeleted = (callback) => {
|
|
18297
18986
|
const client = getActiveClient();
|
|
18298
18987
|
const filter = async (rawPayload) => {
|
|
18299
18988
|
const payload = await prepareMessagePayload(rawPayload);
|
|
@@ -18301,30 +18990,48 @@ const onMessageUpdated = (callback) => {
|
|
|
18301
18990
|
callback(payload.messages[0]);
|
|
18302
18991
|
};
|
|
18303
18992
|
const disposers = [
|
|
18304
|
-
createEventSubscriber(client, '
|
|
18305
|
-
createEventSubscriber(client, '
|
|
18993
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
18994
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
18306
18995
|
];
|
|
18307
18996
|
return () => {
|
|
18308
18997
|
disposers.forEach(fn => fn());
|
|
18309
18998
|
};
|
|
18310
18999
|
};
|
|
18311
19000
|
|
|
19001
|
+
/**
|
|
19002
|
+
* Defensive clear of `channel.pinnedMessage` when the pinned message itself is deleted.
|
|
19003
|
+
*
|
|
19004
|
+
* The server also emits `channel.messageUnpinned` in this case, but realtime events are
|
|
19005
|
+
* fire-and-forget and their order is not guaranteed. Clearing on `message.deleted`
|
|
19006
|
+
* (MQTT or local) makes the banner disappear even if the unpin event is lost; the
|
|
19007
|
+
* server's own `messageUnpinned` then becomes a no-op.
|
|
19008
|
+
*
|
|
19009
|
+
* Internal — wired into the `getChannel` live object; not exported publicly.
|
|
19010
|
+
*/
|
|
19011
|
+
const onChannelPinnedMessageDeleted = (callback) => onMessageDeleted(message => {
|
|
19012
|
+
var _a;
|
|
19013
|
+
const channel = findCachedChannelByAnyId(message.channelId);
|
|
19014
|
+
if (!channel || ((_a = channel.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) !== message.messageId)
|
|
19015
|
+
return;
|
|
19016
|
+
callback(updatePinnedMessageCache(channel, null));
|
|
19017
|
+
});
|
|
19018
|
+
|
|
18312
19019
|
/**
|
|
18313
19020
|
* ```js
|
|
18314
|
-
* import {
|
|
18315
|
-
* const dispose =
|
|
19021
|
+
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
19022
|
+
* const dispose = onMessageUpdated(message => {
|
|
18316
19023
|
* // ...
|
|
18317
19024
|
* })
|
|
18318
19025
|
* ```
|
|
18319
19026
|
*
|
|
18320
|
-
* Fired when an {@link Amity.Message}
|
|
19027
|
+
* Fired when an {@link Amity.Message} has been updated
|
|
18321
19028
|
*
|
|
18322
19029
|
* @param callback The function to call when the event was fired
|
|
18323
19030
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18324
19031
|
*
|
|
18325
19032
|
* @category Message Events
|
|
18326
19033
|
*/
|
|
18327
|
-
const
|
|
19034
|
+
const onMessageUpdated = (callback) => {
|
|
18328
19035
|
const client = getActiveClient();
|
|
18329
19036
|
const filter = async (rawPayload) => {
|
|
18330
19037
|
const payload = await prepareMessagePayload(rawPayload);
|
|
@@ -18332,8 +19039,8 @@ const onMessageDeleted = (callback) => {
|
|
|
18332
19039
|
callback(payload.messages[0]);
|
|
18333
19040
|
};
|
|
18334
19041
|
const disposers = [
|
|
18335
|
-
createEventSubscriber(client, '
|
|
18336
|
-
createEventSubscriber(client, '
|
|
19042
|
+
createEventSubscriber(client, 'onMessageUpdated', 'message.updated', filter),
|
|
19043
|
+
createEventSubscriber(client, 'onMessageUpdated', 'local.message.updated', payload => callback(payload.messages[0])),
|
|
18337
19044
|
];
|
|
18338
19045
|
return () => {
|
|
18339
19046
|
disposers.forEach(fn => fn());
|
|
@@ -18914,6 +19621,132 @@ softDeleteMessage.optimistically = (messageId) => {
|
|
|
18914
19621
|
};
|
|
18915
19622
|
/* end_public_function */
|
|
18916
19623
|
|
|
19624
|
+
/**
|
|
19625
|
+
* Fire-and-forget refresh of `channelUsers[...].permissions` for the channel a
|
|
19626
|
+
* message belongs to. Used by `pinMessage` / `unpinMessage` on `403` so the next
|
|
19627
|
+
* `hasPermission(PIN_MESSAGE).channel(channelId)` reflects a revoked role
|
|
19628
|
+
* ([`pinMessage` REQ-010](../../@types/../..) / [`unpinMessage` REQ-008](../../@types/../..)).
|
|
19629
|
+
*
|
|
19630
|
+
* The API only receives a `messageId`, so the channel is resolved through the
|
|
19631
|
+
* local cache: first the message row, then any cached channel whose current pin
|
|
19632
|
+
* is that message. When nothing matches the refresh is skipped — the next
|
|
19633
|
+
* channel read picks up the fresh permissions anyway.
|
|
19634
|
+
*/
|
|
19635
|
+
const refreshChannelPermissionsForMessage = (messageId) => {
|
|
19636
|
+
var _a, _b, _c;
|
|
19637
|
+
const cachedMessage = (_a = getMessage$1.locally(messageId)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19638
|
+
let channelId = cachedMessage === null || cachedMessage === void 0 ? void 0 : cachedMessage.channelId;
|
|
19639
|
+
if (!channelId) {
|
|
19640
|
+
channelId = (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => { var _a; return ((_a = data.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) === messageId; })) === null || _c === void 0 ? void 0 : _c.data.channelId;
|
|
19641
|
+
}
|
|
19642
|
+
if (!channelId)
|
|
19643
|
+
return;
|
|
19644
|
+
getChannel$1(channelId).catch(() => {
|
|
19645
|
+
/* silent per spec; UIKit renders no error toast */
|
|
19646
|
+
});
|
|
19647
|
+
};
|
|
19648
|
+
|
|
19649
|
+
/* begin_public_function
|
|
19650
|
+
id: message.pin
|
|
19651
|
+
*/
|
|
19652
|
+
/**
|
|
19653
|
+
* ```js
|
|
19654
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
19655
|
+
* const channel = await MessageRepository.pinMessage(messageId)
|
|
19656
|
+
* console.log(channel.pinnedMessage)
|
|
19657
|
+
* ```
|
|
19658
|
+
*
|
|
19659
|
+
* Pins a {@link Amity.Message} in its livestream (`live`) channel. A channel holds at
|
|
19660
|
+
* most one pinned message: pinning a different message replaces the current pin in a
|
|
19661
|
+
* single step — no unpin is needed first. Pinning the message that is already pinned is
|
|
19662
|
+
* rejected by the server (400).
|
|
19663
|
+
*
|
|
19664
|
+
* The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
|
|
19665
|
+
* `ModerateChannel`). The server also rejects pinning a deleted message, a message whose
|
|
19666
|
+
* author is banned from the channel or globally banned, and pinning in any channel type
|
|
19667
|
+
* other than `live`. On any error the pin state is left unchanged.
|
|
19668
|
+
*
|
|
19669
|
+
* The response is the affected channel; it is ingested into cache and fires
|
|
19670
|
+
* `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
|
|
19671
|
+
* waiting for the `channel.messagePinned` realtime event.
|
|
19672
|
+
*
|
|
19673
|
+
* @param messageId the **internal** ID of the {@link Amity.Message} to pin
|
|
19674
|
+
* @returns the updated {@link Amity.Channel}, with `pinnedMessage` set
|
|
19675
|
+
*
|
|
19676
|
+
* @category Message API
|
|
19677
|
+
* @async
|
|
19678
|
+
*/
|
|
19679
|
+
const pinMessage = async (messageId) => {
|
|
19680
|
+
const client = getActiveClient();
|
|
19681
|
+
client.log('message/pinMessage', messageId);
|
|
19682
|
+
let payload;
|
|
19683
|
+
try {
|
|
19684
|
+
({ data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
|
|
19685
|
+
}
|
|
19686
|
+
catch (error) {
|
|
19687
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
19688
|
+
refreshChannelPermissionsForMessage(messageId);
|
|
19689
|
+
}
|
|
19690
|
+
throw error;
|
|
19691
|
+
}
|
|
19692
|
+
const data = await prepareChannelPayload(payload);
|
|
19693
|
+
if (client.cache)
|
|
19694
|
+
ingestInCache(data);
|
|
19695
|
+
fireEvent('local.channel.updated', data);
|
|
19696
|
+
return constructChannelObject(data.channels[0]);
|
|
19697
|
+
};
|
|
19698
|
+
/* end_public_function */
|
|
19699
|
+
|
|
19700
|
+
/* begin_public_function
|
|
19701
|
+
id: message.unpin
|
|
19702
|
+
*/
|
|
19703
|
+
/**
|
|
19704
|
+
* ```js
|
|
19705
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
19706
|
+
* const channel = await MessageRepository.unpinMessage(messageId)
|
|
19707
|
+
* console.log(channel.pinnedMessage) // null
|
|
19708
|
+
* ```
|
|
19709
|
+
*
|
|
19710
|
+
* Removes the pin from a {@link Amity.Message}. `messageId` must be the message that is
|
|
19711
|
+
* **currently** pinned in its channel; otherwise the server answers 400 — this is
|
|
19712
|
+
* deliberate, so a stale client cannot clear a pin that someone else has since replaced.
|
|
19713
|
+
* On that error, re-read the channel (or rely on the `channel.messagePinned` event) to
|
|
19714
|
+
* get the current pin.
|
|
19715
|
+
*
|
|
19716
|
+
* The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
|
|
19717
|
+
* `ModerateChannel`). Unpinning is allowed regardless of channel type and stream state.
|
|
19718
|
+
*
|
|
19719
|
+
* The response is the affected channel; it is ingested into cache and fires
|
|
19720
|
+
* `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
|
|
19721
|
+
* waiting for the `channel.messageUnpinned` realtime event.
|
|
19722
|
+
*
|
|
19723
|
+
* @param messageId the **internal** ID of the currently pinned {@link Amity.Message}
|
|
19724
|
+
* @returns the updated {@link Amity.Channel}, with `pinnedMessage` cleared
|
|
19725
|
+
*
|
|
19726
|
+
* @category Message API
|
|
19727
|
+
* @async
|
|
19728
|
+
*/
|
|
19729
|
+
const unpinMessage = async (messageId) => {
|
|
19730
|
+
const client = getActiveClient();
|
|
19731
|
+
client.log('message/unpinMessage', messageId);
|
|
19732
|
+
let payload;
|
|
19733
|
+
try {
|
|
19734
|
+
({ data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
|
|
19735
|
+
}
|
|
19736
|
+
catch (error) {
|
|
19737
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
19738
|
+
refreshChannelPermissionsForMessage(messageId);
|
|
19739
|
+
}
|
|
19740
|
+
throw error;
|
|
19741
|
+
}
|
|
19742
|
+
const data = await prepareChannelPayload(payload);
|
|
19743
|
+
if (client.cache)
|
|
19744
|
+
ingestInCache(data);
|
|
19745
|
+
fireEvent('local.channel.updated', data);
|
|
19746
|
+
return constructChannelObject(data.channels[0]);
|
|
19747
|
+
};
|
|
19748
|
+
/* end_public_function */
|
|
19749
|
+
|
|
18917
19750
|
/**
|
|
18918
19751
|
* ```js
|
|
18919
19752
|
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
@@ -19810,13 +20643,15 @@ const searchMessage = (params, callback) => {
|
|
|
19810
20643
|
};
|
|
19811
20644
|
/* end_public_function */
|
|
19812
20645
|
|
|
19813
|
-
var index$
|
|
20646
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
19814
20647
|
__proto__: null,
|
|
19815
20648
|
createMessage: createMessage,
|
|
19816
20649
|
updateMessage: updateMessage,
|
|
19817
20650
|
editMessage: editMessage,
|
|
19818
20651
|
deleteMessage: deleteMessage,
|
|
19819
20652
|
softDeleteMessage: softDeleteMessage,
|
|
20653
|
+
pinMessage: pinMessage,
|
|
20654
|
+
unpinMessage: unpinMessage,
|
|
19820
20655
|
markAsDelivered: markAsDelivered,
|
|
19821
20656
|
getReadUsers: getReadUsers,
|
|
19822
20657
|
getDeliveredUsers: getDeliveredUsers,
|
|
@@ -20346,7 +21181,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
20346
21181
|
};
|
|
20347
21182
|
/* end_public_function */
|
|
20348
21183
|
|
|
20349
|
-
var index$
|
|
21184
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
20350
21185
|
__proto__: null,
|
|
20351
21186
|
getSubChannelByIds: getSubChannels$1,
|
|
20352
21187
|
createSubChannel: createSubChannel,
|
|
@@ -20453,7 +21288,12 @@ const getChannel = (channelId, callback) => {
|
|
|
20453
21288
|
onChannelMemberRemoved,
|
|
20454
21289
|
onChannelMemberBanned,
|
|
20455
21290
|
onChannelMemberUnbanned,
|
|
21291
|
+
onChannelMemberRoleAdded,
|
|
21292
|
+
onChannelMemberRoleRemoved,
|
|
20456
21293
|
onChannelSetMuted,
|
|
21294
|
+
onChannelMessagePinned,
|
|
21295
|
+
onChannelMessageUnpinned,
|
|
21296
|
+
onChannelPinnedMessageDeleted,
|
|
20457
21297
|
convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
20458
21298
|
convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
|
|
20459
21299
|
convertEventPayload((callback) => {
|
|
@@ -21079,6 +21919,14 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21079
21919
|
return;
|
|
21080
21920
|
if (messagePreviewSetting ===
|
|
21081
21921
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
21922
|
+
// The replacement preview the server sends back is an OLDER
|
|
21923
|
+
// message than the one just deleted, and
|
|
21924
|
+
// updateChannelMessagePreviewCache drops any preview that is not
|
|
21925
|
+
// newer than what is cached — so without clearing the entry
|
|
21926
|
+
// first the refetch is a no-op and the channel keeps showing the
|
|
21927
|
+
// deleted message. getChannel's own live object already does
|
|
21928
|
+
// this; the live collections did not.
|
|
21929
|
+
dropFromCache(['messagePreviewChannel', 'get', message.channelId]);
|
|
21082
21930
|
await getChannel$1(message.channelId);
|
|
21083
21931
|
}
|
|
21084
21932
|
callback(message);
|
|
@@ -21803,6 +22651,14 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21803
22651
|
return;
|
|
21804
22652
|
if (messagePreviewSetting ===
|
|
21805
22653
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
22654
|
+
// The replacement preview the server sends back is an OLDER
|
|
22655
|
+
// message than the one just deleted, and
|
|
22656
|
+
// updateChannelMessagePreviewCache drops any preview that is not
|
|
22657
|
+
// newer than what is cached — so without clearing the entry
|
|
22658
|
+
// first the refetch is a no-op and the channel keeps showing the
|
|
22659
|
+
// deleted message. getChannel's own live object already does
|
|
22660
|
+
// this; the live collections did not.
|
|
22661
|
+
dropFromCache(['messagePreviewChannel', 'get', message.channelId]);
|
|
21806
22662
|
await getChannel$1(message.channelId);
|
|
21807
22663
|
}
|
|
21808
22664
|
callback(message);
|
|
@@ -22297,7 +23153,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
22297
23153
|
};
|
|
22298
23154
|
/* end_public_function */
|
|
22299
23155
|
|
|
22300
|
-
var index$
|
|
23156
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
22301
23157
|
__proto__: null,
|
|
22302
23158
|
addMembers: addMembers$1,
|
|
22303
23159
|
removeMembers: removeMembers$1,
|
|
@@ -22519,7 +23375,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22519
23375
|
};
|
|
22520
23376
|
/* end_public_function */
|
|
22521
23377
|
|
|
22522
|
-
var index$
|
|
23378
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
22523
23379
|
__proto__: null,
|
|
22524
23380
|
addRole: addRole,
|
|
22525
23381
|
removeRole: removeRole,
|
|
@@ -22529,10 +23385,10 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
22529
23385
|
unmuteMembers: unmuteMembers
|
|
22530
23386
|
});
|
|
22531
23387
|
|
|
22532
|
-
var index$
|
|
23388
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
22533
23389
|
__proto__: null,
|
|
22534
|
-
Membership: index$
|
|
22535
|
-
Moderation: index$
|
|
23390
|
+
Membership: index$m,
|
|
23391
|
+
Moderation: index$l,
|
|
22536
23392
|
getChannelByIds: getChannelByIds$1,
|
|
22537
23393
|
createChannel: createChannel,
|
|
22538
23394
|
updateChannel: updateChannel,
|
|
@@ -22550,6 +23406,8 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22550
23406
|
onChannelJoined: onChannelJoined,
|
|
22551
23407
|
onChannelLeft: onChannelLeft,
|
|
22552
23408
|
onChannelSetMuted: onChannelSetMuted,
|
|
23409
|
+
onChannelMessagePinned: onChannelMessagePinned,
|
|
23410
|
+
onChannelMessageUnpinned: onChannelMessageUnpinned,
|
|
22553
23411
|
onChannelMemberAdded: onChannelMemberAdded,
|
|
22554
23412
|
onChannelMemberRemoved: onChannelMemberRemoved,
|
|
22555
23413
|
onChannelMemberBanned: onChannelMemberBanned,
|
|
@@ -22567,7 +23425,11 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22567
23425
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22568
23426
|
convertFromRaw: convertFromRaw,
|
|
22569
23427
|
preUpdateChannelCache: preUpdateChannelCache,
|
|
22570
|
-
prepareChannelPayload: prepareChannelPayload
|
|
23428
|
+
prepareChannelPayload: prepareChannelPayload,
|
|
23429
|
+
findCachedChannelByAnyId: findCachedChannelByAnyId,
|
|
23430
|
+
findCachedChannelForPin: findCachedChannelForPin,
|
|
23431
|
+
updatePinnedMessageCache: updatePinnedMessageCache,
|
|
23432
|
+
applyChannelRolePayload: applyChannelRolePayload
|
|
22571
23433
|
});
|
|
22572
23434
|
|
|
22573
23435
|
const saveCommunityUsers = (communities, communityUsers) => {
|
|
@@ -23961,7 +24823,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
23961
24823
|
};
|
|
23962
24824
|
/* end_public_function */
|
|
23963
24825
|
|
|
23964
|
-
var index$
|
|
24826
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
23965
24827
|
__proto__: null,
|
|
23966
24828
|
addMembers: addMembers,
|
|
23967
24829
|
removeMembers: removeMembers,
|
|
@@ -25212,7 +26074,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
25212
26074
|
};
|
|
25213
26075
|
/* end_public_function */
|
|
25214
26076
|
|
|
25215
|
-
var index$
|
|
26077
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
25216
26078
|
__proto__: null,
|
|
25217
26079
|
addRoles: addRoles,
|
|
25218
26080
|
removeRoles: removeRoles,
|
|
@@ -25220,10 +26082,10 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
25220
26082
|
unbanMembers: unbanMembers
|
|
25221
26083
|
});
|
|
25222
26084
|
|
|
25223
|
-
var index$
|
|
26085
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
25224
26086
|
__proto__: null,
|
|
25225
|
-
Moderation: index$
|
|
25226
|
-
Membership: index$
|
|
26087
|
+
Moderation: index$i,
|
|
26088
|
+
Membership: index$j,
|
|
25227
26089
|
getCommunityByIds: getCommunities$1,
|
|
25228
26090
|
createCommunity: createCommunity,
|
|
25229
26091
|
updateCommunity: updateCommunity,
|
|
@@ -25459,7 +26321,7 @@ const getCategories = (params, callback, config) => {
|
|
|
25459
26321
|
};
|
|
25460
26322
|
/* end_public_function */
|
|
25461
26323
|
|
|
25462
|
-
var index$
|
|
26324
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
25463
26325
|
__proto__: null,
|
|
25464
26326
|
getCategory: getCategory,
|
|
25465
26327
|
getCategories: getCategories
|
|
@@ -25758,6 +26620,11 @@ const createCommentOptimistic = (bundle) => {
|
|
|
25758
26620
|
targetType: 'community',
|
|
25759
26621
|
dataType: 'text',
|
|
25760
26622
|
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
26623
|
+
// In a gated community the optimistic object stays out of public collections until the
|
|
26624
|
+
// response settles the status; the author's own view still updates through the local event
|
|
26625
|
+
approvalStatus: isCommentApprovalRequired(bundle)
|
|
26626
|
+
? "pending" /* Amity.CommentApprovalStatusEnum.Pending */
|
|
26627
|
+
: "approved" /* Amity.CommentApprovalStatusEnum.Approved */,
|
|
25761
26628
|
};
|
|
25762
26629
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
25763
26630
|
pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
|
|
@@ -25774,32 +26641,57 @@ const createCommentOptimistic = (bundle) => {
|
|
|
25774
26641
|
* ```js
|
|
25775
26642
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
25776
26643
|
* const newComment = await CommentRepository.createComment(bundle)
|
|
26644
|
+
*
|
|
26645
|
+
* // Server-confirmed only: nothing is shown until the request succeeds
|
|
26646
|
+
* const confirmed = await CommentRepository.createComment(bundle, false)
|
|
25777
26647
|
* ```
|
|
25778
26648
|
*
|
|
25779
26649
|
* Creates an {@link Amity.Comment}
|
|
25780
26650
|
*
|
|
26651
|
+
* With `isOptimistic` (the default) a local comment appears at once with `syncState: 'syncing'`,
|
|
26652
|
+
* moves to `'synced'` when the server confirms it and to `'error'` if the request fails, so the
|
|
26653
|
+
* caller can offer a retry. With `isOptimistic: false` nothing is created locally until the
|
|
26654
|
+
* server answers: on success the comment arrives already `'synced'`; on failure no comment
|
|
26655
|
+
* entity exists anywhere and the promise rejects.
|
|
26656
|
+
*
|
|
25781
26657
|
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
26658
|
+
* @param isOptimistic Show a local comment before the server confirms it. Default `true`.
|
|
26659
|
+
* Ignored when the client cache is disabled, since there is nowhere to hold the local comment.
|
|
25782
26660
|
* @returns The newly created {@link Amity.Comment}
|
|
25783
26661
|
*
|
|
25784
26662
|
* @category Comment API
|
|
25785
26663
|
* @async
|
|
25786
26664
|
*/
|
|
25787
|
-
const createComment = async (bundle) => {
|
|
26665
|
+
const createComment = async (bundle, isOptimistic = true) => {
|
|
25788
26666
|
const client = getActiveClient();
|
|
25789
|
-
client.log('comment/createComment', bundle);
|
|
25790
|
-
|
|
26667
|
+
client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
|
|
26668
|
+
// Without a local comment the server assigns the id; with one, the same id travels through the
|
|
26669
|
+
// optimistic object, the response and every realtime event so each step recognises it.
|
|
26670
|
+
const optimisticData = isOptimistic ? createCommentOptimistic(bundle) : undefined;
|
|
25791
26671
|
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
25792
26672
|
try {
|
|
25793
|
-
const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
25794
|
-
const { comments } = data;
|
|
26673
|
+
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
25795
26674
|
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
25796
|
-
if (comments.length === 0)
|
|
26675
|
+
if (payload.comments.length === 0)
|
|
25797
26676
|
throw new Error('Comment not created');
|
|
26677
|
+
// Absent `approvalStatus` means approved; the result is the only source of the status.
|
|
26678
|
+
// The confirmed comment is written as `synced` so the cache itself tells the two states apart
|
|
26679
|
+
// (a local-event subscriber is not guaranteed to be listening).
|
|
26680
|
+
const prepared = prepareCommentPayload(payload);
|
|
26681
|
+
const data = Object.assign(Object.assign({}, prepared), { comments: prepared.comments.map(comment => comment.commentId === (commentId !== null && commentId !== void 0 ? commentId : comment.commentId)
|
|
26682
|
+
? Object.assign(Object.assign({}, comment), { syncState: "synced" /* Amity.SyncState.Synced */ }) : comment) });
|
|
26683
|
+
const { comments } = data;
|
|
25798
26684
|
const cachedAt = client.cache && Date.now();
|
|
25799
26685
|
if (client.cache)
|
|
25800
26686
|
ingestInCache(data, { cachedAt });
|
|
25801
26687
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
25802
|
-
|
|
26688
|
+
if (isCommentPending(comments[0])) {
|
|
26689
|
+
// Not counted for anyone else until approved; the author sees their own +1
|
|
26690
|
+
recordPendingAuthoredComment(comments[0]);
|
|
26691
|
+
}
|
|
26692
|
+
else {
|
|
26693
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, comments[0].createdAt));
|
|
26694
|
+
}
|
|
25803
26695
|
}
|
|
25804
26696
|
else if (bundle.referenceType === 'story') {
|
|
25805
26697
|
const storyIndex = pullFromCache([
|
|
@@ -25820,9 +26712,9 @@ const createComment = async (bundle) => {
|
|
|
25820
26712
|
categories: [],
|
|
25821
26713
|
comments,
|
|
25822
26714
|
communities: [],
|
|
25823
|
-
communityUsers:
|
|
25824
|
-
files:
|
|
25825
|
-
users:
|
|
26715
|
+
communityUsers: payload.communityUsers,
|
|
26716
|
+
files: payload.files,
|
|
26717
|
+
users: payload.users,
|
|
25826
26718
|
});
|
|
25827
26719
|
}
|
|
25828
26720
|
}
|
|
@@ -25830,9 +26722,9 @@ const createComment = async (bundle) => {
|
|
|
25830
26722
|
fireEvent('local.comment.created', {
|
|
25831
26723
|
comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
25832
26724
|
commentChildren: data.commentChildren,
|
|
25833
|
-
users:
|
|
25834
|
-
files:
|
|
25835
|
-
communityUsers:
|
|
26725
|
+
users: payload.users,
|
|
26726
|
+
files: payload.files,
|
|
26727
|
+
communityUsers: payload.communityUsers,
|
|
25836
26728
|
});
|
|
25837
26729
|
return {
|
|
25838
26730
|
data: LinkedObject.comment(comments[0]),
|
|
@@ -25840,9 +26732,17 @@ const createComment = async (bundle) => {
|
|
|
25840
26732
|
};
|
|
25841
26733
|
}
|
|
25842
26734
|
catch (e) {
|
|
26735
|
+
// Only a local comment has anything to mark as failed; a server-confirmed-only create leaves
|
|
26736
|
+
// no entity behind
|
|
25843
26737
|
if (optimisticData) {
|
|
26738
|
+
const failed = Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ });
|
|
26739
|
+
// Write the failure to the cache directly: the local event below only reaches pages that
|
|
26740
|
+
// observe comments, and the caller's retry UI reads the cached state
|
|
26741
|
+
pushToCache(['comment', 'get', failed.commentId], failed, {
|
|
26742
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
26743
|
+
});
|
|
25844
26744
|
fireEvent('local.comment.created', {
|
|
25845
|
-
comments: [
|
|
26745
|
+
comments: [failed],
|
|
25846
26746
|
commentChildren: [],
|
|
25847
26747
|
users: [],
|
|
25848
26748
|
files: [],
|
|
@@ -25875,16 +26775,26 @@ const createComment = async (bundle) => {
|
|
|
25875
26775
|
* @async
|
|
25876
26776
|
*/
|
|
25877
26777
|
const updateComment = async (commentId, patch) => {
|
|
26778
|
+
var _a;
|
|
25878
26779
|
const client = getActiveClient();
|
|
25879
26780
|
client.log('user/updateComment', patch);
|
|
25880
|
-
const
|
|
26781
|
+
const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26782
|
+
const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
26783
|
+
const data = prepareCommentPayload(payload);
|
|
26784
|
+
const updated = data.comments.find(comment => comment.commentId === commentId);
|
|
25881
26785
|
const cachedAt = client.cache && Date.now();
|
|
25882
26786
|
if (client.cache)
|
|
25883
26787
|
ingestInCache(data, { cachedAt });
|
|
25884
|
-
|
|
25885
|
-
|
|
26788
|
+
// An effective edit in a gated community sends the comment back for review: it leaves the
|
|
26789
|
+
// public reply list and the public count once. The `comment.updated` event below removes it
|
|
26790
|
+
// from the comment collections; the realtime echo finds it already pending and does nothing.
|
|
26791
|
+
if (isCommentPending(updated) && previous && isCommentApproved(previous)) {
|
|
26792
|
+
unlinkCommentFromParent(updated);
|
|
26793
|
+
applyCommentReReviewCount(updated);
|
|
26794
|
+
}
|
|
26795
|
+
fireEvent('comment.updated', payload);
|
|
25886
26796
|
return {
|
|
25887
|
-
data: LinkedObject.comment(
|
|
26797
|
+
data: LinkedObject.comment(updated),
|
|
25888
26798
|
cachedAt,
|
|
25889
26799
|
};
|
|
25890
26800
|
};
|
|
@@ -26024,7 +26934,13 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
26024
26934
|
const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26025
26935
|
if (post) {
|
|
26026
26936
|
const engine = PostCommentCountEngine$1.getInstance();
|
|
26027
|
-
|
|
26937
|
+
if (isCommentPending(comment.data)) {
|
|
26938
|
+
// Never counted for anyone else; only the author's own +1 goes away
|
|
26939
|
+
engine.removePendingAuthoredComment(post.postId, commentId);
|
|
26940
|
+
}
|
|
26941
|
+
else {
|
|
26942
|
+
engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
|
|
26943
|
+
}
|
|
26028
26944
|
if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
26029
26945
|
// NOTE: delete the parent comment will also remove all children comments
|
|
26030
26946
|
deleted.children.forEach((childCommentId) => {
|
|
@@ -26094,6 +27010,109 @@ const hardDeleteComment = async (commentId) => {
|
|
|
26094
27010
|
};
|
|
26095
27011
|
/* end_public_function */
|
|
26096
27012
|
|
|
27013
|
+
/* begin_public_function
|
|
27014
|
+
id: comment.approve
|
|
27015
|
+
*/
|
|
27016
|
+
/**
|
|
27017
|
+
* ```js
|
|
27018
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
27019
|
+
*
|
|
27020
|
+
* const { data: comment } = await CommentRepository.approveComment('commentId')
|
|
27021
|
+
* ```
|
|
27022
|
+
*
|
|
27023
|
+
* Approves a {@link Amity.Comment} held for review, making it visible to everyone
|
|
27024
|
+
*
|
|
27025
|
+
* @param commentId The {@link Amity.Comment} ID to be approved
|
|
27026
|
+
* @return The {@link Amity.Comment} that was approved
|
|
27027
|
+
*
|
|
27028
|
+
* @category Comment API
|
|
27029
|
+
* @async
|
|
27030
|
+
*/
|
|
27031
|
+
const approveComment = async (commentId) => {
|
|
27032
|
+
const client = getActiveClient();
|
|
27033
|
+
client.log('comment/approveComment', commentId);
|
|
27034
|
+
// No request body, and nothing is revealed before the server confirms
|
|
27035
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/approve`);
|
|
27036
|
+
const data = prepareCommentPayload(prepareMembershipPayload(payload, 'communityUsers'));
|
|
27037
|
+
const approved = data.comments.find(comment => comment.commentId === commentId);
|
|
27038
|
+
const cachedAt = client.cache && Date.now();
|
|
27039
|
+
if (client.cache)
|
|
27040
|
+
ingestInCache(data, { cachedAt });
|
|
27041
|
+
// The reveal path: parent link and exactly one count task. Applied here so it does not depend
|
|
27042
|
+
// on an observer being open; the event below and the realtime `comment.approved` that follows
|
|
27043
|
+
// find the work done and reconcile by comment id (collection insert, queue removal).
|
|
27044
|
+
linkCommentToParent(approved);
|
|
27045
|
+
applyCommentApprovedCount(approved);
|
|
27046
|
+
fireEvent('comment.approved', payload);
|
|
27047
|
+
return {
|
|
27048
|
+
data: LinkedObject.comment(approved),
|
|
27049
|
+
cachedAt,
|
|
27050
|
+
};
|
|
27051
|
+
};
|
|
27052
|
+
/* end_public_function */
|
|
27053
|
+
|
|
27054
|
+
// Rejected is terminal and implies deleted
|
|
27055
|
+
const markRejected = (comment) => (Object.assign(Object.assign({}, comment), { approvalStatus: "rejected" /* Amity.CommentApprovalStatusEnum.Rejected */, isDeleted: true }));
|
|
27056
|
+
/* begin_public_function
|
|
27057
|
+
id: comment.decline
|
|
27058
|
+
*/
|
|
27059
|
+
/**
|
|
27060
|
+
* ```js
|
|
27061
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
27062
|
+
*
|
|
27063
|
+
* const { data: comment } = await CommentRepository.declineComment('commentId', 'Off-topic')
|
|
27064
|
+
* ```
|
|
27065
|
+
*
|
|
27066
|
+
* Declines a {@link Amity.Comment} held for review. A declined comment is also a deleted comment
|
|
27067
|
+
*
|
|
27068
|
+
* @param commentId The {@link Amity.Comment} ID to be declined
|
|
27069
|
+
* @param reason Optional reviewer's note, at most 250 characters, kept for the moderation record only
|
|
27070
|
+
* @return The {@link Amity.Comment} that was declined
|
|
27071
|
+
*
|
|
27072
|
+
* @category Comment API
|
|
27073
|
+
* @async
|
|
27074
|
+
*/
|
|
27075
|
+
const declineComment = async (commentId, reason) => {
|
|
27076
|
+
var _a, _b, _c, _d, _e, _f;
|
|
27077
|
+
const client = getActiveClient();
|
|
27078
|
+
client.log('comment/declineComment', commentId, reason);
|
|
27079
|
+
// Read before the request: the fallback when the response carries no comment
|
|
27080
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27081
|
+
// `reason` is surfaced to nobody; the key is absent from the body when the caller gives none
|
|
27082
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/decline`, reason ? { reason } : undefined);
|
|
27083
|
+
// The BE contract (PDT-5135 §3) states the response body for approve only; for decline the
|
|
27084
|
+
// standard comment payload is assumed. Ingest whatever came back, and when the body carries no
|
|
27085
|
+
// comment fall back to the cached one so the delete path below still runs.
|
|
27086
|
+
const returned = (_b = payload === null || payload === void 0 ? void 0 : payload.comments) === null || _b === void 0 ? void 0 : _b.some(comment => comment.commentId === commentId);
|
|
27087
|
+
if (!returned && !cached)
|
|
27088
|
+
throw new Error('Comment not found after decline');
|
|
27089
|
+
const comments = returned
|
|
27090
|
+
? payload.comments.map(comment => comment.commentId === commentId ? markRejected(comment) : comment)
|
|
27091
|
+
: [markRejected(cached)];
|
|
27092
|
+
const declined = {
|
|
27093
|
+
comments,
|
|
27094
|
+
commentChildren: (_c = payload === null || payload === void 0 ? void 0 : payload.commentChildren) !== null && _c !== void 0 ? _c : [],
|
|
27095
|
+
users: (_d = payload === null || payload === void 0 ? void 0 : payload.users) !== null && _d !== void 0 ? _d : [],
|
|
27096
|
+
files: (_e = payload === null || payload === void 0 ? void 0 : payload.files) !== null && _e !== void 0 ? _e : [],
|
|
27097
|
+
communityUsers: (_f = payload === null || payload === void 0 ? void 0 : payload.communityUsers) !== null && _f !== void 0 ? _f : [],
|
|
27098
|
+
};
|
|
27099
|
+
// There is no `comment.declined` event: the existing delete path drops the comment from every
|
|
27100
|
+
// collection and the review queue, and moves no count because a pending comment was never counted.
|
|
27101
|
+
const data = prepareCommentPayload(prepareMembershipPayload(declined, 'communityUsers'));
|
|
27102
|
+
const rejected = data.comments.find(comment => comment.commentId === commentId);
|
|
27103
|
+
const cachedAt = client.cache && Date.now();
|
|
27104
|
+
if (client.cache)
|
|
27105
|
+
ingestInCache(data, { cachedAt });
|
|
27106
|
+
unlinkCommentFromParent(rejected);
|
|
27107
|
+
releasePendingAuthoredComment(rejected);
|
|
27108
|
+
fireEvent('comment.deleted', declined);
|
|
27109
|
+
return {
|
|
27110
|
+
data: LinkedObject.comment(rejected),
|
|
27111
|
+
cachedAt,
|
|
27112
|
+
};
|
|
27113
|
+
};
|
|
27114
|
+
/* end_public_function */
|
|
27115
|
+
|
|
26097
27116
|
/* begin_public_function
|
|
26098
27117
|
id: comment.flag
|
|
26099
27118
|
*/
|
|
@@ -26179,6 +27198,7 @@ const isCommentFlaggedByMe = async (commentId) => {
|
|
|
26179
27198
|
/* end_public_function */
|
|
26180
27199
|
|
|
26181
27200
|
const getComment$1 = async (commentId) => {
|
|
27201
|
+
var _a;
|
|
26182
27202
|
const client = getActiveClient();
|
|
26183
27203
|
client.log('comment/getComment', commentId);
|
|
26184
27204
|
isInTombstone('comment', commentId);
|
|
@@ -26189,7 +27209,11 @@ const getComment$1 = async (commentId) => {
|
|
|
26189
27209
|
data = response.data;
|
|
26190
27210
|
}
|
|
26191
27211
|
catch (error) {
|
|
26192
|
-
|
|
27212
|
+
// A pending comment answers 404 to anyone but its author and reviewers. That is a
|
|
27213
|
+
// visibility answer, not a deletion — never tombstone a comment known to be pending.
|
|
27214
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27215
|
+
const isKnownPending = !!cached && isCommentPending(cached);
|
|
27216
|
+
if (!isKnownPending && checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
26193
27217
|
pushToTombstone('comment', commentId);
|
|
26194
27218
|
}
|
|
26195
27219
|
throw error;
|
|
@@ -26316,6 +27340,7 @@ const onLocalCommentReactionRemoved = (callback) => {
|
|
|
26316
27340
|
*/
|
|
26317
27341
|
const getComment = (commentId, callback) => {
|
|
26318
27342
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
27343
|
+
onCommentApproved,
|
|
26319
27344
|
onCommentDeleteLocal,
|
|
26320
27345
|
onCommentDeleted,
|
|
26321
27346
|
onCommentFlagged,
|
|
@@ -26329,28 +27354,31 @@ const getComment = (commentId, callback) => {
|
|
|
26329
27354
|
};
|
|
26330
27355
|
/* end_public_function */
|
|
26331
27356
|
|
|
26332
|
-
|
|
26333
|
-
|
|
26334
|
-
|
|
26335
|
-
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
26343
|
-
|
|
26344
|
-
|
|
26345
|
-
|
|
26346
|
-
|
|
26347
|
-
|
|
27357
|
+
/**
|
|
27358
|
+
* ```js
|
|
27359
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
27360
|
+
* const dispose = onCommentCreated(comment => {
|
|
27361
|
+
* // ...
|
|
27362
|
+
* })
|
|
27363
|
+
* ```
|
|
27364
|
+
*
|
|
27365
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
27366
|
+
*
|
|
27367
|
+
* @param callback The function to call when the event was fired
|
|
27368
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27369
|
+
*
|
|
27370
|
+
* @category Comment Events
|
|
27371
|
+
*/
|
|
27372
|
+
const onCommentCreatedLocal = (callback) => {
|
|
27373
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
27374
|
+
};
|
|
26348
27375
|
|
|
26349
27376
|
var EnumCommentActions;
|
|
26350
27377
|
(function (EnumCommentActions) {
|
|
26351
27378
|
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
26352
27379
|
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
26353
27380
|
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
27381
|
+
EnumCommentActions["OnCommentApproved"] = "onCommentApproved";
|
|
26354
27382
|
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
26355
27383
|
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
26356
27384
|
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
@@ -26373,15 +27401,17 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26373
27401
|
}
|
|
26374
27402
|
appendToQueryStream(response, direction, refresh = false) {
|
|
26375
27403
|
var _a, _b;
|
|
27404
|
+
// The public list is approved-only even when the server widens the read for a reviewer
|
|
27405
|
+
const commentIds = response.comments.filter(isCommentApproved).map(getResolver('comment'));
|
|
26376
27406
|
if (refresh) {
|
|
26377
27407
|
pushToCache(this.cacheKey, {
|
|
26378
|
-
data:
|
|
27408
|
+
data: commentIds,
|
|
26379
27409
|
});
|
|
26380
27410
|
}
|
|
26381
27411
|
else {
|
|
26382
27412
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26383
27413
|
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26384
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...
|
|
27414
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...commentIds])] }));
|
|
26385
27415
|
}
|
|
26386
27416
|
}
|
|
26387
27417
|
reactor(action) {
|
|
@@ -26400,8 +27430,19 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26400
27430
|
return;
|
|
26401
27431
|
}
|
|
26402
27432
|
if (action === EnumCommentActions.OnCommentCreated) {
|
|
27433
|
+
// A pending comment reaches clients over realtime before anyone may see it: persist
|
|
27434
|
+
// only, no insert and no emit. `comment.approved` is the reveal signal.
|
|
27435
|
+
if (!isCommentApproved(comment))
|
|
27436
|
+
return;
|
|
27437
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
27438
|
+
}
|
|
27439
|
+
if (action === EnumCommentActions.OnCommentApproved) {
|
|
26403
27440
|
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
26404
27441
|
}
|
|
27442
|
+
// An effective edit in a gated community returns the comment to review: it leaves the list
|
|
27443
|
+
if (action === EnumCommentActions.OnCommentUpdated && isCommentPending(comment)) {
|
|
27444
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
27445
|
+
}
|
|
26405
27446
|
pushToCache(this.cacheKey, collection);
|
|
26406
27447
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26407
27448
|
};
|
|
@@ -26411,24 +27452,22 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26411
27452
|
}
|
|
26412
27453
|
}
|
|
26413
27454
|
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
26431
|
-
};
|
|
27455
|
+
class CommentPaginationController extends PaginationController {
|
|
27456
|
+
async getRequest(queryParams, token) {
|
|
27457
|
+
var _a;
|
|
27458
|
+
const { pageSize, limit, includeDeleted } = queryParams, params = __rest(queryParams, ["pageSize", "limit", "includeDeleted"]);
|
|
27459
|
+
const effectiveLimit = (_a = pageSize !== null && pageSize !== void 0 ? pageSize : limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
27460
|
+
const baseOptions = {
|
|
27461
|
+
type: params.sortBy || queryParams.limit || queryParams.pageSize ? 'pagination' : undefined,
|
|
27462
|
+
};
|
|
27463
|
+
const options = token
|
|
27464
|
+
? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { pageSize: effectiveLimit, limit: effectiveLimit });
|
|
27465
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
27466
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
27467
|
+
});
|
|
27468
|
+
return queryResponse;
|
|
27469
|
+
}
|
|
27470
|
+
}
|
|
26432
27471
|
|
|
26433
27472
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
26434
27473
|
constructor(query, callback) {
|
|
@@ -26464,6 +27503,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26464
27503
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
26465
27504
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
26466
27505
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
27506
|
+
{ fn: onCommentApproved, action: EnumCommentActions.OnCommentApproved },
|
|
26467
27507
|
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
26468
27508
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
26469
27509
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
@@ -26497,7 +27537,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26497
27537
|
});
|
|
26498
27538
|
}
|
|
26499
27539
|
applyFilter(data) {
|
|
26500
|
-
|
|
27540
|
+
// Approved-only, for every caller including the author of a pending comment
|
|
27541
|
+
let comments = data.filter(isCommentApproved);
|
|
26501
27542
|
if (!this.query.includeDeleted) {
|
|
26502
27543
|
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
26503
27544
|
}
|
|
@@ -26585,7 +27626,202 @@ const getComments = (params, callback, config) => {
|
|
|
26585
27626
|
};
|
|
26586
27627
|
/* end_public_function */
|
|
26587
27628
|
|
|
26588
|
-
|
|
27629
|
+
class CommentReviewQueuePaginationController extends PaginationController {
|
|
27630
|
+
async getRequest(queryParams, token) {
|
|
27631
|
+
const { communityId, limit } = queryParams, params = __rest(queryParams, ["communityId", "limit"]);
|
|
27632
|
+
// The route defaults to 10, not the SDK-wide 20, and rejects anything above 100
|
|
27633
|
+
const effectiveLimit = Math.min(limit !== null && limit !== void 0 ? limit : COMMENT_REVIEW_QUEUE_DEFAULT_PAGINATION_SIZE, COMMENT_REVIEW_QUEUE_MAX_PAGINATION_SIZE);
|
|
27634
|
+
// Token paging only. The route also accepts options[skip], but offset paging over a queue that
|
|
27635
|
+
// drains from the front skips items, so the SDK never sends it.
|
|
27636
|
+
const options = token ? { token } : { limit: effectiveLimit };
|
|
27637
|
+
const { data: queryResponse } = await this.http.get(API_ENDPOINTS.commentReviewQueue(communityId), {
|
|
27638
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
27639
|
+
});
|
|
27640
|
+
return queryResponse;
|
|
27641
|
+
}
|
|
27642
|
+
}
|
|
27643
|
+
|
|
27644
|
+
class CommentReviewQueueQueryStreamController extends QueryStreamController {
|
|
27645
|
+
constructor(query, cacheKey, notifyChange) {
|
|
27646
|
+
super(query, cacheKey);
|
|
27647
|
+
this.notifyChange = notifyChange;
|
|
27648
|
+
}
|
|
27649
|
+
async saveToMainDB(response) {
|
|
27650
|
+
const processedPayload = prepareCommentPayload(response);
|
|
27651
|
+
const client = getActiveClient();
|
|
27652
|
+
const cachedAt = client.cache && Date.now();
|
|
27653
|
+
if (client.cache) {
|
|
27654
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27655
|
+
}
|
|
27656
|
+
}
|
|
27657
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27658
|
+
var _a, _b;
|
|
27659
|
+
// Server order is queue-entry order, oldest first. Keep it: later pages append, nothing
|
|
27660
|
+
// re-sorts by createdAt (the two diverge on re-review).
|
|
27661
|
+
const commentIds = response.comments.map(getResolver('comment'));
|
|
27662
|
+
if (refresh) {
|
|
27663
|
+
pushToCache(this.cacheKey, {
|
|
27664
|
+
data: commentIds,
|
|
27665
|
+
});
|
|
27666
|
+
}
|
|
27667
|
+
else {
|
|
27668
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27669
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27670
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...commentIds])] }));
|
|
27671
|
+
}
|
|
27672
|
+
}
|
|
27673
|
+
matchesQuery(comment) {
|
|
27674
|
+
return (comment.targetType === 'community' &&
|
|
27675
|
+
comment.targetId === this.query.communityId &&
|
|
27676
|
+
(!this.query.postId || comment.referenceId === this.query.postId));
|
|
27677
|
+
}
|
|
27678
|
+
reactor(action) {
|
|
27679
|
+
return (comment) => {
|
|
27680
|
+
var _a;
|
|
27681
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27682
|
+
if (!collection || !this.matchesQuery(comment))
|
|
27683
|
+
return;
|
|
27684
|
+
const isQueued = collection.data.includes(comment.commentId);
|
|
27685
|
+
// A date-filtered queue is the server's to shape; live events only remove from it
|
|
27686
|
+
const acceptsLiveInserts = !this.query.startDate && !this.query.endDate;
|
|
27687
|
+
switch (action) {
|
|
27688
|
+
case EnumCommentActions.OnCommentCreated:
|
|
27689
|
+
case EnumCommentActions.OnCommentUpdated:
|
|
27690
|
+
if (isCommentPending(comment) && !comment.isDeleted) {
|
|
27691
|
+
if (isQueued || !acceptsLiveInserts)
|
|
27692
|
+
return;
|
|
27693
|
+
// Enters (or, after an edit, re-enters) the queue at the end
|
|
27694
|
+
collection.data = [...collection.data, comment.commentId];
|
|
27695
|
+
}
|
|
27696
|
+
else {
|
|
27697
|
+
if (!isQueued)
|
|
27698
|
+
return;
|
|
27699
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
27700
|
+
}
|
|
27701
|
+
break;
|
|
27702
|
+
case EnumCommentActions.OnCommentApproved:
|
|
27703
|
+
case EnumCommentActions.OnCommentDeleted:
|
|
27704
|
+
if (!isQueued)
|
|
27705
|
+
return;
|
|
27706
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
27707
|
+
break;
|
|
27708
|
+
default:
|
|
27709
|
+
return;
|
|
27710
|
+
}
|
|
27711
|
+
pushToCache(this.cacheKey, collection);
|
|
27712
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27713
|
+
};
|
|
27714
|
+
}
|
|
27715
|
+
subscribeRTE(createSubscriber) {
|
|
27716
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27717
|
+
}
|
|
27718
|
+
}
|
|
27719
|
+
|
|
27720
|
+
class CommentReviewQueueLiveCollectionController extends LiveCollectionController {
|
|
27721
|
+
constructor(query, callback) {
|
|
27722
|
+
const queryStreamId = hash__default["default"](query);
|
|
27723
|
+
const cacheKey = ['commentReviewQueue', 'collection', queryStreamId];
|
|
27724
|
+
const paginationController = new CommentReviewQueuePaginationController(query);
|
|
27725
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27726
|
+
this.query = query;
|
|
27727
|
+
this.queryStreamController = new CommentReviewQueueQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
27728
|
+
this.callback = callback.bind(this);
|
|
27729
|
+
this.loadPage({ initial: true });
|
|
27730
|
+
}
|
|
27731
|
+
setup() {
|
|
27732
|
+
var _a;
|
|
27733
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27734
|
+
if (!collection) {
|
|
27735
|
+
pushToCache(this.cacheKey, {
|
|
27736
|
+
data: [],
|
|
27737
|
+
params: {},
|
|
27738
|
+
});
|
|
27739
|
+
}
|
|
27740
|
+
}
|
|
27741
|
+
async persistModel(queryPayload) {
|
|
27742
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27743
|
+
}
|
|
27744
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27745
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27746
|
+
}
|
|
27747
|
+
startSubscription() {
|
|
27748
|
+
// No `comment.declined` exists: a decline arrives as `comment.deleted`
|
|
27749
|
+
return this.queryStreamController.subscribeRTE([
|
|
27750
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
27751
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
27752
|
+
{ fn: onCommentApproved, action: EnumCommentActions.OnCommentApproved },
|
|
27753
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
27754
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
27755
|
+
]);
|
|
27756
|
+
}
|
|
27757
|
+
notifyChange({ origin, loading, error }) {
|
|
27758
|
+
var _a;
|
|
27759
|
+
// A caller who lost REVIEW_COMMUNITY_COMMENT must not keep reading stale pending content
|
|
27760
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
27761
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
27762
|
+
}
|
|
27763
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27764
|
+
if (!collection)
|
|
27765
|
+
return;
|
|
27766
|
+
const data = collection.data
|
|
27767
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
27768
|
+
.filter(isNonNullable)
|
|
27769
|
+
.map(({ data }) => data)
|
|
27770
|
+
.filter(comment => isCommentPending(comment) && !comment.isDeleted)
|
|
27771
|
+
.map(LinkedObject.comment);
|
|
27772
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27773
|
+
return;
|
|
27774
|
+
this.callback({
|
|
27775
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27776
|
+
data,
|
|
27777
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27778
|
+
loading,
|
|
27779
|
+
error,
|
|
27780
|
+
});
|
|
27781
|
+
}
|
|
27782
|
+
}
|
|
27783
|
+
|
|
27784
|
+
/* begin_public_function
|
|
27785
|
+
id: comment.review_queue
|
|
27786
|
+
*/
|
|
27787
|
+
/**
|
|
27788
|
+
* ```js
|
|
27789
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
27790
|
+
*
|
|
27791
|
+
* const unsub = CommentRepository.getCommentReviewQueue(
|
|
27792
|
+
* { communityId: 'communityId' },
|
|
27793
|
+
* ({ data: comments, hasNextPage, onNextPage }) => {
|
|
27794
|
+
* // every comment is awaiting review
|
|
27795
|
+
* },
|
|
27796
|
+
* )
|
|
27797
|
+
* ```
|
|
27798
|
+
*
|
|
27799
|
+
* Observe the {@link Amity.Comment} list awaiting moderator review in a community, oldest first
|
|
27800
|
+
*
|
|
27801
|
+
* @param params the community to read the queue of, optionally narrowed to one post and a date range
|
|
27802
|
+
* @param callback the function to call when new data are available
|
|
27803
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the queue
|
|
27804
|
+
*
|
|
27805
|
+
* @category Comments Live Collection
|
|
27806
|
+
*/
|
|
27807
|
+
const getCommentReviewQueue = (params, callback) => {
|
|
27808
|
+
const { log, cache } = getActiveClient();
|
|
27809
|
+
if (!cache)
|
|
27810
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
27811
|
+
const timestamp = Date.now();
|
|
27812
|
+
log(`getCommentReviewQueue(tmpid: ${timestamp}) > listen`);
|
|
27813
|
+
const commentReviewQueueLiveCollection = new CommentReviewQueueLiveCollectionController(params, callback);
|
|
27814
|
+
const disposers = commentReviewQueueLiveCollection.startSubscription();
|
|
27815
|
+
const cacheKey = commentReviewQueueLiveCollection.getCacheKey();
|
|
27816
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27817
|
+
return () => {
|
|
27818
|
+
log(`getCommentReviewQueue(tmpid: ${timestamp}) > dispose`);
|
|
27819
|
+
disposers.forEach(fn => fn());
|
|
27820
|
+
};
|
|
27821
|
+
};
|
|
27822
|
+
/* end_public_function */
|
|
27823
|
+
|
|
27824
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
26589
27825
|
__proto__: null,
|
|
26590
27826
|
getCommentByIds: getCommentByIds,
|
|
26591
27827
|
createComment: createComment,
|
|
@@ -26593,18 +27829,22 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
26593
27829
|
deleteComment: deleteComment,
|
|
26594
27830
|
softDeleteComment: softDeleteComment,
|
|
26595
27831
|
hardDeleteComment: hardDeleteComment,
|
|
27832
|
+
approveComment: approveComment,
|
|
27833
|
+
declineComment: declineComment,
|
|
26596
27834
|
flagComment: flagComment,
|
|
26597
27835
|
unflagComment: unflagComment,
|
|
26598
27836
|
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
26599
27837
|
onCommentCreated: onCommentCreated,
|
|
26600
27838
|
onCommentUpdated: onCommentUpdated,
|
|
26601
27839
|
onCommentDeleted: onCommentDeleted,
|
|
27840
|
+
onCommentApproved: onCommentApproved,
|
|
26602
27841
|
onCommentFlagged: onCommentFlagged,
|
|
26603
27842
|
onCommentUnflagged: onCommentUnflagged,
|
|
26604
27843
|
onCommentReactionAdded: onCommentReactionAdded,
|
|
26605
27844
|
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
26606
27845
|
getComment: getComment,
|
|
26607
|
-
getComments: getComments
|
|
27846
|
+
getComments: getComments,
|
|
27847
|
+
getCommentReviewQueue: getCommentReviewQueue
|
|
26608
27848
|
});
|
|
26609
27849
|
|
|
26610
27850
|
/**
|
|
@@ -27854,7 +29094,7 @@ const getForYouFeed = (callback) => {
|
|
|
27854
29094
|
};
|
|
27855
29095
|
/* end_public_function */
|
|
27856
29096
|
|
|
27857
|
-
var index$
|
|
29097
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
27858
29098
|
__proto__: null,
|
|
27859
29099
|
queryGlobalFeed: queryGlobalFeed,
|
|
27860
29100
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -30999,7 +32239,7 @@ const getRooms = (params, callback, config) => {
|
|
|
30999
32239
|
};
|
|
31000
32240
|
/* end_public_function */
|
|
31001
32241
|
|
|
31002
|
-
var index$
|
|
32242
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
31003
32243
|
__proto__: null,
|
|
31004
32244
|
createRoom: createRoom,
|
|
31005
32245
|
updateRoom: updateRoom,
|
|
@@ -31298,7 +32538,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
31298
32538
|
};
|
|
31299
32539
|
/* end_public_function */
|
|
31300
32540
|
|
|
31301
|
-
var index$
|
|
32541
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
31302
32542
|
__proto__: null,
|
|
31303
32543
|
getPostByIds: getPostByIds,
|
|
31304
32544
|
createPost: createPost,
|
|
@@ -31913,7 +33153,7 @@ const getStreams = (params, callback, config) => {
|
|
|
31913
33153
|
};
|
|
31914
33154
|
};
|
|
31915
33155
|
|
|
31916
|
-
var index$
|
|
33156
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
31917
33157
|
__proto__: null,
|
|
31918
33158
|
createStream: createStream,
|
|
31919
33159
|
updateStream: updateStream,
|
|
@@ -32216,7 +33456,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
32216
33456
|
};
|
|
32217
33457
|
/* end_public_function */
|
|
32218
33458
|
|
|
32219
|
-
var index$
|
|
33459
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
32220
33460
|
__proto__: null,
|
|
32221
33461
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
32222
33462
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -32527,7 +33767,7 @@ const getPoll = (pollId, callback) => {
|
|
|
32527
33767
|
};
|
|
32528
33768
|
/* end_public_function */
|
|
32529
33769
|
|
|
32530
|
-
var index$
|
|
33770
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
32531
33771
|
__proto__: null,
|
|
32532
33772
|
createPoll: createPoll,
|
|
32533
33773
|
closePoll: closePoll,
|
|
@@ -32831,7 +34071,7 @@ const getPlayer = async (parameters) => {
|
|
|
32831
34071
|
return video;
|
|
32832
34072
|
};
|
|
32833
34073
|
|
|
32834
|
-
var index$
|
|
34074
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
32835
34075
|
__proto__: null,
|
|
32836
34076
|
getPlayer: getPlayer
|
|
32837
34077
|
});
|
|
@@ -34004,7 +35244,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
34004
35244
|
};
|
|
34005
35245
|
};
|
|
34006
35246
|
|
|
34007
|
-
var index$
|
|
35247
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
34008
35248
|
__proto__: null,
|
|
34009
35249
|
createImageStory: createImageStory,
|
|
34010
35250
|
createVideoStory: createVideoStory,
|
|
@@ -34041,7 +35281,7 @@ const getNetworkAds = async () => {
|
|
|
34041
35281
|
};
|
|
34042
35282
|
};
|
|
34043
35283
|
|
|
34044
|
-
var index$
|
|
35284
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
34045
35285
|
__proto__: null,
|
|
34046
35286
|
getNetworkAds: getNetworkAds
|
|
34047
35287
|
});
|
|
@@ -34432,7 +35672,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
34432
35672
|
};
|
|
34433
35673
|
/* end_public_function */
|
|
34434
35674
|
|
|
34435
|
-
var index$
|
|
35675
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
34436
35676
|
__proto__: null,
|
|
34437
35677
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
34438
35678
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -34734,7 +35974,7 @@ const getInvitations = (params, callback) => {
|
|
|
34734
35974
|
};
|
|
34735
35975
|
};
|
|
34736
35976
|
|
|
34737
|
-
var index$
|
|
35977
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
34738
35978
|
__proto__: null,
|
|
34739
35979
|
cancelInvitation: cancelInvitation,
|
|
34740
35980
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -34883,7 +36123,7 @@ const getReactions = (postId, callback) => {
|
|
|
34883
36123
|
};
|
|
34884
36124
|
};
|
|
34885
36125
|
|
|
34886
|
-
var index$
|
|
36126
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
34887
36127
|
__proto__: null,
|
|
34888
36128
|
createReaction: createReaction,
|
|
34889
36129
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -35366,7 +36606,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
35366
36606
|
};
|
|
35367
36607
|
};
|
|
35368
36608
|
|
|
35369
|
-
var index$
|
|
36609
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
35370
36610
|
__proto__: null,
|
|
35371
36611
|
createEvent: createEvent,
|
|
35372
36612
|
updateEvent: updateEvent,
|
|
@@ -35593,12 +36833,36 @@ const searchProducts = (params, callback, config) => {
|
|
|
35593
36833
|
};
|
|
35594
36834
|
/* end_public_function */
|
|
35595
36835
|
|
|
35596
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
36836
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
35597
36837
|
__proto__: null,
|
|
35598
36838
|
getProduct: getProduct,
|
|
35599
36839
|
searchProducts: searchProducts
|
|
35600
36840
|
});
|
|
35601
36841
|
|
|
36842
|
+
const getPool = async (topicId, limit) => {
|
|
36843
|
+
const client = getActiveClient();
|
|
36844
|
+
if (!topicId)
|
|
36845
|
+
throw new ASCError('topicId must not be empty', 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
36846
|
+
if (limit !== undefined && (limit < 1 || limit > 100))
|
|
36847
|
+
throw new ASCError('limit must be between 1 and 100', 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
36848
|
+
const { data } = await client.http.get('/api/v5/curated-content/pool', { params: { topicId, limit } });
|
|
36849
|
+
const { topic } = data, payload = __rest(data, ["topic"]);
|
|
36850
|
+
const processedPayload = preparePostPayload(payload);
|
|
36851
|
+
const cachedAt = client.cache && Date.now();
|
|
36852
|
+
if (client.cache) {
|
|
36853
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
36854
|
+
}
|
|
36855
|
+
return {
|
|
36856
|
+
topic: LinkedObject.curatedContentTopic(topic),
|
|
36857
|
+
posts: processedPayload.posts.map(LinkedObject.post),
|
|
36858
|
+
};
|
|
36859
|
+
};
|
|
36860
|
+
|
|
36861
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
36862
|
+
__proto__: null,
|
|
36863
|
+
getPool: getPool
|
|
36864
|
+
});
|
|
36865
|
+
|
|
35602
36866
|
/**
|
|
35603
36867
|
* Helper class for managing product tags per media attachment.
|
|
35604
36868
|
*
|
|
@@ -35647,39 +36911,40 @@ class AmityAttachmentProductTags {
|
|
|
35647
36911
|
}
|
|
35648
36912
|
|
|
35649
36913
|
exports.API_REGIONS = API_REGIONS;
|
|
35650
|
-
exports.AdRepository = index$
|
|
36914
|
+
exports.AdRepository = index$6;
|
|
35651
36915
|
exports.AmityAttachmentProductTags = AmityAttachmentProductTags;
|
|
35652
|
-
exports.CategoryRepository = index$
|
|
35653
|
-
exports.ChannelRepository = index$
|
|
35654
|
-
exports.Client = index$
|
|
35655
|
-
exports.CommentRepository = index$
|
|
36916
|
+
exports.CategoryRepository = index$g;
|
|
36917
|
+
exports.ChannelRepository = index$k;
|
|
36918
|
+
exports.Client = index$t;
|
|
36919
|
+
exports.CommentRepository = index$f;
|
|
35656
36920
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
35657
36921
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
35658
|
-
exports.CommunityRepository = index$
|
|
36922
|
+
exports.CommunityRepository = index$h;
|
|
35659
36923
|
exports.ContentFeedType = ContentFeedType;
|
|
36924
|
+
exports.CuratedContentRepository = index;
|
|
35660
36925
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
35661
|
-
exports.EventRepository = index$
|
|
35662
|
-
exports.FeedRepository = index$
|
|
35663
|
-
exports.FileRepository = index$
|
|
36926
|
+
exports.EventRepository = index$2;
|
|
36927
|
+
exports.FeedRepository = index$e;
|
|
36928
|
+
exports.FileRepository = index$q;
|
|
35664
36929
|
exports.FileType = FileType;
|
|
35665
36930
|
exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
|
|
35666
|
-
exports.InvitationRepository = index$
|
|
35667
|
-
exports.LiveReactionRepository = index$
|
|
35668
|
-
exports.LiveStreamPlayer = index$
|
|
36931
|
+
exports.InvitationRepository = index$4;
|
|
36932
|
+
exports.LiveReactionRepository = index$3;
|
|
36933
|
+
exports.LiveStreamPlayer = index$8;
|
|
35669
36934
|
exports.MessageContentType = MessageContentType;
|
|
35670
|
-
exports.MessageRepository = index$
|
|
35671
|
-
exports.PollRepository = index$
|
|
36935
|
+
exports.MessageRepository = index$o;
|
|
36936
|
+
exports.PollRepository = index$9;
|
|
35672
36937
|
exports.PostContentType = PostContentType;
|
|
35673
|
-
exports.PostRepository = index$
|
|
36938
|
+
exports.PostRepository = index$c;
|
|
35674
36939
|
exports.PostStructureType = PostStructureType;
|
|
35675
|
-
exports.ProductRepository = index;
|
|
35676
|
-
exports.ReactionRepository = index$
|
|
35677
|
-
exports.RoomPresenceRepository = index$
|
|
35678
|
-
exports.RoomRepository = index$
|
|
35679
|
-
exports.StoryRepository = index$
|
|
35680
|
-
exports.StreamRepository = index$
|
|
35681
|
-
exports.SubChannelRepository = index$
|
|
35682
|
-
exports.UserRepository = index$
|
|
36940
|
+
exports.ProductRepository = index$1;
|
|
36941
|
+
exports.ReactionRepository = index$p;
|
|
36942
|
+
exports.RoomPresenceRepository = index$a;
|
|
36943
|
+
exports.RoomRepository = index$d;
|
|
36944
|
+
exports.StoryRepository = index$7;
|
|
36945
|
+
exports.StreamRepository = index$b;
|
|
36946
|
+
exports.SubChannelRepository = index$n;
|
|
36947
|
+
exports.UserRepository = index$r;
|
|
35683
36948
|
exports.VERSION = VERSION;
|
|
35684
36949
|
exports.VideoResolution = VideoResolution;
|
|
35685
36950
|
exports.VideoSize = VideoSize;
|
|
@@ -35741,7 +37006,7 @@ exports.isPaged = isPaged;
|
|
|
35741
37006
|
exports.isReportedByMe = isReportedByMe;
|
|
35742
37007
|
exports.isSkip = isSkip;
|
|
35743
37008
|
exports.mergeInCache = mergeInCache;
|
|
35744
|
-
exports.notificationTray = index$
|
|
37009
|
+
exports.notificationTray = index$5;
|
|
35745
37010
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
35746
37011
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
35747
37012
|
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|