@amityco/ts-sdk 7.7.1-9d0f043.0 → 7.7.1-e0c5cdf.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/events.d.ts +6 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +25 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +6 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/liveReaction.d.ts +20 -0
- package/dist/@types/domains/liveReaction.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +3 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +9 -1
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channelRepository/api/createChannel.d.ts +3 -1
- package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +1 -1
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelSetMuted.d.ts +2 -0
- package/dist/channelRepository/events/onChannelSetMuted.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelSetUserMuted.d.ts +2 -0
- package/dist/channelRepository/events/onChannelSetUserMuted.d.ts.map +1 -0
- package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/internalApi/getMyMembership.d.ts +11 -0
- package/dist/channelRepository/internalApi/getMyMembership.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getMyMembership.d.ts +2 -0
- package/dist/channelRepository/observers/getMyMembership.d.ts.map +1 -0
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -1
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/index.cjs.js +6358 -5681
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +6297 -5622
- package/dist/index.umd.js +3 -3
- package/dist/liveReactionRepository/api/createReaction.d.ts +20 -0
- package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -0
- package/dist/liveReactionRepository/api/index.d.ts +2 -0
- package/dist/liveReactionRepository/api/index.d.ts.map +1 -0
- package/dist/liveReactionRepository/events/index.d.ts +2 -0
- package/dist/liveReactionRepository/events/index.d.ts.map +1 -0
- package/dist/liveReactionRepository/events/onLiveReactionCreated.d.ts +17 -0
- package/dist/liveReactionRepository/events/onLiveReactionCreated.d.ts.map +1 -0
- package/dist/liveReactionRepository/events/onLiveReactionCreatedLocal.d.ts +17 -0
- package/dist/liveReactionRepository/events/onLiveReactionCreatedLocal.d.ts.map +1 -0
- package/dist/liveReactionRepository/index.d.ts +4 -0
- package/dist/liveReactionRepository/index.d.ts.map +1 -0
- package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts +20 -0
- package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts.map +1 -0
- package/dist/liveReactionRepository/observers/getReactions.d.ts +19 -0
- package/dist/liveReactionRepository/observers/getReactions.d.ts.map +1 -0
- package/dist/liveReactionRepository/observers/index.d.ts +2 -0
- package/dist/liveReactionRepository/observers/index.d.ts.map +1 -0
- package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +26 -0
- package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -0
- package/dist/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/liveStreamPlayer/utils/eventRegister.d.ts +2 -1
- package/dist/liveStreamPlayer/utils/eventRegister.d.ts.map +1 -1
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +4 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/deleteMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/api/createPost.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/streamRepository/api/createStream.d.ts +1 -1
- package/dist/streamRepository/api/createStream.d.ts.map +1 -1
- package/dist/streamRepository/api/editStream.d.ts +18 -0
- package/dist/streamRepository/api/editStream.d.ts.map +1 -0
- package/dist/streamRepository/api/index.d.ts +1 -0
- package/dist/streamRepository/api/index.d.ts.map +1 -1
- package/dist/streamRepository/api/updateStream.d.ts +4 -1
- package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
- package/dist/streamRepository/events/index.d.ts +2 -0
- package/dist/streamRepository/events/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamViewerBanned.d.ts +17 -0
- package/dist/streamRepository/events/onStreamViewerBanned.d.ts.map +1 -0
- package/dist/streamRepository/events/onStreamViewerUnbanned.d.ts +17 -0
- package/dist/streamRepository/events/onStreamViewerUnbanned.d.ts.map +1 -0
- package/dist/streamRepository/internalApi/getLiveChat.d.ts +16 -0
- package/dist/streamRepository/internalApi/getLiveChat.d.ts.map +1 -0
- package/dist/streamRepository/internalApi/getStream.d.ts +2 -2
- package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +2 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +9 -1
- package/src/@types/core/payload.ts +32 -0
- package/src/@types/domains/channel.ts +9 -0
- package/src/@types/domains/liveReaction.ts +25 -0
- package/src/@types/domains/post.ts +3 -0
- package/src/@types/domains/stream.ts +12 -1
- package/src/@types/index.ts +1 -0
- package/src/channelRepository/api/createChannel.ts +11 -8
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +2 -0
- package/src/channelRepository/events/index.ts +1 -1
- package/src/channelRepository/events/onChannelSetMuted.ts +48 -0
- package/src/channelRepository/events/onChannelSetUserMuted.ts +65 -0
- package/src/channelRepository/internalApi/getChannel.ts +0 -1
- package/src/channelRepository/internalApi/getMyMembership.ts +37 -0
- package/src/channelRepository/observers/getChannel.ts +2 -2
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +2 -2
- package/src/channelRepository/observers/getMyMembership.ts +98 -0
- package/src/channelRepository/utils/constructChannelObject.ts +2 -2
- package/src/client/api/login.ts +2 -0
- package/src/core/events.ts +4 -1
- package/src/core/subscription.ts +10 -6
- package/src/index.ts +2 -0
- package/src/liveReactionRepository/api/createReaction.ts +58 -0
- package/src/liveReactionRepository/api/index.ts +1 -0
- package/src/liveReactionRepository/events/index.ts +1 -0
- package/src/liveReactionRepository/events/onLiveReactionCreated.ts +37 -0
- package/src/liveReactionRepository/events/onLiveReactionCreatedLocal.ts +29 -0
- package/src/liveReactionRepository/index.ts +3 -0
- package/src/liveReactionRepository/internalApi/createLiveReaction.ts +42 -0
- package/src/liveReactionRepository/observers/getReactions.ts +59 -0
- package/src/liveReactionRepository/observers/index.ts +1 -0
- package/src/liveReactionRepository/service/ReactionSyncEngine.ts +138 -0
- package/src/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.ts +19 -0
- package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
- package/src/liveStreamPlayer/utils/eventRegister.ts +16 -1
- package/src/messageRepository/api/deleteMessage.ts +16 -0
- package/src/messageRepository/observers/getMessage.ts +2 -0
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +2 -0
- package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +13 -0
- package/src/postRepository/api/createPost.ts +3 -2
- package/src/postRepository/utils/payload.ts +37 -1
- package/src/streamRepository/api/createStream.ts +4 -1
- package/src/streamRepository/api/editStream.ts +51 -0
- package/src/streamRepository/api/index.ts +1 -0
- package/src/streamRepository/api/updateStream.ts +8 -1
- package/src/streamRepository/events/index.ts +2 -0
- package/src/streamRepository/events/onStreamViewerBanned.ts +58 -0
- package/src/streamRepository/events/onStreamViewerUnbanned.ts +47 -0
- package/src/streamRepository/internalApi/getLiveChat.ts +59 -0
- package/src/streamRepository/internalApi/getStream.ts +3 -3
- package/src/streamRepository/observers/getStreamById.ts +2 -0
- package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +5 -1
- package/src/utils/linkedObject/channelLinkedObject.ts +3 -0
- package/src/utils/linkedObject/postLinkedObject.ts +28 -2
- package/src/utils/linkedObject/streamLinkedObject.ts +4 -0
- package/src/utils/postTypePredicate.ts +18 -0
- package/dist/channelRepository/events/onChannelMuted.d.ts +0 -2
- package/dist/channelRepository/events/onChannelMuted.d.ts.map +0 -1
- package/src/channelRepository/events/onChannelMuted.ts +0 -39
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Amity {
|
|
5
|
+
type RawLiveReaction = {
|
|
6
|
+
userId: string; // user's public ID
|
|
7
|
+
referenceId: string; // post's internal ID
|
|
8
|
+
referencePublicId: string; // post's public ID
|
|
9
|
+
referenceType: string; // 'post'
|
|
10
|
+
reactionName: string; // 'love
|
|
11
|
+
// date string in ISO format
|
|
12
|
+
occurredAt: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type InternalLiveReaction = RawLiveReaction;
|
|
16
|
+
|
|
17
|
+
type LiveReaction = InternalLiveReaction;
|
|
18
|
+
|
|
19
|
+
type CreateLiveReactionRequest = Omit<RawLiveReaction, 'userId' | 'referenceId' | 'occurredAt'>;
|
|
20
|
+
|
|
21
|
+
type CreateLiveReactionResponse = {
|
|
22
|
+
addedIds: string[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -74,6 +74,7 @@ declare global {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
type PostLinkObject = {
|
|
77
|
+
childrenPosts: Amity.Post[];
|
|
77
78
|
latestComments: (Amity.Comment | null)[];
|
|
78
79
|
creator: Amity.User | undefined;
|
|
79
80
|
analytics: {
|
|
@@ -83,6 +84,8 @@ declare global {
|
|
|
83
84
|
getVideoInfo: () => Amity.File<'video'> | undefined;
|
|
84
85
|
getVideoThumbnailInfo: () => Amity.File<'image'> | undefined;
|
|
85
86
|
getFileInfo: () => Amity.File<'file'> | undefined;
|
|
87
|
+
getPollInfo: () => Amity.Poll | undefined;
|
|
88
|
+
getLivestreamInfo: () => Amity.Stream | undefined;
|
|
86
89
|
getClipInfo: () => Amity.File<'clip'> | undefined;
|
|
87
90
|
};
|
|
88
91
|
|
|
@@ -73,6 +73,12 @@ declare global {
|
|
|
73
73
|
*/
|
|
74
74
|
targetId?: string; // communityId, userId, etc..
|
|
75
75
|
targetType?: string; // 'community', 'user', etc..
|
|
76
|
+
/*
|
|
77
|
+
* when stream linked with a post and a live channel.
|
|
78
|
+
*/
|
|
79
|
+
postId?: string;
|
|
80
|
+
channelId?: string;
|
|
81
|
+
channelEnabled?: boolean;
|
|
76
82
|
} & Amity.Metadata &
|
|
77
83
|
Amity.Timestamps &
|
|
78
84
|
Amity.SoftDelete;
|
|
@@ -81,9 +87,14 @@ declare global {
|
|
|
81
87
|
|
|
82
88
|
type StreamLinkedObject = {
|
|
83
89
|
moderation?: Amity.StreamModeration;
|
|
90
|
+
post?: Amity.InternalPost;
|
|
91
|
+
getLiveChat: () => Promise<Amity.Channel<'live'> | undefined>;
|
|
84
92
|
};
|
|
85
93
|
|
|
86
|
-
type Stream = Amity.InternalStream & Amity.StreamLinkedObject
|
|
94
|
+
type Stream = Omit<Amity.InternalStream & Amity.StreamLinkedObject, 'watcherUrl'> & {
|
|
95
|
+
isBanned: boolean;
|
|
96
|
+
watcherUrl: null;
|
|
97
|
+
};
|
|
87
98
|
|
|
88
99
|
type QueryStreams = {
|
|
89
100
|
isLive?: boolean;
|
package/src/@types/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
5
|
import { prepareChannelPayload } from '../utils';
|
|
6
|
-
import {
|
|
6
|
+
import { constructChannelObject } from '../utils/constructChannelObject';
|
|
7
7
|
|
|
8
8
|
/* begin_public_function
|
|
9
9
|
id: channel.create
|
|
@@ -23,11 +23,14 @@ import { constructChannelDynamicValue } from '../utils/constructChannelDynamicVa
|
|
|
23
23
|
* @async
|
|
24
24
|
*/
|
|
25
25
|
export const createChannel = async <T extends Amity.ChannelType>(
|
|
26
|
-
bundle: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
bundle: {
|
|
27
|
+
type: T;
|
|
28
|
+
userIds?: Amity.InternalUser['userId'][];
|
|
29
|
+
// For live channel linked with a livestream post
|
|
30
|
+
videoStreamId?: string;
|
|
31
|
+
postId?: string;
|
|
32
|
+
} & Pick<Amity.Channel<T>, 'displayName' | 'avatarFileId' | 'tags' | 'metadata' | 'isPublic'>,
|
|
33
|
+
): Promise<Amity.Cached<Amity.Channel<T>>> => {
|
|
31
34
|
const client = getActiveClient();
|
|
32
35
|
client.log('user/createChannel', bundle);
|
|
33
36
|
|
|
@@ -53,7 +56,7 @@ export const createChannel = async <T extends Amity.ChannelType>(
|
|
|
53
56
|
|
|
54
57
|
const { channels } = data;
|
|
55
58
|
return {
|
|
56
|
-
data:
|
|
59
|
+
data: constructChannelObject(channels[0]),
|
|
57
60
|
cachedAt,
|
|
58
61
|
};
|
|
59
62
|
};
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { prepareChannelPayload } from '~/channelRepository/utils';
|
|
25
25
|
import { onUserDeleted } from '~/channelRepository/events/onUserDeleted';
|
|
26
26
|
import { LinkedObject } from '~/utils/linkedObject';
|
|
27
|
+
import { onChannelSetUserMuted } from '~/channelRepository/events/onChannelSetUserMuted';
|
|
27
28
|
|
|
28
29
|
export class ChannelMemberLiveCollectionController extends LiveCollectionController<
|
|
29
30
|
'channelUser',
|
|
@@ -89,6 +90,7 @@ export class ChannelMemberLiveCollectionController extends LiveCollectionControl
|
|
|
89
90
|
{ fn: onChannelMemberUnbanned, action: 'onChannelMemberUnbanned' },
|
|
90
91
|
{ fn: onChannelMemberRoleAdded, action: 'onChannelMemberRoleAdded' },
|
|
91
92
|
{ fn: onChannelMemberRoleRemoved, action: 'onChannelMemberRoleRemoved' },
|
|
93
|
+
{ fn: onChannelSetUserMuted, action: 'onChannelSetUserMuted' },
|
|
92
94
|
{ fn: onUserDeleted(this.query.channelId), action: 'onChannelMemberChanged' },
|
|
93
95
|
]);
|
|
94
96
|
}
|
|
@@ -4,7 +4,7 @@ export * from './onChannelDeleted';
|
|
|
4
4
|
|
|
5
5
|
export * from './onChannelJoined';
|
|
6
6
|
export * from './onChannelLeft';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './onChannelSetMuted';
|
|
8
8
|
|
|
9
9
|
export * from './onChannelMemberAdded';
|
|
10
10
|
export * from './onChannelMemberRemoved';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
import { pullFromCache, upsertInCache } from '~/cache/api';
|
|
4
|
+
|
|
5
|
+
type CallbackFn = Amity.Listener<Amity.StaticInternalChannel>;
|
|
6
|
+
const callbacks: CallbackFn[] = [];
|
|
7
|
+
let mainDisposer: (() => void) | null = null;
|
|
8
|
+
|
|
9
|
+
const dispose = (cb: CallbackFn) => {
|
|
10
|
+
const index = callbacks.indexOf(cb);
|
|
11
|
+
if (index > -1) {
|
|
12
|
+
callbacks.splice(index, 1);
|
|
13
|
+
}
|
|
14
|
+
if (callbacks.length === 0) {
|
|
15
|
+
mainDisposer?.();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const onChannelSetMuted = (callback: Amity.Listener<Amity.StaticInternalChannel>) => {
|
|
20
|
+
if (callbacks.length === 0) {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
const filter = async (payloads: Amity.ChannelSetMutedPayload) => {
|
|
24
|
+
payloads.forEach(payload => {
|
|
25
|
+
upsertInCache(['channel', 'get', payload.channelId], {
|
|
26
|
+
// If muteTimeout > now => user is muted
|
|
27
|
+
// Otherwise => user is unmuted
|
|
28
|
+
isMuted: Date.parse(payload.muteTimeout) > Date.now(),
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const channel = pullFromCache<Amity.StaticInternalChannel>([
|
|
33
|
+
'channel',
|
|
34
|
+
'get',
|
|
35
|
+
payloads[0].channelId,
|
|
36
|
+
])?.data;
|
|
37
|
+
|
|
38
|
+
if (channel) {
|
|
39
|
+
callbacks.forEach(cb => cb(channel));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
mainDisposer = createEventSubscriber(client, 'onChannelMute', 'channel.setMuted', filter);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
callbacks.push(callback);
|
|
47
|
+
return () => dispose(callback);
|
|
48
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { pullFromCache, upsertInCache } from '~/cache/api';
|
|
5
|
+
|
|
6
|
+
type CallbackFn = (
|
|
7
|
+
channel: Amity.StaticInternalChannel,
|
|
8
|
+
member: Amity.Membership<'channel'>,
|
|
9
|
+
) => void;
|
|
10
|
+
const callbacks: CallbackFn[] = [];
|
|
11
|
+
let mainDisposer: (() => void) | null = null;
|
|
12
|
+
|
|
13
|
+
const dispose = (cb: CallbackFn) => {
|
|
14
|
+
const index = callbacks.indexOf(cb);
|
|
15
|
+
if (index > -1) {
|
|
16
|
+
callbacks.splice(index, 1);
|
|
17
|
+
}
|
|
18
|
+
if (callbacks.length === 0) {
|
|
19
|
+
mainDisposer?.();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const onChannelSetUserMuted = (
|
|
24
|
+
callback: (channel: Amity.StaticInternalChannel, member: Amity.Membership<'channel'>) => void,
|
|
25
|
+
): Amity.Unsubscriber => {
|
|
26
|
+
if (callbacks.length === 0) {
|
|
27
|
+
const client = getActiveClient();
|
|
28
|
+
|
|
29
|
+
const filter = async (payload: Amity.ChannelSetUserMutedPayload) => {
|
|
30
|
+
payload.userIds.forEach(userId =>
|
|
31
|
+
// If muteTimeout > now => user is muted
|
|
32
|
+
// Otherwise => user is unmuted
|
|
33
|
+
upsertInCache(['channelUsers', 'get', `${payload.channelId}#${userId}`], {
|
|
34
|
+
isMuted: Date.parse(payload.muteTimeout) > Date.now(),
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const channel = pullFromCache<Amity.StaticInternalChannel>([
|
|
39
|
+
'channel',
|
|
40
|
+
'get',
|
|
41
|
+
payload.channelId,
|
|
42
|
+
])?.data;
|
|
43
|
+
|
|
44
|
+
const channelUser = pullFromCache<Amity.Membership<'channel'>>([
|
|
45
|
+
'channelUsers',
|
|
46
|
+
'get',
|
|
47
|
+
`${payload.channelId}#${payload.userIds[0]}`,
|
|
48
|
+
])?.data;
|
|
49
|
+
|
|
50
|
+
if (channel && channelUser) {
|
|
51
|
+
callbacks.forEach(cb => cb(channel, channelUser));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
mainDisposer = createEventSubscriber(
|
|
56
|
+
client,
|
|
57
|
+
'onChannelUserMute',
|
|
58
|
+
'channel.setMutedUsers',
|
|
59
|
+
filter,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
callbacks.push(callback);
|
|
64
|
+
return () => dispose(callback);
|
|
65
|
+
};
|
|
@@ -9,7 +9,6 @@ import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
|
9
9
|
|
|
10
10
|
import { prepareChannelPayload } from '../utils';
|
|
11
11
|
import { prepareUnreadCountInfo } from '../utils/prepareUnreadCountInfo';
|
|
12
|
-
import { constructChannelDynamicValue } from '../utils/constructChannelDynamicValue';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* ```js
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
3
|
+
import { ASCApiError } from '~/core/errors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* get current user's membership data
|
|
8
|
+
*
|
|
9
|
+
* @returns the {@link Amity.Membership<'channel'>} objects
|
|
10
|
+
*
|
|
11
|
+
* @category Channel API
|
|
12
|
+
* @async
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const getMyMembership = (channelId: string): Amity.Cached<Amity.Membership<'channel'>> => {
|
|
16
|
+
const client = getActiveClient();
|
|
17
|
+
client.log('channel/getMyMembership.locally');
|
|
18
|
+
|
|
19
|
+
const cacheChannelUser = pullFromCache<Amity.Membership<'channel'>>([
|
|
20
|
+
'channelUsers',
|
|
21
|
+
'get',
|
|
22
|
+
`${channelId}#${client.userId}`,
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
if (!cacheChannelUser) {
|
|
26
|
+
throw new ASCApiError(
|
|
27
|
+
'Item not found!',
|
|
28
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
29
|
+
Amity.ErrorLevel.ERROR,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
data: cacheChannelUser.data,
|
|
35
|
+
cachedAt: cacheChannelUser.cachedAt,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
onChannelMemberBanned,
|
|
11
11
|
onChannelMemberRemoved,
|
|
12
12
|
onChannelMemberUnbanned,
|
|
13
|
-
|
|
13
|
+
onChannelSetMuted,
|
|
14
14
|
onChannelUpdated,
|
|
15
15
|
} from '../events';
|
|
16
16
|
import { dropFromCache, pullFromCache } from '~/cache/api';
|
|
@@ -104,7 +104,7 @@ export const getChannel = (
|
|
|
104
104
|
onChannelMemberRemoved,
|
|
105
105
|
onChannelMemberBanned,
|
|
106
106
|
onChannelMemberUnbanned,
|
|
107
|
-
|
|
107
|
+
onChannelSetMuted,
|
|
108
108
|
convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
109
109
|
convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
|
|
110
110
|
convertEventPayload(
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
onChannelLeft,
|
|
12
12
|
onChannelMemberAdded,
|
|
13
13
|
onChannelMemberRemoved,
|
|
14
|
-
onChannelMuted,
|
|
15
14
|
onChannelUpdated,
|
|
16
15
|
} from '~/channelRepository/events';
|
|
17
16
|
import {
|
|
@@ -58,6 +57,7 @@ import { onUserMessageFeedMarkerResolved } from '~/marker/events/onUserMessageFe
|
|
|
58
57
|
import { onChannelUnreadInfoUpdatedLocal } from '~/marker/events/onChannelUnreadInfoUpdatedLocal';
|
|
59
58
|
import { constructChannelObject } from '~/channelRepository/utils/constructChannelObject';
|
|
60
59
|
import { onChannelUnreadUpdatedLocal } from '~/channelRepository/events/onChannelUnreadUpdatedLocal';
|
|
60
|
+
import { onChannelSetMuted } from '~/channelRepository/events/onChannelSetMuted';
|
|
61
61
|
|
|
62
62
|
export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
63
63
|
'channel',
|
|
@@ -313,7 +313,7 @@ export class ChannelLiveCollectionController extends LiveCollectionController<
|
|
|
313
313
|
},
|
|
314
314
|
{ fn: onChannelDeleted, action: Amity.ChannelActionType.OnDelete },
|
|
315
315
|
{ fn: onChannelUpdated, action: Amity.ChannelActionType.OnUpdate },
|
|
316
|
-
{ fn:
|
|
316
|
+
{ fn: onChannelSetMuted, action: Amity.ChannelActionType.OnMute },
|
|
317
317
|
{
|
|
318
318
|
fn: (callback: Amity.Listener<Amity.StaticInternalChannel>) => {
|
|
319
319
|
return onChannelJoined(channel => {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { getActiveUser } from '~/client/api/activeUser';
|
|
2
|
+
import { getMyMembership as _getMyMembership } from '../internalApi/getMyMembership';
|
|
3
|
+
import { ASCApiError, ASCError } from '~/core/errors';
|
|
4
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
5
|
+
import { isEqual } from '~/utils/isEqual';
|
|
6
|
+
import { createQuery, runQuery } from '~/core/query';
|
|
7
|
+
import {
|
|
8
|
+
UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
|
|
9
|
+
UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
10
|
+
} from '~/utils/constants';
|
|
11
|
+
import { channelMemberLinkedObject } from '~/utils/linkedObject/channelMemberLinkedObject';
|
|
12
|
+
import { onChannelMemberBanned, onChannelMemberUnbanned } from '../events';
|
|
13
|
+
import { onChannelSetUserMuted } from '../events/onChannelSetUserMuted';
|
|
14
|
+
|
|
15
|
+
export const getMyMembership = (
|
|
16
|
+
channelId: string,
|
|
17
|
+
callback: Amity.LiveObjectCallback<Amity.Membership<'channel'> | undefined>,
|
|
18
|
+
): Amity.Unsubscriber => {
|
|
19
|
+
const { _id: userId } = getActiveUser();
|
|
20
|
+
|
|
21
|
+
if (!userId)
|
|
22
|
+
throw new ASCError(
|
|
23
|
+
'The _id has not been defined in ActiveUser',
|
|
24
|
+
Amity.ClientError.UNKNOWN_ERROR,
|
|
25
|
+
Amity.ErrorLevel.ERROR,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const { log, cache } = getActiveClient();
|
|
29
|
+
|
|
30
|
+
if (!cache) {
|
|
31
|
+
console.log('This observable object need the cache data!');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const timestamp = Date.now();
|
|
35
|
+
log(`liveMymembership(tmpid: ${timestamp}) > listen`);
|
|
36
|
+
|
|
37
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
38
|
+
|
|
39
|
+
let isUnsyncedModel = false; // for messages
|
|
40
|
+
|
|
41
|
+
let model: Amity.Membership<'channel'> | undefined;
|
|
42
|
+
|
|
43
|
+
const dispatcher = (data: Amity.LiveObject<Amity.Membership<'channel'> | undefined>) => {
|
|
44
|
+
callback({
|
|
45
|
+
...data,
|
|
46
|
+
data: data.data ? channelMemberLinkedObject(data.data) : data.data,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const realtimeRouter = (_: Amity.StaticInternalChannel, __: Amity.RawMembership<'channel'>) => {
|
|
51
|
+
const { data } = _getMyMembership(channelId);
|
|
52
|
+
|
|
53
|
+
if (isEqual(model, data)) return;
|
|
54
|
+
|
|
55
|
+
dispatcher({
|
|
56
|
+
loading: false,
|
|
57
|
+
data,
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const onFetch = () => {
|
|
62
|
+
const query = createQuery(async () => _getMyMembership(channelId));
|
|
63
|
+
|
|
64
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
65
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
66
|
+
dispatcher({
|
|
67
|
+
data,
|
|
68
|
+
origin,
|
|
69
|
+
loading: false,
|
|
70
|
+
error: new ASCApiError(
|
|
71
|
+
UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
|
|
72
|
+
Amity.ClientError.DISALOOW_UNSYNCED_OBJECT,
|
|
73
|
+
Amity.ErrorLevel.ERROR,
|
|
74
|
+
),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
isUnsyncedModel = true;
|
|
78
|
+
disposers.forEach(fn => fn());
|
|
79
|
+
} else if (!isUnsyncedModel) {
|
|
80
|
+
dispatcher({ loading, data, origin, error });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (error) {
|
|
84
|
+
disposers.forEach(fn => fn());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
disposers.push(onChannelMemberBanned(realtimeRouter));
|
|
90
|
+
disposers.push(onChannelMemberUnbanned(realtimeRouter));
|
|
91
|
+
disposers.push(onChannelSetUserMuted(realtimeRouter));
|
|
92
|
+
|
|
93
|
+
onFetch();
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
disposers.forEach(fn => fn());
|
|
97
|
+
};
|
|
98
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getChannelMessagePreviewWithUser } from '~/messagePreview/utils';
|
|
2
2
|
import { constructChannelDynamicValue } from './constructChannelDynamicValue';
|
|
3
|
-
import {
|
|
3
|
+
import { channelLinkedObject } from '~/utils/linkedObject/channelLinkedObject';
|
|
4
4
|
|
|
5
5
|
export const constructChannelObject = (channel: Amity.StaticInternalChannel): Amity.Channel => {
|
|
6
6
|
/**
|
|
@@ -10,7 +10,7 @@ export const constructChannelObject = (channel: Amity.StaticInternalChannel): Am
|
|
|
10
10
|
* 3. [LinkedObject.channel] add markAsRead >> Amity.InternalChannel -> Amity.Channel
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
return
|
|
13
|
+
return channelLinkedObject(
|
|
14
14
|
constructChannelDynamicValue(getChannelMessagePreviewWithUser(channel)),
|
|
15
15
|
);
|
|
16
16
|
};
|
package/src/client/api/login.ts
CHANGED
|
@@ -13,6 +13,7 @@ import analyticsEngineOnLoginHandler from '~/analytic/utils/analyticsEngineOnLog
|
|
|
13
13
|
import readReceiptSyncEngineOnLoginHandler from '~/client/utils/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler';
|
|
14
14
|
import legacyReadReceiptSyncEngineOnLoginHandler from '~/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler';
|
|
15
15
|
import objectResolverEngineOnLoginHandler from '~/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler';
|
|
16
|
+
import reactionSyncEngineOnLoginHandler from '~/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler';
|
|
16
17
|
import { logout } from './logout';
|
|
17
18
|
|
|
18
19
|
import { getActiveClient } from './activeClient';
|
|
@@ -201,6 +202,7 @@ export const login = async (
|
|
|
201
202
|
markReadEngineOnLoginHandler(),
|
|
202
203
|
analyticsEngineOnLoginHandler(),
|
|
203
204
|
objectResolverEngineOnLoginHandler(),
|
|
205
|
+
reactionSyncEngineOnLoginHandler(),
|
|
204
206
|
);
|
|
205
207
|
|
|
206
208
|
if (client.useLegacyUnreadCount) {
|
package/src/core/events.ts
CHANGED
|
@@ -32,7 +32,10 @@ const MQTT_EVENTS = [
|
|
|
32
32
|
'video-streaming.didFlag',
|
|
33
33
|
'video-streaming.didTerminate',
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
'video-streaming.viewerDidBan',
|
|
36
|
+
'video-streaming.viewerDidUnban',
|
|
37
|
+
|
|
38
|
+
'liveReaction.created',
|
|
36
39
|
] as const;
|
|
37
40
|
|
|
38
41
|
/** @hidden */
|
package/src/core/subscription.ts
CHANGED
|
@@ -154,6 +154,16 @@ export const getSmartFeedMessageTopic = (): string => {
|
|
|
154
154
|
return `${getNetworkId(user)}/smartfeed/${user._id}/messages`;
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
+
export const getLiveStreamTopic = (): string => {
|
|
158
|
+
const user = getActiveUser();
|
|
159
|
+
|
|
160
|
+
return `${getNetworkId(user)}/videostreaming`;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const getLiveReactionTopic = (post: Amity.Post) => {
|
|
164
|
+
return `${post.path}/liveReaction`;
|
|
165
|
+
};
|
|
166
|
+
|
|
157
167
|
let mqttAccessToken: string;
|
|
158
168
|
let mqttUserId: string;
|
|
159
169
|
|
|
@@ -168,9 +178,3 @@ export function subscribeTopic(
|
|
|
168
178
|
|
|
169
179
|
return mqtt.subscribe(topic, callback);
|
|
170
180
|
}
|
|
171
|
-
|
|
172
|
-
export const getLiveStreamTopic = (): string => {
|
|
173
|
-
const user = getActiveUser();
|
|
174
|
-
|
|
175
|
-
return `${getNetworkId(user)}/videostreaming`;
|
|
176
|
-
};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
2
|
+
import ReactionSyncEngine from '../service/ReactionSyncEngine';
|
|
3
|
+
|
|
4
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
5
|
+
// TODO: confirm id
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: live_reaction.create
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
12
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @param referenceId that is target post's ID linked with a livestream
|
|
17
|
+
* @param reactionName that is the reaction name
|
|
18
|
+
* @param streamId stream id
|
|
19
|
+
* @returns a success boolean if the reaction was added
|
|
20
|
+
*
|
|
21
|
+
* @category Live Reaction API
|
|
22
|
+
* @async
|
|
23
|
+
*/
|
|
24
|
+
export const createReaction = async ({
|
|
25
|
+
referenceId,
|
|
26
|
+
referenceType,
|
|
27
|
+
reactionName,
|
|
28
|
+
streamId,
|
|
29
|
+
}: Pick<Amity.CreateLiveReactionRequest, 'referenceType' | 'reactionName'> & {
|
|
30
|
+
referenceId: string;
|
|
31
|
+
streamId: string;
|
|
32
|
+
}): Promise<boolean> => {
|
|
33
|
+
const client = getActiveClient();
|
|
34
|
+
|
|
35
|
+
client.log('live_reaction/createReaction', {
|
|
36
|
+
referenceId,
|
|
37
|
+
referenceType,
|
|
38
|
+
reactionName,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const reactionSynceEngine = ReactionSyncEngine.getInstance();
|
|
42
|
+
|
|
43
|
+
const reaction = {
|
|
44
|
+
reactionName,
|
|
45
|
+
referencePublicId: referenceId,
|
|
46
|
+
referenceType,
|
|
47
|
+
streamId,
|
|
48
|
+
occurredAt: new Date().toISOString(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
reactionSynceEngine.createLiveReaction(reaction);
|
|
53
|
+
|
|
54
|
+
fireEvent('local.liveReaction.created', [{ ...reaction, userId: client.userId!, referenceId }]);
|
|
55
|
+
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
/* end_public_function */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createReaction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './onLiveReactionCreated';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { onLiveReactionCreated } from '@amityco/ts-sdk'
|
|
6
|
+
* const dispose = onLiveReactionCreated(reactions => {
|
|
7
|
+
* // ...
|
|
8
|
+
* })
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Fired when a batch of {@link Amity.LiveReaction} has been created
|
|
12
|
+
*
|
|
13
|
+
* @param callback The function to call when the event was fired
|
|
14
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
|
+
*
|
|
16
|
+
* @category Live Reaction Events
|
|
17
|
+
*/
|
|
18
|
+
export const onLiveReactionCreated = (
|
|
19
|
+
callback: Amity.Listener<Amity.LiveReaction[]>,
|
|
20
|
+
): Amity.Unsubscriber => {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
const filter = (rawPayload: Amity.LiveReactionPayload) => {
|
|
24
|
+
if (rawPayload.reactions.length > 0) {
|
|
25
|
+
// TODO: check with BE if user id is internal or pulbic id
|
|
26
|
+
const filteredPayload = rawPayload.reactions.filter(({ userId }) => userId !== client.userId);
|
|
27
|
+
callback(filteredPayload);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return createEventSubscriber(
|
|
32
|
+
client,
|
|
33
|
+
'live_reaction/onLiveReactionCreated',
|
|
34
|
+
'liveReaction.created',
|
|
35
|
+
filter,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { onLiveReactionCreatedLocal } from '@amityco/ts-sdk'
|
|
6
|
+
* const dispose = onLiveReactionCreatedLocal(reactions => {
|
|
7
|
+
* // ...
|
|
8
|
+
* })
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Fired when a batch of {@link Amity.LiveReaction} has been created
|
|
12
|
+
*
|
|
13
|
+
* @param callback The function to call when the event was fired
|
|
14
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
|
+
*
|
|
16
|
+
* @category Live Reaction Events
|
|
17
|
+
*/
|
|
18
|
+
export const onLiveReactionCreatedLocal = (
|
|
19
|
+
callback: Amity.Listener<Amity.LiveReaction[]>,
|
|
20
|
+
): Amity.Unsubscriber => {
|
|
21
|
+
const client = getActiveClient();
|
|
22
|
+
|
|
23
|
+
return createEventSubscriber(
|
|
24
|
+
client,
|
|
25
|
+
'live_reaction/onLiveReactionCreated',
|
|
26
|
+
'local.liveReaction.created',
|
|
27
|
+
callback,
|
|
28
|
+
);
|
|
29
|
+
};
|