@amityco/ts-sdk 7.20.0 → 7.20.1-0c91c8e.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/comment.d.ts +3 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/commentRepository/api/createComment.d.ts +3 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/index.cjs.js +126 -45
- package/dist/index.esm.js +126 -45
- package/dist/index.umd.js +3 -3
- package/dist/utils/tests/dummy/comment.d.ts +1 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,9 @@ declare global {
|
|
|
18
18
|
targetType: 'community' | 'user' | 'content';
|
|
19
19
|
links?: Amity.Link[];
|
|
20
20
|
} & Amity.Relationship<CommentReferenceType> & Amity.Content<T> & Amity.Metadata & Amity.Flaggable & Amity.Reactable & Amity.Timestamps & Amity.SoftDelete & Amity.Subscribable & Amity.Mentionable<'user'>;
|
|
21
|
-
type InternalComment<T extends CommentContentType = any> = RawComment<T
|
|
21
|
+
type InternalComment<T extends CommentContentType = any> = RawComment<T> & {
|
|
22
|
+
syncState?: Amity.SyncState;
|
|
23
|
+
};
|
|
22
24
|
type CommentTarget = {
|
|
23
25
|
type: InternalComment['targetType'] | 'unknown';
|
|
24
26
|
communityId?: Amity.Community['communityId'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,kBAAkB,GAAG,MAAM,CAAC;QACjC,KAAK,oBAAoB,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;QAEzD,KAAK,iBAAiB,GAClB,SAAS,GACT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,oBAAoB,CACrD,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG;YACvC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC;SACzC,CACF,CAAC;QAEF,KAAK,0BAA0B,GAAG,KAAK,CAAC,mBAAmB,CACzD,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,EAClC;YAAE,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CACnD,CAAC;KACH;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare type CreateCommentBundle = Pick<Amity.Comment<Amity.CommentContentType>, 'data' | 'referenceType' | 'referenceId' | 'parentId' | 'metadata' | 'mentionees' | 'attachments' | 'links'>;
|
|
1
2
|
/**
|
|
2
3
|
* ```js
|
|
3
4
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
@@ -12,5 +13,6 @@
|
|
|
12
13
|
* @category Comment API
|
|
13
14
|
* @async
|
|
14
15
|
*/
|
|
15
|
-
export declare const createComment: (bundle:
|
|
16
|
+
export declare const createComment: (bundle: CreateCommentBundle) => Promise<Amity.Cached<Amity.Comment>>;
|
|
17
|
+
export {};
|
|
16
18
|
//# sourceMappingURL=createComment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/createComment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/createComment.ts"],"names":[],"mappings":"AAkBA,aAAK,mBAAmB,GAAG,IAAI,CAC7B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,EACrC,MAAM,GACN,eAAe,GACf,aAAa,GACb,UAAU,GACV,UAAU,GACV,YAAY,GACZ,aAAa,GACb,OAAO,CACV,CAAC;AA+DF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,WAChB,mBAAmB,KAC1B,QAAQ,MAAM,MAAM,CAAC,aAAa,CAAC,CAmFrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/deleteComment.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,0BAEpC,QAAQ,aAAa,
|
|
1
|
+
{"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/api/deleteComment.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,0BAEpC,QAAQ,aAAa,CAoFvB,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -13232,7 +13232,7 @@ const getWatchSessionStorage = () => {
|
|
|
13232
13232
|
return storageInstance;
|
|
13233
13233
|
};
|
|
13234
13234
|
|
|
13235
|
-
const privateKey = "
|
|
13235
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9D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jtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
13236
13236
|
/*
|
|
13237
13237
|
* The crypto algorithm used for importing key and signing string
|
|
13238
13238
|
*/
|
|
@@ -25980,9 +25980,55 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
25980
25980
|
};
|
|
25981
25981
|
};
|
|
25982
25982
|
|
|
25983
|
-
|
|
25984
|
-
|
|
25985
|
-
|
|
25983
|
+
const getLocalCommentId = () => uuid();
|
|
25984
|
+
const createCommentOptimistic = (bundle) => {
|
|
25985
|
+
const client = getActiveClient();
|
|
25986
|
+
if (!client.cache)
|
|
25987
|
+
return;
|
|
25988
|
+
const commentId = getLocalCommentId();
|
|
25989
|
+
client.log('comment/createComment.optimistically', Object.assign({ commentId }, bundle));
|
|
25990
|
+
const createdTime = new Date().toISOString();
|
|
25991
|
+
const comment = {
|
|
25992
|
+
commentId,
|
|
25993
|
+
userId: client.userId,
|
|
25994
|
+
parentId: bundle.parentId,
|
|
25995
|
+
rootId: bundle.parentId || commentId,
|
|
25996
|
+
childrenNumber: 0,
|
|
25997
|
+
children: [],
|
|
25998
|
+
segmentNumber: 0,
|
|
25999
|
+
editedAt: createdTime,
|
|
26000
|
+
referenceId: bundle.referenceId,
|
|
26001
|
+
referenceType: bundle.referenceType,
|
|
26002
|
+
data: bundle.data,
|
|
26003
|
+
metadata: bundle.metadata,
|
|
26004
|
+
mentionees: bundle.mentionees,
|
|
26005
|
+
attachments: bundle.attachments,
|
|
26006
|
+
links: bundle.links,
|
|
26007
|
+
createdAt: createdTime,
|
|
26008
|
+
updatedAt: createdTime,
|
|
26009
|
+
isDeleted: false,
|
|
26010
|
+
flagCount: 0,
|
|
26011
|
+
hashFlag: null,
|
|
26012
|
+
reactions: {},
|
|
26013
|
+
reactionsCount: 0,
|
|
26014
|
+
myReactions: [],
|
|
26015
|
+
path: '',
|
|
26016
|
+
targetId: '',
|
|
26017
|
+
targetType: 'community',
|
|
26018
|
+
dataType: 'text',
|
|
26019
|
+
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
26020
|
+
};
|
|
26021
|
+
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
26022
|
+
pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
|
|
26023
|
+
fireEvent('local.comment.created', {
|
|
26024
|
+
comments: [comment],
|
|
26025
|
+
commentChildren: [],
|
|
26026
|
+
users: [],
|
|
26027
|
+
files: [],
|
|
26028
|
+
communityUsers: [],
|
|
26029
|
+
});
|
|
26030
|
+
return comment;
|
|
26031
|
+
};
|
|
25986
26032
|
/**
|
|
25987
26033
|
* ```js
|
|
25988
26034
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
@@ -26000,48 +26046,70 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
26000
26046
|
const createComment = async (bundle) => {
|
|
26001
26047
|
const client = getActiveClient();
|
|
26002
26048
|
client.log('comment/createComment', bundle);
|
|
26003
|
-
const
|
|
26004
|
-
const
|
|
26005
|
-
|
|
26006
|
-
|
|
26007
|
-
|
|
26008
|
-
|
|
26009
|
-
|
|
26010
|
-
|
|
26011
|
-
|
|
26012
|
-
|
|
26013
|
-
|
|
26014
|
-
|
|
26015
|
-
|
|
26016
|
-
|
|
26017
|
-
|
|
26018
|
-
|
|
26019
|
-
|
|
26020
|
-
|
|
26021
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
26022
|
-
'get',
|
|
26023
|
-
storyIndex.data,
|
|
26049
|
+
const optimisticData = createCommentOptimistic(bundle);
|
|
26050
|
+
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
26051
|
+
try {
|
|
26052
|
+
const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
26053
|
+
const { comments } = data;
|
|
26054
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
26055
|
+
if (comments.length === 0)
|
|
26056
|
+
throw new Error('Comment not created');
|
|
26057
|
+
const cachedAt = client.cache && Date.now();
|
|
26058
|
+
if (client.cache)
|
|
26059
|
+
ingestInCache(data, { cachedAt });
|
|
26060
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
26061
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
|
|
26062
|
+
}
|
|
26063
|
+
else if (bundle.referenceType === 'story') {
|
|
26064
|
+
const storyIndex = pullFromCache([
|
|
26065
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
26066
|
+
bundle.referenceId,
|
|
26024
26067
|
]);
|
|
26025
|
-
if (
|
|
26026
|
-
|
|
26027
|
-
|
|
26028
|
-
|
|
26029
|
-
|
|
26030
|
-
|
|
26031
|
-
|
|
26032
|
-
|
|
26033
|
-
|
|
26034
|
-
|
|
26035
|
-
|
|
26036
|
-
|
|
26068
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
26069
|
+
const cacheStory = pullFromCache([
|
|
26070
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
26071
|
+
'get',
|
|
26072
|
+
storyIndex.data,
|
|
26073
|
+
]);
|
|
26074
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
26075
|
+
fireEvent('story.updated', {
|
|
26076
|
+
stories: [
|
|
26077
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
26078
|
+
],
|
|
26079
|
+
categories: [],
|
|
26080
|
+
comments,
|
|
26081
|
+
communities: [],
|
|
26082
|
+
communityUsers: data.communityUsers,
|
|
26083
|
+
files: data.files,
|
|
26084
|
+
users: data.users,
|
|
26085
|
+
});
|
|
26086
|
+
}
|
|
26037
26087
|
}
|
|
26038
26088
|
}
|
|
26089
|
+
fireEvent('local.comment.created', {
|
|
26090
|
+
comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
26091
|
+
commentChildren: data.commentChildren,
|
|
26092
|
+
users: data.users,
|
|
26093
|
+
files: data.files,
|
|
26094
|
+
communityUsers: data.communityUsers,
|
|
26095
|
+
});
|
|
26096
|
+
return {
|
|
26097
|
+
data: LinkedObject.comment(comments[0]),
|
|
26098
|
+
cachedAt,
|
|
26099
|
+
};
|
|
26100
|
+
}
|
|
26101
|
+
catch (e) {
|
|
26102
|
+
if (optimisticData) {
|
|
26103
|
+
fireEvent('local.comment.created', {
|
|
26104
|
+
comments: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
|
|
26105
|
+
commentChildren: [],
|
|
26106
|
+
users: [],
|
|
26107
|
+
files: [],
|
|
26108
|
+
communityUsers: [],
|
|
26109
|
+
});
|
|
26110
|
+
}
|
|
26111
|
+
throw e;
|
|
26039
26112
|
}
|
|
26040
|
-
fireEvent('local.comment.created', data);
|
|
26041
|
-
return {
|
|
26042
|
-
data: LinkedObject.comment(comments[0]),
|
|
26043
|
-
cachedAt,
|
|
26044
|
-
};
|
|
26045
26113
|
};
|
|
26046
26114
|
/* end_public_function */
|
|
26047
26115
|
|
|
@@ -26168,8 +26236,21 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
26168
26236
|
* @async
|
|
26169
26237
|
*/
|
|
26170
26238
|
const deleteComment = async (commentId, permanent = false) => {
|
|
26171
|
-
var _a, _b;
|
|
26239
|
+
var _a, _b, _c;
|
|
26172
26240
|
const client = getActiveClient();
|
|
26241
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26242
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.syncState) === "error" /* Amity.SyncState.Error */) {
|
|
26243
|
+
const deletedComment = Object.assign(Object.assign({}, cached), { isDeleted: true });
|
|
26244
|
+
dropFromCache(['comment', 'get', commentId]);
|
|
26245
|
+
fireEvent('local.comment.deleted', {
|
|
26246
|
+
comments: [deletedComment],
|
|
26247
|
+
commentChildren: [],
|
|
26248
|
+
files: [],
|
|
26249
|
+
users: [],
|
|
26250
|
+
communityUsers: [],
|
|
26251
|
+
});
|
|
26252
|
+
return deletedComment;
|
|
26253
|
+
}
|
|
26173
26254
|
const comment = await getComment$2(commentId);
|
|
26174
26255
|
// API-FIX: This endpoint has not been implemented yet.
|
|
26175
26256
|
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
@@ -26199,11 +26280,11 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
26199
26280
|
});
|
|
26200
26281
|
}
|
|
26201
26282
|
else {
|
|
26202
|
-
const post = (
|
|
26283
|
+
const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26203
26284
|
if (post) {
|
|
26204
26285
|
const engine = PostCommentCountEngine$1.getInstance();
|
|
26205
26286
|
engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
|
|
26206
|
-
if (!deleted.parentId && ((
|
|
26287
|
+
if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
26207
26288
|
// NOTE: delete the parent comment will also remove all children comments
|
|
26208
26289
|
deleted.children.forEach((childCommentId) => {
|
|
26209
26290
|
engine.queueCommentChangeTask(new DeleteTask(post.postId, childCommentId));
|
package/dist/index.esm.js
CHANGED
|
@@ -29324,7 +29324,7 @@ const getWatchSessionStorage = () => {
|
|
|
29324
29324
|
return storageInstance;
|
|
29325
29325
|
};
|
|
29326
29326
|
|
|
29327
|
-
const privateKey = "
|
|
29327
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5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R8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
29328
29328
|
/*
|
|
29329
29329
|
* The crypto algorithm used for importing key and signing string
|
|
29330
29330
|
*/
|
|
@@ -42072,9 +42072,55 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
42072
42072
|
};
|
|
42073
42073
|
};
|
|
42074
42074
|
|
|
42075
|
-
|
|
42076
|
-
|
|
42077
|
-
|
|
42075
|
+
const getLocalCommentId = () => uuid();
|
|
42076
|
+
const createCommentOptimistic = (bundle) => {
|
|
42077
|
+
const client = getActiveClient();
|
|
42078
|
+
if (!client.cache)
|
|
42079
|
+
return;
|
|
42080
|
+
const commentId = getLocalCommentId();
|
|
42081
|
+
client.log('comment/createComment.optimistically', Object.assign({ commentId }, bundle));
|
|
42082
|
+
const createdTime = new Date().toISOString();
|
|
42083
|
+
const comment = {
|
|
42084
|
+
commentId,
|
|
42085
|
+
userId: client.userId,
|
|
42086
|
+
parentId: bundle.parentId,
|
|
42087
|
+
rootId: bundle.parentId || commentId,
|
|
42088
|
+
childrenNumber: 0,
|
|
42089
|
+
children: [],
|
|
42090
|
+
segmentNumber: 0,
|
|
42091
|
+
editedAt: createdTime,
|
|
42092
|
+
referenceId: bundle.referenceId,
|
|
42093
|
+
referenceType: bundle.referenceType,
|
|
42094
|
+
data: bundle.data,
|
|
42095
|
+
metadata: bundle.metadata,
|
|
42096
|
+
mentionees: bundle.mentionees,
|
|
42097
|
+
attachments: bundle.attachments,
|
|
42098
|
+
links: bundle.links,
|
|
42099
|
+
createdAt: createdTime,
|
|
42100
|
+
updatedAt: createdTime,
|
|
42101
|
+
isDeleted: false,
|
|
42102
|
+
flagCount: 0,
|
|
42103
|
+
hashFlag: null,
|
|
42104
|
+
reactions: {},
|
|
42105
|
+
reactionsCount: 0,
|
|
42106
|
+
myReactions: [],
|
|
42107
|
+
path: '',
|
|
42108
|
+
targetId: '',
|
|
42109
|
+
targetType: 'community',
|
|
42110
|
+
dataType: 'text',
|
|
42111
|
+
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
42112
|
+
};
|
|
42113
|
+
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
42114
|
+
pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
|
|
42115
|
+
fireEvent('local.comment.created', {
|
|
42116
|
+
comments: [comment],
|
|
42117
|
+
commentChildren: [],
|
|
42118
|
+
users: [],
|
|
42119
|
+
files: [],
|
|
42120
|
+
communityUsers: [],
|
|
42121
|
+
});
|
|
42122
|
+
return comment;
|
|
42123
|
+
};
|
|
42078
42124
|
/**
|
|
42079
42125
|
* ```js
|
|
42080
42126
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
@@ -42092,48 +42138,70 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
42092
42138
|
const createComment = async (bundle) => {
|
|
42093
42139
|
const client = getActiveClient();
|
|
42094
42140
|
client.log('comment/createComment', bundle);
|
|
42095
|
-
const
|
|
42096
|
-
const
|
|
42097
|
-
|
|
42098
|
-
|
|
42099
|
-
|
|
42100
|
-
|
|
42101
|
-
|
|
42102
|
-
|
|
42103
|
-
|
|
42104
|
-
|
|
42105
|
-
|
|
42106
|
-
|
|
42107
|
-
|
|
42108
|
-
|
|
42109
|
-
|
|
42110
|
-
|
|
42111
|
-
|
|
42112
|
-
|
|
42113
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
42114
|
-
'get',
|
|
42115
|
-
storyIndex.data,
|
|
42141
|
+
const optimisticData = createCommentOptimistic(bundle);
|
|
42142
|
+
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
42143
|
+
try {
|
|
42144
|
+
const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
42145
|
+
const { comments } = data;
|
|
42146
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
42147
|
+
if (comments.length === 0)
|
|
42148
|
+
throw new Error('Comment not created');
|
|
42149
|
+
const cachedAt = client.cache && Date.now();
|
|
42150
|
+
if (client.cache)
|
|
42151
|
+
ingestInCache(data, { cachedAt });
|
|
42152
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
42153
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
|
|
42154
|
+
}
|
|
42155
|
+
else if (bundle.referenceType === 'story') {
|
|
42156
|
+
const storyIndex = pullFromCache([
|
|
42157
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
42158
|
+
bundle.referenceId,
|
|
42116
42159
|
]);
|
|
42117
|
-
if (
|
|
42118
|
-
|
|
42119
|
-
|
|
42120
|
-
|
|
42121
|
-
|
|
42122
|
-
|
|
42123
|
-
|
|
42124
|
-
|
|
42125
|
-
|
|
42126
|
-
|
|
42127
|
-
|
|
42128
|
-
|
|
42160
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
42161
|
+
const cacheStory = pullFromCache([
|
|
42162
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
42163
|
+
'get',
|
|
42164
|
+
storyIndex.data,
|
|
42165
|
+
]);
|
|
42166
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
42167
|
+
fireEvent('story.updated', {
|
|
42168
|
+
stories: [
|
|
42169
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
42170
|
+
],
|
|
42171
|
+
categories: [],
|
|
42172
|
+
comments,
|
|
42173
|
+
communities: [],
|
|
42174
|
+
communityUsers: data.communityUsers,
|
|
42175
|
+
files: data.files,
|
|
42176
|
+
users: data.users,
|
|
42177
|
+
});
|
|
42178
|
+
}
|
|
42129
42179
|
}
|
|
42130
42180
|
}
|
|
42181
|
+
fireEvent('local.comment.created', {
|
|
42182
|
+
comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
42183
|
+
commentChildren: data.commentChildren,
|
|
42184
|
+
users: data.users,
|
|
42185
|
+
files: data.files,
|
|
42186
|
+
communityUsers: data.communityUsers,
|
|
42187
|
+
});
|
|
42188
|
+
return {
|
|
42189
|
+
data: LinkedObject.comment(comments[0]),
|
|
42190
|
+
cachedAt,
|
|
42191
|
+
};
|
|
42192
|
+
}
|
|
42193
|
+
catch (e) {
|
|
42194
|
+
if (optimisticData) {
|
|
42195
|
+
fireEvent('local.comment.created', {
|
|
42196
|
+
comments: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
|
|
42197
|
+
commentChildren: [],
|
|
42198
|
+
users: [],
|
|
42199
|
+
files: [],
|
|
42200
|
+
communityUsers: [],
|
|
42201
|
+
});
|
|
42202
|
+
}
|
|
42203
|
+
throw e;
|
|
42131
42204
|
}
|
|
42132
|
-
fireEvent('local.comment.created', data);
|
|
42133
|
-
return {
|
|
42134
|
-
data: LinkedObject.comment(comments[0]),
|
|
42135
|
-
cachedAt,
|
|
42136
|
-
};
|
|
42137
42205
|
};
|
|
42138
42206
|
/* end_public_function */
|
|
42139
42207
|
|
|
@@ -42260,8 +42328,21 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
42260
42328
|
* @async
|
|
42261
42329
|
*/
|
|
42262
42330
|
const deleteComment = async (commentId, permanent = false) => {
|
|
42263
|
-
var _a, _b;
|
|
42331
|
+
var _a, _b, _c;
|
|
42264
42332
|
const client = getActiveClient();
|
|
42333
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
42334
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.syncState) === "error" /* Amity.SyncState.Error */) {
|
|
42335
|
+
const deletedComment = Object.assign(Object.assign({}, cached), { isDeleted: true });
|
|
42336
|
+
dropFromCache(['comment', 'get', commentId]);
|
|
42337
|
+
fireEvent('local.comment.deleted', {
|
|
42338
|
+
comments: [deletedComment],
|
|
42339
|
+
commentChildren: [],
|
|
42340
|
+
files: [],
|
|
42341
|
+
users: [],
|
|
42342
|
+
communityUsers: [],
|
|
42343
|
+
});
|
|
42344
|
+
return deletedComment;
|
|
42345
|
+
}
|
|
42265
42346
|
const comment = await getComment$2(commentId);
|
|
42266
42347
|
// API-FIX: This endpoint has not been implemented yet.
|
|
42267
42348
|
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
@@ -42291,11 +42372,11 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
42291
42372
|
});
|
|
42292
42373
|
}
|
|
42293
42374
|
else {
|
|
42294
|
-
const post = (
|
|
42375
|
+
const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
42295
42376
|
if (post) {
|
|
42296
42377
|
const engine = PostCommentCountEngine$1.getInstance();
|
|
42297
42378
|
engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
|
|
42298
|
-
if (!deleted.parentId && ((
|
|
42379
|
+
if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
42299
42380
|
// NOTE: delete the parent comment will also remove all children comments
|
|
42300
42381
|
deleted.children.forEach((childCommentId) => {
|
|
42301
42382
|
engine.queueCommentChangeTask(new DeleteTask(post.postId, childCommentId));
|