@amityco/ts-sdk 6.26.3 → 6.27.1-061592b.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/.env +26 -26
- package/dist/@types/core/model.d.ts +5 -5
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/ad.d.ts +14 -2
- package/dist/@types/domains/ad.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +6 -0
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +4 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +3 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/adRepository/api/getNetworkAds.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +2 -2
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +11 -5
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts +10 -5
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/api/renewal.d.ts.map +1 -1
- package/dist/client/api/setUploadedFileAccessType.d.ts +2 -0
- package/dist/client/api/setUploadedFileAccessType.d.ts.map +1 -0
- package/dist/client/events/index.d.ts +1 -0
- package/dist/client/events/index.d.ts.map +1 -1
- package/dist/client/events/onNetworkActivities.d.ts +11 -0
- package/dist/client/events/onNetworkActivities.d.ts.map +1 -0
- package/dist/client/utils/GlobalFileAccessType.d.ts +10 -0
- package/dist/client/utils/GlobalFileAccessType.d.ts.map +1 -0
- package/dist/client/utils/NetworkActivitiesWatcher.d.ts +12 -0
- package/dist/client/utils/NetworkActivitiesWatcher.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments.d.ts +1 -1
- package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +7 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/fileRepository/api/createFile.d.ts.map +1 -1
- package/dist/fileRepository/api/createImage.d.ts.map +1 -1
- package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
- package/dist/index.cjs.js +898 -688
- package/dist/index.esm.js +729 -517
- package/dist/index.umd.js +4 -4
- package/dist/messageRepository/api/createMessage.d.ts +7 -25
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts +4 -4
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +1 -1
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/api/updatePost.d.ts +1 -1
- package/dist/postRepository/api/updatePost.d.ts.map +1 -1
- package/dist/postRepository/internalApi/getPost.d.ts +5 -0
- package/dist/postRepository/internalApi/getPost.d.ts.map +1 -0
- package/dist/postRepository/internalApi/index.d.ts +13 -0
- package/dist/postRepository/internalApi/index.d.ts.map +1 -0
- package/dist/postRepository/observers/getPost.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts +5 -0
- package/dist/postRepository/observers/getPosts/PostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts +15 -0
- package/dist/postRepository/observers/getPosts/PostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts +12 -0
- package/dist/postRepository/observers/getPosts/enums.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts +2 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -0
- package/dist/utils/linkedObject/adLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/adLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/categoryLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -1
- package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts +3 -3
- package/package.json +1 -1
- package/src/@types/core/model.ts +5 -5
- package/src/@types/core/payload.ts +1 -1
- package/src/@types/domains/ad.ts +17 -6
- package/src/@types/domains/file.ts +8 -0
- package/src/@types/domains/message.ts +6 -1
- package/src/@types/domains/post.ts +3 -4
- package/src/adRepository/api/getNetworkAds.ts +22 -8
- package/src/analytic/service/analytic/AnalyticsEngine.ts +2 -2
- package/src/analytic/service/analytic/AnalyticsEventCapturer.ts +45 -27
- package/src/client/api/getToken.ts +15 -7
- package/src/client/api/index.ts +2 -0
- package/src/client/api/login.ts +11 -7
- package/src/client/api/logout.ts +4 -0
- package/src/client/api/renewal.ts +6 -1
- package/src/client/api/setUploadedFileAccessType.ts +5 -0
- package/src/client/api/tests/getToken.test.ts +3 -3
- package/src/client/events/index.ts +2 -0
- package/src/client/events/onNetworkActivities.ts +14 -0
- package/src/client/utils/GlobalFileAccessType.ts +23 -0
- package/src/client/utils/NetworkActivitiesWatcher.ts +31 -0
- package/src/commentRepository/observers/getComments.ts +1 -1
- package/src/communityRepository/utils/payload.ts +19 -3
- package/src/core/model/idResolvers.ts +1 -1
- package/src/core/transports/http.ts +25 -1
- package/src/fileRepository/api/createFile.ts +4 -0
- package/src/fileRepository/api/createImage.ts +4 -0
- package/src/fileRepository/api/createVideo.ts +4 -0
- package/src/fileRepository/api/uploadFile.ts +4 -0
- package/src/fileRepository/api/uploadImage.ts +4 -0
- package/src/fileRepository/api/uploadVideo.ts +4 -0
- package/src/messageRepository/api/createMessage.ts +83 -98
- package/src/messageRepository/events/onMessageCreated.ts +12 -6
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +26 -24
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +3 -2
- package/src/messageRepository/observers/observeMessages.ts +3 -3
- package/src/messageRepository/utils/prepareMessagePayload.ts +1 -1
- package/src/postRepository/internalApi/getPost.ts +65 -0
- package/src/postRepository/internalApi/index.ts +16 -0
- package/src/postRepository/observers/getPost.ts +8 -1
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +190 -0
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +45 -0
- package/src/postRepository/observers/getPosts/PostQueryStreamController.ts +102 -0
- package/src/postRepository/observers/getPosts/enums.ts +11 -0
- package/src/postRepository/observers/getPosts.ts +6 -197
- package/src/postRepository/utils/payload.ts +17 -0
- package/src/utils/linkedObject/adLinkedObject.ts +11 -11
- package/src/utils/linkedObject/categoryLinkedObject.ts +6 -28
- package/src/utils/linkedObject/userLinkedObject.ts +8 -27
package/dist/index.cjs.js
CHANGED
|
@@ -46,7 +46,12 @@ const VideoSize = Object.freeze({
|
|
|
46
46
|
MEDIUM: 'medium',
|
|
47
47
|
HIGH: 'high',
|
|
48
48
|
ORIGINAL: 'original',
|
|
49
|
-
});
|
|
49
|
+
});
|
|
50
|
+
exports.FileAccessTypeEnum = void 0;
|
|
51
|
+
(function (FileAccessTypeEnum) {
|
|
52
|
+
FileAccessTypeEnum["PUBLIC"] = "public";
|
|
53
|
+
FileAccessTypeEnum["NETWORK"] = "network";
|
|
54
|
+
})(exports.FileAccessTypeEnum || (exports.FileAccessTypeEnum = {}));
|
|
50
55
|
|
|
51
56
|
const CommunityPostSettings = Object.freeze({
|
|
52
57
|
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
@@ -97,8 +102,8 @@ const PostContentType = Object.freeze({
|
|
|
97
102
|
|
|
98
103
|
function getVersion() {
|
|
99
104
|
try {
|
|
100
|
-
// the string ''v6.
|
|
101
|
-
return 'v6.
|
|
105
|
+
// the string ''v6.27.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
106
|
+
return 'v6.27.0-cjs';
|
|
102
107
|
}
|
|
103
108
|
catch (error) {
|
|
104
109
|
return '__dev__';
|
|
@@ -506,7 +511,7 @@ const idResolvers = {
|
|
|
506
511
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
507
512
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
508
513
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
509
|
-
message: ({ messageId }) => messageId,
|
|
514
|
+
message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
|
|
510
515
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
511
516
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
512
517
|
channelUnreadInfo: ({ channelId }) => channelId,
|
|
@@ -1588,6 +1593,33 @@ const unwrapPayload = (response) => {
|
|
|
1588
1593
|
return undefined;
|
|
1589
1594
|
};
|
|
1590
1595
|
|
|
1596
|
+
class NetworkActivitiesWatcher {
|
|
1597
|
+
constructor() {
|
|
1598
|
+
this._listener = new Map();
|
|
1599
|
+
}
|
|
1600
|
+
onNetworkActivities(callback) {
|
|
1601
|
+
this._listener.set(callback, callback);
|
|
1602
|
+
return () => {
|
|
1603
|
+
this._listener.delete(callback);
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
setNetworkActivities(request, response) {
|
|
1607
|
+
this._listener.forEach(cb => cb(request, response));
|
|
1608
|
+
}
|
|
1609
|
+
destroy() {
|
|
1610
|
+
this._listener.clear();
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
let instance$5;
|
|
1614
|
+
var NetworkActivitiesWatcher$1 = {
|
|
1615
|
+
getInstance: () => {
|
|
1616
|
+
if (!instance$5) {
|
|
1617
|
+
instance$5 = new NetworkActivitiesWatcher();
|
|
1618
|
+
}
|
|
1619
|
+
return instance$5;
|
|
1620
|
+
},
|
|
1621
|
+
};
|
|
1622
|
+
|
|
1591
1623
|
/*
|
|
1592
1624
|
* Defined here as transport is a private module. Also, outside of this module
|
|
1593
1625
|
* this enum holds no meaning.
|
|
@@ -1695,7 +1727,24 @@ const createHttpTransport = (endpoint) => {
|
|
|
1695
1727
|
}
|
|
1696
1728
|
return config;
|
|
1697
1729
|
});
|
|
1698
|
-
instance.interceptors.response.use(response =>
|
|
1730
|
+
instance.interceptors.response.use(response => {
|
|
1731
|
+
const headers = new Headers();
|
|
1732
|
+
Object.entries(response.headers).forEach(([key, value]) => {
|
|
1733
|
+
if (typeof value === 'string') {
|
|
1734
|
+
headers.append(key, value);
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
NetworkActivitiesWatcher$1.getInstance().setNetworkActivities(new Request(response.request.url, {
|
|
1738
|
+
method: response.request.method,
|
|
1739
|
+
headers: response.request.headers,
|
|
1740
|
+
body: response.request.data,
|
|
1741
|
+
}), new Response(response.data, {
|
|
1742
|
+
status: response.status,
|
|
1743
|
+
statusText: response.statusText,
|
|
1744
|
+
headers,
|
|
1745
|
+
}));
|
|
1746
|
+
return response;
|
|
1747
|
+
}, error => {
|
|
1699
1748
|
var _a, _b;
|
|
1700
1749
|
const { response } = error;
|
|
1701
1750
|
// handle unauthorized request
|
|
@@ -4653,6 +4702,17 @@ function __rest(s, e) {
|
|
|
4653
4702
|
}
|
|
4654
4703
|
return t;
|
|
4655
4704
|
}
|
|
4705
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
4706
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4707
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4708
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
4709
|
+
}
|
|
4710
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
4711
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4712
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4713
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
4714
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
4715
|
+
}
|
|
4656
4716
|
|
|
4657
4717
|
/**
|
|
4658
4718
|
* Attach user object to membership model
|
|
@@ -4858,12 +4918,12 @@ class AnalyticsEventCapturer {
|
|
|
4858
4918
|
this._throttleStoryTimer = undefined;
|
|
4859
4919
|
this._bufferNewSeenStoryReferenceIds = [];
|
|
4860
4920
|
}
|
|
4861
|
-
isAbleToEnqueue({
|
|
4921
|
+
isAbleToEnqueue({ uniqueId, expireTime, isHighPriority = false, }) {
|
|
4862
4922
|
const now = new Date();
|
|
4863
4923
|
const getRecentViewedDate = () => {
|
|
4864
4924
|
if (isHighPriority)
|
|
4865
|
-
return this._recentHighPriorityViewed[
|
|
4866
|
-
return this._recentViewed[
|
|
4925
|
+
return this._recentHighPriorityViewed[uniqueId];
|
|
4926
|
+
return this._recentViewed[uniqueId];
|
|
4867
4927
|
};
|
|
4868
4928
|
const recentViewedDate = getRecentViewedDate() || new Date(DAY * -1);
|
|
4869
4929
|
const timeDiff = now.getTime() - recentViewedDate.getTime();
|
|
@@ -4873,8 +4933,8 @@ class AnalyticsEventCapturer {
|
|
|
4873
4933
|
}
|
|
4874
4934
|
return true;
|
|
4875
4935
|
}
|
|
4876
|
-
markAs(
|
|
4877
|
-
if (!this.isAbleToEnqueue({
|
|
4936
|
+
markAs({ uniqueId, contentId, contentType, activityType, metadata, }) {
|
|
4937
|
+
if (!this.isAbleToEnqueue({ uniqueId, expireTime: this._expireTime }))
|
|
4878
4938
|
return;
|
|
4879
4939
|
const now = new Date();
|
|
4880
4940
|
const currentData = { event: [] };
|
|
@@ -4888,7 +4948,7 @@ class AnalyticsEventCapturer {
|
|
|
4888
4948
|
currentData.event.shift();
|
|
4889
4949
|
}
|
|
4890
4950
|
const analyticItem = {
|
|
4891
|
-
contentId
|
|
4951
|
+
contentId,
|
|
4892
4952
|
contentType,
|
|
4893
4953
|
activityType,
|
|
4894
4954
|
timestamp: now.toISOString(),
|
|
@@ -4898,10 +4958,15 @@ class AnalyticsEventCapturer {
|
|
|
4898
4958
|
}
|
|
4899
4959
|
currentData.event.push(analyticItem);
|
|
4900
4960
|
upsertInCache(ANALYTIC_CACHE_KEY, currentData);
|
|
4901
|
-
this._recentViewed[
|
|
4961
|
+
this._recentViewed[uniqueId] = now;
|
|
4902
4962
|
}
|
|
4903
4963
|
markPostAsViewed(postId) {
|
|
4904
|
-
this.markAs(
|
|
4964
|
+
this.markAs({
|
|
4965
|
+
uniqueId: postId,
|
|
4966
|
+
contentId: postId,
|
|
4967
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
4968
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
4969
|
+
});
|
|
4905
4970
|
}
|
|
4906
4971
|
markStory(story, activityType) {
|
|
4907
4972
|
if (!story.expiresAt)
|
|
@@ -4909,7 +4974,7 @@ class AnalyticsEventCapturer {
|
|
|
4909
4974
|
const now = new Date();
|
|
4910
4975
|
const expireTime = new Date(story.expiresAt);
|
|
4911
4976
|
if (!this.isAbleToEnqueue({
|
|
4912
|
-
|
|
4977
|
+
uniqueId: story.storyId,
|
|
4913
4978
|
expireTime: expireTime.getTime(),
|
|
4914
4979
|
isHighPriority: true,
|
|
4915
4980
|
}))
|
|
@@ -4975,13 +5040,27 @@ class AnalyticsEventCapturer {
|
|
|
4975
5040
|
const metadata = {
|
|
4976
5041
|
placement,
|
|
4977
5042
|
};
|
|
4978
|
-
|
|
5043
|
+
const activityType = "view" /* Amity.AnalyticEventActivityType.View */;
|
|
5044
|
+
this.markAs({
|
|
5045
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
5046
|
+
contentId: ad.adId,
|
|
5047
|
+
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
5048
|
+
activityType,
|
|
5049
|
+
metadata,
|
|
5050
|
+
});
|
|
4979
5051
|
}
|
|
4980
5052
|
markAdAsClicked(ad, placement) {
|
|
4981
5053
|
const metadata = {
|
|
4982
5054
|
placement,
|
|
4983
5055
|
};
|
|
4984
|
-
|
|
5056
|
+
const activityType = "linkClicked" /* Amity.AnalyticEventActivityType.Click */;
|
|
5057
|
+
this.markAs({
|
|
5058
|
+
uniqueId: `${ad.adId}.${activityType}.${placement}`,
|
|
5059
|
+
contentId: ad.adId,
|
|
5060
|
+
contentType: "ad" /* Amity.AnalyticEventContentType.Ad */,
|
|
5061
|
+
activityType,
|
|
5062
|
+
metadata,
|
|
5063
|
+
});
|
|
4985
5064
|
}
|
|
4986
5065
|
}
|
|
4987
5066
|
|
|
@@ -5037,13 +5116,13 @@ class AnalyticsEngine {
|
|
|
5037
5116
|
this._eventCapturer.resetAllBuckets();
|
|
5038
5117
|
}
|
|
5039
5118
|
}
|
|
5040
|
-
let instance$
|
|
5119
|
+
let instance$4;
|
|
5041
5120
|
var AnalyticsEngine$1 = {
|
|
5042
5121
|
getInstance: () => {
|
|
5043
|
-
if (!instance$
|
|
5044
|
-
instance$
|
|
5122
|
+
if (!instance$4) {
|
|
5123
|
+
instance$4 = new AnalyticsEngine();
|
|
5045
5124
|
}
|
|
5046
|
-
return instance$
|
|
5125
|
+
return instance$4;
|
|
5047
5126
|
},
|
|
5048
5127
|
};
|
|
5049
5128
|
|
|
@@ -5051,30 +5130,12 @@ const userLinkedObject = (user) => {
|
|
|
5051
5130
|
return Object.assign(Object.assign({}, user), { get avatar() {
|
|
5052
5131
|
var _a;
|
|
5053
5132
|
if (!user.avatarFileId)
|
|
5054
|
-
return
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
attributes: {
|
|
5061
|
-
name: '',
|
|
5062
|
-
extension: '',
|
|
5063
|
-
size: '',
|
|
5064
|
-
mimeType: '',
|
|
5065
|
-
metadata: {
|
|
5066
|
-
exif: {},
|
|
5067
|
-
gps: {},
|
|
5068
|
-
width: 0,
|
|
5069
|
-
height: 0,
|
|
5070
|
-
isFull: false,
|
|
5071
|
-
},
|
|
5072
|
-
},
|
|
5073
|
-
};
|
|
5074
|
-
const cacheData = pullFromCache(['file', 'get', `${user.avatarFileId}`]);
|
|
5075
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data) {
|
|
5076
|
-
avatar = cacheData === null || cacheData === void 0 ? void 0 : cacheData.data;
|
|
5077
|
-
}
|
|
5133
|
+
return undefined;
|
|
5134
|
+
const avatar = (_a = pullFromCache([
|
|
5135
|
+
'file',
|
|
5136
|
+
'get',
|
|
5137
|
+
`${user.avatarFileId}`,
|
|
5138
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5078
5139
|
return avatar;
|
|
5079
5140
|
} });
|
|
5080
5141
|
};
|
|
@@ -5289,34 +5350,12 @@ const categoryLinkedObject = (category) => {
|
|
|
5289
5350
|
return Object.assign(Object.assign({}, category), { get avatar() {
|
|
5290
5351
|
var _a;
|
|
5291
5352
|
if (!category.avatarFileId)
|
|
5292
|
-
return
|
|
5293
|
-
|
|
5294
|
-
fileId: ((_a = category.avatarFileId) === null || _a === void 0 ? void 0 : _a.toString()) ? category.avatarFileId.toString() : '',
|
|
5295
|
-
type: 'image',
|
|
5296
|
-
fileUrl: '',
|
|
5297
|
-
createdAt: '',
|
|
5298
|
-
attributes: {
|
|
5299
|
-
name: '',
|
|
5300
|
-
extension: '',
|
|
5301
|
-
size: '',
|
|
5302
|
-
mimeType: '',
|
|
5303
|
-
metadata: {
|
|
5304
|
-
exif: {},
|
|
5305
|
-
gps: {},
|
|
5306
|
-
width: 0,
|
|
5307
|
-
height: 0,
|
|
5308
|
-
isFull: false,
|
|
5309
|
-
},
|
|
5310
|
-
},
|
|
5311
|
-
};
|
|
5312
|
-
const cacheData = pullFromCache([
|
|
5353
|
+
return undefined;
|
|
5354
|
+
const avatar = (_a = pullFromCache([
|
|
5313
5355
|
'file',
|
|
5314
5356
|
'get',
|
|
5315
5357
|
`${category.avatarFileId}`,
|
|
5316
|
-
]);
|
|
5317
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data) {
|
|
5318
|
-
avatar = cacheData === null || cacheData === void 0 ? void 0 : cacheData.data;
|
|
5319
|
-
}
|
|
5358
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5320
5359
|
return avatar;
|
|
5321
5360
|
} });
|
|
5322
5361
|
};
|
|
@@ -5674,12 +5713,12 @@ class MessageReadReceiptSyncEngine {
|
|
|
5674
5713
|
}
|
|
5675
5714
|
}
|
|
5676
5715
|
}
|
|
5677
|
-
let instance$
|
|
5716
|
+
let instance$3 = null;
|
|
5678
5717
|
var ReadReceiptSyncEngine = {
|
|
5679
5718
|
getInstance: () => {
|
|
5680
|
-
if (!instance$
|
|
5681
|
-
instance$
|
|
5682
|
-
return instance$
|
|
5719
|
+
if (!instance$3)
|
|
5720
|
+
instance$3 = new MessageReadReceiptSyncEngine();
|
|
5721
|
+
return instance$3;
|
|
5683
5722
|
},
|
|
5684
5723
|
};
|
|
5685
5724
|
|
|
@@ -5748,20 +5787,17 @@ const channelLinkedObject = (channel) => {
|
|
|
5748
5787
|
return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
|
|
5749
5788
|
};
|
|
5750
5789
|
|
|
5751
|
-
// import AnalyticsEngine from '~/analytic/service/analytic/AnalyticsEngine';
|
|
5752
5790
|
const adLinkedObject = (ad) => {
|
|
5753
|
-
|
|
5791
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
5754
5792
|
const { image9_16: image916, image1_1: image11 } = ad, restAds = __rest(ad, ["image9_16", "image1_1"]);
|
|
5755
|
-
return Object.assign(Object.assign({}, restAds), {
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
// },
|
|
5764
|
-
get advertiser() {
|
|
5793
|
+
return Object.assign(Object.assign({}, restAds), { analytics: {
|
|
5794
|
+
markAsSeen: (placement) => {
|
|
5795
|
+
analyticsEngineInstance.markAdAsViewed(ad, placement);
|
|
5796
|
+
},
|
|
5797
|
+
markLinkAsClicked: (placement) => {
|
|
5798
|
+
analyticsEngineInstance.markAdAsClicked(ad, placement);
|
|
5799
|
+
},
|
|
5800
|
+
}, get advertiser() {
|
|
5765
5801
|
var _a, _b;
|
|
5766
5802
|
const advertiserData = (_a = pullFromCache([
|
|
5767
5803
|
'advertiser',
|
|
@@ -6649,7 +6685,7 @@ function convertFromRaw(message, reactors, event) {
|
|
|
6649
6685
|
*
|
|
6650
6686
|
* Check git blame for previous iteration
|
|
6651
6687
|
*/
|
|
6652
|
-
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId });
|
|
6688
|
+
myReactions: myReactions || ((_a = cache === null || cache === void 0 ? void 0 : cache.data.myReactions) !== null && _a !== void 0 ? _a : []), reactionsCount: reactionCount, subChannelId: messageFeedId, uniqueId: cache ? cache.data.uniqueId : messageId, referenceId, syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
6653
6689
|
if (mentionedUsers) {
|
|
6654
6690
|
out.mentionees = mentionedUsers.map(mention => {
|
|
6655
6691
|
if (mention.type === 'channel') {
|
|
@@ -6792,13 +6828,13 @@ class SessionWatcher {
|
|
|
6792
6828
|
this._listener.clear();
|
|
6793
6829
|
}
|
|
6794
6830
|
}
|
|
6795
|
-
let instance$
|
|
6831
|
+
let instance$2;
|
|
6796
6832
|
var SessionWatcher$1 = {
|
|
6797
6833
|
getInstance: () => {
|
|
6798
|
-
if (!instance$
|
|
6799
|
-
instance$
|
|
6834
|
+
if (!instance$2) {
|
|
6835
|
+
instance$2 = new SessionWatcher();
|
|
6800
6836
|
}
|
|
6801
|
-
return instance$
|
|
6837
|
+
return instance$2;
|
|
6802
6838
|
},
|
|
6803
6839
|
};
|
|
6804
6840
|
|
|
@@ -7510,13 +7546,15 @@ const setSessionState = (state) => {
|
|
|
7510
7546
|
* @category Client API
|
|
7511
7547
|
* @hidden
|
|
7512
7548
|
*/
|
|
7513
|
-
const getToken = async (params) => {
|
|
7549
|
+
const getToken = async ({ params, options, }) => {
|
|
7514
7550
|
const client = getActiveClient();
|
|
7515
7551
|
client.log('client/api/getToken', params);
|
|
7516
7552
|
const deviceInfo = getDeviceInfo();
|
|
7517
7553
|
const { data } = await client.http.post('/api/v5/sessions', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
7518
|
-
|
|
7519
|
-
|
|
7554
|
+
headers: {
|
|
7555
|
+
'X-API-Key': client.apiKey,
|
|
7556
|
+
'set-access-token-cookie': (options === null || options === void 0 ? void 0 : options.setAccessTokenCookie) || false,
|
|
7557
|
+
},
|
|
7520
7558
|
});
|
|
7521
7559
|
return data;
|
|
7522
7560
|
};
|
|
@@ -7828,12 +7866,12 @@ class ObjectResolverEngine {
|
|
|
7828
7866
|
this.stopResolver();
|
|
7829
7867
|
}
|
|
7830
7868
|
}
|
|
7831
|
-
let instance = null;
|
|
7869
|
+
let instance$1 = null;
|
|
7832
7870
|
var ObjectResolverEngine$1 = {
|
|
7833
7871
|
getInstance: () => {
|
|
7834
|
-
if (!instance)
|
|
7835
|
-
instance = new ObjectResolverEngine();
|
|
7836
|
-
return instance;
|
|
7872
|
+
if (!instance$1)
|
|
7873
|
+
instance$1 = new ObjectResolverEngine();
|
|
7874
|
+
return instance$1;
|
|
7837
7875
|
},
|
|
7838
7876
|
};
|
|
7839
7877
|
|
|
@@ -7908,6 +7946,9 @@ const logout = async () => {
|
|
|
7908
7946
|
isUserDeleted: false,
|
|
7909
7947
|
};
|
|
7910
7948
|
client.ws.io.opts.query = { token: '' };
|
|
7949
|
+
if (typeof document !== 'undefined') {
|
|
7950
|
+
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
7951
|
+
}
|
|
7911
7952
|
/*
|
|
7912
7953
|
* Cache should be usable if tokenExpired
|
|
7913
7954
|
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#SDK-usability-based-on-Session-State
|
|
@@ -8015,6 +8056,17 @@ const onClientBanned = (callback) => {
|
|
|
8015
8056
|
return createEventSubscriber(client, `client/onConnectionError(user.didGlobalBan)`, 'user.didGlobalBan', callback);
|
|
8016
8057
|
};
|
|
8017
8058
|
|
|
8059
|
+
/**
|
|
8060
|
+
*
|
|
8061
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
8062
|
+
*
|
|
8063
|
+
* @param callback The function to call when the event was fired
|
|
8064
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8065
|
+
*
|
|
8066
|
+
* @category Client Events
|
|
8067
|
+
*/
|
|
8068
|
+
const onNetworkActivities = (callback) => NetworkActivitiesWatcher$1.getInstance().onNetworkActivities(callback);
|
|
8069
|
+
|
|
8018
8070
|
/**
|
|
8019
8071
|
* ```js
|
|
8020
8072
|
* import { onTokenExpired } from '@amityco/ts-sdk'
|
|
@@ -8449,9 +8501,12 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
8449
8501
|
const onMessageCreatedLocal = (callback) => {
|
|
8450
8502
|
const client = getActiveClient();
|
|
8451
8503
|
const disposers = [
|
|
8452
|
-
createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created',
|
|
8453
|
-
|
|
8454
|
-
|
|
8504
|
+
createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', async (payload) => {
|
|
8505
|
+
ingestInCache(payload);
|
|
8506
|
+
return payload.messages.forEach(message => {
|
|
8507
|
+
callback(message);
|
|
8508
|
+
});
|
|
8509
|
+
}),
|
|
8455
8510
|
];
|
|
8456
8511
|
return () => {
|
|
8457
8512
|
disposers.forEach(fn => fn());
|
|
@@ -8854,7 +8909,12 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8854
8909
|
// default values
|
|
8855
8910
|
const defaultDeviceId = await getDeviceId();
|
|
8856
8911
|
try {
|
|
8857
|
-
const { users } = await setClientToken(
|
|
8912
|
+
const { users } = await setClientToken({
|
|
8913
|
+
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 }),
|
|
8914
|
+
options: {
|
|
8915
|
+
setAccessTokenCookie: true,
|
|
8916
|
+
},
|
|
8917
|
+
});
|
|
8858
8918
|
const user = users.find(u => u.userId === params.userId);
|
|
8859
8919
|
if (user == null) {
|
|
8860
8920
|
throw new ASCError(`${params.userId} has not been founded`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
@@ -8885,7 +8945,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8885
8945
|
* if getting token failed session state reverts to initial state when app
|
|
8886
8946
|
* is first launched
|
|
8887
8947
|
*/
|
|
8888
|
-
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
8948
|
+
SessionWatcher$1.getInstance().setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
8889
8949
|
// pass error down tree so the calling function handle it
|
|
8890
8950
|
throw error;
|
|
8891
8951
|
}
|
|
@@ -8911,7 +8971,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
8911
8971
|
unsubWatcher();
|
|
8912
8972
|
}
|
|
8913
8973
|
}), onTokenExpired(state => {
|
|
8914
|
-
setSessionState(state);
|
|
8974
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
8915
8975
|
logout();
|
|
8916
8976
|
subscriptions.forEach(fn => fn());
|
|
8917
8977
|
}),
|
|
@@ -8956,7 +9016,12 @@ const renewal = () => {
|
|
|
8956
9016
|
}
|
|
8957
9017
|
else {
|
|
8958
9018
|
// about to expire
|
|
8959
|
-
await setClientToken(
|
|
9019
|
+
await setClientToken({
|
|
9020
|
+
params,
|
|
9021
|
+
options: {
|
|
9022
|
+
setAccessTokenCookie: true,
|
|
9023
|
+
},
|
|
9024
|
+
});
|
|
8960
9025
|
}
|
|
8961
9026
|
tokenRenewed = true;
|
|
8962
9027
|
if (renewTimeoutId)
|
|
@@ -9181,6 +9246,33 @@ const isConnected = () => {
|
|
|
9181
9246
|
client.ws.connected);
|
|
9182
9247
|
};
|
|
9183
9248
|
|
|
9249
|
+
var _GlobalFileAccessType_fileAccessType;
|
|
9250
|
+
class GlobalFileAccessType {
|
|
9251
|
+
constructor() {
|
|
9252
|
+
_GlobalFileAccessType_fileAccessType.set(this, exports.FileAccessTypeEnum.PUBLIC);
|
|
9253
|
+
}
|
|
9254
|
+
setFileAccessType(fileAccessType) {
|
|
9255
|
+
__classPrivateFieldSet(this, _GlobalFileAccessType_fileAccessType, fileAccessType, "f");
|
|
9256
|
+
}
|
|
9257
|
+
getFileAccessType() {
|
|
9258
|
+
return __classPrivateFieldGet(this, _GlobalFileAccessType_fileAccessType, "f");
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9261
|
+
_GlobalFileAccessType_fileAccessType = new WeakMap();
|
|
9262
|
+
let instance;
|
|
9263
|
+
var GlobalFileAccessType$1 = {
|
|
9264
|
+
getInstance: () => {
|
|
9265
|
+
if (!instance) {
|
|
9266
|
+
instance = new GlobalFileAccessType();
|
|
9267
|
+
}
|
|
9268
|
+
return instance;
|
|
9269
|
+
},
|
|
9270
|
+
};
|
|
9271
|
+
|
|
9272
|
+
function setUploadedFileAccessType(accessType) {
|
|
9273
|
+
GlobalFileAccessType$1.getInstance().setFileAccessType(accessType);
|
|
9274
|
+
}
|
|
9275
|
+
|
|
9184
9276
|
/**
|
|
9185
9277
|
* ```js
|
|
9186
9278
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -9711,10 +9803,12 @@ var index$l = /*#__PURE__*/Object.freeze({
|
|
|
9711
9803
|
renewal: renewal,
|
|
9712
9804
|
markerSync: markerSync,
|
|
9713
9805
|
enableUnreadCount: enableUnreadCount,
|
|
9806
|
+
setUploadedFileAccessType: setUploadedFileAccessType,
|
|
9714
9807
|
onConnectionError: onConnectionError,
|
|
9715
9808
|
onClientDisconnected: onClientDisconnected,
|
|
9716
9809
|
onClientBanned: onClientBanned,
|
|
9717
9810
|
onSessionStateChange: onSessionStateChange,
|
|
9811
|
+
onNetworkActivities: onNetworkActivities,
|
|
9718
9812
|
getTotalUnreadCount: getTotalUnreadCount,
|
|
9719
9813
|
getUserUnread: getUserUnread,
|
|
9720
9814
|
getMarkerSyncEvents: getMarkerSyncEvents,
|
|
@@ -11850,6 +11944,8 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
11850
11944
|
const files = formData.getAll('files');
|
|
11851
11945
|
if (!files.length)
|
|
11852
11946
|
throw new Error('The formData object must have a `files` key.');
|
|
11947
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
11948
|
+
formData.append('accessType', accessType);
|
|
11853
11949
|
formData.append('preferredFilename', files[0].name);
|
|
11854
11950
|
const headers = 'getHeaders' in formData
|
|
11855
11951
|
? formData.getHeaders()
|
|
@@ -11935,6 +12031,8 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
11935
12031
|
const files = formData.getAll('files');
|
|
11936
12032
|
if (!files.length)
|
|
11937
12033
|
throw new Error('The formData object must have a `files` key.');
|
|
12034
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12035
|
+
formData.append('accessType', accessType);
|
|
11938
12036
|
formData.append('preferredFilename', files[0].name);
|
|
11939
12037
|
if (feedType) {
|
|
11940
12038
|
formData.append('feedType', feedType);
|
|
@@ -11984,6 +12082,8 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
11984
12082
|
const files = formData.getAll('files');
|
|
11985
12083
|
if (!files.length)
|
|
11986
12084
|
throw new Error('The formData object must have a `files` key.');
|
|
12085
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12086
|
+
formData.append('accessType', accessType);
|
|
11987
12087
|
formData.append('preferredFilename', files[0].name);
|
|
11988
12088
|
const headers = 'getHeaders' in formData
|
|
11989
12089
|
? formData.getHeaders()
|
|
@@ -12027,6 +12127,8 @@ const createImage = async (formData, onProgress) => {
|
|
|
12027
12127
|
const files = formData.getAll('files');
|
|
12028
12128
|
if (!files.length)
|
|
12029
12129
|
throw new Error('The formData object must have a `files` key.');
|
|
12130
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12131
|
+
formData.append('accessType', accessType);
|
|
12030
12132
|
formData.append('preferredFilename', files[0].name);
|
|
12031
12133
|
const headers = 'getHeaders' in formData
|
|
12032
12134
|
? formData.getHeaders()
|
|
@@ -12070,6 +12172,8 @@ const createFile = async (formData, onProgress) => {
|
|
|
12070
12172
|
const files = formData.getAll('files');
|
|
12071
12173
|
if (!files.length)
|
|
12072
12174
|
throw new Error('The formData object must have a `files` key.');
|
|
12175
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12176
|
+
formData.append('accessType', accessType);
|
|
12073
12177
|
formData.append('preferredFilename', files[0].name);
|
|
12074
12178
|
const headers = 'getHeaders' in formData
|
|
12075
12179
|
? formData.getHeaders()
|
|
@@ -12113,6 +12217,8 @@ const createVideo = async (formData, feedType, onProgress) => {
|
|
|
12113
12217
|
const files = formData.getAll('files');
|
|
12114
12218
|
if (!files.length)
|
|
12115
12219
|
throw new Error('The formData object must have a `files` key.');
|
|
12220
|
+
const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
|
|
12221
|
+
formData.append('accessType', accessType);
|
|
12116
12222
|
formData.append('preferredFilename', files[0].name);
|
|
12117
12223
|
if (feedType) {
|
|
12118
12224
|
formData.append('feedType', feedType);
|
|
@@ -12414,7 +12520,7 @@ getMessage$2.locally = (messageId) => {
|
|
|
12414
12520
|
* @category Post API
|
|
12415
12521
|
* @async
|
|
12416
12522
|
*/
|
|
12417
|
-
const getPost$
|
|
12523
|
+
const getPost$2 = async (postId) => {
|
|
12418
12524
|
const client = getActiveClient();
|
|
12419
12525
|
client.log('post/getPost', postId);
|
|
12420
12526
|
isInTombstone('post', postId);
|
|
@@ -12454,7 +12560,7 @@ const getPost$1 = async (postId) => {
|
|
|
12454
12560
|
*
|
|
12455
12561
|
* @category Post API
|
|
12456
12562
|
*/
|
|
12457
|
-
getPost$
|
|
12563
|
+
getPost$2.locally = (postId) => {
|
|
12458
12564
|
const client = getActiveClient();
|
|
12459
12565
|
client.log('post/getPost.locally', postId);
|
|
12460
12566
|
if (!client.cache)
|
|
@@ -14495,9 +14601,40 @@ getMessages$1.locally = (messageIds) => {
|
|
|
14495
14601
|
const getLocalId = () => `LOCAL_${uuid()}`;
|
|
14496
14602
|
// FIXME: temp solution
|
|
14497
14603
|
let uniqueId;
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14604
|
+
const createMessageOptimistic = (bundle) => {
|
|
14605
|
+
var _a, _b;
|
|
14606
|
+
const client = getActiveClient();
|
|
14607
|
+
if (!client.cache)
|
|
14608
|
+
return;
|
|
14609
|
+
/*
|
|
14610
|
+
* When creating messages optimistically a messageId needs to be added by the
|
|
14611
|
+
* client, created a new variable to allow backward compatibility of API
|
|
14612
|
+
*
|
|
14613
|
+
* Updated to handle client requirement to add messageId while uploading
|
|
14614
|
+
* a message with image.
|
|
14615
|
+
* Temporary!
|
|
14616
|
+
*/
|
|
14617
|
+
uniqueId = bundle.referenceId || getLocalId();
|
|
14618
|
+
const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
|
|
14619
|
+
client.log('message/createMessage.optimistically', bundleWithMessageId);
|
|
14620
|
+
const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
|
|
14621
|
+
if (subChannel) {
|
|
14622
|
+
upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
|
|
14623
|
+
if (subChannel.data.channelId === subChannel.data.subChannelId) {
|
|
14624
|
+
const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
|
|
14625
|
+
if (channel === null || channel === void 0 ? void 0 : channel.data) {
|
|
14626
|
+
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
|
|
14627
|
+
}
|
|
14628
|
+
}
|
|
14629
|
+
}
|
|
14630
|
+
// as reused to update created and updated time, which should be the same
|
|
14631
|
+
const createdTime = new Date().toISOString();
|
|
14632
|
+
const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
|
|
14633
|
+
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
14634
|
+
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
14635
|
+
fireEvent('local.message.created', { messages: [message] });
|
|
14636
|
+
return message;
|
|
14637
|
+
};
|
|
14501
14638
|
/**
|
|
14502
14639
|
* ```js
|
|
14503
14640
|
* import { createMessage, createQuery, runQuery } from '@amityco/ts-sdk'
|
|
@@ -14523,75 +14660,31 @@ let uniqueId;
|
|
|
14523
14660
|
const createMessage = async (bundle) => {
|
|
14524
14661
|
const client = getActiveClient();
|
|
14525
14662
|
client.log('message/createMessage', bundle);
|
|
14663
|
+
const optimisticData = createMessageOptimistic(bundle);
|
|
14526
14664
|
const referenceId = bundle.referenceId || uniqueId || getLocalId();
|
|
14527
14665
|
uniqueId = undefined;
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14533
|
-
|
|
14534
|
-
|
|
14535
|
-
}
|
|
14536
|
-
fireEvent('local.message.created', { messages });
|
|
14537
|
-
return {
|
|
14538
|
-
data: LinkedObject.message(messages[0]),
|
|
14539
|
-
cachedAt,
|
|
14540
|
-
};
|
|
14541
|
-
};
|
|
14542
|
-
/**
|
|
14543
|
-
* ```js
|
|
14544
|
-
* import { createMessage } from '@amityco/ts-sdk'
|
|
14545
|
-
*
|
|
14546
|
-
* const created = createMessage.optimistically({
|
|
14547
|
-
* channelId: 'foobar',
|
|
14548
|
-
* data: { text: 'hello world' }
|
|
14549
|
-
* })
|
|
14550
|
-
* ```
|
|
14551
|
-
*
|
|
14552
|
-
* Creates an {@link Amity.Message} in cache
|
|
14553
|
-
*
|
|
14554
|
-
* @param bundle The data necessary to create a new {@link Amity.Message}
|
|
14555
|
-
* @returns The newly created {@link Amity.Message}
|
|
14556
|
-
*
|
|
14557
|
-
* @category Message API
|
|
14558
|
-
*/
|
|
14559
|
-
createMessage.optimistically = (_a) => {
|
|
14560
|
-
var _b, _c;
|
|
14561
|
-
var { referenceId } = _a, bundle = __rest(_a, ["referenceId"]);
|
|
14562
|
-
const client = getActiveClient();
|
|
14563
|
-
if (!client.cache)
|
|
14564
|
-
return;
|
|
14565
|
-
/*
|
|
14566
|
-
* when creating messages optimistically a messageId needs to be added by the
|
|
14567
|
-
* client, created a new variable so as to allow backward compatibility of API
|
|
14568
|
-
*
|
|
14569
|
-
* Updated to handle client requirement to add messageId while uploading
|
|
14570
|
-
* message with image. Temporary!
|
|
14571
|
-
*/
|
|
14572
|
-
uniqueId = referenceId || getLocalId();
|
|
14573
|
-
const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
|
|
14574
|
-
client.log('message/createMessage.optimistically', bundleWithMessageId);
|
|
14575
|
-
const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
|
|
14576
|
-
if (subChannel) {
|
|
14577
|
-
upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
|
|
14578
|
-
if (subChannel.data.channelId === subChannel.data.subChannelId) {
|
|
14579
|
-
const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
|
|
14580
|
-
if (channel === null || channel === void 0 ? void 0 : channel.data) {
|
|
14581
|
-
upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_b = channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1 }));
|
|
14582
|
-
}
|
|
14666
|
+
try {
|
|
14667
|
+
const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
|
|
14668
|
+
const data = await prepareMessagePayload(payload);
|
|
14669
|
+
const { messages } = data;
|
|
14670
|
+
const cachedAt = client.cache && Date.now();
|
|
14671
|
+
if (client.cache) {
|
|
14672
|
+
ingestInCache(data, { cachedAt });
|
|
14583
14673
|
}
|
|
14674
|
+
fireEvent('local.message.created', {
|
|
14675
|
+
messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
14676
|
+
});
|
|
14677
|
+
return {
|
|
14678
|
+
data: LinkedObject.message(messages[0]),
|
|
14679
|
+
cachedAt,
|
|
14680
|
+
};
|
|
14681
|
+
}
|
|
14682
|
+
catch (e) {
|
|
14683
|
+
fireEvent('local.message.created', {
|
|
14684
|
+
messages: [Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ })],
|
|
14685
|
+
});
|
|
14686
|
+
throw e;
|
|
14584
14687
|
}
|
|
14585
|
-
// as reused to update created and updated time, which should be the same
|
|
14586
|
-
const createdTime = new Date().toISOString();
|
|
14587
|
-
const message = Object.assign({ creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_c = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _c !== void 0 ? _c : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
|
|
14588
|
-
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
14589
|
-
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
14590
|
-
fireEvent('local.message.created', { messages: [message] });
|
|
14591
|
-
return {
|
|
14592
|
-
cachedAt,
|
|
14593
|
-
data: LinkedObject.message(message),
|
|
14594
|
-
};
|
|
14595
14688
|
};
|
|
14596
14689
|
/* end_public_function */
|
|
14597
14690
|
|
|
@@ -15304,176 +15397,24 @@ const getMessage$1 = (messageId, callback) => {
|
|
|
15304
15397
|
};
|
|
15305
15398
|
/* end_public_function */
|
|
15306
15399
|
|
|
15307
|
-
class
|
|
15400
|
+
class PaginationNoPageController {
|
|
15308
15401
|
constructor(queryParams) {
|
|
15309
15402
|
const { http } = getActiveClient();
|
|
15310
15403
|
this.queryParams = queryParams;
|
|
15311
15404
|
this.http = http;
|
|
15312
15405
|
}
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
}
|
|
15316
|
-
loadNextPage() {
|
|
15317
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
15318
|
-
}
|
|
15319
|
-
loadPreviousPage() {
|
|
15320
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
15321
|
-
}
|
|
15322
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
15323
|
-
var _a, _b, _c, _d;
|
|
15324
|
-
if (direction === 'prev' && !this.previousToken)
|
|
15325
|
-
return;
|
|
15326
|
-
if (direction === 'next' && !this.nextToken)
|
|
15327
|
-
return;
|
|
15328
|
-
let token;
|
|
15329
|
-
if (direction === 'prev')
|
|
15330
|
-
token = this.previousToken;
|
|
15331
|
-
if (direction === 'next')
|
|
15332
|
-
token = this.nextToken;
|
|
15333
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
15334
|
-
if (direction === 'first') {
|
|
15335
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
15336
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
15337
|
-
}
|
|
15338
|
-
if (direction === 'prev')
|
|
15339
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
15340
|
-
if (direction === 'next')
|
|
15341
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
15342
|
-
return queryResponse;
|
|
15343
|
-
}
|
|
15344
|
-
getNextToken() {
|
|
15345
|
-
return this.nextToken;
|
|
15346
|
-
}
|
|
15347
|
-
getPrevToken() {
|
|
15348
|
-
return this.previousToken;
|
|
15349
|
-
}
|
|
15350
|
-
}
|
|
15351
|
-
|
|
15352
|
-
/* eslint-disable no-use-before-define */
|
|
15353
|
-
/**
|
|
15354
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
15355
|
-
* TODO: check if querybyIds is supported
|
|
15356
|
-
*/
|
|
15357
|
-
class MessagePaginationController extends PaginationController {
|
|
15358
|
-
async getRequest(queryParams, token) {
|
|
15359
|
-
const processedQueryParams = convertQueryParams$1(queryParams);
|
|
15360
|
-
const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
|
|
15361
|
-
params: Object.assign(Object.assign({}, processedQueryParams), { options: token
|
|
15362
|
-
? {
|
|
15363
|
-
token,
|
|
15364
|
-
}
|
|
15365
|
-
: Object.assign({}, processedQueryParams.options) }),
|
|
15366
|
-
});
|
|
15406
|
+
async onFetch() {
|
|
15407
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
15367
15408
|
return queryResponse;
|
|
15368
15409
|
}
|
|
15369
15410
|
}
|
|
15370
15411
|
|
|
15371
|
-
class
|
|
15372
|
-
constructor(
|
|
15373
|
-
this.query = query;
|
|
15374
|
-
this.cacheKey = cacheKey;
|
|
15375
|
-
}
|
|
15376
|
-
}
|
|
15377
|
-
|
|
15378
|
-
/* eslint-disable no-use-before-define */
|
|
15379
|
-
class MessageQueryStreamController extends QueryStreamController {
|
|
15380
|
-
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
15381
|
-
super(query, cacheKey);
|
|
15382
|
-
this.notifyChange = notifyChange;
|
|
15383
|
-
this.preparePayload = preparePayload;
|
|
15412
|
+
class LiveCollectionController {
|
|
15413
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
15384
15414
|
this.paginationController = paginationController;
|
|
15385
|
-
|
|
15386
|
-
|
|
15387
|
-
|
|
15388
|
-
const client = getActiveClient();
|
|
15389
|
-
const cachedAt = client.cache && Date.now();
|
|
15390
|
-
if (client.cache) {
|
|
15391
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
15392
|
-
}
|
|
15393
|
-
}
|
|
15394
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
15395
|
-
var _a, _b;
|
|
15396
|
-
if (refresh) {
|
|
15397
|
-
pushToCache(this.cacheKey, {
|
|
15398
|
-
data: response.messages.map(getResolver('message')),
|
|
15399
|
-
query: this.query,
|
|
15400
|
-
});
|
|
15401
|
-
}
|
|
15402
|
-
else {
|
|
15403
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15404
|
-
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
15405
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
15406
|
-
? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
|
|
15407
|
-
: [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
|
|
15408
|
-
}
|
|
15409
|
-
}
|
|
15410
|
-
reactor(action) {
|
|
15411
|
-
return (payload) => {
|
|
15412
|
-
var _a, _b, _c, _d, _e;
|
|
15413
|
-
if (action === 'onCreate') {
|
|
15414
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15415
|
-
if (!collection)
|
|
15416
|
-
return;
|
|
15417
|
-
if (this.query.subChannelId !== (payload === null || payload === void 0 ? void 0 : payload.subChannelId) || !collection)
|
|
15418
|
-
return;
|
|
15419
|
-
if (this.query.type && this.query.type !== payload.dataType)
|
|
15420
|
-
return;
|
|
15421
|
-
if (this.query.dataType && this.query.dataType !== payload.dataType)
|
|
15422
|
-
return;
|
|
15423
|
-
if (this.query.excludingTags &&
|
|
15424
|
-
((_b = this.query.excludingTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15425
|
-
return;
|
|
15426
|
-
if (this.query.excludeTags &&
|
|
15427
|
-
((_c = this.query.excludeTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15428
|
-
return;
|
|
15429
|
-
if (!!this.query.hasFlags !== !!payload.flagCount)
|
|
15430
|
-
return;
|
|
15431
|
-
if (this.query.parentId && this.query.parentId !== payload.parentId)
|
|
15432
|
-
return;
|
|
15433
|
-
if (this.query.hasOwnProperty('includeDeleted') &&
|
|
15434
|
-
!this.query.includeDeleted &&
|
|
15435
|
-
payload.isDeleted)
|
|
15436
|
-
return;
|
|
15437
|
-
if (this.query.includingTags &&
|
|
15438
|
-
!((_d = this.query.includingTags) === null || _d === void 0 ? void 0 : _d.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15439
|
-
return;
|
|
15440
|
-
if (this.query.tags && !((_e = this.query.tags) === null || _e === void 0 ? void 0 : _e.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15441
|
-
return;
|
|
15442
|
-
if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
|
|
15443
|
-
!this.paginationController.getPrevToken()) {
|
|
15444
|
-
collection.data = [...new Set([payload.messageId, ...collection.data])];
|
|
15445
|
-
}
|
|
15446
|
-
if (this.query.sortBy === 'segmentAsc' && !this.paginationController.getNextToken()) {
|
|
15447
|
-
collection.data = [...new Set([...collection.data, payload.messageId])];
|
|
15448
|
-
}
|
|
15449
|
-
pushToCache(this.cacheKey, collection);
|
|
15450
|
-
}
|
|
15451
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
15452
|
-
};
|
|
15453
|
-
}
|
|
15454
|
-
subscribeRTE(createSubscriber) {
|
|
15455
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
15456
|
-
}
|
|
15457
|
-
}
|
|
15458
|
-
|
|
15459
|
-
class PaginationNoPageController {
|
|
15460
|
-
constructor(queryParams) {
|
|
15461
|
-
const { http } = getActiveClient();
|
|
15462
|
-
this.queryParams = queryParams;
|
|
15463
|
-
this.http = http;
|
|
15464
|
-
}
|
|
15465
|
-
async onFetch() {
|
|
15466
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
15467
|
-
return queryResponse;
|
|
15468
|
-
}
|
|
15469
|
-
}
|
|
15470
|
-
|
|
15471
|
-
class LiveCollectionController {
|
|
15472
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
15473
|
-
this.paginationController = paginationController;
|
|
15474
|
-
this.queryStreamId = queryStreamId;
|
|
15475
|
-
this.cacheKey = cacheKey;
|
|
15476
|
-
this.callback = callback;
|
|
15415
|
+
this.queryStreamId = queryStreamId;
|
|
15416
|
+
this.cacheKey = cacheKey;
|
|
15417
|
+
this.callback = callback;
|
|
15477
15418
|
}
|
|
15478
15419
|
async refresh() {
|
|
15479
15420
|
try {
|
|
@@ -15559,6 +15500,159 @@ class LiveCollectionController {
|
|
|
15559
15500
|
}
|
|
15560
15501
|
}
|
|
15561
15502
|
|
|
15503
|
+
class QueryStreamController {
|
|
15504
|
+
constructor(query, cacheKey) {
|
|
15505
|
+
this.query = query;
|
|
15506
|
+
this.cacheKey = cacheKey;
|
|
15507
|
+
}
|
|
15508
|
+
}
|
|
15509
|
+
|
|
15510
|
+
/* eslint-disable no-use-before-define */
|
|
15511
|
+
class MessageQueryStreamController extends QueryStreamController {
|
|
15512
|
+
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
15513
|
+
super(query, cacheKey);
|
|
15514
|
+
this.notifyChange = notifyChange;
|
|
15515
|
+
this.preparePayload = preparePayload;
|
|
15516
|
+
this.paginationController = paginationController;
|
|
15517
|
+
}
|
|
15518
|
+
async saveToMainDB(response) {
|
|
15519
|
+
const processedPayload = await this.preparePayload(response);
|
|
15520
|
+
const client = getActiveClient();
|
|
15521
|
+
const cachedAt = client.cache && Date.now();
|
|
15522
|
+
if (client.cache) {
|
|
15523
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
15524
|
+
}
|
|
15525
|
+
}
|
|
15526
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
15527
|
+
var _a, _b;
|
|
15528
|
+
if (refresh) {
|
|
15529
|
+
pushToCache(this.cacheKey, {
|
|
15530
|
+
data: response.messages.map(getResolver('message')),
|
|
15531
|
+
query: this.query,
|
|
15532
|
+
});
|
|
15533
|
+
}
|
|
15534
|
+
else {
|
|
15535
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15536
|
+
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
15537
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
|
|
15538
|
+
? [...new Set([...messages, ...response.messages.map(getResolver('message'))])]
|
|
15539
|
+
: [...new Set([...response.messages.map(getResolver('message')), ...messages])] }));
|
|
15540
|
+
}
|
|
15541
|
+
}
|
|
15542
|
+
reactor(action) {
|
|
15543
|
+
return (payload) => {
|
|
15544
|
+
var _a, _b, _c, _d, _e;
|
|
15545
|
+
if (action === 'onCreate') {
|
|
15546
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15547
|
+
const { referenceId } = payload;
|
|
15548
|
+
if (!collection)
|
|
15549
|
+
return;
|
|
15550
|
+
if (this.query.subChannelId !== (payload === null || payload === void 0 ? void 0 : payload.subChannelId) || !collection)
|
|
15551
|
+
return;
|
|
15552
|
+
if (this.query.type && this.query.type !== payload.dataType)
|
|
15553
|
+
return;
|
|
15554
|
+
if (this.query.dataType && this.query.dataType !== payload.dataType)
|
|
15555
|
+
return;
|
|
15556
|
+
if (this.query.excludingTags &&
|
|
15557
|
+
((_b = this.query.excludingTags) === null || _b === void 0 ? void 0 : _b.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15558
|
+
return;
|
|
15559
|
+
if (this.query.excludeTags &&
|
|
15560
|
+
((_c = this.query.excludeTags) === null || _c === void 0 ? void 0 : _c.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15561
|
+
return;
|
|
15562
|
+
if (!!this.query.hasFlags !== !!payload.flagCount)
|
|
15563
|
+
return;
|
|
15564
|
+
if (this.query.parentId && this.query.parentId !== payload.parentId)
|
|
15565
|
+
return;
|
|
15566
|
+
if (this.query.hasOwnProperty('includeDeleted') &&
|
|
15567
|
+
!this.query.includeDeleted &&
|
|
15568
|
+
payload.isDeleted)
|
|
15569
|
+
return;
|
|
15570
|
+
if (this.query.includingTags &&
|
|
15571
|
+
!((_d = this.query.includingTags) === null || _d === void 0 ? void 0 : _d.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15572
|
+
return;
|
|
15573
|
+
if (this.query.tags && !((_e = this.query.tags) === null || _e === void 0 ? void 0 : _e.some(value => { var _a; return (_a = payload.tags) === null || _a === void 0 ? void 0 : _a.includes(value); })))
|
|
15574
|
+
return;
|
|
15575
|
+
if ((!this.query.sortBy || this.query.sortBy === 'segmentDesc') &&
|
|
15576
|
+
!this.paginationController.getPrevToken()) {
|
|
15577
|
+
collection.data = [...new Set([referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId, ...collection.data])];
|
|
15578
|
+
}
|
|
15579
|
+
if (this.query.sortBy === 'segmentAsc' && !this.paginationController.getNextToken()) {
|
|
15580
|
+
collection.data = [...new Set([...collection.data, referenceId !== null && referenceId !== void 0 ? referenceId : payload.messageId])];
|
|
15581
|
+
}
|
|
15582
|
+
pushToCache(this.cacheKey, collection);
|
|
15583
|
+
}
|
|
15584
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
15585
|
+
};
|
|
15586
|
+
}
|
|
15587
|
+
subscribeRTE(createSubscriber) {
|
|
15588
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
15589
|
+
}
|
|
15590
|
+
}
|
|
15591
|
+
|
|
15592
|
+
class PaginationController {
|
|
15593
|
+
constructor(queryParams) {
|
|
15594
|
+
const { http } = getActiveClient();
|
|
15595
|
+
this.queryParams = queryParams;
|
|
15596
|
+
this.http = http;
|
|
15597
|
+
}
|
|
15598
|
+
loadFirstPage() {
|
|
15599
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
15600
|
+
}
|
|
15601
|
+
loadNextPage() {
|
|
15602
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
15603
|
+
}
|
|
15604
|
+
loadPreviousPage() {
|
|
15605
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
15606
|
+
}
|
|
15607
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
15608
|
+
var _a, _b, _c, _d;
|
|
15609
|
+
if (direction === 'prev' && !this.previousToken)
|
|
15610
|
+
return;
|
|
15611
|
+
if (direction === 'next' && !this.nextToken)
|
|
15612
|
+
return;
|
|
15613
|
+
let token;
|
|
15614
|
+
if (direction === 'prev')
|
|
15615
|
+
token = this.previousToken;
|
|
15616
|
+
if (direction === 'next')
|
|
15617
|
+
token = this.nextToken;
|
|
15618
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
15619
|
+
if (direction === 'first') {
|
|
15620
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
15621
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
15622
|
+
}
|
|
15623
|
+
if (direction === 'prev')
|
|
15624
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
15625
|
+
if (direction === 'next')
|
|
15626
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
15627
|
+
return queryResponse;
|
|
15628
|
+
}
|
|
15629
|
+
getNextToken() {
|
|
15630
|
+
return this.nextToken;
|
|
15631
|
+
}
|
|
15632
|
+
getPrevToken() {
|
|
15633
|
+
return this.previousToken;
|
|
15634
|
+
}
|
|
15635
|
+
}
|
|
15636
|
+
|
|
15637
|
+
/* eslint-disable no-use-before-define */
|
|
15638
|
+
/**
|
|
15639
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
15640
|
+
* TODO: check if querybyIds is supported
|
|
15641
|
+
*/
|
|
15642
|
+
class MessagePaginationController extends PaginationController {
|
|
15643
|
+
async getRequest(queryParams, token) {
|
|
15644
|
+
const processedQueryParams = convertQueryParams$1(queryParams);
|
|
15645
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/messages`, {
|
|
15646
|
+
params: Object.assign(Object.assign({}, processedQueryParams), { options: token
|
|
15647
|
+
? {
|
|
15648
|
+
token,
|
|
15649
|
+
}
|
|
15650
|
+
: Object.assign({}, processedQueryParams.options) }),
|
|
15651
|
+
});
|
|
15652
|
+
return queryResponse;
|
|
15653
|
+
}
|
|
15654
|
+
}
|
|
15655
|
+
|
|
15562
15656
|
class MessageLiveCollectionController extends LiveCollectionController {
|
|
15563
15657
|
constructor(query, callback) {
|
|
15564
15658
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -15570,25 +15664,10 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
15570
15664
|
this.callback = callback.bind(this);
|
|
15571
15665
|
this.loadPage({ initial: true });
|
|
15572
15666
|
}
|
|
15573
|
-
setup() {
|
|
15574
|
-
var _a;
|
|
15575
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15576
|
-
if (!collection) {
|
|
15577
|
-
pushToCache(this.cacheKey, {
|
|
15578
|
-
data: [],
|
|
15579
|
-
query: this.query,
|
|
15580
|
-
});
|
|
15581
|
-
}
|
|
15582
|
-
}
|
|
15583
|
-
async persistModel(response) {
|
|
15584
|
-
await this.queryStreamController.saveToMainDB(response);
|
|
15585
|
-
}
|
|
15586
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
15587
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
15588
|
-
}
|
|
15589
15667
|
startSubscription() {
|
|
15590
15668
|
return this.queryStreamController.subscribeRTE([
|
|
15591
15669
|
{ fn: onMessageCreatedMqtt, action: 'onCreate' },
|
|
15670
|
+
{ fn: onMessageCreatedLocal, action: 'onCreate' },
|
|
15592
15671
|
{ fn: onMessageDeleted, action: 'onDelete' },
|
|
15593
15672
|
{ fn: onMessageUpdated, action: 'onUpdate' },
|
|
15594
15673
|
{ fn: onMessageFlagged, action: 'onFlagged' },
|
|
@@ -15665,9 +15744,25 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
15665
15744
|
});
|
|
15666
15745
|
return messages;
|
|
15667
15746
|
}
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15747
|
+
setup() {
|
|
15748
|
+
var _a;
|
|
15749
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
15750
|
+
if (!collection) {
|
|
15751
|
+
pushToCache(this.cacheKey, {
|
|
15752
|
+
data: [],
|
|
15753
|
+
query: this.query,
|
|
15754
|
+
});
|
|
15755
|
+
}
|
|
15756
|
+
}
|
|
15757
|
+
async persistModel(response) {
|
|
15758
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
15759
|
+
}
|
|
15760
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
15761
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
15762
|
+
}
|
|
15763
|
+
}
|
|
15764
|
+
|
|
15765
|
+
/* eslint-disable no-use-before-define */
|
|
15671
15766
|
/* begin_public_function
|
|
15672
15767
|
id: message.query
|
|
15673
15768
|
*/
|
|
@@ -17865,7 +17960,7 @@ const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
|
17865
17960
|
});
|
|
17866
17961
|
return result;
|
|
17867
17962
|
};
|
|
17868
|
-
const
|
|
17963
|
+
const convertCommunityPayload = (rawPayload) => {
|
|
17869
17964
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
17870
17965
|
const communities = rawPayload.communities.map((_a) => {
|
|
17871
17966
|
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
@@ -17889,6 +17984,11 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
17889
17984
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
17890
17985
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
17891
17986
|
};
|
|
17987
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
17988
|
+
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
17989
|
+
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
17990
|
+
communityUsers });
|
|
17991
|
+
};
|
|
17892
17992
|
const prepareCommunityRequest = (params) => {
|
|
17893
17993
|
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
17894
17994
|
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
@@ -20621,7 +20721,7 @@ const editPost = async (postId, patch) => {
|
|
|
20621
20721
|
const deletePost = async (postId, permanent = false) => {
|
|
20622
20722
|
var _a;
|
|
20623
20723
|
const client = getActiveClient();
|
|
20624
|
-
const post = await getPost$
|
|
20724
|
+
const post = await getPost$2(postId);
|
|
20625
20725
|
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
20626
20726
|
params: {
|
|
20627
20727
|
postId,
|
|
@@ -20960,7 +21060,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
20960
21060
|
};
|
|
20961
21061
|
const disposers = [];
|
|
20962
21062
|
disposers.push(onPostUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPostDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')), onPostApproved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onApproved')), onPostDeclined(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDeclined')), onPostFlagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onFlagged')), onPostUnflagged(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUnflagged')), onPostReactionAdded(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionAdded')), onPostReactionRemoved(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onReactionRemoved')));
|
|
20963
|
-
runQuery(createQuery(getPost$
|
|
21063
|
+
runQuery(createQuery(getPost$2, postId), result => (result.data || result.error) &&
|
|
20964
21064
|
router(Object.assign(Object.assign({}, result), { data: result.data && LinkedObject.post(result.data) }), 'onFetch'), queryOptions(policy));
|
|
20965
21065
|
return () => {
|
|
20966
21066
|
log(`observePosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -21075,7 +21175,7 @@ const createComment = async (bundle) => {
|
|
|
21075
21175
|
if (client.cache)
|
|
21076
21176
|
ingestInCache(data, { cachedAt });
|
|
21077
21177
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
21078
|
-
const post = await getPost$
|
|
21178
|
+
const post = await getPost$2(bundle.referenceId);
|
|
21079
21179
|
fireEvent('local.post.updated', {
|
|
21080
21180
|
posts: [post.data],
|
|
21081
21181
|
categories: [],
|
|
@@ -21269,7 +21369,7 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
21269
21369
|
});
|
|
21270
21370
|
}
|
|
21271
21371
|
else {
|
|
21272
|
-
const post = await getPost$
|
|
21372
|
+
const post = await getPost$2(comment.data.referenceId);
|
|
21273
21373
|
fireEvent('local.post.updated', {
|
|
21274
21374
|
posts: [post.data],
|
|
21275
21375
|
categories: [],
|
|
@@ -21775,217 +21875,432 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
21775
21875
|
}
|
|
21776
21876
|
switch (this.query.sortBy) {
|
|
21777
21877
|
case 'firstCreated':
|
|
21778
|
-
comments = comments.sort(sortByFirstCreated);
|
|
21878
|
+
comments = comments.sort(sortByFirstCreated);
|
|
21879
|
+
break;
|
|
21880
|
+
case 'lastCreated':
|
|
21881
|
+
default:
|
|
21882
|
+
comments = comments.sort(sortByLastCreated);
|
|
21883
|
+
break;
|
|
21884
|
+
}
|
|
21885
|
+
return comments;
|
|
21886
|
+
}
|
|
21887
|
+
}
|
|
21888
|
+
|
|
21889
|
+
/* begin_public_function
|
|
21890
|
+
id: comment.query
|
|
21891
|
+
*/
|
|
21892
|
+
/**
|
|
21893
|
+
* ```js
|
|
21894
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
21895
|
+
*
|
|
21896
|
+
* let comments = []
|
|
21897
|
+
* const unsub = getComments({
|
|
21898
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
21899
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
21900
|
+
* }, response => merge(comments, response.data))
|
|
21901
|
+
* ```
|
|
21902
|
+
*
|
|
21903
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
21904
|
+
*
|
|
21905
|
+
* @param referenceType the type of the target
|
|
21906
|
+
* @param referenceId the ID of the target
|
|
21907
|
+
* @param callback the function to call when new data are available
|
|
21908
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
21909
|
+
*
|
|
21910
|
+
* @category Comments Live Collection
|
|
21911
|
+
*/
|
|
21912
|
+
const getComments = (params, callback, config) => {
|
|
21913
|
+
const { log, cache } = getActiveClient();
|
|
21914
|
+
if (!cache) {
|
|
21915
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
21916
|
+
}
|
|
21917
|
+
const timestamp = Date.now();
|
|
21918
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
21919
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
21920
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
21921
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
21922
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
21923
|
+
return () => {
|
|
21924
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
21925
|
+
disposers.forEach(fn => fn());
|
|
21926
|
+
};
|
|
21927
|
+
};
|
|
21928
|
+
/* end_public_function */
|
|
21929
|
+
|
|
21930
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
21931
|
+
__proto__: null,
|
|
21932
|
+
getCommentByIds: getCommentByIds,
|
|
21933
|
+
createComment: createComment,
|
|
21934
|
+
updateComment: updateComment,
|
|
21935
|
+
deleteComment: deleteComment,
|
|
21936
|
+
softDeleteComment: softDeleteComment,
|
|
21937
|
+
hardDeleteComment: hardDeleteComment,
|
|
21938
|
+
flagComment: flagComment,
|
|
21939
|
+
unflagComment: unflagComment,
|
|
21940
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
21941
|
+
onCommentCreated: onCommentCreated,
|
|
21942
|
+
onCommentUpdated: onCommentUpdated,
|
|
21943
|
+
onCommentDeleted: onCommentDeleted,
|
|
21944
|
+
onCommentFlagged: onCommentFlagged,
|
|
21945
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
21946
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
21947
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
21948
|
+
observeComments: observeComments,
|
|
21949
|
+
observeComment: observeComment,
|
|
21950
|
+
getComment: getComment,
|
|
21951
|
+
getComments: getComments
|
|
21952
|
+
});
|
|
21953
|
+
|
|
21954
|
+
/* begin_public_function
|
|
21955
|
+
id: post.get
|
|
21956
|
+
*/
|
|
21957
|
+
/**
|
|
21958
|
+
* ```js
|
|
21959
|
+
* import { PostRepository } from '@amityco/ts-sdk';
|
|
21960
|
+
*
|
|
21961
|
+
* let post;
|
|
21962
|
+
*
|
|
21963
|
+
* const unsub = PostRepository.getPost(postId, response => {
|
|
21964
|
+
* post = response.data;
|
|
21965
|
+
* });
|
|
21966
|
+
* ```
|
|
21967
|
+
*
|
|
21968
|
+
* Observe all mutation on a given {@link Amity.Post}
|
|
21969
|
+
*
|
|
21970
|
+
* @param postId the ID of the message to observe
|
|
21971
|
+
* @param callback the function to call when new data are available
|
|
21972
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
21973
|
+
*
|
|
21974
|
+
* @category Post Live Object
|
|
21975
|
+
*/
|
|
21976
|
+
const getPost$1 = (postId, callback) => {
|
|
21977
|
+
const responder = (snapshot) => {
|
|
21978
|
+
const { data } = snapshot;
|
|
21979
|
+
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
21980
|
+
};
|
|
21981
|
+
return liveObject(postId, responder, 'postId', getPost$2, [
|
|
21982
|
+
onPostApproved,
|
|
21983
|
+
onPostDeclined,
|
|
21984
|
+
(callback) => {
|
|
21985
|
+
return onPostDeleted((post) => {
|
|
21986
|
+
var _a;
|
|
21987
|
+
let targetPost = post;
|
|
21988
|
+
// check if the deleted post is a child of the target post
|
|
21989
|
+
if (post.parentPostId === postId && post.isDeleted) {
|
|
21990
|
+
const parentPost = (_a = pullFromCache([
|
|
21991
|
+
'post',
|
|
21992
|
+
'get',
|
|
21993
|
+
post.parentPostId,
|
|
21994
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21995
|
+
if (parentPost) {
|
|
21996
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
21997
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
21998
|
+
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
21999
|
+
targetPost = parentPost;
|
|
22000
|
+
}
|
|
22001
|
+
}
|
|
22002
|
+
callback(targetPost);
|
|
22003
|
+
});
|
|
22004
|
+
},
|
|
22005
|
+
onPostFlagged,
|
|
22006
|
+
(callback) => {
|
|
22007
|
+
return onPostReactionAdded((post) => {
|
|
22008
|
+
callback(LinkedObject.post(post));
|
|
22009
|
+
});
|
|
22010
|
+
},
|
|
22011
|
+
(callback) => {
|
|
22012
|
+
return onPostReactionRemoved((post) => {
|
|
22013
|
+
callback(LinkedObject.post(post));
|
|
22014
|
+
});
|
|
22015
|
+
},
|
|
22016
|
+
onPostUnflagged,
|
|
22017
|
+
onPostUpdated,
|
|
22018
|
+
convertEventPayload((callback) => {
|
|
22019
|
+
return onCommentCreated(async (comment) => {
|
|
22020
|
+
if (comment.referenceId === postId) {
|
|
22021
|
+
await getPost$2(postId);
|
|
22022
|
+
callback(comment);
|
|
22023
|
+
}
|
|
22024
|
+
});
|
|
22025
|
+
}, 'referenceId', 'post'),
|
|
22026
|
+
convertEventPayload((callback) => {
|
|
22027
|
+
return onCommentDeleted(async (comment) => {
|
|
22028
|
+
if (comment.referenceId === postId) {
|
|
22029
|
+
await getPost$2(postId);
|
|
22030
|
+
callback(comment);
|
|
22031
|
+
}
|
|
22032
|
+
});
|
|
22033
|
+
}, 'referenceId', 'post'),
|
|
22034
|
+
]);
|
|
22035
|
+
};
|
|
22036
|
+
/* end_public_function */
|
|
22037
|
+
|
|
22038
|
+
class PostPaginationController extends PaginationController {
|
|
22039
|
+
async getRequest(queryParams, token) {
|
|
22040
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost"]);
|
|
22041
|
+
const { dataTypes } = params;
|
|
22042
|
+
const baseOptions = {
|
|
22043
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
22044
|
+
};
|
|
22045
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
22046
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/posts`, {
|
|
22047
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
22048
|
+
/*
|
|
22049
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
22050
|
+
* 1. parent post to store text with dataType=text
|
|
22051
|
+
* 2. child post to store dataTypes post data
|
|
22052
|
+
*
|
|
22053
|
+
* By default, BE queries only parent post
|
|
22054
|
+
*/
|
|
22055
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
22056
|
+
});
|
|
22057
|
+
return queryResponse;
|
|
22058
|
+
}
|
|
22059
|
+
}
|
|
22060
|
+
|
|
22061
|
+
var EnumPostActions;
|
|
22062
|
+
(function (EnumPostActions) {
|
|
22063
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
22064
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
22065
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
22066
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
22067
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
22068
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
22069
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
22070
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
22071
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
22072
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
22073
|
+
|
|
22074
|
+
class PostQueryStreamController extends QueryStreamController {
|
|
22075
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
22076
|
+
super(query, cacheKey);
|
|
22077
|
+
this.notifyChange = notifyChange;
|
|
22078
|
+
this.preparePayload = preparePayload;
|
|
22079
|
+
}
|
|
22080
|
+
async saveToMainDB(response) {
|
|
22081
|
+
const processedPayload = await this.preparePayload(response);
|
|
22082
|
+
const client = getActiveClient();
|
|
22083
|
+
const cachedAt = client.cache && Date.now();
|
|
22084
|
+
if (client.cache) {
|
|
22085
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
22086
|
+
}
|
|
22087
|
+
}
|
|
22088
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
22089
|
+
var _a, _b;
|
|
22090
|
+
if (refresh) {
|
|
22091
|
+
pushToCache(this.cacheKey, {
|
|
22092
|
+
data: response.posts.map(getResolver('post')),
|
|
22093
|
+
});
|
|
22094
|
+
}
|
|
22095
|
+
else {
|
|
22096
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22097
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22098
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
22099
|
+
}
|
|
22100
|
+
}
|
|
22101
|
+
reactor(action) {
|
|
22102
|
+
return (post) => {
|
|
22103
|
+
var _a, _b;
|
|
22104
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22105
|
+
if (!collection)
|
|
22106
|
+
return;
|
|
22107
|
+
if (post.parentPostId && post.isDeleted) {
|
|
22108
|
+
const parentPost = (_b = pullFromCache([
|
|
22109
|
+
'post',
|
|
22110
|
+
'get',
|
|
22111
|
+
post.parentPostId,
|
|
22112
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22113
|
+
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== this.query.targetId)
|
|
22114
|
+
return;
|
|
22115
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
22116
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
22117
|
+
}
|
|
22118
|
+
else {
|
|
22119
|
+
if (this.query.targetId !== post.targetId)
|
|
22120
|
+
return;
|
|
22121
|
+
if (this.query.targetType !== post.targetType)
|
|
22122
|
+
return;
|
|
22123
|
+
}
|
|
22124
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
22125
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
22126
|
+
}
|
|
22127
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
22128
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
22129
|
+
}
|
|
22130
|
+
pushToCache(this.cacheKey, collection);
|
|
22131
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
22132
|
+
};
|
|
22133
|
+
}
|
|
22134
|
+
subscribeRTE(createSubscriber) {
|
|
22135
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
22136
|
+
}
|
|
22137
|
+
}
|
|
22138
|
+
|
|
22139
|
+
const preparePostPayload = (postPayload) => {
|
|
22140
|
+
const { posts } = postPayload;
|
|
22141
|
+
const { communities, communityUsers } = convertCommunityPayload({
|
|
22142
|
+
communities: postPayload.communities,
|
|
22143
|
+
communityUsers: postPayload.communityUsers,
|
|
22144
|
+
});
|
|
22145
|
+
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
22146
|
+
communities,
|
|
22147
|
+
communityUsers });
|
|
22148
|
+
};
|
|
22149
|
+
|
|
22150
|
+
const getPost = async (postId) => {
|
|
22151
|
+
const client = getActiveClient();
|
|
22152
|
+
client.log('post/getPost', postId);
|
|
22153
|
+
isInTombstone('post', postId);
|
|
22154
|
+
let payload;
|
|
22155
|
+
try {
|
|
22156
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22157
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
22158
|
+
payload = response.data;
|
|
22159
|
+
}
|
|
22160
|
+
catch (error) {
|
|
22161
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22162
|
+
pushToTombstone('post', postId);
|
|
22163
|
+
}
|
|
22164
|
+
throw error;
|
|
22165
|
+
}
|
|
22166
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22167
|
+
const cachedAt = client.cache && Date.now();
|
|
22168
|
+
if (client.cache)
|
|
22169
|
+
ingestInCache(data, { cachedAt });
|
|
22170
|
+
const { posts } = data;
|
|
22171
|
+
const result = posts.find(post => post.postId === postId);
|
|
22172
|
+
return {
|
|
22173
|
+
data: result,
|
|
22174
|
+
cachedAt,
|
|
22175
|
+
};
|
|
22176
|
+
};
|
|
22177
|
+
getPost.locally = (postId) => {
|
|
22178
|
+
const client = getActiveClient();
|
|
22179
|
+
client.log('post/getPost.locally', postId);
|
|
22180
|
+
if (!client.cache)
|
|
22181
|
+
return;
|
|
22182
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
22183
|
+
if (!cached)
|
|
22184
|
+
return;
|
|
22185
|
+
return {
|
|
22186
|
+
data: cached.data,
|
|
22187
|
+
cachedAt: cached.cachedAt,
|
|
22188
|
+
};
|
|
22189
|
+
};
|
|
22190
|
+
|
|
22191
|
+
class PostLiveCollectionController extends LiveCollectionController {
|
|
22192
|
+
constructor(query, callback) {
|
|
22193
|
+
const queryStreamId = hash__default["default"](query);
|
|
22194
|
+
const cacheKey = ['posts', 'collection', queryStreamId];
|
|
22195
|
+
const paginationController = new PostPaginationController(query);
|
|
22196
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22197
|
+
this.query = query;
|
|
22198
|
+
this.queryStreamController = new PostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
22199
|
+
this.callback = callback.bind(this);
|
|
22200
|
+
this.loadPage({ initial: true });
|
|
22201
|
+
}
|
|
22202
|
+
setup() {
|
|
22203
|
+
var _a;
|
|
22204
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22205
|
+
if (!collection) {
|
|
22206
|
+
pushToCache(this.cacheKey, {
|
|
22207
|
+
data: [],
|
|
22208
|
+
params: {},
|
|
22209
|
+
});
|
|
22210
|
+
}
|
|
22211
|
+
}
|
|
22212
|
+
async persistModel(queryPayload) {
|
|
22213
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
22214
|
+
}
|
|
22215
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22216
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22217
|
+
}
|
|
22218
|
+
startSubscription() {
|
|
22219
|
+
return this.queryStreamController.subscribeRTE([
|
|
22220
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
22221
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
22222
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
22223
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
22224
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
22225
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
22226
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
22227
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
22228
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
22229
|
+
{
|
|
22230
|
+
fn: convertEventPayload((callback) => {
|
|
22231
|
+
return onCommentCreated(async (comment) => {
|
|
22232
|
+
var _a;
|
|
22233
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22234
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22235
|
+
return;
|
|
22236
|
+
await getPost(comment.referenceId);
|
|
22237
|
+
callback(comment);
|
|
22238
|
+
});
|
|
22239
|
+
}, 'referenceId', 'post'),
|
|
22240
|
+
action: EnumPostActions.OnPostUpdated,
|
|
22241
|
+
},
|
|
22242
|
+
{
|
|
22243
|
+
fn: convertEventPayload((callback) => {
|
|
22244
|
+
return onCommentDeleted(async (comment) => {
|
|
22245
|
+
var _a;
|
|
22246
|
+
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22247
|
+
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22248
|
+
return;
|
|
22249
|
+
await getPost(comment.referenceId);
|
|
22250
|
+
callback(comment);
|
|
22251
|
+
});
|
|
22252
|
+
}, 'referenceId', 'post'),
|
|
22253
|
+
action: EnumPostActions.OnPostUpdated,
|
|
22254
|
+
},
|
|
22255
|
+
]);
|
|
22256
|
+
}
|
|
22257
|
+
notifyChange({ origin, loading, error }) {
|
|
22258
|
+
var _a, _b;
|
|
22259
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22260
|
+
if (!collection)
|
|
22261
|
+
return;
|
|
22262
|
+
const data = this.applyFilter((_b = collection.data
|
|
22263
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
22264
|
+
.filter(isNonNullable)
|
|
22265
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
22266
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22267
|
+
return;
|
|
22268
|
+
this.callback({
|
|
22269
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22270
|
+
data,
|
|
22271
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22272
|
+
loading,
|
|
22273
|
+
error,
|
|
22274
|
+
});
|
|
22275
|
+
}
|
|
22276
|
+
applyFilter(data) {
|
|
22277
|
+
var _a;
|
|
22278
|
+
let posts = data;
|
|
22279
|
+
if (!this.query.includeDeleted) {
|
|
22280
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
22281
|
+
}
|
|
22282
|
+
if (this.query.tags) {
|
|
22283
|
+
posts = posts.filter(p => { var _a; return (_a = p.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
22284
|
+
}
|
|
22285
|
+
if (this.query.targetType === 'community' && this.query.feedType) {
|
|
22286
|
+
posts = filterByFeedType(posts, this.query.feedType);
|
|
22287
|
+
}
|
|
22288
|
+
if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
|
|
22289
|
+
posts = filterByPostDataTypes(posts, this.query.dataTypes);
|
|
22290
|
+
}
|
|
22291
|
+
switch (this.query.sortBy) {
|
|
22292
|
+
case 'firstCreated':
|
|
22293
|
+
posts = posts.sort(sortByFirstCreated);
|
|
21779
22294
|
break;
|
|
21780
22295
|
case 'lastCreated':
|
|
21781
22296
|
default:
|
|
21782
|
-
|
|
22297
|
+
posts = posts.sort(sortByLastCreated);
|
|
21783
22298
|
break;
|
|
21784
22299
|
}
|
|
21785
|
-
return
|
|
22300
|
+
return posts;
|
|
21786
22301
|
}
|
|
21787
22302
|
}
|
|
21788
22303
|
|
|
21789
|
-
/* begin_public_function
|
|
21790
|
-
id: comment.query
|
|
21791
|
-
*/
|
|
21792
|
-
/**
|
|
21793
|
-
* ```js
|
|
21794
|
-
* import { getComments } from '@amityco/ts-sdk'
|
|
21795
|
-
*
|
|
21796
|
-
* let comments = []
|
|
21797
|
-
* const unsub = getComments({
|
|
21798
|
-
* referenceType: Amity.InternalComment['referenceType'];
|
|
21799
|
-
* referenceId: Amity.InternalComment['referenceId'];
|
|
21800
|
-
* }, response => merge(comments, response.data))
|
|
21801
|
-
* ```
|
|
21802
|
-
*
|
|
21803
|
-
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
21804
|
-
*
|
|
21805
|
-
* @param referenceType the type of the target
|
|
21806
|
-
* @param referenceId the ID of the target
|
|
21807
|
-
* @param callback the function to call when new data are available
|
|
21808
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
21809
|
-
*
|
|
21810
|
-
* @category Comments Live Collection
|
|
21811
|
-
*/
|
|
21812
|
-
const getComments = (params, callback, config) => {
|
|
21813
|
-
const { log, cache } = getActiveClient();
|
|
21814
|
-
if (!cache) {
|
|
21815
|
-
console.log('For using Live Collection feature you need to enable Cache!');
|
|
21816
|
-
}
|
|
21817
|
-
const timestamp = Date.now();
|
|
21818
|
-
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
21819
|
-
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
21820
|
-
const disposers = commentsLiveCollection.startSubscription();
|
|
21821
|
-
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
21822
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
21823
|
-
return () => {
|
|
21824
|
-
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
21825
|
-
disposers.forEach(fn => fn());
|
|
21826
|
-
};
|
|
21827
|
-
};
|
|
21828
|
-
/* end_public_function */
|
|
21829
|
-
|
|
21830
|
-
var index$6 = /*#__PURE__*/Object.freeze({
|
|
21831
|
-
__proto__: null,
|
|
21832
|
-
getCommentByIds: getCommentByIds,
|
|
21833
|
-
createComment: createComment,
|
|
21834
|
-
updateComment: updateComment,
|
|
21835
|
-
deleteComment: deleteComment,
|
|
21836
|
-
softDeleteComment: softDeleteComment,
|
|
21837
|
-
hardDeleteComment: hardDeleteComment,
|
|
21838
|
-
flagComment: flagComment,
|
|
21839
|
-
unflagComment: unflagComment,
|
|
21840
|
-
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
21841
|
-
onCommentCreated: onCommentCreated,
|
|
21842
|
-
onCommentUpdated: onCommentUpdated,
|
|
21843
|
-
onCommentDeleted: onCommentDeleted,
|
|
21844
|
-
onCommentFlagged: onCommentFlagged,
|
|
21845
|
-
onCommentUnflagged: onCommentUnflagged,
|
|
21846
|
-
onCommentReactionAdded: onCommentReactionAdded,
|
|
21847
|
-
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
21848
|
-
observeComments: observeComments,
|
|
21849
|
-
observeComment: observeComment,
|
|
21850
|
-
getComment: getComment,
|
|
21851
|
-
getComments: getComments
|
|
21852
|
-
});
|
|
21853
|
-
|
|
21854
|
-
/* begin_public_function
|
|
21855
|
-
id: post.get
|
|
21856
|
-
*/
|
|
21857
|
-
/**
|
|
21858
|
-
* ```js
|
|
21859
|
-
* import { PostRepository } from '@amityco/ts-sdk';
|
|
21860
|
-
*
|
|
21861
|
-
* let post;
|
|
21862
|
-
*
|
|
21863
|
-
* const unsub = PostRepository.getPost(postId, response => {
|
|
21864
|
-
* post = response.data;
|
|
21865
|
-
* });
|
|
21866
|
-
* ```
|
|
21867
|
-
*
|
|
21868
|
-
* Observe all mutation on a given {@link Amity.Post}
|
|
21869
|
-
*
|
|
21870
|
-
* @param postId the ID of the message to observe
|
|
21871
|
-
* @param callback the function to call when new data are available
|
|
21872
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
|
|
21873
|
-
*
|
|
21874
|
-
* @category Post Live Object
|
|
21875
|
-
*/
|
|
21876
|
-
const getPost = (postId, callback) => {
|
|
21877
|
-
return liveObject(postId, callback, 'postId', getPost$1, [
|
|
21878
|
-
onPostApproved,
|
|
21879
|
-
onPostDeclined,
|
|
21880
|
-
(callback) => {
|
|
21881
|
-
return onPostDeleted((post) => {
|
|
21882
|
-
var _a;
|
|
21883
|
-
let targetPost = post;
|
|
21884
|
-
// check if the deleted post is a child of the target post
|
|
21885
|
-
if (post.parentPostId === postId && post.isDeleted) {
|
|
21886
|
-
const parentPost = (_a = pullFromCache([
|
|
21887
|
-
'post',
|
|
21888
|
-
'get',
|
|
21889
|
-
post.parentPostId,
|
|
21890
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21891
|
-
if (parentPost) {
|
|
21892
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
21893
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
21894
|
-
// if the deleted post is a child of the target post, then the target post is the parent post
|
|
21895
|
-
targetPost = parentPost;
|
|
21896
|
-
}
|
|
21897
|
-
}
|
|
21898
|
-
callback(targetPost);
|
|
21899
|
-
});
|
|
21900
|
-
},
|
|
21901
|
-
onPostFlagged,
|
|
21902
|
-
(callback) => {
|
|
21903
|
-
return onPostReactionAdded((post) => {
|
|
21904
|
-
callback(LinkedObject.post(post));
|
|
21905
|
-
});
|
|
21906
|
-
},
|
|
21907
|
-
(callback) => {
|
|
21908
|
-
return onPostReactionRemoved((post) => {
|
|
21909
|
-
callback(LinkedObject.post(post));
|
|
21910
|
-
});
|
|
21911
|
-
},
|
|
21912
|
-
onPostUnflagged,
|
|
21913
|
-
onPostUpdated,
|
|
21914
|
-
convertEventPayload((callback) => {
|
|
21915
|
-
return onCommentCreated(async (comment) => {
|
|
21916
|
-
if (comment.referenceId === postId) {
|
|
21917
|
-
await getPost$1(postId);
|
|
21918
|
-
callback(comment);
|
|
21919
|
-
}
|
|
21920
|
-
});
|
|
21921
|
-
}, 'referenceId', 'post'),
|
|
21922
|
-
convertEventPayload((callback) => {
|
|
21923
|
-
return onCommentDeleted(async (comment) => {
|
|
21924
|
-
if (comment.referenceId === postId) {
|
|
21925
|
-
await getPost$1(postId);
|
|
21926
|
-
callback(comment);
|
|
21927
|
-
}
|
|
21928
|
-
});
|
|
21929
|
-
}, 'referenceId', 'post'),
|
|
21930
|
-
]);
|
|
21931
|
-
};
|
|
21932
|
-
/* end_public_function */
|
|
21933
|
-
|
|
21934
|
-
/**
|
|
21935
|
-
* ```js
|
|
21936
|
-
* import { queryPosts } from '@amityco/ts-sdk'
|
|
21937
|
-
* const { data: posts, prevPage, nextPage } = await queryPosts({ targetId, targetType })
|
|
21938
|
-
* ```
|
|
21939
|
-
*
|
|
21940
|
-
* Queries a paginable list of {@link Amity.Post} objects
|
|
21941
|
-
*
|
|
21942
|
-
* @param query The query parameters
|
|
21943
|
-
* @returns posts
|
|
21944
|
-
*
|
|
21945
|
-
* @category Post API
|
|
21946
|
-
* @async
|
|
21947
|
-
*/
|
|
21948
|
-
const queryPosts = async (query) => {
|
|
21949
|
-
const client = getActiveClient();
|
|
21950
|
-
client.log('post/queryPosts', query);
|
|
21951
|
-
const { page, limit = 10, includeDeleted } = query, params = __rest(query, ["page", "limit", "includeDeleted"]);
|
|
21952
|
-
const { dataTypes, matchingOnlyParentPost } = params;
|
|
21953
|
-
const options = (() => {
|
|
21954
|
-
if (page)
|
|
21955
|
-
return { token: page };
|
|
21956
|
-
if (limit)
|
|
21957
|
-
return { limit };
|
|
21958
|
-
return undefined;
|
|
21959
|
-
})();
|
|
21960
|
-
// API-FIX: parameters should be querystring. (1)
|
|
21961
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
21962
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
21963
|
-
const { data } = await client.http.get(`/api/v4/posts`, {
|
|
21964
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
21965
|
-
/*
|
|
21966
|
-
* when creating post like image, file, video BE will create 2 posts
|
|
21967
|
-
* 1. parent post to store text with dataType=text
|
|
21968
|
-
* 2. child post to store dataTypes post data
|
|
21969
|
-
*
|
|
21970
|
-
* By default, BE queries only parent post
|
|
21971
|
-
*/
|
|
21972
|
-
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
21973
|
-
});
|
|
21974
|
-
// API-FIX: backend should answer Amity.Response (2)
|
|
21975
|
-
// const { paging, posts } = unwrapPayload(data)
|
|
21976
|
-
// unpacking
|
|
21977
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21978
|
-
const paperedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
21979
|
-
const { posts } = payload;
|
|
21980
|
-
const cachedAt = client.cache && Date.now();
|
|
21981
|
-
if (client.cache) {
|
|
21982
|
-
ingestInCache(paperedPayload, { cachedAt });
|
|
21983
|
-
const cacheKey = ['post', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
21984
|
-
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
21985
|
-
}
|
|
21986
|
-
return { data: posts.map(LinkedObject.post), cachedAt, paging };
|
|
21987
|
-
};
|
|
21988
|
-
|
|
21989
22304
|
/* begin_public_function
|
|
21990
22305
|
id: post.query
|
|
21991
22306
|
*/
|
|
@@ -22017,121 +22332,9 @@ const getPosts = (params, callback, config) => {
|
|
|
22017
22332
|
}
|
|
22018
22333
|
const timestamp = Date.now();
|
|
22019
22334
|
log(`getPosts(tmpid: ${timestamp}) > listen`);
|
|
22020
|
-
const
|
|
22021
|
-
const
|
|
22022
|
-
const
|
|
22023
|
-
const disposers = [];
|
|
22024
|
-
const cacheKey = [
|
|
22025
|
-
'post',
|
|
22026
|
-
'collection',
|
|
22027
|
-
{ targetId: params.targetId, targetType: params.targetType },
|
|
22028
|
-
];
|
|
22029
|
-
const responder = (data) => {
|
|
22030
|
-
var _a, _b, _c;
|
|
22031
|
-
let posts = (_a = data.data
|
|
22032
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
22033
|
-
.filter(Boolean)
|
|
22034
|
-
.map(({ data }) => LinkedObject.post(data))) !== null && _a !== void 0 ? _a : [];
|
|
22035
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
22036
|
-
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
22037
|
-
if (!params.includeDeleted) {
|
|
22038
|
-
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
22039
|
-
}
|
|
22040
|
-
if (params.tags) {
|
|
22041
|
-
posts = posts.filter(p => { var _a; return (_a = p.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
22042
|
-
}
|
|
22043
|
-
if (params.targetType === 'community' && params.feedType) {
|
|
22044
|
-
posts = filterByFeedType(posts, params.feedType);
|
|
22045
|
-
}
|
|
22046
|
-
if ((_b = params.dataTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
22047
|
-
posts = filterByPostDataTypes(posts, params.dataTypes);
|
|
22048
|
-
}
|
|
22049
|
-
callback({
|
|
22050
|
-
onNextPage: onFetch,
|
|
22051
|
-
data: posts,
|
|
22052
|
-
hasNextPage: !!((_c = data.params) === null || _c === void 0 ? void 0 : _c.page),
|
|
22053
|
-
loading: data.loading,
|
|
22054
|
-
error: data.error,
|
|
22055
|
-
});
|
|
22056
|
-
};
|
|
22057
|
-
const realtimeRouter = (action) => (post) => {
|
|
22058
|
-
var _a, _b;
|
|
22059
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22060
|
-
if (!collection)
|
|
22061
|
-
return;
|
|
22062
|
-
if (post.parentPostId && post.isDeleted) {
|
|
22063
|
-
const parentPost = (_b = pullFromCache([
|
|
22064
|
-
'post',
|
|
22065
|
-
'get',
|
|
22066
|
-
post.parentPostId,
|
|
22067
|
-
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
22068
|
-
if (!parentPost || (parentPost === null || parentPost === void 0 ? void 0 : parentPost.targetId) !== params.targetId)
|
|
22069
|
-
return;
|
|
22070
|
-
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
22071
|
-
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
22072
|
-
}
|
|
22073
|
-
else {
|
|
22074
|
-
if (params.targetId !== post.targetId)
|
|
22075
|
-
return;
|
|
22076
|
-
if (params.targetType !== post.targetType)
|
|
22077
|
-
return;
|
|
22078
|
-
}
|
|
22079
|
-
/*
|
|
22080
|
-
* This is not ideal, but currently this is the only way to update the
|
|
22081
|
-
* collection on post declined
|
|
22082
|
-
*/
|
|
22083
|
-
if (action === 'onDeclined') {
|
|
22084
|
-
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
22085
|
-
}
|
|
22086
|
-
else {
|
|
22087
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
22088
|
-
}
|
|
22089
|
-
pushToCache(cacheKey, collection);
|
|
22090
|
-
responder(collection);
|
|
22091
|
-
};
|
|
22092
|
-
const onFetch = (initial = false) => {
|
|
22093
|
-
var _a, _b, _c;
|
|
22094
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22095
|
-
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22096
|
-
if (!initial && posts.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
22097
|
-
return;
|
|
22098
|
-
const query = createQuery(queryPosts, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
22099
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
22100
|
-
const data = {
|
|
22101
|
-
loading,
|
|
22102
|
-
error,
|
|
22103
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
22104
|
-
data: posts,
|
|
22105
|
-
};
|
|
22106
|
-
if (result) {
|
|
22107
|
-
data.data = initial
|
|
22108
|
-
? result.map(getResolver('post'))
|
|
22109
|
-
: [...new Set([...posts, ...result.map(getResolver('post'))])];
|
|
22110
|
-
}
|
|
22111
|
-
pushToCache(cacheKey, data);
|
|
22112
|
-
responder(data);
|
|
22113
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
22114
|
-
};
|
|
22115
|
-
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')), convertEventPayload((callback) => {
|
|
22116
|
-
return onCommentCreated(async (comment) => {
|
|
22117
|
-
var _a;
|
|
22118
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22119
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22120
|
-
return;
|
|
22121
|
-
await getPost$1(comment.referenceId);
|
|
22122
|
-
callback(comment);
|
|
22123
|
-
});
|
|
22124
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')), convertEventPayload((callback) => {
|
|
22125
|
-
return onCommentDeleted(async (comment) => {
|
|
22126
|
-
var _a;
|
|
22127
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22128
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
22129
|
-
return;
|
|
22130
|
-
await getPost$1(comment.referenceId);
|
|
22131
|
-
callback(comment);
|
|
22132
|
-
});
|
|
22133
|
-
}, 'referenceId', 'post')(realtimeRouter('onUpdate')));
|
|
22134
|
-
onFetch(true);
|
|
22335
|
+
const postsLiveCollection = new PostLiveCollectionController(params, callback);
|
|
22336
|
+
const disposers = postsLiveCollection.startSubscription();
|
|
22337
|
+
const cacheKey = postsLiveCollection.getCacheKey();
|
|
22135
22338
|
disposers.push(() => dropFromCache(cacheKey));
|
|
22136
22339
|
return () => {
|
|
22137
22340
|
log(`getPosts(tmpid: ${timestamp}) > dispose`);
|
|
@@ -22165,7 +22368,7 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
22165
22368
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
22166
22369
|
observePosts: observePosts,
|
|
22167
22370
|
observePost: observePost,
|
|
22168
|
-
getPost: getPost,
|
|
22371
|
+
getPost: getPost$1,
|
|
22169
22372
|
getPosts: getPosts
|
|
22170
22373
|
});
|
|
22171
22374
|
|
|
@@ -23060,7 +23263,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
23060
23263
|
getPoll: getPoll
|
|
23061
23264
|
});
|
|
23062
23265
|
|
|
23063
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
23266
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
23064
23267
|
/*
|
|
23065
23268
|
* The crypto algorithm used for importing key and signing string
|
|
23066
23269
|
*/
|
|
@@ -24507,20 +24710,27 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
24507
24710
|
getGlobalStoryTargets: getGlobalStoryTargets
|
|
24508
24711
|
});
|
|
24509
24712
|
|
|
24510
|
-
const
|
|
24511
|
-
|
|
24512
|
-
|
|
24513
|
-
|
|
24514
|
-
|
|
24515
|
-
};
|
|
24713
|
+
const convertToInternalAd = (ad) => {
|
|
24714
|
+
return Object.assign(Object.assign({}, ad), { endAt: ad.endAt ? ad.endAt : null });
|
|
24715
|
+
};
|
|
24716
|
+
const convertToInternalAdvertiser = (advertiser) => {
|
|
24717
|
+
return Object.assign({}, advertiser);
|
|
24516
24718
|
};
|
|
24517
24719
|
const getNetworkAds = async () => {
|
|
24518
24720
|
const client = getActiveClient();
|
|
24519
24721
|
const { data } = await client.http.get('/api/v1/ads/me');
|
|
24520
|
-
const
|
|
24521
|
-
|
|
24522
|
-
|
|
24523
|
-
|
|
24722
|
+
const internalAds = data.ads.map(convertToInternalAd);
|
|
24723
|
+
const internalAdvertisers = data.advertisers.map(convertToInternalAdvertiser);
|
|
24724
|
+
ingestInCache({
|
|
24725
|
+
ads: internalAds,
|
|
24726
|
+
advertisers: internalAdvertisers,
|
|
24727
|
+
files: data.files,
|
|
24728
|
+
});
|
|
24729
|
+
pushToCache(['ad', 'setting'], data.settings);
|
|
24730
|
+
return {
|
|
24731
|
+
ads: internalAds.map(LinkedObject.ad),
|
|
24732
|
+
settings: data.settings,
|
|
24733
|
+
};
|
|
24524
24734
|
};
|
|
24525
24735
|
|
|
24526
24736
|
var index = /*#__PURE__*/Object.freeze({
|