@amityco/ts-sdk 7.6.1-bba8c29.0 → 7.6.1-ce05a481.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/payload.d.ts +1 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +8 -2
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +6 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +3 -1
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +3 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +1 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +23 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
- package/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +3 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -0
- package/dist/feedRepository/observers/utils.d.ts +6 -0
- package/dist/feedRepository/observers/utils.d.ts.map +1 -0
- package/dist/fileRepository/api/index.d.ts +1 -0
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadClip.d.ts +17 -0
- package/dist/fileRepository/api/uploadClip.d.ts.map +1 -0
- package/dist/index.cjs.js +1565 -1195
- package/dist/index.esm.js +1657 -1287
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/postRepository/api/createClipPost.d.ts +32 -0
- package/dist/postRepository/api/createClipPost.d.ts.map +1 -0
- package/dist/postRepository/api/index.d.ts +1 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/events/utils.d.ts.map +1 -1
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/utils.d.ts +13 -0
- package/dist/postRepository/observers/utils.d.ts.map +1 -0
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +1 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +1 -1
- package/src/@types/domains/content.ts +10 -0
- package/src/@types/domains/feed.ts +18 -1
- package/src/@types/domains/file.ts +5 -0
- package/src/@types/domains/post.ts +4 -0
- package/src/commentRepository/api/deleteComment.ts +6 -6
- package/src/communityRepository/api/getCommunity.ts +0 -9
- package/src/core/model/index.ts +2 -1
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +1 -1
- package/src/feedRepository/api/queryGlobalFeed.ts +3 -1
- package/src/feedRepository/index.ts +1 -1
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.ts +95 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.ts +25 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.ts +101 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed.ts +57 -0
- package/src/feedRepository/observers/getGlobalFeed/LiveCollectionController.ts +91 -0
- package/src/feedRepository/observers/getGlobalFeed/PaginationController.ts +23 -0
- package/src/feedRepository/observers/getGlobalFeed/QueryStreamController.ts +99 -0
- package/src/feedRepository/observers/getGlobalFeed.ts +56 -0
- package/src/feedRepository/observers/index.ts +2 -0
- package/src/feedRepository/observers/utils.ts +85 -0
- package/src/fileRepository/api/index.ts +1 -0
- package/src/fileRepository/api/uploadClip.ts +71 -0
- package/src/postRepository/api/createClipPost.ts +62 -0
- package/src/postRepository/api/index.ts +2 -0
- package/src/postRepository/api/queryPosts.ts +1 -1
- package/src/postRepository/events/utils.ts +35 -1
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +5 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +27 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +2 -74
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +1 -1
- package/src/postRepository/observers/utils.ts +97 -0
- package/src/reactionRepository/api/addReaction.ts +1 -0
- package/src/reactionRepository/api/removeReaction.ts +1 -0
- package/src/utils/linkedObject/postLinkedObject.ts +15 -5
- package/src/utils/postTypePredicate.ts +9 -0
|
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
4
4
|
import { getResolver } from '~/core/model';
|
|
5
5
|
import { getActiveClient } from '~/client';
|
|
6
6
|
import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
|
|
7
|
+
import { EnumPostActions } from '../enums';
|
|
7
8
|
|
|
8
9
|
export class PinnedPostQueryStreamController extends QueryStreamController<
|
|
9
10
|
Amity.PinnedPostPayload,
|
|
@@ -64,4 +65,30 @@ export class PinnedPostQueryStreamController extends QueryStreamController<
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
|
|
69
|
+
reactor(action: EnumPostActions) {
|
|
70
|
+
return (post: Amity.InternalPost) => {
|
|
71
|
+
const collection = pullFromCache<Amity.PostLiveCollectionCache>(this.cacheKey)?.data;
|
|
72
|
+
|
|
73
|
+
if (!collection) return;
|
|
74
|
+
|
|
75
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
76
|
+
collection.data = collection.data.filter(
|
|
77
|
+
referenceId => referenceId !== `global#${post.postId}`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pushToCache(this.cacheKey, collection);
|
|
82
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
subscribeRTE(
|
|
87
|
+
createSubscriber: {
|
|
88
|
+
fn: (reactor: (post: Amity.InternalPost) => void) => Amity.Unsubscriber;
|
|
89
|
+
action: EnumPostActions;
|
|
90
|
+
}[],
|
|
91
|
+
) {
|
|
92
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
93
|
+
}
|
|
67
94
|
}
|
|
@@ -3,17 +3,6 @@ import { pullFromCache, pushToCache } from '~/cache/api';
|
|
|
3
3
|
import { PostPaginationController } from './PostPaginationController';
|
|
4
4
|
import { PostQueryStreamController } from './PostQueryStreamController';
|
|
5
5
|
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
6
|
-
import {
|
|
7
|
-
onPostCreated,
|
|
8
|
-
onPostUpdated,
|
|
9
|
-
onPostDeleted,
|
|
10
|
-
onPostFlagged,
|
|
11
|
-
onPostUnflagged,
|
|
12
|
-
onPostReactionAdded,
|
|
13
|
-
onPostReactionRemoved,
|
|
14
|
-
onPostApproved,
|
|
15
|
-
onPostDeclined,
|
|
16
|
-
} from '~/postRepository/events';
|
|
17
6
|
import {
|
|
18
7
|
filterByFeedType,
|
|
19
8
|
filterByPostDataTypes,
|
|
@@ -22,16 +11,9 @@ import {
|
|
|
22
11
|
sortByLastCreated,
|
|
23
12
|
} from '~/core/query';
|
|
24
13
|
import { isNonNullable } from '~/utils';
|
|
25
|
-
import { EnumPostActions } from '../enums';
|
|
26
14
|
import { LinkedObject } from '~/utils/linkedObject';
|
|
27
15
|
import { preparePostPayload } from '~/postRepository/utils/payload';
|
|
28
|
-
import {
|
|
29
|
-
import { onCommentCreated, onCommentDeleted } from '~/commentRepository';
|
|
30
|
-
import { getPost } from '~/postRepository/internalApi/getPost';
|
|
31
|
-
import { onPostUpdatedLocal } from '~/postRepository/events/onPostUpdatedLocal';
|
|
32
|
-
import { onLocalPostReactionAdded } from '~/postRepository/events/onLocalPostReactionAdded';
|
|
33
|
-
import { onLocalPostReactionRemoved } from '~/postRepository/events/onLocalPostReactionRemoved';
|
|
34
|
-
import { onLocalPostDeleted } from '~/postRepository/events/onLocalPostDeleted';
|
|
16
|
+
import { getPostSubscription } from '../utils';
|
|
35
17
|
|
|
36
18
|
export class PostLiveCollectionController extends LiveCollectionController<
|
|
37
19
|
'post',
|
|
@@ -85,61 +67,7 @@ export class PostLiveCollectionController extends LiveCollectionController<
|
|
|
85
67
|
}
|
|
86
68
|
|
|
87
69
|
startSubscription() {
|
|
88
|
-
return this.queryStreamController.subscribeRTE(
|
|
89
|
-
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
90
|
-
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
91
|
-
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
92
|
-
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
93
|
-
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
94
|
-
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
95
|
-
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
96
|
-
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
97
|
-
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
98
|
-
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
99
|
-
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
100
|
-
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
101
|
-
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
102
|
-
{
|
|
103
|
-
fn: convertEventPayload(
|
|
104
|
-
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
105
|
-
return onCommentCreated(async (comment: Amity.InternalComment) => {
|
|
106
|
-
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(
|
|
107
|
-
this.cacheKey,
|
|
108
|
-
)?.data;
|
|
109
|
-
|
|
110
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
111
|
-
return;
|
|
112
|
-
|
|
113
|
-
await getPost(comment.referenceId);
|
|
114
|
-
callback(comment);
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
'referenceId',
|
|
118
|
-
'post',
|
|
119
|
-
),
|
|
120
|
-
action: EnumPostActions.OnPostUpdated,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
fn: convertEventPayload(
|
|
124
|
-
(callback: Amity.Listener<Amity.InternalComment>) => {
|
|
125
|
-
return onCommentDeleted(async (comment: Amity.InternalComment) => {
|
|
126
|
-
const currentCollection = pullFromCache<Amity.PostLiveCollectionCache>(
|
|
127
|
-
this.cacheKey,
|
|
128
|
-
)?.data;
|
|
129
|
-
|
|
130
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
131
|
-
return;
|
|
132
|
-
|
|
133
|
-
await getPost(comment.referenceId);
|
|
134
|
-
callback(comment);
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
'referenceId',
|
|
138
|
-
'post',
|
|
139
|
-
),
|
|
140
|
-
action: EnumPostActions.OnPostUpdated,
|
|
141
|
-
},
|
|
142
|
-
]);
|
|
70
|
+
return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
143
71
|
}
|
|
144
72
|
|
|
145
73
|
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
@@ -23,7 +23,7 @@ export class PostPaginationController extends PaginationController<
|
|
|
23
23
|
const options = token ? { ...baseOptions, token } : { ...baseOptions, limit };
|
|
24
24
|
|
|
25
25
|
const { data: queryResponse } = await this.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
26
|
-
`/api/
|
|
26
|
+
`/api/v5/posts`,
|
|
27
27
|
{
|
|
28
28
|
params: {
|
|
29
29
|
...params,
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api';
|
|
2
|
+
import { onCommentCreated, onCommentDeleted } from '~/commentRepository';
|
|
3
|
+
import { getPost } from '~/postRepository/internalApi';
|
|
4
|
+
import {
|
|
5
|
+
onPostCreated,
|
|
6
|
+
onPostUpdated,
|
|
7
|
+
onPostDeleted,
|
|
8
|
+
onPostFlagged,
|
|
9
|
+
onPostUnflagged,
|
|
10
|
+
onPostReactionAdded,
|
|
11
|
+
onPostReactionRemoved,
|
|
12
|
+
onPostApproved,
|
|
13
|
+
onPostDeclined,
|
|
14
|
+
} from '~/postRepository/events';
|
|
15
|
+
import { onLocalPostDeleted } from '~/postRepository/events/onLocalPostDeleted';
|
|
16
|
+
import { onLocalPostReactionAdded } from '~/postRepository/events/onLocalPostReactionAdded';
|
|
17
|
+
import { onLocalPostReactionRemoved } from '~/postRepository/events/onLocalPostReactionRemoved';
|
|
18
|
+
import { onPostUpdatedLocal } from '~/postRepository/events/onPostUpdatedLocal';
|
|
19
|
+
import { EnumPostActions } from '~/postRepository/observers/enums';
|
|
20
|
+
import { convertEventPayload } from '~/utils/event';
|
|
21
|
+
import { onCommentCreatedLocal } from '~/commentRepository/events/onCommentCreatedLocal';
|
|
22
|
+
import { onCommentDeleteLocal } from '~/commentRepository/events/onCommentDeletedLocal';
|
|
23
|
+
import { onCommentReactionAdded, onCommentReactionRemoved } from '~/commentRepository/events';
|
|
24
|
+
import { onLocalCommentReactionAdded } from '~/commentRepository/events/onLocalCommentReactionAdded';
|
|
25
|
+
import { onLocalCommentReactionRemoved } from '~/commentRepository/events/onLocalCommentReactionRemoved';
|
|
26
|
+
|
|
27
|
+
type CommentEventHandler = (callback: Amity.Listener<Amity.InternalComment>) => Amity.Unsubscriber;
|
|
28
|
+
|
|
29
|
+
const commentEventHanlder = (
|
|
30
|
+
callback: Amity.Listener<Amity.InternalComment>,
|
|
31
|
+
eventHandler: CommentEventHandler,
|
|
32
|
+
cacheKey: Amity.CacheKey,
|
|
33
|
+
resolveId?: (id: string) => string,
|
|
34
|
+
) => {
|
|
35
|
+
return eventHandler(async (comment: Amity.InternalComment) => {
|
|
36
|
+
const currentCollection = pullFromCache<Amity.PinnedPostLiveCollectionCache>(cacheKey)?.data;
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
!currentCollection ||
|
|
40
|
+
!currentCollection.data.includes(
|
|
41
|
+
resolveId ? resolveId(comment.referenceId) : comment.referenceId,
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
return;
|
|
45
|
+
|
|
46
|
+
await getPost(comment.referenceId);
|
|
47
|
+
callback(comment);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const generateCommentSubscriptions = ({
|
|
52
|
+
cacheKey,
|
|
53
|
+
resolveId,
|
|
54
|
+
}: {
|
|
55
|
+
cacheKey: Amity.CacheKey;
|
|
56
|
+
resolveId?: (id: string) => string;
|
|
57
|
+
}) => {
|
|
58
|
+
const eventHandlers = [
|
|
59
|
+
onCommentCreated,
|
|
60
|
+
onCommentDeleted,
|
|
61
|
+
onCommentReactionAdded,
|
|
62
|
+
onCommentReactionRemoved,
|
|
63
|
+
onCommentCreatedLocal,
|
|
64
|
+
onCommentDeleteLocal,
|
|
65
|
+
onLocalCommentReactionAdded,
|
|
66
|
+
onLocalCommentReactionRemoved,
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
return eventHandlers.map(handler => ({
|
|
70
|
+
fn: convertEventPayload(
|
|
71
|
+
(callback: Amity.Listener<Amity.InternalComment>) =>
|
|
72
|
+
commentEventHanlder(callback, handler, cacheKey, resolveId),
|
|
73
|
+
'referenceId',
|
|
74
|
+
'post',
|
|
75
|
+
),
|
|
76
|
+
action: EnumPostActions.OnPostUpdated,
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const getPostSubscription = (cacheKey: Amity.CacheKey) => {
|
|
81
|
+
return [
|
|
82
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
83
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
84
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
85
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
86
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
87
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
88
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
89
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
90
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
91
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
92
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
93
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
94
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
95
|
+
...generateCommentSubscriptions({ cacheKey }),
|
|
96
|
+
];
|
|
97
|
+
};
|
|
@@ -72,6 +72,7 @@ export const removeReaction = async (
|
|
|
72
72
|
...model.data.reactions,
|
|
73
73
|
[reactionName]: Math.max(0, (model.data.reactions[reactionName] ?? 0) - 1),
|
|
74
74
|
},
|
|
75
|
+
updatedAt: new Date().toISOString(),
|
|
75
76
|
} as Amity.Models[Amity.ReactableType];
|
|
76
77
|
|
|
77
78
|
if (referenceType === 'comment') {
|
|
@@ -2,12 +2,16 @@ import { pullFromCache } from '~/cache/api';
|
|
|
2
2
|
import { commentLinkedObject } from '~/utils/linkedObject/commentLinkedObject';
|
|
3
3
|
import AnalyticsEngine from '../../analytic/service/analytic/AnalyticsEngine';
|
|
4
4
|
import { userLinkedObject } from './userLinkedObject';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
isAmityClipPost,
|
|
7
|
+
isAmityFilePost,
|
|
8
|
+
isAmityImagePost,
|
|
9
|
+
isAmityVideoPost,
|
|
10
|
+
} from '../postTypePredicate';
|
|
11
|
+
import { shallowClone } from '../shallowClone';
|
|
6
12
|
|
|
7
13
|
export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
8
|
-
return {
|
|
9
|
-
...post,
|
|
10
|
-
|
|
14
|
+
return shallowClone(post, {
|
|
11
15
|
analytics: {
|
|
12
16
|
markAsViewed: () => {
|
|
13
17
|
const analyticsEngineInstance = AnalyticsEngine.getInstance();
|
|
@@ -64,5 +68,11 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
|
64
68
|
? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
|
|
65
69
|
: undefined;
|
|
66
70
|
},
|
|
67
|
-
|
|
71
|
+
|
|
72
|
+
getClipInfo(): Amity.File<'clip'> | undefined {
|
|
73
|
+
return isAmityClipPost(post)
|
|
74
|
+
? pullFromCache<Amity.File<'clip'>>(['file', 'get', post?.data?.fileId])?.data
|
|
75
|
+
: undefined;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
68
78
|
};
|
|
@@ -25,3 +25,12 @@ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'
|
|
|
25
25
|
post.dataType === 'video'
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export function isAmityClipPost(post: Amity.InternalPost): post is Amity.Post<'clip'> {
|
|
30
|
+
return !!(
|
|
31
|
+
post.data &&
|
|
32
|
+
typeof post.data !== 'string' &&
|
|
33
|
+
'fileId' in post.data &&
|
|
34
|
+
post.dataType === 'clip'
|
|
35
|
+
);
|
|
36
|
+
}
|