@amityco/ts-sdk 0.0.1-beta.22 → 0.0.1-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +5 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -2
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +1 -1
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +2 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/client/api/connectClient.d.ts +3 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts +1 -0
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts +1 -0
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/index.cjs.js +381 -67
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +376 -68
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/events/onMessageUpdated.d.ts.map +1 -1
- package/dist/poll/api/closePoll.d.ts.map +1 -1
- package/dist/poll/api/deletePoll.d.ts.map +1 -1
- package/dist/poll/api/votePoll.d.ts.map +1 -1
- package/dist/poll/events/index.d.ts +3 -0
- package/dist/poll/events/index.d.ts.map +1 -0
- package/dist/poll/events/onPollDeleted.d.ts +17 -0
- package/dist/poll/events/onPollDeleted.d.ts.map +1 -0
- package/dist/poll/events/onPollUpdated.d.ts +17 -0
- package/dist/poll/events/onPollUpdated.d.ts.map +1 -0
- package/dist/poll/observers/index.d.ts +2 -0
- package/dist/poll/observers/index.d.ts.map +1 -0
- package/dist/poll/observers/observePoll.d.ts +18 -0
- package/dist/poll/observers/observePoll.d.ts.map +1 -0
- package/dist/post/api/approvePost.d.ts +17 -0
- package/dist/post/api/approvePost.d.ts.map +1 -0
- package/dist/post/api/declinePost.d.ts +17 -0
- package/dist/post/api/declinePost.d.ts.map +1 -0
- package/dist/post/api/index.d.ts +2 -0
- package/dist/post/api/index.d.ts.map +1 -1
- package/dist/reaction/events/onReactionAdded.d.ts.map +1 -1
- package/dist/reaction/utils/index.d.ts +1 -0
- package/dist/reaction/utils/index.d.ts.map +1 -1
- package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts +3 -0
- package/dist/reaction/utils/prepareMessagePayloadForCache.d.ts.map +1 -0
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +6 -1
- package/src/@types/domains/channel.ts +1 -2
- package/src/@types/domains/reaction.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +4 -4
- package/src/channel/api/updateChannel.ts +1 -1
- package/src/client/api/connectClient.ts +12 -7
- package/src/comment/api/queryComments.ts +6 -3
- package/src/core/model/identifyModel.ts +18 -0
- package/src/core/query/query.ts +19 -1
- package/src/index.ts +2 -0
- package/src/message/api/createMessage.ts +22 -6
- package/src/message/events/onMessageUpdated.ts +9 -1
- package/src/poll/api/closePoll.ts +3 -0
- package/src/poll/api/deletePoll.ts +3 -0
- package/src/poll/api/votePoll.ts +3 -0
- package/src/poll/events/index.ts +2 -0
- package/src/poll/events/onPollDeleted.ts +31 -0
- package/src/poll/events/onPollUpdated.ts +31 -0
- package/src/poll/observers/index.ts +1 -0
- package/src/poll/observers/observePoll.ts +67 -0
- package/src/post/api/approvePost.ts +48 -0
- package/src/post/api/declinePost.ts +48 -0
- package/src/post/api/index.ts +3 -0
- package/src/reaction/events/onReactionAdded.ts +4 -0
- package/src/reaction/utils/index.ts +1 -0
- package/src/reaction/utils/prepareMessagePayloadForCache.ts +40 -0
- package/src/report/api/createReport.ts +7 -1
- package/src/report/api/deleteReport.ts +7 -1
package/dist/index.esm.js
CHANGED
|
@@ -5,6 +5,7 @@ import debug from 'debug';
|
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
|
7
7
|
import io from 'socket.io-client';
|
|
8
|
+
import nativeIdGenerator from 'react-native-uuid';
|
|
8
9
|
|
|
9
10
|
var _a$1;
|
|
10
11
|
/* eslint-disable no-undef */
|
|
@@ -166,6 +167,121 @@ const toPageRaw = (token) => {
|
|
|
166
167
|
return undefined;
|
|
167
168
|
};
|
|
168
169
|
|
|
170
|
+
/** @hidden */
|
|
171
|
+
const idResolvers = {
|
|
172
|
+
user: ({ userId }) => userId,
|
|
173
|
+
file: ({ fileId }) => fileId,
|
|
174
|
+
role: ({ roleId }) => roleId,
|
|
175
|
+
channel: ({ channelId }) => channelId,
|
|
176
|
+
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
177
|
+
message: ({ messageId }) => messageId,
|
|
178
|
+
community: ({ communityId }) => communityId,
|
|
179
|
+
category: ({ categoryId }) => categoryId,
|
|
180
|
+
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
181
|
+
post: ({ postId }) => postId,
|
|
182
|
+
comment: ({ commentId }) => commentId,
|
|
183
|
+
poll: ({ pollId }) => pollId,
|
|
184
|
+
reaction: ({ reactionId }) => reactionId,
|
|
185
|
+
stream: ({ streamId }) => streamId,
|
|
186
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
187
|
+
followCount: ({ userId }) => userId,
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Retrieve the id resolver matching a domain name
|
|
191
|
+
*
|
|
192
|
+
* @param name the domain name for the resolve
|
|
193
|
+
* @returns an idResolver function for the given domain name
|
|
194
|
+
*/
|
|
195
|
+
const getResolver = (name) => idResolvers[name];
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Identification criterias
|
|
199
|
+
*
|
|
200
|
+
* As key, the name of the identified model ;
|
|
201
|
+
* As value, the list of properties to consider a given model as of type
|
|
202
|
+
*
|
|
203
|
+
* Used as source of truth for {@link identifyModel}
|
|
204
|
+
*
|
|
205
|
+
* @hidden
|
|
206
|
+
*/
|
|
207
|
+
const CRITERIAS = {
|
|
208
|
+
file: ['fileId', 'attributes'],
|
|
209
|
+
user: ['userId', 'avatarFileId'],
|
|
210
|
+
role: ['roleId'],
|
|
211
|
+
channel: ['channelId', 'rateLimit'],
|
|
212
|
+
channelUsers: ['channelId', 'userId', 'membership'],
|
|
213
|
+
message: ['messageId'],
|
|
214
|
+
community: ['communityId', 'onlyAdminCanPost'],
|
|
215
|
+
category: ['categoryId'],
|
|
216
|
+
communityUsers: ['userId', 'communityId', 'communityMembership'],
|
|
217
|
+
post: ['postId', 'feedId'],
|
|
218
|
+
comment: ['commentId', 'referenceId'],
|
|
219
|
+
poll: ['pollId'],
|
|
220
|
+
reaction: ['reactionId'],
|
|
221
|
+
stream: ['streamId'],
|
|
222
|
+
follow: ['from', 'to'],
|
|
223
|
+
followCount: ['userId', 'followerCount'],
|
|
224
|
+
};
|
|
225
|
+
/** @hidden */
|
|
226
|
+
const hasKeys = (object, needles) => {
|
|
227
|
+
const haystack = Object.keys(object);
|
|
228
|
+
return needles.every(needle => haystack.includes(needle));
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Finds the name of the store for a given unknown model
|
|
232
|
+
*
|
|
233
|
+
* @param model one of the {@link Amity.Model} to identify
|
|
234
|
+
* @returns the name of the corresponding store
|
|
235
|
+
*/
|
|
236
|
+
const identifyModel = (model) => {
|
|
237
|
+
var _a;
|
|
238
|
+
// we cannot avoid "as" in here because Object.entries does not
|
|
239
|
+
// allow anything else than "string" as key in the iterator type
|
|
240
|
+
const criterias = Object.entries(CRITERIAS);
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
242
|
+
return (_a = criterias.find(([_, keys]) => hasKeys(model, keys))) === null || _a === void 0 ? void 0 : _a[0];
|
|
243
|
+
};
|
|
244
|
+
/*
|
|
245
|
+
* Identify the modal key for a model
|
|
246
|
+
* Used to get args for optimistic updates
|
|
247
|
+
* Example: createMessage: get messageId on optimistic message creation
|
|
248
|
+
*
|
|
249
|
+
* @param model to be recognized
|
|
250
|
+
* @returns model key array if one if found or undefined
|
|
251
|
+
*/
|
|
252
|
+
const identifyModelKey = (model) => {
|
|
253
|
+
var _a;
|
|
254
|
+
const modalKey = identifyModel(model);
|
|
255
|
+
if (!modalKey) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
return (_a = CRITERIAS[modalKey]) === null || _a === void 0 ? void 0 : _a[0];
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A map of v3 response keys to a store name.
|
|
263
|
+
* @hidden
|
|
264
|
+
*/
|
|
265
|
+
const PAYLOAD2MODEL = {
|
|
266
|
+
users: 'user',
|
|
267
|
+
files: 'file',
|
|
268
|
+
roles: 'role',
|
|
269
|
+
channels: 'channel',
|
|
270
|
+
channelUsers: 'channelUsers',
|
|
271
|
+
messages: 'message',
|
|
272
|
+
communities: 'community',
|
|
273
|
+
categories: 'category',
|
|
274
|
+
communityUsers: 'communityUsers',
|
|
275
|
+
posts: 'post',
|
|
276
|
+
postChildren: 'post',
|
|
277
|
+
comments: 'comment',
|
|
278
|
+
polls: 'poll',
|
|
279
|
+
reactions: 'reaction',
|
|
280
|
+
videoStreamings: 'stream',
|
|
281
|
+
follows: 'follow',
|
|
282
|
+
followCounts: 'followCount',
|
|
283
|
+
};
|
|
284
|
+
|
|
169
285
|
/* eslint-disable no-use-before-define */
|
|
170
286
|
/**
|
|
171
287
|
* Type guard to check and cast that a given async function is has the ".locally" property
|
|
@@ -310,7 +426,23 @@ const runQuery = ({ func, args }, callback, options = queryOptions('cache_then_s
|
|
|
310
426
|
loading: true,
|
|
311
427
|
}));
|
|
312
428
|
}
|
|
313
|
-
|
|
429
|
+
let optimisticArgs = args;
|
|
430
|
+
/* get args for optimistic method calls
|
|
431
|
+
*
|
|
432
|
+
* On optimistic updates, the modal key for the update needs to be passed to
|
|
433
|
+
* the server so as to avoid duplicate modal creation
|
|
434
|
+
*
|
|
435
|
+
* ex: on creating a new message pass the modalKey is messageId, pass this
|
|
436
|
+
* id onto the server so that a duplicate with seperate messageId is not
|
|
437
|
+
* created.
|
|
438
|
+
*/
|
|
439
|
+
if (isMutator(func)) {
|
|
440
|
+
// @ts-ignore
|
|
441
|
+
const modelKey = local && local.data && identifyModelKey(local.data);
|
|
442
|
+
// @ts-ignore
|
|
443
|
+
optimisticArgs = modelKey ? [...args, { [modelKey]: local.data[modelKey] }] : args;
|
|
444
|
+
}
|
|
445
|
+
func(...optimisticArgs)
|
|
314
446
|
.then(fresh => {
|
|
315
447
|
// @ts-ignore i know.
|
|
316
448
|
// isLocal(local) && syncInCache(local, fresh)
|
|
@@ -20203,57 +20335,6 @@ const onClientBanned = (callback) => {
|
|
|
20203
20335
|
});
|
|
20204
20336
|
};
|
|
20205
20337
|
|
|
20206
|
-
/** @hidden */
|
|
20207
|
-
const idResolvers = {
|
|
20208
|
-
user: ({ userId }) => userId,
|
|
20209
|
-
file: ({ fileId }) => fileId,
|
|
20210
|
-
role: ({ roleId }) => roleId,
|
|
20211
|
-
channel: ({ channelId }) => channelId,
|
|
20212
|
-
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
20213
|
-
message: ({ messageId }) => messageId,
|
|
20214
|
-
community: ({ communityId }) => communityId,
|
|
20215
|
-
category: ({ categoryId }) => categoryId,
|
|
20216
|
-
communityUsers: ({ communityId, userId }) => `${communityId}#${userId}`,
|
|
20217
|
-
post: ({ postId }) => postId,
|
|
20218
|
-
comment: ({ commentId }) => commentId,
|
|
20219
|
-
poll: ({ pollId }) => pollId,
|
|
20220
|
-
reaction: ({ reactionId }) => reactionId,
|
|
20221
|
-
stream: ({ streamId }) => streamId,
|
|
20222
|
-
follow: ({ from, to }) => `${from}#${to}`,
|
|
20223
|
-
followCount: ({ userId }) => userId,
|
|
20224
|
-
};
|
|
20225
|
-
/**
|
|
20226
|
-
* Retrieve the id resolver matching a domain name
|
|
20227
|
-
*
|
|
20228
|
-
* @param name the domain name for the resolve
|
|
20229
|
-
* @returns an idResolver function for the given domain name
|
|
20230
|
-
*/
|
|
20231
|
-
const getResolver = (name) => idResolvers[name];
|
|
20232
|
-
|
|
20233
|
-
/**
|
|
20234
|
-
* A map of v3 response keys to a store name.
|
|
20235
|
-
* @hidden
|
|
20236
|
-
*/
|
|
20237
|
-
const PAYLOAD2MODEL = {
|
|
20238
|
-
users: 'user',
|
|
20239
|
-
files: 'file',
|
|
20240
|
-
roles: 'role',
|
|
20241
|
-
channels: 'channel',
|
|
20242
|
-
channelUsers: 'channelUsers',
|
|
20243
|
-
messages: 'message',
|
|
20244
|
-
communities: 'community',
|
|
20245
|
-
categories: 'category',
|
|
20246
|
-
communityUsers: 'communityUsers',
|
|
20247
|
-
posts: 'post',
|
|
20248
|
-
postChildren: 'post',
|
|
20249
|
-
comments: 'comment',
|
|
20250
|
-
polls: 'poll',
|
|
20251
|
-
reactions: 'reaction',
|
|
20252
|
-
videoStreamings: 'stream',
|
|
20253
|
-
follows: 'follow',
|
|
20254
|
-
followCounts: 'followCount',
|
|
20255
|
-
};
|
|
20256
|
-
|
|
20257
20338
|
/**
|
|
20258
20339
|
* Ingest a payload (v3) into the cache
|
|
20259
20340
|
*
|
|
@@ -20327,7 +20408,7 @@ const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', ca
|
|
|
20327
20408
|
* @category Client API
|
|
20328
20409
|
* @async
|
|
20329
20410
|
*/
|
|
20330
|
-
const connectClient = async (params) => {
|
|
20411
|
+
const connectClient = async (params, config) => {
|
|
20331
20412
|
var _a;
|
|
20332
20413
|
const client = getActiveClient();
|
|
20333
20414
|
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey }, params));
|
|
@@ -20352,7 +20433,9 @@ const connectClient = async (params) => {
|
|
|
20352
20433
|
client.userId = params.userId;
|
|
20353
20434
|
client.accessToken = accessToken;
|
|
20354
20435
|
setActiveUser(users[0]);
|
|
20355
|
-
|
|
20436
|
+
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
20437
|
+
subscribeTopic(getNetworkTopic());
|
|
20438
|
+
}
|
|
20356
20439
|
const subscriptions = [
|
|
20357
20440
|
onClientBanned(() => {
|
|
20358
20441
|
disconnectClient();
|
|
@@ -21298,6 +21381,8 @@ queryMessages.locally = (query) => {
|
|
|
21298
21381
|
: undefined;
|
|
21299
21382
|
};
|
|
21300
21383
|
|
|
21384
|
+
const uuid = () => nativeIdGenerator.v4().toString();
|
|
21385
|
+
|
|
21301
21386
|
/**
|
|
21302
21387
|
* ```js
|
|
21303
21388
|
* import { createMessage } from '@amityco/ts-sdk'
|
|
@@ -21348,12 +21433,23 @@ const createMessage = async (bundle) => {
|
|
|
21348
21433
|
createMessage.optimistically = (bundle) => {
|
|
21349
21434
|
var _a, _b;
|
|
21350
21435
|
const client = getActiveClient();
|
|
21351
|
-
client.log('user/createMessage.locally', bundle);
|
|
21352
21436
|
if (!client.cache)
|
|
21353
21437
|
return;
|
|
21354
|
-
|
|
21355
|
-
|
|
21356
|
-
|
|
21438
|
+
/*
|
|
21439
|
+
* when creating messages optimistically a messageId needs to be added by the
|
|
21440
|
+
* client, created a new variable so as to allow backward compatibility of API
|
|
21441
|
+
*
|
|
21442
|
+
* Updated to handle client requirement to add messageId while uploading
|
|
21443
|
+
* message with image. Temporary!
|
|
21444
|
+
*/
|
|
21445
|
+
const bundleWithMessageId = Object.assign({ messageId: uuid() }, bundle);
|
|
21446
|
+
// only log if cache is enabled
|
|
21447
|
+
client.log('user/createMessage.locally', bundleWithMessageId);
|
|
21448
|
+
const channel = pullFromCache(['channel', 'get', bundleWithMessageId.channelId]);
|
|
21449
|
+
upsertInCache(['channel', 'get', bundleWithMessageId.channelId], Object.assign(Object.assign({}, channel === null || channel === void 0 ? void 0 : channel.data), { messageCount: ((_a = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
|
|
21450
|
+
// as reused to update created and updated time, which should be the same
|
|
21451
|
+
const createdTime = new Date().toISOString();
|
|
21452
|
+
const message = Object.assign({ userId: client.userId, channelSegment: ((_b = channel === null || channel === void 0 ? void 0 : channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
|
|
21357
21453
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt: -1 });
|
|
21358
21454
|
fireEvent('v3.message.didCreate', { messages: [message] });
|
|
21359
21455
|
return {
|
|
@@ -22396,6 +22492,78 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
22396
22492
|
return deleted;
|
|
22397
22493
|
};
|
|
22398
22494
|
|
|
22495
|
+
/**
|
|
22496
|
+
* ```js
|
|
22497
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
22498
|
+
*
|
|
22499
|
+
* const { data: post } = await approvePost('postId')
|
|
22500
|
+
* ```
|
|
22501
|
+
*
|
|
22502
|
+
* Approves a {@link Amity.Post}
|
|
22503
|
+
*
|
|
22504
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
22505
|
+
* @return A {@link Amity.Post} that was approved
|
|
22506
|
+
*
|
|
22507
|
+
* @category Post API
|
|
22508
|
+
* @async
|
|
22509
|
+
*/
|
|
22510
|
+
const approvePost = async (postId) => {
|
|
22511
|
+
var _a;
|
|
22512
|
+
const client = getActiveClient();
|
|
22513
|
+
client.log('post/approvePost', postId);
|
|
22514
|
+
const { data: approved } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
22515
|
+
const cachedAt = client.cache && Date.now();
|
|
22516
|
+
if (client.cache)
|
|
22517
|
+
ingestInCache(approved, { cachedAt });
|
|
22518
|
+
// fire virtual event for community update
|
|
22519
|
+
if (approved.posts[0].targetType === 'community') {
|
|
22520
|
+
const community = (_a = approved.communities) === null || _a === void 0 ? void 0 : _a[0];
|
|
22521
|
+
// @ts-ignore as communities is optional currently in PostPayload
|
|
22522
|
+
fireEvent('community.updated', { communities: [community] });
|
|
22523
|
+
}
|
|
22524
|
+
fireEvent('post.approved', { posts: [approved.posts[0]] });
|
|
22525
|
+
return {
|
|
22526
|
+
data: approved.posts.find(post => post.postId === postId),
|
|
22527
|
+
cachedAt,
|
|
22528
|
+
};
|
|
22529
|
+
};
|
|
22530
|
+
|
|
22531
|
+
/**
|
|
22532
|
+
* ```js
|
|
22533
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
22534
|
+
*
|
|
22535
|
+
* const {data: post} = await declinePost('postId')
|
|
22536
|
+
* ```
|
|
22537
|
+
*
|
|
22538
|
+
* Declines a {@link Amity.Post}
|
|
22539
|
+
*
|
|
22540
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
22541
|
+
* @return A {@link Amity.Post} that was declined
|
|
22542
|
+
*
|
|
22543
|
+
* @category Post API
|
|
22544
|
+
* @async
|
|
22545
|
+
*/
|
|
22546
|
+
const declinePost = async (postId) => {
|
|
22547
|
+
var _a;
|
|
22548
|
+
const client = getActiveClient();
|
|
22549
|
+
client.log('post/declinePost', postId);
|
|
22550
|
+
const { data: declined } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
22551
|
+
const cachedAt = client.cache && Date.now();
|
|
22552
|
+
if (client.cache)
|
|
22553
|
+
ingestInCache(declined, { cachedAt });
|
|
22554
|
+
// fire virtual event
|
|
22555
|
+
if (declined.posts[0].targetType === 'community') {
|
|
22556
|
+
const community = (_a = declined.communities) === null || _a === void 0 ? void 0 : _a[0];
|
|
22557
|
+
// @ts-ignore as communities is optional currently in PostPayload
|
|
22558
|
+
fireEvent('community.updated', { communities: [community] });
|
|
22559
|
+
}
|
|
22560
|
+
fireEvent('post.declined', { posts: [declined.posts[0]] });
|
|
22561
|
+
return {
|
|
22562
|
+
data: declined.posts.find(post => post.postId === postId),
|
|
22563
|
+
cachedAt,
|
|
22564
|
+
};
|
|
22565
|
+
};
|
|
22566
|
+
|
|
22399
22567
|
/**
|
|
22400
22568
|
* ```js
|
|
22401
22569
|
* import { queryComments } from '@amityco/ts-sdk'
|
|
@@ -22414,6 +22582,10 @@ const queryComments = async (query) => {
|
|
|
22414
22582
|
const client = getActiveClient();
|
|
22415
22583
|
client.log('comment/queryComments', query);
|
|
22416
22584
|
const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
|
|
22585
|
+
const options = {
|
|
22586
|
+
type: params.sortBy ? 'pagination' : undefined,
|
|
22587
|
+
token: toToken(page, params.sortBy ? 'skiplimit' : 'afterbefore'),
|
|
22588
|
+
};
|
|
22417
22589
|
// const filterByParentId = query.parentId !== undefined
|
|
22418
22590
|
// API-FIX: parameters should be querystring. (1)
|
|
22419
22591
|
// API-FIX: backend should answer Amity.Response (2)
|
|
@@ -22421,9 +22593,7 @@ const queryComments = async (query) => {
|
|
|
22421
22593
|
const { data } = await client.http.get(`/api/v3/comments`, {
|
|
22422
22594
|
params: Object.assign(Object.assign({}, params), {
|
|
22423
22595
|
// filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
|
|
22424
|
-
options
|
|
22425
|
-
token: toToken(page, 'afterbefore'),
|
|
22426
|
-
} }),
|
|
22596
|
+
options }),
|
|
22427
22597
|
});
|
|
22428
22598
|
// API-FIX: backend should answer Amity.Response (2)
|
|
22429
22599
|
// const { paging, comments } = unwrapPayload(data)
|
|
@@ -22758,6 +22928,38 @@ const preparePayloadForCache = (event, payload) => {
|
|
|
22758
22928
|
}
|
|
22759
22929
|
};
|
|
22760
22930
|
|
|
22931
|
+
/** @hidden */
|
|
22932
|
+
/*
|
|
22933
|
+
* @param message payload from http request without myReactions
|
|
22934
|
+
* add myReactions to http response if the event was a reaction event
|
|
22935
|
+
*/
|
|
22936
|
+
const prepareMessagePayloadForCache = (payload) => {
|
|
22937
|
+
const client = getActiveClient();
|
|
22938
|
+
const cached = pullFromCache(['message', 'get', payload.messageId]);
|
|
22939
|
+
// '[]' in cases where the new reaction is the first one
|
|
22940
|
+
const myReactions = (cached === null || cached === void 0 ? void 0 : cached.data.myReactions) || [];
|
|
22941
|
+
// add myReactions to the payload
|
|
22942
|
+
Object.assign(payload, { myReactions });
|
|
22943
|
+
// check if there are any updates to the reactions
|
|
22944
|
+
const latestReaction = payload === null || payload === void 0 ? void 0 : payload.latestReaction;
|
|
22945
|
+
const isLatestReactionMine = latestReaction && latestReaction.userId === client.userId;
|
|
22946
|
+
if (!isLatestReactionMine) {
|
|
22947
|
+
return;
|
|
22948
|
+
}
|
|
22949
|
+
// new reaction added
|
|
22950
|
+
if (latestReaction.eventName === 'add' && !myReactions.includes(latestReaction.reactionName)) {
|
|
22951
|
+
Object.assign(payload, {
|
|
22952
|
+
myReactions: [...myReactions, latestReaction.reactionName],
|
|
22953
|
+
});
|
|
22954
|
+
}
|
|
22955
|
+
// existing reaction removed
|
|
22956
|
+
if (latestReaction.eventName === 'remove' && myReactions.includes(latestReaction.reactionName)) {
|
|
22957
|
+
Object.assign(payload, {
|
|
22958
|
+
myReactions: myReactions.filter(x => x !== latestReaction.reactionName),
|
|
22959
|
+
});
|
|
22960
|
+
}
|
|
22961
|
+
};
|
|
22962
|
+
|
|
22761
22963
|
/**
|
|
22762
22964
|
* ```js
|
|
22763
22965
|
* import { addReaction } from '@amityco/ts-sdk'
|
|
@@ -23414,7 +23616,9 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
23414
23616
|
const client = getActiveClient();
|
|
23415
23617
|
client.log('report/createReport', { referenceType, referenceId });
|
|
23416
23618
|
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
23417
|
-
const { data } = await client.http.post(`/api
|
|
23619
|
+
const { data } = await client.http.post(`/api/${referenceType === 'user'
|
|
23620
|
+
? `v4/me/flags/${encodeURIComponent(referenceId)}`
|
|
23621
|
+
: `v3/${domainName}/${encodeURIComponent(referenceId)}/flag`}`);
|
|
23418
23622
|
if (client.cache)
|
|
23419
23623
|
ingestInCache(data);
|
|
23420
23624
|
const event = referenceType === 'message'
|
|
@@ -23441,7 +23645,9 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
23441
23645
|
const client = getActiveClient();
|
|
23442
23646
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
23443
23647
|
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
23444
|
-
const { data } = await client.http.delete(`/api
|
|
23648
|
+
const { data } = await client.http.delete(`/api/${referenceType === 'user'
|
|
23649
|
+
? `v4/me/flags/${encodeURIComponent(referenceId)}`
|
|
23650
|
+
: `v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`}`);
|
|
23445
23651
|
if (client.cache)
|
|
23446
23652
|
ingestInCache(data);
|
|
23447
23653
|
const event = referenceType === 'message'
|
|
@@ -23806,9 +24012,9 @@ const leaveChannel = async (channelId) => {
|
|
|
23806
24012
|
const queryChannelMembers = async (query) => {
|
|
23807
24013
|
const client = getActiveClient();
|
|
23808
24014
|
client.log('channel/queryChannelMembers', query);
|
|
23809
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page, channelId
|
|
23810
|
-
const { data } = await client.http.get(`/api/
|
|
23811
|
-
params: Object.assign(Object.assign({}, params), {
|
|
24015
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
|
|
24016
|
+
const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24017
|
+
params: Object.assign(Object.assign({}, params), { options: {
|
|
23812
24018
|
token: toToken(page, 'skiplimit'),
|
|
23813
24019
|
} }),
|
|
23814
24020
|
});
|
|
@@ -24179,7 +24385,12 @@ const onMessageUpdated = (callback) => {
|
|
|
24179
24385
|
const client = getActiveClient();
|
|
24180
24386
|
const filter = (payload) => {
|
|
24181
24387
|
ingestInCache(payload);
|
|
24182
|
-
|
|
24388
|
+
const message = payload.messages[0];
|
|
24389
|
+
// if payload does not have myReactions
|
|
24390
|
+
if (!(message === null || message === void 0 ? void 0 : message.myReactions)) {
|
|
24391
|
+
prepareMessagePayloadForCache(message);
|
|
24392
|
+
}
|
|
24393
|
+
callback(message);
|
|
24183
24394
|
};
|
|
24184
24395
|
return createEventSubscriber(client, 'message/onMessageUpdated', 'v3.message.didUpdate', filter);
|
|
24185
24396
|
};
|
|
@@ -25615,6 +25826,7 @@ const closePoll = async (pollId) => {
|
|
|
25615
25826
|
const cachedAt = client.cache && Date.now();
|
|
25616
25827
|
if (client.cache)
|
|
25617
25828
|
ingestInCache(data, { cachedAt });
|
|
25829
|
+
fireEvent('poll.updated', data);
|
|
25618
25830
|
const { polls } = data;
|
|
25619
25831
|
return {
|
|
25620
25832
|
data: polls.find(poll => poll.pollId === pollId),
|
|
@@ -25645,6 +25857,7 @@ const deletePoll = async (pollId) => {
|
|
|
25645
25857
|
const { success } = data; // unwrapPayload(data)
|
|
25646
25858
|
const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
|
|
25647
25859
|
upsertInCache(['poll', 'get', pollId], deleted);
|
|
25860
|
+
fireEvent('poll.deleted', { polls: [deleted], users: [] });
|
|
25648
25861
|
return success;
|
|
25649
25862
|
};
|
|
25650
25863
|
|
|
@@ -25671,12 +25884,107 @@ const votePoll = async (pollId, answerIds) => {
|
|
|
25671
25884
|
if (client.cache)
|
|
25672
25885
|
ingestInCache(data, { cachedAt });
|
|
25673
25886
|
const { polls } = data;
|
|
25887
|
+
fireEvent('poll.updated', data);
|
|
25674
25888
|
return {
|
|
25675
25889
|
data: polls.find(poll => poll.pollId === pollId),
|
|
25676
25890
|
cachedAt,
|
|
25677
25891
|
};
|
|
25678
25892
|
};
|
|
25679
25893
|
|
|
25894
|
+
/**
|
|
25895
|
+
* ```js
|
|
25896
|
+
* import { onPollUpdated } from '@amityco/ts-sdk'
|
|
25897
|
+
* const dispose = onPollUpdated(poll => {
|
|
25898
|
+
* // ...
|
|
25899
|
+
* })
|
|
25900
|
+
* ```
|
|
25901
|
+
*
|
|
25902
|
+
* Fired when an {@link Amity.Poll} has been updated
|
|
25903
|
+
*
|
|
25904
|
+
* @param callback The function to call when the event was fired
|
|
25905
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25906
|
+
*
|
|
25907
|
+
* @category Poll Events
|
|
25908
|
+
*/
|
|
25909
|
+
const onPollUpdated = (callback) => {
|
|
25910
|
+
const client = getActiveClient();
|
|
25911
|
+
const filter = (payload) => {
|
|
25912
|
+
if (client.cache)
|
|
25913
|
+
ingestInCache(payload);
|
|
25914
|
+
callback(payload.polls[0]);
|
|
25915
|
+
};
|
|
25916
|
+
return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
|
|
25917
|
+
};
|
|
25918
|
+
|
|
25919
|
+
/**
|
|
25920
|
+
* ```js
|
|
25921
|
+
* import { onPollDeleted } from '@amityco/ts-sdk'
|
|
25922
|
+
* const dispose = onPollDeleted(poll => {
|
|
25923
|
+
* // ...
|
|
25924
|
+
* })
|
|
25925
|
+
* ```
|
|
25926
|
+
*
|
|
25927
|
+
* Fired when an {@link Amity.Poll} has been deleted
|
|
25928
|
+
*
|
|
25929
|
+
* @param callback The function to call when the event was fired
|
|
25930
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25931
|
+
*
|
|
25932
|
+
* @category Poll Events
|
|
25933
|
+
*/
|
|
25934
|
+
const onPollDeleted = (callback) => {
|
|
25935
|
+
const client = getActiveClient();
|
|
25936
|
+
const filter = (payload) => {
|
|
25937
|
+
if (client.cache)
|
|
25938
|
+
ingestInCache(payload);
|
|
25939
|
+
callback(payload.polls[0]);
|
|
25940
|
+
};
|
|
25941
|
+
return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
|
|
25942
|
+
};
|
|
25943
|
+
|
|
25944
|
+
/**
|
|
25945
|
+
* ```js
|
|
25946
|
+
* import { observePoll } from '@amityco/ts-sdk'
|
|
25947
|
+
*
|
|
25948
|
+
* let poll = {}
|
|
25949
|
+
* const dispose = observePoll(pollId, updated => poll = updated)
|
|
25950
|
+
* ```
|
|
25951
|
+
*
|
|
25952
|
+
* Observe all mutation on a given {@link Amity.Poll}
|
|
25953
|
+
*
|
|
25954
|
+
* @param pollId the ID of the poll to observe
|
|
25955
|
+
* @param callback the function to call when new data are available
|
|
25956
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
|
|
25957
|
+
*
|
|
25958
|
+
* @category Poll Observer
|
|
25959
|
+
*/
|
|
25960
|
+
const observePoll = (pollId, callback, policy = 'cache_then_server') => {
|
|
25961
|
+
const { log } = getActiveClient();
|
|
25962
|
+
const timestamp = Date.now();
|
|
25963
|
+
log(`observePoll(tmpid: ${timestamp}) > listen`);
|
|
25964
|
+
// wrapper function to make sure
|
|
25965
|
+
const router = (result, action) => {
|
|
25966
|
+
var _a, _b;
|
|
25967
|
+
if (callback instanceof Function)
|
|
25968
|
+
return callback(result);
|
|
25969
|
+
if (action !== 'onFetch')
|
|
25970
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
25971
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
25972
|
+
};
|
|
25973
|
+
const realtimeRouter = (result, action) => {
|
|
25974
|
+
var _a;
|
|
25975
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.pollId) !== pollId)
|
|
25976
|
+
return;
|
|
25977
|
+
router(result, action);
|
|
25978
|
+
};
|
|
25979
|
+
const disposers = [];
|
|
25980
|
+
disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
|
|
25981
|
+
runQuery(createQuery(getPoll, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
25982
|
+
return () => {
|
|
25983
|
+
log(`observePoll(tmpid: ${timestamp}) > dispose`);
|
|
25984
|
+
disposers.forEach(fn => fn());
|
|
25985
|
+
};
|
|
25986
|
+
};
|
|
25987
|
+
|
|
25680
25988
|
/**
|
|
25681
25989
|
* ```js
|
|
25682
25990
|
* import { getStream } from '@amityco/ts-sdk'
|
|
@@ -25992,4 +26300,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
25992
26300
|
return { accessToken: data.accessToken };
|
|
25993
26301
|
};
|
|
25994
26302
|
|
|
25995
|
-
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
|
|
26303
|
+
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
|