@amityco/ts-sdk 6.4.2 → 6.4.3-9741e51.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/commentRepository/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/index.cjs.js +36 -39
- package/dist/index.esm.js +36 -39
- package/dist/index.umd.js +1 -1
- package/dist/postRepository/events/onPostReactionAdded.d.ts.map +1 -1
- package/dist/postRepository/events/onPostReactionRemoved.d.ts.map +1 -1
- package/dist/reactionRepository/utils/index.d.ts +1 -1
- package/dist/reactionRepository/utils/index.d.ts.map +1 -1
- package/dist/reactionRepository/utils/prepareReactionPayloadFormEvent.d.ts +3 -0
- package/dist/reactionRepository/utils/prepareReactionPayloadFormEvent.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/commentRepository/events/onCommentReactionAdded.ts +3 -4
- package/src/commentRepository/events/onCommentReactionRemoved.ts +3 -4
- package/src/postRepository/events/onPostReactionAdded.ts +3 -4
- package/src/postRepository/events/onPostReactionRemoved.ts +3 -4
- package/src/postRepository/events/tests/onPostReactionAdded.test.ts +1 -1
- package/src/reactionRepository/utils/index.ts +1 -1
- package/src/reactionRepository/utils/prepareReactionPayloadFormEvent.ts +62 -0
- package/dist/reactionRepository/utils/preparePayloadForCache.d.ts +0 -3
- package/dist/reactionRepository/utils/preparePayloadForCache.d.ts.map +0 -1
- package/src/reactionRepository/utils/preparePayloadForCache.ts +0 -53
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onCommentReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionAdded.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,aACvB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,
|
|
1
|
+
{"version":3,"file":"onCommentReactionAdded.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionAdded.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB,aACvB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,YAuBR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onCommentReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionRemoved.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,aACzB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,
|
|
1
|
+
{"version":3,"file":"onCommentReactionRemoved.d.ts","sourceRoot":"","sources":["../../../src/commentRepository/events/onCommentReactionRemoved.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,aACzB,MAAM,QAAQ,CAAC,aAAa,CAAC,KACtC,MAAM,YAuBR,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -26885,42 +26885,43 @@ getComment$1.locally = (commentId) => {
|
|
|
26885
26885
|
};
|
|
26886
26886
|
};
|
|
26887
26887
|
|
|
26888
|
-
|
|
26889
|
-
const preparePayloadForCache = (event, payload) => {
|
|
26888
|
+
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
26890
26889
|
var _a, _b;
|
|
26891
|
-
|
|
26892
|
-
if (
|
|
26893
|
-
|
|
26890
|
+
let id;
|
|
26891
|
+
if (eventPrefix === 'post') {
|
|
26892
|
+
id = payload.posts[0].postId;
|
|
26894
26893
|
}
|
|
26895
|
-
|
|
26896
|
-
|
|
26897
|
-
if (event === 'post.addReaction' || event === 'post.removeReaction') {
|
|
26898
|
-
const post = payload.posts[0];
|
|
26899
|
-
cached = (_a = pullFromCache(['post', 'get', post.postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26900
|
-
model = post;
|
|
26894
|
+
else if (eventPrefix === 'comment') {
|
|
26895
|
+
id = payload.comments[0].commentId;
|
|
26901
26896
|
}
|
|
26902
26897
|
else {
|
|
26903
|
-
|
|
26904
|
-
cached = (_b = pullFromCache(['comment', 'get', comment.commentId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26905
|
-
model = comment;
|
|
26898
|
+
throw new Error(`Unknown event type`);
|
|
26906
26899
|
}
|
|
26907
|
-
|
|
26908
|
-
|
|
26900
|
+
return ((_b = (_a = pullFromCache(['comment', 'get', id])) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.myReactions) || [];
|
|
26901
|
+
};
|
|
26902
|
+
const rebuildPayload = (payload, payloadKey, myReactions) => {
|
|
26903
|
+
const [model] = payload[payloadKey];
|
|
26904
|
+
return Object.assign(Object.assign({}, payload), { [payloadKey]: [Object.assign(Object.assign({}, model), { myReactions })] });
|
|
26905
|
+
};
|
|
26906
|
+
/** @hidden */
|
|
26907
|
+
const prepareReactionPayloadFormEvent = (event, payload) => {
|
|
26908
|
+
if (getActiveClient().userId !== payload.reactor.userId) {
|
|
26909
|
+
return payload;
|
|
26909
26910
|
}
|
|
26910
|
-
|
|
26911
|
-
|
|
26912
|
-
|
|
26913
|
-
|
|
26914
|
-
|
|
26911
|
+
const eventPrefix = event.split('.')[0]; // 'post' | 'comment'
|
|
26912
|
+
const eventSuffix = event.split('.')[1]; // 'addReaction' | 'removeReaction'
|
|
26913
|
+
let myReactions;
|
|
26914
|
+
const cachedMyReactions = getMyReactionsInCache(payload, eventPrefix);
|
|
26915
|
+
if (eventSuffix === 'addReaction') {
|
|
26916
|
+
myReactions = [...cachedMyReactions, payload.reactor.reactionName];
|
|
26917
|
+
}
|
|
26918
|
+
else if (eventSuffix === 'removeReaction') {
|
|
26919
|
+
myReactions = cachedMyReactions.filter(reaction => reaction !== payload.reactor.reactionName);
|
|
26915
26920
|
}
|
|
26916
26921
|
else {
|
|
26917
|
-
|
|
26918
|
-
return;
|
|
26919
|
-
}
|
|
26920
|
-
Object.assign(model, {
|
|
26921
|
-
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
26922
|
-
});
|
|
26922
|
+
throw new Error(`Unknown event type`);
|
|
26923
26923
|
}
|
|
26924
|
+
return rebuildPayload(payload, `${eventPrefix}s`, myReactions);
|
|
26924
26925
|
};
|
|
26925
26926
|
|
|
26926
26927
|
/* begin_public_function
|
|
@@ -27270,9 +27271,8 @@ const onPostReactionAdded = (callback) => {
|
|
|
27270
27271
|
callback(payload.posts[0]);
|
|
27271
27272
|
}
|
|
27272
27273
|
else {
|
|
27273
|
-
|
|
27274
|
-
|
|
27275
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27274
|
+
const processed = prepareReactionPayloadFormEvent('post.addReaction', payload);
|
|
27275
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27276
27276
|
ingestInCache(postPayload);
|
|
27277
27277
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27278
27278
|
callback(post.data);
|
|
@@ -27303,9 +27303,8 @@ const onPostReactionRemoved = (callback) => {
|
|
|
27303
27303
|
callback(payload.posts[0]);
|
|
27304
27304
|
}
|
|
27305
27305
|
else {
|
|
27306
|
-
|
|
27307
|
-
|
|
27308
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27306
|
+
const processed = prepareReactionPayloadFormEvent('post.removeReaction', payload);
|
|
27307
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27309
27308
|
ingestInCache(postPayload);
|
|
27310
27309
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27311
27310
|
callback(post.data);
|
|
@@ -27446,9 +27445,8 @@ const onCommentReactionAdded = (callback) => {
|
|
|
27446
27445
|
callback(payload.comments[0]);
|
|
27447
27446
|
}
|
|
27448
27447
|
else {
|
|
27449
|
-
|
|
27450
|
-
|
|
27451
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27448
|
+
const processed = prepareReactionPayloadFormEvent('comment.addReaction', payload);
|
|
27449
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27452
27450
|
ingestInCache(commentPayload);
|
|
27453
27451
|
const comment = pullFromCache([
|
|
27454
27452
|
'comment',
|
|
@@ -27483,9 +27481,8 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
27483
27481
|
callback(payload.comments[0]);
|
|
27484
27482
|
}
|
|
27485
27483
|
else {
|
|
27486
|
-
|
|
27487
|
-
|
|
27488
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27484
|
+
const processed = prepareReactionPayloadFormEvent('comment.removeReaction', payload);
|
|
27485
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27489
27486
|
ingestInCache(commentPayload);
|
|
27490
27487
|
const comment = pullFromCache([
|
|
27491
27488
|
'comment',
|
package/dist/index.esm.js
CHANGED
|
@@ -26871,42 +26871,43 @@ getComment$1.locally = (commentId) => {
|
|
|
26871
26871
|
};
|
|
26872
26872
|
};
|
|
26873
26873
|
|
|
26874
|
-
|
|
26875
|
-
const preparePayloadForCache = (event, payload) => {
|
|
26874
|
+
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
26876
26875
|
var _a, _b;
|
|
26877
|
-
|
|
26878
|
-
if (
|
|
26879
|
-
|
|
26876
|
+
let id;
|
|
26877
|
+
if (eventPrefix === 'post') {
|
|
26878
|
+
id = payload.posts[0].postId;
|
|
26880
26879
|
}
|
|
26881
|
-
|
|
26882
|
-
|
|
26883
|
-
if (event === 'post.addReaction' || event === 'post.removeReaction') {
|
|
26884
|
-
const post = payload.posts[0];
|
|
26885
|
-
cached = (_a = pullFromCache(['post', 'get', post.postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26886
|
-
model = post;
|
|
26880
|
+
else if (eventPrefix === 'comment') {
|
|
26881
|
+
id = payload.comments[0].commentId;
|
|
26887
26882
|
}
|
|
26888
26883
|
else {
|
|
26889
|
-
|
|
26890
|
-
cached = (_b = pullFromCache(['comment', 'get', comment.commentId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26891
|
-
model = comment;
|
|
26884
|
+
throw new Error(`Unknown event type`);
|
|
26892
26885
|
}
|
|
26893
|
-
|
|
26894
|
-
|
|
26886
|
+
return ((_b = (_a = pullFromCache(['comment', 'get', id])) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.myReactions) || [];
|
|
26887
|
+
};
|
|
26888
|
+
const rebuildPayload = (payload, payloadKey, myReactions) => {
|
|
26889
|
+
const [model] = payload[payloadKey];
|
|
26890
|
+
return Object.assign(Object.assign({}, payload), { [payloadKey]: [Object.assign(Object.assign({}, model), { myReactions })] });
|
|
26891
|
+
};
|
|
26892
|
+
/** @hidden */
|
|
26893
|
+
const prepareReactionPayloadFormEvent = (event, payload) => {
|
|
26894
|
+
if (getActiveClient().userId !== payload.reactor.userId) {
|
|
26895
|
+
return payload;
|
|
26895
26896
|
}
|
|
26896
|
-
|
|
26897
|
-
|
|
26898
|
-
|
|
26899
|
-
|
|
26900
|
-
|
|
26897
|
+
const eventPrefix = event.split('.')[0]; // 'post' | 'comment'
|
|
26898
|
+
const eventSuffix = event.split('.')[1]; // 'addReaction' | 'removeReaction'
|
|
26899
|
+
let myReactions;
|
|
26900
|
+
const cachedMyReactions = getMyReactionsInCache(payload, eventPrefix);
|
|
26901
|
+
if (eventSuffix === 'addReaction') {
|
|
26902
|
+
myReactions = [...cachedMyReactions, payload.reactor.reactionName];
|
|
26903
|
+
}
|
|
26904
|
+
else if (eventSuffix === 'removeReaction') {
|
|
26905
|
+
myReactions = cachedMyReactions.filter(reaction => reaction !== payload.reactor.reactionName);
|
|
26901
26906
|
}
|
|
26902
26907
|
else {
|
|
26903
|
-
|
|
26904
|
-
return;
|
|
26905
|
-
}
|
|
26906
|
-
Object.assign(model, {
|
|
26907
|
-
myReactions: cached.myReactions.filter(x => x !== payload.reactor.reactionName),
|
|
26908
|
-
});
|
|
26908
|
+
throw new Error(`Unknown event type`);
|
|
26909
26909
|
}
|
|
26910
|
+
return rebuildPayload(payload, `${eventPrefix}s`, myReactions);
|
|
26910
26911
|
};
|
|
26911
26912
|
|
|
26912
26913
|
/* begin_public_function
|
|
@@ -27256,9 +27257,8 @@ const onPostReactionAdded = (callback) => {
|
|
|
27256
27257
|
callback(payload.posts[0]);
|
|
27257
27258
|
}
|
|
27258
27259
|
else {
|
|
27259
|
-
|
|
27260
|
-
|
|
27261
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27260
|
+
const processed = prepareReactionPayloadFormEvent('post.addReaction', payload);
|
|
27261
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27262
27262
|
ingestInCache(postPayload);
|
|
27263
27263
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27264
27264
|
callback(post.data);
|
|
@@ -27289,9 +27289,8 @@ const onPostReactionRemoved = (callback) => {
|
|
|
27289
27289
|
callback(payload.posts[0]);
|
|
27290
27290
|
}
|
|
27291
27291
|
else {
|
|
27292
|
-
|
|
27293
|
-
|
|
27294
|
-
const postPayload = __rest(payload, ["reactor"]);
|
|
27292
|
+
const processed = prepareReactionPayloadFormEvent('post.removeReaction', payload);
|
|
27293
|
+
const postPayload = __rest(processed, ["reactor"]);
|
|
27295
27294
|
ingestInCache(postPayload);
|
|
27296
27295
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
27297
27296
|
callback(post.data);
|
|
@@ -27432,9 +27431,8 @@ const onCommentReactionAdded = (callback) => {
|
|
|
27432
27431
|
callback(payload.comments[0]);
|
|
27433
27432
|
}
|
|
27434
27433
|
else {
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27434
|
+
const processed = prepareReactionPayloadFormEvent('comment.addReaction', payload);
|
|
27435
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27438
27436
|
ingestInCache(commentPayload);
|
|
27439
27437
|
const comment = pullFromCache([
|
|
27440
27438
|
'comment',
|
|
@@ -27469,9 +27467,8 @@ const onCommentReactionRemoved = (callback) => {
|
|
|
27469
27467
|
callback(payload.comments[0]);
|
|
27470
27468
|
}
|
|
27471
27469
|
else {
|
|
27472
|
-
|
|
27473
|
-
|
|
27474
|
-
const commentPayload = __rest(payload, ["reactor"]);
|
|
27470
|
+
const processed = prepareReactionPayloadFormEvent('comment.removeReaction', payload);
|
|
27471
|
+
const commentPayload = __rest(processed, ["reactor"]);
|
|
27475
27472
|
ingestInCache(commentPayload);
|
|
27476
27473
|
const comment = pullFromCache([
|
|
27477
27474
|
'comment',
|