@amityco/ts-sdk 7.29.1-e932a95f.0 → 7.30.1-2bd00c07.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +6 -0
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +16 -10
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +448 -138
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +446 -139
- package/dist/index.umd.js +2 -2
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/flagUserBehavior.d.ts +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts +9 -23
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts.map +1 -1
- package/dist/userRepository/api/unflagUser.d.ts +5 -4
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
- package/dist/userRepository/internalApi/getFlagsByMe.d.ts +4 -3
- package/dist/userRepository/internalApi/getFlagsByMe.d.ts.map +1 -1
- 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/getUser.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/utils/submitUserReport.d.ts.map +1 -1
- 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 +1 -1
- package/dist/utils/bloomFilter.d.ts +8 -3
- package/dist/utils/bloomFilter.d.ts.map +1 -1
- package/dist/utils/contentFlag.d.ts +1 -1
- package/dist/utils/contentFlagReason.d.ts +32 -0
- package/dist/utils/contentFlagReason.d.ts.map +1 -0
- package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/contentFlagReason.test.d.ts +2 -0
- package/dist/utils/tests/contentFlagReason.test.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -58,7 +58,7 @@ var UserProfileFieldEnum;
|
|
|
58
58
|
* Selects which of the caller's reports `UserRepository.unflagUser` withdraws, sent as the
|
|
59
59
|
* `reportType` query parameter. The four typed members are the backend `reportType` wire
|
|
60
60
|
* values and match `UserReportTypeEnum`. `UNTYPED` selects the typeless (legacy) report,
|
|
61
|
-
* which `
|
|
61
|
+
* which `user.getUserFlagsByMe()` returns as `reportType: null`; it is a selector only, never
|
|
62
62
|
* stored, and the flag endpoint refuses it.
|
|
63
63
|
*/
|
|
64
64
|
var UserReportTypeFilterEnum;
|
|
@@ -145,6 +145,7 @@ const ContentFeedType = Object.freeze({
|
|
|
145
145
|
var ContentFlagReasonEnum;
|
|
146
146
|
(function (ContentFlagReasonEnum) {
|
|
147
147
|
ContentFlagReasonEnum["CommunityGuidelines"] = "Against community guidelines";
|
|
148
|
+
ContentFlagReasonEnum["ChildEndangerment"] = "Child endangerment";
|
|
148
149
|
ContentFlagReasonEnum["HarassmentOrBullying"] = "Harassment or bullying";
|
|
149
150
|
ContentFlagReasonEnum["SelfHarmOrSuicide"] = "Self-harm or suicide";
|
|
150
151
|
ContentFlagReasonEnum["ViolenceOrThreateningContent"] = "Violence or threatening content";
|
|
@@ -343,8 +344,8 @@ var AmityLiveViewerCountMode;
|
|
|
343
344
|
|
|
344
345
|
function getVersion() {
|
|
345
346
|
try {
|
|
346
|
-
// the string ''v7.
|
|
347
|
-
return 'v7.
|
|
347
|
+
// the string ''v7.30.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
348
|
+
return 'v7.30.0-esm';
|
|
348
349
|
}
|
|
349
350
|
catch (error) {
|
|
350
351
|
return '__dev__';
|
|
@@ -1836,15 +1837,64 @@ async function modifyMqttConnection() {
|
|
|
1836
1837
|
}
|
|
1837
1838
|
}
|
|
1838
1839
|
|
|
1840
|
+
class SessionWatcher {
|
|
1841
|
+
constructor() {
|
|
1842
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
1843
|
+
this._listener = new Map();
|
|
1844
|
+
}
|
|
1845
|
+
onSessionStateChange(callback) {
|
|
1846
|
+
this._listener.set(callback, callback);
|
|
1847
|
+
return () => {
|
|
1848
|
+
this._listener.delete(callback);
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
setSessionState(state, reason) {
|
|
1852
|
+
if (this._sessionState === state)
|
|
1853
|
+
return;
|
|
1854
|
+
this._sessionState = state;
|
|
1855
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
1856
|
+
}
|
|
1857
|
+
destroy() {
|
|
1858
|
+
this._listener.clear();
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
let instance$b;
|
|
1862
|
+
var SessionWatcher$1 = {
|
|
1863
|
+
getInstance: () => {
|
|
1864
|
+
if (!instance$b) {
|
|
1865
|
+
instance$b = new SessionWatcher();
|
|
1866
|
+
}
|
|
1867
|
+
return instance$b;
|
|
1868
|
+
},
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
/**
|
|
1872
|
+
* ```js
|
|
1873
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
1874
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
1875
|
+
* // ...
|
|
1876
|
+
* })
|
|
1877
|
+
* ```
|
|
1878
|
+
*
|
|
1879
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
1880
|
+
*
|
|
1881
|
+
* @param callback The function to call when the event was fired
|
|
1882
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
1883
|
+
*
|
|
1884
|
+
* @category Client Events
|
|
1885
|
+
*/
|
|
1886
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
1887
|
+
|
|
1839
1888
|
/**
|
|
1840
1889
|
* ```js
|
|
1841
1890
|
* import { getFlagsByMe } from '~/userRepository/internalApi/getFlagsByMe'
|
|
1842
1891
|
* const { isFlagByMe, flags } = await getFlagsByMe('userId')
|
|
1843
1892
|
* ```
|
|
1844
1893
|
*
|
|
1845
|
-
* The v4 read behind `user.getUserFlagsByMe()
|
|
1846
|
-
* `
|
|
1847
|
-
* received. Nothing is filtered, cached or
|
|
1894
|
+
* The v4 read behind `user.getUserFlagsByMe()`, the background confirm of
|
|
1895
|
+
* `user.isFlaggedByMe`, and the deprecated `UserRepository.isUserFlaggedByMe`:
|
|
1896
|
+
* `GET /api/v4/users/:userId/isFlagByMe`, returned as received. Nothing is filtered, cached or
|
|
1897
|
+
* persisted here, and `hashFlag` is not consulted.
|
|
1848
1898
|
* This is the Web counterpart of iOS `ASCUserService.getFlagsByMe` and Android
|
|
1849
1899
|
* `UserRepository.getFlagsByMe`, kept apart from the deprecated public function so the
|
|
1850
1900
|
* user-object read does not change if that function ever does.
|
|
@@ -1905,35 +1955,72 @@ const locationsFor = (value, bits, hashes) => {
|
|
|
1905
1955
|
}
|
|
1906
1956
|
return locations;
|
|
1907
1957
|
};
|
|
1958
|
+
/** Standard or URL-safe base64, padding optional. Anything else is not a filter we can read. */
|
|
1959
|
+
const BASE64 = /^[A-Za-z0-9+/_-]*={0,2}$/;
|
|
1908
1960
|
/**
|
|
1909
|
-
* Whether `value` is probably in the filter. `false` is exact; `true`
|
|
1910
|
-
*
|
|
1911
|
-
*
|
|
1961
|
+
* Whether `value` is probably in the filter. `false` is exact; `true` means "maybe", which may be
|
|
1962
|
+
* a false positive. `null` (the server's value when nobody has flagged the object), a missing
|
|
1963
|
+
* filter or a missing value answer `false`.
|
|
1964
|
+
*
|
|
1965
|
+
* A filter that cannot be read answers `true` ("maybe") and never throws, so the caller asks the
|
|
1966
|
+
* server instead of trusting a "definitely not" it cannot back up (REQ-017): `bits` or `hashes`
|
|
1967
|
+
* not a positive integer, a `hash` that is not base64, or a `hash` shorter than `ceil(bits / 8)`
|
|
1968
|
+
* bytes.
|
|
1912
1969
|
*/
|
|
1913
1970
|
const testBloomFilter = (hashFlag, value) => {
|
|
1914
1971
|
if (!hashFlag || !value)
|
|
1915
1972
|
return false;
|
|
1916
1973
|
const { bits, hashes, hash } = hashFlag;
|
|
1917
|
-
if (!(bits
|
|
1918
|
-
return
|
|
1974
|
+
if (!Number.isInteger(bits) || bits <= 0)
|
|
1975
|
+
return true;
|
|
1976
|
+
if (!Number.isInteger(hashes) || hashes <= 0)
|
|
1977
|
+
return true;
|
|
1978
|
+
if (typeof hash !== 'string' || !BASE64.test(hash))
|
|
1979
|
+
return true;
|
|
1919
1980
|
let buckets;
|
|
1920
1981
|
try {
|
|
1921
1982
|
buckets = toUint8Array(hash);
|
|
1922
1983
|
}
|
|
1923
1984
|
catch (_a) {
|
|
1924
|
-
return
|
|
1985
|
+
return true;
|
|
1925
1986
|
}
|
|
1987
|
+
if (buckets.length < Math.ceil(bits / 8))
|
|
1988
|
+
return true;
|
|
1926
1989
|
const locations = locationsFor(value, bits, hashes);
|
|
1927
1990
|
for (let i = 0; i < locations.length; i += 1) {
|
|
1928
1991
|
const index = Math.floor(locations[i] / 8);
|
|
1929
1992
|
const bit = 1 << locations[i] % 8;
|
|
1930
|
-
if (
|
|
1993
|
+
if ((buckets[index] & bit) === 0)
|
|
1931
1994
|
return false;
|
|
1932
1995
|
}
|
|
1933
1996
|
return true;
|
|
1934
1997
|
};
|
|
1935
1998
|
|
|
1936
|
-
/**
|
|
1999
|
+
/**
|
|
2000
|
+
* Flag state of the current user on a target user, behind `Amity.User.isFlaggedByMe` and
|
|
2001
|
+
* `Amity.User.getUserFlagsByMe()` (`user.check_flag_by_me` v1, REQ-011, REQ-012, REQ-016).
|
|
2002
|
+
*
|
|
2003
|
+
* `hashFlag` is a Bloom filter of reporter ids. "Definitely not" is exact. "Maybe" can be a
|
|
2004
|
+
* false positive caused by other reporters, so the SDK confirms it with the server once per
|
|
2005
|
+
* `hashFlag` value and records the answer in the cache under its own key, never on the user's
|
|
2006
|
+
* cache row (REQ-015). Observers are told through `local.user.flagConfirmed` when a recorded
|
|
2007
|
+
* answer changes what a user object would show.
|
|
2008
|
+
*
|
|
2009
|
+
* Not exported from the public API.
|
|
2010
|
+
*/
|
|
2011
|
+
/** Confirms for the same user are at least this far apart, as Android's `EkoFlag.expired`. */
|
|
2012
|
+
const FLAG_CONFIRM_INTERVAL = 1000;
|
|
2013
|
+
const cacheKey = (userId) => ['userFlagByMe', 'get', userId];
|
|
2014
|
+
const lastConfirmAt = new Map();
|
|
2015
|
+
/**
|
|
2016
|
+
* Bumped by the current user's own flag and unflag. A confirm or exact read that started before
|
|
2017
|
+
* one of them must not record its answer, because the write may have changed it while the
|
|
2018
|
+
* `hashFlag` stayed the same.
|
|
2019
|
+
*/
|
|
2020
|
+
const generations = new Map();
|
|
2021
|
+
const generationOf = (userId) => { var _a; return (_a = generations.get(userId)) !== null && _a !== void 0 ? _a : 0; };
|
|
2022
|
+
const bumpGeneration = (userId) => generations.set(userId, generationOf(userId) + 1);
|
|
2023
|
+
/** The current user's id, or `undefined` when there is no active client. Never throws. */
|
|
1937
2024
|
const currentUserId = () => {
|
|
1938
2025
|
try {
|
|
1939
2026
|
return getActiveClient().userId;
|
|
@@ -1942,43 +2029,223 @@ const currentUserId = () => {
|
|
|
1942
2029
|
return undefined;
|
|
1943
2030
|
}
|
|
1944
2031
|
};
|
|
2032
|
+
const readRecord = (userId) => {
|
|
2033
|
+
var _a;
|
|
2034
|
+
try {
|
|
2035
|
+
return (_a = pullFromCache(cacheKey(userId))) === null || _a === void 0 ? void 0 : _a.data;
|
|
2036
|
+
}
|
|
2037
|
+
catch (_b) {
|
|
2038
|
+
return undefined;
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
1945
2041
|
/**
|
|
1946
|
-
*
|
|
1947
|
-
*
|
|
1948
|
-
* functions by reference: a fresh closure on every linked object would make two reads of the
|
|
1949
|
-
* same user unequal and re-dispatch snapshots that did not change.
|
|
2042
|
+
* The server's answer recorded for this user and this exact `hashFlag`, or `undefined` when there
|
|
2043
|
+
* is none for the current user. Never throws.
|
|
1950
2044
|
*/
|
|
1951
|
-
const
|
|
2045
|
+
const readConfirmedFlag = (userId, hashFlag) => {
|
|
2046
|
+
const me = currentUserId();
|
|
2047
|
+
if (!me || !hashFlag || typeof hashFlag.hash !== 'string')
|
|
2048
|
+
return undefined;
|
|
2049
|
+
const record = readRecord(userId);
|
|
2050
|
+
if (!record || record.reporterId !== me || record.hash !== hashFlag.hash)
|
|
2051
|
+
return undefined;
|
|
2052
|
+
return record.isFlagByMe;
|
|
2053
|
+
};
|
|
1952
2054
|
/**
|
|
1953
|
-
*
|
|
1954
|
-
*
|
|
1955
|
-
*
|
|
2055
|
+
* The v4 request in flight per user, with the generation it started in. A confirm and an exact
|
|
2056
|
+
* read of the same user share one request; a request that started before the current user's own
|
|
2057
|
+
* flag or unflag is not joined.
|
|
1956
2058
|
*/
|
|
1957
|
-
const
|
|
2059
|
+
const inFlight = new Map();
|
|
2060
|
+
const requestFlagsByMe = (userId) => {
|
|
2061
|
+
const generation = generationOf(userId);
|
|
2062
|
+
const pending = inFlight.get(userId);
|
|
2063
|
+
if (pending && pending.generation === generation)
|
|
2064
|
+
return pending.promise;
|
|
2065
|
+
const promise = getFlagsByMe(userId).finally(() => {
|
|
2066
|
+
var _a;
|
|
2067
|
+
if (((_a = inFlight.get(userId)) === null || _a === void 0 ? void 0 : _a.promise) === promise)
|
|
2068
|
+
inFlight.delete(userId);
|
|
2069
|
+
});
|
|
2070
|
+
inFlight.set(userId, { generation, promise });
|
|
2071
|
+
return promise;
|
|
2072
|
+
};
|
|
2073
|
+
const notifyObservers = (userId) => fireEvent('local.user.flagConfirmed', { userId });
|
|
2074
|
+
/**
|
|
2075
|
+
* Records `isFlagByMe` for `hashFlag`. A "maybe" without a record shows `true`, so observers are
|
|
2076
|
+
* told only when the shown value changes.
|
|
2077
|
+
*/
|
|
2078
|
+
const recordFlag = (userId, hashFlag, isFlagByMe) => {
|
|
1958
2079
|
var _a;
|
|
1959
2080
|
const me = currentUserId();
|
|
1960
|
-
|
|
1961
|
-
|
|
2081
|
+
if (!me || typeof hashFlag.hash !== 'string')
|
|
2082
|
+
return;
|
|
2083
|
+
const shown = (_a = readConfirmedFlag(userId, hashFlag)) !== null && _a !== void 0 ? _a : true;
|
|
2084
|
+
const record = { reporterId: me, hash: hashFlag.hash, isFlagByMe };
|
|
2085
|
+
pushToCache(cacheKey(userId), record);
|
|
2086
|
+
if (shown !== isFlagByMe)
|
|
2087
|
+
notifyObservers(userId);
|
|
2088
|
+
};
|
|
2089
|
+
/**
|
|
2090
|
+
* Starts one background confirm of a "maybe" (REQ-016): at most one in flight per user, and
|
|
2091
|
+
* confirms for the same user at least {@link FLAG_CONFIRM_INTERVAL} apart. A failed confirm
|
|
2092
|
+
* records nothing, surfaces no error, and a later read tries again.
|
|
2093
|
+
*/
|
|
2094
|
+
const confirmFlagByMe = (userId, hashFlag) => {
|
|
2095
|
+
if (inFlight.has(userId))
|
|
2096
|
+
return;
|
|
2097
|
+
const now = Date.now();
|
|
2098
|
+
const last = lastConfirmAt.get(userId);
|
|
2099
|
+
if (last !== undefined && now - last < FLAG_CONFIRM_INTERVAL)
|
|
2100
|
+
return;
|
|
2101
|
+
const me = currentUserId();
|
|
2102
|
+
const generation = generationOf(userId);
|
|
2103
|
+
lastConfirmAt.set(userId, now);
|
|
2104
|
+
requestFlagsByMe(userId)
|
|
2105
|
+
.then(({ isFlagByMe }) => {
|
|
2106
|
+
if (currentUserId() !== me || generationOf(userId) !== generation)
|
|
2107
|
+
return;
|
|
2108
|
+
recordFlag(userId, hashFlag, isFlagByMe);
|
|
2109
|
+
})
|
|
2110
|
+
.catch(() => {
|
|
2111
|
+
// Not an answer: isFlaggedByMe stays true until a later read confirms again.
|
|
2112
|
+
});
|
|
2113
|
+
};
|
|
2114
|
+
/**
|
|
2115
|
+
* The value of `Amity.User.isFlaggedByMe` for a user object whose confirmed answer was captured
|
|
2116
|
+
* (`confirmed`) when the object was linked, so a held object never changes (REQ-014).
|
|
2117
|
+
*
|
|
2118
|
+
* - No current user, `hashFlag: null` or a missing `hashFlag`, or "definitely not": `false`.
|
|
2119
|
+
* - "Maybe" with a confirmed answer: that answer, no request.
|
|
2120
|
+
* - "Maybe" without one: `true`, and one background confirm (REQ-016).
|
|
2121
|
+
*
|
|
2122
|
+
* The linked object declares this as a getter inside an object spread, which the build compiles
|
|
2123
|
+
* to `Object.assign`, so it runs once when the user is linked and the object keeps that value.
|
|
2124
|
+
*/
|
|
2125
|
+
const isFlaggedByMeFor = (user, confirmed) => {
|
|
2126
|
+
const me = currentUserId();
|
|
2127
|
+
if (!me || !user.hashFlag || !testBloomFilter(user.hashFlag, me))
|
|
1962
2128
|
return false;
|
|
1963
|
-
|
|
2129
|
+
if (confirmed !== undefined)
|
|
2130
|
+
return confirmed;
|
|
2131
|
+
confirmFlagByMe(user.userId, user.hashFlag);
|
|
2132
|
+
return true;
|
|
2133
|
+
};
|
|
2134
|
+
const NOT_FLAGGED = { isFlagByMe: false, flags: [] };
|
|
2135
|
+
const isNotOlder = (next, current) => {
|
|
2136
|
+
var _a, _b;
|
|
2137
|
+
const nextAt = Date.parse((_a = next.updatedAt) !== null && _a !== void 0 ? _a : '');
|
|
2138
|
+
const currentAt = Date.parse((_b = current.updatedAt) !== null && _b !== void 0 ? _b : '');
|
|
2139
|
+
return Number.isNaN(nextAt) || Number.isNaN(currentAt) || nextAt >= currentAt;
|
|
2140
|
+
};
|
|
2141
|
+
/**
|
|
2142
|
+
* One `getUserFlagsByMe` closure per userId, remembering the newest user object linked for that
|
|
2143
|
+
* id. Live objects and collections compare snapshots with `isEqual`, which compares functions by
|
|
2144
|
+
* reference, so a fresh closure per linked object would re-dispatch unchanged snapshots
|
|
2145
|
+
* (REQ-015). An older snapshot linked later does not replace a newer one.
|
|
2146
|
+
*/
|
|
2147
|
+
const flagsByMeEntries = new Map();
|
|
2148
|
+
/**
|
|
2149
|
+
* `Amity.User.getUserFlagsByMe()` (REQ-012): `{ isFlagByMe: false, flags: [] }` with no request
|
|
2150
|
+
* when the newest linked user says "not flagged", including a confirmed `false`. Otherwise the
|
|
2151
|
+
* v4 read, returned as is; a confirm already in flight for the user is joined instead of sending
|
|
2152
|
+
* a second request. Its `isFlagByMe` is recorded as the confirmed answer for the
|
|
2153
|
+
* `hashFlag` it was read for; `flags[]` is never stored (REQ-009). A missing `hashFlag` is
|
|
2154
|
+
* unknown, so the server is asked.
|
|
2155
|
+
*/
|
|
2156
|
+
const readFlagsByMe = async (userId) => {
|
|
2157
|
+
var _a, _b;
|
|
2158
|
+
const me = currentUserId();
|
|
2159
|
+
const { hashFlag } = (_b = (_a = flagsByMeEntries.get(userId)) === null || _a === void 0 ? void 0 : _a.latest) !== null && _b !== void 0 ? _b : {};
|
|
2160
|
+
if (me && hashFlag !== undefined) {
|
|
2161
|
+
if (!hashFlag || !testBloomFilter(hashFlag, me))
|
|
2162
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2163
|
+
if (readConfirmedFlag(userId, hashFlag) === false)
|
|
2164
|
+
return Object.assign(Object.assign({}, NOT_FLAGGED), { flags: [] });
|
|
2165
|
+
}
|
|
2166
|
+
const generation = generationOf(userId);
|
|
2167
|
+
const result = await requestFlagsByMe(userId);
|
|
2168
|
+
if (hashFlag && currentUserId() === me && generationOf(userId) === generation) {
|
|
2169
|
+
recordFlag(userId, hashFlag, result.isFlagByMe);
|
|
2170
|
+
}
|
|
2171
|
+
return result;
|
|
1964
2172
|
};
|
|
1965
2173
|
const getUserFlagsByMeFor = (user) => {
|
|
1966
2174
|
let entry = flagsByMeEntries.get(user.userId);
|
|
1967
2175
|
if (!entry) {
|
|
1968
|
-
entry = {
|
|
1969
|
-
latest: user,
|
|
1970
|
-
getUserFlagsByMe: async () => {
|
|
1971
|
-
if (knownNotFlaggedByMe(user.userId))
|
|
1972
|
-
return { isFlagByMe: false, flags: [] };
|
|
1973
|
-
return getFlagsByMe(user.userId);
|
|
1974
|
-
},
|
|
1975
|
-
};
|
|
2176
|
+
entry = { latest: user, getUserFlagsByMe: () => readFlagsByMe(user.userId) };
|
|
1976
2177
|
flagsByMeEntries.set(user.userId, entry);
|
|
1977
2178
|
}
|
|
1978
|
-
entry.latest
|
|
2179
|
+
else if (isNotOlder(user, entry.latest)) {
|
|
2180
|
+
entry.latest = user;
|
|
2181
|
+
}
|
|
1979
2182
|
return entry.getUserFlagsByMe;
|
|
1980
2183
|
};
|
|
2184
|
+
/**
|
|
2185
|
+
* The current user's own flag succeeded (REQ-016). Their report may leave `hashFlag` unchanged
|
|
2186
|
+
* when other reporters had already set all of their bits, so the answer is known: record `true`
|
|
2187
|
+
* for the `hashFlag` the response carries, or drop the answer when it carries none.
|
|
2188
|
+
*/
|
|
2189
|
+
const onFlaggedByMe = (user, userId) => {
|
|
2190
|
+
bumpGeneration(userId);
|
|
2191
|
+
if (user === null || user === void 0 ? void 0 : user.hashFlag) {
|
|
2192
|
+
recordFlag(userId, user.hashFlag, true);
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
const dropped = readRecord(userId);
|
|
2196
|
+
dropFromCache(cacheKey(userId), true);
|
|
2197
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2198
|
+
notifyObservers(userId);
|
|
2199
|
+
};
|
|
2200
|
+
/**
|
|
2201
|
+
* The current user's own unflag succeeded (`user.unflag` REQ-010, REQ-016). A per-type unflag can
|
|
2202
|
+
* leave other reports in place, so the answer is dropped, never set to `false`; the next "maybe"
|
|
2203
|
+
* is confirmed again.
|
|
2204
|
+
*/
|
|
2205
|
+
const onUnflaggedByMe = (userId) => {
|
|
2206
|
+
bumpGeneration(userId);
|
|
2207
|
+
const dropped = readRecord(userId);
|
|
2208
|
+
dropFromCache(cacheKey(userId), true);
|
|
2209
|
+
if ((dropped === null || dropped === void 0 ? void 0 : dropped.isFlagByMe) === false)
|
|
2210
|
+
notifyObservers(userId);
|
|
2211
|
+
};
|
|
2212
|
+
/** Forgets every in-memory trace of the current user's flag state. Records live in the cache. */
|
|
2213
|
+
const resetUserFlagByMe = () => {
|
|
2214
|
+
flagsByMeEntries.clear();
|
|
2215
|
+
inFlight.clear();
|
|
2216
|
+
lastConfirmAt.clear();
|
|
2217
|
+
generations.clear();
|
|
2218
|
+
};
|
|
2219
|
+
/**
|
|
2220
|
+
* Registered through `setupLoginSubscriptions`. Every confirmed answer belongs to the current
|
|
2221
|
+
* user, so the state is cleared on logout; the records themselves go with the cache, and each
|
|
2222
|
+
* also carries the reporter's id.
|
|
2223
|
+
*/
|
|
2224
|
+
const userFlagByMeOnLoginHandler = () => {
|
|
2225
|
+
const unsubscribe = onSessionStateChange(state => {
|
|
2226
|
+
if (state === "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */ || state === "terminated" /* Amity.SessionStates.TERMINATED */) {
|
|
2227
|
+
resetUserFlagByMe();
|
|
2228
|
+
}
|
|
2229
|
+
});
|
|
2230
|
+
return () => {
|
|
2231
|
+
unsubscribe();
|
|
2232
|
+
resetUserFlagByMe();
|
|
2233
|
+
};
|
|
2234
|
+
};
|
|
2235
|
+
/**
|
|
2236
|
+
* Called with the cached user when a recorded answer changes what that user would show, so live
|
|
2237
|
+
* objects and live collections deliver it again (REQ-016, delivery).
|
|
2238
|
+
*/
|
|
2239
|
+
const onUserFlagConfirmed = (callback) => createEventSubscriber(getActiveClient(), 'user/onUserFlagConfirmed', 'local.user.flagConfirmed', ({ userId }) => {
|
|
2240
|
+
var _a;
|
|
2241
|
+
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
2242
|
+
if (user)
|
|
2243
|
+
callback(user);
|
|
2244
|
+
});
|
|
2245
|
+
|
|
1981
2246
|
const userLinkedObject = (user) => {
|
|
2247
|
+
// Captured now, so a user object the app holds never changes after a confirm (REQ-014).
|
|
2248
|
+
const confirmedFlagByMe = readConfirmedFlag(user.userId, user.hashFlag);
|
|
1982
2249
|
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
1983
2250
|
var _a;
|
|
1984
2251
|
if (!user.avatarFileId)
|
|
@@ -1989,9 +2256,10 @@ const userLinkedObject = (user) => {
|
|
|
1989
2256
|
return avatar;
|
|
1990
2257
|
},
|
|
1991
2258
|
get isFlaggedByMe() {
|
|
1992
|
-
//
|
|
1993
|
-
//
|
|
1994
|
-
|
|
2259
|
+
// Bloom test on this object's hashFlag: "definitely not" is exact and sends nothing.
|
|
2260
|
+
// "Maybe" returns the answer confirmed for this hashFlag, or true while one background
|
|
2261
|
+
// confirm runs (REQ-011, REQ-016). Never throws.
|
|
2262
|
+
return isFlaggedByMeFor(user, confirmedFlagByMe);
|
|
1995
2263
|
},
|
|
1996
2264
|
/* begin_public_function
|
|
1997
2265
|
id: user.get_flags_by_me
|
|
@@ -2263,13 +2531,13 @@ class NetworkActivitiesWatcher {
|
|
|
2263
2531
|
this._listener.clear();
|
|
2264
2532
|
}
|
|
2265
2533
|
}
|
|
2266
|
-
let instance$
|
|
2534
|
+
let instance$a;
|
|
2267
2535
|
var NetworkActivitiesWatcher$1 = {
|
|
2268
2536
|
getInstance: () => {
|
|
2269
|
-
if (!instance$
|
|
2270
|
-
instance$
|
|
2537
|
+
if (!instance$a) {
|
|
2538
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
2271
2539
|
}
|
|
2272
|
-
return instance$
|
|
2540
|
+
return instance$a;
|
|
2273
2541
|
},
|
|
2274
2542
|
};
|
|
2275
2543
|
|
|
@@ -2453,54 +2721,6 @@ const createHttpTransport = (endpoint) => {
|
|
|
2453
2721
|
return instance;
|
|
2454
2722
|
};
|
|
2455
2723
|
|
|
2456
|
-
class SessionWatcher {
|
|
2457
|
-
constructor() {
|
|
2458
|
-
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
2459
|
-
this._listener = new Map();
|
|
2460
|
-
}
|
|
2461
|
-
onSessionStateChange(callback) {
|
|
2462
|
-
this._listener.set(callback, callback);
|
|
2463
|
-
return () => {
|
|
2464
|
-
this._listener.delete(callback);
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
setSessionState(state, reason) {
|
|
2468
|
-
if (this._sessionState === state)
|
|
2469
|
-
return;
|
|
2470
|
-
this._sessionState = state;
|
|
2471
|
-
this._listener.forEach(cb => cb(state, reason));
|
|
2472
|
-
}
|
|
2473
|
-
destroy() {
|
|
2474
|
-
this._listener.clear();
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
let instance$a;
|
|
2478
|
-
var SessionWatcher$1 = {
|
|
2479
|
-
getInstance: () => {
|
|
2480
|
-
if (!instance$a) {
|
|
2481
|
-
instance$a = new SessionWatcher();
|
|
2482
|
-
}
|
|
2483
|
-
return instance$a;
|
|
2484
|
-
},
|
|
2485
|
-
};
|
|
2486
|
-
|
|
2487
|
-
/**
|
|
2488
|
-
* ```js
|
|
2489
|
-
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
2490
|
-
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
2491
|
-
* // ...
|
|
2492
|
-
* })
|
|
2493
|
-
* ```
|
|
2494
|
-
*
|
|
2495
|
-
* Fired when any {@link Amity.Client} has a session state change
|
|
2496
|
-
*
|
|
2497
|
-
* @param callback The function to call when the event was fired
|
|
2498
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
2499
|
-
*
|
|
2500
|
-
* @category Client Events
|
|
2501
|
-
*/
|
|
2502
|
-
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
2503
|
-
|
|
2504
2724
|
const TOPICS = {
|
|
2505
2725
|
[AmityAutoSubscription.NETWORK]: [getNetworkTopic],
|
|
2506
2726
|
[AmityAutoSubscription.CHAT]: [
|
|
@@ -8584,7 +8804,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8584
8804
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8585
8805
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8586
8806
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8587
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler());
|
|
8807
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler(), userFlagByMeOnLoginHandler());
|
|
8588
8808
|
if (client.useLegacyUnreadCount) {
|
|
8589
8809
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8590
8810
|
}
|
|
@@ -15630,8 +15850,11 @@ const flagUser = async (userId, options) => {
|
|
|
15630
15850
|
if (client.cache) {
|
|
15631
15851
|
ingestInCache(payload);
|
|
15632
15852
|
}
|
|
15853
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
15854
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
15855
|
+
onFlaggedByMe(flagged, userId);
|
|
15633
15856
|
fireEvent('user.flagged', data);
|
|
15634
|
-
return userLinkedObject(
|
|
15857
|
+
return userLinkedObject(flagged);
|
|
15635
15858
|
};
|
|
15636
15859
|
/* end_public_function */
|
|
15637
15860
|
|
|
@@ -15651,8 +15874,11 @@ const submitUserReport = async (apiName, userId, body) => {
|
|
|
15651
15874
|
if (client.cache) {
|
|
15652
15875
|
ingestInCache(payload);
|
|
15653
15876
|
}
|
|
15877
|
+
const flagged = (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
15878
|
+
// The caller's own report may leave hashFlag unchanged; record that they flagged (REQ-016).
|
|
15879
|
+
onFlaggedByMe(flagged, userId);
|
|
15654
15880
|
fireEvent('user.flagged', data);
|
|
15655
|
-
return userLinkedObject(
|
|
15881
|
+
return userLinkedObject(flagged);
|
|
15656
15882
|
};
|
|
15657
15883
|
|
|
15658
15884
|
/** Maximum `comment` length, in string length units, after trimming. */
|
|
@@ -15706,7 +15932,7 @@ const toUserProfileReportBody = (options) => {
|
|
|
15706
15932
|
};
|
|
15707
15933
|
/**
|
|
15708
15934
|
* Validates `flagUserBehavior` options and builds its request body. `reason` must be one
|
|
15709
|
-
* of the
|
|
15935
|
+
* of the `ContentFlagReasonEnum` values and is sent as that canonical label;
|
|
15710
15936
|
* `reportType` is always `behavior`.
|
|
15711
15937
|
*
|
|
15712
15938
|
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
@@ -15787,7 +16013,7 @@ const flagUserProfile = async (userId, options) => submitUserReport('flagUserPro
|
|
|
15787
16013
|
* })
|
|
15788
16014
|
* ```
|
|
15789
16015
|
*
|
|
15790
|
-
* Reports a user's behavior. `reason` is required and is one of the
|
|
16016
|
+
* Reports a user's behavior. `reason` is required and is one of the
|
|
15791
16017
|
* `ContentFlagReasonEnum` values, sent as its canonical label. Reporter text, including
|
|
15792
16018
|
* the explanation for `Others`, always travels in `comment`; the reason never carries text.
|
|
15793
16019
|
*
|
|
@@ -15831,14 +16057,15 @@ const flagUserBehavior = async (userId, options) => submitUserReport('flagUserBe
|
|
|
15831
16057
|
* untouched. Withdrawing a report that does not exist succeeds and changes nothing.
|
|
15832
16058
|
*
|
|
15833
16059
|
* The returned user is persisted to the cache, so its `hashFlag` says whether the caller
|
|
15834
|
-
* still
|
|
15835
|
-
* after a per-type withdrawal;
|
|
15836
|
-
* remaining per-type state (`flags`).
|
|
16060
|
+
* may still hold a report on the user. Do not flip a local "flagged by me" flag to `false`
|
|
16061
|
+
* after a per-type withdrawal; observe the user and read `isFlaggedByMe`, or call
|
|
16062
|
+
* `user.getUserFlagsByMe()` for the remaining per-type state (`flags`). The SDK drops the
|
|
16063
|
+
* answer it confirmed for this user, so the next "maybe" is confirmed again.
|
|
15837
16064
|
*
|
|
15838
16065
|
* Sends `DELETE /api/v4/me/flags/:userId`, with `?reportType=<type>` when one is given.
|
|
15839
16066
|
*
|
|
15840
16067
|
* @param userId The ID of the user to unflag
|
|
15841
|
-
* @param options Optional; `reportType` selects a single report to withdraw. For a report that `
|
|
16068
|
+
* @param options Optional; `reportType` selects a single report to withdraw. For a report that `user.getUserFlagsByMe()` lists with `reportType: null`, pass `UserReportTypeFilterEnum.UNTYPED`
|
|
15842
16069
|
* @returns `true` once the server has processed the withdrawal
|
|
15843
16070
|
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `reportType` is not a `UserReportTypeFilterEnum` value, before any request is made
|
|
15844
16071
|
*
|
|
@@ -15857,6 +16084,8 @@ const unflagUser = async (userId, options) => {
|
|
|
15857
16084
|
if (client.cache) {
|
|
15858
16085
|
ingestInCache(payload);
|
|
15859
16086
|
}
|
|
16087
|
+
// Drop the confirmed answer; never set it to false: other reports may remain (REQ-010).
|
|
16088
|
+
onUnflaggedByMe(userId);
|
|
15860
16089
|
fireEvent('user.unflagged', data);
|
|
15861
16090
|
return !!payload;
|
|
15862
16091
|
};
|
|
@@ -15868,33 +16097,19 @@ const unflagUser = async (userId, options) => {
|
|
|
15868
16097
|
/**
|
|
15869
16098
|
* ```js
|
|
15870
16099
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
15871
|
-
*
|
|
15872
|
-
* const { isFlagByMe, flags } = await UserRepository.isUserFlaggedByMe('userId')
|
|
15873
|
-
*
|
|
15874
|
-
* // Grey out the report options already used; null marks the typeless report.
|
|
15875
|
-
* const used = new Set(flags.map(flag => flag.reportType))
|
|
16100
|
+
* const isFlagged = await UserRepository.isUserFlaggedByMe(userId)
|
|
15876
16101
|
* ```
|
|
15877
16102
|
*
|
|
15878
|
-
*
|
|
15879
|
-
*
|
|
15880
|
-
* carries `reportType`, `reason`, `comment` and `createdAt`; a field the report does not
|
|
15881
|
-
* have is `null`. `reportType: null` is the typeless (legacy) report, which `unflagUser`
|
|
15882
|
-
* withdraws with `UserReportTypeFilterEnum.UNTYPED`. Only the caller's reports come back.
|
|
16103
|
+
* Whether the current user has reported a user. Sends one request per call and caches
|
|
16104
|
+
* nothing.
|
|
15883
16105
|
*
|
|
15884
|
-
*
|
|
15885
|
-
*
|
|
15886
|
-
*
|
|
15887
|
-
*
|
|
15888
|
-
*
|
|
15889
|
-
* Breaking change: earlier versions returned a boolean from the v3 endpoint, which the
|
|
15890
|
-
* backend has deprecated. Read `isFlagByMe` on the result for the same answer.
|
|
15891
|
-
*
|
|
15892
|
-
* @deprecated On an {@link Amity.User} you already hold, read `user.isFlaggedByMe` for a
|
|
15893
|
-
* request-free badge and call `user.getUserFlagsByMe()` for the reports; it skips the request
|
|
15894
|
-
* when the Bloom test says the user is not flagged. This function remains the underlying request.
|
|
16106
|
+
* @deprecated Read `user.isFlaggedByMe` on an {@link Amity.User} for a yes/no hint that
|
|
16107
|
+
* usually needs no request, and call `user.getUserFlagsByMe()` for the exact answer with the
|
|
16108
|
+
* caller's reports by type. Observe the user with `UserRepository.getUser(userId, callback)`
|
|
16109
|
+
* to follow a flag or unflag.
|
|
15895
16110
|
*
|
|
15896
16111
|
* @param userId The ID of the user to check
|
|
15897
|
-
* @returns the
|
|
16112
|
+
* @returns `true` if the current user has reported the user, `false` if not
|
|
15898
16113
|
*
|
|
15899
16114
|
* @category Report API
|
|
15900
16115
|
* @async
|
|
@@ -15902,7 +16117,8 @@ const unflagUser = async (userId, options) => {
|
|
|
15902
16117
|
const isUserFlaggedByMe = async (userId) => {
|
|
15903
16118
|
const client = getActiveClient();
|
|
15904
16119
|
client.log('user/isUserFlaggedByMe', userId);
|
|
15905
|
-
|
|
16120
|
+
const { isFlagByMe } = await getFlagsByMe(userId);
|
|
16121
|
+
return isFlagByMe;
|
|
15906
16122
|
};
|
|
15907
16123
|
/* end_public_function */
|
|
15908
16124
|
|
|
@@ -16141,7 +16357,7 @@ const getUser = (userId, callback) => {
|
|
|
16141
16357
|
const reactor = (response) => {
|
|
16142
16358
|
return callback(Object.assign(Object.assign({}, response), { data: response.data ? LinkedObject.user(response.data) : response.data }));
|
|
16143
16359
|
};
|
|
16144
|
-
|
|
16360
|
+
const unsubscribeUser = liveObject(userId, reactor, 'userId', getUser$1, [
|
|
16145
16361
|
onUserFetched,
|
|
16146
16362
|
onUserUpdated,
|
|
16147
16363
|
onUserDeleted$2,
|
|
@@ -16149,6 +16365,17 @@ const getUser = (userId, callback) => {
|
|
|
16149
16365
|
onUserUnflagged,
|
|
16150
16366
|
onUserFlagCleared,
|
|
16151
16367
|
]);
|
|
16368
|
+
// A confirmed flag answer leaves the cached user row unchanged, so the live object's own
|
|
16369
|
+
// dedupe would drop it. Deliver the re-linked user directly (user.check_flag_by_me REQ-016).
|
|
16370
|
+
const unsubscribeFlag = onUserFlagConfirmed(user => {
|
|
16371
|
+
if (user.userId !== userId)
|
|
16372
|
+
return;
|
|
16373
|
+
callback({ data: LinkedObject.user(user), loading: false, origin: 'event' });
|
|
16374
|
+
});
|
|
16375
|
+
return () => {
|
|
16376
|
+
unsubscribeUser();
|
|
16377
|
+
unsubscribeFlag();
|
|
16378
|
+
};
|
|
16152
16379
|
};
|
|
16153
16380
|
/* end_public_function */
|
|
16154
16381
|
|
|
@@ -16246,13 +16473,24 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
16246
16473
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16247
16474
|
}
|
|
16248
16475
|
startSubscription() {
|
|
16249
|
-
return
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
16254
|
-
|
|
16255
|
-
|
|
16476
|
+
return [
|
|
16477
|
+
...this.queryStreamController.subscribeRTE([
|
|
16478
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
16479
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
16480
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
16481
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
16482
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
16483
|
+
]),
|
|
16484
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
16485
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
16486
|
+
onUserFlagConfirmed(user => {
|
|
16487
|
+
var _a;
|
|
16488
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16489
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
16490
|
+
return;
|
|
16491
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16492
|
+
}),
|
|
16493
|
+
];
|
|
16256
16494
|
}
|
|
16257
16495
|
notifyChange({ origin, loading, error }) {
|
|
16258
16496
|
var _a, _b;
|
|
@@ -16804,13 +17042,24 @@ class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
|
16804
17042
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
16805
17043
|
}
|
|
16806
17044
|
startSubscription() {
|
|
16807
|
-
return
|
|
16808
|
-
|
|
16809
|
-
|
|
16810
|
-
|
|
16811
|
-
|
|
16812
|
-
|
|
16813
|
-
|
|
17045
|
+
return [
|
|
17046
|
+
...this.queryStreamController.subscribeRTE([
|
|
17047
|
+
{ fn: onUserDeleted$2, action: EnumUserActions.OnUserDeleted },
|
|
17048
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
17049
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
17050
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
17051
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
17052
|
+
]),
|
|
17053
|
+
// A confirmed flag answer changes isFlaggedByMe on a listed user without changing its
|
|
17054
|
+
// cache row (user.check_flag_by_me REQ-016). Re-link only collections that hold it.
|
|
17055
|
+
onUserFlagConfirmed(user => {
|
|
17056
|
+
var _a;
|
|
17057
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17058
|
+
if (!(collection === null || collection === void 0 ? void 0 : collection.data.includes(user.userId)))
|
|
17059
|
+
return;
|
|
17060
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17061
|
+
}),
|
|
17062
|
+
];
|
|
16814
17063
|
}
|
|
16815
17064
|
notifyChange({ origin, loading, error }) {
|
|
16816
17065
|
var _a, _b;
|
|
@@ -20760,7 +21009,7 @@ const isLegacyContentFlagReason = (input) => input === undefined || typeof input
|
|
|
20760
21009
|
/**
|
|
20761
21010
|
* Validates an `Amity.ContentFlagOptions` argument. Untyped (plain JS) callers can pass
|
|
20762
21011
|
* anything at runtime, so the checks do not trust the declared type: the value must be a
|
|
20763
|
-
* plain object, `reason` must be one of the
|
|
21012
|
+
* plain object, `reason` must be one of the `ContentFlagReasonEnum` values and
|
|
20764
21013
|
* `detail`, when supplied, must be a string (`null` is not a valid supplied detail).
|
|
20765
21014
|
*
|
|
20766
21015
|
* @param apiName used in the error message, e.g. `flagPost`
|
|
@@ -37939,4 +38188,62 @@ class AmityAttachmentProductTags {
|
|
|
37939
38188
|
}
|
|
37940
38189
|
}
|
|
37941
38190
|
|
|
37942
|
-
|
|
38191
|
+
/**
|
|
38192
|
+
* Stable, cross-platform key per report category. Android and iOS expose the same
|
|
38193
|
+
* keys on `AmityContentFlagReasonType.key`. A UIKit builds its string key from it
|
|
38194
|
+
* (`amity_social_label_report_reason_<key>`), so a released key is never renamed.
|
|
38195
|
+
* The key is not derived from the enum member name on purpose: the existing UIKit
|
|
38196
|
+
* string keys do not follow it (`selling_restricted`, `violence_or_threatening`).
|
|
38197
|
+
*/
|
|
38198
|
+
const CONTENT_FLAG_REASON_KEYS = Object.freeze({
|
|
38199
|
+
[ContentFlagReasonEnum.CommunityGuidelines]: 'community_guidelines',
|
|
38200
|
+
[ContentFlagReasonEnum.ChildEndangerment]: 'child_endangerment',
|
|
38201
|
+
[ContentFlagReasonEnum.HarassmentOrBullying]: 'harassment_or_bullying',
|
|
38202
|
+
[ContentFlagReasonEnum.SelfHarmOrSuicide]: 'self_harm_or_suicide',
|
|
38203
|
+
[ContentFlagReasonEnum.ViolenceOrThreateningContent]: 'violence_or_threatening',
|
|
38204
|
+
[ContentFlagReasonEnum.SellingRestrictedItems]: 'selling_restricted',
|
|
38205
|
+
[ContentFlagReasonEnum.SexualContentOrNudity]: 'sexual_content_or_nudity',
|
|
38206
|
+
[ContentFlagReasonEnum.SpamOrScams]: 'spam_or_scams',
|
|
38207
|
+
[ContentFlagReasonEnum.FalseInformation]: 'false_information',
|
|
38208
|
+
[ContentFlagReasonEnum.Others]: 'others',
|
|
38209
|
+
});
|
|
38210
|
+
/* begin_public_function
|
|
38211
|
+
id: content_flag_reason.get_reasons
|
|
38212
|
+
*/
|
|
38213
|
+
/**
|
|
38214
|
+
* ```js
|
|
38215
|
+
* import { getContentFlagReasons, AmityContentFlagReasonType } from '@amityco/ts-sdk'
|
|
38216
|
+
* const reasons = getContentFlagReasons().filter(r => r !== AmityContentFlagReasonType.Others)
|
|
38217
|
+
* ```
|
|
38218
|
+
*
|
|
38219
|
+
* Returns every report category in display order, with `Others` last. Render a report
|
|
38220
|
+
* picker from this list rather than a copy, so a category added in a later SDK release
|
|
38221
|
+
* appears without a UI change. Each value is also its English default label.
|
|
38222
|
+
*
|
|
38223
|
+
* @returns a new array on every call; mutating it does not affect the SDK
|
|
38224
|
+
*
|
|
38225
|
+
* @category Content Flag
|
|
38226
|
+
*/
|
|
38227
|
+
const getContentFlagReasons = () => Object.values(ContentFlagReasonEnum);
|
|
38228
|
+
/* end_public_function */
|
|
38229
|
+
/* begin_public_function
|
|
38230
|
+
id: content_flag_reason.get_key
|
|
38231
|
+
*/
|
|
38232
|
+
/**
|
|
38233
|
+
* ```js
|
|
38234
|
+
* import { getContentFlagReasonKey, AmityContentFlagReasonType } from '@amityco/ts-sdk'
|
|
38235
|
+
* getContentFlagReasonKey(AmityContentFlagReasonType.ChildEndangerment) // 'child_endangerment'
|
|
38236
|
+
* ```
|
|
38237
|
+
*
|
|
38238
|
+
* Returns the stable, cross-platform key of a report category, for building a
|
|
38239
|
+
* localisation key. Never send the key to the server: flag with the enum value.
|
|
38240
|
+
*
|
|
38241
|
+
* @param reason an `AmityContentFlagReasonType` (`ContentFlagReasonEnum`) value
|
|
38242
|
+
* @returns the category's snake_case key
|
|
38243
|
+
*
|
|
38244
|
+
* @category Content Flag
|
|
38245
|
+
*/
|
|
38246
|
+
const getContentFlagReasonKey = (reason) => CONTENT_FLAG_REASON_KEYS[reason];
|
|
38247
|
+
/* end_public_function */
|
|
38248
|
+
|
|
38249
|
+
export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, ContentFlagReasonEnum as AmityContentFlagReasonType, 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, getContentFlagReasonKey, getContentFlagReasons, 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 };
|