@amityco/ts-sdk-react-native 7.29.0 → 7.30.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/errors.d.ts +4 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +13 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +11 -0
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/event.d.ts +1 -1
- package/dist/@types/domains/event.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +2 -2
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +101 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/events/onUserDeleted.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/tests/integrations/getChannelsSortByLastMessage.integration.test.d.ts +2 -0
- package/dist/channelRepository/observers/tests/integrations/getChannelsSortByLastMessage.integration.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/channelActivityOnLoginHandler.d.ts +16 -0
- package/dist/channelRepository/utils/channelActivityOnLoginHandler.d.ts.map +1 -0
- package/dist/channelRepository/utils/tests/integrations/channelActivity.integration.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/integrations/channelActivity.integration.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/tests/updateChannelActivityTimestamps.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/updateChannelActivityTimestamps.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/updateChannelActivityTimestamps.d.ts +42 -0
- package/dist/channelRepository/utils/updateChannelActivityTimestamps.d.ts.map +1 -0
- package/dist/client/api/resumeSession.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/commentRepository/api/flagComment.d.ts +72 -5
- package/dist/commentRepository/api/flagComment.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/flagCommentWithOptions.d.ts +13 -0
- package/dist/commentRepository/internalApi/flagCommentWithOptions.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/flagCommentWithReasonString.d.ts +17 -0
- package/dist/commentRepository/internalApi/flagCommentWithReasonString.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/index.d.ts +2 -0
- package/dist/commentRepository/internalApi/index.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithOptions.integration.test.d.ts +2 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithOptions.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithReasonString.integration.test.d.ts +2 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.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/microtasks.d.ts.map +1 -1
- package/dist/core/query/sorting.d.ts +10 -0
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/core/query/tests/sorting.test.d.ts +2 -0
- package/dist/core/query/tests/sorting.test.d.ts.map +1 -0
- package/dist/core/tests/microtasks.test.d.ts +2 -0
- package/dist/core/tests/microtasks.test.d.ts.map +1 -0
- package/dist/core/transports/tests/integration/serverErrorCodes.integration.test.d.ts +2 -0
- package/dist/core/transports/tests/integration/serverErrorCodes.integration.test.d.ts.map +1 -0
- package/dist/group/utils/withUser.d.ts +3 -3
- package/dist/group/utils/withUser.d.ts.map +1 -1
- package/dist/index.cjs.js +1258 -217
- package/dist/index.esm.js +1259 -219
- package/dist/index.umd.js +1 -1
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/flagMessage.d.ts +73 -6
- package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/flagMessageWithOptions.d.ts +13 -0
- package/dist/messageRepository/internalApi/flagMessageWithOptions.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/flagMessageWithReasonString.d.ts +18 -0
- package/dist/messageRepository/internalApi/flagMessageWithReasonString.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithOptions.integration.test.d.ts +2 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithOptions.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithReasonString.integration.test.d.ts +2 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/postRepository/api/flagPost.d.ts +73 -6
- package/dist/postRepository/api/flagPost.d.ts.map +1 -1
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts +2 -0
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts.map +1 -0
- package/dist/postRepository/api/tests/integration/setup.d.ts +3 -3
- package/dist/postRepository/internalApi/flagPostWithOptions.d.ts +13 -0
- package/dist/postRepository/internalApi/flagPostWithOptions.d.ts.map +1 -0
- package/dist/postRepository/internalApi/flagPostWithReasonString.d.ts +17 -0
- package/dist/postRepository/internalApi/flagPostWithReasonString.d.ts.map +1 -0
- package/dist/postRepository/internalApi/index.d.ts +2 -0
- package/dist/postRepository/internalApi/index.d.ts.map +1 -1
- package/dist/postRepository/internalApi/tests/integration/flagPostWithOptions.integration.test.d.ts +2 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithOptions.integration.test.d.ts.map +1 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithReasonString.integration.test.d.ts +2 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/report/api/isReportedByMe.d.ts.map +1 -1
- package/dist/userRepository/api/flagUser.d.ts +51 -10
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/flagUserBehavior.d.ts +29 -0
- package/dist/userRepository/api/flagUserBehavior.d.ts.map +1 -0
- package/dist/userRepository/api/flagUserProfile.d.ts +29 -0
- package/dist/userRepository/api/flagUserProfile.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +2 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts +12 -4
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts.map +1 -1
- package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/unflagUser.d.ts +27 -4
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
- package/dist/userRepository/api/updateUser.d.ts.map +1 -1
- package/dist/userRepository/internalApi/getFlagsByMe.d.ts +22 -0
- package/dist/userRepository/internalApi/getFlagsByMe.d.ts.map +1 -0
- package/dist/userRepository/internalApi/tests/getFlagsByMe.test.d.ts +2 -0
- package/dist/userRepository/internalApi/tests/getFlagsByMe.test.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts +2 -2
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts +1 -1
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getUser.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts +2 -2
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts +2 -2
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUsers.d.ts +1 -1
- package/dist/userRepository/observers/searchUsers.d.ts.map +1 -1
- package/dist/userRepository/utils/submitUserReport.d.ts +10 -0
- package/dist/userRepository/utils/submitUserReport.d.ts.map +1 -0
- package/dist/userRepository/utils/userFlagByMe.d.ts +68 -0
- package/dist/userRepository/utils/userFlagByMe.d.ts.map +1 -0
- package/dist/userRepository/utils/userReport.d.ts +50 -0
- package/dist/userRepository/utils/userReport.d.ts.map +1 -0
- package/dist/utils/bloomFilter.d.ts +14 -0
- package/dist/utils/bloomFilter.d.ts.map +1 -0
- package/dist/utils/contentFlag.d.ts +28 -0
- package/dist/utils/contentFlag.d.ts.map +1 -0
- package/dist/utils/linkedObject/tests/userLinkedObject.test.d.ts +2 -0
- package/dist/utils/linkedObject/tests/userLinkedObject.test.d.ts.map +1 -0
- package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/bloomFilter.test.d.ts +2 -0
- package/dist/utils/tests/bloomFilter.test.d.ts.map +1 -0
- package/dist/utils/tests/client.d.ts +1 -1
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +31 -10
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -2
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/message.d.ts +1 -1
- package/dist/utils/tests/dummy/token.d.ts +1 -1
- package/dist/utils/tests/dummy/user.d.ts +10 -12
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -79,6 +79,33 @@ exports.UserReportTypeEnum = void 0;
|
|
|
79
79
|
UserReportTypeEnum["AVATAR"] = "avatarFileId";
|
|
80
80
|
UserReportTypeEnum["BEHAVIOR"] = "behavior";
|
|
81
81
|
})(exports.UserReportTypeEnum || (exports.UserReportTypeEnum = {}));
|
|
82
|
+
/**
|
|
83
|
+
* The profile field a user is reported for in `UserRepository.flagUserProfile`.
|
|
84
|
+
* Each member is the backend `reportType` wire value. There is deliberately no
|
|
85
|
+
* behavior member: behavior reports need a reason and go through
|
|
86
|
+
* `UserRepository.flagUserBehavior`.
|
|
87
|
+
*/
|
|
88
|
+
exports.UserProfileFieldEnum = void 0;
|
|
89
|
+
(function (UserProfileFieldEnum) {
|
|
90
|
+
UserProfileFieldEnum["DISPLAY_NAME"] = "displayName";
|
|
91
|
+
UserProfileFieldEnum["DESCRIPTION"] = "description";
|
|
92
|
+
UserProfileFieldEnum["AVATAR"] = "avatarFileId";
|
|
93
|
+
})(exports.UserProfileFieldEnum || (exports.UserProfileFieldEnum = {}));
|
|
94
|
+
/**
|
|
95
|
+
* Selects which of the caller's reports `UserRepository.unflagUser` withdraws, sent as the
|
|
96
|
+
* `reportType` query parameter. The four typed members are the backend `reportType` wire
|
|
97
|
+
* values and match `UserReportTypeEnum`. `UNTYPED` selects the typeless (legacy) report,
|
|
98
|
+
* which `user.getUserFlagsByMe()` returns as `reportType: null`; it is a selector only, never
|
|
99
|
+
* stored, and the flag endpoint refuses it.
|
|
100
|
+
*/
|
|
101
|
+
exports.UserReportTypeFilterEnum = void 0;
|
|
102
|
+
(function (UserReportTypeFilterEnum) {
|
|
103
|
+
UserReportTypeFilterEnum["DISPLAY_NAME"] = "displayName";
|
|
104
|
+
UserReportTypeFilterEnum["DESCRIPTION"] = "description";
|
|
105
|
+
UserReportTypeFilterEnum["AVATAR"] = "avatarFileId";
|
|
106
|
+
UserReportTypeFilterEnum["BEHAVIOR"] = "behavior";
|
|
107
|
+
UserReportTypeFilterEnum["UNTYPED"] = "untyped";
|
|
108
|
+
})(exports.UserReportTypeFilterEnum || (exports.UserReportTypeFilterEnum = {}));
|
|
82
109
|
|
|
83
110
|
const FileType = Object.freeze({
|
|
84
111
|
FILE: 'file',
|
|
@@ -353,8 +380,8 @@ exports.AmityLiveViewerCountMode = void 0;
|
|
|
353
380
|
|
|
354
381
|
function getVersion() {
|
|
355
382
|
try {
|
|
356
|
-
// the string ''v7.
|
|
357
|
-
return 'v7.
|
|
383
|
+
// the string ''v7.30.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
384
|
+
return 'v7.30.0-cjs';
|
|
358
385
|
}
|
|
359
386
|
catch (error) {
|
|
360
387
|
return '__dev__';
|
|
@@ -1640,6 +1667,24 @@ const sortByLastUpdated = ({ updatedAt: a = 0 }, { updatedAt: b = 0 }) => new Da
|
|
|
1640
1667
|
* Sorting a collection by the items with most recent activity
|
|
1641
1668
|
*/
|
|
1642
1669
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
1670
|
+
/**
|
|
1671
|
+
* Sorting a channel collection by the time of its newest message (newest first).
|
|
1672
|
+
* Channels whose `lastMessageAt` is `null` sort last, ordered by `createdAt`
|
|
1673
|
+
* (newest first) among themselves, matching the server's `sortBy=lastMessage`
|
|
1674
|
+
* order so the local sort agrees with the page order.
|
|
1675
|
+
*/
|
|
1676
|
+
const sortByLastMessage = (a, b) => {
|
|
1677
|
+
var _a, _b;
|
|
1678
|
+
const aAt = (_a = a.lastMessageAt) !== null && _a !== void 0 ? _a : null;
|
|
1679
|
+
const bAt = (_b = b.lastMessageAt) !== null && _b !== void 0 ? _b : null;
|
|
1680
|
+
if (aAt !== null && bAt !== null)
|
|
1681
|
+
return new Date(bAt).valueOf() - new Date(aAt).valueOf();
|
|
1682
|
+
if (aAt !== null)
|
|
1683
|
+
return -1;
|
|
1684
|
+
if (bAt !== null)
|
|
1685
|
+
return 1;
|
|
1686
|
+
return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf();
|
|
1687
|
+
};
|
|
1643
1688
|
/**
|
|
1644
1689
|
* Filter items by untilAt timestamp based on sort direction
|
|
1645
1690
|
* - For 'lastCreated' (newest first): untilAt acts as lower bound, excludes items older than boundary
|
|
@@ -1724,8 +1769,13 @@ const scheduleTask = (task) => {
|
|
|
1724
1769
|
clearTimeout(timer);
|
|
1725
1770
|
tasks.push(task);
|
|
1726
1771
|
timer = setTimeout(() => {
|
|
1727
|
-
|
|
1772
|
+
// Swap the queue out before running it. A task that schedules another task
|
|
1773
|
+
// while the batch runs (an event handler that fires an event) must land in
|
|
1774
|
+
// a fresh queue and its own timer, not in the array being drained and then
|
|
1775
|
+
// discarded.
|
|
1776
|
+
const batch = tasks;
|
|
1728
1777
|
tasks = [];
|
|
1778
|
+
batch.forEach(fn => fn());
|
|
1729
1779
|
}, 0);
|
|
1730
1780
|
};
|
|
1731
1781
|
|
|
@@ -1823,18 +1873,434 @@ async function modifyMqttConnection() {
|
|
|
1823
1873
|
}
|
|
1824
1874
|
}
|
|
1825
1875
|
|
|
1876
|
+
class SessionWatcher {
|
|
1877
|
+
constructor() {
|
|
1878
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
1879
|
+
this._listener = new Map();
|
|
1880
|
+
}
|
|
1881
|
+
onSessionStateChange(callback) {
|
|
1882
|
+
this._listener.set(callback, callback);
|
|
1883
|
+
return () => {
|
|
1884
|
+
this._listener.delete(callback);
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
setSessionState(state, reason) {
|
|
1888
|
+
if (this._sessionState === state)
|
|
1889
|
+
return;
|
|
1890
|
+
this._sessionState = state;
|
|
1891
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
1892
|
+
}
|
|
1893
|
+
destroy() {
|
|
1894
|
+
this._listener.clear();
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
let instance$b;
|
|
1898
|
+
var SessionWatcher$1 = {
|
|
1899
|
+
getInstance: () => {
|
|
1900
|
+
if (!instance$b) {
|
|
1901
|
+
instance$b = new SessionWatcher();
|
|
1902
|
+
}
|
|
1903
|
+
return instance$b;
|
|
1904
|
+
},
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* ```js
|
|
1909
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk-react-native'
|
|
1910
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
1911
|
+
* // ...
|
|
1912
|
+
* })
|
|
1913
|
+
* ```
|
|
1914
|
+
*
|
|
1915
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
1916
|
+
*
|
|
1917
|
+
* @param callback The function to call when the event was fired
|
|
1918
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
1919
|
+
*
|
|
1920
|
+
* @category Client Events
|
|
1921
|
+
*/
|
|
1922
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* ```js
|
|
1926
|
+
* import { getFlagsByMe } from '~/userRepository/internalApi/getFlagsByMe'
|
|
1927
|
+
* const { isFlagByMe, flags } = await getFlagsByMe('userId')
|
|
1928
|
+
* ```
|
|
1929
|
+
*
|
|
1930
|
+
* The v4 read behind `user.getUserFlagsByMe()`, the background confirm of
|
|
1931
|
+
* `user.isFlaggedByMe`, and the deprecated `UserRepository.isUserFlaggedByMe`:
|
|
1932
|
+
* `GET /api/v4/users/:userId/isFlagByMe`, returned as received. Nothing is filtered, cached or
|
|
1933
|
+
* persisted here, and `hashFlag` is not consulted.
|
|
1934
|
+
* This is the Web counterpart of iOS `ASCUserService.getFlagsByMe` and Android
|
|
1935
|
+
* `UserRepository.getFlagsByMe`, kept apart from the deprecated public function so the
|
|
1936
|
+
* user-object read does not change if that function ever does.
|
|
1937
|
+
*
|
|
1938
|
+
* @param userId The ID of the user whose reports by the caller are read
|
|
1939
|
+
* @returns the caller's {@link Amity.UserFlagByMe} on that user
|
|
1940
|
+
*
|
|
1941
|
+
* @category Private
|
|
1942
|
+
* @async
|
|
1943
|
+
*/
|
|
1944
|
+
const getFlagsByMe = async (userId) => {
|
|
1945
|
+
const client = getActiveClient();
|
|
1946
|
+
client.log('user/getFlagsByMe', userId);
|
|
1947
|
+
const { data } = await client.http.get(`/api/v4/users/${encodeURIComponent(userId)}/isFlagByMe`);
|
|
1948
|
+
return data;
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
/* eslint-disable no-bitwise */
|
|
1952
|
+
/**
|
|
1953
|
+
* Client-side test of the `hashFlag` Bloom filter the backend attaches to flaggable objects.
|
|
1954
|
+
*
|
|
1955
|
+
* The filter holds the ids of every user who flagged the object: `bits` is its size, `hashes`
|
|
1956
|
+
* the number of hash functions per id and `hash` the bit array, base64-encoded. This is a port
|
|
1957
|
+
* of the test iOS (`_BloomFilter`) and Android (`EkoBloomFilter`) already run: FNV-1a 32-bit
|
|
1958
|
+
* over the UTF-8 bytes of the id with seeds `0` and `1576284489`, combined by double hashing
|
|
1959
|
+
* (`(a + i·b) mod bits`). A Bloom filter has no false negatives, so `false` is exact; `true`
|
|
1960
|
+
* means "probably", because another id's hashes may have set the same bits. The filter knows
|
|
1961
|
+
* nothing about report types.
|
|
1962
|
+
*/
|
|
1963
|
+
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
1964
|
+
const FNV_PRIME = 16777619;
|
|
1965
|
+
const SECOND_SEED = 1576284489;
|
|
1966
|
+
/** FNV-1a with the same mixing step and signed-byte handling as the native SDKs. */
|
|
1967
|
+
const fnv1a = (bytes, seed) => {
|
|
1968
|
+
let a = (FNV_OFFSET_BASIS ^ seed) >>> 0;
|
|
1969
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
1970
|
+
// Bytes are `char` on iOS and `byte` on Android: both signed, so 0x80..0xff sign-extend.
|
|
1971
|
+
const byte = bytes[i] > 127 ? bytes[i] - 256 : bytes[i];
|
|
1972
|
+
a = Math.imul((a ^ byte) >>> 0, FNV_PRIME) >>> 0;
|
|
1973
|
+
}
|
|
1974
|
+
a = (a + (a << 13)) >>> 0;
|
|
1975
|
+
a = (a ^ (a >>> 7)) >>> 0;
|
|
1976
|
+
a = (a + (a << 3)) >>> 0;
|
|
1977
|
+
a = (a ^ (a >>> 17)) >>> 0;
|
|
1978
|
+
a = (a + (a << 5)) >>> 0;
|
|
1979
|
+
return a;
|
|
1980
|
+
};
|
|
1981
|
+
/** Bit positions for `value`, reproducing the native SDKs' signed 32-bit arithmetic. */
|
|
1982
|
+
const locationsFor = (value, bits, hashes) => {
|
|
1983
|
+
const bytes = jsBase64.toUint8Array(jsBase64.encode(value)); // UTF-8 bytes of the id
|
|
1984
|
+
const a = fnv1a(bytes, 0) | 0;
|
|
1985
|
+
const b = fnv1a(bytes, SECOND_SEED) | 0;
|
|
1986
|
+
const locations = [];
|
|
1987
|
+
let x = a % bits;
|
|
1988
|
+
for (let i = 0; i < hashes; i += 1) {
|
|
1989
|
+
locations.push(x < 0 ? x + bits : x);
|
|
1990
|
+
x = ((x + b) | 0) % bits;
|
|
1991
|
+
}
|
|
1992
|
+
return locations;
|
|
1993
|
+
};
|
|
1994
|
+
/** Standard or URL-safe base64, padding optional. Anything else is not a filter we can read. */
|
|
1995
|
+
const BASE64 = /^[A-Za-z0-9+/_-]*={0,2}$/;
|
|
1996
|
+
/**
|
|
1997
|
+
* Whether `value` is probably in the filter. `false` is exact; `true` means "maybe", which may be
|
|
1998
|
+
* a false positive. `null` (the server's value when nobody has flagged the object), a missing
|
|
1999
|
+
* filter or a missing value answer `false`.
|
|
2000
|
+
*
|
|
2001
|
+
* A filter that cannot be read answers `true` ("maybe") and never throws, so the caller asks the
|
|
2002
|
+
* server instead of trusting a "definitely not" it cannot back up (REQ-017): `bits` or `hashes`
|
|
2003
|
+
* not a positive integer, a `hash` that is not base64, or a `hash` shorter than `ceil(bits / 8)`
|
|
2004
|
+
* bytes.
|
|
2005
|
+
*/
|
|
2006
|
+
const testBloomFilter = (hashFlag, value) => {
|
|
2007
|
+
if (!hashFlag || !value)
|
|
2008
|
+
return false;
|
|
2009
|
+
const { bits, hashes, hash } = hashFlag;
|
|
2010
|
+
if (!Number.isInteger(bits) || bits <= 0)
|
|
2011
|
+
return true;
|
|
2012
|
+
if (!Number.isInteger(hashes) || hashes <= 0)
|
|
2013
|
+
return true;
|
|
2014
|
+
if (typeof hash !== 'string' || !BASE64.test(hash))
|
|
2015
|
+
return true;
|
|
2016
|
+
let buckets;
|
|
2017
|
+
try {
|
|
2018
|
+
buckets = jsBase64.toUint8Array(hash);
|
|
2019
|
+
}
|
|
2020
|
+
catch (_a) {
|
|
2021
|
+
return true;
|
|
2022
|
+
}
|
|
2023
|
+
if (buckets.length < Math.ceil(bits / 8))
|
|
2024
|
+
return true;
|
|
2025
|
+
const locations = locationsFor(value, bits, hashes);
|
|
2026
|
+
for (let i = 0; i < locations.length; i += 1) {
|
|
2027
|
+
const index = Math.floor(locations[i] / 8);
|
|
2028
|
+
const bit = 1 << locations[i] % 8;
|
|
2029
|
+
if ((buckets[index] & bit) === 0)
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
return true;
|
|
2033
|
+
};
|
|
2034
|
+
|
|
2035
|
+
/**
|
|
2036
|
+
* Flag state of the current user on a target user, behind `Amity.User.isFlaggedByMe` and
|
|
2037
|
+
* `Amity.User.getUserFlagsByMe()` (`user.check_flag_by_me` v1, REQ-011, REQ-012, REQ-016).
|
|
2038
|
+
*
|
|
2039
|
+
* `hashFlag` is a Bloom filter of reporter ids. "Definitely not" is exact. "Maybe" can be a
|
|
2040
|
+
* false positive caused by other reporters, so the SDK confirms it with the server once per
|
|
2041
|
+
* `hashFlag` value and records the answer in the cache under its own key, never on the user's
|
|
2042
|
+
* cache row (REQ-015). Observers are told through `local.user.flagConfirmed` when a recorded
|
|
2043
|
+
* answer changes what a user object would show.
|
|
2044
|
+
*
|
|
2045
|
+
* Not exported from the public API.
|
|
2046
|
+
*/
|
|
2047
|
+
/** Confirms for the same user are at least this far apart, as Android's `EkoFlag.expired`. */
|
|
2048
|
+
const FLAG_CONFIRM_INTERVAL = 1000;
|
|
2049
|
+
const cacheKey = (userId) => ['userFlagByMe', 'get', userId];
|
|
2050
|
+
const lastConfirmAt = new Map();
|
|
2051
|
+
/**
|
|
2052
|
+
* Bumped by the current user's own flag and unflag. A confirm or exact read that started before
|
|
2053
|
+
* one of them must not record its answer, because the write may have changed it while the
|
|
2054
|
+
* `hashFlag` stayed the same.
|
|
2055
|
+
*/
|
|
2056
|
+
const generations = new Map();
|
|
2057
|
+
const generationOf = (userId) => { var _a; return (_a = generations.get(userId)) !== null && _a !== void 0 ? _a : 0; };
|
|
2058
|
+
const bumpGeneration = (userId) => generations.set(userId, generationOf(userId) + 1);
|
|
2059
|
+
/** The current user's id, or `undefined` when there is no active client. Never throws. */
|
|
2060
|
+
const currentUserId = () => {
|
|
2061
|
+
try {
|
|
2062
|
+
return getActiveClient().userId;
|
|
2063
|
+
}
|
|
2064
|
+
catch (_a) {
|
|
2065
|
+
return undefined;
|
|
2066
|
+
}
|
|
2067
|
+
};
|
|
2068
|
+
const readRecord = (userId) => {
|
|
2069
|
+
var _a;
|
|
2070
|
+
try {
|
|
2071
|
+
return (_a = pullFromCache(cacheKey(userId))) === null || _a === void 0 ? void 0 : _a.data;
|
|
2072
|
+
}
|
|
2073
|
+
catch (_b) {
|
|
2074
|
+
return undefined;
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
/**
|
|
2078
|
+
* The server's answer recorded for this user and this exact `hashFlag`, or `undefined` when there
|
|
2079
|
+
* is none for the current user. Never throws.
|
|
2080
|
+
*/
|
|
2081
|
+
const readConfirmedFlag = (userId, hashFlag) => {
|
|
2082
|
+
const me = currentUserId();
|
|
2083
|
+
if (!me || !hashFlag || typeof hashFlag.hash !== 'string')
|
|
2084
|
+
return undefined;
|
|
2085
|
+
const record = readRecord(userId);
|
|
2086
|
+
if (!record || record.reporterId !== me || record.hash !== hashFlag.hash)
|
|
2087
|
+
return undefined;
|
|
2088
|
+
return record.isFlagByMe;
|
|
2089
|
+
};
|
|
2090
|
+
/**
|
|
2091
|
+
* The v4 request in flight per user, with the generation it started in. A confirm and an exact
|
|
2092
|
+
* read of the same user share one request; a request that started before the current user's own
|
|
2093
|
+
* flag or unflag is not joined.
|
|
2094
|
+
*/
|
|
2095
|
+
const inFlight = new Map();
|
|
2096
|
+
const requestFlagsByMe = (userId) => {
|
|
2097
|
+
const generation = generationOf(userId);
|
|
2098
|
+
const pending = inFlight.get(userId);
|
|
2099
|
+
if (pending && pending.generation === generation)
|
|
2100
|
+
return pending.promise;
|
|
2101
|
+
const promise = getFlagsByMe(userId).finally(() => {
|
|
2102
|
+
var _a;
|
|
2103
|
+
if (((_a = inFlight.get(userId)) === null || _a === void 0 ? void 0 : _a.promise) === promise)
|
|
2104
|
+
inFlight.delete(userId);
|
|
2105
|
+
});
|
|
2106
|
+
inFlight.set(userId, { generation, promise });
|
|
2107
|
+
return promise;
|
|
2108
|
+
};
|
|
2109
|
+
const notifyObservers = (userId) => fireEvent('local.user.flagConfirmed', { userId });
|
|
2110
|
+
/**
|
|
2111
|
+
* Records `isFlagByMe` for `hashFlag`. A "maybe" without a record shows `true`, so observers are
|
|
2112
|
+
* told only when the shown value changes.
|
|
2113
|
+
*/
|
|
2114
|
+
const recordFlag = (userId, hashFlag, isFlagByMe) => {
|
|
2115
|
+
var _a;
|
|
2116
|
+
const me = currentUserId();
|
|
2117
|
+
if (!me || typeof hashFlag.hash !== 'string')
|
|
2118
|
+
return;
|
|
2119
|
+
const shown = (_a = readConfirmedFlag(userId, hashFlag)) !== null && _a !== void 0 ? _a : true;
|
|
2120
|
+
const record = { reporterId: me, hash: hashFlag.hash, isFlagByMe };
|
|
2121
|
+
pushToCache(cacheKey(userId), record);
|
|
2122
|
+
if (shown !== isFlagByMe)
|
|
2123
|
+
notifyObservers(userId);
|
|
2124
|
+
};
|
|
2125
|
+
/**
|
|
2126
|
+
* Starts one background confirm of a "maybe" (REQ-016): at most one in flight per user, and
|
|
2127
|
+
* confirms for the same user at least {@link FLAG_CONFIRM_INTERVAL} apart. A failed confirm
|
|
2128
|
+
* records nothing, surfaces no error, and a later read tries again.
|
|
2129
|
+
*/
|
|
2130
|
+
const confirmFlagByMe = (userId, hashFlag) => {
|
|
2131
|
+
if (inFlight.has(userId))
|
|
2132
|
+
return;
|
|
2133
|
+
const now = Date.now();
|
|
2134
|
+
const last = lastConfirmAt.get(userId);
|
|
2135
|
+
if (last !== undefined && now - last < FLAG_CONFIRM_INTERVAL)
|
|
2136
|
+
return;
|
|
2137
|
+
const me = currentUserId();
|
|
2138
|
+
const generation = generationOf(userId);
|
|
2139
|
+
lastConfirmAt.set(userId, now);
|
|
2140
|
+
requestFlagsByMe(userId)
|
|
2141
|
+
.then(({ isFlagByMe }) => {
|
|
2142
|
+
if (currentUserId() !== me || generationOf(userId) !== generation)
|
|
2143
|
+
return;
|
|
2144
|
+
recordFlag(userId, hashFlag, isFlagByMe);
|
|
2145
|
+
})
|
|
2146
|
+
.catch(() => {
|
|
2147
|
+
// Not an answer: isFlaggedByMe stays true until a later read confirms again.
|
|
2148
|
+
});
|
|
2149
|
+
};
|
|
2150
|
+
/**
|
|
2151
|
+
* The value of `Amity.User.isFlaggedByMe` for a user object whose confirmed answer was captured
|
|
2152
|
+
* (`confirmed`) when the object was linked, so a held object never changes (REQ-014).
|
|
2153
|
+
*
|
|
2154
|
+
* - No current user, `hashFlag: null` or a missing `hashFlag`, or "definitely not": `false`.
|
|
2155
|
+
* - "Maybe" with a confirmed answer: that answer, no request.
|
|
2156
|
+
* - "Maybe" without one: `true`, and one background confirm (REQ-016).
|
|
2157
|
+
*
|
|
2158
|
+
* The linked object declares this as a getter inside an object spread, which the build compiles
|
|
2159
|
+
* to `Object.assign`, so it runs once when the user is linked and the object keeps that value.
|
|
2160
|
+
*/
|
|
2161
|
+
const isFlaggedByMeFor = (user, confirmed) => {
|
|
2162
|
+
const me = currentUserId();
|
|
2163
|
+
if (!me || !user.hashFlag || !testBloomFilter(user.hashFlag, me))
|
|
2164
|
+
return false;
|
|
2165
|
+
if (confirmed !== undefined)
|
|
2166
|
+
return confirmed;
|
|
2167
|
+
confirmFlagByMe(user.userId, user.hashFlag);
|
|
2168
|
+
return true;
|
|
2169
|
+
};
|
|
2170
|
+
const NOT_FLAGGED = { isFlagByMe: false, flags: [] };
|
|
2171
|
+
const isNotOlder = (next, current) => {
|
|
2172
|
+
var _a, _b;
|
|
2173
|
+
const nextAt = Date.parse((_a = next.updatedAt) !== null && _a !== void 0 ? _a : '');
|
|
2174
|
+
const currentAt = Date.parse((_b = current.updatedAt) !== null && _b !== void 0 ? _b : '');
|
|
2175
|
+
return Number.isNaN(nextAt) || Number.isNaN(currentAt) || nextAt >= currentAt;
|
|
2176
|
+
};
|
|
2177
|
+
/**
|
|
2178
|
+
* One `getUserFlagsByMe` closure per userId, remembering the newest user object linked for that
|
|
2179
|
+
* id. Live objects and collections compare snapshots with `isEqual`, which compares functions by
|
|
2180
|
+
* reference, so a fresh closure per linked object would re-dispatch unchanged snapshots
|
|
2181
|
+
* (REQ-015). An older snapshot linked later does not replace a newer one.
|
|
2182
|
+
*/
|
|
2183
|
+
const flagsByMeEntries = new Map();
|
|
2184
|
+
/**
|
|
2185
|
+
* `Amity.User.getUserFlagsByMe()` (REQ-012): `{ isFlagByMe: false, flags: [] }` with no request
|
|
2186
|
+
* when the newest linked user says "not flagged", including a confirmed `false`. Otherwise the
|
|
2187
|
+
* v4 read, returned as is; a confirm already in flight for the user is joined instead of sending
|
|
2188
|
+
* a second request. Its `isFlagByMe` is recorded as the confirmed answer for the
|
|
2189
|
+
* `hashFlag` it was read for; `flags[]` is never stored (REQ-009). A missing `hashFlag` is
|
|
2190
|
+
* unknown, so the server is asked.
|
|
2191
|
+
*/
|
|
2192
|
+
const readFlagsByMe = async (userId) => {
|
|
2193
|
+
var _a, _b;
|
|
2194
|
+
const me = currentUserId();
|
|
2195
|
+
const { hashFlag } = (_b = (_a = flagsByMeEntries.get(userId)) === null || _a === void 0 ? void 0 : _a.latest) !== null && _b !== void 0 ? _b : {};
|
|
2196
|
+
if (me && hashFlag !== undefined) {
|
|
2197
|
+
if (!hashFlag || !testBloomFilter(hashFlag, me))
|
|
2198
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2199
|
+
if (readConfirmedFlag(userId, hashFlag) === false)
|
|
2200
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2201
|
+
}
|
|
2202
|
+
const generation = generationOf(userId);
|
|
2203
|
+
const result = await requestFlagsByMe(userId);
|
|
2204
|
+
if (hashFlag && currentUserId() === me && generationOf(userId) === generation) {
|
|
2205
|
+
recordFlag(userId, hashFlag, result.isFlagByMe);
|
|
2206
|
+
}
|
|
2207
|
+
return result;
|
|
2208
|
+
};
|
|
2209
|
+
const getUserFlagsByMeFor = (user) => {
|
|
2210
|
+
let entry = flagsByMeEntries.get(user.userId);
|
|
2211
|
+
if (!entry) {
|
|
2212
|
+
entry = { latest: user, getUserFlagsByMe: () => readFlagsByMe(user.userId) };
|
|
2213
|
+
flagsByMeEntries.set(user.userId, entry);
|
|
2214
|
+
}
|
|
2215
|
+
else if (isNotOlder(user, entry.latest)) {
|
|
2216
|
+
entry.latest = user;
|
|
2217
|
+
}
|
|
2218
|
+
return entry.getUserFlagsByMe;
|
|
2219
|
+
};
|
|
2220
|
+
/**
|
|
2221
|
+
* The current user's own flag succeeded (REQ-016). Their report may leave `hashFlag` unchanged
|
|
2222
|
+
* when other reporters had already set all of their bits, so the answer is known: record `true`
|
|
2223
|
+
* for the `hashFlag` the response carries, or drop the answer when it carries none.
|
|
2224
|
+
*/
|
|
2225
|
+
const onFlaggedByMe = (user, userId) => {
|
|
2226
|
+
bumpGeneration(userId);
|
|
2227
|
+
if (user === null || user === void 0 ? void 0 : user.hashFlag) {
|
|
2228
|
+
recordFlag(userId, user.hashFlag, true);
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
const dropped = readRecord(userId);
|
|
2232
|
+
dropFromCache(cacheKey(userId), true);
|
|
2233
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2234
|
+
notifyObservers(userId);
|
|
2235
|
+
};
|
|
2236
|
+
/**
|
|
2237
|
+
* The current user's own unflag succeeded (`user.unflag` REQ-010, REQ-016). A per-type unflag can
|
|
2238
|
+
* leave other reports in place, so the answer is dropped, never set to `false`; the next "maybe"
|
|
2239
|
+
* is confirmed again.
|
|
2240
|
+
*/
|
|
2241
|
+
const onUnflaggedByMe = (userId) => {
|
|
2242
|
+
bumpGeneration(userId);
|
|
2243
|
+
const dropped = readRecord(userId);
|
|
2244
|
+
dropFromCache(cacheKey(userId), true);
|
|
2245
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2246
|
+
notifyObservers(userId);
|
|
2247
|
+
};
|
|
2248
|
+
/** Forgets every in-memory trace of the current user's flag state. Records live in the cache. */
|
|
2249
|
+
const resetUserFlagByMe = () => {
|
|
2250
|
+
flagsByMeEntries.clear();
|
|
2251
|
+
inFlight.clear();
|
|
2252
|
+
lastConfirmAt.clear();
|
|
2253
|
+
generations.clear();
|
|
2254
|
+
};
|
|
2255
|
+
/**
|
|
2256
|
+
* Registered through `setupLoginSubscriptions`. Every confirmed answer belongs to the current
|
|
2257
|
+
* user, so the state is cleared on logout; the records themselves go with the cache, and each
|
|
2258
|
+
* also carries the reporter's id.
|
|
2259
|
+
*/
|
|
2260
|
+
const userFlagByMeOnLoginHandler = () => {
|
|
2261
|
+
const unsubscribe = onSessionStateChange(state => {
|
|
2262
|
+
if (state === "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */ || state === "terminated" /* Amity.SessionStates.TERMINATED */) {
|
|
2263
|
+
resetUserFlagByMe();
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
return () => {
|
|
2267
|
+
unsubscribe();
|
|
2268
|
+
resetUserFlagByMe();
|
|
2269
|
+
};
|
|
2270
|
+
};
|
|
2271
|
+
/**
|
|
2272
|
+
* Called with the cached user when a recorded answer changes what that user would show, so live
|
|
2273
|
+
* objects and live collections deliver it again (REQ-016, delivery).
|
|
2274
|
+
*/
|
|
2275
|
+
const onUserFlagConfirmed = (callback) => createEventSubscriber(getActiveClient(), 'user/onUserFlagConfirmed', 'local.user.flagConfirmed', ({ userId }) => {
|
|
2276
|
+
var _a;
|
|
2277
|
+
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2278
|
+
if (user)
|
|
2279
|
+
callback(user);
|
|
2280
|
+
});
|
|
2281
|
+
|
|
1826
2282
|
const userLinkedObject = (user) => {
|
|
2283
|
+
// Captured now, so a user object the app holds never changes after a confirm (REQ-014).
|
|
2284
|
+
const confirmedFlagByMe = readConfirmedFlag(user.userId, user.hashFlag);
|
|
1827
2285
|
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
1828
2286
|
var _a;
|
|
1829
2287
|
if (!user.avatarFileId)
|
|
1830
|
-
return
|
|
1831
|
-
const avatar = (_a = pullFromCache([
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
`${user.avatarFileId}`,
|
|
1835
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2288
|
+
return null;
|
|
2289
|
+
const avatar = (_a = pullFromCache(['file', 'get', user.avatarFileId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2290
|
+
if (!avatar)
|
|
2291
|
+
return null;
|
|
1836
2292
|
return avatar;
|
|
1837
|
-
}
|
|
2293
|
+
},
|
|
2294
|
+
get isFlaggedByMe() {
|
|
2295
|
+
// Bloom test on this object's hashFlag: "definitely not" is exact and sends nothing.
|
|
2296
|
+
// "Maybe" returns the answer confirmed for this hashFlag, or true while one background
|
|
2297
|
+
// confirm runs (REQ-011, REQ-016). Never throws.
|
|
2298
|
+
return isFlaggedByMeFor(user, confirmedFlagByMe);
|
|
2299
|
+
},
|
|
2300
|
+
/* begin_public_function
|
|
2301
|
+
id: user.get_flags_by_me
|
|
2302
|
+
*/
|
|
2303
|
+
getUserFlagsByMe: getUserFlagsByMeFor(user) });
|
|
1838
2304
|
};
|
|
1839
2305
|
|
|
1840
2306
|
/* begin_public_function
|
|
@@ -2101,13 +2567,13 @@ class NetworkActivitiesWatcher {
|
|
|
2101
2567
|
this._listener.clear();
|
|
2102
2568
|
}
|
|
2103
2569
|
}
|
|
2104
|
-
let instance$
|
|
2570
|
+
let instance$a;
|
|
2105
2571
|
var NetworkActivitiesWatcher$1 = {
|
|
2106
2572
|
getInstance: () => {
|
|
2107
|
-
if (!instance$
|
|
2108
|
-
instance$
|
|
2573
|
+
if (!instance$a) {
|
|
2574
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
2109
2575
|
}
|
|
2110
|
-
return instance$
|
|
2576
|
+
return instance$a;
|
|
2111
2577
|
},
|
|
2112
2578
|
};
|
|
2113
2579
|
|
|
@@ -2291,54 +2757,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
2291
2757
|
return instance;
|
|
2292
2758
|
};
|
|
2293
2759
|
|
|
2294
|
-
class SessionWatcher {
|
|
2295
|
-
constructor() {
|
|
2296
|
-
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
2297
|
-
this._listener = new Map();
|
|
2298
|
-
}
|
|
2299
|
-
onSessionStateChange(callback) {
|
|
2300
|
-
this._listener.set(callback, callback);
|
|
2301
|
-
return () => {
|
|
2302
|
-
this._listener.delete(callback);
|
|
2303
|
-
};
|
|
2304
|
-
}
|
|
2305
|
-
setSessionState(state, reason) {
|
|
2306
|
-
if (this._sessionState === state)
|
|
2307
|
-
return;
|
|
2308
|
-
this._sessionState = state;
|
|
2309
|
-
this._listener.forEach(cb => cb(state, reason));
|
|
2310
|
-
}
|
|
2311
|
-
destroy() {
|
|
2312
|
-
this._listener.clear();
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
let instance$a;
|
|
2316
|
-
var SessionWatcher$1 = {
|
|
2317
|
-
getInstance: () => {
|
|
2318
|
-
if (!instance$a) {
|
|
2319
|
-
instance$a = new SessionWatcher();
|
|
2320
|
-
}
|
|
2321
|
-
return instance$a;
|
|
2322
|
-
},
|
|
2323
|
-
};
|
|
2324
|
-
|
|
2325
|
-
/**
|
|
2326
|
-
* ```js
|
|
2327
|
-
* import { onSessionStateChange } from '@amityco/ts-sdk-react-native'
|
|
2328
|
-
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
2329
|
-
* // ...
|
|
2330
|
-
* })
|
|
2331
|
-
* ```
|
|
2332
|
-
*
|
|
2333
|
-
* Fired when any {@link Amity.Client} has a session state change
|
|
2334
|
-
*
|
|
2335
|
-
* @param callback The function to call when the event was fired
|
|
2336
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
2337
|
-
*
|
|
2338
|
-
* @category Client Events
|
|
2339
|
-
*/
|
|
2340
|
-
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
2341
|
-
|
|
2342
2760
|
const TOPICS = {
|
|
2343
2761
|
[exports.AmityAutoSubscription.NETWORK]: [getNetworkTopic],
|
|
2344
2762
|
[exports.AmityAutoSubscription.CHAT]: [
|
|
@@ -2932,7 +3350,8 @@ const convertRawMembershipToMembership = (member) => {
|
|
|
2932
3350
|
if (!userCache) {
|
|
2933
3351
|
return undefined;
|
|
2934
3352
|
}
|
|
2935
|
-
|
|
3353
|
+
// Every user the SDK hands out is a linked object (isFlaggedByMe, getUserFlagsByMe, avatar).
|
|
3354
|
+
return userLinkedObject(userCache);
|
|
2936
3355
|
} });
|
|
2937
3356
|
};
|
|
2938
3357
|
/**
|
|
@@ -2966,7 +3385,7 @@ const withUser = (member, userIdProp = 'userId', userProp = 'user') => {
|
|
|
2966
3385
|
if (!userCache) {
|
|
2967
3386
|
return undefined;
|
|
2968
3387
|
}
|
|
2969
|
-
return userCache;
|
|
3388
|
+
return userLinkedObject(userCache);
|
|
2970
3389
|
} }, member);
|
|
2971
3390
|
};
|
|
2972
3391
|
/**
|
|
@@ -3120,12 +3539,19 @@ const getSubChannelMessagePreview = (subChannelId) => {
|
|
|
3120
3539
|
};
|
|
3121
3540
|
|
|
3122
3541
|
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
3123
|
-
var _a;
|
|
3124
3542
|
const messagePreview = subChannel.messagePreviewId
|
|
3125
3543
|
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
3126
3544
|
: null;
|
|
3127
3545
|
const messagePreviewWithUser = messagePreview
|
|
3128
|
-
? Object.assign(Object.assign({}, messagePreview), { user: (
|
|
3546
|
+
? Object.assign(Object.assign({}, messagePreview), { user: (() => {
|
|
3547
|
+
var _a;
|
|
3548
|
+
const internalUser = (_a = pullFromCache([
|
|
3549
|
+
'user',
|
|
3550
|
+
'get',
|
|
3551
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
3552
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3553
|
+
return internalUser ? userLinkedObject(internalUser) : undefined;
|
|
3554
|
+
})() }) : null;
|
|
3129
3555
|
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
3130
3556
|
};
|
|
3131
3557
|
|
|
@@ -8142,6 +8568,140 @@ const postCommentCountEngineOnLoginHandler = () => onSessionStateChange(state =>
|
|
|
8142
8568
|
}
|
|
8143
8569
|
});
|
|
8144
8570
|
|
|
8571
|
+
const BOTH_FIELDS = { lastActivity: true, lastMessageAt: true };
|
|
8572
|
+
/**
|
|
8573
|
+
* The channel cache is keyed by `channelInternalId`, but a message names its
|
|
8574
|
+
* channel by whichever id the producer had: the raw MQTT payload carries the
|
|
8575
|
+
* internal id, a converted `Amity.InternalMessage` carries the public id, and
|
|
8576
|
+
* the optimistic message carries the sub-channel's `channelId`. Try the direct
|
|
8577
|
+
* key first, then match any of the three ids.
|
|
8578
|
+
*/
|
|
8579
|
+
const findCachedChannel = (channelId) => {
|
|
8580
|
+
var _a, _b, _c;
|
|
8581
|
+
const direct = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8582
|
+
if (direct)
|
|
8583
|
+
return direct;
|
|
8584
|
+
return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === channelId ||
|
|
8585
|
+
data.channelId === channelId ||
|
|
8586
|
+
data.channelPublicId === channelId)) === null || _c === void 0 ? void 0 : _c.data;
|
|
8587
|
+
};
|
|
8588
|
+
const isNewer = (stored, at) => !stored || convertDateStringToTimestamp(stored) < convertDateStringToTimestamp(at);
|
|
8589
|
+
const isSameInstant = (stored, at) => !!stored && convertDateStringToTimestamp(stored) === convertDateStringToTimestamp(at);
|
|
8590
|
+
/** Pushes the changed fields in one write and emits one `local.channel.updated`. */
|
|
8591
|
+
const commit = (channel, changes) => {
|
|
8592
|
+
if (Object.keys(changes).length === 0)
|
|
8593
|
+
return false;
|
|
8594
|
+
const updated = shallowClone(channel, changes);
|
|
8595
|
+
// Write back under the key the cache actually uses (the resolver key), not
|
|
8596
|
+
// under `channel.channelId`, which can differ from `channelInternalId`.
|
|
8597
|
+
pushToCache(['channel', 'get', getResolver('channel')(updated)], updated);
|
|
8598
|
+
fireEvent('local.channel.updated', {
|
|
8599
|
+
channels: [updated],
|
|
8600
|
+
channelUsers: [],
|
|
8601
|
+
users: [],
|
|
8602
|
+
files: [],
|
|
8603
|
+
});
|
|
8604
|
+
return true;
|
|
8605
|
+
};
|
|
8606
|
+
/**
|
|
8607
|
+
* Single owner of every local write to a channel's ordering timestamps,
|
|
8608
|
+
* `lastActivity` and `lastMessageAt` (ChannelActivityService v1).
|
|
8609
|
+
*
|
|
8610
|
+
* - Monotonic per field: a field moves only when `at` is newer than the stored
|
|
8611
|
+
* value (or the stored value is `null`), so a late or replayed event never
|
|
8612
|
+
* moves a channel down the list.
|
|
8613
|
+
* - One write: both fields are read, compared and pushed in a single cache
|
|
8614
|
+
* update, followed by one `local.channel.updated` event so every open channel
|
|
8615
|
+
* collection re-sorts once.
|
|
8616
|
+
* - Server channel payloads never go through here; they overwrite unguarded.
|
|
8617
|
+
*
|
|
8618
|
+
* @returns `true` when at least one field moved
|
|
8619
|
+
* @category private
|
|
8620
|
+
*/
|
|
8621
|
+
const updateChannelActivityTimestamps = (channelId, at, fields = BOTH_FIELDS) => {
|
|
8622
|
+
const client = getActiveClient();
|
|
8623
|
+
if (!client.cache || !channelId || !at)
|
|
8624
|
+
return false;
|
|
8625
|
+
const channel = findCachedChannel(channelId);
|
|
8626
|
+
if (!channel)
|
|
8627
|
+
return false;
|
|
8628
|
+
const changes = {};
|
|
8629
|
+
if (fields.lastActivity && isNewer(channel.lastActivity, at))
|
|
8630
|
+
changes.lastActivity = at;
|
|
8631
|
+
if (fields.lastMessageAt && isNewer(channel.lastMessageAt, at))
|
|
8632
|
+
changes.lastMessageAt = at;
|
|
8633
|
+
return commit(channel, changes);
|
|
8634
|
+
};
|
|
8635
|
+
/**
|
|
8636
|
+
* Local correction for the current user's own send (ChannelActivityService v1
|
|
8637
|
+
* REQ-009, Trigger Matrix row 1b). Once the server confirms the message, each
|
|
8638
|
+
* field that still holds the device-clock `localAt` written at send time is
|
|
8639
|
+
* replaced by the server's `serverAt`, even when that is older. A field a newer
|
|
8640
|
+
* message has already moved is left alone. One write, one change notification,
|
|
8641
|
+
* nothing when neither field still holds `localAt`.
|
|
8642
|
+
*
|
|
8643
|
+
* @returns `true` when at least one field was replaced
|
|
8644
|
+
* @category private
|
|
8645
|
+
*/
|
|
8646
|
+
const confirmOwnMessage = (channelId, localAt, serverAt) => {
|
|
8647
|
+
const client = getActiveClient();
|
|
8648
|
+
if (!client.cache || !channelId || !localAt || !serverAt)
|
|
8649
|
+
return false;
|
|
8650
|
+
if (isSameInstant(localAt, serverAt))
|
|
8651
|
+
return false;
|
|
8652
|
+
const channel = findCachedChannel(channelId);
|
|
8653
|
+
if (!channel)
|
|
8654
|
+
return false;
|
|
8655
|
+
const changes = {};
|
|
8656
|
+
if (isSameInstant(channel.lastActivity, localAt))
|
|
8657
|
+
changes.lastActivity = serverAt;
|
|
8658
|
+
if (isSameInstant(channel.lastMessageAt, localAt))
|
|
8659
|
+
changes.lastMessageAt = serverAt;
|
|
8660
|
+
return commit(channel, changes);
|
|
8661
|
+
};
|
|
8662
|
+
|
|
8663
|
+
/**
|
|
8664
|
+
* Session-wide owner of the local `lastActivity` / `lastMessageAt` updates
|
|
8665
|
+
* (ChannelActivityService v1, Web migration rows W1 – W5).
|
|
8666
|
+
*
|
|
8667
|
+
* Registered once per session from `setupLoginSubscriptions` and
|
|
8668
|
+
* `resumeSession`, so the update runs whether or not a channel collection is
|
|
8669
|
+
* open, and exactly once per message however many collections are open.
|
|
8670
|
+
*
|
|
8671
|
+
* It listens to the raw events rather than `onMessageCreatedMqtt`, so it does
|
|
8672
|
+
* not duplicate that subscriber's side effects (mark-read, unread recount).
|
|
8673
|
+
*
|
|
8674
|
+
* @category private
|
|
8675
|
+
*/
|
|
8676
|
+
const channelActivityOnLoginHandler = () => {
|
|
8677
|
+
const client = getActiveClient();
|
|
8678
|
+
const disposers = [
|
|
8679
|
+
// Any user's new message, in any message feed of the channel. The raw
|
|
8680
|
+
// payload's `channelId` is the channel's internal id.
|
|
8681
|
+
createEventSubscriber(client, 'channelActivity', 'message.created', payload => {
|
|
8682
|
+
payload.messages.forEach(message => {
|
|
8683
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8684
|
+
});
|
|
8685
|
+
}),
|
|
8686
|
+
// The current user's own send fires this three times: with the optimistic
|
|
8687
|
+
// message at send time (Syncing), on the create response (Synced), and on
|
|
8688
|
+
// failure (Error). The device-clock time of the Syncing / Error fires was
|
|
8689
|
+
// already applied synchronously in createMessageOptimistic, and replaying it
|
|
8690
|
+
// here could undo the server correction made on the response
|
|
8691
|
+
// (confirmOwnMessage). Only the server-confirmed fire goes through the guard.
|
|
8692
|
+
createEventSubscriber(client, 'channelActivity', 'local.message.created', payload => {
|
|
8693
|
+
payload.messages.forEach(message => {
|
|
8694
|
+
if (message.syncState !== "synced" /* Amity.SyncState.Synced */)
|
|
8695
|
+
return;
|
|
8696
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8697
|
+
});
|
|
8698
|
+
}),
|
|
8699
|
+
];
|
|
8700
|
+
return () => {
|
|
8701
|
+
disposers.forEach(fn => fn());
|
|
8702
|
+
};
|
|
8703
|
+
};
|
|
8704
|
+
|
|
8145
8705
|
const EVENTS = [
|
|
8146
8706
|
'disconnected',
|
|
8147
8707
|
'error',
|
|
@@ -8331,7 +8891,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8331
8891
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8332
8892
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8333
8893
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8334
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler());
|
|
8894
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8335
8895
|
if (client.useLegacyUnreadCount) {
|
|
8336
8896
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8337
8897
|
}
|
|
@@ -9635,7 +10195,7 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
9635
10195
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9636
10196
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9637
10197
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9638
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
10198
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), channelActivityOnLoginHandler());
|
|
9639
10199
|
if (client.useLegacyUnreadCount) {
|
|
9640
10200
|
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
9641
10201
|
}
|
|
@@ -11952,7 +12512,7 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
11952
12512
|
// map users with community
|
|
11953
12513
|
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
11954
12514
|
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
11955
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
12515
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(user) : undefined });
|
|
11956
12516
|
});
|
|
11957
12517
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
11958
12518
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
@@ -11969,7 +12529,7 @@ const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
|
11969
12529
|
// map users with community
|
|
11970
12530
|
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
11971
12531
|
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
11972
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
12532
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(convertRawUserToInternalUser(user)) : undefined });
|
|
11973
12533
|
});
|
|
11974
12534
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
11975
12535
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
@@ -15394,7 +15954,7 @@ const updateUser = async (userId, patch) => {
|
|
|
15394
15954
|
ingestInCache(payload, { cachedAt });
|
|
15395
15955
|
fireEvent('user.updated', data);
|
|
15396
15956
|
return {
|
|
15397
|
-
data: payload.users.find(user => user.userId === userId),
|
|
15957
|
+
data: userLinkedObject(payload.users.find(user => user.userId === userId)),
|
|
15398
15958
|
cachedAt,
|
|
15399
15959
|
};
|
|
15400
15960
|
};
|
|
@@ -15417,19 +15977,19 @@ const buildFlagUserBody = (options) => {
|
|
|
15417
15977
|
*/
|
|
15418
15978
|
/**
|
|
15419
15979
|
* ```js
|
|
15420
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15980
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
15981
|
+
*
|
|
15982
|
+
* // Typeless report (supported).
|
|
15421
15983
|
* const flagged = await UserRepository.flagUser('userId')
|
|
15422
|
-
* const flaggedBehavior = await UserRepository.flagUser('userId', {
|
|
15423
|
-
* reportType: 'behavior',
|
|
15424
|
-
* reason: 'Harassment or bullying',
|
|
15425
|
-
* comment: 'optional free-text',
|
|
15426
|
-
* })
|
|
15427
15984
|
* ```
|
|
15428
15985
|
*
|
|
15986
|
+
* Flags a user. Two call shapes are accepted (see the overloads): id-only, which
|
|
15987
|
+
* sends no body and stays supported, and the deprecated structured options object,
|
|
15988
|
+
* whose request mapping is unchanged. New code reporting a profile field or behavior
|
|
15989
|
+
* should use `flagUserProfile` or `flagUserBehavior`.
|
|
15990
|
+
*
|
|
15429
15991
|
* @param userId The ID of the user to be flagged
|
|
15430
|
-
* @param options
|
|
15431
|
-
* body: `reportType`, `reason`, `comment`. Only non-null fields are included.
|
|
15432
|
-
* All validation is server-side; a bodyless call produces a typeless report.
|
|
15992
|
+
* @param options Deprecated report metadata; omit for a typeless report
|
|
15433
15993
|
* @returns the flagged {@link Amity.User}
|
|
15434
15994
|
*
|
|
15435
15995
|
* @category User API
|
|
@@ -15445,34 +16005,242 @@ const flagUser = async (userId, options) => {
|
|
|
15445
16005
|
if (client.cache) {
|
|
15446
16006
|
ingestInCache(payload);
|
|
15447
16007
|
}
|
|
16008
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
16009
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
16010
|
+
onFlaggedByMe(flagged, userId);
|
|
15448
16011
|
fireEvent('user.flagged', data);
|
|
15449
|
-
return (
|
|
16012
|
+
return userLinkedObject(flagged);
|
|
15450
16013
|
};
|
|
15451
16014
|
/* end_public_function */
|
|
15452
16015
|
|
|
16016
|
+
/**
|
|
16017
|
+
* Sends a validated split user report (`flagUserProfile` / `flagUserBehavior`) to the
|
|
16018
|
+
* same endpoint as `flagUser`, then persists the returned user and fires `user.flagged`
|
|
16019
|
+
* exactly as `flagUser` does, so all three calls share return, cache and event behaviour.
|
|
16020
|
+
*
|
|
16021
|
+
* Not exported from the public API.
|
|
16022
|
+
*/
|
|
16023
|
+
const submitUserReport = async (apiName, userId, body) => {
|
|
16024
|
+
var _a;
|
|
16025
|
+
const client = getActiveClient();
|
|
16026
|
+
client.log(`user/${apiName}`, { userId, body });
|
|
16027
|
+
const { data } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(userId)}`, body);
|
|
16028
|
+
const payload = prepareUserPayload(data);
|
|
16029
|
+
if (client.cache) {
|
|
16030
|
+
ingestInCache(payload);
|
|
16031
|
+
}
|
|
16032
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
16033
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
16034
|
+
onFlaggedByMe(flagged, userId);
|
|
16035
|
+
fireEvent('user.flagged', data);
|
|
16036
|
+
return userLinkedObject(flagged);
|
|
16037
|
+
};
|
|
16038
|
+
|
|
16039
|
+
/** Maximum `comment` length, in string length units, after trimming. */
|
|
16040
|
+
const USER_REPORT_COMMENT_MAX_LENGTH = 300;
|
|
16041
|
+
const PROFILE_FIELDS = Object.values(exports.UserProfileFieldEnum);
|
|
16042
|
+
const BEHAVIOR_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
16043
|
+
const REPORT_TYPE_FILTERS = Object.values(exports.UserReportTypeFilterEnum);
|
|
16044
|
+
const assertOptionsObject = (apiName, options, shape) => {
|
|
16045
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
16046
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`${shape}\``);
|
|
16047
|
+
}
|
|
16048
|
+
return options;
|
|
16049
|
+
};
|
|
16050
|
+
/**
|
|
16051
|
+
* Normalizes an optional reporter `comment`: it must be a string when supplied (`null`
|
|
16052
|
+
* is not a valid supplied comment); it is trimmed; a blank result is omitted (the
|
|
16053
|
+
* backend rejects `""`); a result longer than 300 characters is rejected before any
|
|
16054
|
+
* request. Otherwise the trimmed text is returned unchanged.
|
|
16055
|
+
*
|
|
16056
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` for a non-string or over-length comment
|
|
16057
|
+
*/
|
|
16058
|
+
const normalizeUserReportComment = (apiName, comment) => {
|
|
16059
|
+
if (comment === undefined)
|
|
16060
|
+
return undefined;
|
|
16061
|
+
if (typeof comment !== 'string') {
|
|
16062
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be a string when supplied`);
|
|
16063
|
+
}
|
|
16064
|
+
const trimmed = comment.trim();
|
|
16065
|
+
if (trimmed.length === 0)
|
|
16066
|
+
return undefined;
|
|
16067
|
+
if (trimmed.length > USER_REPORT_COMMENT_MAX_LENGTH) {
|
|
16068
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be at most ${USER_REPORT_COMMENT_MAX_LENGTH} characters after trimming`);
|
|
16069
|
+
}
|
|
16070
|
+
return trimmed;
|
|
16071
|
+
};
|
|
16072
|
+
const withComment = (body, comment) => comment === undefined ? body : Object.assign(Object.assign({}, body), { comment });
|
|
16073
|
+
/**
|
|
16074
|
+
* Validates `flagUserProfile` options and builds its request body. Untyped callers can
|
|
16075
|
+
* pass anything at runtime, so nothing is trusted from the declared type. Any `reason`
|
|
16076
|
+
* key is ignored and never sent.
|
|
16077
|
+
*
|
|
16078
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
16079
|
+
*/
|
|
16080
|
+
const toUserProfileReportBody = (options) => {
|
|
16081
|
+
const apiName = 'flagUserProfile';
|
|
16082
|
+
const { field, comment } = assertOptionsObject(apiName, options, '{ field, comment? }');
|
|
16083
|
+
if (typeof field !== 'string' || !PROFILE_FIELDS.includes(field)) {
|
|
16084
|
+
throw new ASCInvalidParameterError(`${apiName}: \`field\` must be a \`UserProfileFieldEnum\` value`);
|
|
16085
|
+
}
|
|
16086
|
+
return withComment({ reportType: field }, normalizeUserReportComment(apiName, comment));
|
|
16087
|
+
};
|
|
16088
|
+
/**
|
|
16089
|
+
* Validates `flagUserBehavior` options and builds its request body. `reason` must be one
|
|
16090
|
+
* of the nine `ContentFlagReasonEnum` values and is sent as that canonical label;
|
|
16091
|
+
* `reportType` is always `behavior`.
|
|
16092
|
+
*
|
|
16093
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
16094
|
+
*/
|
|
16095
|
+
const toUserBehaviorReportBody = (options) => {
|
|
16096
|
+
const apiName = 'flagUserBehavior';
|
|
16097
|
+
const { reason, comment } = assertOptionsObject(apiName, options, '{ reason, comment? }');
|
|
16098
|
+
if (typeof reason !== 'string' || !BEHAVIOR_REASONS.includes(reason)) {
|
|
16099
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
16100
|
+
}
|
|
16101
|
+
return withComment({ reportType: 'behavior', reason }, normalizeUserReportComment(apiName, comment));
|
|
16102
|
+
};
|
|
16103
|
+
/**
|
|
16104
|
+
* Validates the optional `{ reportType? }` of `unflagUser` and builds its query parameters.
|
|
16105
|
+
* Returns `undefined` when no `reportType` is given, so the request carries no query string
|
|
16106
|
+
* and withdraws every report the caller filed on the user. The server validates the value
|
|
16107
|
+
* too (422); this local check only saves the round-trip for the string alias, which admits
|
|
16108
|
+
* raw strings. Untyped callers can pass anything at runtime, so nothing is trusted from the
|
|
16109
|
+
* declared type.
|
|
16110
|
+
*
|
|
16111
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed or `reportType` is unknown
|
|
16112
|
+
*/
|
|
16113
|
+
const toUserReportTypeFilter = (options) => {
|
|
16114
|
+
if (options === undefined)
|
|
16115
|
+
return undefined;
|
|
16116
|
+
const apiName = 'unflagUser';
|
|
16117
|
+
const { reportType } = assertOptionsObject(apiName, options, '{ reportType? }');
|
|
16118
|
+
if (reportType === undefined)
|
|
16119
|
+
return undefined;
|
|
16120
|
+
if (typeof reportType !== 'string' || !REPORT_TYPE_FILTERS.includes(reportType)) {
|
|
16121
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reportType\` must be a \`UserReportTypeFilterEnum\` value`);
|
|
16122
|
+
}
|
|
16123
|
+
return { reportType: reportType };
|
|
16124
|
+
};
|
|
16125
|
+
|
|
16126
|
+
/* begin_public_function
|
|
16127
|
+
id: user.flag_profile
|
|
16128
|
+
*/
|
|
16129
|
+
/**
|
|
16130
|
+
* ```js
|
|
16131
|
+
* import { UserRepository, UserProfileFieldEnum } from '@amityco/ts-sdk'
|
|
16132
|
+
* const flagged = await UserRepository.flagUserProfile('userId', {
|
|
16133
|
+
* field: UserProfileFieldEnum.AVATAR,
|
|
16134
|
+
* comment: 'Nudity in profile photo',
|
|
16135
|
+
* })
|
|
16136
|
+
* ```
|
|
16137
|
+
*
|
|
16138
|
+
* Reports one of a user's profile fields (display name, description or avatar). The
|
|
16139
|
+
* call has no reason: profile reports never carry one, so the backend's reason rules
|
|
16140
|
+
* cannot be violated from here. A `reason` key passed at runtime is ignored and never sent.
|
|
16141
|
+
*
|
|
16142
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
16143
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
16144
|
+
* trimmed text is sent unchanged.
|
|
16145
|
+
*
|
|
16146
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: <field>, comment? }`.
|
|
16147
|
+
*
|
|
16148
|
+
* @param userId The ID of the user to be reported
|
|
16149
|
+
* @param options `field` is a `UserProfileFieldEnum` value; `comment` is optional free text
|
|
16150
|
+
* @returns the flagged {@link Amity.User}
|
|
16151
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, or `comment` is over 300 characters, before any request is made
|
|
16152
|
+
*
|
|
16153
|
+
* @category User API
|
|
16154
|
+
* @async
|
|
16155
|
+
* */
|
|
16156
|
+
const flagUserProfile = async (userId, options) => submitUserReport('flagUserProfile', userId, toUserProfileReportBody(options));
|
|
16157
|
+
/* end_public_function */
|
|
16158
|
+
|
|
16159
|
+
/* begin_public_function
|
|
16160
|
+
id: user.flag_behavior
|
|
16161
|
+
*/
|
|
16162
|
+
/**
|
|
16163
|
+
* ```js
|
|
16164
|
+
* import { UserRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
16165
|
+
* const flagged = await UserRepository.flagUserBehavior('userId', {
|
|
16166
|
+
* reason: ContentFlagReasonEnum.Others,
|
|
16167
|
+
* comment: 'Impersonating our brand',
|
|
16168
|
+
* })
|
|
16169
|
+
* ```
|
|
16170
|
+
*
|
|
16171
|
+
* Reports a user's behavior. `reason` is required and is one of the nine
|
|
16172
|
+
* `ContentFlagReasonEnum` values, sent as its canonical label. Reporter text, including
|
|
16173
|
+
* the explanation for `Others`, always travels in `comment`; the reason never carries text.
|
|
16174
|
+
*
|
|
16175
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
16176
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
16177
|
+
* trimmed text is sent unchanged.
|
|
16178
|
+
*
|
|
16179
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: 'behavior', reason, comment? }`.
|
|
16180
|
+
*
|
|
16181
|
+
* @param userId The ID of the user to be reported
|
|
16182
|
+
* @param options `reason` is a `ContentFlagReasonEnum` value; `comment` is optional free text
|
|
16183
|
+
* @returns the flagged {@link Amity.User}
|
|
16184
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, `reason` is missing or unknown, or `comment` is over 300 characters, before any request is made
|
|
16185
|
+
*
|
|
16186
|
+
* @category User API
|
|
16187
|
+
* @async
|
|
16188
|
+
* */
|
|
16189
|
+
const flagUserBehavior = async (userId, options) => submitUserReport('flagUserBehavior', userId, toUserBehaviorReportBody(options));
|
|
16190
|
+
/* end_public_function */
|
|
16191
|
+
|
|
15453
16192
|
/* begin_public_function
|
|
15454
16193
|
id: user.unflag
|
|
15455
16194
|
*/
|
|
15456
16195
|
/**
|
|
15457
16196
|
* ```js
|
|
15458
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15459
|
-
*
|
|
16197
|
+
* import { UserRepository, UserReportTypeFilterEnum } from '@amityco/ts-sdk'
|
|
16198
|
+
*
|
|
16199
|
+
* // Withdraw every report I filed on the user.
|
|
16200
|
+
* const unflagged = await UserRepository.unflagUser('userId')
|
|
16201
|
+
*
|
|
16202
|
+
* // Withdraw only my behavior report; my other reports on the user stay.
|
|
16203
|
+
* await UserRepository.unflagUser('userId', { reportType: UserReportTypeFilterEnum.BEHAVIOR })
|
|
16204
|
+
*
|
|
16205
|
+
* // Withdraw only my typeless (legacy) report.
|
|
16206
|
+
* await UserRepository.unflagUser('userId', { reportType: UserReportTypeFilterEnum.UNTYPED })
|
|
15460
16207
|
* ```
|
|
15461
16208
|
*
|
|
16209
|
+
* Withdraws the caller's reports on a user. Without `reportType` every report the caller
|
|
16210
|
+
* filed on that user is withdrawn, as before. With `reportType` only the caller's report
|
|
16211
|
+
* of that type is withdrawn; the caller's other reports and other users' reports are
|
|
16212
|
+
* untouched. Withdrawing a report that does not exist succeeds and changes nothing.
|
|
16213
|
+
*
|
|
16214
|
+
* The returned user is persisted to the cache, so its `hashFlag` says whether the caller
|
|
16215
|
+
* may still hold a report on the user. Do not flip a local "flagged by me" flag to `false`
|
|
16216
|
+
* after a per-type withdrawal; observe the user and read `isFlaggedByMe`, or call
|
|
16217
|
+
* `user.getUserFlagsByMe()` for the remaining per-type state (`flags`). The SDK drops the
|
|
16218
|
+
* answer it confirmed for this user, so the next "maybe" is confirmed again.
|
|
16219
|
+
*
|
|
16220
|
+
* Sends `DELETE /api/v4/me/flags/:userId`, with `?reportType=<type>` when one is given.
|
|
16221
|
+
*
|
|
15462
16222
|
* @param userId The ID of the user to unflag
|
|
15463
|
-
* @
|
|
16223
|
+
* @param options Optional; `reportType` selects a single report to withdraw. For a report that `user.getUserFlagsByMe()` lists with `reportType: null`, pass `UserReportTypeFilterEnum.UNTYPED`
|
|
16224
|
+
* @returns `true` once the server has processed the withdrawal
|
|
16225
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `reportType` is not a `UserReportTypeFilterEnum` value, before any request is made
|
|
15464
16226
|
*
|
|
15465
16227
|
* @category User API
|
|
15466
16228
|
* @async
|
|
15467
16229
|
* */
|
|
15468
|
-
const unflagUser = async (userId) => {
|
|
15469
|
-
const client = getActiveClient();
|
|
15470
|
-
client.log('user/unflag', userId);
|
|
15471
|
-
const
|
|
16230
|
+
const unflagUser = async (userId, options) => {
|
|
16231
|
+
const client = getActiveClient();
|
|
16232
|
+
client.log('user/unflag', { userId, options });
|
|
16233
|
+
const params = toUserReportTypeFilter(options);
|
|
16234
|
+
const url = `/api/v4/me/flags/${encodeURIComponent(userId)}`;
|
|
16235
|
+
const { data } = params
|
|
16236
|
+
? await client.http.delete(url, { params })
|
|
16237
|
+
: await client.http.delete(url);
|
|
15472
16238
|
const payload = prepareUserPayload(data);
|
|
15473
16239
|
if (client.cache) {
|
|
15474
16240
|
ingestInCache(payload);
|
|
15475
16241
|
}
|
|
16242
|
+
// Drop the confirmed answer; never set it to false: other reports may remain (REQ-010).
|
|
16243
|
+
onUnflaggedByMe(userId);
|
|
15476
16244
|
fireEvent('user.unflagged', data);
|
|
15477
16245
|
return !!payload;
|
|
15478
16246
|
};
|
|
@@ -15483,12 +16251,20 @@ const unflagUser = async (userId) => {
|
|
|
15483
16251
|
*/
|
|
15484
16252
|
/**
|
|
15485
16253
|
* ```js
|
|
15486
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15487
|
-
* const isFlagged = await UserRepository.isUserFlaggedByMe(
|
|
16254
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16255
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(userId)
|
|
15488
16256
|
* ```
|
|
15489
16257
|
*
|
|
15490
|
-
*
|
|
15491
|
-
*
|
|
16258
|
+
* Whether the current user has reported a user. Sends one request per call and caches
|
|
16259
|
+
* nothing.
|
|
16260
|
+
*
|
|
16261
|
+
* @deprecated Read `user.isFlaggedByMe` on an {@link Amity.User} for a yes/no hint that
|
|
16262
|
+
* usually needs no request, and call `user.getUserFlagsByMe()` for the exact answer with the
|
|
16263
|
+
* caller's reports by type. Observe the user with `UserRepository.getUser(userId, callback)`
|
|
16264
|
+
* to follow a flag or unflag.
|
|
16265
|
+
*
|
|
16266
|
+
* @param userId The ID of the user to check
|
|
16267
|
+
* @returns `true` if the current user has reported the user, `false` if not
|
|
15492
16268
|
*
|
|
15493
16269
|
* @category Report API
|
|
15494
16270
|
* @async
|
|
@@ -15496,7 +16272,7 @@ const unflagUser = async (userId) => {
|
|
|
15496
16272
|
const isUserFlaggedByMe = async (userId) => {
|
|
15497
16273
|
const client = getActiveClient();
|
|
15498
16274
|
client.log('user/isUserFlaggedByMe', userId);
|
|
15499
|
-
const {
|
|
16275
|
+
const { isFlagByMe } = await getFlagsByMe(userId);
|
|
15500
16276
|
return isFlagByMe;
|
|
15501
16277
|
};
|
|
15502
16278
|
/* end_public_function */
|
|
@@ -15736,7 +16512,7 @@ const getUser = (userId, callback) => {
|
|
|
15736
16512
|
const reactor = (response) => {
|
|
15737
16513
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
15738
16514
|
};
|
|
15739
|
-
|
|
16515
|
+
const unsubscribeUser = liveObject(userId, reactor, 'userId', getUser$1, [
|
|
15740
16516
|
onUserFetched,
|
|
15741
16517
|
onUserUpdated,
|
|
15742
16518
|
onUserDeleted$2,
|
|
@@ -15744,19 +16520,28 @@ const getUser = (userId, callback) => {
|
|
|
15744
16520
|
onUserUnflagged,
|
|
15745
16521
|
onUserFlagCleared,
|
|
15746
16522
|
]);
|
|
16523
|
+
// A confirmed flag answer leaves the cached user row unchanged, so the live object's own
|
|
16524
|
+
// dedupe would drop it. Deliver the re-linked user directly (user.check_flag_by_me REQ-016).
|
|
16525
|
+
const unsubscribeFlag = onUserFlagConfirmed(user => {
|
|
16526
|
+
if (user.userId !== userId)
|
|
16527
|
+
return;
|
|
16528
|
+
callback({ data: LinkedObject.user(user), loading: false, origin: 'event' });
|
|
16529
|
+
});
|
|
16530
|
+
return () => {
|
|
16531
|
+
unsubscribeUser();
|
|
16532
|
+
unsubscribeFlag();
|
|
16533
|
+
};
|
|
15747
16534
|
};
|
|
15748
16535
|
/* end_public_function */
|
|
15749
16536
|
|
|
15750
|
-
|
|
15751
|
-
|
|
15752
|
-
|
|
15753
|
-
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
}
|
|
15759
|
-
}
|
|
16537
|
+
var EnumUserActions;
|
|
16538
|
+
(function (EnumUserActions) {
|
|
16539
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
16540
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
16541
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
16542
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
16543
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
16544
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
15760
16545
|
|
|
15761
16546
|
class UserQueryStreamController extends QueryStreamController {
|
|
15762
16547
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -15804,14 +16589,16 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
15804
16589
|
}
|
|
15805
16590
|
}
|
|
15806
16591
|
|
|
15807
|
-
|
|
15808
|
-
(
|
|
15809
|
-
|
|
15810
|
-
|
|
15811
|
-
|
|
15812
|
-
|
|
15813
|
-
|
|
15814
|
-
|
|
16592
|
+
class UserPaginationController extends PaginationController {
|
|
16593
|
+
async getRequest(queryParams, token) {
|
|
16594
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
16595
|
+
const options = token ? { token } : { limit };
|
|
16596
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
16597
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
16598
|
+
});
|
|
16599
|
+
return queryResponse;
|
|
16600
|
+
}
|
|
16601
|
+
}
|
|
15815
16602
|
|
|
15816
16603
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
15817
16604
|
constructor(query, callback) {
|
|
@@ -15841,13 +16628,24 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
15841
16628
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
15842
16629
|
}
|
|
15843
16630
|
startSubscription() {
|
|
15844
|
-
return
|
|
15845
|
-
|
|
15846
|
-
|
|
15847
|
-
|
|
15848
|
-
|
|
15849
|
-
|
|
15850
|
-
|
|
16631
|
+
return [
|
|
16632
|
+
...this.queryStreamController.subscribeRTE([
|
|
16633
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
16634
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
16635
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
16636
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
16637
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
16638
|
+
]),
|
|
16639
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
16640
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
16641
|
+
onUserFlagConfirmed(user => {
|
|
16642
|
+
var _a;
|
|
16643
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16644
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
16645
|
+
return;
|
|
16646
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16647
|
+
}),
|
|
16648
|
+
];
|
|
15851
16649
|
}
|
|
15852
16650
|
notifyChange({ origin, loading, error }) {
|
|
15853
16651
|
var _a, _b;
|
|
@@ -15928,16 +16726,17 @@ const getUsers = (params, callback, config) => {
|
|
|
15928
16726
|
};
|
|
15929
16727
|
/* end_public_function */
|
|
15930
16728
|
|
|
15931
|
-
|
|
15932
|
-
|
|
15933
|
-
|
|
15934
|
-
|
|
15935
|
-
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
15936
|
-
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
15937
|
-
});
|
|
15938
|
-
return queryResponse;
|
|
16729
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
16730
|
+
var _a;
|
|
16731
|
+
if (!sourceModel) {
|
|
16732
|
+
return sourceModel;
|
|
15939
16733
|
}
|
|
15940
|
-
}
|
|
16734
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
16735
|
+
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16736
|
+
if (!model)
|
|
16737
|
+
return;
|
|
16738
|
+
return callback(model);
|
|
16739
|
+
});
|
|
15941
16740
|
|
|
15942
16741
|
var EnumBlockActions;
|
|
15943
16742
|
(function (EnumBlockActions) {
|
|
@@ -15993,17 +16792,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
15993
16792
|
}
|
|
15994
16793
|
}
|
|
15995
16794
|
|
|
15996
|
-
|
|
15997
|
-
|
|
15998
|
-
|
|
15999
|
-
|
|
16795
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
16796
|
+
async getRequest(queryParams, token) {
|
|
16797
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
16798
|
+
const options = token ? { token } : { limit };
|
|
16799
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
16800
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
16801
|
+
});
|
|
16802
|
+
return queryResponse;
|
|
16000
16803
|
}
|
|
16001
|
-
|
|
16002
|
-
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16003
|
-
if (!model)
|
|
16004
|
-
return;
|
|
16005
|
-
return callback(model);
|
|
16006
|
-
});
|
|
16804
|
+
}
|
|
16007
16805
|
|
|
16008
16806
|
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
16009
16807
|
constructor(query, callback) {
|
|
@@ -16313,17 +17111,6 @@ const getBlockingUsers = (callback) => {
|
|
|
16313
17111
|
};
|
|
16314
17112
|
/* end_public_function */
|
|
16315
17113
|
|
|
16316
|
-
class SearchUserPaginationController extends PaginationController {
|
|
16317
|
-
async getRequest(queryParams, token) {
|
|
16318
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
16319
|
-
const options = token ? { token } : { limit };
|
|
16320
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
16321
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
16322
|
-
});
|
|
16323
|
-
return queryResponse;
|
|
16324
|
-
}
|
|
16325
|
-
}
|
|
16326
|
-
|
|
16327
17114
|
class SearchUserQueryStreamController extends QueryStreamController {
|
|
16328
17115
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
16329
17116
|
super(query, cacheKey);
|
|
@@ -16370,6 +17157,17 @@ class SearchUserQueryStreamController extends QueryStreamController {
|
|
|
16370
17157
|
}
|
|
16371
17158
|
}
|
|
16372
17159
|
|
|
17160
|
+
class SearchUserPaginationController extends PaginationController {
|
|
17161
|
+
async getRequest(queryParams, token) {
|
|
17162
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
17163
|
+
const options = token ? { token } : { limit };
|
|
17164
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
17165
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
17166
|
+
});
|
|
17167
|
+
return queryResponse;
|
|
17168
|
+
}
|
|
17169
|
+
}
|
|
17170
|
+
|
|
16373
17171
|
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
16374
17172
|
constructor(query, callback) {
|
|
16375
17173
|
var _a;
|
|
@@ -16399,13 +17197,24 @@ class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
|
16399
17197
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16400
17198
|
}
|
|
16401
17199
|
startSubscription() {
|
|
16402
|
-
return
|
|
16403
|
-
|
|
16404
|
-
|
|
16405
|
-
|
|
16406
|
-
|
|
16407
|
-
|
|
16408
|
-
|
|
17200
|
+
return [
|
|
17201
|
+
...this.queryStreamController.subscribeRTE([
|
|
17202
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
17203
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
17204
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
17205
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
17206
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
17207
|
+
]),
|
|
17208
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
17209
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
17210
|
+
onUserFlagConfirmed(user => {
|
|
17211
|
+
var _a;
|
|
17212
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17213
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
17214
|
+
return;
|
|
17215
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17216
|
+
}),
|
|
17217
|
+
];
|
|
16409
17218
|
}
|
|
16410
17219
|
notifyChange({ origin, loading, error }) {
|
|
16411
17220
|
var _a, _b;
|
|
@@ -16624,6 +17433,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
16624
17433
|
getUserByIds: getUserByIds,
|
|
16625
17434
|
updateUser: updateUser,
|
|
16626
17435
|
flagUser: flagUser,
|
|
17436
|
+
flagUserProfile: flagUserProfile,
|
|
17437
|
+
flagUserBehavior: flagUserBehavior,
|
|
16627
17438
|
unflagUser: unflagUser,
|
|
16628
17439
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
16629
17440
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
@@ -17234,7 +18045,7 @@ const preparePostPayload = (payload) => {
|
|
|
17234
18045
|
// map users with community
|
|
17235
18046
|
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
17236
18047
|
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
17237
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
18048
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(convertRawUserToInternalUser(user)) : undefined });
|
|
17238
18049
|
});
|
|
17239
18050
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
17240
18051
|
let mappedNewStream = [];
|
|
@@ -19045,7 +19856,8 @@ const getPostReport = async ({ client, referenceId, }) => {
|
|
|
19045
19856
|
};
|
|
19046
19857
|
const getUserReport = async ({ client, referenceId, }) => {
|
|
19047
19858
|
var _a;
|
|
19048
|
-
|
|
19859
|
+
// v3 isFlagByMe is deprecated by the backend; v4 answers the same boolean plus the caller's flags.
|
|
19860
|
+
const { data } = await client.http.get(`/api/v4/users/${encodeURIComponent(referenceId)}/isFlagByMe`);
|
|
19049
19861
|
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
19050
19862
|
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
19051
19863
|
};
|
|
@@ -19662,7 +20474,7 @@ const getLocalId = () => `LOCAL_${uuid()}`;
|
|
|
19662
20474
|
// FIXME: temp solution
|
|
19663
20475
|
let uniqueId;
|
|
19664
20476
|
const createMessageOptimistic = (bundle) => {
|
|
19665
|
-
var _a, _b;
|
|
20477
|
+
var _a, _b, _c, _d;
|
|
19666
20478
|
const client = getActiveClient();
|
|
19667
20479
|
if (!client.cache)
|
|
19668
20480
|
return;
|
|
@@ -19693,9 +20505,20 @@ const createMessageOptimistic = (bundle) => {
|
|
|
19693
20505
|
}
|
|
19694
20506
|
// as reused to update created and updated time, which should be the same
|
|
19695
20507
|
const createdTime = new Date().toISOString();
|
|
19696
|
-
const message = Object.assign({
|
|
20508
|
+
const message = Object.assign({
|
|
20509
|
+
// The optimistic message must name its channel (public id) so the own-send
|
|
20510
|
+
// update can move lastActivity / lastMessageAt at send time. Take it from the
|
|
20511
|
+
// cached sub-channel; when that is not cached, resolve the sub-channel id
|
|
20512
|
+
// through the channel cache, which for a channel's default sub-channel is
|
|
20513
|
+
// the channel itself (ChannelActivityService migration row I2). A thread or
|
|
20514
|
+
// unknown channel resolves to undefined, as before.
|
|
20515
|
+
channelId: (_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.channelId) !== null && _b !== void 0 ? _b : (_c = findCachedChannel(bundle.subChannelId)) === null || _c === void 0 ? void 0 : _c.channelId, creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_d = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _d !== void 0 ? _d : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
|
|
19697
20516
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
19698
20517
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
20518
|
+
// Own-send update (ChannelActivityService row 1): move the channel at send
|
|
20519
|
+
// time, synchronously, so the confirmation on the send response always sees
|
|
20520
|
+
// this value rather than racing the scheduled local event below.
|
|
20521
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
19699
20522
|
fireEvent('local.message.created', { messages: [message] });
|
|
19700
20523
|
return message;
|
|
19701
20524
|
};
|
|
@@ -19735,6 +20558,9 @@ const createMessage = async (bundle) => {
|
|
|
19735
20558
|
if (client.cache) {
|
|
19736
20559
|
ingestInCache(data, { cachedAt });
|
|
19737
20560
|
}
|
|
20561
|
+
// The own-send update wrote the device-clock createdAt; replace it with the
|
|
20562
|
+
// server's now that the message is confirmed (ChannelActivityService REQ-009).
|
|
20563
|
+
confirmOwnMessage(optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.channelId, optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.createdAt, messages[0].createdAt);
|
|
19738
20564
|
fireEvent('local.message.created', {
|
|
19739
20565
|
messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
19740
20566
|
});
|
|
@@ -20328,23 +21154,85 @@ getDeliveredUsers.locally = (query) => {
|
|
|
20328
21154
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
20329
21155
|
};
|
|
20330
21156
|
|
|
20331
|
-
|
|
20332
|
-
id: message.flag
|
|
20333
|
-
*/
|
|
21157
|
+
const CONTENT_FLAG_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
20334
21158
|
/**
|
|
20335
|
-
*
|
|
20336
|
-
*
|
|
20337
|
-
*
|
|
20338
|
-
|
|
21159
|
+
* True when a public `flagX(id, input)` argument is the legacy shape (a reason string
|
|
21160
|
+
* or nothing). Anything else is routed to the `Amity.ContentFlagOptions` path, whose
|
|
21161
|
+
* validation rejects malformed values before any request is made.
|
|
21162
|
+
*/
|
|
21163
|
+
const isLegacyContentFlagReason = (input) => input === undefined || typeof input === 'string';
|
|
21164
|
+
/**
|
|
21165
|
+
* Validates an `Amity.ContentFlagOptions` argument. Untyped (plain JS) callers can pass
|
|
21166
|
+
* anything at runtime, so the checks do not trust the declared type: the value must be a
|
|
21167
|
+
* plain object, `reason` must be one of the nine `ContentFlagReasonEnum` values and
|
|
21168
|
+
* `detail`, when supplied, must be a string (`null` is not a valid supplied detail).
|
|
20339
21169
|
*
|
|
20340
|
-
* @param
|
|
20341
|
-
* @
|
|
20342
|
-
|
|
21170
|
+
* @param apiName used in the error message, e.g. `flagPost`
|
|
21171
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
21172
|
+
*/
|
|
21173
|
+
const validateContentFlagOptions = (apiName, options) => {
|
|
21174
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
21175
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`{ reason, detail? }\``);
|
|
21176
|
+
}
|
|
21177
|
+
const { reason, detail } = options;
|
|
21178
|
+
if (typeof reason !== 'string' || !CONTENT_FLAG_REASONS.includes(reason)) {
|
|
21179
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
21180
|
+
}
|
|
21181
|
+
if (detail !== undefined && typeof detail !== 'string') {
|
|
21182
|
+
throw new ASCInvalidParameterError(`${apiName}: \`detail\` must be a string when supplied`);
|
|
21183
|
+
}
|
|
21184
|
+
return { reason: reason, detail };
|
|
21185
|
+
};
|
|
21186
|
+
/**
|
|
21187
|
+
* Builds the request body for validated options. `detail` is forwarded unchanged (empty
|
|
21188
|
+
* and whitespace-only strings included) and omitted from the body when `undefined`; the
|
|
21189
|
+
* backend enforces the 300-character limit.
|
|
21190
|
+
*/
|
|
21191
|
+
const toContentFlagBody = ({ reason, detail }) => detail === undefined ? { reason } : { reason, detail };
|
|
21192
|
+
|
|
21193
|
+
/**
|
|
21194
|
+
* New `flagMessage(messageId, { reason, detail? })` implementation. Any category,
|
|
21195
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
21196
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
21197
|
+
* the backend enforces the 300-character limit.
|
|
20343
21198
|
*
|
|
20344
|
-
*
|
|
20345
|
-
*
|
|
20346
|
-
*
|
|
20347
|
-
|
|
21199
|
+
* Not exported from the public API. It is reached through the
|
|
21200
|
+
* `MessageRepository.flagMessage(messageId, options)` overload; see `api/flagMessage.ts`.
|
|
21201
|
+
*
|
|
21202
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
21203
|
+
*/
|
|
21204
|
+
const flagMessageWithOptions = async (messageId, options) => {
|
|
21205
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
21206
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
21207
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagMessage', options));
|
|
21208
|
+
const client = getActiveClient();
|
|
21209
|
+
client.log('message/flag', messageId);
|
|
21210
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
|
|
21211
|
+
if (client.cache) {
|
|
21212
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
21213
|
+
ingestInCache(messagePayload);
|
|
21214
|
+
}
|
|
21215
|
+
fireEvent('message.flagged', payload);
|
|
21216
|
+
return !!payload;
|
|
21217
|
+
};
|
|
21218
|
+
|
|
21219
|
+
/**
|
|
21220
|
+
* Legacy `flagMessage(messageId, reason?)` implementation, kept verbatim so existing
|
|
21221
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
21222
|
+
*
|
|
21223
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
21224
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
21225
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
21226
|
+
* (for `undefined` the message body carries `detail: undefined`, which JSON serialization omits)
|
|
21227
|
+
*
|
|
21228
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
21229
|
+
* `MessageRepository.flagMessage(messageId, reason)` overload; see `api/flagMessage.ts`.
|
|
21230
|
+
*
|
|
21231
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
21232
|
+
* `flagMessage`, which carries the deprecation tag. New code should use `flagMessageWithOptions`
|
|
21233
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
21234
|
+
*/
|
|
21235
|
+
const flagMessageWithReasonString = async (messageId, reason) => {
|
|
20348
21236
|
const client = getActiveClient();
|
|
20349
21237
|
client.log('message/flag', messageId);
|
|
20350
21238
|
const isPredefinedReason = reason &&
|
|
@@ -20361,6 +21249,42 @@ const flagMessage = async (messageId, reason) => {
|
|
|
20361
21249
|
fireEvent('message.flagged', payload);
|
|
20362
21250
|
return !!payload;
|
|
20363
21251
|
};
|
|
21252
|
+
|
|
21253
|
+
/* begin_public_function
|
|
21254
|
+
id: message.flag
|
|
21255
|
+
*/
|
|
21256
|
+
/**
|
|
21257
|
+
* ```js
|
|
21258
|
+
* import { MessageRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
21259
|
+
*
|
|
21260
|
+
* // No reason.
|
|
21261
|
+
* await MessageRepository.flagMessage(messageId)
|
|
21262
|
+
*
|
|
21263
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
21264
|
+
* await MessageRepository.flagMessage(messageId, {
|
|
21265
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
21266
|
+
* detail: 'Repeated promotional links',
|
|
21267
|
+
* })
|
|
21268
|
+
* ```
|
|
21269
|
+
*
|
|
21270
|
+
* Reports a message to moderation. Three call shapes are accepted (see the overloads):
|
|
21271
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
21272
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
21273
|
+
* so the legacy path is untouched by the new contract:
|
|
21274
|
+
*
|
|
21275
|
+
* - `undefined` or a string → `flagMessageWithReasonString` (unchanged legacy mapping)
|
|
21276
|
+
* - anything else → `flagMessageWithOptions` (validated `{ reason, detail? }`)
|
|
21277
|
+
*
|
|
21278
|
+
* @param messageId The ID of the message to flag
|
|
21279
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
21280
|
+
* @returns `true` when the report was created
|
|
21281
|
+
*
|
|
21282
|
+
* @category Message API
|
|
21283
|
+
* @async
|
|
21284
|
+
* */
|
|
21285
|
+
const flagMessage = (messageId, input) => isLegacyContentFlagReason(input)
|
|
21286
|
+
? flagMessageWithReasonString(messageId, input)
|
|
21287
|
+
: flagMessageWithOptions(messageId, input);
|
|
20364
21288
|
/* end_public_function */
|
|
20365
21289
|
|
|
20366
21290
|
/* begin_public_function
|
|
@@ -22080,6 +23004,9 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22080
23004
|
case 'lastCreated':
|
|
22081
23005
|
channels = channels.sort(sortByLastCreated);
|
|
22082
23006
|
break;
|
|
23007
|
+
case 'lastMessage':
|
|
23008
|
+
channels = channels.sort(sortByLastMessage);
|
|
23009
|
+
break;
|
|
22083
23010
|
case 'displayName':
|
|
22084
23011
|
/*
|
|
22085
23012
|
* The server returns channels with empty | null displayName's first before
|
|
@@ -22140,9 +23067,8 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22140
23067
|
objectResolverEngine.resolve(message.channelId, "channel" /* Amity.ReferenceType.CHANNEL */);
|
|
22141
23068
|
}
|
|
22142
23069
|
else {
|
|
22143
|
-
|
|
22144
|
-
|
|
22145
|
-
});
|
|
23070
|
+
// lastActivity / lastMessageAt are moved by channelActivityOnLoginHandler
|
|
23071
|
+
// (session-wide, monotonic, one write). This listener only re-sorts.
|
|
22146
23072
|
callback(message);
|
|
22147
23073
|
}
|
|
22148
23074
|
});
|
|
@@ -22160,9 +23086,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22160
23086
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22161
23087
|
if (!cacheData)
|
|
22162
23088
|
return;
|
|
22163
|
-
|
|
22164
|
-
lastActivity: message.createdAt,
|
|
22165
|
-
});
|
|
23089
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22166
23090
|
callback(message);
|
|
22167
23091
|
});
|
|
22168
23092
|
}, 'channelId', 'channel'),
|
|
@@ -22900,9 +23824,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22900
23824
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22901
23825
|
if (!cacheData)
|
|
22902
23826
|
return;
|
|
22903
|
-
|
|
22904
|
-
lastActivity: message.createdAt,
|
|
22905
|
-
});
|
|
23827
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22906
23828
|
callback(message);
|
|
22907
23829
|
});
|
|
22908
23830
|
}, 'channelId', 'channel'),
|
|
@@ -22919,9 +23841,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22919
23841
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22920
23842
|
if (!cacheData)
|
|
22921
23843
|
return;
|
|
22922
|
-
|
|
22923
|
-
lastActivity: message.createdAt,
|
|
22924
|
-
});
|
|
23844
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22925
23845
|
callback(message);
|
|
22926
23846
|
});
|
|
22927
23847
|
}, 'channelId', 'channel'),
|
|
@@ -23344,7 +24264,7 @@ const onUserDeleted$1 = (channelId) => (callback) => {
|
|
|
23344
24264
|
'get',
|
|
23345
24265
|
channelUserCacheKey,
|
|
23346
24266
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23347
|
-
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
24267
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }));
|
|
23348
24268
|
const channel = (_b = pullFromCache([
|
|
23349
24269
|
'channel',
|
|
23350
24270
|
'get',
|
|
@@ -24817,10 +25737,10 @@ const onUserDeleted = (communityId) => (callback) => {
|
|
|
24817
25737
|
'get',
|
|
24818
25738
|
communityUserCacheKey,
|
|
24819
25739
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24820
|
-
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
25740
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }));
|
|
24821
25741
|
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
24822
25742
|
callback(community, [
|
|
24823
|
-
Object.assign(Object.assign({}, cacheData), { user }),
|
|
25743
|
+
Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }),
|
|
24824
25744
|
]);
|
|
24825
25745
|
};
|
|
24826
25746
|
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
@@ -27507,23 +28427,22 @@ const declineComment = async (commentId, reason) => {
|
|
|
27507
28427
|
};
|
|
27508
28428
|
/* end_public_function */
|
|
27509
28429
|
|
|
27510
|
-
/* begin_public_function
|
|
27511
|
-
id: comment.flag
|
|
27512
|
-
*/
|
|
27513
28430
|
/**
|
|
27514
|
-
*
|
|
27515
|
-
*
|
|
27516
|
-
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
27517
|
-
* ```
|
|
28431
|
+
* Legacy `flagComment(commentId, reason?)` implementation, kept verbatim so existing
|
|
28432
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
27518
28433
|
*
|
|
27519
|
-
*
|
|
27520
|
-
*
|
|
27521
|
-
*
|
|
28434
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
28435
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
28436
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
27522
28437
|
*
|
|
27523
|
-
*
|
|
27524
|
-
*
|
|
27525
|
-
*
|
|
27526
|
-
|
|
28438
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
28439
|
+
* `CommentRepository.flagComment(commentId, reason)` overload; see `api/flagComment.ts`.
|
|
28440
|
+
*
|
|
28441
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
28442
|
+
* `flagComment`, which carries the deprecation tag. New code should use `flagCommentWithOptions`
|
|
28443
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
28444
|
+
*/
|
|
28445
|
+
const flagCommentWithReasonString = async (commentId, reason) => {
|
|
27527
28446
|
const client = getActiveClient();
|
|
27528
28447
|
client.log('comment/flagComment', commentId);
|
|
27529
28448
|
const isPredefinedReason = reason &&
|
|
@@ -27539,6 +28458,67 @@ const flagComment = async (commentId, reason) => {
|
|
|
27539
28458
|
fireEvent('comment.flagged', payload);
|
|
27540
28459
|
return !!payload;
|
|
27541
28460
|
};
|
|
28461
|
+
|
|
28462
|
+
/**
|
|
28463
|
+
* New `flagComment(commentId, { reason, detail? })` implementation. Any category,
|
|
28464
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
28465
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
28466
|
+
* the backend enforces the 300-character limit.
|
|
28467
|
+
*
|
|
28468
|
+
* Not exported from the public API. It is reached through the
|
|
28469
|
+
* `CommentRepository.flagComment(commentId, options)` overload; see `api/flagComment.ts`.
|
|
28470
|
+
*
|
|
28471
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
28472
|
+
*/
|
|
28473
|
+
const flagCommentWithOptions = async (commentId, options) => {
|
|
28474
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
28475
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
28476
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagComment', options));
|
|
28477
|
+
const client = getActiveClient();
|
|
28478
|
+
client.log('comment/flagComment', commentId);
|
|
28479
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
28480
|
+
if (client.cache) {
|
|
28481
|
+
ingestInCache(payload);
|
|
28482
|
+
}
|
|
28483
|
+
fireEvent('comment.flagged', payload);
|
|
28484
|
+
return !!payload;
|
|
28485
|
+
};
|
|
28486
|
+
|
|
28487
|
+
/* begin_public_function
|
|
28488
|
+
id: comment.flag
|
|
28489
|
+
*/
|
|
28490
|
+
/**
|
|
28491
|
+
* ```js
|
|
28492
|
+
* import { CommentRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
28493
|
+
*
|
|
28494
|
+
* // No reason: sent as Others with an empty detail.
|
|
28495
|
+
* await CommentRepository.flagComment(commentId)
|
|
28496
|
+
*
|
|
28497
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
28498
|
+
* await CommentRepository.flagComment(commentId, {
|
|
28499
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
28500
|
+
* detail: 'Repeated promotional links',
|
|
28501
|
+
* })
|
|
28502
|
+
* ```
|
|
28503
|
+
*
|
|
28504
|
+
* Reports a comment to moderation. Three call shapes are accepted (see the overloads):
|
|
28505
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
28506
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
28507
|
+
* so the legacy path is untouched by the new contract:
|
|
28508
|
+
*
|
|
28509
|
+
* - `undefined` or a string → `flagCommentWithReasonString` (unchanged legacy mapping)
|
|
28510
|
+
* - anything else → `flagCommentWithOptions` (validated `{ reason, detail? }`)
|
|
28511
|
+
*
|
|
28512
|
+
* @param commentId The ID of the comment to flag
|
|
28513
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
28514
|
+
* @returns `true` when the report was created
|
|
28515
|
+
*
|
|
28516
|
+
* @category Comment API
|
|
28517
|
+
* @async
|
|
28518
|
+
* */
|
|
28519
|
+
const flagComment = (commentId, input) => isLegacyContentFlagReason(input)
|
|
28520
|
+
? flagCommentWithReasonString(commentId, input)
|
|
28521
|
+
: flagCommentWithOptions(commentId, input);
|
|
27542
28522
|
/* end_public_function */
|
|
27543
28523
|
|
|
27544
28524
|
/* begin_public_function
|
|
@@ -29892,23 +30872,47 @@ const declinePost = async (postId) => {
|
|
|
29892
30872
|
};
|
|
29893
30873
|
/* end_public_function */
|
|
29894
30874
|
|
|
29895
|
-
/* begin_public_function
|
|
29896
|
-
id: post.flag
|
|
29897
|
-
*/
|
|
29898
30875
|
/**
|
|
29899
|
-
*
|
|
29900
|
-
*
|
|
29901
|
-
*
|
|
29902
|
-
*
|
|
30876
|
+
* New `flagPost(postId, { reason, detail? })` implementation. Any category, including
|
|
30877
|
+
* `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
30878
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
30879
|
+
* the backend enforces the 300-character limit.
|
|
29903
30880
|
*
|
|
29904
|
-
*
|
|
29905
|
-
*
|
|
29906
|
-
* @returns a boolean
|
|
30881
|
+
* Not exported from the public API. It is reached through the
|
|
30882
|
+
* `PostRepository.flagPost(postId, options)` overload; see `api/flagPost.ts`.
|
|
29907
30883
|
*
|
|
29908
|
-
* @
|
|
29909
|
-
|
|
29910
|
-
|
|
29911
|
-
|
|
30884
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
30885
|
+
*/
|
|
30886
|
+
const flagPostWithOptions = async (postId, options) => {
|
|
30887
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
30888
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
30889
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagPost', options));
|
|
30890
|
+
const client = getActiveClient();
|
|
30891
|
+
client.log('post/flagPost', postId);
|
|
30892
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
30893
|
+
if (client.cache) {
|
|
30894
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30895
|
+
}
|
|
30896
|
+
fireEvent('post.flagged', payload);
|
|
30897
|
+
return !!payload;
|
|
30898
|
+
};
|
|
30899
|
+
|
|
30900
|
+
/**
|
|
30901
|
+
* Legacy `flagPost(postId, reason?)` implementation, kept verbatim so existing
|
|
30902
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
30903
|
+
*
|
|
30904
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
30905
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
30906
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
30907
|
+
*
|
|
30908
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
30909
|
+
* `PostRepository.flagPost(postId, reason)` overload; see `api/flagPost.ts`.
|
|
30910
|
+
*
|
|
30911
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
30912
|
+
* `flagPost`, which carries the deprecation tag. New code should use `flagPostWithOptions`
|
|
30913
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
30914
|
+
*/
|
|
30915
|
+
const flagPostWithReasonString = async (postId, reason) => {
|
|
29912
30916
|
const client = getActiveClient();
|
|
29913
30917
|
client.log('post/flagPost', postId);
|
|
29914
30918
|
const isPredefinedReason = reason &&
|
|
@@ -29924,6 +30928,42 @@ const flagPost = async (postId, reason) => {
|
|
|
29924
30928
|
fireEvent('post.flagged', payload);
|
|
29925
30929
|
return !!payload;
|
|
29926
30930
|
};
|
|
30931
|
+
|
|
30932
|
+
/* begin_public_function
|
|
30933
|
+
id: post.flag
|
|
30934
|
+
*/
|
|
30935
|
+
/**
|
|
30936
|
+
* ```js
|
|
30937
|
+
* import { PostRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
30938
|
+
*
|
|
30939
|
+
* // No reason.
|
|
30940
|
+
* await PostRepository.flagPost(postId)
|
|
30941
|
+
*
|
|
30942
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
30943
|
+
* await PostRepository.flagPost(postId, {
|
|
30944
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
30945
|
+
* detail: 'Repeated promotional links',
|
|
30946
|
+
* })
|
|
30947
|
+
* ```
|
|
30948
|
+
*
|
|
30949
|
+
* Reports a post to moderation. Three call shapes are accepted (see the overloads):
|
|
30950
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
30951
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
30952
|
+
* so the legacy path is untouched by the new contract:
|
|
30953
|
+
*
|
|
30954
|
+
* - `undefined` or a string → `flagPostWithReasonString` (unchanged legacy mapping)
|
|
30955
|
+
* - anything else → `flagPostWithOptions` (validated `{ reason, detail? }`)
|
|
30956
|
+
*
|
|
30957
|
+
* @param postId The ID of the post to flag
|
|
30958
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
30959
|
+
* @returns `true` when the report was created
|
|
30960
|
+
*
|
|
30961
|
+
* @category Post API
|
|
30962
|
+
* @async
|
|
30963
|
+
* */
|
|
30964
|
+
const flagPost = (postId, input) => isLegacyContentFlagReason(input)
|
|
30965
|
+
? flagPostWithReasonString(postId, input)
|
|
30966
|
+
: flagPostWithOptions(postId, input);
|
|
29927
30967
|
/* end_public_function */
|
|
29928
30968
|
|
|
29929
30969
|
/* begin_public_function
|
|
@@ -37417,6 +38457,7 @@ exports.sortByFirstCreated = sortByFirstCreated;
|
|
|
37417
38457
|
exports.sortByFirstUpdated = sortByFirstUpdated;
|
|
37418
38458
|
exports.sortByLastActivity = sortByLastActivity;
|
|
37419
38459
|
exports.sortByLastCreated = sortByLastCreated;
|
|
38460
|
+
exports.sortByLastMessage = sortByLastMessage;
|
|
37420
38461
|
exports.sortByLastUpdated = sortByLastUpdated;
|
|
37421
38462
|
exports.sortByLocalSortingDate = sortByLocalSortingDate;
|
|
37422
38463
|
exports.sortByName = sortByName;
|