@amityco/ts-sdk 7.1.1-c8d4edca.0 → 7.1.1-e887d15f.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.
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Internal used only
3
3
  *
4
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
4
+ * Fired when an {@link Amity.channelUnreadInfo} has been updated.
5
5
  *
6
6
  * @param callback The function to call when the event was fired
7
7
  * @returns an {@link Amity.Unsubscriber} function to stop listening
8
8
  *
9
- * @category MessageMarker Events
9
+ * @category ChannelMarker Events
10
10
  */
11
11
  export declare const onChannelUnreadInfoUpdatedLocal: (callback: Amity.Listener<Amity.Events['local.channelUnreadInfo.updated']>) => Amity.Unsubscriber;
12
12
  //# sourceMappingURL=onChannelUnreadInfoUpdatedLocal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,aACrB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YA+BR,CAAC;AAEF,eAAO,MAAM,qBAAqB,aACtB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YAoBR,CAAC"}
1
+ {"version":3,"file":"onMessageCreated.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/events/onMessageCreated.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,aACrB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YAgER,CAAC;AAEF,eAAO,MAAM,qBAAqB,aACtB,MAAM,QAAQ,CAAC,MAAM,eAAe,CAAC,KAC9C,MAAM,YAoBR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "7.1.1-c8d4edca.0",
3
+ "version": "7.1.1-e887d15f.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -84,6 +84,8 @@ declare global {
84
84
  > & {
85
85
  isMentioned: boolean;
86
86
  subChannelsUnreadCount: number;
87
+ // legacy unread count does not use the maker service
88
+ unreadCount: number;
87
89
  };
88
90
 
89
91
  /* public type */
@@ -6,6 +6,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
6
6
  import { prepareChannelPayload } from '../utils/prepareChannelPayload';
7
7
  import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
8
8
  import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
9
+ import { dropFromCache } from '~/cache/api';
9
10
 
10
11
  type CallbackFn = (channel: Amity.StaticInternalChannel) => void;
11
12
  const callbacks: CallbackFn[] = [];
@@ -28,12 +29,17 @@ export const onChannelDeleted = (callback: Amity.Listener<Amity.StaticInternalCh
28
29
  const filter = async (payload: Amity.ChannelPayload) => {
29
30
  const data = await prepareChannelPayload(payload);
30
31
 
31
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
32
- data.channels.forEach(channel => {
32
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
33
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
34
+
35
+ data.channels.forEach(channel => {
36
+ if (isConsistentMode) {
33
37
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
34
38
  deleteChannelUnreadByChannelId(channel.channelId);
35
- });
36
- }
39
+ } else if (isLegacyUnreadCount) {
40
+ dropFromCache(['channelUnread', 'get', channel.channelId]);
41
+ }
42
+ });
37
43
 
38
44
  ingestInCache(data);
39
45
  callbacks.forEach(cb => cb(data.channels[0]));
@@ -6,6 +6,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
6
6
  import { prepareChannelPayload } from '../utils';
7
7
  import { deleteChannelUnreadByChannelId } from '../../marker/utils/deleteChannelUnreadByChannelId';
8
8
  import { addFlagIsDeletedSubChannelUnreadByChannelId } from '~/marker/utils/addFlagIsDeletedSubChannelUnreadByChannelId';
9
+ import { dropFromCache } from '~/cache/api';
9
10
 
10
11
  type CallbackFn = (
11
12
  channel: Amity.StaticInternalChannel,
@@ -40,10 +41,17 @@ export const onChannelLeft = (
40
41
  isMessagePreviewUpdated: isLeftByMe,
41
42
  });
42
43
 
43
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
44
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
45
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
46
+
47
+ if (isLeftByMe) {
44
48
  preparedPayload.channels.forEach(channel => {
45
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
46
- deleteChannelUnreadByChannelId(channel.channelId);
49
+ if (isConsistentMode) {
50
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
51
+ deleteChannelUnreadByChannelId(channel.channelId);
52
+ } else if (isLegacyUnreadCount) {
53
+ dropFromCache(['channelUnread', 'get', channel.channelId]);
54
+ }
47
55
  });
48
56
  }
49
57
 
@@ -4,12 +4,12 @@ import { createEventSubscriber } from '~/core/events';
4
4
  /**
5
5
  * Internal used only
6
6
  *
7
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
7
+ * Fired when an {@link Amity.ChannelUnread} has been updated.
8
8
  *
9
9
  * @param callback The function to call when the event was fired
10
10
  * @returns an {@link Amity.Unsubscriber} function to stop listening
11
11
  *
12
- * @category MessageMarker Events
12
+ * @category Channel Events
13
13
  */
14
14
  export const onChannelUnreadUpdatedLocal = (
15
15
  callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>,
@@ -38,7 +38,6 @@ export class MessageReadReceiptSyncEngine {
38
38
  if (this.jobQueue.length === 0 || this.isActive === false) return;
39
39
 
40
40
  const readReceipts = this.getReadReceipts();
41
- console.log('[New 🌟 readReceipts] Sync read receipts', readReceipts);
42
41
  if (readReceipts) {
43
42
  this.markReadApi(readReceipts);
44
43
  }
@@ -159,8 +158,6 @@ export class MessageReadReceiptSyncEngine {
159
158
  const cacheKey = ['channelUnread', 'get', channelId];
160
159
  const channelUnread = pullFromCache<Amity.ChannelUnread>(cacheKey)?.data;
161
160
 
162
- console.log('[New 🌟] Mark read => channel unread', channelUnread);
163
-
164
161
  if (channelUnread && segment > channelUnread.readToSegment) {
165
162
  channelUnread.readToSegment = segment;
166
163
  channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
@@ -4,12 +4,12 @@ import { createEventSubscriber } from '~/core/events';
4
4
  /**
5
5
  * Internal used only
6
6
  *
7
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
7
+ * Fired when an {@link Amity.channelUnreadInfo} has been updated.
8
8
  *
9
9
  * @param callback The function to call when the event was fired
10
10
  * @returns an {@link Amity.Unsubscriber} function to stop listening
11
11
  *
12
- * @category MessageMarker Events
12
+ * @category ChannelMarker Events
13
13
  */
14
14
  export const onChannelUnreadInfoUpdatedLocal = (
15
15
  callback: Amity.Listener<Amity.Events['local.channelUnreadInfo.updated']>,
@@ -6,6 +6,7 @@ import { reCalculateChannelUnreadInfo } from '~/marker/utils/reCalculateChannelU
6
6
  import { getActiveUser } from '~/client/api/activeUser';
7
7
  import { markReadMessage } from '../utils/markReadMessage';
8
8
  import { prepareMessagePayload } from '../utils';
9
+ import { pullFromCache, pushToCache } from '~/cache/api';
9
10
 
10
11
  /**
11
12
  * ```js
@@ -40,6 +41,39 @@ export const onMessageCreatedMqtt = (
40
41
  });
41
42
  }
42
43
 
44
+ if (client.useLegacyUnreadCount) {
45
+ rawPayload.messages.forEach(message => {
46
+ const channelUnread = pullFromCache<Amity.ChannelUnread>([
47
+ 'channelUnread',
48
+ 'get',
49
+ message.channelId,
50
+ ])?.data;
51
+ if (!channelUnread || channelUnread.lastSegment >= message.segment) return;
52
+
53
+ const lastSegment = message.segment;
54
+ const isMentionedInMessage = message.mentionedUsers?.some(mention => {
55
+ return (
56
+ mention.type === 'channel' ||
57
+ (mention.type === 'user' &&
58
+ client.userId &&
59
+ mention.userPublicIds.includes(client.userId))
60
+ );
61
+ });
62
+
63
+ const lastMentionSegment = isMentionedInMessage
64
+ ? message.segment
65
+ : channelUnread.lastMentionSegment;
66
+
67
+ pushToCache(['channelUnread', 'get', message.channelId], {
68
+ ...channelUnread,
69
+ lastSegment,
70
+ unreadCount: lastSegment - channelUnread.readToSegment,
71
+ lastMentionSegment,
72
+ isMentioned: !(channelUnread.readToSegment >= lastMentionSegment),
73
+ });
74
+ });
75
+ }
76
+
43
77
  // Update in cache
44
78
  ingestInCache(payload);
45
79
 
@@ -1,12 +0,0 @@
1
- /**
2
- * Internal used only
3
- *
4
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
5
- *
6
- * @param callback The function to call when the event was fired
7
- * @returns an {@link Amity.Unsubscriber} function to stop listening
8
- *
9
- * @category MessageMarker Events
10
- */
11
- export declare const onChannelUnreadUpdatedLocal: (callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>) => Amity.Unsubscriber;
12
- //# sourceMappingURL=onChannelUnreadUpdatedLocal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onChannelUnreadUpdatedLocal.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onChannelUnreadUpdatedLocal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,aAC5B,MAAM,QAAQ,CAAC,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC,KACpE,MAAM,YAaR,CAAC"}
@@ -1,29 +0,0 @@
1
- import { getActiveClient } from '~/client/api/activeClient';
2
- import { createEventSubscriber } from '~/core/events';
3
-
4
- /**
5
- * Internal used only
6
- *
7
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
8
- *
9
- * @param callback The function to call when the event was fired
10
- * @returns an {@link Amity.Unsubscriber} function to stop listening
11
- *
12
- * @category MessageMarker Events
13
- */
14
- export const onChannelUnreadUpdatedLocal = (
15
- callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>,
16
- ): Amity.Unsubscriber => {
17
- const client = getActiveClient();
18
-
19
- const filter = (payload: Amity.Events['local.channelUnread.updated']) => {
20
- callback(payload);
21
- };
22
-
23
- return createEventSubscriber(
24
- client,
25
- 'channel/onChannelUnreadUpdatedLocal',
26
- 'local.channelUnread.updated',
27
- filter,
28
- );
29
- };