@amityco/ts-sdk-react-native 6.9.1-e6a3d26.0 → 6.10.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/channelRepsitory/observers/getChannels.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentCreated.d.ts +3 -3
- package/dist/commentRepository/events/onCommentCreated.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentDeleted.d.ts +3 -3
- package/dist/commentRepository/events/onCommentDeleted.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentFlagged.d.ts +3 -3
- package/dist/commentRepository/events/onCommentFlagged.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentReactionAdded.d.ts +3 -3
- package/dist/commentRepository/events/onCommentReactionAdded.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentReactionRemoved.d.ts +3 -3
- package/dist/commentRepository/events/onCommentReactionRemoved.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentUnflagged.d.ts +3 -3
- package/dist/commentRepository/events/onCommentUnflagged.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentUpdated.d.ts +3 -3
- package/dist/commentRepository/events/onCommentUpdated.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts +2 -2
- package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/index.cjs.js +113 -86
- package/dist/index.esm.js +113 -86
- package/dist/index.umd.js +2 -2
- package/dist/utils/tests/dummy/comment.d.ts +40 -1
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channelRepsitory/observers/getChannels.ts +17 -2
- package/src/client/api/logout.ts +7 -5
- package/src/commentRepository/events/onCommentCreated.ts +4 -5
- package/src/commentRepository/events/onCommentDeleted.ts +4 -5
- package/src/commentRepository/events/onCommentFlagged.ts +4 -5
- package/src/commentRepository/events/onCommentReactionAdded.ts +6 -5
- package/src/commentRepository/events/onCommentReactionRemoved.ts +6 -5
- package/src/commentRepository/events/onCommentUnflagged.ts +4 -5
- package/src/commentRepository/events/onCommentUpdated.ts +4 -5
- package/src/commentRepository/events/utils.ts +4 -3
- package/src/commentRepository/observers/getComment.ts +2 -2
- package/src/commentRepository/observers/getComments.ts +5 -1
- package/src/commentRepository/observers/tests/getComment.test.ts +18 -14
- package/src/core/device.ts +2 -1
- package/src/core/events.ts +6 -1
- package/src/core/query/filtering.ts +24 -17
- package/src/utils/tests/dummy/comment.ts +16 -9
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
import { createComment } from '~/commentRepository/api';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function generateInternalComment(params?: Partial<Amity.InternalComment>): Amity.InternalComment;
|
|
3
|
+
export declare const generateComment: (params?: Partial<Amity.Comment>) => {
|
|
4
|
+
target: {
|
|
5
|
+
type: string;
|
|
6
|
+
communityId: string;
|
|
7
|
+
creatorMember: Amity.Membership<"community">;
|
|
8
|
+
};
|
|
9
|
+
commentId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
parentId?: string | undefined;
|
|
12
|
+
rootId: string;
|
|
13
|
+
childrenNumber: number;
|
|
14
|
+
children: string[];
|
|
15
|
+
segmentNumber: number;
|
|
16
|
+
editedAt: string;
|
|
17
|
+
attachments?: Amity.Attachment[] | undefined;
|
|
18
|
+
targetId: string;
|
|
19
|
+
targetType: "user" | "community" | "content";
|
|
20
|
+
referenceId: string;
|
|
21
|
+
referenceType: Amity.CommentReferenceType;
|
|
22
|
+
dataType?: any;
|
|
23
|
+
dataTypes?: any[] | undefined;
|
|
24
|
+
data?: string | Record<string, unknown> | Amity.ContentDataText | Amity.ContentDataFile | Amity.ContentDataImage | Amity.ContentDataVideo | Amity.ContentDataPoll | undefined;
|
|
25
|
+
metadata?: Record<string, any> | undefined;
|
|
26
|
+
flagCount: number;
|
|
27
|
+
hashFlag: {
|
|
28
|
+
bits: number;
|
|
29
|
+
hashes: number;
|
|
30
|
+
hash: string;
|
|
31
|
+
} | null;
|
|
32
|
+
reactionsCount: number;
|
|
33
|
+
reactions: Record<string, number>;
|
|
34
|
+
myReactions?: string[] | undefined;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
updatedAt?: string | undefined;
|
|
37
|
+
deletedAt?: string | undefined;
|
|
38
|
+
isDeleted?: boolean | undefined;
|
|
39
|
+
path: string;
|
|
40
|
+
mentionees?: Amity.UserMention[] | undefined;
|
|
41
|
+
};
|
|
3
42
|
export declare const comment11: Amity.InternalComment;
|
|
4
43
|
export declare const imageComment11: Amity.InternalComment;
|
|
5
44
|
export declare const textImageComment11: Amity.InternalComment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,wBAAgB,
|
|
1
|
+
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,wBAAgB,uBAAuB,CACrC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,GACtC,KAAK,CAAC,eAAe,CA+BvB;AAED,eAAO,MAAM,eAAe,YAAa,QAAQ,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAU9D,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,eAAmC,CAAC;AAElE,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,eASjC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,eASrC,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,eAOvC,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,eAG5B,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,eAGjC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,eAGrC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,cAMtC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,cAMpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,cAMvC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,cAM3C,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,cAM7C,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,oBAU/B,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,KAAK,CAAC,cAMnD,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,cAmBzC,CAAC;AAGF,eAAO,MAAM,mBAAmB;;;;;;;;;CAO/B,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;CAOhC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;CAOpC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;CAOtC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;CAOlC,CAAC;AAGF,eAAO,MAAM,yBAAyB,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAMzE,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAOjF,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAS1E,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAY9E,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAYpF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
|
-
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { dropFromCache, pullFromCache, pushToCache, upsertInCache } from '~/cache/api';
|
|
4
4
|
import { getActiveClient } from '~/client/api';
|
|
5
5
|
import {
|
|
6
6
|
createQuery,
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
} from '~/utils/constants';
|
|
22
22
|
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
23
23
|
import { convertEventPayload } from '~/utils/event';
|
|
24
|
+
import { uuid } from '~/core/uuid';
|
|
25
|
+
import { onMessageCreated } from '../../messageRepository/events/onMessageCreated';
|
|
24
26
|
import {
|
|
25
27
|
onChannelCreated,
|
|
26
28
|
onChannelDeleted,
|
|
@@ -32,7 +34,6 @@ import {
|
|
|
32
34
|
onChannelUpdated,
|
|
33
35
|
} from '../events';
|
|
34
36
|
import { queryChannels } from '../api/queryChannels';
|
|
35
|
-
import { uuid } from '~/core/uuid';
|
|
36
37
|
|
|
37
38
|
/* begin_public_function
|
|
38
39
|
id: channel.query
|
|
@@ -186,6 +187,20 @@ export const getChannels = (
|
|
|
186
187
|
};
|
|
187
188
|
|
|
188
189
|
disposers.push(
|
|
190
|
+
onMessageCreated(message => {
|
|
191
|
+
const cacheData = pullFromCache<Amity.Channel>(['channel', 'get', message.channelId]);
|
|
192
|
+
|
|
193
|
+
if (!cacheData) return;
|
|
194
|
+
|
|
195
|
+
const channelData = {
|
|
196
|
+
...cacheData.data,
|
|
197
|
+
lastActivity: message.createdAt,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
upsertInCache(['channel', 'get', message.channelId], channelData);
|
|
201
|
+
|
|
202
|
+
realtimeRouter('onUpdate')(channelData);
|
|
203
|
+
}),
|
|
189
204
|
onChannelCreated(realtimeRouter('onCreate')),
|
|
190
205
|
onChannelDeleted(realtimeRouter('onDelete')),
|
|
191
206
|
onChannelUpdated(realtimeRouter('onUpdate')),
|
package/src/client/api/logout.ts
CHANGED
|
@@ -22,11 +22,13 @@ export const logout = async (): Promise<boolean> => {
|
|
|
22
22
|
|
|
23
23
|
client.log('client/api/disconnectClient');
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
client.ws.once('disconnect', resolve);
|
|
27
|
-
client.ws.disconnect();
|
|
25
|
+
if (client.mqtt.connected) {
|
|
28
26
|
client.mqtt.disconnect();
|
|
29
|
-
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (client.ws.connected) {
|
|
30
|
+
client.ws.disconnect();
|
|
31
|
+
}
|
|
30
32
|
|
|
31
33
|
/*
|
|
32
34
|
* for cases when session state is terminated (example on ban) or token expired,
|
|
@@ -61,6 +63,6 @@ export const logout = async (): Promise<boolean> => {
|
|
|
61
63
|
client.cache = { data: {} };
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
return
|
|
66
|
+
return true;
|
|
65
67
|
};
|
|
66
68
|
/* end_public_function */
|
|
@@ -8,13 +8,12 @@ import { createCommentEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.Comment} has been created
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
|
-
* @category
|
|
16
|
+
* @category Comment Events
|
|
17
17
|
*/
|
|
18
|
-
export const onCommentCreated = (
|
|
19
|
-
callback
|
|
20
|
-
): Amity.Unsubscriber => createCommentEventSubscriber('comment.created', callback);
|
|
18
|
+
export const onCommentCreated = (callback: Amity.Listener<Amity.Comment>): Amity.Unsubscriber =>
|
|
19
|
+
createCommentEventSubscriber('comment.created', callback);
|
|
@@ -8,13 +8,12 @@ import { createCommentEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.Comment} has been deleted
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
|
-
* @category
|
|
16
|
+
* @category Comment Events
|
|
17
17
|
*/
|
|
18
|
-
export const onCommentDeleted = (
|
|
19
|
-
callback
|
|
20
|
-
): Amity.Unsubscriber => createCommentEventSubscriber('comment.deleted', callback);
|
|
18
|
+
export const onCommentDeleted = (callback: Amity.Listener<Amity.Comment>): Amity.Unsubscriber =>
|
|
19
|
+
createCommentEventSubscriber('comment.deleted', callback);
|
|
@@ -8,13 +8,12 @@ import { createCommentEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.Comment} has been flagged
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
|
-
* @category
|
|
16
|
+
* @category Comment Events
|
|
17
17
|
*/
|
|
18
|
-
export const onCommentFlagged = (
|
|
19
|
-
callback
|
|
20
|
-
): Amity.Unsubscriber => createCommentEventSubscriber('comment.flagged', callback);
|
|
18
|
+
export const onCommentFlagged = (callback: Amity.Listener<Amity.Comment>): Amity.Unsubscriber =>
|
|
19
|
+
createCommentEventSubscriber('comment.flagged', callback);
|
|
@@ -3,6 +3,7 @@ import { pullFromCache } from '~/cache/api';
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { createEventSubscriber } from '~/core/events';
|
|
5
5
|
import { prepareReactionPayloadFormEvent } from '~/reactionRepository/utils';
|
|
6
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* ```js
|
|
@@ -12,21 +13,21 @@ import { prepareReactionPayloadFormEvent } from '~/reactionRepository/utils';
|
|
|
12
13
|
* })
|
|
13
14
|
* ```
|
|
14
15
|
*
|
|
15
|
-
* Fired when a {@link Amity.
|
|
16
|
+
* Fired when a {@link Amity.Comment} has been reacted
|
|
16
17
|
*
|
|
17
18
|
* @param callback The function to call when the event was fired
|
|
18
19
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19
20
|
*
|
|
20
|
-
* @category
|
|
21
|
+
* @category Comment Events
|
|
21
22
|
*/
|
|
22
23
|
export const onCommentReactionAdded = (
|
|
23
|
-
callback: Amity.Listener<Amity.
|
|
24
|
+
callback: Amity.Listener<Amity.Comment>,
|
|
24
25
|
): Amity.Unsubscriber => {
|
|
25
26
|
const client = getActiveClient();
|
|
26
27
|
|
|
27
28
|
const filter = (payload: Amity.CommentPayload & { reactor: Amity.Reactor }) => {
|
|
28
29
|
if (!client.cache) {
|
|
29
|
-
callback(payload.comments[0]);
|
|
30
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
30
31
|
} else {
|
|
31
32
|
const processed = prepareReactionPayloadFormEvent('comment.addReaction', payload);
|
|
32
33
|
const { reactor, ...commentPayload } = processed;
|
|
@@ -39,7 +40,7 @@ export const onCommentReactionAdded = (
|
|
|
39
40
|
payload.comments[0].commentId,
|
|
40
41
|
])!;
|
|
41
42
|
|
|
42
|
-
callback(comment.data);
|
|
43
|
+
callback(LinkedObject.comment(comment.data));
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -3,6 +3,7 @@ import { pullFromCache } from '~/cache/api';
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { createEventSubscriber } from '~/core/events';
|
|
5
5
|
import { prepareReactionPayloadFormEvent } from '~/reactionRepository/utils';
|
|
6
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* ```js
|
|
@@ -12,21 +13,21 @@ import { prepareReactionPayloadFormEvent } from '~/reactionRepository/utils';
|
|
|
12
13
|
* })
|
|
13
14
|
* ```
|
|
14
15
|
*
|
|
15
|
-
* Fired when a reaction has been removed from a {@link Amity.
|
|
16
|
+
* Fired when a reaction has been removed from a {@link Amity.Comment}
|
|
16
17
|
*
|
|
17
18
|
* @param callback The function to call when the event was fired
|
|
18
19
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19
20
|
*
|
|
20
|
-
* @category
|
|
21
|
+
* @category Comment Events
|
|
21
22
|
*/
|
|
22
23
|
export const onCommentReactionRemoved = (
|
|
23
|
-
callback: Amity.Listener<Amity.
|
|
24
|
+
callback: Amity.Listener<Amity.Comment>,
|
|
24
25
|
): Amity.Unsubscriber => {
|
|
25
26
|
const client = getActiveClient();
|
|
26
27
|
|
|
27
28
|
const filter = (payload: Amity.CommentPayload & { reactor: Amity.Reactor }) => {
|
|
28
29
|
if (!client.cache) {
|
|
29
|
-
callback(payload.comments[0]);
|
|
30
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
30
31
|
} else {
|
|
31
32
|
const processed = prepareReactionPayloadFormEvent('comment.removeReaction', payload);
|
|
32
33
|
const { reactor, ...commentPayload } = processed;
|
|
@@ -39,7 +40,7 @@ export const onCommentReactionRemoved = (
|
|
|
39
40
|
payload.comments[0].commentId,
|
|
40
41
|
])!;
|
|
41
42
|
|
|
42
|
-
callback(comment.data);
|
|
43
|
+
callback(LinkedObject.comment(comment.data));
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -8,13 +8,12 @@ import { createCommentEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a flag has been removed from a {@link Amity.
|
|
11
|
+
* Fired when a flag has been removed from a {@link Amity.Comment}
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
|
-
* @category
|
|
16
|
+
* @category Comment Events
|
|
17
17
|
*/
|
|
18
|
-
export const onCommentUnflagged = (
|
|
19
|
-
callback
|
|
20
|
-
): Amity.Unsubscriber => createCommentEventSubscriber('comment.unflagged', callback);
|
|
18
|
+
export const onCommentUnflagged = (callback: Amity.Listener<Amity.Comment>): Amity.Unsubscriber =>
|
|
19
|
+
createCommentEventSubscriber('comment.unflagged', callback);
|
|
@@ -8,13 +8,12 @@ import { createCommentEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.Comment} has been updated
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
|
-
* @category
|
|
16
|
+
* @category Comment Events
|
|
17
17
|
*/
|
|
18
|
-
export const onCommentUpdated = (
|
|
19
|
-
callback
|
|
20
|
-
): Amity.Unsubscriber => createCommentEventSubscriber('comment.updated', callback);
|
|
18
|
+
export const onCommentUpdated = (callback: Amity.Listener<Amity.Comment>): Amity.Unsubscriber =>
|
|
19
|
+
createCommentEventSubscriber('comment.updated', callback);
|
|
@@ -2,17 +2,18 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
import { pullFromCache, queryCache, upsertInCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
5
6
|
|
|
6
7
|
export const createCommentEventSubscriber = (
|
|
7
8
|
event: keyof Amity.MqttCommentEvents,
|
|
8
|
-
callback: Amity.Listener<Amity.
|
|
9
|
+
callback: Amity.Listener<Amity.Comment>,
|
|
9
10
|
) => {
|
|
10
11
|
const client = getActiveClient();
|
|
11
12
|
|
|
12
13
|
const filter = (payload: Amity.CommentPayload) => {
|
|
13
14
|
if (!client.cache) {
|
|
14
15
|
// TODO: here we are missing specific properties here!
|
|
15
|
-
callback(payload.comments[0]);
|
|
16
|
+
callback(LinkedObject.comment(payload.comments[0]));
|
|
16
17
|
} else {
|
|
17
18
|
ingestInCache(payload);
|
|
18
19
|
|
|
@@ -30,7 +31,7 @@ export const createCommentEventSubscriber = (
|
|
|
30
31
|
queries?.map(({ key, data }) => upsertInCache(key, data as any, { cachedAt: -1 }));
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
callback(comment.data);
|
|
34
|
+
callback(LinkedObject.comment(comment.data));
|
|
34
35
|
}
|
|
35
36
|
};
|
|
36
37
|
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
* });
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
|
-
* Observe all mutation on a given {@link Amity.
|
|
26
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
27
27
|
*
|
|
28
28
|
* @param commentId the ID of the comment to observe
|
|
29
29
|
* @param callback the function to call when new data are available
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
*/
|
|
34
34
|
export const getComment = (
|
|
35
35
|
commentId: Amity.InternalComment['commentId'],
|
|
36
|
-
callback: Amity.LiveObjectCallback<Amity.
|
|
36
|
+
callback: Amity.LiveObjectCallback<Amity.Comment>,
|
|
37
37
|
): Amity.Unsubscriber => {
|
|
38
38
|
return liveObject(commentId, callback, 'commentId', _getComment, [
|
|
39
39
|
onCommentDeleted,
|
|
@@ -76,7 +76,11 @@ export const getComments = (
|
|
|
76
76
|
const cacheKey = [
|
|
77
77
|
'comment',
|
|
78
78
|
'collection',
|
|
79
|
-
{
|
|
79
|
+
{
|
|
80
|
+
referenceId: params.referenceType,
|
|
81
|
+
referenceType: params.referenceId,
|
|
82
|
+
parentId: params?.parentId || '',
|
|
83
|
+
},
|
|
80
84
|
];
|
|
81
85
|
|
|
82
86
|
const responder = (data: Amity.CommentLiveCollectionCache) => {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { disableCache, enableCache } from '~/cache/api';
|
|
2
2
|
import {
|
|
3
3
|
client,
|
|
4
|
+
communityUser11,
|
|
4
5
|
connectClient,
|
|
5
6
|
disconnectClient,
|
|
6
7
|
generateComment,
|
|
8
|
+
generateInternalComment,
|
|
7
9
|
pause,
|
|
10
|
+
user11,
|
|
8
11
|
user12,
|
|
9
12
|
} from '~/utils/tests';
|
|
10
13
|
import { getFutureDate } from '~/core/model';
|
|
@@ -12,8 +15,13 @@ import { getFutureDate } from '~/core/model';
|
|
|
12
15
|
import { getComment } from '../getComment';
|
|
13
16
|
|
|
14
17
|
describe('getComment', () => {
|
|
15
|
-
const
|
|
16
|
-
|
|
18
|
+
const response = {
|
|
19
|
+
data: {
|
|
20
|
+
comments: [generateInternalComment()],
|
|
21
|
+
communityUsers: [communityUser11],
|
|
22
|
+
users: [user11],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
17
25
|
|
|
18
26
|
beforeAll(async () => {
|
|
19
27
|
await connectClient();
|
|
@@ -24,7 +32,6 @@ describe('getComment', () => {
|
|
|
24
32
|
});
|
|
25
33
|
|
|
26
34
|
beforeEach(enableCache);
|
|
27
|
-
|
|
28
35
|
afterEach(disableCache);
|
|
29
36
|
|
|
30
37
|
const events: [string, keyof Amity.MqttCommentEvents][] = [
|
|
@@ -35,16 +42,14 @@ describe('getComment', () => {
|
|
|
35
42
|
];
|
|
36
43
|
|
|
37
44
|
test.each(events)('%s', async (test, event) => {
|
|
38
|
-
const update = {
|
|
39
|
-
...comment,
|
|
45
|
+
const update = generateComment({
|
|
40
46
|
data: { text: 'new-text' },
|
|
41
|
-
|
|
42
|
-
};
|
|
47
|
+
});
|
|
43
48
|
|
|
44
49
|
const callback = jest.fn();
|
|
45
50
|
client.http.get = jest.fn().mockResolvedValue(response);
|
|
46
51
|
|
|
47
|
-
getComment(
|
|
52
|
+
getComment(update.commentId, callback);
|
|
48
53
|
await pause();
|
|
49
54
|
|
|
50
55
|
client.emitter.emit(event, {
|
|
@@ -71,13 +76,12 @@ describe('getComment', () => {
|
|
|
71
76
|
['should get update on comment.addReaction event', 'comment.addReaction'],
|
|
72
77
|
['should get update on comment.removeReaction event', 'comment.removeReaction'],
|
|
73
78
|
] as [string, keyof Amity.MqttCommentEvents][])('%s', async (test, event) => {
|
|
74
|
-
const update = {
|
|
75
|
-
...comment,
|
|
79
|
+
const update = generateComment({
|
|
76
80
|
data: { text: 'new-text' },
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
});
|
|
82
|
+
|
|
79
83
|
const reactor: Amity.Reactor = {
|
|
80
|
-
createdAt: getFutureDate(
|
|
84
|
+
createdAt: getFutureDate(update.updatedAt),
|
|
81
85
|
reactionId: 'like',
|
|
82
86
|
reactionName: 'like',
|
|
83
87
|
userId: user12.userId,
|
|
@@ -85,7 +89,7 @@ describe('getComment', () => {
|
|
|
85
89
|
const callback = jest.fn();
|
|
86
90
|
client.http.get = jest.fn().mockResolvedValue(response);
|
|
87
91
|
|
|
88
|
-
getComment(
|
|
92
|
+
getComment(update.commentId, callback);
|
|
89
93
|
await pause();
|
|
90
94
|
|
|
91
95
|
client.emitter.emit(event, {
|
package/src/core/device.ts
CHANGED
|
@@ -13,7 +13,8 @@ type CrossTabResponse = {
|
|
|
13
13
|
|
|
14
14
|
let tabIndex = 0;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// This logic is running on browser only
|
|
17
|
+
if (typeof BroadcastChannel !== 'undefined' && typeof window !== 'undefined') {
|
|
17
18
|
const tabId = uuid();
|
|
18
19
|
const openedTabs: { [key: CrossTabResponse['tabId']]: CrossTabResponse['tabIndex'] } = {};
|
|
19
20
|
const internalBroadcast = new BroadcastChannel('amity_ts_sdk');
|
package/src/core/events.ts
CHANGED
|
@@ -94,7 +94,12 @@ export const createEventSubscriber = <T extends keyof Amity.Events>(
|
|
|
94
94
|
|
|
95
95
|
const handler = (...payload: Parameters<typeof fn>) => {
|
|
96
96
|
log(`${namespace}(tmpid: ${timestamp}) > trigger`, payload);
|
|
97
|
-
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
fn(...payload);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
log(`${namespace}(tmpid: ${timestamp}) > error`, e);
|
|
102
|
+
}
|
|
98
103
|
};
|
|
99
104
|
|
|
100
105
|
emitter.on(event, handler);
|
|
@@ -180,29 +180,36 @@ export const filterByPostDataTypes = <T extends Amity.Post>(
|
|
|
180
180
|
collection: T[],
|
|
181
181
|
dataTypes: Amity.PostLiveCollection['dataTypes'],
|
|
182
182
|
): T[] => {
|
|
183
|
-
const
|
|
183
|
+
const postIds: T['postId'][] = [];
|
|
184
184
|
|
|
185
|
-
collection.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*/
|
|
189
|
-
if (c.dataType === 'text' && !c.children.length) return;
|
|
185
|
+
return collection.reduce((acc: T[], post: T) => {
|
|
186
|
+
// A text post with no children is just a text post
|
|
187
|
+
if (post.dataType === 'text' && !post.children.length) return acc;
|
|
190
188
|
|
|
191
|
-
if
|
|
192
|
-
|
|
189
|
+
// Skip if post is already in the collection
|
|
190
|
+
if (postIds.includes(post.postId)) return acc;
|
|
193
191
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return;
|
|
192
|
+
// Check dataType for current post
|
|
193
|
+
if (dataTypes?.includes(post.dataType)) {
|
|
194
|
+
acc.push(post);
|
|
200
195
|
}
|
|
201
196
|
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
// Check dataType for child post. this function will return all child posts in a same level of parent post (flatten)
|
|
198
|
+
if (!post.children.length) return acc;
|
|
199
|
+
|
|
200
|
+
const childPost = pullFromCache<Amity.Post>(['post', 'get', post.children[0]])?.data;
|
|
201
|
+
if (!childPost) return acc;
|
|
202
|
+
// Prevent to insert a duplicate record
|
|
203
|
+
if (postIds.includes(childPost.postId)) return acc;
|
|
204
|
+
if (dataTypes?.includes(childPost?.dataType)) return acc;
|
|
205
|
+
|
|
206
|
+
postIds.push(childPost.postId);
|
|
207
|
+
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
acc.push(childPost);
|
|
204
210
|
|
|
205
|
-
|
|
211
|
+
return acc;
|
|
212
|
+
}, []);
|
|
206
213
|
};
|
|
207
214
|
|
|
208
215
|
/**
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createComment } from '~/commentRepository/api';
|
|
2
|
-
import { communityUser11 } from '~/utils/tests';
|
|
2
|
+
import { community11, communityUser11 } from '~/utils/tests';
|
|
3
3
|
import { file11 } from './file';
|
|
4
4
|
import { post11 } from './post';
|
|
5
5
|
import { user11, user12 } from './user';
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function generateInternalComment(
|
|
8
|
+
params?: Partial<Amity.InternalComment>,
|
|
9
|
+
): Amity.InternalComment {
|
|
8
10
|
return {
|
|
9
11
|
path: '',
|
|
10
12
|
referenceType: 'post',
|
|
@@ -20,9 +22,9 @@ export function generateComment(params?: Partial<Amity.InternalComment>): Amity.
|
|
|
20
22
|
updatedAt: '2022-10-31T05:57:45.670Z',
|
|
21
23
|
createdAt: '2022-10-31T05:57:45.661Z',
|
|
22
24
|
segmentNumber: 2,
|
|
23
|
-
commentId: 'comment11',
|
|
24
|
-
userId: 'test',
|
|
25
|
-
referenceId:
|
|
25
|
+
commentId: 'comment11', // comment11._id
|
|
26
|
+
userId: 'test', // user11._id
|
|
27
|
+
referenceId: post11.postId,
|
|
26
28
|
flagCount: 0,
|
|
27
29
|
hashFlag: null,
|
|
28
30
|
children: [],
|
|
@@ -31,18 +33,23 @@ export function generateComment(params?: Partial<Amity.InternalComment>): Amity.
|
|
|
31
33
|
myReactions: [],
|
|
32
34
|
reactionsCount: 0,
|
|
33
35
|
attachments: [],
|
|
34
|
-
targetId: '
|
|
36
|
+
targetId: 'community11', // community11._id
|
|
35
37
|
targetType: 'community',
|
|
36
38
|
...params,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
export const generateComment = (params?: Partial<Amity.Comment>) => {
|
|
43
|
+
const basedComment = generateInternalComment(params);
|
|
44
|
+
return {
|
|
45
|
+
...basedComment,
|
|
39
46
|
target: {
|
|
40
47
|
type: 'community',
|
|
41
|
-
communityId: '
|
|
48
|
+
communityId: 'community11', // community11._id
|
|
42
49
|
creatorMember: communityUser11 as Amity.Membership<'community'>,
|
|
43
50
|
},
|
|
44
51
|
};
|
|
45
|
-
}
|
|
52
|
+
};
|
|
46
53
|
|
|
47
54
|
export const comment11: Amity.InternalComment = generateComment();
|
|
48
55
|
|