@amityco/ts-sdk-react-native 7.29.1-cb1ee02.0 → 7.30.1-61b0b52.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.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encode, decode, btoa, atob } from 'js-base64';
|
|
1
|
+
import { encode, decode, toUint8Array, btoa, atob } from 'js-base64';
|
|
2
2
|
import mitt from 'mitt';
|
|
3
3
|
import debug from 'debug';
|
|
4
4
|
import axios from 'axios';
|
|
@@ -44,6 +44,33 @@ var UserReportTypeEnum;
|
|
|
44
44
|
UserReportTypeEnum["AVATAR"] = "avatarFileId";
|
|
45
45
|
UserReportTypeEnum["BEHAVIOR"] = "behavior";
|
|
46
46
|
})(UserReportTypeEnum || (UserReportTypeEnum = {}));
|
|
47
|
+
/**
|
|
48
|
+
* The profile field a user is reported for in `UserRepository.flagUserProfile`.
|
|
49
|
+
* Each member is the backend `reportType` wire value. There is deliberately no
|
|
50
|
+
* behavior member: behavior reports need a reason and go through
|
|
51
|
+
* `UserRepository.flagUserBehavior`.
|
|
52
|
+
*/
|
|
53
|
+
var UserProfileFieldEnum;
|
|
54
|
+
(function (UserProfileFieldEnum) {
|
|
55
|
+
UserProfileFieldEnum["DISPLAY_NAME"] = "displayName";
|
|
56
|
+
UserProfileFieldEnum["DESCRIPTION"] = "description";
|
|
57
|
+
UserProfileFieldEnum["AVATAR"] = "avatarFileId";
|
|
58
|
+
})(UserProfileFieldEnum || (UserProfileFieldEnum = {}));
|
|
59
|
+
/**
|
|
60
|
+
* Selects which of the caller's reports `UserRepository.unflagUser` withdraws, sent as the
|
|
61
|
+
* `reportType` query parameter. The four typed members are the backend `reportType` wire
|
|
62
|
+
* values and match `UserReportTypeEnum`. `UNTYPED` selects the typeless (legacy) report,
|
|
63
|
+
* which `user.getUserFlagsByMe()` returns as `reportType: null`; it is a selector only, never
|
|
64
|
+
* stored, and the flag endpoint refuses it.
|
|
65
|
+
*/
|
|
66
|
+
var UserReportTypeFilterEnum;
|
|
67
|
+
(function (UserReportTypeFilterEnum) {
|
|
68
|
+
UserReportTypeFilterEnum["DISPLAY_NAME"] = "displayName";
|
|
69
|
+
UserReportTypeFilterEnum["DESCRIPTION"] = "description";
|
|
70
|
+
UserReportTypeFilterEnum["AVATAR"] = "avatarFileId";
|
|
71
|
+
UserReportTypeFilterEnum["BEHAVIOR"] = "behavior";
|
|
72
|
+
UserReportTypeFilterEnum["UNTYPED"] = "untyped";
|
|
73
|
+
})(UserReportTypeFilterEnum || (UserReportTypeFilterEnum = {}));
|
|
47
74
|
|
|
48
75
|
const FileType = Object.freeze({
|
|
49
76
|
FILE: 'file',
|
|
@@ -318,8 +345,8 @@ var AmityLiveViewerCountMode;
|
|
|
318
345
|
|
|
319
346
|
function getVersion() {
|
|
320
347
|
try {
|
|
321
|
-
// the string ''v7.
|
|
322
|
-
return 'v7.
|
|
348
|
+
// the string ''v7.30.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
349
|
+
return 'v7.30.0-esm';
|
|
323
350
|
}
|
|
324
351
|
catch (error) {
|
|
325
352
|
return '__dev__';
|
|
@@ -1605,6 +1632,24 @@ const sortByLastUpdated = ({ updatedAt: a = 0 }, { updatedAt: b = 0 }) => new Da
|
|
|
1605
1632
|
* Sorting a collection by the items with most recent activity
|
|
1606
1633
|
*/
|
|
1607
1634
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
1635
|
+
/**
|
|
1636
|
+
* Sorting a channel collection by the time of its newest message (newest first).
|
|
1637
|
+
* Channels whose `lastMessageAt` is `null` sort last, ordered by `createdAt`
|
|
1638
|
+
* (newest first) among themselves, matching the server's `sortBy=lastMessage`
|
|
1639
|
+
* order so the local sort agrees with the page order.
|
|
1640
|
+
*/
|
|
1641
|
+
const sortByLastMessage = (a, b) => {
|
|
1642
|
+
var _a, _b;
|
|
1643
|
+
const aAt = (_a = a.lastMessageAt) !== null && _a !== void 0 ? _a : null;
|
|
1644
|
+
const bAt = (_b = b.lastMessageAt) !== null && _b !== void 0 ? _b : null;
|
|
1645
|
+
if (aAt !== null && bAt !== null)
|
|
1646
|
+
return new Date(bAt).valueOf() - new Date(aAt).valueOf();
|
|
1647
|
+
if (aAt !== null)
|
|
1648
|
+
return -1;
|
|
1649
|
+
if (bAt !== null)
|
|
1650
|
+
return 1;
|
|
1651
|
+
return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf();
|
|
1652
|
+
};
|
|
1608
1653
|
/**
|
|
1609
1654
|
* Filter items by untilAt timestamp based on sort direction
|
|
1610
1655
|
* - For 'lastCreated' (newest first): untilAt acts as lower bound, excludes items older than boundary
|
|
@@ -1689,8 +1734,13 @@ const scheduleTask = (task) => {
|
|
|
1689
1734
|
clearTimeout(timer);
|
|
1690
1735
|
tasks.push(task);
|
|
1691
1736
|
timer = setTimeout(() => {
|
|
1692
|
-
|
|
1737
|
+
// Swap the queue out before running it. A task that schedules another task
|
|
1738
|
+
// while the batch runs (an event handler that fires an event) must land in
|
|
1739
|
+
// a fresh queue and its own timer, not in the array being drained and then
|
|
1740
|
+
// discarded.
|
|
1741
|
+
const batch = tasks;
|
|
1693
1742
|
tasks = [];
|
|
1743
|
+
batch.forEach(fn => fn());
|
|
1694
1744
|
}, 0);
|
|
1695
1745
|
};
|
|
1696
1746
|
|
|
@@ -1788,18 +1838,434 @@ async function modifyMqttConnection() {
|
|
|
1788
1838
|
}
|
|
1789
1839
|
}
|
|
1790
1840
|
|
|
1841
|
+
class SessionWatcher {
|
|
1842
|
+
constructor() {
|
|
1843
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
1844
|
+
this._listener = new Map();
|
|
1845
|
+
}
|
|
1846
|
+
onSessionStateChange(callback) {
|
|
1847
|
+
this._listener.set(callback, callback);
|
|
1848
|
+
return () => {
|
|
1849
|
+
this._listener.delete(callback);
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
setSessionState(state, reason) {
|
|
1853
|
+
if (this._sessionState === state)
|
|
1854
|
+
return;
|
|
1855
|
+
this._sessionState = state;
|
|
1856
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
1857
|
+
}
|
|
1858
|
+
destroy() {
|
|
1859
|
+
this._listener.clear();
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
let instance$b;
|
|
1863
|
+
var SessionWatcher$1 = {
|
|
1864
|
+
getInstance: () => {
|
|
1865
|
+
if (!instance$b) {
|
|
1866
|
+
instance$b = new SessionWatcher();
|
|
1867
|
+
}
|
|
1868
|
+
return instance$b;
|
|
1869
|
+
},
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
/**
|
|
1873
|
+
* ```js
|
|
1874
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk-react-native'
|
|
1875
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
1876
|
+
* // ...
|
|
1877
|
+
* })
|
|
1878
|
+
* ```
|
|
1879
|
+
*
|
|
1880
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
1881
|
+
*
|
|
1882
|
+
* @param callback The function to call when the event was fired
|
|
1883
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
1884
|
+
*
|
|
1885
|
+
* @category Client Events
|
|
1886
|
+
*/
|
|
1887
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
1888
|
+
|
|
1889
|
+
/**
|
|
1890
|
+
* ```js
|
|
1891
|
+
* import { getFlagsByMe } from '~/userRepository/internalApi/getFlagsByMe'
|
|
1892
|
+
* const { isFlagByMe, flags } = await getFlagsByMe('userId')
|
|
1893
|
+
* ```
|
|
1894
|
+
*
|
|
1895
|
+
* The v4 read behind `user.getUserFlagsByMe()`, the background confirm of
|
|
1896
|
+
* `user.isFlaggedByMe`, and the deprecated `UserRepository.isUserFlaggedByMe`:
|
|
1897
|
+
* `GET /api/v4/users/:userId/isFlagByMe`, returned as received. Nothing is filtered, cached or
|
|
1898
|
+
* persisted here, and `hashFlag` is not consulted.
|
|
1899
|
+
* This is the Web counterpart of iOS `ASCUserService.getFlagsByMe` and Android
|
|
1900
|
+
* `UserRepository.getFlagsByMe`, kept apart from the deprecated public function so the
|
|
1901
|
+
* user-object read does not change if that function ever does.
|
|
1902
|
+
*
|
|
1903
|
+
* @param userId The ID of the user whose reports by the caller are read
|
|
1904
|
+
* @returns the caller's {@link Amity.UserFlagByMe} on that user
|
|
1905
|
+
*
|
|
1906
|
+
* @category Private
|
|
1907
|
+
* @async
|
|
1908
|
+
*/
|
|
1909
|
+
const getFlagsByMe = async (userId) => {
|
|
1910
|
+
const client = getActiveClient();
|
|
1911
|
+
client.log('user/getFlagsByMe', userId);
|
|
1912
|
+
const { data } = await client.http.get(`/api/v4/users/${encodeURIComponent(userId)}/isFlagByMe`);
|
|
1913
|
+
return data;
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
/* eslint-disable no-bitwise */
|
|
1917
|
+
/**
|
|
1918
|
+
* Client-side test of the `hashFlag` Bloom filter the backend attaches to flaggable objects.
|
|
1919
|
+
*
|
|
1920
|
+
* The filter holds the ids of every user who flagged the object: `bits` is its size, `hashes`
|
|
1921
|
+
* the number of hash functions per id and `hash` the bit array, base64-encoded. This is a port
|
|
1922
|
+
* of the test iOS (`_BloomFilter`) and Android (`EkoBloomFilter`) already run: FNV-1a 32-bit
|
|
1923
|
+
* over the UTF-8 bytes of the id with seeds `0` and `1576284489`, combined by double hashing
|
|
1924
|
+
* (`(a + i·b) mod bits`). A Bloom filter has no false negatives, so `false` is exact; `true`
|
|
1925
|
+
* means "probably", because another id's hashes may have set the same bits. The filter knows
|
|
1926
|
+
* nothing about report types.
|
|
1927
|
+
*/
|
|
1928
|
+
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
1929
|
+
const FNV_PRIME = 16777619;
|
|
1930
|
+
const SECOND_SEED = 1576284489;
|
|
1931
|
+
/** FNV-1a with the same mixing step and signed-byte handling as the native SDKs. */
|
|
1932
|
+
const fnv1a = (bytes, seed) => {
|
|
1933
|
+
let a = (FNV_OFFSET_BASIS ^ seed) >>> 0;
|
|
1934
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
1935
|
+
// Bytes are `char` on iOS and `byte` on Android: both signed, so 0x80..0xff sign-extend.
|
|
1936
|
+
const byte = bytes[i] > 127 ? bytes[i] - 256 : bytes[i];
|
|
1937
|
+
a = Math.imul((a ^ byte) >>> 0, FNV_PRIME) >>> 0;
|
|
1938
|
+
}
|
|
1939
|
+
a = (a + (a << 13)) >>> 0;
|
|
1940
|
+
a = (a ^ (a >>> 7)) >>> 0;
|
|
1941
|
+
a = (a + (a << 3)) >>> 0;
|
|
1942
|
+
a = (a ^ (a >>> 17)) >>> 0;
|
|
1943
|
+
a = (a + (a << 5)) >>> 0;
|
|
1944
|
+
return a;
|
|
1945
|
+
};
|
|
1946
|
+
/** Bit positions for `value`, reproducing the native SDKs' signed 32-bit arithmetic. */
|
|
1947
|
+
const locationsFor = (value, bits, hashes) => {
|
|
1948
|
+
const bytes = toUint8Array(encode(value)); // UTF-8 bytes of the id
|
|
1949
|
+
const a = fnv1a(bytes, 0) | 0;
|
|
1950
|
+
const b = fnv1a(bytes, SECOND_SEED) | 0;
|
|
1951
|
+
const locations = [];
|
|
1952
|
+
let x = a % bits;
|
|
1953
|
+
for (let i = 0; i < hashes; i += 1) {
|
|
1954
|
+
locations.push(x < 0 ? x + bits : x);
|
|
1955
|
+
x = ((x + b) | 0) % bits;
|
|
1956
|
+
}
|
|
1957
|
+
return locations;
|
|
1958
|
+
};
|
|
1959
|
+
/** Standard or URL-safe base64, padding optional. Anything else is not a filter we can read. */
|
|
1960
|
+
const BASE64 = /^[A-Za-z0-9+/_-]*={0,2}$/;
|
|
1961
|
+
/**
|
|
1962
|
+
* Whether `value` is probably in the filter. `false` is exact; `true` means "maybe", which may be
|
|
1963
|
+
* a false positive. `null` (the server's value when nobody has flagged the object), a missing
|
|
1964
|
+
* filter or a missing value answer `false`.
|
|
1965
|
+
*
|
|
1966
|
+
* A filter that cannot be read answers `true` ("maybe") and never throws, so the caller asks the
|
|
1967
|
+
* server instead of trusting a "definitely not" it cannot back up (REQ-017): `bits` or `hashes`
|
|
1968
|
+
* not a positive integer, a `hash` that is not base64, or a `hash` shorter than `ceil(bits / 8)`
|
|
1969
|
+
* bytes.
|
|
1970
|
+
*/
|
|
1971
|
+
const testBloomFilter = (hashFlag, value) => {
|
|
1972
|
+
if (!hashFlag || !value)
|
|
1973
|
+
return false;
|
|
1974
|
+
const { bits, hashes, hash } = hashFlag;
|
|
1975
|
+
if (!Number.isInteger(bits) || bits <= 0)
|
|
1976
|
+
return true;
|
|
1977
|
+
if (!Number.isInteger(hashes) || hashes <= 0)
|
|
1978
|
+
return true;
|
|
1979
|
+
if (typeof hash !== 'string' || !BASE64.test(hash))
|
|
1980
|
+
return true;
|
|
1981
|
+
let buckets;
|
|
1982
|
+
try {
|
|
1983
|
+
buckets = toUint8Array(hash);
|
|
1984
|
+
}
|
|
1985
|
+
catch (_a) {
|
|
1986
|
+
return true;
|
|
1987
|
+
}
|
|
1988
|
+
if (buckets.length < Math.ceil(bits / 8))
|
|
1989
|
+
return true;
|
|
1990
|
+
const locations = locationsFor(value, bits, hashes);
|
|
1991
|
+
for (let i = 0; i < locations.length; i += 1) {
|
|
1992
|
+
const index = Math.floor(locations[i] / 8);
|
|
1993
|
+
const bit = 1 << locations[i] % 8;
|
|
1994
|
+
if ((buckets[index] & bit) === 0)
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
return true;
|
|
1998
|
+
};
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Flag state of the current user on a target user, behind `Amity.User.isFlaggedByMe` and
|
|
2002
|
+
* `Amity.User.getUserFlagsByMe()` (`user.check_flag_by_me` v1, REQ-011, REQ-012, REQ-016).
|
|
2003
|
+
*
|
|
2004
|
+
* `hashFlag` is a Bloom filter of reporter ids. "Definitely not" is exact. "Maybe" can be a
|
|
2005
|
+
* false positive caused by other reporters, so the SDK confirms it with the server once per
|
|
2006
|
+
* `hashFlag` value and records the answer in the cache under its own key, never on the user's
|
|
2007
|
+
* cache row (REQ-015). Observers are told through `local.user.flagConfirmed` when a recorded
|
|
2008
|
+
* answer changes what a user object would show.
|
|
2009
|
+
*
|
|
2010
|
+
* Not exported from the public API.
|
|
2011
|
+
*/
|
|
2012
|
+
/** Confirms for the same user are at least this far apart, as Android's `EkoFlag.expired`. */
|
|
2013
|
+
const FLAG_CONFIRM_INTERVAL = 1000;
|
|
2014
|
+
const cacheKey = (userId) => ['userFlagByMe', 'get', userId];
|
|
2015
|
+
const lastConfirmAt = new Map();
|
|
2016
|
+
/**
|
|
2017
|
+
* Bumped by the current user's own flag and unflag. A confirm or exact read that started before
|
|
2018
|
+
* one of them must not record its answer, because the write may have changed it while the
|
|
2019
|
+
* `hashFlag` stayed the same.
|
|
2020
|
+
*/
|
|
2021
|
+
const generations = new Map();
|
|
2022
|
+
const generationOf = (userId) => { var _a; return (_a = generations.get(userId)) !== null && _a !== void 0 ? _a : 0; };
|
|
2023
|
+
const bumpGeneration = (userId) => generations.set(userId, generationOf(userId) + 1);
|
|
2024
|
+
/** The current user's id, or `undefined` when there is no active client. Never throws. */
|
|
2025
|
+
const currentUserId = () => {
|
|
2026
|
+
try {
|
|
2027
|
+
return getActiveClient().userId;
|
|
2028
|
+
}
|
|
2029
|
+
catch (_a) {
|
|
2030
|
+
return undefined;
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
const readRecord = (userId) => {
|
|
2034
|
+
var _a;
|
|
2035
|
+
try {
|
|
2036
|
+
return (_a = pullFromCache(cacheKey(userId))) === null || _a === void 0 ? void 0 : _a.data;
|
|
2037
|
+
}
|
|
2038
|
+
catch (_b) {
|
|
2039
|
+
return undefined;
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
2042
|
+
/**
|
|
2043
|
+
* The server's answer recorded for this user and this exact `hashFlag`, or `undefined` when there
|
|
2044
|
+
* is none for the current user. Never throws.
|
|
2045
|
+
*/
|
|
2046
|
+
const readConfirmedFlag = (userId, hashFlag) => {
|
|
2047
|
+
const me = currentUserId();
|
|
2048
|
+
if (!me || !hashFlag || typeof hashFlag.hash !== 'string')
|
|
2049
|
+
return undefined;
|
|
2050
|
+
const record = readRecord(userId);
|
|
2051
|
+
if (!record || record.reporterId !== me || record.hash !== hashFlag.hash)
|
|
2052
|
+
return undefined;
|
|
2053
|
+
return record.isFlagByMe;
|
|
2054
|
+
};
|
|
2055
|
+
/**
|
|
2056
|
+
* The v4 request in flight per user, with the generation it started in. A confirm and an exact
|
|
2057
|
+
* read of the same user share one request; a request that started before the current user's own
|
|
2058
|
+
* flag or unflag is not joined.
|
|
2059
|
+
*/
|
|
2060
|
+
const inFlight = new Map();
|
|
2061
|
+
const requestFlagsByMe = (userId) => {
|
|
2062
|
+
const generation = generationOf(userId);
|
|
2063
|
+
const pending = inFlight.get(userId);
|
|
2064
|
+
if (pending && pending.generation === generation)
|
|
2065
|
+
return pending.promise;
|
|
2066
|
+
const promise = getFlagsByMe(userId).finally(() => {
|
|
2067
|
+
var _a;
|
|
2068
|
+
if (((_a = inFlight.get(userId)) === null || _a === void 0 ? void 0 : _a.promise) === promise)
|
|
2069
|
+
inFlight.delete(userId);
|
|
2070
|
+
});
|
|
2071
|
+
inFlight.set(userId, { generation, promise });
|
|
2072
|
+
return promise;
|
|
2073
|
+
};
|
|
2074
|
+
const notifyObservers = (userId) => fireEvent('local.user.flagConfirmed', { userId });
|
|
2075
|
+
/**
|
|
2076
|
+
* Records `isFlagByMe` for `hashFlag`. A "maybe" without a record shows `true`, so observers are
|
|
2077
|
+
* told only when the shown value changes.
|
|
2078
|
+
*/
|
|
2079
|
+
const recordFlag = (userId, hashFlag, isFlagByMe) => {
|
|
2080
|
+
var _a;
|
|
2081
|
+
const me = currentUserId();
|
|
2082
|
+
if (!me || typeof hashFlag.hash !== 'string')
|
|
2083
|
+
return;
|
|
2084
|
+
const shown = (_a = readConfirmedFlag(userId, hashFlag)) !== null && _a !== void 0 ? _a : true;
|
|
2085
|
+
const record = { reporterId: me, hash: hashFlag.hash, isFlagByMe };
|
|
2086
|
+
pushToCache(cacheKey(userId), record);
|
|
2087
|
+
if (shown !== isFlagByMe)
|
|
2088
|
+
notifyObservers(userId);
|
|
2089
|
+
};
|
|
2090
|
+
/**
|
|
2091
|
+
* Starts one background confirm of a "maybe" (REQ-016): at most one in flight per user, and
|
|
2092
|
+
* confirms for the same user at least {@link FLAG_CONFIRM_INTERVAL} apart. A failed confirm
|
|
2093
|
+
* records nothing, surfaces no error, and a later read tries again.
|
|
2094
|
+
*/
|
|
2095
|
+
const confirmFlagByMe = (userId, hashFlag) => {
|
|
2096
|
+
if (inFlight.has(userId))
|
|
2097
|
+
return;
|
|
2098
|
+
const now = Date.now();
|
|
2099
|
+
const last = lastConfirmAt.get(userId);
|
|
2100
|
+
if (last !== undefined && now - last < FLAG_CONFIRM_INTERVAL)
|
|
2101
|
+
return;
|
|
2102
|
+
const me = currentUserId();
|
|
2103
|
+
const generation = generationOf(userId);
|
|
2104
|
+
lastConfirmAt.set(userId, now);
|
|
2105
|
+
requestFlagsByMe(userId)
|
|
2106
|
+
.then(({ isFlagByMe }) => {
|
|
2107
|
+
if (currentUserId() !== me || generationOf(userId) !== generation)
|
|
2108
|
+
return;
|
|
2109
|
+
recordFlag(userId, hashFlag, isFlagByMe);
|
|
2110
|
+
})
|
|
2111
|
+
.catch(() => {
|
|
2112
|
+
// Not an answer: isFlaggedByMe stays true until a later read confirms again.
|
|
2113
|
+
});
|
|
2114
|
+
};
|
|
2115
|
+
/**
|
|
2116
|
+
* The value of `Amity.User.isFlaggedByMe` for a user object whose confirmed answer was captured
|
|
2117
|
+
* (`confirmed`) when the object was linked, so a held object never changes (REQ-014).
|
|
2118
|
+
*
|
|
2119
|
+
* - No current user, `hashFlag: null` or a missing `hashFlag`, or "definitely not": `false`.
|
|
2120
|
+
* - "Maybe" with a confirmed answer: that answer, no request.
|
|
2121
|
+
* - "Maybe" without one: `true`, and one background confirm (REQ-016).
|
|
2122
|
+
*
|
|
2123
|
+
* The linked object declares this as a getter inside an object spread, which the build compiles
|
|
2124
|
+
* to `Object.assign`, so it runs once when the user is linked and the object keeps that value.
|
|
2125
|
+
*/
|
|
2126
|
+
const isFlaggedByMeFor = (user, confirmed) => {
|
|
2127
|
+
const me = currentUserId();
|
|
2128
|
+
if (!me || !user.hashFlag || !testBloomFilter(user.hashFlag, me))
|
|
2129
|
+
return false;
|
|
2130
|
+
if (confirmed !== undefined)
|
|
2131
|
+
return confirmed;
|
|
2132
|
+
confirmFlagByMe(user.userId, user.hashFlag);
|
|
2133
|
+
return true;
|
|
2134
|
+
};
|
|
2135
|
+
const NOT_FLAGGED = { isFlagByMe: false, flags: [] };
|
|
2136
|
+
const isNotOlder = (next, current) => {
|
|
2137
|
+
var _a, _b;
|
|
2138
|
+
const nextAt = Date.parse((_a = next.updatedAt) !== null && _a !== void 0 ? _a : '');
|
|
2139
|
+
const currentAt = Date.parse((_b = current.updatedAt) !== null && _b !== void 0 ? _b : '');
|
|
2140
|
+
return Number.isNaN(nextAt) || Number.isNaN(currentAt) || nextAt >= currentAt;
|
|
2141
|
+
};
|
|
2142
|
+
/**
|
|
2143
|
+
* One `getUserFlagsByMe` closure per userId, remembering the newest user object linked for that
|
|
2144
|
+
* id. Live objects and collections compare snapshots with `isEqual`, which compares functions by
|
|
2145
|
+
* reference, so a fresh closure per linked object would re-dispatch unchanged snapshots
|
|
2146
|
+
* (REQ-015). An older snapshot linked later does not replace a newer one.
|
|
2147
|
+
*/
|
|
2148
|
+
const flagsByMeEntries = new Map();
|
|
2149
|
+
/**
|
|
2150
|
+
* `Amity.User.getUserFlagsByMe()` (REQ-012): `{ isFlagByMe: false, flags: [] }` with no request
|
|
2151
|
+
* when the newest linked user says "not flagged", including a confirmed `false`. Otherwise the
|
|
2152
|
+
* v4 read, returned as is; a confirm already in flight for the user is joined instead of sending
|
|
2153
|
+
* a second request. Its `isFlagByMe` is recorded as the confirmed answer for the
|
|
2154
|
+
* `hashFlag` it was read for; `flags[]` is never stored (REQ-009). A missing `hashFlag` is
|
|
2155
|
+
* unknown, so the server is asked.
|
|
2156
|
+
*/
|
|
2157
|
+
const readFlagsByMe = async (userId) => {
|
|
2158
|
+
var _a, _b;
|
|
2159
|
+
const me = currentUserId();
|
|
2160
|
+
const { hashFlag } = (_b = (_a = flagsByMeEntries.get(userId)) === null || _a === void 0 ? void 0 : _a.latest) !== null && _b !== void 0 ? _b : {};
|
|
2161
|
+
if (me && hashFlag !== undefined) {
|
|
2162
|
+
if (!hashFlag || !testBloomFilter(hashFlag, me))
|
|
2163
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2164
|
+
if (readConfirmedFlag(userId, hashFlag) === false)
|
|
2165
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2166
|
+
}
|
|
2167
|
+
const generation = generationOf(userId);
|
|
2168
|
+
const result = await requestFlagsByMe(userId);
|
|
2169
|
+
if (hashFlag && currentUserId() === me && generationOf(userId) === generation) {
|
|
2170
|
+
recordFlag(userId, hashFlag, result.isFlagByMe);
|
|
2171
|
+
}
|
|
2172
|
+
return result;
|
|
2173
|
+
};
|
|
2174
|
+
const getUserFlagsByMeFor = (user) => {
|
|
2175
|
+
let entry = flagsByMeEntries.get(user.userId);
|
|
2176
|
+
if (!entry) {
|
|
2177
|
+
entry = { latest: user, getUserFlagsByMe: () => readFlagsByMe(user.userId) };
|
|
2178
|
+
flagsByMeEntries.set(user.userId, entry);
|
|
2179
|
+
}
|
|
2180
|
+
else if (isNotOlder(user, entry.latest)) {
|
|
2181
|
+
entry.latest = user;
|
|
2182
|
+
}
|
|
2183
|
+
return entry.getUserFlagsByMe;
|
|
2184
|
+
};
|
|
2185
|
+
/**
|
|
2186
|
+
* The current user's own flag succeeded (REQ-016). Their report may leave `hashFlag` unchanged
|
|
2187
|
+
* when other reporters had already set all of their bits, so the answer is known: record `true`
|
|
2188
|
+
* for the `hashFlag` the response carries, or drop the answer when it carries none.
|
|
2189
|
+
*/
|
|
2190
|
+
const onFlaggedByMe = (user, userId) => {
|
|
2191
|
+
bumpGeneration(userId);
|
|
2192
|
+
if (user === null || user === void 0 ? void 0 : user.hashFlag) {
|
|
2193
|
+
recordFlag(userId, user.hashFlag, true);
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
const dropped = readRecord(userId);
|
|
2197
|
+
dropFromCache(cacheKey(userId), true);
|
|
2198
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2199
|
+
notifyObservers(userId);
|
|
2200
|
+
};
|
|
2201
|
+
/**
|
|
2202
|
+
* The current user's own unflag succeeded (`user.unflag` REQ-010, REQ-016). A per-type unflag can
|
|
2203
|
+
* leave other reports in place, so the answer is dropped, never set to `false`; the next "maybe"
|
|
2204
|
+
* is confirmed again.
|
|
2205
|
+
*/
|
|
2206
|
+
const onUnflaggedByMe = (userId) => {
|
|
2207
|
+
bumpGeneration(userId);
|
|
2208
|
+
const dropped = readRecord(userId);
|
|
2209
|
+
dropFromCache(cacheKey(userId), true);
|
|
2210
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2211
|
+
notifyObservers(userId);
|
|
2212
|
+
};
|
|
2213
|
+
/** Forgets every in-memory trace of the current user's flag state. Records live in the cache. */
|
|
2214
|
+
const resetUserFlagByMe = () => {
|
|
2215
|
+
flagsByMeEntries.clear();
|
|
2216
|
+
inFlight.clear();
|
|
2217
|
+
lastConfirmAt.clear();
|
|
2218
|
+
generations.clear();
|
|
2219
|
+
};
|
|
2220
|
+
/**
|
|
2221
|
+
* Registered through `setupLoginSubscriptions`. Every confirmed answer belongs to the current
|
|
2222
|
+
* user, so the state is cleared on logout; the records themselves go with the cache, and each
|
|
2223
|
+
* also carries the reporter's id.
|
|
2224
|
+
*/
|
|
2225
|
+
const userFlagByMeOnLoginHandler = () => {
|
|
2226
|
+
const unsubscribe = onSessionStateChange(state => {
|
|
2227
|
+
if (state === "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */ || state === "terminated" /* Amity.SessionStates.TERMINATED */) {
|
|
2228
|
+
resetUserFlagByMe();
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
return () => {
|
|
2232
|
+
unsubscribe();
|
|
2233
|
+
resetUserFlagByMe();
|
|
2234
|
+
};
|
|
2235
|
+
};
|
|
2236
|
+
/**
|
|
2237
|
+
* Called with the cached user when a recorded answer changes what that user would show, so live
|
|
2238
|
+
* objects and live collections deliver it again (REQ-016, delivery).
|
|
2239
|
+
*/
|
|
2240
|
+
const onUserFlagConfirmed = (callback) => createEventSubscriber(getActiveClient(), 'user/onUserFlagConfirmed', 'local.user.flagConfirmed', ({ userId }) => {
|
|
2241
|
+
var _a;
|
|
2242
|
+
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2243
|
+
if (user)
|
|
2244
|
+
callback(user);
|
|
2245
|
+
});
|
|
2246
|
+
|
|
1791
2247
|
const userLinkedObject = (user) => {
|
|
2248
|
+
// Captured now, so a user object the app holds never changes after a confirm (REQ-014).
|
|
2249
|
+
const confirmedFlagByMe = readConfirmedFlag(user.userId, user.hashFlag);
|
|
1792
2250
|
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
1793
2251
|
var _a;
|
|
1794
2252
|
if (!user.avatarFileId)
|
|
1795
|
-
return
|
|
1796
|
-
const avatar = (_a = pullFromCache([
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
`${user.avatarFileId}`,
|
|
1800
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2253
|
+
return null;
|
|
2254
|
+
const avatar = (_a = pullFromCache(['file', 'get', user.avatarFileId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2255
|
+
if (!avatar)
|
|
2256
|
+
return null;
|
|
1801
2257
|
return avatar;
|
|
1802
|
-
}
|
|
2258
|
+
},
|
|
2259
|
+
get isFlaggedByMe() {
|
|
2260
|
+
// Bloom test on this object's hashFlag: "definitely not" is exact and sends nothing.
|
|
2261
|
+
// "Maybe" returns the answer confirmed for this hashFlag, or true while one background
|
|
2262
|
+
// confirm runs (REQ-011, REQ-016). Never throws.
|
|
2263
|
+
return isFlaggedByMeFor(user, confirmedFlagByMe);
|
|
2264
|
+
},
|
|
2265
|
+
/* begin_public_function
|
|
2266
|
+
id: user.get_flags_by_me
|
|
2267
|
+
*/
|
|
2268
|
+
getUserFlagsByMe: getUserFlagsByMeFor(user) });
|
|
1803
2269
|
};
|
|
1804
2270
|
|
|
1805
2271
|
/* begin_public_function
|
|
@@ -2066,13 +2532,13 @@ class NetworkActivitiesWatcher {
|
|
|
2066
2532
|
this._listener.clear();
|
|
2067
2533
|
}
|
|
2068
2534
|
}
|
|
2069
|
-
let instance$
|
|
2535
|
+
let instance$a;
|
|
2070
2536
|
var NetworkActivitiesWatcher$1 = {
|
|
2071
2537
|
getInstance: () => {
|
|
2072
|
-
if (!instance$
|
|
2073
|
-
instance$
|
|
2538
|
+
if (!instance$a) {
|
|
2539
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
2074
2540
|
}
|
|
2075
|
-
return instance$
|
|
2541
|
+
return instance$a;
|
|
2076
2542
|
},
|
|
2077
2543
|
};
|
|
2078
2544
|
|
|
@@ -2256,54 +2722,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
2256
2722
|
return instance;
|
|
2257
2723
|
};
|
|
2258
2724
|
|
|
2259
|
-
class SessionWatcher {
|
|
2260
|
-
constructor() {
|
|
2261
|
-
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
2262
|
-
this._listener = new Map();
|
|
2263
|
-
}
|
|
2264
|
-
onSessionStateChange(callback) {
|
|
2265
|
-
this._listener.set(callback, callback);
|
|
2266
|
-
return () => {
|
|
2267
|
-
this._listener.delete(callback);
|
|
2268
|
-
};
|
|
2269
|
-
}
|
|
2270
|
-
setSessionState(state, reason) {
|
|
2271
|
-
if (this._sessionState === state)
|
|
2272
|
-
return;
|
|
2273
|
-
this._sessionState = state;
|
|
2274
|
-
this._listener.forEach(cb => cb(state, reason));
|
|
2275
|
-
}
|
|
2276
|
-
destroy() {
|
|
2277
|
-
this._listener.clear();
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
let instance$a;
|
|
2281
|
-
var SessionWatcher$1 = {
|
|
2282
|
-
getInstance: () => {
|
|
2283
|
-
if (!instance$a) {
|
|
2284
|
-
instance$a = new SessionWatcher();
|
|
2285
|
-
}
|
|
2286
|
-
return instance$a;
|
|
2287
|
-
},
|
|
2288
|
-
};
|
|
2289
|
-
|
|
2290
|
-
/**
|
|
2291
|
-
* ```js
|
|
2292
|
-
* import { onSessionStateChange } from '@amityco/ts-sdk-react-native'
|
|
2293
|
-
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
2294
|
-
* // ...
|
|
2295
|
-
* })
|
|
2296
|
-
* ```
|
|
2297
|
-
*
|
|
2298
|
-
* Fired when any {@link Amity.Client} has a session state change
|
|
2299
|
-
*
|
|
2300
|
-
* @param callback The function to call when the event was fired
|
|
2301
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
2302
|
-
*
|
|
2303
|
-
* @category Client Events
|
|
2304
|
-
*/
|
|
2305
|
-
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
2306
|
-
|
|
2307
2725
|
const TOPICS = {
|
|
2308
2726
|
[AmityAutoSubscription.NETWORK]: [getNetworkTopic],
|
|
2309
2727
|
[AmityAutoSubscription.CHAT]: [
|
|
@@ -2913,7 +3331,8 @@ const convertRawMembershipToMembership = (member) => {
|
|
|
2913
3331
|
if (!userCache) {
|
|
2914
3332
|
return undefined;
|
|
2915
3333
|
}
|
|
2916
|
-
|
|
3334
|
+
// Every user the SDK hands out is a linked object (isFlaggedByMe, getUserFlagsByMe, avatar).
|
|
3335
|
+
return userLinkedObject(userCache);
|
|
2917
3336
|
} });
|
|
2918
3337
|
};
|
|
2919
3338
|
/**
|
|
@@ -2947,7 +3366,7 @@ const withUser = (member, userIdProp = 'userId', userProp = 'user') => {
|
|
|
2947
3366
|
if (!userCache) {
|
|
2948
3367
|
return undefined;
|
|
2949
3368
|
}
|
|
2950
|
-
return userCache;
|
|
3369
|
+
return userLinkedObject(userCache);
|
|
2951
3370
|
} }, member);
|
|
2952
3371
|
};
|
|
2953
3372
|
/**
|
|
@@ -3101,12 +3520,19 @@ const getSubChannelMessagePreview = (subChannelId) => {
|
|
|
3101
3520
|
};
|
|
3102
3521
|
|
|
3103
3522
|
const getSubChannelMessagePreviewWithUser = (subChannel) => {
|
|
3104
|
-
var _a;
|
|
3105
3523
|
const messagePreview = subChannel.messagePreviewId
|
|
3106
3524
|
? getSubChannelMessagePreview(subChannel.subChannelId)
|
|
3107
3525
|
: null;
|
|
3108
3526
|
const messagePreviewWithUser = messagePreview
|
|
3109
|
-
? Object.assign(Object.assign({}, messagePreview), { user: (
|
|
3527
|
+
? Object.assign(Object.assign({}, messagePreview), { user: (() => {
|
|
3528
|
+
var _a;
|
|
3529
|
+
const internalUser = (_a = pullFromCache([
|
|
3530
|
+
'user',
|
|
3531
|
+
'get',
|
|
3532
|
+
messagePreview === null || messagePreview === void 0 ? void 0 : messagePreview.creatorId,
|
|
3533
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
3534
|
+
return internalUser ? userLinkedObject(internalUser) : undefined;
|
|
3535
|
+
})() }) : null;
|
|
3110
3536
|
return Object.assign(Object.assign({}, subChannel), { messagePreview: messagePreviewWithUser });
|
|
3111
3537
|
};
|
|
3112
3538
|
|
|
@@ -8123,6 +8549,140 @@ const postCommentCountEngineOnLoginHandler = () => onSessionStateChange(state =>
|
|
|
8123
8549
|
}
|
|
8124
8550
|
});
|
|
8125
8551
|
|
|
8552
|
+
const BOTH_FIELDS = { lastActivity: true, lastMessageAt: true };
|
|
8553
|
+
/**
|
|
8554
|
+
* The channel cache is keyed by `channelInternalId`, but a message names its
|
|
8555
|
+
* channel by whichever id the producer had: the raw MQTT payload carries the
|
|
8556
|
+
* internal id, a converted `Amity.InternalMessage` carries the public id, and
|
|
8557
|
+
* the optimistic message carries the sub-channel's `channelId`. Try the direct
|
|
8558
|
+
* key first, then match any of the three ids.
|
|
8559
|
+
*/
|
|
8560
|
+
const findCachedChannel = (channelId) => {
|
|
8561
|
+
var _a, _b, _c;
|
|
8562
|
+
const direct = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8563
|
+
if (direct)
|
|
8564
|
+
return direct;
|
|
8565
|
+
return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === channelId ||
|
|
8566
|
+
data.channelId === channelId ||
|
|
8567
|
+
data.channelPublicId === channelId)) === null || _c === void 0 ? void 0 : _c.data;
|
|
8568
|
+
};
|
|
8569
|
+
const isNewer = (stored, at) => !stored || convertDateStringToTimestamp(stored) < convertDateStringToTimestamp(at);
|
|
8570
|
+
const isSameInstant = (stored, at) => !!stored && convertDateStringToTimestamp(stored) === convertDateStringToTimestamp(at);
|
|
8571
|
+
/** Pushes the changed fields in one write and emits one `local.channel.updated`. */
|
|
8572
|
+
const commit = (channel, changes) => {
|
|
8573
|
+
if (Object.keys(changes).length === 0)
|
|
8574
|
+
return false;
|
|
8575
|
+
const updated = shallowClone(channel, changes);
|
|
8576
|
+
// Write back under the key the cache actually uses (the resolver key), not
|
|
8577
|
+
// under `channel.channelId`, which can differ from `channelInternalId`.
|
|
8578
|
+
pushToCache(['channel', 'get', getResolver('channel')(updated)], updated);
|
|
8579
|
+
fireEvent('local.channel.updated', {
|
|
8580
|
+
channels: [updated],
|
|
8581
|
+
channelUsers: [],
|
|
8582
|
+
users: [],
|
|
8583
|
+
files: [],
|
|
8584
|
+
});
|
|
8585
|
+
return true;
|
|
8586
|
+
};
|
|
8587
|
+
/**
|
|
8588
|
+
* Single owner of every local write to a channel's ordering timestamps,
|
|
8589
|
+
* `lastActivity` and `lastMessageAt` (ChannelActivityService v1).
|
|
8590
|
+
*
|
|
8591
|
+
* - Monotonic per field: a field moves only when `at` is newer than the stored
|
|
8592
|
+
* value (or the stored value is `null`), so a late or replayed event never
|
|
8593
|
+
* moves a channel down the list.
|
|
8594
|
+
* - One write: both fields are read, compared and pushed in a single cache
|
|
8595
|
+
* update, followed by one `local.channel.updated` event so every open channel
|
|
8596
|
+
* collection re-sorts once.
|
|
8597
|
+
* - Server channel payloads never go through here; they overwrite unguarded.
|
|
8598
|
+
*
|
|
8599
|
+
* @returns `true` when at least one field moved
|
|
8600
|
+
* @category private
|
|
8601
|
+
*/
|
|
8602
|
+
const updateChannelActivityTimestamps = (channelId, at, fields = BOTH_FIELDS) => {
|
|
8603
|
+
const client = getActiveClient();
|
|
8604
|
+
if (!client.cache || !channelId || !at)
|
|
8605
|
+
return false;
|
|
8606
|
+
const channel = findCachedChannel(channelId);
|
|
8607
|
+
if (!channel)
|
|
8608
|
+
return false;
|
|
8609
|
+
const changes = {};
|
|
8610
|
+
if (fields.lastActivity && isNewer(channel.lastActivity, at))
|
|
8611
|
+
changes.lastActivity = at;
|
|
8612
|
+
if (fields.lastMessageAt && isNewer(channel.lastMessageAt, at))
|
|
8613
|
+
changes.lastMessageAt = at;
|
|
8614
|
+
return commit(channel, changes);
|
|
8615
|
+
};
|
|
8616
|
+
/**
|
|
8617
|
+
* Local correction for the current user's own send (ChannelActivityService v1
|
|
8618
|
+
* REQ-009, Trigger Matrix row 1b). Once the server confirms the message, each
|
|
8619
|
+
* field that still holds the device-clock `localAt` written at send time is
|
|
8620
|
+
* replaced by the server's `serverAt`, even when that is older. A field a newer
|
|
8621
|
+
* message has already moved is left alone. One write, one change notification,
|
|
8622
|
+
* nothing when neither field still holds `localAt`.
|
|
8623
|
+
*
|
|
8624
|
+
* @returns `true` when at least one field was replaced
|
|
8625
|
+
* @category private
|
|
8626
|
+
*/
|
|
8627
|
+
const confirmOwnMessage = (channelId, localAt, serverAt) => {
|
|
8628
|
+
const client = getActiveClient();
|
|
8629
|
+
if (!client.cache || !channelId || !localAt || !serverAt)
|
|
8630
|
+
return false;
|
|
8631
|
+
if (isSameInstant(localAt, serverAt))
|
|
8632
|
+
return false;
|
|
8633
|
+
const channel = findCachedChannel(channelId);
|
|
8634
|
+
if (!channel)
|
|
8635
|
+
return false;
|
|
8636
|
+
const changes = {};
|
|
8637
|
+
if (isSameInstant(channel.lastActivity, localAt))
|
|
8638
|
+
changes.lastActivity = serverAt;
|
|
8639
|
+
if (isSameInstant(channel.lastMessageAt, localAt))
|
|
8640
|
+
changes.lastMessageAt = serverAt;
|
|
8641
|
+
return commit(channel, changes);
|
|
8642
|
+
};
|
|
8643
|
+
|
|
8644
|
+
/**
|
|
8645
|
+
* Session-wide owner of the local `lastActivity` / `lastMessageAt` updates
|
|
8646
|
+
* (ChannelActivityService v1, Web migration rows W1 – W5).
|
|
8647
|
+
*
|
|
8648
|
+
* Registered once per session from `setupLoginSubscriptions` and
|
|
8649
|
+
* `resumeSession`, so the update runs whether or not a channel collection is
|
|
8650
|
+
* open, and exactly once per message however many collections are open.
|
|
8651
|
+
*
|
|
8652
|
+
* It listens to the raw events rather than `onMessageCreatedMqtt`, so it does
|
|
8653
|
+
* not duplicate that subscriber's side effects (mark-read, unread recount).
|
|
8654
|
+
*
|
|
8655
|
+
* @category private
|
|
8656
|
+
*/
|
|
8657
|
+
const channelActivityOnLoginHandler = () => {
|
|
8658
|
+
const client = getActiveClient();
|
|
8659
|
+
const disposers = [
|
|
8660
|
+
// Any user's new message, in any message feed of the channel. The raw
|
|
8661
|
+
// payload's `channelId` is the channel's internal id.
|
|
8662
|
+
createEventSubscriber(client, 'channelActivity', 'message.created', payload => {
|
|
8663
|
+
payload.messages.forEach(message => {
|
|
8664
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8665
|
+
});
|
|
8666
|
+
}),
|
|
8667
|
+
// The current user's own send fires this three times: with the optimistic
|
|
8668
|
+
// message at send time (Syncing), on the create response (Synced), and on
|
|
8669
|
+
// failure (Error). The device-clock time of the Syncing / Error fires was
|
|
8670
|
+
// already applied synchronously in createMessageOptimistic, and replaying it
|
|
8671
|
+
// here could undo the server correction made on the response
|
|
8672
|
+
// (confirmOwnMessage). Only the server-confirmed fire goes through the guard.
|
|
8673
|
+
createEventSubscriber(client, 'channelActivity', 'local.message.created', payload => {
|
|
8674
|
+
payload.messages.forEach(message => {
|
|
8675
|
+
if (message.syncState !== "synced" /* Amity.SyncState.Synced */)
|
|
8676
|
+
return;
|
|
8677
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8678
|
+
});
|
|
8679
|
+
}),
|
|
8680
|
+
];
|
|
8681
|
+
return () => {
|
|
8682
|
+
disposers.forEach(fn => fn());
|
|
8683
|
+
};
|
|
8684
|
+
};
|
|
8685
|
+
|
|
8126
8686
|
const EVENTS = [
|
|
8127
8687
|
'disconnected',
|
|
8128
8688
|
'error',
|
|
@@ -8312,7 +8872,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8312
8872
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8313
8873
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8314
8874
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8315
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler());
|
|
8875
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8316
8876
|
if (client.useLegacyUnreadCount) {
|
|
8317
8877
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8318
8878
|
}
|
|
@@ -9616,7 +10176,7 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
9616
10176
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9617
10177
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9618
10178
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9619
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
10179
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), channelActivityOnLoginHandler());
|
|
9620
10180
|
if (client.useLegacyUnreadCount) {
|
|
9621
10181
|
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
9622
10182
|
}
|
|
@@ -11933,7 +12493,7 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
11933
12493
|
// map users with community
|
|
11934
12494
|
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
11935
12495
|
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
11936
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
12496
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(user) : undefined });
|
|
11937
12497
|
});
|
|
11938
12498
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
11939
12499
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
@@ -11950,7 +12510,7 @@ const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
|
11950
12510
|
// map users with community
|
|
11951
12511
|
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
11952
12512
|
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
11953
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
12513
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(convertRawUserToInternalUser(user)) : undefined });
|
|
11954
12514
|
});
|
|
11955
12515
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
11956
12516
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
@@ -15375,7 +15935,7 @@ const updateUser = async (userId, patch) => {
|
|
|
15375
15935
|
ingestInCache(payload, { cachedAt });
|
|
15376
15936
|
fireEvent('user.updated', data);
|
|
15377
15937
|
return {
|
|
15378
|
-
data: payload.users.find(user => user.userId === userId),
|
|
15938
|
+
data: userLinkedObject(payload.users.find(user => user.userId === userId)),
|
|
15379
15939
|
cachedAt,
|
|
15380
15940
|
};
|
|
15381
15941
|
};
|
|
@@ -15398,19 +15958,19 @@ const buildFlagUserBody = (options) => {
|
|
|
15398
15958
|
*/
|
|
15399
15959
|
/**
|
|
15400
15960
|
* ```js
|
|
15401
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15961
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
15962
|
+
*
|
|
15963
|
+
* // Typeless report (supported).
|
|
15402
15964
|
* const flagged = await UserRepository.flagUser('userId')
|
|
15403
|
-
* const flaggedBehavior = await UserRepository.flagUser('userId', {
|
|
15404
|
-
* reportType: 'behavior',
|
|
15405
|
-
* reason: 'Harassment or bullying',
|
|
15406
|
-
* comment: 'optional free-text',
|
|
15407
|
-
* })
|
|
15408
15965
|
* ```
|
|
15409
15966
|
*
|
|
15967
|
+
* Flags a user. Two call shapes are accepted (see the overloads): id-only, which
|
|
15968
|
+
* sends no body and stays supported, and the deprecated structured options object,
|
|
15969
|
+
* whose request mapping is unchanged. New code reporting a profile field or behavior
|
|
15970
|
+
* should use `flagUserProfile` or `flagUserBehavior`.
|
|
15971
|
+
*
|
|
15410
15972
|
* @param userId The ID of the user to be flagged
|
|
15411
|
-
* @param options
|
|
15412
|
-
* body: `reportType`, `reason`, `comment`. Only non-null fields are included.
|
|
15413
|
-
* All validation is server-side; a bodyless call produces a typeless report.
|
|
15973
|
+
* @param options Deprecated report metadata; omit for a typeless report
|
|
15414
15974
|
* @returns the flagged {@link Amity.User}
|
|
15415
15975
|
*
|
|
15416
15976
|
* @category User API
|
|
@@ -15426,34 +15986,242 @@ const flagUser = async (userId, options) => {
|
|
|
15426
15986
|
if (client.cache) {
|
|
15427
15987
|
ingestInCache(payload);
|
|
15428
15988
|
}
|
|
15989
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
15990
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
15991
|
+
onFlaggedByMe(flagged, userId);
|
|
15429
15992
|
fireEvent('user.flagged', data);
|
|
15430
|
-
return (
|
|
15993
|
+
return userLinkedObject(flagged);
|
|
15431
15994
|
};
|
|
15432
15995
|
/* end_public_function */
|
|
15433
15996
|
|
|
15997
|
+
/**
|
|
15998
|
+
* Sends a validated split user report (`flagUserProfile` / `flagUserBehavior`) to the
|
|
15999
|
+
* same endpoint as `flagUser`, then persists the returned user and fires `user.flagged`
|
|
16000
|
+
* exactly as `flagUser` does, so all three calls share return, cache and event behaviour.
|
|
16001
|
+
*
|
|
16002
|
+
* Not exported from the public API.
|
|
16003
|
+
*/
|
|
16004
|
+
const submitUserReport = async (apiName, userId, body) => {
|
|
16005
|
+
var _a;
|
|
16006
|
+
const client = getActiveClient();
|
|
16007
|
+
client.log(`user/${apiName}`, { userId, body });
|
|
16008
|
+
const { data } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(userId)}`, body);
|
|
16009
|
+
const payload = prepareUserPayload(data);
|
|
16010
|
+
if (client.cache) {
|
|
16011
|
+
ingestInCache(payload);
|
|
16012
|
+
}
|
|
16013
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
16014
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
16015
|
+
onFlaggedByMe(flagged, userId);
|
|
16016
|
+
fireEvent('user.flagged', data);
|
|
16017
|
+
return userLinkedObject(flagged);
|
|
16018
|
+
};
|
|
16019
|
+
|
|
16020
|
+
/** Maximum `comment` length, in string length units, after trimming. */
|
|
16021
|
+
const USER_REPORT_COMMENT_MAX_LENGTH = 300;
|
|
16022
|
+
const PROFILE_FIELDS = Object.values(UserProfileFieldEnum);
|
|
16023
|
+
const BEHAVIOR_REASONS = Object.values(ContentFlagReasonEnum);
|
|
16024
|
+
const REPORT_TYPE_FILTERS = Object.values(UserReportTypeFilterEnum);
|
|
16025
|
+
const assertOptionsObject = (apiName, options, shape) => {
|
|
16026
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
16027
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`${shape}\``);
|
|
16028
|
+
}
|
|
16029
|
+
return options;
|
|
16030
|
+
};
|
|
16031
|
+
/**
|
|
16032
|
+
* Normalizes an optional reporter `comment`: it must be a string when supplied (`null`
|
|
16033
|
+
* is not a valid supplied comment); it is trimmed; a blank result is omitted (the
|
|
16034
|
+
* backend rejects `""`); a result longer than 300 characters is rejected before any
|
|
16035
|
+
* request. Otherwise the trimmed text is returned unchanged.
|
|
16036
|
+
*
|
|
16037
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` for a non-string or over-length comment
|
|
16038
|
+
*/
|
|
16039
|
+
const normalizeUserReportComment = (apiName, comment) => {
|
|
16040
|
+
if (comment === undefined)
|
|
16041
|
+
return undefined;
|
|
16042
|
+
if (typeof comment !== 'string') {
|
|
16043
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be a string when supplied`);
|
|
16044
|
+
}
|
|
16045
|
+
const trimmed = comment.trim();
|
|
16046
|
+
if (trimmed.length === 0)
|
|
16047
|
+
return undefined;
|
|
16048
|
+
if (trimmed.length > USER_REPORT_COMMENT_MAX_LENGTH) {
|
|
16049
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be at most ${USER_REPORT_COMMENT_MAX_LENGTH} characters after trimming`);
|
|
16050
|
+
}
|
|
16051
|
+
return trimmed;
|
|
16052
|
+
};
|
|
16053
|
+
const withComment = (body, comment) => comment === undefined ? body : Object.assign(Object.assign({}, body), { comment });
|
|
16054
|
+
/**
|
|
16055
|
+
* Validates `flagUserProfile` options and builds its request body. Untyped callers can
|
|
16056
|
+
* pass anything at runtime, so nothing is trusted from the declared type. Any `reason`
|
|
16057
|
+
* key is ignored and never sent.
|
|
16058
|
+
*
|
|
16059
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
16060
|
+
*/
|
|
16061
|
+
const toUserProfileReportBody = (options) => {
|
|
16062
|
+
const apiName = 'flagUserProfile';
|
|
16063
|
+
const { field, comment } = assertOptionsObject(apiName, options, '{ field, comment? }');
|
|
16064
|
+
if (typeof field !== 'string' || !PROFILE_FIELDS.includes(field)) {
|
|
16065
|
+
throw new ASCInvalidParameterError(`${apiName}: \`field\` must be a \`UserProfileFieldEnum\` value`);
|
|
16066
|
+
}
|
|
16067
|
+
return withComment({ reportType: field }, normalizeUserReportComment(apiName, comment));
|
|
16068
|
+
};
|
|
16069
|
+
/**
|
|
16070
|
+
* Validates `flagUserBehavior` options and builds its request body. `reason` must be one
|
|
16071
|
+
* of the nine `ContentFlagReasonEnum` values and is sent as that canonical label;
|
|
16072
|
+
* `reportType` is always `behavior`.
|
|
16073
|
+
*
|
|
16074
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
16075
|
+
*/
|
|
16076
|
+
const toUserBehaviorReportBody = (options) => {
|
|
16077
|
+
const apiName = 'flagUserBehavior';
|
|
16078
|
+
const { reason, comment } = assertOptionsObject(apiName, options, '{ reason, comment? }');
|
|
16079
|
+
if (typeof reason !== 'string' || !BEHAVIOR_REASONS.includes(reason)) {
|
|
16080
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
16081
|
+
}
|
|
16082
|
+
return withComment({ reportType: 'behavior', reason }, normalizeUserReportComment(apiName, comment));
|
|
16083
|
+
};
|
|
16084
|
+
/**
|
|
16085
|
+
* Validates the optional `{ reportType? }` of `unflagUser` and builds its query parameters.
|
|
16086
|
+
* Returns `undefined` when no `reportType` is given, so the request carries no query string
|
|
16087
|
+
* and withdraws every report the caller filed on the user. The server validates the value
|
|
16088
|
+
* too (422); this local check only saves the round-trip for the string alias, which admits
|
|
16089
|
+
* raw strings. Untyped callers can pass anything at runtime, so nothing is trusted from the
|
|
16090
|
+
* declared type.
|
|
16091
|
+
*
|
|
16092
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed or `reportType` is unknown
|
|
16093
|
+
*/
|
|
16094
|
+
const toUserReportTypeFilter = (options) => {
|
|
16095
|
+
if (options === undefined)
|
|
16096
|
+
return undefined;
|
|
16097
|
+
const apiName = 'unflagUser';
|
|
16098
|
+
const { reportType } = assertOptionsObject(apiName, options, '{ reportType? }');
|
|
16099
|
+
if (reportType === undefined)
|
|
16100
|
+
return undefined;
|
|
16101
|
+
if (typeof reportType !== 'string' || !REPORT_TYPE_FILTERS.includes(reportType)) {
|
|
16102
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reportType\` must be a \`UserReportTypeFilterEnum\` value`);
|
|
16103
|
+
}
|
|
16104
|
+
return { reportType: reportType };
|
|
16105
|
+
};
|
|
16106
|
+
|
|
16107
|
+
/* begin_public_function
|
|
16108
|
+
id: user.flag_profile
|
|
16109
|
+
*/
|
|
16110
|
+
/**
|
|
16111
|
+
* ```js
|
|
16112
|
+
* import { UserRepository, UserProfileFieldEnum } from '@amityco/ts-sdk'
|
|
16113
|
+
* const flagged = await UserRepository.flagUserProfile('userId', {
|
|
16114
|
+
* field: UserProfileFieldEnum.AVATAR,
|
|
16115
|
+
* comment: 'Nudity in profile photo',
|
|
16116
|
+
* })
|
|
16117
|
+
* ```
|
|
16118
|
+
*
|
|
16119
|
+
* Reports one of a user's profile fields (display name, description or avatar). The
|
|
16120
|
+
* call has no reason: profile reports never carry one, so the backend's reason rules
|
|
16121
|
+
* cannot be violated from here. A `reason` key passed at runtime is ignored and never sent.
|
|
16122
|
+
*
|
|
16123
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
16124
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
16125
|
+
* trimmed text is sent unchanged.
|
|
16126
|
+
*
|
|
16127
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: <field>, comment? }`.
|
|
16128
|
+
*
|
|
16129
|
+
* @param userId The ID of the user to be reported
|
|
16130
|
+
* @param options `field` is a `UserProfileFieldEnum` value; `comment` is optional free text
|
|
16131
|
+
* @returns the flagged {@link Amity.User}
|
|
16132
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, or `comment` is over 300 characters, before any request is made
|
|
16133
|
+
*
|
|
16134
|
+
* @category User API
|
|
16135
|
+
* @async
|
|
16136
|
+
* */
|
|
16137
|
+
const flagUserProfile = async (userId, options) => submitUserReport('flagUserProfile', userId, toUserProfileReportBody(options));
|
|
16138
|
+
/* end_public_function */
|
|
16139
|
+
|
|
16140
|
+
/* begin_public_function
|
|
16141
|
+
id: user.flag_behavior
|
|
16142
|
+
*/
|
|
16143
|
+
/**
|
|
16144
|
+
* ```js
|
|
16145
|
+
* import { UserRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
16146
|
+
* const flagged = await UserRepository.flagUserBehavior('userId', {
|
|
16147
|
+
* reason: ContentFlagReasonEnum.Others,
|
|
16148
|
+
* comment: 'Impersonating our brand',
|
|
16149
|
+
* })
|
|
16150
|
+
* ```
|
|
16151
|
+
*
|
|
16152
|
+
* Reports a user's behavior. `reason` is required and is one of the nine
|
|
16153
|
+
* `ContentFlagReasonEnum` values, sent as its canonical label. Reporter text, including
|
|
16154
|
+
* the explanation for `Others`, always travels in `comment`; the reason never carries text.
|
|
16155
|
+
*
|
|
16156
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
16157
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
16158
|
+
* trimmed text is sent unchanged.
|
|
16159
|
+
*
|
|
16160
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: 'behavior', reason, comment? }`.
|
|
16161
|
+
*
|
|
16162
|
+
* @param userId The ID of the user to be reported
|
|
16163
|
+
* @param options `reason` is a `ContentFlagReasonEnum` value; `comment` is optional free text
|
|
16164
|
+
* @returns the flagged {@link Amity.User}
|
|
16165
|
+
* @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
|
|
16166
|
+
*
|
|
16167
|
+
* @category User API
|
|
16168
|
+
* @async
|
|
16169
|
+
* */
|
|
16170
|
+
const flagUserBehavior = async (userId, options) => submitUserReport('flagUserBehavior', userId, toUserBehaviorReportBody(options));
|
|
16171
|
+
/* end_public_function */
|
|
16172
|
+
|
|
15434
16173
|
/* begin_public_function
|
|
15435
16174
|
id: user.unflag
|
|
15436
16175
|
*/
|
|
15437
16176
|
/**
|
|
15438
16177
|
* ```js
|
|
15439
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15440
|
-
*
|
|
16178
|
+
* import { UserRepository, UserReportTypeFilterEnum } from '@amityco/ts-sdk'
|
|
16179
|
+
*
|
|
16180
|
+
* // Withdraw every report I filed on the user.
|
|
16181
|
+
* const unflagged = await UserRepository.unflagUser('userId')
|
|
16182
|
+
*
|
|
16183
|
+
* // Withdraw only my behavior report; my other reports on the user stay.
|
|
16184
|
+
* await UserRepository.unflagUser('userId', { reportType: UserReportTypeFilterEnum.BEHAVIOR })
|
|
16185
|
+
*
|
|
16186
|
+
* // Withdraw only my typeless (legacy) report.
|
|
16187
|
+
* await UserRepository.unflagUser('userId', { reportType: UserReportTypeFilterEnum.UNTYPED })
|
|
15441
16188
|
* ```
|
|
15442
16189
|
*
|
|
16190
|
+
* Withdraws the caller's reports on a user. Without `reportType` every report the caller
|
|
16191
|
+
* filed on that user is withdrawn, as before. With `reportType` only the caller's report
|
|
16192
|
+
* of that type is withdrawn; the caller's other reports and other users' reports are
|
|
16193
|
+
* untouched. Withdrawing a report that does not exist succeeds and changes nothing.
|
|
16194
|
+
*
|
|
16195
|
+
* The returned user is persisted to the cache, so its `hashFlag` says whether the caller
|
|
16196
|
+
* may still hold a report on the user. Do not flip a local "flagged by me" flag to `false`
|
|
16197
|
+
* after a per-type withdrawal; observe the user and read `isFlaggedByMe`, or call
|
|
16198
|
+
* `user.getUserFlagsByMe()` for the remaining per-type state (`flags`). The SDK drops the
|
|
16199
|
+
* answer it confirmed for this user, so the next "maybe" is confirmed again.
|
|
16200
|
+
*
|
|
16201
|
+
* Sends `DELETE /api/v4/me/flags/:userId`, with `?reportType=<type>` when one is given.
|
|
16202
|
+
*
|
|
15443
16203
|
* @param userId The ID of the user to unflag
|
|
15444
|
-
* @
|
|
16204
|
+
* @param options Optional; `reportType` selects a single report to withdraw. For a report that `user.getUserFlagsByMe()` lists with `reportType: null`, pass `UserReportTypeFilterEnum.UNTYPED`
|
|
16205
|
+
* @returns `true` once the server has processed the withdrawal
|
|
16206
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `reportType` is not a `UserReportTypeFilterEnum` value, before any request is made
|
|
15445
16207
|
*
|
|
15446
16208
|
* @category User API
|
|
15447
16209
|
* @async
|
|
15448
16210
|
* */
|
|
15449
|
-
const unflagUser = async (userId) => {
|
|
15450
|
-
const client = getActiveClient();
|
|
15451
|
-
client.log('user/unflag', userId);
|
|
15452
|
-
const
|
|
16211
|
+
const unflagUser = async (userId, options) => {
|
|
16212
|
+
const client = getActiveClient();
|
|
16213
|
+
client.log('user/unflag', { userId, options });
|
|
16214
|
+
const params = toUserReportTypeFilter(options);
|
|
16215
|
+
const url = `/api/v4/me/flags/${encodeURIComponent(userId)}`;
|
|
16216
|
+
const { data } = params
|
|
16217
|
+
? await client.http.delete(url, { params })
|
|
16218
|
+
: await client.http.delete(url);
|
|
15453
16219
|
const payload = prepareUserPayload(data);
|
|
15454
16220
|
if (client.cache) {
|
|
15455
16221
|
ingestInCache(payload);
|
|
15456
16222
|
}
|
|
16223
|
+
// Drop the confirmed answer; never set it to false: other reports may remain (REQ-010).
|
|
16224
|
+
onUnflaggedByMe(userId);
|
|
15457
16225
|
fireEvent('user.unflagged', data);
|
|
15458
16226
|
return !!payload;
|
|
15459
16227
|
};
|
|
@@ -15464,12 +16232,20 @@ const unflagUser = async (userId) => {
|
|
|
15464
16232
|
*/
|
|
15465
16233
|
/**
|
|
15466
16234
|
* ```js
|
|
15467
|
-
* import { UserRepository } from '@amityco/ts-sdk
|
|
15468
|
-
* const isFlagged = await UserRepository.isUserFlaggedByMe(
|
|
16235
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16236
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(userId)
|
|
15469
16237
|
* ```
|
|
15470
16238
|
*
|
|
15471
|
-
*
|
|
15472
|
-
*
|
|
16239
|
+
* Whether the current user has reported a user. Sends one request per call and caches
|
|
16240
|
+
* nothing.
|
|
16241
|
+
*
|
|
16242
|
+
* @deprecated Read `user.isFlaggedByMe` on an {@link Amity.User} for a yes/no hint that
|
|
16243
|
+
* usually needs no request, and call `user.getUserFlagsByMe()` for the exact answer with the
|
|
16244
|
+
* caller's reports by type. Observe the user with `UserRepository.getUser(userId, callback)`
|
|
16245
|
+
* to follow a flag or unflag.
|
|
16246
|
+
*
|
|
16247
|
+
* @param userId The ID of the user to check
|
|
16248
|
+
* @returns `true` if the current user has reported the user, `false` if not
|
|
15473
16249
|
*
|
|
15474
16250
|
* @category Report API
|
|
15475
16251
|
* @async
|
|
@@ -15477,7 +16253,7 @@ const unflagUser = async (userId) => {
|
|
|
15477
16253
|
const isUserFlaggedByMe = async (userId) => {
|
|
15478
16254
|
const client = getActiveClient();
|
|
15479
16255
|
client.log('user/isUserFlaggedByMe', userId);
|
|
15480
|
-
const {
|
|
16256
|
+
const { isFlagByMe } = await getFlagsByMe(userId);
|
|
15481
16257
|
return isFlagByMe;
|
|
15482
16258
|
};
|
|
15483
16259
|
/* end_public_function */
|
|
@@ -15717,7 +16493,7 @@ const getUser = (userId, callback) => {
|
|
|
15717
16493
|
const reactor = (response) => {
|
|
15718
16494
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
15719
16495
|
};
|
|
15720
|
-
|
|
16496
|
+
const unsubscribeUser = liveObject(userId, reactor, 'userId', getUser$1, [
|
|
15721
16497
|
onUserFetched,
|
|
15722
16498
|
onUserUpdated,
|
|
15723
16499
|
onUserDeleted$2,
|
|
@@ -15725,19 +16501,28 @@ const getUser = (userId, callback) => {
|
|
|
15725
16501
|
onUserUnflagged,
|
|
15726
16502
|
onUserFlagCleared,
|
|
15727
16503
|
]);
|
|
16504
|
+
// A confirmed flag answer leaves the cached user row unchanged, so the live object's own
|
|
16505
|
+
// dedupe would drop it. Deliver the re-linked user directly (user.check_flag_by_me REQ-016).
|
|
16506
|
+
const unsubscribeFlag = onUserFlagConfirmed(user => {
|
|
16507
|
+
if (user.userId !== userId)
|
|
16508
|
+
return;
|
|
16509
|
+
callback({ data: LinkedObject.user(user), loading: false, origin: 'event' });
|
|
16510
|
+
});
|
|
16511
|
+
return () => {
|
|
16512
|
+
unsubscribeUser();
|
|
16513
|
+
unsubscribeFlag();
|
|
16514
|
+
};
|
|
15728
16515
|
};
|
|
15729
16516
|
/* end_public_function */
|
|
15730
16517
|
|
|
15731
|
-
|
|
15732
|
-
|
|
15733
|
-
|
|
15734
|
-
|
|
15735
|
-
|
|
15736
|
-
|
|
15737
|
-
|
|
15738
|
-
|
|
15739
|
-
}
|
|
15740
|
-
}
|
|
16518
|
+
var EnumUserActions;
|
|
16519
|
+
(function (EnumUserActions) {
|
|
16520
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
16521
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
16522
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
16523
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
16524
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
16525
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
15741
16526
|
|
|
15742
16527
|
class UserQueryStreamController extends QueryStreamController {
|
|
15743
16528
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -15785,14 +16570,16 @@ class UserQueryStreamController extends QueryStreamController {
|
|
|
15785
16570
|
}
|
|
15786
16571
|
}
|
|
15787
16572
|
|
|
15788
|
-
|
|
15789
|
-
(
|
|
15790
|
-
|
|
15791
|
-
|
|
15792
|
-
|
|
15793
|
-
|
|
15794
|
-
|
|
15795
|
-
|
|
16573
|
+
class UserPaginationController extends PaginationController {
|
|
16574
|
+
async getRequest(queryParams, token) {
|
|
16575
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
16576
|
+
const options = token ? { token } : { limit };
|
|
16577
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
16578
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
16579
|
+
});
|
|
16580
|
+
return queryResponse;
|
|
16581
|
+
}
|
|
16582
|
+
}
|
|
15796
16583
|
|
|
15797
16584
|
class UserLiveCollectionController extends LiveCollectionController {
|
|
15798
16585
|
constructor(query, callback) {
|
|
@@ -15822,13 +16609,24 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
15822
16609
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
15823
16610
|
}
|
|
15824
16611
|
startSubscription() {
|
|
15825
|
-
return
|
|
15826
|
-
|
|
15827
|
-
|
|
15828
|
-
|
|
15829
|
-
|
|
15830
|
-
|
|
15831
|
-
|
|
16612
|
+
return [
|
|
16613
|
+
...this.queryStreamController.subscribeRTE([
|
|
16614
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
16615
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
16616
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
16617
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
16618
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
16619
|
+
]),
|
|
16620
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
16621
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
16622
|
+
onUserFlagConfirmed(user => {
|
|
16623
|
+
var _a;
|
|
16624
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16625
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
16626
|
+
return;
|
|
16627
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16628
|
+
}),
|
|
16629
|
+
];
|
|
15832
16630
|
}
|
|
15833
16631
|
notifyChange({ origin, loading, error }) {
|
|
15834
16632
|
var _a, _b;
|
|
@@ -15909,16 +16707,17 @@ const getUsers = (params, callback, config) => {
|
|
|
15909
16707
|
};
|
|
15910
16708
|
/* end_public_function */
|
|
15911
16709
|
|
|
15912
|
-
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15916
|
-
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
15917
|
-
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
15918
|
-
});
|
|
15919
|
-
return queryResponse;
|
|
16710
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
16711
|
+
var _a;
|
|
16712
|
+
if (!sourceModel) {
|
|
16713
|
+
return sourceModel;
|
|
15920
16714
|
}
|
|
15921
|
-
}
|
|
16715
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
16716
|
+
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16717
|
+
if (!model)
|
|
16718
|
+
return;
|
|
16719
|
+
return callback(model);
|
|
16720
|
+
});
|
|
15922
16721
|
|
|
15923
16722
|
var EnumBlockActions;
|
|
15924
16723
|
(function (EnumBlockActions) {
|
|
@@ -15974,17 +16773,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
15974
16773
|
}
|
|
15975
16774
|
}
|
|
15976
16775
|
|
|
15977
|
-
|
|
15978
|
-
|
|
15979
|
-
|
|
15980
|
-
|
|
16776
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
16777
|
+
async getRequest(queryParams, token) {
|
|
16778
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
16779
|
+
const options = token ? { token } : { limit };
|
|
16780
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
16781
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
16782
|
+
});
|
|
16783
|
+
return queryResponse;
|
|
15981
16784
|
}
|
|
15982
|
-
|
|
15983
|
-
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15984
|
-
if (!model)
|
|
15985
|
-
return;
|
|
15986
|
-
return callback(model);
|
|
15987
|
-
});
|
|
16785
|
+
}
|
|
15988
16786
|
|
|
15989
16787
|
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
15990
16788
|
constructor(query, callback) {
|
|
@@ -16294,17 +17092,6 @@ const getBlockingUsers = (callback) => {
|
|
|
16294
17092
|
};
|
|
16295
17093
|
/* end_public_function */
|
|
16296
17094
|
|
|
16297
|
-
class SearchUserPaginationController extends PaginationController {
|
|
16298
|
-
async getRequest(queryParams, token) {
|
|
16299
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
16300
|
-
const options = token ? { token } : { limit };
|
|
16301
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
16302
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
16303
|
-
});
|
|
16304
|
-
return queryResponse;
|
|
16305
|
-
}
|
|
16306
|
-
}
|
|
16307
|
-
|
|
16308
17095
|
class SearchUserQueryStreamController extends QueryStreamController {
|
|
16309
17096
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
16310
17097
|
super(query, cacheKey);
|
|
@@ -16351,6 +17138,17 @@ class SearchUserQueryStreamController extends QueryStreamController {
|
|
|
16351
17138
|
}
|
|
16352
17139
|
}
|
|
16353
17140
|
|
|
17141
|
+
class SearchUserPaginationController extends PaginationController {
|
|
17142
|
+
async getRequest(queryParams, token) {
|
|
17143
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
17144
|
+
const options = token ? { token } : { limit };
|
|
17145
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
17146
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
17147
|
+
});
|
|
17148
|
+
return queryResponse;
|
|
17149
|
+
}
|
|
17150
|
+
}
|
|
17151
|
+
|
|
16354
17152
|
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
16355
17153
|
constructor(query, callback) {
|
|
16356
17154
|
var _a;
|
|
@@ -16380,13 +17178,24 @@ class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
|
16380
17178
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16381
17179
|
}
|
|
16382
17180
|
startSubscription() {
|
|
16383
|
-
return
|
|
16384
|
-
|
|
16385
|
-
|
|
16386
|
-
|
|
16387
|
-
|
|
16388
|
-
|
|
16389
|
-
|
|
17181
|
+
return [
|
|
17182
|
+
...this.queryStreamController.subscribeRTE([
|
|
17183
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
17184
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
17185
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
17186
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
17187
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
17188
|
+
]),
|
|
17189
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
17190
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
17191
|
+
onUserFlagConfirmed(user => {
|
|
17192
|
+
var _a;
|
|
17193
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17194
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
17195
|
+
return;
|
|
17196
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17197
|
+
}),
|
|
17198
|
+
];
|
|
16390
17199
|
}
|
|
16391
17200
|
notifyChange({ origin, loading, error }) {
|
|
16392
17201
|
var _a, _b;
|
|
@@ -16605,6 +17414,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
16605
17414
|
getUserByIds: getUserByIds,
|
|
16606
17415
|
updateUser: updateUser,
|
|
16607
17416
|
flagUser: flagUser,
|
|
17417
|
+
flagUserProfile: flagUserProfile,
|
|
17418
|
+
flagUserBehavior: flagUserBehavior,
|
|
16608
17419
|
unflagUser: unflagUser,
|
|
16609
17420
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
16610
17421
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
@@ -17215,7 +18026,7 @@ const preparePostPayload = (payload) => {
|
|
|
17215
18026
|
// map users with community
|
|
17216
18027
|
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
17217
18028
|
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
17218
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
18029
|
+
return Object.assign(Object.assign({}, communityUser), { user: user ? userLinkedObject(convertRawUserToInternalUser(user)) : undefined });
|
|
17219
18030
|
});
|
|
17220
18031
|
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
17221
18032
|
let mappedNewStream = [];
|
|
@@ -19026,7 +19837,8 @@ const getPostReport = async ({ client, referenceId, }) => {
|
|
|
19026
19837
|
};
|
|
19027
19838
|
const getUserReport = async ({ client, referenceId, }) => {
|
|
19028
19839
|
var _a;
|
|
19029
|
-
|
|
19840
|
+
// v3 isFlagByMe is deprecated by the backend; v4 answers the same boolean plus the caller's flags.
|
|
19841
|
+
const { data } = await client.http.get(`/api/v4/users/${encodeURIComponent(referenceId)}/isFlagByMe`);
|
|
19030
19842
|
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
19031
19843
|
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
19032
19844
|
};
|
|
@@ -19643,7 +20455,7 @@ const getLocalId = () => `LOCAL_${uuid()}`;
|
|
|
19643
20455
|
// FIXME: temp solution
|
|
19644
20456
|
let uniqueId;
|
|
19645
20457
|
const createMessageOptimistic = (bundle) => {
|
|
19646
|
-
var _a, _b;
|
|
20458
|
+
var _a, _b, _c, _d;
|
|
19647
20459
|
const client = getActiveClient();
|
|
19648
20460
|
if (!client.cache)
|
|
19649
20461
|
return;
|
|
@@ -19674,9 +20486,20 @@ const createMessageOptimistic = (bundle) => {
|
|
|
19674
20486
|
}
|
|
19675
20487
|
// as reused to update created and updated time, which should be the same
|
|
19676
20488
|
const createdTime = new Date().toISOString();
|
|
19677
|
-
const message = Object.assign({
|
|
20489
|
+
const message = Object.assign({
|
|
20490
|
+
// The optimistic message must name its channel (public id) so the own-send
|
|
20491
|
+
// update can move lastActivity / lastMessageAt at send time. Take it from the
|
|
20492
|
+
// cached sub-channel; when that is not cached, resolve the sub-channel id
|
|
20493
|
+
// through the channel cache, which for a channel's default sub-channel is
|
|
20494
|
+
// the channel itself (ChannelActivityService migration row I2). A thread or
|
|
20495
|
+
// unknown channel resolves to undefined, as before.
|
|
20496
|
+
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);
|
|
19678
20497
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
19679
20498
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
20499
|
+
// Own-send update (ChannelActivityService row 1): move the channel at send
|
|
20500
|
+
// time, synchronously, so the confirmation on the send response always sees
|
|
20501
|
+
// this value rather than racing the scheduled local event below.
|
|
20502
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
19680
20503
|
fireEvent('local.message.created', { messages: [message] });
|
|
19681
20504
|
return message;
|
|
19682
20505
|
};
|
|
@@ -19716,6 +20539,9 @@ const createMessage = async (bundle) => {
|
|
|
19716
20539
|
if (client.cache) {
|
|
19717
20540
|
ingestInCache(data, { cachedAt });
|
|
19718
20541
|
}
|
|
20542
|
+
// The own-send update wrote the device-clock createdAt; replace it with the
|
|
20543
|
+
// server's now that the message is confirmed (ChannelActivityService REQ-009).
|
|
20544
|
+
confirmOwnMessage(optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.channelId, optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.createdAt, messages[0].createdAt);
|
|
19719
20545
|
fireEvent('local.message.created', {
|
|
19720
20546
|
messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
19721
20547
|
});
|
|
@@ -20309,23 +21135,85 @@ getDeliveredUsers.locally = (query) => {
|
|
|
20309
21135
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
20310
21136
|
};
|
|
20311
21137
|
|
|
20312
|
-
|
|
20313
|
-
id: message.flag
|
|
20314
|
-
*/
|
|
21138
|
+
const CONTENT_FLAG_REASONS = Object.values(ContentFlagReasonEnum);
|
|
20315
21139
|
/**
|
|
20316
|
-
*
|
|
20317
|
-
*
|
|
20318
|
-
*
|
|
20319
|
-
|
|
21140
|
+
* True when a public `flagX(id, input)` argument is the legacy shape (a reason string
|
|
21141
|
+
* or nothing). Anything else is routed to the `Amity.ContentFlagOptions` path, whose
|
|
21142
|
+
* validation rejects malformed values before any request is made.
|
|
21143
|
+
*/
|
|
21144
|
+
const isLegacyContentFlagReason = (input) => input === undefined || typeof input === 'string';
|
|
21145
|
+
/**
|
|
21146
|
+
* Validates an `Amity.ContentFlagOptions` argument. Untyped (plain JS) callers can pass
|
|
21147
|
+
* anything at runtime, so the checks do not trust the declared type: the value must be a
|
|
21148
|
+
* plain object, `reason` must be one of the nine `ContentFlagReasonEnum` values and
|
|
21149
|
+
* `detail`, when supplied, must be a string (`null` is not a valid supplied detail).
|
|
20320
21150
|
*
|
|
20321
|
-
* @param
|
|
20322
|
-
* @
|
|
20323
|
-
|
|
21151
|
+
* @param apiName used in the error message, e.g. `flagPost`
|
|
21152
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
21153
|
+
*/
|
|
21154
|
+
const validateContentFlagOptions = (apiName, options) => {
|
|
21155
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
21156
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`{ reason, detail? }\``);
|
|
21157
|
+
}
|
|
21158
|
+
const { reason, detail } = options;
|
|
21159
|
+
if (typeof reason !== 'string' || !CONTENT_FLAG_REASONS.includes(reason)) {
|
|
21160
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
21161
|
+
}
|
|
21162
|
+
if (detail !== undefined && typeof detail !== 'string') {
|
|
21163
|
+
throw new ASCInvalidParameterError(`${apiName}: \`detail\` must be a string when supplied`);
|
|
21164
|
+
}
|
|
21165
|
+
return { reason: reason, detail };
|
|
21166
|
+
};
|
|
21167
|
+
/**
|
|
21168
|
+
* Builds the request body for validated options. `detail` is forwarded unchanged (empty
|
|
21169
|
+
* and whitespace-only strings included) and omitted from the body when `undefined`; the
|
|
21170
|
+
* backend enforces the 300-character limit.
|
|
21171
|
+
*/
|
|
21172
|
+
const toContentFlagBody = ({ reason, detail }) => detail === undefined ? { reason } : { reason, detail };
|
|
21173
|
+
|
|
21174
|
+
/**
|
|
21175
|
+
* New `flagMessage(messageId, { reason, detail? })` implementation. Any category,
|
|
21176
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
21177
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
21178
|
+
* the backend enforces the 300-character limit.
|
|
20324
21179
|
*
|
|
20325
|
-
*
|
|
20326
|
-
*
|
|
20327
|
-
*
|
|
20328
|
-
|
|
21180
|
+
* Not exported from the public API. It is reached through the
|
|
21181
|
+
* `MessageRepository.flagMessage(messageId, options)` overload; see `api/flagMessage.ts`.
|
|
21182
|
+
*
|
|
21183
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
21184
|
+
*/
|
|
21185
|
+
const flagMessageWithOptions = async (messageId, options) => {
|
|
21186
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
21187
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
21188
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagMessage', options));
|
|
21189
|
+
const client = getActiveClient();
|
|
21190
|
+
client.log('message/flag', messageId);
|
|
21191
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
|
|
21192
|
+
if (client.cache) {
|
|
21193
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
21194
|
+
ingestInCache(messagePayload);
|
|
21195
|
+
}
|
|
21196
|
+
fireEvent('message.flagged', payload);
|
|
21197
|
+
return !!payload;
|
|
21198
|
+
};
|
|
21199
|
+
|
|
21200
|
+
/**
|
|
21201
|
+
* Legacy `flagMessage(messageId, reason?)` implementation, kept verbatim so existing
|
|
21202
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
21203
|
+
*
|
|
21204
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
21205
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
21206
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
21207
|
+
* (for `undefined` the message body carries `detail: undefined`, which JSON serialization omits)
|
|
21208
|
+
*
|
|
21209
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
21210
|
+
* `MessageRepository.flagMessage(messageId, reason)` overload; see `api/flagMessage.ts`.
|
|
21211
|
+
*
|
|
21212
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
21213
|
+
* `flagMessage`, which carries the deprecation tag. New code should use `flagMessageWithOptions`
|
|
21214
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
21215
|
+
*/
|
|
21216
|
+
const flagMessageWithReasonString = async (messageId, reason) => {
|
|
20329
21217
|
const client = getActiveClient();
|
|
20330
21218
|
client.log('message/flag', messageId);
|
|
20331
21219
|
const isPredefinedReason = reason &&
|
|
@@ -20342,6 +21230,42 @@ const flagMessage = async (messageId, reason) => {
|
|
|
20342
21230
|
fireEvent('message.flagged', payload);
|
|
20343
21231
|
return !!payload;
|
|
20344
21232
|
};
|
|
21233
|
+
|
|
21234
|
+
/* begin_public_function
|
|
21235
|
+
id: message.flag
|
|
21236
|
+
*/
|
|
21237
|
+
/**
|
|
21238
|
+
* ```js
|
|
21239
|
+
* import { MessageRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
21240
|
+
*
|
|
21241
|
+
* // No reason.
|
|
21242
|
+
* await MessageRepository.flagMessage(messageId)
|
|
21243
|
+
*
|
|
21244
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
21245
|
+
* await MessageRepository.flagMessage(messageId, {
|
|
21246
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
21247
|
+
* detail: 'Repeated promotional links',
|
|
21248
|
+
* })
|
|
21249
|
+
* ```
|
|
21250
|
+
*
|
|
21251
|
+
* Reports a message to moderation. Three call shapes are accepted (see the overloads):
|
|
21252
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
21253
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
21254
|
+
* so the legacy path is untouched by the new contract:
|
|
21255
|
+
*
|
|
21256
|
+
* - `undefined` or a string → `flagMessageWithReasonString` (unchanged legacy mapping)
|
|
21257
|
+
* - anything else → `flagMessageWithOptions` (validated `{ reason, detail? }`)
|
|
21258
|
+
*
|
|
21259
|
+
* @param messageId The ID of the message to flag
|
|
21260
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
21261
|
+
* @returns `true` when the report was created
|
|
21262
|
+
*
|
|
21263
|
+
* @category Message API
|
|
21264
|
+
* @async
|
|
21265
|
+
* */
|
|
21266
|
+
const flagMessage = (messageId, input) => isLegacyContentFlagReason(input)
|
|
21267
|
+
? flagMessageWithReasonString(messageId, input)
|
|
21268
|
+
: flagMessageWithOptions(messageId, input);
|
|
20345
21269
|
/* end_public_function */
|
|
20346
21270
|
|
|
20347
21271
|
/* begin_public_function
|
|
@@ -22061,6 +22985,9 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22061
22985
|
case 'lastCreated':
|
|
22062
22986
|
channels = channels.sort(sortByLastCreated);
|
|
22063
22987
|
break;
|
|
22988
|
+
case 'lastMessage':
|
|
22989
|
+
channels = channels.sort(sortByLastMessage);
|
|
22990
|
+
break;
|
|
22064
22991
|
case 'displayName':
|
|
22065
22992
|
/*
|
|
22066
22993
|
* The server returns channels with empty | null displayName's first before
|
|
@@ -22121,9 +23048,8 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22121
23048
|
objectResolverEngine.resolve(message.channelId, "channel" /* Amity.ReferenceType.CHANNEL */);
|
|
22122
23049
|
}
|
|
22123
23050
|
else {
|
|
22124
|
-
|
|
22125
|
-
|
|
22126
|
-
});
|
|
23051
|
+
// lastActivity / lastMessageAt are moved by channelActivityOnLoginHandler
|
|
23052
|
+
// (session-wide, monotonic, one write). This listener only re-sorts.
|
|
22127
23053
|
callback(message);
|
|
22128
23054
|
}
|
|
22129
23055
|
});
|
|
@@ -22141,9 +23067,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22141
23067
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22142
23068
|
if (!cacheData)
|
|
22143
23069
|
return;
|
|
22144
|
-
|
|
22145
|
-
lastActivity: message.createdAt,
|
|
22146
|
-
});
|
|
23070
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22147
23071
|
callback(message);
|
|
22148
23072
|
});
|
|
22149
23073
|
}, 'channelId', 'channel'),
|
|
@@ -22881,9 +23805,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22881
23805
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22882
23806
|
if (!cacheData)
|
|
22883
23807
|
return;
|
|
22884
|
-
|
|
22885
|
-
lastActivity: message.createdAt,
|
|
22886
|
-
});
|
|
23808
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22887
23809
|
callback(message);
|
|
22888
23810
|
});
|
|
22889
23811
|
}, 'channelId', 'channel'),
|
|
@@ -22900,9 +23822,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22900
23822
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22901
23823
|
if (!cacheData)
|
|
22902
23824
|
return;
|
|
22903
|
-
|
|
22904
|
-
lastActivity: message.createdAt,
|
|
22905
|
-
});
|
|
23825
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22906
23826
|
callback(message);
|
|
22907
23827
|
});
|
|
22908
23828
|
}, 'channelId', 'channel'),
|
|
@@ -23325,7 +24245,7 @@ const onUserDeleted$1 = (channelId) => (callback) => {
|
|
|
23325
24245
|
'get',
|
|
23326
24246
|
channelUserCacheKey,
|
|
23327
24247
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23328
|
-
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
24248
|
+
upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }));
|
|
23329
24249
|
const channel = (_b = pullFromCache([
|
|
23330
24250
|
'channel',
|
|
23331
24251
|
'get',
|
|
@@ -24798,10 +25718,10 @@ const onUserDeleted = (communityId) => (callback) => {
|
|
|
24798
25718
|
'get',
|
|
24799
25719
|
communityUserCacheKey,
|
|
24800
25720
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24801
|
-
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
|
|
25721
|
+
pushToCache(['communityUsers', 'get', communityUserCacheKey], Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }));
|
|
24802
25722
|
const community = (_b = pullFromCache(['community', 'get', communityId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
24803
25723
|
callback(community, [
|
|
24804
|
-
Object.assign(Object.assign({}, cacheData), { user }),
|
|
25724
|
+
Object.assign(Object.assign({}, cacheData), { user: userLinkedObject(user) }),
|
|
24805
25725
|
]);
|
|
24806
25726
|
};
|
|
24807
25727
|
return createEventSubscriber(client, 'user.deleted', 'user.deleted', filter);
|
|
@@ -27488,23 +28408,22 @@ const declineComment = async (commentId, reason) => {
|
|
|
27488
28408
|
};
|
|
27489
28409
|
/* end_public_function */
|
|
27490
28410
|
|
|
27491
|
-
/* begin_public_function
|
|
27492
|
-
id: comment.flag
|
|
27493
|
-
*/
|
|
27494
28411
|
/**
|
|
27495
|
-
*
|
|
27496
|
-
*
|
|
27497
|
-
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
27498
|
-
* ```
|
|
28412
|
+
* Legacy `flagComment(commentId, reason?)` implementation, kept verbatim so existing
|
|
28413
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
27499
28414
|
*
|
|
27500
|
-
*
|
|
27501
|
-
*
|
|
27502
|
-
*
|
|
28415
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
28416
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
28417
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
27503
28418
|
*
|
|
27504
|
-
*
|
|
27505
|
-
*
|
|
27506
|
-
*
|
|
27507
|
-
|
|
28419
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
28420
|
+
* `CommentRepository.flagComment(commentId, reason)` overload; see `api/flagComment.ts`.
|
|
28421
|
+
*
|
|
28422
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
28423
|
+
* `flagComment`, which carries the deprecation tag. New code should use `flagCommentWithOptions`
|
|
28424
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
28425
|
+
*/
|
|
28426
|
+
const flagCommentWithReasonString = async (commentId, reason) => {
|
|
27508
28427
|
const client = getActiveClient();
|
|
27509
28428
|
client.log('comment/flagComment', commentId);
|
|
27510
28429
|
const isPredefinedReason = reason &&
|
|
@@ -27520,6 +28439,67 @@ const flagComment = async (commentId, reason) => {
|
|
|
27520
28439
|
fireEvent('comment.flagged', payload);
|
|
27521
28440
|
return !!payload;
|
|
27522
28441
|
};
|
|
28442
|
+
|
|
28443
|
+
/**
|
|
28444
|
+
* New `flagComment(commentId, { reason, detail? })` implementation. Any category,
|
|
28445
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
28446
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
28447
|
+
* the backend enforces the 300-character limit.
|
|
28448
|
+
*
|
|
28449
|
+
* Not exported from the public API. It is reached through the
|
|
28450
|
+
* `CommentRepository.flagComment(commentId, options)` overload; see `api/flagComment.ts`.
|
|
28451
|
+
*
|
|
28452
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
28453
|
+
*/
|
|
28454
|
+
const flagCommentWithOptions = async (commentId, options) => {
|
|
28455
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
28456
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
28457
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagComment', options));
|
|
28458
|
+
const client = getActiveClient();
|
|
28459
|
+
client.log('comment/flagComment', commentId);
|
|
28460
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
28461
|
+
if (client.cache) {
|
|
28462
|
+
ingestInCache(payload);
|
|
28463
|
+
}
|
|
28464
|
+
fireEvent('comment.flagged', payload);
|
|
28465
|
+
return !!payload;
|
|
28466
|
+
};
|
|
28467
|
+
|
|
28468
|
+
/* begin_public_function
|
|
28469
|
+
id: comment.flag
|
|
28470
|
+
*/
|
|
28471
|
+
/**
|
|
28472
|
+
* ```js
|
|
28473
|
+
* import { CommentRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
28474
|
+
*
|
|
28475
|
+
* // No reason: sent as Others with an empty detail.
|
|
28476
|
+
* await CommentRepository.flagComment(commentId)
|
|
28477
|
+
*
|
|
28478
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
28479
|
+
* await CommentRepository.flagComment(commentId, {
|
|
28480
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
28481
|
+
* detail: 'Repeated promotional links',
|
|
28482
|
+
* })
|
|
28483
|
+
* ```
|
|
28484
|
+
*
|
|
28485
|
+
* Reports a comment to moderation. Three call shapes are accepted (see the overloads):
|
|
28486
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
28487
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
28488
|
+
* so the legacy path is untouched by the new contract:
|
|
28489
|
+
*
|
|
28490
|
+
* - `undefined` or a string → `flagCommentWithReasonString` (unchanged legacy mapping)
|
|
28491
|
+
* - anything else → `flagCommentWithOptions` (validated `{ reason, detail? }`)
|
|
28492
|
+
*
|
|
28493
|
+
* @param commentId The ID of the comment to flag
|
|
28494
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
28495
|
+
* @returns `true` when the report was created
|
|
28496
|
+
*
|
|
28497
|
+
* @category Comment API
|
|
28498
|
+
* @async
|
|
28499
|
+
* */
|
|
28500
|
+
const flagComment = (commentId, input) => isLegacyContentFlagReason(input)
|
|
28501
|
+
? flagCommentWithReasonString(commentId, input)
|
|
28502
|
+
: flagCommentWithOptions(commentId, input);
|
|
27523
28503
|
/* end_public_function */
|
|
27524
28504
|
|
|
27525
28505
|
/* begin_public_function
|
|
@@ -29873,23 +30853,47 @@ const declinePost = async (postId) => {
|
|
|
29873
30853
|
};
|
|
29874
30854
|
/* end_public_function */
|
|
29875
30855
|
|
|
29876
|
-
/* begin_public_function
|
|
29877
|
-
id: post.flag
|
|
29878
|
-
*/
|
|
29879
30856
|
/**
|
|
29880
|
-
*
|
|
29881
|
-
*
|
|
29882
|
-
*
|
|
29883
|
-
*
|
|
30857
|
+
* New `flagPost(postId, { reason, detail? })` implementation. Any category, including
|
|
30858
|
+
* `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
30859
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
30860
|
+
* the backend enforces the 300-character limit.
|
|
29884
30861
|
*
|
|
29885
|
-
*
|
|
29886
|
-
*
|
|
29887
|
-
* @returns a boolean
|
|
30862
|
+
* Not exported from the public API. It is reached through the
|
|
30863
|
+
* `PostRepository.flagPost(postId, options)` overload; see `api/flagPost.ts`.
|
|
29888
30864
|
*
|
|
29889
|
-
* @
|
|
29890
|
-
|
|
29891
|
-
|
|
29892
|
-
|
|
30865
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
30866
|
+
*/
|
|
30867
|
+
const flagPostWithOptions = async (postId, options) => {
|
|
30868
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
30869
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
30870
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagPost', options));
|
|
30871
|
+
const client = getActiveClient();
|
|
30872
|
+
client.log('post/flagPost', postId);
|
|
30873
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
30874
|
+
if (client.cache) {
|
|
30875
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30876
|
+
}
|
|
30877
|
+
fireEvent('post.flagged', payload);
|
|
30878
|
+
return !!payload;
|
|
30879
|
+
};
|
|
30880
|
+
|
|
30881
|
+
/**
|
|
30882
|
+
* Legacy `flagPost(postId, reason?)` implementation, kept verbatim so existing
|
|
30883
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
30884
|
+
*
|
|
30885
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
30886
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
30887
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
30888
|
+
*
|
|
30889
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
30890
|
+
* `PostRepository.flagPost(postId, reason)` overload; see `api/flagPost.ts`.
|
|
30891
|
+
*
|
|
30892
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
30893
|
+
* `flagPost`, which carries the deprecation tag. New code should use `flagPostWithOptions`
|
|
30894
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
30895
|
+
*/
|
|
30896
|
+
const flagPostWithReasonString = async (postId, reason) => {
|
|
29893
30897
|
const client = getActiveClient();
|
|
29894
30898
|
client.log('post/flagPost', postId);
|
|
29895
30899
|
const isPredefinedReason = reason &&
|
|
@@ -29905,6 +30909,42 @@ const flagPost = async (postId, reason) => {
|
|
|
29905
30909
|
fireEvent('post.flagged', payload);
|
|
29906
30910
|
return !!payload;
|
|
29907
30911
|
};
|
|
30912
|
+
|
|
30913
|
+
/* begin_public_function
|
|
30914
|
+
id: post.flag
|
|
30915
|
+
*/
|
|
30916
|
+
/**
|
|
30917
|
+
* ```js
|
|
30918
|
+
* import { PostRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
30919
|
+
*
|
|
30920
|
+
* // No reason.
|
|
30921
|
+
* await PostRepository.flagPost(postId)
|
|
30922
|
+
*
|
|
30923
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
30924
|
+
* await PostRepository.flagPost(postId, {
|
|
30925
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
30926
|
+
* detail: 'Repeated promotional links',
|
|
30927
|
+
* })
|
|
30928
|
+
* ```
|
|
30929
|
+
*
|
|
30930
|
+
* Reports a post to moderation. Three call shapes are accepted (see the overloads):
|
|
30931
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
30932
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
30933
|
+
* so the legacy path is untouched by the new contract:
|
|
30934
|
+
*
|
|
30935
|
+
* - `undefined` or a string → `flagPostWithReasonString` (unchanged legacy mapping)
|
|
30936
|
+
* - anything else → `flagPostWithOptions` (validated `{ reason, detail? }`)
|
|
30937
|
+
*
|
|
30938
|
+
* @param postId The ID of the post to flag
|
|
30939
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
30940
|
+
* @returns `true` when the report was created
|
|
30941
|
+
*
|
|
30942
|
+
* @category Post API
|
|
30943
|
+
* @async
|
|
30944
|
+
* */
|
|
30945
|
+
const flagPost = (postId, input) => isLegacyContentFlagReason(input)
|
|
30946
|
+
? flagPostWithReasonString(postId, input)
|
|
30947
|
+
: flagPostWithOptions(postId, input);
|
|
29908
30948
|
/* end_public_function */
|
|
29909
30949
|
|
|
29910
30950
|
/* begin_public_function
|
|
@@ -37277,4 +38317,4 @@ class AmityAttachmentProductTags {
|
|
|
37277
38317
|
}
|
|
37278
38318
|
}
|
|
37279
38319
|
|
|
37280
|
-
export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmityModuleNotEntitledError, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserReportTypeEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, resolveModuleAvailability, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|
|
38320
|
+
export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmityModuleNotEntitledError, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserProfileFieldEnum, UserReportTypeEnum, UserReportTypeFilterEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, resolveModuleAvailability, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastMessage, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|