@amityco/ts-sdk 7.6.1-a0961ea.0 → 7.6.1-b8014723.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.
Files changed (174) hide show
  1. package/dist/@types/core/events.d.ts +6 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +26 -1
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/channel.d.ts +5 -0
  6. package/dist/@types/domains/channel.d.ts.map +1 -1
  7. package/dist/@types/domains/content.d.ts +2 -8
  8. package/dist/@types/domains/content.d.ts.map +1 -1
  9. package/dist/@types/domains/feed.d.ts +1 -2
  10. package/dist/@types/domains/feed.d.ts.map +1 -1
  11. package/dist/@types/domains/file.d.ts +1 -3
  12. package/dist/@types/domains/file.d.ts.map +1 -1
  13. package/dist/@types/domains/liveReaction.d.ts +20 -0
  14. package/dist/@types/domains/liveReaction.d.ts.map +1 -0
  15. package/dist/@types/domains/post.d.ts +3 -3
  16. package/dist/@types/domains/post.d.ts.map +1 -1
  17. package/dist/@types/domains/stream.d.ts +9 -1
  18. package/dist/@types/domains/stream.d.ts.map +1 -1
  19. package/dist/@types/index.d.ts +1 -0
  20. package/dist/@types/index.d.ts.map +1 -1
  21. package/dist/channelRepository/api/createChannel.d.ts +3 -1
  22. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  23. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
  24. package/dist/channelRepository/events/index.d.ts +1 -1
  25. package/dist/channelRepository/events/index.d.ts.map +1 -1
  26. package/dist/channelRepository/events/onChannelSetMuted.d.ts +2 -0
  27. package/dist/channelRepository/events/onChannelSetMuted.d.ts.map +1 -0
  28. package/dist/channelRepository/events/onChannelSetUserMuted.d.ts +2 -0
  29. package/dist/channelRepository/events/onChannelSetUserMuted.d.ts.map +1 -0
  30. package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -1
  31. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  32. package/dist/client/api/login.d.ts.map +1 -1
  33. package/dist/communityRepository/api/getCommunity.d.ts +1 -1
  34. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  35. package/dist/core/events.d.ts +3 -3
  36. package/dist/core/events.d.ts.map +1 -1
  37. package/dist/core/subscription.d.ts +2 -1
  38. package/dist/core/subscription.d.ts.map +1 -1
  39. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +1 -1
  40. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
  41. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  42. package/dist/fileRepository/api/index.d.ts +0 -1
  43. package/dist/fileRepository/api/index.d.ts.map +1 -1
  44. package/dist/index.cjs.js +6341 -5860
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.esm.js +6182 -5703
  48. package/dist/index.umd.js +3 -3
  49. package/dist/liveReactionRepository/api/createReaction.d.ts +20 -0
  50. package/dist/liveReactionRepository/api/createReaction.d.ts.map +1 -0
  51. package/dist/liveReactionRepository/api/index.d.ts +2 -0
  52. package/dist/liveReactionRepository/api/index.d.ts.map +1 -0
  53. package/dist/liveReactionRepository/events/index.d.ts +2 -0
  54. package/dist/liveReactionRepository/events/index.d.ts.map +1 -0
  55. package/dist/liveReactionRepository/events/onLiveReactionCreated.d.ts +17 -0
  56. package/dist/liveReactionRepository/events/onLiveReactionCreated.d.ts.map +1 -0
  57. package/dist/liveReactionRepository/events/onLiveReactionCreatedLocal.d.ts +17 -0
  58. package/dist/liveReactionRepository/events/onLiveReactionCreatedLocal.d.ts.map +1 -0
  59. package/dist/liveReactionRepository/index.d.ts +4 -0
  60. package/dist/liveReactionRepository/index.d.ts.map +1 -0
  61. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts +20 -0
  62. package/dist/liveReactionRepository/internalApi/createLiveReaction.d.ts.map +1 -0
  63. package/dist/liveReactionRepository/observers/getReactions.d.ts +19 -0
  64. package/dist/liveReactionRepository/observers/getReactions.d.ts.map +1 -0
  65. package/dist/liveReactionRepository/observers/index.d.ts +2 -0
  66. package/dist/liveReactionRepository/observers/index.d.ts.map +1 -0
  67. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts +26 -0
  68. package/dist/liveReactionRepository/service/ReactionSyncEngine.d.ts.map +1 -0
  69. package/dist/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.d.ts +3 -0
  70. package/dist/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.d.ts.map +1 -0
  71. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +4 -0
  72. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  73. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  74. package/dist/messageRepository/api/deleteMessage.d.ts.map +1 -1
  75. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  76. package/dist/messageRepository/observers/getMessages/MessageLiveCollectionController.d.ts.map +1 -1
  77. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  78. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  79. package/dist/postRepository/api/index.d.ts +0 -1
  80. package/dist/postRepository/api/index.d.ts.map +1 -1
  81. package/dist/postRepository/utils/payload.d.ts.map +1 -1
  82. package/dist/streamRepository/api/createStream.d.ts +1 -1
  83. package/dist/streamRepository/api/createStream.d.ts.map +1 -1
  84. package/dist/streamRepository/api/editStream.d.ts +18 -0
  85. package/dist/streamRepository/api/editStream.d.ts.map +1 -0
  86. package/dist/streamRepository/api/index.d.ts +1 -0
  87. package/dist/streamRepository/api/index.d.ts.map +1 -1
  88. package/dist/streamRepository/api/updateStream.d.ts +4 -1
  89. package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
  90. package/dist/streamRepository/events/onStreamViewerBanned.d.ts +17 -0
  91. package/dist/streamRepository/events/onStreamViewerBanned.d.ts.map +1 -0
  92. package/dist/streamRepository/events/onStreamViewerUnbanned.d.ts +17 -0
  93. package/dist/streamRepository/events/onStreamViewerUnbanned.d.ts.map +1 -0
  94. package/dist/streamRepository/internalApi/getLiveChat.d.ts +16 -0
  95. package/dist/streamRepository/internalApi/getLiveChat.d.ts.map +1 -0
  96. package/dist/streamRepository/internalApi/getStream.d.ts +2 -2
  97. package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -1
  98. package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
  99. package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +1 -1
  100. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  101. package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +1 -1
  102. package/dist/utils/postTypePredicate.d.ts +2 -1
  103. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  104. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  105. package/package.json +1 -1
  106. package/src/@types/core/events.ts +9 -1
  107. package/src/@types/core/payload.ts +33 -1
  108. package/src/@types/domains/channel.ts +6 -0
  109. package/src/@types/domains/content.ts +0 -10
  110. package/src/@types/domains/feed.ts +1 -2
  111. package/src/@types/domains/file.ts +0 -5
  112. package/src/@types/domains/liveReaction.ts +25 -0
  113. package/src/@types/domains/post.ts +3 -4
  114. package/src/@types/domains/stream.ts +12 -1
  115. package/src/@types/index.ts +1 -0
  116. package/src/channelRepository/api/createChannel.ts +12 -9
  117. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +2 -0
  118. package/src/channelRepository/events/index.ts +1 -1
  119. package/src/channelRepository/events/onChannelSetMuted.ts +48 -0
  120. package/src/channelRepository/events/onChannelSetUserMuted.ts +67 -0
  121. package/src/channelRepository/internalApi/getChannel.ts +0 -1
  122. package/src/channelRepository/observers/getChannel.ts +2 -2
  123. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +2 -2
  124. package/src/channelRepository/utils/constructChannelObject.ts +2 -2
  125. package/src/client/api/login.ts +2 -0
  126. package/src/communityRepository/api/getCommunity.ts +9 -0
  127. package/src/core/events.ts +1 -0
  128. package/src/core/subscription.ts +10 -6
  129. package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +1 -1
  130. package/src/feedRepository/api/queryGlobalFeed.ts +1 -3
  131. package/src/fileRepository/api/index.ts +0 -1
  132. package/src/index.ts +2 -0
  133. package/src/liveReactionRepository/api/createReaction.ts +58 -0
  134. package/src/liveReactionRepository/api/index.ts +1 -0
  135. package/src/liveReactionRepository/events/index.ts +1 -0
  136. package/src/liveReactionRepository/events/onLiveReactionCreated.ts +37 -0
  137. package/src/liveReactionRepository/events/onLiveReactionCreatedLocal.ts +29 -0
  138. package/src/liveReactionRepository/index.ts +3 -0
  139. package/src/liveReactionRepository/internalApi/createLiveReaction.ts +42 -0
  140. package/src/liveReactionRepository/observers/getReactions.ts +59 -0
  141. package/src/liveReactionRepository/observers/index.ts +1 -0
  142. package/src/liveReactionRepository/service/ReactionSyncEngine.ts +138 -0
  143. package/src/liveReactionRepository/utils/ReactionSyncEngineOnLoginHandler.ts +19 -0
  144. package/src/messageRepository/api/deleteMessage.ts +16 -0
  145. package/src/messageRepository/observers/getMessage.ts +2 -0
  146. package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +2 -0
  147. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +13 -0
  148. package/src/postRepository/api/createPost.ts +3 -2
  149. package/src/postRepository/api/index.ts +0 -2
  150. package/src/postRepository/api/queryPosts.ts +1 -1
  151. package/src/postRepository/observers/getPosts/PostPaginationController.ts +1 -1
  152. package/src/postRepository/utils/payload.ts +37 -1
  153. package/src/streamRepository/api/createStream.ts +4 -1
  154. package/src/streamRepository/api/editStream.ts +51 -0
  155. package/src/streamRepository/api/index.ts +1 -0
  156. package/src/streamRepository/api/updateStream.ts +8 -1
  157. package/src/streamRepository/events/onStreamViewerBanned.ts +58 -0
  158. package/src/streamRepository/events/onStreamViewerUnbanned.ts +47 -0
  159. package/src/streamRepository/internalApi/getLiveChat.ts +59 -0
  160. package/src/streamRepository/internalApi/getStream.ts +3 -3
  161. package/src/streamRepository/observers/getStreamById.ts +2 -0
  162. package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +5 -1
  163. package/src/utils/linkedObject/postLinkedObject.ts +25 -6
  164. package/src/utils/linkedObject/streamLinkedObject.ts +4 -0
  165. package/src/utils/postTypePredicate.ts +12 -3
  166. package/dist/channelRepository/events/onChannelMuted.d.ts +0 -2
  167. package/dist/channelRepository/events/onChannelMuted.d.ts.map +0 -1
  168. package/dist/fileRepository/api/uploadClip.d.ts +0 -17
  169. package/dist/fileRepository/api/uploadClip.d.ts.map +0 -1
  170. package/dist/postRepository/api/createClipPost.d.ts +0 -32
  171. package/dist/postRepository/api/createClipPost.d.ts.map +0 -1
  172. package/src/channelRepository/events/onChannelMuted.ts +0 -39
  173. package/src/fileRepository/api/uploadClip.ts +0 -71
  174. package/src/postRepository/api/createClipPost.ts +0 -62
@@ -0,0 +1,47 @@
1
+ import { getActiveClient } from '~/client/api';
2
+ import { createEventSubscriber } from '~/core/events';
3
+ import { mergeInCache, pullFromCache } from '~/cache/api';
4
+ import { getStream } from '../internalApi/getStream';
5
+
6
+ /**
7
+ * ```js
8
+ * import { onStreamViewerUnbanned } from '@amityco/ts-sdk'
9
+ * const dispose = onStreamViewerBanned(stream => {
10
+ * // ...
11
+ * })
12
+ * ```
13
+ *
14
+ * Fired when a user in channel linked to stream has been unbanned
15
+ *
16
+ * @param callback The function to call when the event was fired
17
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
18
+ *
19
+ * @category Stream Events
20
+ */
21
+ export const onStreamViewerUnbanned = (
22
+ callback: Amity.Listener<Amity.InternalStream>,
23
+ ): Amity.Unsubscriber => {
24
+ const client = getActiveClient();
25
+
26
+ const filter = async (payloads: Amity.StreamViewerUnbanPayload) => {
27
+ // Get new stream object to restore stream watcherUrl in cache
28
+ await Promise.all(payloads.map(({ streamId }) => getStream(streamId)));
29
+
30
+ const stream = pullFromCache<Amity.InternalStream>([
31
+ 'stream',
32
+ 'get',
33
+ payloads[0].streamId,
34
+ ])?.data;
35
+
36
+ if (!stream) return;
37
+
38
+ callback(stream);
39
+ };
40
+
41
+ return createEventSubscriber(
42
+ client,
43
+ 'stream/onStreamViewerDidUnban',
44
+ 'video-streaming.viewerDidUnban',
45
+ filter,
46
+ );
47
+ };
@@ -0,0 +1,59 @@
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
+ import { mergeInCache, pullFromCache } from '~/cache/api';
3
+ import { createChannel } from '~/channelRepository/api/createChannel';
4
+ import { channelLinkedObject } from '~/utils/linkedObject/channelLinkedObject';
5
+ import { getChannel } from '~/channelRepository/internalApi/getChannel';
6
+ import { constructChannelObject } from '~/channelRepository/utils/constructChannelObject';
7
+
8
+ /**
9
+ * ```js
10
+ * import { getStream } from '@amityco/ts-sdk'
11
+ * const stream = await getStream('foobar')
12
+ * ```
13
+ *
14
+ * Fetches a {@link Amity.Channel} object linked with a current stream
15
+ *
16
+ * @param stream {@link Amity.Stream} that has linked live channel
17
+ * @returns the associated {@link Amity.Channel<'live'>} object
18
+ *
19
+ * @category Stream API
20
+ * @async
21
+ */
22
+
23
+ export const getLiveChat = async (
24
+ stream: Amity.InternalStream,
25
+ ): Promise<Amity.Channel<'live'> | undefined> => {
26
+ const client = getActiveClient();
27
+ client.log('stream/getLiveChat', stream.streamId);
28
+
29
+ if (stream.channelId) {
30
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
31
+ 'channel',
32
+ 'get',
33
+ stream.channelId,
34
+ ])?.data;
35
+
36
+ if (channel) return channelLinkedObject(constructChannelObject(channel));
37
+
38
+ const { data } = await getChannel(stream.channelId);
39
+ return channelLinkedObject(constructChannelObject(data));
40
+ }
41
+ // No Channel ID
42
+ // streamer: create a new live channel
43
+ if (stream.userId === client.userId) {
44
+ const { data: channel } = await createChannel({
45
+ type: 'live',
46
+ postId: stream.postId,
47
+ videoStreamId: stream.streamId,
48
+ });
49
+
50
+ // Update channelId to stream object in cache
51
+ mergeInCache(['stream', 'get', stream.streamId], {
52
+ channelId: channel.channelId,
53
+ });
54
+
55
+ return channel;
56
+ }
57
+ // watcher: return undefined
58
+ return undefined;
59
+ };
@@ -22,7 +22,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
22
22
  */
23
23
  export const getStream = async (
24
24
  streamId: Amity.Stream['streamId'],
25
- ): Promise<Amity.Cached<Amity.Stream>> => {
25
+ ): Promise<Amity.Cached<Amity.InternalStream>> => {
26
26
  const client = getActiveClient();
27
27
  client.log('stream/getStream', streamId);
28
28
 
@@ -57,13 +57,13 @@ export const getStream = async (
57
57
  */
58
58
  getStream.locally = (
59
59
  streamId: Amity.Stream['streamId'],
60
- ): Amity.Cached<Amity.Stream> | undefined => {
60
+ ): Amity.Cached<Amity.InternalStream> | undefined => {
61
61
  const client = getActiveClient();
62
62
  client.log('stream/getStream', streamId);
63
63
 
64
64
  if (!client.cache) return;
65
65
 
66
- const cached = pullFromCache<Amity.Stream>(['stream', 'get', streamId]);
66
+ const cached = pullFromCache<Amity.InternalStream>(['stream', 'get', streamId]);
67
67
 
68
68
  if (!cached) return;
69
69
 
@@ -8,6 +8,7 @@ import { onStreamTerminated } from '~/streamRepository/events/onStreamTerminated
8
8
  import { LinkedObject } from '~/utils/linkedObject';
9
9
  import { getStream as _getStream } from '../internalApi/getStream';
10
10
  import { onStreamRecorded, onStreamStarted, onStreamStopped } from '../events';
11
+ import { onStreamViewerBanned } from '../events/onStreamViewerBanned';
11
12
 
12
13
  /* begin_public_function
13
14
  id: stream.get
@@ -45,6 +46,7 @@ export const getStreamById = (
45
46
  onStreamStopped,
46
47
  onStreamFlagged,
47
48
  onStreamTerminated,
49
+ onStreamViewerBanned,
48
50
  ]);
49
51
  };
50
52
  /* end_public_function */
@@ -12,6 +12,8 @@ import {
12
12
  } from '~/streamRepository/events';
13
13
  import { GetStreamsPageController } from '~/streamRepository/observers/getStreams/GetStreamsPageController';
14
14
  import { GetStreamsQueryStreamController } from '~/streamRepository/observers/getStreams/GetStreamsQueryStreamController';
15
+ import { onStreamViewerBanned } from '~/streamRepository/events/onStreamViewerBanned';
16
+ import { onStreamViewerUnbanned } from '~/streamRepository/events/onStreamViewerUnbanned';
15
17
 
16
18
  export class GetStreamsLiveCollectionController extends LiveCollectionController<
17
19
  'stream',
@@ -77,6 +79,8 @@ export class GetStreamsLiveCollectionController extends LiveCollectionController
77
79
  { fn: onStreamStopped, action: 'onStreamStopped' },
78
80
  { fn: onStreamFlagged, action: 'onStreamFlagged' },
79
81
  { fn: onStreamTerminated, action: 'onStreamTerminated' },
82
+ { fn: onStreamViewerBanned, action: 'onStreamViewerBanned' },
83
+ { fn: onStreamViewerUnbanned, action: 'onStreamViewerUnbanned' },
80
84
  ]);
81
85
  }
82
86
 
@@ -102,7 +106,7 @@ export class GetStreamsLiveCollectionController extends LiveCollectionController
102
106
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
103
107
  }
104
108
 
105
- private applyFilter = (data: Amity.InternalStream[]): Amity.InternalStream[] => {
109
+ private applyFilter = (data: Amity.Stream[]): Amity.Stream[] => {
106
110
  let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
107
111
 
108
112
  streams = streams.sort(
@@ -3,16 +3,22 @@ import { commentLinkedObject } from '~/utils/linkedObject/commentLinkedObject';
3
3
  import AnalyticsEngine from '../../analytic/service/analytic/AnalyticsEngine';
4
4
  import { userLinkedObject } from './userLinkedObject';
5
5
  import {
6
- isAmityClipPost,
7
6
  isAmityFilePost,
8
7
  isAmityImagePost,
8
+ isAmityLivestreamPost,
9
+ isAmityPollPost,
9
10
  isAmityVideoPost,
10
11
  } from '../postTypePredicate';
12
+ import { streamLinkedObject } from './streamLinkedObject';
13
+ import { isNonNullable } from '..';
11
14
 
12
15
  export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
13
16
  return {
14
17
  ...post,
15
-
18
+ childrenPosts: post.children
19
+ .map(childPost => pullFromCache<Amity.InternalPost>(['post', 'get', childPost])?.data)
20
+ .filter(isNonNullable)
21
+ .map(postLinkedObject),
16
22
  analytics: {
17
23
  markAsViewed: () => {
18
24
  const analyticsEngineInstance = AnalyticsEngine.getInstance();
@@ -70,10 +76,23 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
70
76
  : undefined;
71
77
  },
72
78
 
73
- getClipInfo(): Amity.File<'clip'> | undefined {
74
- return isAmityClipPost(post)
75
- ? pullFromCache<Amity.File<'clip'>>(['file', 'get', post?.data?.fileId])?.data
76
- : undefined;
79
+ getLivestreamInfo(): Amity.Stream | undefined {
80
+ if (!isAmityLivestreamPost(post)) return;
81
+ const cache = pullFromCache<Amity.InternalStream>([
82
+ 'stream',
83
+ 'get',
84
+ post?.data?.streamId,
85
+ ])?.data;
86
+ if (!cache) return;
87
+
88
+ return streamLinkedObject(cache);
89
+ },
90
+
91
+ getPollInfo(): Amity.Poll | undefined {
92
+ if (!isAmityPollPost(post)) return;
93
+ const cache = pullFromCache<Amity.Poll>(['poll', 'get', post?.data?.pollId])?.data;
94
+ if (!cache) return;
95
+ return cache;
77
96
  },
78
97
  };
79
98
  };
@@ -1,4 +1,5 @@
1
1
  import { pullFromCache } from '~/cache/api';
2
+ import { getLiveChat as _getLiveChat } from '~/streamRepository/internalApi/getLiveChat';
2
3
 
3
4
  export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream => {
4
5
  return {
@@ -18,5 +19,8 @@ export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream =
18
19
  get user() {
19
20
  return pullFromCache<Amity.User>(['user', 'get', stream.userId])?.data;
20
21
  },
22
+ getLiveChat: () => _getLiveChat(stream),
23
+ isBanned: !stream.watcherUrl,
24
+ watcherUrl: null,
21
25
  };
22
26
  };
@@ -26,11 +26,20 @@ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'
26
26
  );
27
27
  }
28
28
 
29
- export function isAmityClipPost(post: Amity.InternalPost): post is Amity.Post<'clip'> {
29
+ export function isAmityLivestreamPost(post: Amity.InternalPost): post is Amity.Post<'liveStream'> {
30
30
  return !!(
31
31
  post.data &&
32
32
  typeof post.data !== 'string' &&
33
- 'fileId' in post.data &&
34
- post.dataType === 'clip'
33
+ 'streamId' in post.data &&
34
+ post.dataType === 'liveStream'
35
+ );
36
+ }
37
+
38
+ export function isAmityPollPost(post: Amity.InternalPost): post is Amity.Post<'poll'> {
39
+ return !!(
40
+ post.data &&
41
+ typeof post.data !== 'string' &&
42
+ 'pollId' in post.data &&
43
+ post.dataType === 'poll'
35
44
  );
36
45
  }
@@ -1,2 +0,0 @@
1
- export declare const onChannelMuted: (callback: Amity.Listener<Amity.StaticInternalChannel>) => () => void;
2
- //# sourceMappingURL=onChannelMuted.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onChannelMuted.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/events/onChannelMuted.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,cAAc,aAAc,MAAM,QAAQ,CAAC,MAAM,qBAAqB,CAAC,eAgBnF,CAAC"}
@@ -1,17 +0,0 @@
1
- /**
2
- * ```js
3
- * import { FileRepository } from '@amityco/ts-sdk'
4
- * const created = await FileRepository.uploadClip(formData)
5
- * ```
6
- *
7
- * Creates an {@link Amity.File}
8
- *
9
- * @param formData The data necessary to create a new {@link Amity.File}
10
- * @param onProgress The callback to track the upload progress
11
- * @returns The newly created {@link Amity.File}
12
- *
13
- * @category File API
14
- * @async
15
- */
16
- export declare const uploadClip: (formData: FormData, feedType?: Amity.ContentFeedType, onProgress?: ((percent: number) => void) | undefined) => Promise<Amity.Cached<Amity.File<'clip'>[]>>;
17
- //# sourceMappingURL=uploadClip.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uploadClip.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadClip.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,aACX,QAAQ,aACP,MAAM,eAAe,0BACT,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CA2C5C,CAAC"}
@@ -1,32 +0,0 @@
1
- /**
2
- * ```js
3
- * import { PostRepository } from '@amityco/ts-sdk'
4
- * const created = await PostRepository.createClipPost({
5
- * targetType: 'user',
6
- * targetId: 'foobar',
7
- * dataType: 'clip',
8
- * data: { text: 'hello world' },
9
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
10
- * }))
11
- * ```
12
- *
13
- * Creates an {@link Amity.Post}
14
- *
15
- * @param bundle The data necessary to create a new {@link Amity.Post}
16
- * @returns The newly created {@link Amity.Post}
17
- *
18
- * @category Post API
19
- * @async
20
- */
21
- export declare const createClipPost: <T extends string>(bundle: Pick<Amity.Post<T>, "targetType" | "targetId"> & Partial<Pick<Amity.Post<T>, "metadata" | "tags" | "mentionees">> & {
22
- data: {
23
- [k: string]: any;
24
- };
25
- attachments: {
26
- type: T;
27
- fileId: Amity.File['fileId'];
28
- displayMode?: Amity.ClipDisplayMode | undefined;
29
- isMuted?: boolean | undefined;
30
- }[];
31
- }) => Promise<Amity.Cached<Amity.Post>>;
32
- //# sourceMappingURL=createClipPost.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createClipPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/createClipPost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc;;;;;;gBAMX,UAAU,CAAC,QAAQ,CAAC;;;;MAKjC,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAmBlC,CAAC"}
@@ -1,39 +0,0 @@
1
- import { getActiveClient } from '~/client/api/activeClient';
2
- import { createEventSubscriber } from '~/core/events';
3
-
4
- import { ingestInCache } from '~/cache/api/ingestInCache';
5
-
6
- import { prepareChannelPayload } from '../utils';
7
- import { constructChannelDynamicValue } from '../utils/constructChannelDynamicValue';
8
-
9
- type CallbackFn = Amity.Listener<Amity.StaticInternalChannel>;
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 onChannelMuted = (callback: Amity.Listener<Amity.StaticInternalChannel>) => {
24
- if (callbacks.length === 0) {
25
- const client = getActiveClient();
26
-
27
- const filter = async (payload: Amity.ChannelPayload) => {
28
- const data = await prepareChannelPayload(payload);
29
-
30
- ingestInCache(data);
31
- callbacks.forEach(cb => cb(data.channels[0]));
32
- };
33
-
34
- mainDisposer = createEventSubscriber(client, 'onChannelMuted', 'channel.setMuted', filter);
35
- }
36
-
37
- callbacks.push(callback);
38
- return () => dispose(callback);
39
- };
@@ -1,71 +0,0 @@
1
- import { getActiveClient } from '~/client/api/activeClient';
2
- import { ingestInCache } from '~/cache/api/ingestInCache';
3
- import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
4
-
5
- /* begin_public_function
6
- id: file.upload.clip
7
- */
8
- /**
9
- * ```js
10
- * import { FileRepository } from '@amityco/ts-sdk'
11
- * const created = await FileRepository.uploadClip(formData)
12
- * ```
13
- *
14
- * Creates an {@link Amity.File}
15
- *
16
- * @param formData The data necessary to create a new {@link Amity.File}
17
- * @param onProgress The callback to track the upload progress
18
- * @returns The newly created {@link Amity.File}
19
- *
20
- * @category File API
21
- * @async
22
- */
23
- export const uploadClip = async (
24
- formData: FormData,
25
- feedType?: Amity.ContentFeedType,
26
- onProgress?: (percent: number) => void,
27
- ): Promise<Amity.Cached<Amity.File<'clip'>[]>> => {
28
- const client = getActiveClient();
29
- client.log('file/uploadClip', formData);
30
-
31
- const file = formData.get('files');
32
-
33
- if (!file) throw new Error('The formData object must have a `files` key.');
34
-
35
- const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
36
- formData.append('accessType', accessType);
37
-
38
- formData.append('preferredFilename', (file as File).name);
39
-
40
- if (feedType) {
41
- formData.append('feedType', feedType);
42
- }
43
-
44
- const headers =
45
- 'getHeaders' in formData
46
- ? (formData as any).getHeaders()
47
- : { 'content-type': 'multipart/form-data' };
48
-
49
- const { data } = await client.upload.post<Amity.CreateFilePayload<'clip'>>(
50
- '/api/v4/clips',
51
- formData,
52
- {
53
- headers,
54
- onUploadProgress({ loaded, total = 100 }) {
55
- onProgress && onProgress(Math.round((loaded * 100) / total));
56
- },
57
- },
58
- );
59
-
60
- // API-FIX: payload should be serialized properly
61
- // const { files } = data
62
-
63
- const cachedAt = client.cache && Date.now();
64
- if (client.cache) ingestInCache({ files: data }, { cachedAt });
65
-
66
- return {
67
- data,
68
- cachedAt,
69
- };
70
- };
71
- /* end_public_function */
@@ -1,62 +0,0 @@
1
- import { getActiveClient } from '~/client/api/activeClient';
2
-
3
- import { ingestInCache } from '~/cache/api/ingestInCache';
4
- import { fireEvent } from '~/core/events';
5
- import { prepareMembershipPayload } from '~/group/utils';
6
- import { LinkedObject } from '~/utils/linkedObject';
7
-
8
- /* begin_public_function
9
- id: post.create.clip_post
10
- */
11
- /**
12
- * ```js
13
- * import { PostRepository } from '@amityco/ts-sdk'
14
- * const created = await PostRepository.createClipPost({
15
- * targetType: 'user',
16
- * targetId: 'foobar',
17
- * dataType: 'clip',
18
- * data: { text: 'hello world' },
19
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
20
- * }))
21
- * ```
22
- *
23
- * Creates an {@link Amity.Post}
24
- *
25
- * @param bundle The data necessary to create a new {@link Amity.Post}
26
- * @returns The newly created {@link Amity.Post}
27
- *
28
- * @category Post API
29
- * @async
30
- */
31
- export const createClipPost = async <T extends Amity.PostContentType | string>(
32
- bundle: Pick<Amity.Post<T>, 'targetType' | 'targetId'> &
33
- Partial<Pick<Amity.Post<T>, 'metadata' | 'mentionees' | 'tags'>> & {
34
- data: { [k: string]: any };
35
- attachments: {
36
- type: T;
37
- fileId: Amity.File['fileId'];
38
- displayMode?: Amity.ClipDisplayMode;
39
- isMuted?: boolean;
40
- }[];
41
- },
42
- ): Promise<Amity.Cached<Amity.Post>> => {
43
- const client = getActiveClient();
44
- client.log('post/createPost', bundle);
45
-
46
- const { data: payload } = await client.http.post<Amity.PostPayload>('/api/v4/posts', bundle);
47
-
48
- fireEvent('post.created', payload);
49
-
50
- const data = prepareMembershipPayload(payload, 'communityUsers');
51
- const cachedAt = client.cache && Date.now();
52
-
53
- if (client.cache) ingestInCache(data, { cachedAt });
54
-
55
- const { posts } = data;
56
-
57
- return {
58
- data: LinkedObject.post(posts[0]),
59
- cachedAt,
60
- };
61
- };
62
- /* end_public_function */