@amityco/ts-sdk 7.5.3-d6ee46d.0 → 7.5.4-2d34fd5f.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/domains/content.d.ts +11 -2
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +2 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +3 -1
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/pinnedPost.d.ts +1 -1
- package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +21 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/communityRepository/api/deleteCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +2 -2
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +1 -0
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadClip.d.ts +17 -0
- package/dist/fileRepository/api/uploadClip.d.ts.map +1 -0
- package/dist/index.cjs.js +433 -432
- package/dist/index.esm.js +400 -399
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/postRepository/api/createClipPost.d.ts +32 -0
- package/dist/postRepository/api/createClipPost.d.ts.map +1 -0
- package/dist/postRepository/api/getPost.d.ts +2 -2
- package/dist/postRepository/api/getPost.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +1 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers.d.ts +4 -4
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +1 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/domains/content.ts +25 -1
- package/src/@types/domains/feed.ts +2 -1
- package/src/@types/domains/file.ts +5 -0
- package/src/@types/domains/pinnedPost.ts +1 -1
- package/src/@types/domains/post.ts +29 -8
- package/src/@types/index.ts +2 -0
- package/src/client/api/enableUnreadCount.ts +0 -22
- package/src/client/api/login.ts +0 -4
- package/src/client/utils/markerSyncEngine.ts +3 -24
- package/src/commentRepository/api/createComment.ts +1 -1
- package/src/commentRepository/api/deleteComment.ts +1 -1
- package/src/communityRepository/api/deleteCommunity.ts +2 -1
- package/src/communityRepository/api/getCommunity.ts +5 -7
- package/src/communityRepository/observers/getCommunity.ts +24 -12
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +1 -2
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +1 -1
- package/src/feedRepository/api/queryGlobalFeed.ts +3 -1
- package/src/fileRepository/api/index.ts +1 -0
- package/src/fileRepository/api/uploadClip.ts +71 -0
- package/src/postRepository/api/createClipPost.ts +62 -0
- package/src/postRepository/api/getPost.ts +6 -4
- package/src/postRepository/api/index.ts +2 -0
- package/src/postRepository/api/queryPosts.ts +1 -1
- package/src/postRepository/observers/getPost.ts +2 -2
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +1 -1
- package/src/reactionRepository/api/addReaction.ts +1 -1
- package/src/userRepository/observers/getBlockedUsers.ts +4 -4
- package/src/utils/linkedObject/postLinkedObject.ts +12 -1
- package/src/utils/linkedObject/streamLinkedObject.ts +1 -1
- package/src/utils/postTypePredicate.ts +10 -0
package/dist/index.cjs.js
CHANGED
|
@@ -33,6 +33,7 @@ const FileType = Object.freeze({
|
|
|
33
33
|
FILE: 'file',
|
|
34
34
|
IMAGE: 'image',
|
|
35
35
|
VIDEO: 'video',
|
|
36
|
+
CLIP: 'clip',
|
|
36
37
|
});
|
|
37
38
|
const VideoResolution = Object.freeze({
|
|
38
39
|
'1080P': '1080p',
|
|
@@ -116,6 +117,7 @@ const PostContentType = Object.freeze({
|
|
|
116
117
|
VIDEO: 'video',
|
|
117
118
|
LIVESTREAM: 'liveStream',
|
|
118
119
|
POLL: 'poll',
|
|
120
|
+
CLIP: 'clip',
|
|
119
121
|
});
|
|
120
122
|
|
|
121
123
|
exports.InvitationTypeEnum = void 0;
|
|
@@ -151,8 +153,8 @@ exports.JoinResultStatusEnum = void 0;
|
|
|
151
153
|
|
|
152
154
|
function getVersion() {
|
|
153
155
|
try {
|
|
154
|
-
// the string ''v7.5.
|
|
155
|
-
return 'v7.5.
|
|
156
|
+
// the string ''v7.5.3-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
157
|
+
return 'v7.5.3-cjs';
|
|
156
158
|
}
|
|
157
159
|
catch (error) {
|
|
158
160
|
return '__dev__';
|
|
@@ -6691,6 +6693,13 @@ function isAmityVideoPost(post) {
|
|
|
6691
6693
|
'videoFileId' in post.data &&
|
|
6692
6694
|
'thumbnailFileId' in post.data &&
|
|
6693
6695
|
post.dataType === 'video');
|
|
6696
|
+
}
|
|
6697
|
+
function isAmityClipPost(post) {
|
|
6698
|
+
return !!(post.data &&
|
|
6699
|
+
typeof post.data !== 'string' &&
|
|
6700
|
+
'fileId' in post.data &&
|
|
6701
|
+
'thumbnailFileId' in post.data &&
|
|
6702
|
+
post.dataType === 'clip');
|
|
6694
6703
|
}
|
|
6695
6704
|
|
|
6696
6705
|
const postLinkedObject = (post) => {
|
|
@@ -6745,6 +6754,12 @@ const postLinkedObject = (post) => {
|
|
|
6745
6754
|
return isAmityFilePost(post)
|
|
6746
6755
|
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
6747
6756
|
: undefined;
|
|
6757
|
+
},
|
|
6758
|
+
getClipInfo() {
|
|
6759
|
+
var _a, _b;
|
|
6760
|
+
return isAmityClipPost(post)
|
|
6761
|
+
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
6762
|
+
: undefined;
|
|
6748
6763
|
} });
|
|
6749
6764
|
};
|
|
6750
6765
|
|
|
@@ -7725,7 +7740,7 @@ class PaginationController {
|
|
|
7725
7740
|
*/
|
|
7726
7741
|
class JoinRequestsPaginationController extends PaginationController {
|
|
7727
7742
|
async getRequest(queryParams, token) {
|
|
7728
|
-
const { limit =
|
|
7743
|
+
const { limit = 20, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
7729
7744
|
const options = token ? { token } : { limit };
|
|
7730
7745
|
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
7731
7746
|
params: Object.assign(Object.assign({}, params), { options }),
|
|
@@ -9895,6 +9910,266 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
9895
9910
|
dropFromCache(['channelMarker', 'get', id], true);
|
|
9896
9911
|
};
|
|
9897
9912
|
|
|
9913
|
+
/* eslint-disable no-param-reassign */
|
|
9914
|
+
/*
|
|
9915
|
+
* declared earlier to accomodate case when logging in with a different user
|
|
9916
|
+
* than the one already connected, in which case the existing subscriptions need
|
|
9917
|
+
* to be cleared
|
|
9918
|
+
*/
|
|
9919
|
+
let subscriptions = [];
|
|
9920
|
+
async function runMqtt() {
|
|
9921
|
+
await modifyMqttConnection();
|
|
9922
|
+
}
|
|
9923
|
+
/* begin_public_function
|
|
9924
|
+
id: client.login
|
|
9925
|
+
*/
|
|
9926
|
+
/**
|
|
9927
|
+
* ```js
|
|
9928
|
+
* import { login } from '@amityco/ts-sdk/client/api'
|
|
9929
|
+
* const success = await login({
|
|
9930
|
+
* userId: 'XYZ123456789',
|
|
9931
|
+
* })
|
|
9932
|
+
* ```
|
|
9933
|
+
*
|
|
9934
|
+
* Connects an {@link Amity.Client} instance to ASC servers
|
|
9935
|
+
*
|
|
9936
|
+
* @param params the connect parameters
|
|
9937
|
+
* @param params.userId the user ID for the current session
|
|
9938
|
+
* @param params.displayName the user's displayName for the current session
|
|
9939
|
+
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
9940
|
+
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
9941
|
+
* @returns a success boolean if connected
|
|
9942
|
+
*
|
|
9943
|
+
* @category Client API
|
|
9944
|
+
* @async
|
|
9945
|
+
*/
|
|
9946
|
+
const login = async (params, sessionHandler, config) => {
|
|
9947
|
+
var _a;
|
|
9948
|
+
const client = getActiveClient();
|
|
9949
|
+
let unsubWatcher;
|
|
9950
|
+
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
9951
|
+
// if connecting to a different userId than the one that is connected currently
|
|
9952
|
+
if (client.userId && client.userId !== params.userId) {
|
|
9953
|
+
await logout();
|
|
9954
|
+
// Remove subscription to ban and delete
|
|
9955
|
+
subscriptions.forEach(fn => fn());
|
|
9956
|
+
subscriptions = [];
|
|
9957
|
+
}
|
|
9958
|
+
// default values
|
|
9959
|
+
const defaultDeviceId = await getDeviceId();
|
|
9960
|
+
try {
|
|
9961
|
+
const { users } = await setClientToken({
|
|
9962
|
+
params: Object.assign(Object.assign({}, params), { displayName: params === null || params === void 0 ? void 0 : params.displayName, deviceId: (params === null || params === void 0 ? void 0 : params.deviceId) || defaultDeviceId }),
|
|
9963
|
+
options: {
|
|
9964
|
+
setAccessTokenCookie: true,
|
|
9965
|
+
},
|
|
9966
|
+
});
|
|
9967
|
+
const user = users.find(u => u.userId === params.userId);
|
|
9968
|
+
if (user == null) {
|
|
9969
|
+
throw new ASCError(`${params.userId} has not been founded`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
9970
|
+
}
|
|
9971
|
+
if (user.isDeleted) {
|
|
9972
|
+
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
9973
|
+
return false;
|
|
9974
|
+
}
|
|
9975
|
+
if (user.isGlobalBanned) {
|
|
9976
|
+
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
9977
|
+
return false;
|
|
9978
|
+
}
|
|
9979
|
+
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
9980
|
+
// wire websocket events to our event emitter
|
|
9981
|
+
proxyWebsocketEvents(client.ws, client.emitter);
|
|
9982
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
9983
|
+
client.userId = user.userId;
|
|
9984
|
+
client.sessionHandler = sessionHandler;
|
|
9985
|
+
/*
|
|
9986
|
+
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
9987
|
+
* token expires
|
|
9988
|
+
*/
|
|
9989
|
+
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
9990
|
+
setActiveUser(user);
|
|
9991
|
+
}
|
|
9992
|
+
catch (error) {
|
|
9993
|
+
/*
|
|
9994
|
+
* if getting token failed session state reverts to initial state when app
|
|
9995
|
+
* is first launched
|
|
9996
|
+
*/
|
|
9997
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
9998
|
+
// pass error down tree so the calling function handle it
|
|
9999
|
+
throw error;
|
|
10000
|
+
}
|
|
10001
|
+
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
10002
|
+
runMqtt();
|
|
10003
|
+
}
|
|
10004
|
+
await initializeMessagePreviewSetting();
|
|
10005
|
+
if (subscriptions.length === 0) {
|
|
10006
|
+
subscriptions.push(
|
|
10007
|
+
// GLOBAL_BAN
|
|
10008
|
+
onClientBanned((_) => {
|
|
10009
|
+
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
10010
|
+
subscriptions.forEach(fn => fn());
|
|
10011
|
+
unsubWatcher();
|
|
10012
|
+
}), onTokenTerminated(_ => {
|
|
10013
|
+
terminateClient();
|
|
10014
|
+
subscriptions.forEach(fn => fn());
|
|
10015
|
+
unsubWatcher();
|
|
10016
|
+
}), onUserDeleted$2((user) => {
|
|
10017
|
+
if (user.userId === client.userId) {
|
|
10018
|
+
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
10019
|
+
subscriptions.forEach(fn => fn());
|
|
10020
|
+
unsubWatcher();
|
|
10021
|
+
}
|
|
10022
|
+
}), onTokenExpired(state => {
|
|
10023
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
10024
|
+
logout();
|
|
10025
|
+
subscriptions.forEach(fn => fn());
|
|
10026
|
+
}),
|
|
10027
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
10028
|
+
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
10029
|
+
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
10030
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
10031
|
+
if (client.useLegacyUnreadCount) {
|
|
10032
|
+
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
10033
|
+
}
|
|
10034
|
+
else
|
|
10035
|
+
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
10036
|
+
}
|
|
10037
|
+
return true;
|
|
10038
|
+
};
|
|
10039
|
+
/* end_public_function */
|
|
10040
|
+
|
|
10041
|
+
/* begin_public_function
|
|
10042
|
+
id: client.renew_access_token
|
|
10043
|
+
*/
|
|
10044
|
+
/*
|
|
10045
|
+
* Renewal defintion accepted by SessionHandler interface
|
|
10046
|
+
*
|
|
10047
|
+
* Tech Spec:
|
|
10048
|
+
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Session-Handler
|
|
10049
|
+
*
|
|
10050
|
+
* @category private
|
|
10051
|
+
*/
|
|
10052
|
+
const renewal = () => {
|
|
10053
|
+
let tokenRenewed = false;
|
|
10054
|
+
let renewTimeoutId;
|
|
10055
|
+
const client = getActiveClient();
|
|
10056
|
+
client.log('initiating access token renewal');
|
|
10057
|
+
/*
|
|
10058
|
+
* Renews a token if it is hasn't been renewed before. Also marks token as
|
|
10059
|
+
* renewed once done
|
|
10060
|
+
* Per instance of Renewal, only one renewal is allowed
|
|
10061
|
+
*/
|
|
10062
|
+
const renewToken = async (authToken) => {
|
|
10063
|
+
const { userId, displayName } = getActiveUser();
|
|
10064
|
+
const deviceId = await getDeviceId();
|
|
10065
|
+
const params = { userId, displayName, authToken, deviceId };
|
|
10066
|
+
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
10067
|
+
await login(params, client.sessionHandler);
|
|
10068
|
+
}
|
|
10069
|
+
else {
|
|
10070
|
+
// about to expire
|
|
10071
|
+
await setClientToken({
|
|
10072
|
+
params,
|
|
10073
|
+
options: {
|
|
10074
|
+
setAccessTokenCookie: true,
|
|
10075
|
+
},
|
|
10076
|
+
});
|
|
10077
|
+
}
|
|
10078
|
+
tokenRenewed = true;
|
|
10079
|
+
if (renewTimeoutId)
|
|
10080
|
+
clearTimeout(renewTimeoutId);
|
|
10081
|
+
};
|
|
10082
|
+
return {
|
|
10083
|
+
renew: () => {
|
|
10084
|
+
if (tokenRenewed) {
|
|
10085
|
+
console.log("'renew' method can be called only once per renewal instance");
|
|
10086
|
+
return;
|
|
10087
|
+
}
|
|
10088
|
+
renewToken();
|
|
10089
|
+
},
|
|
10090
|
+
renewWithAuthToken: (authToken) => {
|
|
10091
|
+
if (tokenRenewed) {
|
|
10092
|
+
console.log("'renewWithAuthToken' method can be called only once per renewal instance");
|
|
10093
|
+
return;
|
|
10094
|
+
}
|
|
10095
|
+
renewToken(authToken);
|
|
10096
|
+
},
|
|
10097
|
+
unableToRetrieveAuthToken: () => {
|
|
10098
|
+
renewTimeoutId = setTimeout(() => {
|
|
10099
|
+
var _a;
|
|
10100
|
+
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
10101
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
10102
|
+
},
|
|
10103
|
+
};
|
|
10104
|
+
};
|
|
10105
|
+
/* end_public_function */
|
|
10106
|
+
|
|
10107
|
+
const ABOUT_TO_EXPIRE_THRESHOLD = 80 / 100;
|
|
10108
|
+
const COMPENSATED_DELAY = 5 * MINUTE;
|
|
10109
|
+
/*
|
|
10110
|
+
* a helper function to check if the token has expires
|
|
10111
|
+
*
|
|
10112
|
+
* @param token to be checked
|
|
10113
|
+
* @returns boolean indicating if token expires
|
|
10114
|
+
*
|
|
10115
|
+
* @category private
|
|
10116
|
+
*/
|
|
10117
|
+
const isExpired = (expiresAt) => Date.now() > Date.parse(expiresAt) - COMPENSATED_DELAY;
|
|
10118
|
+
/*
|
|
10119
|
+
* a helper function to check if the token is about to expire
|
|
10120
|
+
*
|
|
10121
|
+
* @param token to be checked
|
|
10122
|
+
* @returns boolean indicating if token is aboutToExpire
|
|
10123
|
+
*
|
|
10124
|
+
* @category private
|
|
10125
|
+
*/
|
|
10126
|
+
const isAboutToExpire = (params) => {
|
|
10127
|
+
const { expiresAt, issuedAt } = params;
|
|
10128
|
+
const expires = Date.parse(expiresAt);
|
|
10129
|
+
const issued = Date.parse(issuedAt);
|
|
10130
|
+
const now = Date.now();
|
|
10131
|
+
const duration = expires - issued - COMPENSATED_DELAY;
|
|
10132
|
+
const aboutToExpireAt = issued + duration * ABOUT_TO_EXPIRE_THRESHOLD;
|
|
10133
|
+
return now > aboutToExpireAt && now < expires;
|
|
10134
|
+
};
|
|
10135
|
+
/*
|
|
10136
|
+
* Monitors time to expire of token and updates session state to aboutToExpire
|
|
10137
|
+
*
|
|
10138
|
+
* @returns intervalId to be cleared after trigger
|
|
10139
|
+
*
|
|
10140
|
+
* @category private
|
|
10141
|
+
*/
|
|
10142
|
+
const accessTokenExpiryWatcher = (sessionHandler) => {
|
|
10143
|
+
const interval = setInterval(() => {
|
|
10144
|
+
const client = getActiveClient();
|
|
10145
|
+
if (!client.token)
|
|
10146
|
+
return;
|
|
10147
|
+
const { issuedAt, expiresAt } = client.token;
|
|
10148
|
+
if (isExpired(expiresAt)) {
|
|
10149
|
+
/*
|
|
10150
|
+
* the event handler will take care of updating session state
|
|
10151
|
+
* Note, this will also clear the interval id, so this event will only be
|
|
10152
|
+
* fired once
|
|
10153
|
+
*/
|
|
10154
|
+
fireEvent('tokenExpired', "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */);
|
|
10155
|
+
/*
|
|
10156
|
+
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Automatically-initiate-renewal-flow
|
|
10157
|
+
*
|
|
10158
|
+
* Why sechduled task?
|
|
10159
|
+
* Since fireEvent is scheduled, it will be called
|
|
10160
|
+
* after sessionHandler leading to an invalid state change from
|
|
10161
|
+
* establishing to tokenExpired
|
|
10162
|
+
*/
|
|
10163
|
+
scheduleTask(() => sessionHandler.sessionWillRenewAccessToken(renewal()));
|
|
10164
|
+
return;
|
|
10165
|
+
}
|
|
10166
|
+
if (isAboutToExpire({ expiresAt, issuedAt })) {
|
|
10167
|
+
sessionHandler.sessionWillRenewAccessToken(renewal());
|
|
10168
|
+
}
|
|
10169
|
+
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
10170
|
+
return () => clearInterval(interval);
|
|
10171
|
+
};
|
|
10172
|
+
|
|
9898
10173
|
const callbacks$9 = [];
|
|
9899
10174
|
let mainDisposer$8 = null;
|
|
9900
10175
|
const dispose$9 = (cb) => {
|
|
@@ -10167,33 +10442,6 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
10167
10442
|
return () => dispose(callback);
|
|
10168
10443
|
};
|
|
10169
10444
|
|
|
10170
|
-
/**
|
|
10171
|
-
* ```js
|
|
10172
|
-
* import { onUserMarkerSync } from '@amityco/ts-sdk'
|
|
10173
|
-
* const dispose = onUserMarkerSync(UserMarker => {
|
|
10174
|
-
* // ...
|
|
10175
|
-
* })
|
|
10176
|
-
* ```
|
|
10177
|
-
*
|
|
10178
|
-
* Fired when an {@link Amity.UserMarker} has been sync
|
|
10179
|
-
*
|
|
10180
|
-
* @param callback The function to call when the event was fired
|
|
10181
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10182
|
-
*
|
|
10183
|
-
* @category UserMarker Events
|
|
10184
|
-
*/
|
|
10185
|
-
const onUserMarkerSync = (callback) => {
|
|
10186
|
-
const client = getActiveClient();
|
|
10187
|
-
const filter = (payload) => {
|
|
10188
|
-
const { userMarkers, userEntityMarkers: userEntityMarkersPayload, userFeedMarkers: userFeedMarkersPayload } = payload, rest = __rest(payload, ["userMarkers", "userEntityMarkers", "userFeedMarkers"]);
|
|
10189
|
-
const userEntityMarkers = convertChannelMarkerResponse(userEntityMarkersPayload);
|
|
10190
|
-
const userFeedMarker = convertSubChannelMarkerResponse(userFeedMarkersPayload);
|
|
10191
|
-
ingestInCache(Object.assign({ userMarkers, userEntityMarkers, userFeedMarker }, rest));
|
|
10192
|
-
callback(userMarkers[0]);
|
|
10193
|
-
};
|
|
10194
|
-
return createEventSubscriber(client, 'UserMarker/onUserMarkerSync', 'marker.user-sync', filter);
|
|
10195
|
-
};
|
|
10196
|
-
|
|
10197
10445
|
/**
|
|
10198
10446
|
* ```js
|
|
10199
10447
|
* import { onFeedMarkerUpdated } from '@amityco/ts-sdk'
|
|
@@ -10465,52 +10713,11 @@ const markerSync = async (deviceLastSyncAt) => {
|
|
|
10465
10713
|
};
|
|
10466
10714
|
};
|
|
10467
10715
|
|
|
10468
|
-
const enableUnreadCount = () => {
|
|
10469
|
-
const client = getActiveClient();
|
|
10470
|
-
client.log('client/api/isUnreadCountEnabled', client.isUnreadCountEnabled);
|
|
10471
|
-
if (!client) {
|
|
10472
|
-
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
10473
|
-
}
|
|
10474
|
-
if (client.isUnreadCountEnabled)
|
|
10475
|
-
return false;
|
|
10476
|
-
client.isUnreadCountEnabled = true;
|
|
10477
|
-
client.useLegacyUnreadCount = false;
|
|
10478
|
-
client.emitter.emit('unreadCountEnabled', true);
|
|
10479
|
-
return true;
|
|
10480
|
-
};
|
|
10481
|
-
|
|
10482
|
-
/**
|
|
10483
|
-
* ```js
|
|
10484
|
-
* import { onFeedMarkerUpdated } from '@amityco/ts-sdk'
|
|
10485
|
-
* const dispose = onFeedMarkerUpdated(feedMarker => {
|
|
10486
|
-
* // ...
|
|
10487
|
-
* })
|
|
10488
|
-
* ```
|
|
10489
|
-
*
|
|
10490
|
-
* Fired when an {@link Amity.UserFeedMarker} has been updated
|
|
10491
|
-
*
|
|
10492
|
-
* @param callback The function to call when the event was fired
|
|
10493
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
10494
|
-
*
|
|
10495
|
-
* @category FeedMarker Events
|
|
10496
|
-
*/
|
|
10497
|
-
const onUserFeedMarkerUpdated = (callback) => {
|
|
10498
|
-
const client = getActiveClient();
|
|
10499
|
-
const filter = (payload) => {
|
|
10500
|
-
persistUnreadCountInfo(payload);
|
|
10501
|
-
payload.feedMarkers.forEach(feedMarker => {
|
|
10502
|
-
callback(feedMarker);
|
|
10503
|
-
});
|
|
10504
|
-
};
|
|
10505
|
-
return createEventSubscriber(client, 'feedMarker/onUserFeedMarkerUpdated', 'marker.userFeed-updated', filter);
|
|
10506
|
-
};
|
|
10507
|
-
|
|
10508
10716
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
10509
|
-
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
10510
10717
|
let isSyncRunning = false;
|
|
10511
10718
|
let disposers$1 = [];
|
|
10512
10719
|
let isWaitingForResponse = false;
|
|
10513
|
-
|
|
10720
|
+
const isConsistentMode = true;
|
|
10514
10721
|
let deviceLastSyncAt = null;
|
|
10515
10722
|
const getDeviceLastSyncAt = () => {
|
|
10516
10723
|
if (deviceLastSyncAt == null) {
|
|
@@ -10525,12 +10732,6 @@ const saveDeviceLastSyncAt = (lastSyncAt) => {
|
|
|
10525
10732
|
deviceLastSyncAt = lastSyncAt;
|
|
10526
10733
|
}
|
|
10527
10734
|
};
|
|
10528
|
-
const fetchDeviceLastSyncAt = async () => {
|
|
10529
|
-
const { data: userMarker } = await getUserMarker();
|
|
10530
|
-
if (userMarker == null)
|
|
10531
|
-
return;
|
|
10532
|
-
saveDeviceLastSyncAt(new Date(userMarker.lastSyncAt));
|
|
10533
|
-
};
|
|
10534
10735
|
/**
|
|
10535
10736
|
* list of conditions that make timer still trigger the syncing process.
|
|
10536
10737
|
* If it's empty, it means sync is stopped.
|
|
@@ -10587,353 +10788,52 @@ const markerSyncTrigger = async () => {
|
|
|
10587
10788
|
}
|
|
10588
10789
|
}
|
|
10589
10790
|
catch (_a) {
|
|
10590
|
-
// prevent sync from stopping
|
|
10591
|
-
}
|
|
10592
|
-
finally {
|
|
10593
|
-
if (isWaitingForResponse) {
|
|
10594
|
-
isWaitingForResponse = false;
|
|
10595
|
-
}
|
|
10596
|
-
}
|
|
10597
|
-
};
|
|
10598
|
-
const registerEventListeners = () => {
|
|
10599
|
-
if (disposers$1.length > 0) {
|
|
10600
|
-
return;
|
|
10601
|
-
}
|
|
10602
|
-
// based on the tech spec design, we designed a fetch marker in case of these events
|
|
10603
|
-
// - new message
|
|
10604
|
-
// - create channel
|
|
10605
|
-
// - remove channel
|
|
10606
|
-
// - app going to online again after offline
|
|
10607
|
-
disposers$1.push(onOnline(() => {
|
|
10608
|
-
// should add RESUME to the event to trigger marker syncing again
|
|
10609
|
-
events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
|
|
10610
|
-
}), onMessageCreatedMqtt(message => {
|
|
10611
|
-
// only conversation, community and broadcast types can sync
|
|
10612
|
-
const client = getActiveClient();
|
|
10613
|
-
if (isUnreadCountSupport$1(message) && message.creatorId !== client.userId)
|
|
10614
|
-
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
10615
|
-
}), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
10616
|
-
/*
|
|
10617
|
-
workaround: when receiving the event for sub-channel deletion,
|
|
10618
|
-
before triggering marker update, the SDK will have to add a 2-second delay.
|
|
10619
|
-
so that the unread count is calculated correctly.
|
|
10620
|
-
*/
|
|
10621
|
-
setTimeout(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */), ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY)), onFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)), onUserMarkerSync(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)), onUserFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)));
|
|
10622
|
-
};
|
|
10623
|
-
const unRegisterEventListeners = () => {
|
|
10624
|
-
disposers$1.forEach(fn => fn());
|
|
10625
|
-
disposers$1 = [];
|
|
10626
|
-
};
|
|
10627
|
-
const startMarkerSync = async () => {
|
|
10628
|
-
await fetchDeviceLastSyncAt();
|
|
10629
|
-
pushMarkerSyncEvent("start syncing" /* Amity.MarkerSyncEvent.START_SYNCING */);
|
|
10630
|
-
isConsistentMode = true;
|
|
10631
|
-
isSyncRunning = true;
|
|
10632
|
-
registerEventListeners();
|
|
10633
|
-
return unRegisterEventListeners;
|
|
10634
|
-
};
|
|
10635
|
-
/**
|
|
10636
|
-
```js
|
|
10637
|
-
* import { startUnreadSync } from '@amityco/ts-sdk'
|
|
10638
|
-
* startUnreadSync()
|
|
10639
|
-
* ```
|
|
10640
|
-
*
|
|
10641
|
-
* start syncing to keep feed markers, channel markers and user makers cache
|
|
10642
|
-
* update to the server.
|
|
10643
|
-
*
|
|
10644
|
-
* @category Marker API
|
|
10645
|
-
*/
|
|
10646
|
-
const startUnreadSync = async () => {
|
|
10647
|
-
await fetchDeviceLastSyncAt();
|
|
10648
|
-
pushMarkerSyncEvent("start syncing" /* Amity.MarkerSyncEvent.START_SYNCING */);
|
|
10649
|
-
enableUnreadCount();
|
|
10650
|
-
isConsistentMode = false;
|
|
10651
|
-
isSyncRunning = true;
|
|
10652
|
-
registerEventListeners();
|
|
10653
|
-
};
|
|
10654
|
-
/**
|
|
10655
|
-
```js
|
|
10656
|
-
* import { stopUnreadSync } from '@amityco/ts-sdk'
|
|
10657
|
-
* stopUnreadSync()
|
|
10658
|
-
* ```
|
|
10659
|
-
*
|
|
10660
|
-
* stop unread syncing
|
|
10661
|
-
*
|
|
10662
|
-
* @category Marker API
|
|
10663
|
-
*/
|
|
10664
|
-
const stopUnreadSync = () => {
|
|
10665
|
-
isSyncRunning = false;
|
|
10666
|
-
setMarkerSyncEvents([]);
|
|
10667
|
-
unRegisterEventListeners();
|
|
10668
|
-
};
|
|
10669
|
-
setIntervalTask(async () => {
|
|
10670
|
-
if (!isSyncRunning)
|
|
10671
|
-
return;
|
|
10672
|
-
await markerSyncTrigger();
|
|
10673
|
-
}, SYNC_TRIGGER_INTERVAL_TIME);
|
|
10674
|
-
const getMarkerSyncConsistentMode = () => isConsistentMode;
|
|
10675
|
-
|
|
10676
|
-
/* eslint-disable no-param-reassign */
|
|
10677
|
-
/*
|
|
10678
|
-
* declared earlier to accomodate case when logging in with a different user
|
|
10679
|
-
* than the one already connected, in which case the existing subscriptions need
|
|
10680
|
-
* to be cleared
|
|
10681
|
-
*/
|
|
10682
|
-
let subscriptions = [];
|
|
10683
|
-
async function runMqtt() {
|
|
10684
|
-
await modifyMqttConnection();
|
|
10685
|
-
}
|
|
10686
|
-
/* begin_public_function
|
|
10687
|
-
id: client.login
|
|
10688
|
-
*/
|
|
10689
|
-
/**
|
|
10690
|
-
* ```js
|
|
10691
|
-
* import { login } from '@amityco/ts-sdk/client/api'
|
|
10692
|
-
* const success = await login({
|
|
10693
|
-
* userId: 'XYZ123456789',
|
|
10694
|
-
* })
|
|
10695
|
-
* ```
|
|
10696
|
-
*
|
|
10697
|
-
* Connects an {@link Amity.Client} instance to ASC servers
|
|
10698
|
-
*
|
|
10699
|
-
* @param params the connect parameters
|
|
10700
|
-
* @param params.userId the user ID for the current session
|
|
10701
|
-
* @param params.displayName the user's displayName for the current session
|
|
10702
|
-
* @param params.deviceId Manual override of the user's device id (for device management)
|
|
10703
|
-
* @param params.authToken The authentication token - necessary when network option is set to secure
|
|
10704
|
-
* @returns a success boolean if connected
|
|
10705
|
-
*
|
|
10706
|
-
* @category Client API
|
|
10707
|
-
* @async
|
|
10708
|
-
*/
|
|
10709
|
-
const login = async (params, sessionHandler, config) => {
|
|
10710
|
-
var _a;
|
|
10711
|
-
const client = getActiveClient();
|
|
10712
|
-
let unsubWatcher;
|
|
10713
|
-
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
10714
|
-
// if connecting to a different userId than the one that is connected currently
|
|
10715
|
-
if (client.userId && client.userId !== params.userId) {
|
|
10716
|
-
await logout();
|
|
10717
|
-
// Remove subscription to ban and delete
|
|
10718
|
-
subscriptions.forEach(fn => fn());
|
|
10719
|
-
subscriptions = [];
|
|
10720
|
-
}
|
|
10721
|
-
// default values
|
|
10722
|
-
const defaultDeviceId = await getDeviceId();
|
|
10723
|
-
try {
|
|
10724
|
-
const { users } = await setClientToken({
|
|
10725
|
-
params: Object.assign(Object.assign({}, params), { displayName: params === null || params === void 0 ? void 0 : params.displayName, deviceId: (params === null || params === void 0 ? void 0 : params.deviceId) || defaultDeviceId }),
|
|
10726
|
-
options: {
|
|
10727
|
-
setAccessTokenCookie: true,
|
|
10728
|
-
},
|
|
10729
|
-
});
|
|
10730
|
-
const user = users.find(u => u.userId === params.userId);
|
|
10731
|
-
if (user == null) {
|
|
10732
|
-
throw new ASCError(`${params.userId} has not been founded`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
10733
|
-
}
|
|
10734
|
-
if (user.isDeleted) {
|
|
10735
|
-
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
10736
|
-
return false;
|
|
10737
|
-
}
|
|
10738
|
-
if (user.isGlobalBanned) {
|
|
10739
|
-
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
10740
|
-
return false;
|
|
10741
|
-
}
|
|
10742
|
-
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
10743
|
-
// wire websocket events to our event emitter
|
|
10744
|
-
proxyWebsocketEvents(client.ws, client.emitter);
|
|
10745
|
-
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
10746
|
-
client.userId = user.userId;
|
|
10747
|
-
client.sessionHandler = sessionHandler;
|
|
10748
|
-
/*
|
|
10749
|
-
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
10750
|
-
* token expires
|
|
10751
|
-
*/
|
|
10752
|
-
unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
|
|
10753
|
-
setActiveUser(user);
|
|
10754
|
-
}
|
|
10755
|
-
catch (error) {
|
|
10756
|
-
/*
|
|
10757
|
-
* if getting token failed session state reverts to initial state when app
|
|
10758
|
-
* is first launched
|
|
10759
|
-
*/
|
|
10760
|
-
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
10761
|
-
// pass error down tree so the calling function handle it
|
|
10762
|
-
throw error;
|
|
10763
|
-
}
|
|
10764
|
-
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
10765
|
-
runMqtt();
|
|
10766
|
-
}
|
|
10767
|
-
await initializeMessagePreviewSetting();
|
|
10768
|
-
if (subscriptions.length === 0) {
|
|
10769
|
-
subscriptions.push(
|
|
10770
|
-
// GLOBAL_BAN
|
|
10771
|
-
onClientBanned((_) => {
|
|
10772
|
-
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
10773
|
-
subscriptions.forEach(fn => fn());
|
|
10774
|
-
unsubWatcher();
|
|
10775
|
-
}), onTokenTerminated(_ => {
|
|
10776
|
-
terminateClient();
|
|
10777
|
-
subscriptions.forEach(fn => fn());
|
|
10778
|
-
unsubWatcher();
|
|
10779
|
-
}), onUserDeleted$2((user) => {
|
|
10780
|
-
if (user.userId === client.userId) {
|
|
10781
|
-
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
10782
|
-
subscriptions.forEach(fn => fn());
|
|
10783
|
-
unsubWatcher();
|
|
10784
|
-
}
|
|
10785
|
-
}), onTokenExpired(state => {
|
|
10786
|
-
SessionWatcher$1.getInstance().setSessionState(state);
|
|
10787
|
-
logout();
|
|
10788
|
-
subscriptions.forEach(fn => fn());
|
|
10789
|
-
}),
|
|
10790
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
10791
|
-
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
10792
|
-
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
10793
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
10794
|
-
if (client.useLegacyUnreadCount) {
|
|
10795
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
10791
|
+
// prevent sync from stopping
|
|
10792
|
+
}
|
|
10793
|
+
finally {
|
|
10794
|
+
if (isWaitingForResponse) {
|
|
10795
|
+
isWaitingForResponse = false;
|
|
10796
10796
|
}
|
|
10797
|
-
else
|
|
10798
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
10799
|
-
const markerSyncUnsubscriber = await startMarkerSync();
|
|
10800
|
-
subscriptions.push(markerSyncUnsubscriber);
|
|
10801
10797
|
}
|
|
10802
|
-
return true;
|
|
10803
10798
|
};
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
id: client.renew_access_token
|
|
10808
|
-
*/
|
|
10809
|
-
/*
|
|
10810
|
-
* Renewal defintion accepted by SessionHandler interface
|
|
10811
|
-
*
|
|
10812
|
-
* Tech Spec:
|
|
10813
|
-
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Session-Handler
|
|
10814
|
-
*
|
|
10815
|
-
* @category private
|
|
10816
|
-
*/
|
|
10817
|
-
const renewal = () => {
|
|
10818
|
-
let tokenRenewed = false;
|
|
10819
|
-
let renewTimeoutId;
|
|
10820
|
-
const client = getActiveClient();
|
|
10821
|
-
client.log('initiating access token renewal');
|
|
10822
|
-
/*
|
|
10823
|
-
* Renews a token if it is hasn't been renewed before. Also marks token as
|
|
10824
|
-
* renewed once done
|
|
10825
|
-
* Per instance of Renewal, only one renewal is allowed
|
|
10826
|
-
*/
|
|
10827
|
-
const renewToken = async (authToken) => {
|
|
10828
|
-
const { userId, displayName } = getActiveUser();
|
|
10829
|
-
const deviceId = await getDeviceId();
|
|
10830
|
-
const params = { userId, displayName, authToken, deviceId };
|
|
10831
|
-
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
10832
|
-
await login(params, client.sessionHandler);
|
|
10833
|
-
}
|
|
10834
|
-
else {
|
|
10835
|
-
// about to expire
|
|
10836
|
-
await setClientToken({
|
|
10837
|
-
params,
|
|
10838
|
-
options: {
|
|
10839
|
-
setAccessTokenCookie: true,
|
|
10840
|
-
},
|
|
10841
|
-
});
|
|
10842
|
-
}
|
|
10843
|
-
tokenRenewed = true;
|
|
10844
|
-
if (renewTimeoutId)
|
|
10845
|
-
clearTimeout(renewTimeoutId);
|
|
10846
|
-
};
|
|
10847
|
-
return {
|
|
10848
|
-
renew: () => {
|
|
10849
|
-
if (tokenRenewed) {
|
|
10850
|
-
console.log("'renew' method can be called only once per renewal instance");
|
|
10851
|
-
return;
|
|
10852
|
-
}
|
|
10853
|
-
renewToken();
|
|
10854
|
-
},
|
|
10855
|
-
renewWithAuthToken: (authToken) => {
|
|
10856
|
-
if (tokenRenewed) {
|
|
10857
|
-
console.log("'renewWithAuthToken' method can be called only once per renewal instance");
|
|
10858
|
-
return;
|
|
10859
|
-
}
|
|
10860
|
-
renewToken(authToken);
|
|
10861
|
-
},
|
|
10862
|
-
unableToRetrieveAuthToken: () => {
|
|
10863
|
-
renewTimeoutId = setTimeout(() => {
|
|
10864
|
-
var _a;
|
|
10865
|
-
(_a = client.sessionHandler) === null || _a === void 0 ? void 0 : _a.sessionWillRenewAccessToken(renewal());
|
|
10866
|
-
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
10867
|
-
},
|
|
10868
|
-
};
|
|
10799
|
+
const unRegisterEventListeners = () => {
|
|
10800
|
+
disposers$1.forEach(fn => fn());
|
|
10801
|
+
disposers$1 = [];
|
|
10869
10802
|
};
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
*
|
|
10803
|
+
const startMarkerSync = async () => Promise.resolve();
|
|
10804
|
+
/**
|
|
10805
|
+
```js
|
|
10806
|
+
* import { startUnreadSync } from '@amityco/ts-sdk'
|
|
10807
|
+
* startUnreadSync()
|
|
10808
|
+
* ```
|
|
10876
10809
|
*
|
|
10877
|
-
*
|
|
10878
|
-
*
|
|
10810
|
+
* start syncing to keep feed markers, channel markers and user makers cache
|
|
10811
|
+
* update to the server.
|
|
10879
10812
|
*
|
|
10880
|
-
* @category
|
|
10813
|
+
* @category Marker API
|
|
10881
10814
|
*/
|
|
10882
|
-
const
|
|
10883
|
-
|
|
10884
|
-
|
|
10815
|
+
const startUnreadSync = async () => Promise.resolve();
|
|
10816
|
+
/**
|
|
10817
|
+
```js
|
|
10818
|
+
* import { stopUnreadSync } from '@amityco/ts-sdk'
|
|
10819
|
+
* stopUnreadSync()
|
|
10820
|
+
* ```
|
|
10885
10821
|
*
|
|
10886
|
-
*
|
|
10887
|
-
* @returns boolean indicating if token is aboutToExpire
|
|
10822
|
+
* stop unread syncing
|
|
10888
10823
|
*
|
|
10889
|
-
* @category
|
|
10824
|
+
* @category Marker API
|
|
10890
10825
|
*/
|
|
10891
|
-
const
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
const now = Date.now();
|
|
10896
|
-
const duration = expires - issued - COMPENSATED_DELAY;
|
|
10897
|
-
const aboutToExpireAt = issued + duration * ABOUT_TO_EXPIRE_THRESHOLD;
|
|
10898
|
-
return now > aboutToExpireAt && now < expires;
|
|
10826
|
+
const stopUnreadSync = () => {
|
|
10827
|
+
isSyncRunning = false;
|
|
10828
|
+
setMarkerSyncEvents([]);
|
|
10829
|
+
unRegisterEventListeners();
|
|
10899
10830
|
};
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
*/
|
|
10907
|
-
const accessTokenExpiryWatcher = (sessionHandler) => {
|
|
10908
|
-
const interval = setInterval(() => {
|
|
10909
|
-
const client = getActiveClient();
|
|
10910
|
-
if (!client.token)
|
|
10911
|
-
return;
|
|
10912
|
-
const { issuedAt, expiresAt } = client.token;
|
|
10913
|
-
if (isExpired(expiresAt)) {
|
|
10914
|
-
/*
|
|
10915
|
-
* the event handler will take care of updating session state
|
|
10916
|
-
* Note, this will also clear the interval id, so this event will only be
|
|
10917
|
-
* fired once
|
|
10918
|
-
*/
|
|
10919
|
-
fireEvent('tokenExpired', "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */);
|
|
10920
|
-
/*
|
|
10921
|
-
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Automatically-initiate-renewal-flow
|
|
10922
|
-
*
|
|
10923
|
-
* Why sechduled task?
|
|
10924
|
-
* Since fireEvent is scheduled, it will be called
|
|
10925
|
-
* after sessionHandler leading to an invalid state change from
|
|
10926
|
-
* establishing to tokenExpired
|
|
10927
|
-
*/
|
|
10928
|
-
scheduleTask(() => sessionHandler.sessionWillRenewAccessToken(renewal()));
|
|
10929
|
-
return;
|
|
10930
|
-
}
|
|
10931
|
-
if (isAboutToExpire({ expiresAt, issuedAt })) {
|
|
10932
|
-
sessionHandler.sessionWillRenewAccessToken(renewal());
|
|
10933
|
-
}
|
|
10934
|
-
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
10935
|
-
return () => clearInterval(interval);
|
|
10936
|
-
};
|
|
10831
|
+
setIntervalTask(async () => {
|
|
10832
|
+
if (!isSyncRunning)
|
|
10833
|
+
return;
|
|
10834
|
+
await markerSyncTrigger();
|
|
10835
|
+
}, SYNC_TRIGGER_INTERVAL_TIME);
|
|
10836
|
+
const getMarkerSyncConsistentMode = () => isConsistentMode;
|
|
10937
10837
|
|
|
10938
10838
|
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
10939
10839
|
/**
|
|
@@ -11080,6 +10980,10 @@ const isConnected = () => {
|
|
|
11080
10980
|
isWsConnected);
|
|
11081
10981
|
};
|
|
11082
10982
|
|
|
10983
|
+
const enableUnreadCount = () => {
|
|
10984
|
+
return true;
|
|
10985
|
+
};
|
|
10986
|
+
|
|
11083
10987
|
var _GlobalFileAccessType_fileAccessType;
|
|
11084
10988
|
class GlobalFileAccessType {
|
|
11085
10989
|
constructor() {
|
|
@@ -13231,10 +13135,10 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
13231
13135
|
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
13232
13136
|
* ```
|
|
13233
13137
|
*
|
|
13234
|
-
* Blocks a {@link Amity.
|
|
13138
|
+
* Blocks a {@link Amity.User}
|
|
13235
13139
|
*
|
|
13236
|
-
* @param params The params to get blocked {@link Amity.
|
|
13237
|
-
* @param callback to recieve updates on unblocked {@link Amity.
|
|
13140
|
+
* @param params The params to get blocked {@link Amity.User}s
|
|
13141
|
+
* @param callback to recieve updates on unblocked {@link Amity.User}s
|
|
13238
13142
|
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
13239
13143
|
*
|
|
13240
13144
|
* @category Post API
|
|
@@ -13826,6 +13730,57 @@ const updateAltText = async (fileId, altText) => {
|
|
|
13826
13730
|
};
|
|
13827
13731
|
/* end_public_function */
|
|
13828
13732
|
|
|
13733
|
+
/* begin_public_function
|
|
13734
|
+
id: file.upload.clip
|
|
13735
|
+
*/
|
|
13736
|
+
/**
|
|
13737
|
+
* ```js
|
|
13738
|
+
* import { FileRepository } from '@amityco/ts-sdk'
|
|
13739
|
+
* const created = await FileRepository.uploadClip(formData)
|
|
13740
|
+
* ```
|
|
13741
|
+
*
|
|
13742
|
+
* Creates an {@link Amity.File}
|
|
13743
|
+
*
|
|
13744
|
+
* @param formData The data necessary to create a new {@link Amity.File}
|
|
13745
|
+
* @param onProgress The callback to track the upload progress
|
|
13746
|
+
* @returns The newly created {@link Amity.File}
|
|
13747
|
+
*
|
|
13748
|
+
* @category File API
|
|
13749
|
+
* @async
|
|
13750
|
+
*/
|
|
13751
|
+
const uploadClip = async (formData, feedType, onProgress) => {
|
|
13752
|
+
const client = getActiveClient();
|
|
13753
|
+
client.log('file/uploadClip', formData);
|
|
13754
|
+
const file = formData.get('files');
|
|
13755
|
+
if (!file)
|
|
13756
|
+
throw new Error('The formData object must have a `files` key.');
|
|
13757
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
13758
|
+
formData.append('accessType', accessType);
|
|
13759
|
+
formData.append('preferredFilename', file.name);
|
|
13760
|
+
if (feedType) {
|
|
13761
|
+
formData.append('feedType', feedType);
|
|
13762
|
+
}
|
|
13763
|
+
const headers = 'getHeaders' in formData
|
|
13764
|
+
? formData.getHeaders()
|
|
13765
|
+
: { 'content-type': 'multipart/form-data' };
|
|
13766
|
+
const { data } = await client.upload.post('/api/v4/clips', formData, {
|
|
13767
|
+
headers,
|
|
13768
|
+
onUploadProgress({ loaded, total = 100 }) {
|
|
13769
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
13770
|
+
},
|
|
13771
|
+
});
|
|
13772
|
+
// API-FIX: payload should be serialized properly
|
|
13773
|
+
// const { files } = data
|
|
13774
|
+
const cachedAt = client.cache && Date.now();
|
|
13775
|
+
if (client.cache)
|
|
13776
|
+
ingestInCache({ files: data }, { cachedAt });
|
|
13777
|
+
return {
|
|
13778
|
+
data,
|
|
13779
|
+
cachedAt,
|
|
13780
|
+
};
|
|
13781
|
+
};
|
|
13782
|
+
/* end_public_function */
|
|
13783
|
+
|
|
13829
13784
|
var index$k = /*#__PURE__*/Object.freeze({
|
|
13830
13785
|
__proto__: null,
|
|
13831
13786
|
getFile: getFile,
|
|
@@ -13834,7 +13789,8 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
13834
13789
|
fileUrlWithSize: fileUrlWithSize,
|
|
13835
13790
|
uploadVideo: uploadVideo,
|
|
13836
13791
|
uploadImage: uploadImage,
|
|
13837
|
-
updateAltText: updateAltText
|
|
13792
|
+
updateAltText: updateAltText,
|
|
13793
|
+
uploadClip: uploadClip
|
|
13838
13794
|
});
|
|
13839
13795
|
|
|
13840
13796
|
/**
|
|
@@ -14078,7 +14034,7 @@ const getPost$2 = async (postId) => {
|
|
|
14078
14034
|
const { posts } = data;
|
|
14079
14035
|
const result = posts.find(post => post.postId === postId);
|
|
14080
14036
|
return {
|
|
14081
|
-
data:
|
|
14037
|
+
data: result,
|
|
14082
14038
|
cachedAt,
|
|
14083
14039
|
};
|
|
14084
14040
|
};
|
|
@@ -14104,7 +14060,7 @@ getPost$2.locally = (postId) => {
|
|
|
14104
14060
|
if (!cached)
|
|
14105
14061
|
return;
|
|
14106
14062
|
return {
|
|
14107
|
-
data:
|
|
14063
|
+
data: cached.data,
|
|
14108
14064
|
cachedAt: cached.cachedAt,
|
|
14109
14065
|
};
|
|
14110
14066
|
};
|
|
@@ -14265,7 +14221,7 @@ const prepareCommentFromFlaggedEvent = (payload) => {
|
|
|
14265
14221
|
* @async
|
|
14266
14222
|
* */
|
|
14267
14223
|
const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
14268
|
-
var _a, _b;
|
|
14224
|
+
var _a, _b, _c;
|
|
14269
14225
|
const client = getActiveClient();
|
|
14270
14226
|
client.log('reaction/createReaction', {
|
|
14271
14227
|
referenceId,
|
|
@@ -14286,9 +14242,9 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
14286
14242
|
'get',
|
|
14287
14243
|
referenceId,
|
|
14288
14244
|
]);
|
|
14289
|
-
if (!model)
|
|
14245
|
+
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
14290
14246
|
return true;
|
|
14291
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((
|
|
14247
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
14292
14248
|
if (referenceType === 'comment') {
|
|
14293
14249
|
fireEvent('local.comment.addReaction', {
|
|
14294
14250
|
comment: updatedModel,
|
|
@@ -19719,7 +19675,7 @@ const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommu
|
|
|
19719
19675
|
}
|
|
19720
19676
|
const { communities } = data;
|
|
19721
19677
|
return {
|
|
19722
|
-
data:
|
|
19678
|
+
data: communities.find(community => community.communityId === communityId),
|
|
19723
19679
|
cachedAt,
|
|
19724
19680
|
};
|
|
19725
19681
|
};
|
|
@@ -19745,7 +19701,7 @@ getCommunity$1.locally = (communityId) => {
|
|
|
19745
19701
|
if (!cached)
|
|
19746
19702
|
return;
|
|
19747
19703
|
return {
|
|
19748
|
-
data:
|
|
19704
|
+
data: cached.data,
|
|
19749
19705
|
cachedAt: cached.cachedAt,
|
|
19750
19706
|
};
|
|
19751
19707
|
};
|
|
@@ -19781,7 +19737,7 @@ const deleteCommunity = async (communityId) => {
|
|
|
19781
19737
|
files: [],
|
|
19782
19738
|
users: [],
|
|
19783
19739
|
});
|
|
19784
|
-
return deleted.data;
|
|
19740
|
+
return LinkedObject.community(deleted.data);
|
|
19785
19741
|
};
|
|
19786
19742
|
/* end_public_function */
|
|
19787
19743
|
|
|
@@ -21291,7 +21247,11 @@ const getCommunity = (communityId, callback) => {
|
|
|
21291
21247
|
onCommunityUserUnbanned,
|
|
21292
21248
|
onCommunityUserChanged,
|
|
21293
21249
|
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
21294
|
-
]
|
|
21250
|
+
], {
|
|
21251
|
+
callbackDataSelector: (data) => {
|
|
21252
|
+
return LinkedObject.community(data);
|
|
21253
|
+
},
|
|
21254
|
+
});
|
|
21295
21255
|
};
|
|
21296
21256
|
/* end_public_function */
|
|
21297
21257
|
|
|
@@ -22430,14 +22390,14 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
22430
22390
|
const queryGlobalFeed = async (query) => {
|
|
22431
22391
|
const client = getActiveClient();
|
|
22432
22392
|
client.log('feed/queryGlobalFeed', query);
|
|
22433
|
-
const _a = query !== null && query !== void 0 ? query : {}, { queryToken } = _a, params = __rest(_a, ["queryToken"]);
|
|
22393
|
+
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, dataTypes, resolveParent } = _a, params = __rest(_a, ["queryToken", "dataTypes", "resolveParent"]);
|
|
22434
22394
|
const options = (() => {
|
|
22435
22395
|
if (queryToken)
|
|
22436
22396
|
return { token: queryToken };
|
|
22437
22397
|
return undefined;
|
|
22438
22398
|
})();
|
|
22439
22399
|
const { data: queryPayload } = await client.http.get(`/api/v4/me/global-feeds`, {
|
|
22440
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
22400
|
+
params: Object.assign(Object.assign({}, params), { dataTypes, resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
|
|
22441
22401
|
});
|
|
22442
22402
|
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
22443
22403
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
@@ -23023,6 +22983,46 @@ const isPostFlaggedByMe = async (postId) => {
|
|
|
23023
22983
|
};
|
|
23024
22984
|
/* end_public_function */
|
|
23025
22985
|
|
|
22986
|
+
/* begin_public_function
|
|
22987
|
+
id: post.create.clip_post
|
|
22988
|
+
*/
|
|
22989
|
+
/**
|
|
22990
|
+
* ```js
|
|
22991
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
22992
|
+
* const created = await PostRepository.createClipPost({
|
|
22993
|
+
* targetType: 'user',
|
|
22994
|
+
* targetId: 'foobar',
|
|
22995
|
+
* dataType: 'clip',
|
|
22996
|
+
* data: { text: 'hello world' },
|
|
22997
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
22998
|
+
* }))
|
|
22999
|
+
* ```
|
|
23000
|
+
*
|
|
23001
|
+
* Creates an {@link Amity.Post}
|
|
23002
|
+
*
|
|
23003
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
23004
|
+
* @returns The newly created {@link Amity.Post}
|
|
23005
|
+
*
|
|
23006
|
+
* @category Post API
|
|
23007
|
+
* @async
|
|
23008
|
+
*/
|
|
23009
|
+
const createClipPost = async (bundle) => {
|
|
23010
|
+
const client = getActiveClient();
|
|
23011
|
+
client.log('post/createPost', bundle);
|
|
23012
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
23013
|
+
fireEvent('post.created', payload);
|
|
23014
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23015
|
+
const cachedAt = client.cache && Date.now();
|
|
23016
|
+
if (client.cache)
|
|
23017
|
+
ingestInCache(data, { cachedAt });
|
|
23018
|
+
const { posts } = data;
|
|
23019
|
+
return {
|
|
23020
|
+
data: LinkedObject.post(posts[0]),
|
|
23021
|
+
cachedAt,
|
|
23022
|
+
};
|
|
23023
|
+
};
|
|
23024
|
+
/* end_public_function */
|
|
23025
|
+
|
|
23026
23026
|
/* begin_public_function
|
|
23027
23027
|
id: comment.get_by_ids
|
|
23028
23028
|
*/
|
|
@@ -24071,12 +24071,12 @@ const getPost$1 = (postId, callback) => {
|
|
|
24071
24071
|
onPostFlagged,
|
|
24072
24072
|
(callback) => {
|
|
24073
24073
|
return onPostReactionAdded((post) => {
|
|
24074
|
-
callback(
|
|
24074
|
+
callback(post);
|
|
24075
24075
|
});
|
|
24076
24076
|
},
|
|
24077
24077
|
(callback) => {
|
|
24078
24078
|
return onPostReactionRemoved((post) => {
|
|
24079
|
-
callback(
|
|
24079
|
+
callback(post);
|
|
24080
24080
|
});
|
|
24081
24081
|
},
|
|
24082
24082
|
onPostUnflagged,
|
|
@@ -24111,7 +24111,7 @@ class PostPaginationController extends PaginationController {
|
|
|
24111
24111
|
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
24112
24112
|
};
|
|
24113
24113
|
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
24114
|
-
const { data: queryResponse } = await this.http.get(`/api/
|
|
24114
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
24115
24115
|
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
24116
24116
|
/*
|
|
24117
24117
|
* when creating post like image, file, video BE will create 2 posts
|
|
@@ -24923,6 +24923,7 @@ var index$7 = /*#__PURE__*/Object.freeze({
|
|
|
24923
24923
|
flagPost: flagPost,
|
|
24924
24924
|
unflagPost: unflagPost,
|
|
24925
24925
|
isPostFlaggedByMe: isPostFlaggedByMe,
|
|
24926
|
+
createClipPost: createClipPost,
|
|
24926
24927
|
onPostCreated: onPostCreated,
|
|
24927
24928
|
onPostUpdated: onPostUpdated,
|
|
24928
24929
|
onPostDeleted: onPostDeleted,
|