@sendbird/uikit-chat-hooks 2.4.1 → 2.5.0-rc.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 (134) hide show
  1. package/README.md +2 -2
  2. package/lib/commonjs/channel/useChannelMessagesReducer.js +153 -0
  3. package/lib/commonjs/channel/useChannelMessagesReducer.js.map +1 -0
  4. package/lib/commonjs/channel/useGroupChannel.js +0 -4
  5. package/lib/commonjs/channel/useGroupChannel.js.map +1 -1
  6. package/lib/commonjs/channel/useGroupChannelList/index.js +0 -5
  7. package/lib/commonjs/channel/useGroupChannelList/index.js.map +1 -1
  8. package/lib/commonjs/channel/useGroupChannelList/reducer.js +12 -29
  9. package/lib/commonjs/channel/useGroupChannelList/reducer.js.map +1 -1
  10. package/lib/commonjs/channel/useGroupChannelList/useGroupChannelListWithCollection.js +1 -22
  11. package/lib/commonjs/channel/useGroupChannelList/useGroupChannelListWithCollection.js.map +1 -1
  12. package/lib/commonjs/channel/useGroupChannelList/useGroupChannelListWithQuery.js +1 -18
  13. package/lib/commonjs/channel/useGroupChannelList/useGroupChannelListWithQuery.js.map +1 -1
  14. package/lib/commonjs/channel/useGroupChannelMessages/index.js +0 -5
  15. package/lib/commonjs/channel/useGroupChannelMessages/index.js.map +1 -1
  16. package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js +172 -131
  17. package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js.map +1 -1
  18. package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js +76 -73
  19. package/lib/commonjs/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js.map +1 -1
  20. package/lib/commonjs/channel/useOpenChannel.js +0 -4
  21. package/lib/commonjs/channel/useOpenChannel.js.map +1 -1
  22. package/lib/commonjs/channel/useOpenChannelList/index.js +0 -3
  23. package/lib/commonjs/channel/useOpenChannelList/index.js.map +1 -1
  24. package/lib/commonjs/channel/useOpenChannelList/reducer.js +2 -21
  25. package/lib/commonjs/channel/useOpenChannelList/reducer.js.map +1 -1
  26. package/lib/commonjs/channel/useOpenChannelList/useOpenChannelListWithQuery.js +1 -22
  27. package/lib/commonjs/channel/useOpenChannelList/useOpenChannelListWithQuery.js.map +1 -1
  28. package/lib/commonjs/channel/useOpenChannelMessages/index.js +0 -3
  29. package/lib/commonjs/channel/useOpenChannelMessages/index.js.map +1 -1
  30. package/lib/commonjs/channel/useOpenChannelMessages/useOpenChannelMessagesWithQuery.js +128 -57
  31. package/lib/commonjs/channel/useOpenChannelMessages/useOpenChannelMessagesWithQuery.js.map +1 -1
  32. package/lib/commonjs/common/useAppFeatures.js +0 -3
  33. package/lib/commonjs/common/useAppFeatures.js.map +1 -1
  34. package/lib/commonjs/common/useMessageOutgoingStatus.js +0 -11
  35. package/lib/commonjs/common/useMessageOutgoingStatus.js.map +1 -1
  36. package/lib/commonjs/common/usePushTrigger.js +0 -6
  37. package/lib/commonjs/common/usePushTrigger.js.map +1 -1
  38. package/lib/commonjs/common/useTotalUnreadMessageCount.js +0 -7
  39. package/lib/commonjs/common/useTotalUnreadMessageCount.js.map +1 -1
  40. package/lib/commonjs/common/useUserList.js +5 -20
  41. package/lib/commonjs/common/useUserList.js.map +1 -1
  42. package/lib/commonjs/handler/useChannelHandler.js +15 -41
  43. package/lib/commonjs/handler/useChannelHandler.js.map +1 -1
  44. package/lib/commonjs/handler/useConnectionHandler.js +14 -11
  45. package/lib/commonjs/handler/useConnectionHandler.js.map +1 -1
  46. package/lib/commonjs/handler/useUserEventHandler.js +0 -8
  47. package/lib/commonjs/handler/useUserEventHandler.js.map +1 -1
  48. package/lib/commonjs/index.js +0 -23
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/model/CustomQuery.js +0 -6
  51. package/lib/commonjs/model/CustomQuery.js.map +1 -1
  52. package/lib/commonjs/types.js.map +1 -1
  53. package/lib/module/channel/useChannelMessagesReducer.js +146 -0
  54. package/lib/module/channel/useChannelMessagesReducer.js.map +1 -0
  55. package/lib/module/channel/useGroupChannel.js.map +1 -1
  56. package/lib/module/channel/useGroupChannelList/index.js.map +1 -1
  57. package/lib/module/channel/useGroupChannelList/reducer.js +12 -26
  58. package/lib/module/channel/useGroupChannelList/reducer.js.map +1 -1
  59. package/lib/module/channel/useGroupChannelList/useGroupChannelListWithCollection.js +1 -15
  60. package/lib/module/channel/useGroupChannelList/useGroupChannelListWithCollection.js.map +1 -1
  61. package/lib/module/channel/useGroupChannelList/useGroupChannelListWithQuery.js +1 -11
  62. package/lib/module/channel/useGroupChannelList/useGroupChannelListWithQuery.js.map +1 -1
  63. package/lib/module/channel/useGroupChannelMessages/index.js.map +1 -1
  64. package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js +174 -125
  65. package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.js.map +1 -1
  66. package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js +78 -70
  67. package/lib/module/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.js.map +1 -1
  68. package/lib/module/channel/useOpenChannel.js.map +1 -1
  69. package/lib/module/channel/useOpenChannelList/index.js.map +1 -1
  70. package/lib/module/channel/useOpenChannelList/reducer.js +2 -18
  71. package/lib/module/channel/useOpenChannelList/reducer.js.map +1 -1
  72. package/lib/module/channel/useOpenChannelList/useOpenChannelListWithQuery.js +1 -17
  73. package/lib/module/channel/useOpenChannelList/useOpenChannelListWithQuery.js.map +1 -1
  74. package/lib/module/channel/useOpenChannelMessages/index.js.map +1 -1
  75. package/lib/module/channel/useOpenChannelMessages/useOpenChannelMessagesWithQuery.js +129 -53
  76. package/lib/module/channel/useOpenChannelMessages/useOpenChannelMessagesWithQuery.js.map +1 -1
  77. package/lib/module/common/useAppFeatures.js.map +1 -1
  78. package/lib/module/common/useMessageOutgoingStatus.js +0 -6
  79. package/lib/module/common/useMessageOutgoingStatus.js.map +1 -1
  80. package/lib/module/common/usePushTrigger.js.map +1 -1
  81. package/lib/module/common/useTotalUnreadMessageCount.js +0 -1
  82. package/lib/module/common/useTotalUnreadMessageCount.js.map +1 -1
  83. package/lib/module/common/useUserList.js +5 -15
  84. package/lib/module/common/useUserList.js.map +1 -1
  85. package/lib/module/handler/useChannelHandler.js +15 -35
  86. package/lib/module/handler/useChannelHandler.js.map +1 -1
  87. package/lib/module/handler/useConnectionHandler.js +15 -6
  88. package/lib/module/handler/useConnectionHandler.js.map +1 -1
  89. package/lib/module/handler/useUserEventHandler.js +0 -2
  90. package/lib/module/handler/useUserEventHandler.js.map +1 -1
  91. package/lib/module/index.js +0 -1
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/module/model/CustomQuery.js +0 -4
  94. package/lib/module/model/CustomQuery.js.map +1 -1
  95. package/lib/module/types.js.map +1 -1
  96. package/lib/typescript/src/channel/useChannelMessagesReducer.d.ts +18 -0
  97. package/lib/typescript/src/channel/useGroupChannelList/reducer.d.ts +1 -1
  98. package/lib/typescript/src/common/useUserList.d.ts +1 -1
  99. package/lib/typescript/src/handler/useChannelHandler.d.ts +1 -1
  100. package/lib/typescript/src/handler/useConnectionHandler.d.ts +1 -2
  101. package/lib/typescript/src/index.d.ts +0 -1
  102. package/lib/typescript/src/types.d.ts +51 -20
  103. package/package.json +15 -10
  104. package/src/channel/useChannelMessagesReducer.ts +143 -0
  105. package/src/channel/useGroupChannelList/reducer.ts +11 -7
  106. package/src/channel/useGroupChannelList/useGroupChannelListWithCollection.ts +1 -1
  107. package/src/channel/useGroupChannelList/useGroupChannelListWithQuery.ts +1 -1
  108. package/src/channel/useGroupChannelMessages/useGroupChannelMessagesWithCollection.ts +174 -105
  109. package/src/channel/useGroupChannelMessages/useGroupChannelMessagesWithQuery.ts +90 -63
  110. package/src/channel/useOpenChannelList/useOpenChannelListWithQuery.ts +1 -5
  111. package/src/channel/useOpenChannelMessages/useOpenChannelMessagesWithQuery.ts +143 -26
  112. package/src/common/useUserList.ts +4 -4
  113. package/src/handler/useChannelHandler.ts +11 -24
  114. package/src/handler/useConnectionHandler.ts +11 -5
  115. package/src/index.ts +0 -1
  116. package/src/types.ts +58 -20
  117. package/lib/commonjs/channel/useGroupChannelMessages/reducer.js +0 -154
  118. package/lib/commonjs/channel/useGroupChannelMessages/reducer.js.map +0 -1
  119. package/lib/commonjs/channel/useOpenChannelMessages/reducer.js +0 -154
  120. package/lib/commonjs/channel/useOpenChannelMessages/reducer.js.map +0 -1
  121. package/lib/commonjs/common/useTotalUnreadChannelCount.js +0 -29
  122. package/lib/commonjs/common/useTotalUnreadChannelCount.js.map +0 -1
  123. package/lib/module/channel/useGroupChannelMessages/reducer.js +0 -144
  124. package/lib/module/channel/useGroupChannelMessages/reducer.js.map +0 -1
  125. package/lib/module/channel/useOpenChannelMessages/reducer.js +0 -144
  126. package/lib/module/channel/useOpenChannelMessages/reducer.js.map +0 -1
  127. package/lib/module/common/useTotalUnreadChannelCount.js +0 -17
  128. package/lib/module/common/useTotalUnreadChannelCount.js.map +0 -1
  129. package/lib/typescript/src/channel/useGroupChannelMessages/reducer.d.ts +0 -15
  130. package/lib/typescript/src/channel/useOpenChannelMessages/reducer.d.ts +0 -15
  131. package/lib/typescript/src/common/useTotalUnreadChannelCount.d.ts +0 -6
  132. package/src/channel/useGroupChannelMessages/reducer.ts +0 -125
  133. package/src/channel/useOpenChannelMessages/reducer.ts +0 -125
  134. package/src/common/useTotalUnreadChannelCount.ts +0 -26
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useGroupChannelListWithQuery = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _groupChannel = require("@sendbird/chat/groupChannel");
11
-
12
9
  var _uikitUtils = require("@sendbird/uikit-utils");
13
-
14
10
  var _useAppFeatures = require("../../common/useAppFeatures");
15
-
16
11
  var _useChannelHandler = require("../../handler/useChannelHandler");
17
-
18
12
  var _reducer = require("./reducer");
19
-
20
13
  const createGroupChannelListQuery = (sdk, queryCreator) => {
21
14
  const passedQuery = queryCreator === null || queryCreator === void 0 ? void 0 : queryCreator();
22
15
  if (passedQuery) return passedQuery;
@@ -26,7 +19,6 @@ const createGroupChannelListQuery = (sdk, queryCreator) => {
26
19
  order: _groupChannel.GroupChannelListOrder.LATEST_LAST_MESSAGE
27
20
  });
28
21
  };
29
-
30
22
  const useGroupChannelListWithQuery = (sdk, userId, options) => {
31
23
  const {
32
24
  deliveryReceiptEnabled
@@ -44,19 +36,15 @@ const useGroupChannelListWithQuery = (sdk, userId, options) => {
44
36
  updateLoading,
45
37
  updateOrder
46
38
  } = (0, _reducer.useGroupChannelListReducer)();
47
-
48
39
  const updateChannelsAndMarkAsDelivered = channels => {
49
40
  updateChannels(channels);
50
41
  if (deliveryReceiptEnabled) (0, _uikitUtils.confirmAndMarkAsDelivered)(channels);
51
42
  };
52
-
53
43
  const init = (0, _uikitUtils.useFreshCallback)(async uid => {
54
44
  if (uid) {
55
45
  var _queryRef$current, _queryRef$current2;
56
-
57
46
  queryRef.current = createGroupChannelListQuery(sdk, options === null || options === void 0 ? void 0 : options.queryCreator);
58
47
  updateOrder((_queryRef$current = queryRef.current) === null || _queryRef$current === void 0 ? void 0 : _queryRef$current.order);
59
-
60
48
  if ((_queryRef$current2 = queryRef.current) !== null && _queryRef$current2 !== void 0 && _queryRef$current2.hasNext) {
61
49
  const channels = await queryRef.current.next();
62
50
  setChannels(channels, true);
@@ -68,7 +56,7 @@ const useGroupChannelListWithQuery = (sdk, userId, options) => {
68
56
  updateLoading(true);
69
57
  await init(userId);
70
58
  updateLoading(false);
71
- }, [init, userId]);
59
+ }, [userId]);
72
60
  (0, _useChannelHandler.useChannelHandler)(sdk, handlerId, {
73
61
  onChannelChanged: channel => updateChannels([channel]),
74
62
  onChannelFrozen: channel => updateChannels([channel]),
@@ -80,16 +68,13 @@ const useGroupChannelListWithQuery = (sdk, userId, options) => {
80
68
  const isMe = user.userId === userId;
81
69
  if (isMe) deleteChannels([channel.url]);else updateChannels([channel]);
82
70
  },
83
-
84
71
  onUserBanned(channel, user) {
85
72
  const isMe = user.userId === userId;
86
73
  if (isMe) deleteChannels([channel.url]);else updateChannels([channel]);
87
74
  },
88
-
89
75
  onMessageReceived(channel) {
90
76
  updateChannelsAndMarkAsDelivered([channel]);
91
77
  }
92
-
93
78
  });
94
79
  const refresh = (0, _uikitUtils.useFreshCallback)(async () => {
95
80
  updateRefreshing(true);
@@ -98,7 +83,6 @@ const useGroupChannelListWithQuery = (sdk, userId, options) => {
98
83
  });
99
84
  const next = (0, _uikitUtils.useFreshCallback)(async () => {
100
85
  var _queryRef$current3;
101
-
102
86
  if ((_queryRef$current3 = queryRef.current) !== null && _queryRef$current3 !== void 0 && _queryRef$current3.hasNext) {
103
87
  const channels = await queryRef.current.next();
104
88
  setChannels(channels, false);
@@ -113,6 +97,5 @@ const useGroupChannelListWithQuery = (sdk, userId, options) => {
113
97
  next
114
98
  };
115
99
  };
116
-
117
100
  exports.useGroupChannelListWithQuery = useGroupChannelListWithQuery;
118
101
  //# sourceMappingURL=useGroupChannelListWithQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createGroupChannelListQuery","sdk","queryCreator","passedQuery","groupChannel","createMyGroupChannelListQuery","includeEmpty","limit","order","GroupChannelListOrder","LATEST_LAST_MESSAGE","useGroupChannelListWithQuery","userId","options","deliveryReceiptEnabled","useAppFeatures","queryRef","useRef","handlerId","useUniqHandlerId","loading","groupChannels","refreshing","updateChannels","setChannels","deleteChannels","updateRefreshing","updateLoading","updateOrder","useGroupChannelListReducer","updateChannelsAndMarkAsDelivered","channels","confirmAndMarkAsDelivered","init","useFreshCallback","uid","current","hasNext","next","useAsyncEffect","useChannelHandler","onChannelChanged","channel","onChannelFrozen","onChannelUnfrozen","onChannelMemberCountChanged","onChannelDeleted","url","onUserJoined","onUserLeft","user","isMe","onUserBanned","onMessageReceived","refresh"],"sources":["useGroupChannelListWithQuery.ts"],"sourcesContent":["import { useRef } from 'react';\n\nimport { GroupChannelListOrder } from '@sendbird/chat/groupChannel';\nimport type { SendbirdChannel, SendbirdChatSDK, SendbirdGroupChannelListQuery } from '@sendbird/uikit-utils';\nimport { confirmAndMarkAsDelivered, useAsyncEffect, useFreshCallback, useUniqHandlerId } from '@sendbird/uikit-utils';\n\nimport { useAppFeatures } from '../../common/useAppFeatures';\nimport { useChannelHandler } from '../../handler/useChannelHandler';\nimport type { UseGroupChannelList, UseGroupChannelListOptions } from '../../types';\nimport { useGroupChannelListReducer } from './reducer';\n\nconst createGroupChannelListQuery = (\n sdk: SendbirdChatSDK,\n queryCreator: UseGroupChannelListOptions['queryCreator'],\n) => {\n const passedQuery = queryCreator?.();\n if (passedQuery) return passedQuery;\n\n return sdk.groupChannel.createMyGroupChannelListQuery({\n includeEmpty: false,\n limit: 20,\n order: GroupChannelListOrder.LATEST_LAST_MESSAGE,\n });\n};\n\nexport const useGroupChannelListWithQuery: UseGroupChannelList = (sdk, userId, options) => {\n const { deliveryReceiptEnabled } = useAppFeatures(sdk);\n const queryRef = useRef<SendbirdGroupChannelListQuery>();\n const handlerId = useUniqHandlerId('useGroupChannelListWithQuery');\n\n const {\n loading,\n groupChannels,\n refreshing,\n updateChannels,\n setChannels,\n deleteChannels,\n updateRefreshing,\n updateLoading,\n updateOrder,\n } = useGroupChannelListReducer();\n\n const updateChannelsAndMarkAsDelivered = (channels: SendbirdChannel[]) => {\n updateChannels(channels);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n };\n\n const init = useFreshCallback(async (uid?: string) => {\n if (uid) {\n queryRef.current = createGroupChannelListQuery(sdk, options?.queryCreator);\n updateOrder(queryRef.current?.order);\n\n if (queryRef.current?.hasNext) {\n const channels = await queryRef.current.next();\n\n setChannels(channels, true);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n }\n }\n });\n\n useAsyncEffect(async () => {\n updateLoading(true);\n await init(userId);\n updateLoading(false);\n }, [init, userId]);\n\n useChannelHandler(sdk, handlerId, {\n onChannelChanged: (channel) => updateChannels([channel]),\n onChannelFrozen: (channel) => updateChannels([channel]),\n onChannelUnfrozen: (channel) => updateChannels([channel]),\n onChannelMemberCountChanged: (channels) => updateChannels(channels),\n onChannelDeleted: (url) => deleteChannels([url]),\n onUserJoined: (channel) => updateChannels([channel]),\n onUserLeft: (channel, user) => {\n const isMe = user.userId === userId;\n if (isMe) deleteChannels([channel.url]);\n else updateChannels([channel]);\n },\n onUserBanned(channel, user) {\n const isMe = user.userId === userId;\n if (isMe) deleteChannels([channel.url]);\n else updateChannels([channel]);\n },\n onMessageReceived(channel) {\n updateChannelsAndMarkAsDelivered([channel]);\n },\n });\n\n const refresh = useFreshCallback(async () => {\n updateRefreshing(true);\n await init(userId);\n updateRefreshing(false);\n });\n\n const next = useFreshCallback(async () => {\n if (queryRef.current?.hasNext) {\n const channels = await queryRef.current.next();\n setChannels(channels, false);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n }\n });\n\n return {\n loading,\n groupChannels,\n refresh,\n refreshing,\n next,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA;;AACA;;AAEA;;AAEA,MAAMA,2BAA2B,GAAG,CAClCC,GADkC,EAElCC,YAFkC,KAG/B;EACH,MAAMC,WAAW,GAAGD,YAAH,aAAGA,YAAH,uBAAGA,YAAY,EAAhC;EACA,IAAIC,WAAJ,EAAiB,OAAOA,WAAP;EAEjB,OAAOF,GAAG,CAACG,YAAJ,CAAiBC,6BAAjB,CAA+C;IACpDC,YAAY,EAAE,KADsC;IAEpDC,KAAK,EAAE,EAF6C;IAGpDC,KAAK,EAAEC,mCAAA,CAAsBC;EAHuB,CAA/C,CAAP;AAKD,CAZD;;AAcO,MAAMC,4BAAiD,GAAG,CAACV,GAAD,EAAMW,MAAN,EAAcC,OAAd,KAA0B;EACzF,MAAM;IAAEC;EAAF,IAA6B,IAAAC,8BAAA,EAAed,GAAf,CAAnC;EACA,MAAMe,QAAQ,GAAG,IAAA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AAiB,YAAY;IAAA;;IACxC,0BAAIlB,QAAQ,CAACoB,OAAb,+CAAI,mBAAkBC,OAAtB,EAA+B;MAC7B,MAAMN,QAAQ,GAAG,MAAMf,QAAQ,CAACoB,OAAT,CAAiBE,IAAjB,EAAvB;MACAd,WAAW,CAACO,QAAD,EAAW,KAAX,CAAX;MACA,IAAIjB,sBAAJ,EAA4B,IAAAkB,qCAAA,EAA0BD,QAA1B;IAC7B;EACF,CANY,CAAb;EAQA,OAAO;IACLX,OADK;IAELC,aAFK;IAGLiC,OAHK;IAILhC,UAJK;IAKLgB;EALK,CAAP;AAOD,CArFM"}
1
+ {"version":3,"names":["_react","require","_groupChannel","_uikitUtils","_useAppFeatures","_useChannelHandler","_reducer","createGroupChannelListQuery","sdk","queryCreator","passedQuery","groupChannel","createMyGroupChannelListQuery","includeEmpty","limit","order","GroupChannelListOrder","LATEST_LAST_MESSAGE","useGroupChannelListWithQuery","userId","options","deliveryReceiptEnabled","useAppFeatures","queryRef","useRef","handlerId","useUniqHandlerId","loading","groupChannels","refreshing","updateChannels","setChannels","deleteChannels","updateRefreshing","updateLoading","updateOrder","useGroupChannelListReducer","updateChannelsAndMarkAsDelivered","channels","confirmAndMarkAsDelivered","init","useFreshCallback","uid","_queryRef$current","_queryRef$current2","current","hasNext","next","useAsyncEffect","useChannelHandler","onChannelChanged","channel","onChannelFrozen","onChannelUnfrozen","onChannelMemberCountChanged","onChannelDeleted","url","onUserJoined","onUserLeft","user","isMe","onUserBanned","onMessageReceived","refresh","_queryRef$current3","exports"],"sources":["useGroupChannelListWithQuery.ts"],"sourcesContent":["import { useRef } from 'react';\n\nimport { GroupChannelListOrder } from '@sendbird/chat/groupChannel';\nimport type { SendbirdChannel, SendbirdChatSDK, SendbirdGroupChannelListQuery } from '@sendbird/uikit-utils';\nimport { confirmAndMarkAsDelivered, useAsyncEffect, useFreshCallback, useUniqHandlerId } from '@sendbird/uikit-utils';\n\nimport { useAppFeatures } from '../../common/useAppFeatures';\nimport { useChannelHandler } from '../../handler/useChannelHandler';\nimport type { UseGroupChannelList, UseGroupChannelListOptions } from '../../types';\nimport { useGroupChannelListReducer } from './reducer';\n\nconst createGroupChannelListQuery = (\n sdk: SendbirdChatSDK,\n queryCreator: UseGroupChannelListOptions['queryCreator'],\n) => {\n const passedQuery = queryCreator?.();\n if (passedQuery) return passedQuery;\n\n return sdk.groupChannel.createMyGroupChannelListQuery({\n includeEmpty: false,\n limit: 20,\n order: GroupChannelListOrder.LATEST_LAST_MESSAGE,\n });\n};\n\nexport const useGroupChannelListWithQuery: UseGroupChannelList = (sdk, userId, options) => {\n const { deliveryReceiptEnabled } = useAppFeatures(sdk);\n const queryRef = useRef<SendbirdGroupChannelListQuery>();\n const handlerId = useUniqHandlerId('useGroupChannelListWithQuery');\n\n const {\n loading,\n groupChannels,\n refreshing,\n updateChannels,\n setChannels,\n deleteChannels,\n updateRefreshing,\n updateLoading,\n updateOrder,\n } = useGroupChannelListReducer();\n\n const updateChannelsAndMarkAsDelivered = (channels: SendbirdChannel[]) => {\n updateChannels(channels);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n };\n\n const init = useFreshCallback(async (uid?: string) => {\n if (uid) {\n queryRef.current = createGroupChannelListQuery(sdk, options?.queryCreator);\n updateOrder(queryRef.current?.order);\n\n if (queryRef.current?.hasNext) {\n const channels = await queryRef.current.next();\n\n setChannels(channels, true);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n }\n }\n });\n\n useAsyncEffect(async () => {\n updateLoading(true);\n await init(userId);\n updateLoading(false);\n }, [userId]);\n\n useChannelHandler(sdk, handlerId, {\n onChannelChanged: (channel) => updateChannels([channel]),\n onChannelFrozen: (channel) => updateChannels([channel]),\n onChannelUnfrozen: (channel) => updateChannels([channel]),\n onChannelMemberCountChanged: (channels) => updateChannels(channels),\n onChannelDeleted: (url) => deleteChannels([url]),\n onUserJoined: (channel) => updateChannels([channel]),\n onUserLeft: (channel, user) => {\n const isMe = user.userId === userId;\n if (isMe) deleteChannels([channel.url]);\n else updateChannels([channel]);\n },\n onUserBanned(channel, user) {\n const isMe = user.userId === userId;\n if (isMe) deleteChannels([channel.url]);\n else updateChannels([channel]);\n },\n onMessageReceived(channel) {\n updateChannelsAndMarkAsDelivered([channel]);\n },\n });\n\n const refresh = useFreshCallback(async () => {\n updateRefreshing(true);\n await init(userId);\n updateRefreshing(false);\n });\n\n const next = useFreshCallback(async () => {\n if (queryRef.current?.hasNext) {\n const channels = await queryRef.current.next();\n setChannels(channels, false);\n if (deliveryReceiptEnabled) confirmAndMarkAsDelivered(channels);\n }\n });\n\n return {\n loading,\n groupChannels,\n refresh,\n refreshing,\n next,\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AAEA,MAAMM,2BAA2B,GAAGA,CAClCC,GAAoB,EACpBC,YAAwD,KACrD;EACH,MAAMC,WAAW,GAAGD,YAAY,aAAZA,YAAY,uBAAZA,YAAY,EAAI;EACpC,IAAIC,WAAW,EAAE,OAAOA,WAAW;EAEnC,OAAOF,GAAG,CAACG,YAAY,CAACC,6BAA6B,CAAC;IACpDC,YAAY,EAAE,KAAK;IACnBC,KAAK,EAAE,EAAE;IACTC,KAAK,EAAEC,mCAAqB,CAACC;EAC/B,CAAC,CAAC;AACJ,CAAC;AAEM,MAAMC,4BAAiD,GAAGA,CAACV,GAAG,EAAEW,MAAM,EAAEC,OAAO,KAAK;EACzF,MAAM;IAAEC;EAAuB,CAAC,GAAG,IAAAC,8BAAc,EAACd,GAAG,CAAC;EACtD,MAAMe,QAAQ,GAAG,IAAAC,aAAM,GAAiC;EACxD,MAAMC,SAAS,GAAG,IAAAC,4BAAgB,EAAC,8BAA8B,CAAC;EA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BAAgB,EAAC,YAAY;IAAA,IAAAuB,kBAAA;IACxC,KAAAA,kBAAA,GAAIzC,QAAQ,CAACsB,OAAO,cAAAmB,kBAAA,eAAhBA,kBAAA,CAAkBlB,OAAO,EAAE;MAC7B,MAAMR,QAAQ,GAAG,MAAMf,QAAQ,CAACsB,OAAO,CAACE,IAAI,EAAE;MAC9ChB,WAAW,CAACO,QAAQ,EAAE,KAAK,CAAC;MAC5B,IAAIjB,sBAAsB,EAAE,IAAAkB,qCAAyB,EAACD,QAAQ,CAAC;IACjE;EACF,CAAC,CAAC;EAEF,OAAO;IACLX,OAAO;IACPC,aAAa;IACbmC,OAAO;IACPlC,UAAU;IACVkB;EACF,CAAC;AACH,CAAC;AAACkB,OAAA,CAAA/C,4BAAA,GAAAA,4BAAA"}
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useGroupChannelMessages = void 0;
7
-
8
7
  var _uikitUtils = require("@sendbird/uikit-utils");
9
-
10
8
  var _useGroupChannelMessagesWithCollection = require("./useGroupChannelMessagesWithCollection");
11
-
12
9
  var _useGroupChannelMessagesWithQuery = require("./useGroupChannelMessagesWithQuery");
13
-
14
10
  const useGroupChannelMessages = (sdk, channel, userId, options) => {
15
11
  if (sdk.isCacheEnabled || options !== null && options !== void 0 && options.enableCollectionWithoutLocalCache) {
16
12
  if (options !== null && options !== void 0 && options.queryCreator) _uikitUtils.Logger.warn('`queryCreator` is ignored, please use `collectionCreator` instead.');
@@ -19,6 +15,5 @@ const useGroupChannelMessages = (sdk, channel, userId, options) => {
19
15
  return (0, _useGroupChannelMessagesWithQuery.useGroupChannelMessagesWithQuery)(sdk, channel, userId, options);
20
16
  }
21
17
  };
22
-
23
18
  exports.useGroupChannelMessages = useGroupChannelMessages;
24
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useGroupChannelMessages","sdk","channel","userId","options","isCacheEnabled","enableCollectionWithoutLocalCache","queryCreator","Logger","warn","useGroupChannelMessagesWithCollection","useGroupChannelMessagesWithQuery"],"sources":["index.ts"],"sourcesContent":["import { Logger } from '@sendbird/uikit-utils';\n\nimport type { UseGroupChannelMessages } from '../../types';\nimport { useGroupChannelMessagesWithCollection } from './useGroupChannelMessagesWithCollection';\nimport { useGroupChannelMessagesWithQuery } from './useGroupChannelMessagesWithQuery';\n\nexport const useGroupChannelMessages: UseGroupChannelMessages = (sdk, channel, userId, options) => {\n if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) {\n if (options?.queryCreator) Logger.warn('`queryCreator` is ignored, please use `collectionCreator` instead.');\n return useGroupChannelMessagesWithCollection(sdk, channel, userId, options);\n } else {\n return useGroupChannelMessagesWithQuery(sdk, channel, userId, options);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AAGA;;AACA;;AAEO,MAAMA,uBAAgD,GAAG,CAACC,GAAD,EAAMC,OAAN,EAAeC,MAAf,EAAuBC,OAAvB,KAAmC;EACjG,IAAIH,GAAG,CAACI,cAAJ,IAAsBD,OAAtB,aAAsBA,OAAtB,eAAsBA,OAAO,CAAEE,iCAAnC,EAAsE;IACpE,IAAIF,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEG,YAAb,EAA2BC,kBAAA,CAAOC,IAAP,CAAY,oEAAZ;IAC3B,OAAO,IAAAC,4EAAA,EAAsCT,GAAtC,EAA2CC,OAA3C,EAAoDC,MAApD,EAA4DC,OAA5D,CAAP;EACD,CAHD,MAGO;IACL,OAAO,IAAAO,kEAAA,EAAiCV,GAAjC,EAAsCC,OAAtC,EAA+CC,MAA/C,EAAuDC,OAAvD,CAAP;EACD;AACF,CAPM"}
1
+ {"version":3,"names":["_uikitUtils","require","_useGroupChannelMessagesWithCollection","_useGroupChannelMessagesWithQuery","useGroupChannelMessages","sdk","channel","userId","options","isCacheEnabled","enableCollectionWithoutLocalCache","queryCreator","Logger","warn","useGroupChannelMessagesWithCollection","useGroupChannelMessagesWithQuery","exports"],"sources":["index.ts"],"sourcesContent":["import { Logger } from '@sendbird/uikit-utils';\n\nimport type { UseGroupChannelMessages } from '../../types';\nimport { useGroupChannelMessagesWithCollection } from './useGroupChannelMessagesWithCollection';\nimport { useGroupChannelMessagesWithQuery } from './useGroupChannelMessagesWithQuery';\n\nexport const useGroupChannelMessages: UseGroupChannelMessages = (sdk, channel, userId, options) => {\n if (sdk.isCacheEnabled || options?.enableCollectionWithoutLocalCache) {\n if (options?.queryCreator) Logger.warn('`queryCreator` is ignored, please use `collectionCreator` instead.');\n return useGroupChannelMessagesWithCollection(sdk, channel, userId, options);\n } else {\n return useGroupChannelMessagesWithQuery(sdk, channel, userId, options);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA,IAAAC,sCAAA,GAAAD,OAAA;AACA,IAAAE,iCAAA,GAAAF,OAAA;AAEO,MAAMG,uBAAgD,GAAGA,CAACC,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,OAAO,KAAK;EACjG,IAAIH,GAAG,CAACI,cAAc,IAAID,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEE,iCAAiC,EAAE;IACpE,IAAIF,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEG,YAAY,EAAEC,kBAAM,CAACC,IAAI,CAAC,oEAAoE,CAAC;IAC5G,OAAO,IAAAC,4EAAqC,EAACT,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,OAAO,CAAC;EAC7E,CAAC,MAAM;IACL,OAAO,IAAAO,kEAAgC,EAACV,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,OAAO,CAAC;EACxE;AACF,CAAC;AAACQ,OAAA,CAAAZ,uBAAA,GAAAA,uBAAA"}
@@ -4,44 +4,49 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useGroupChannelMessagesWithCollection = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _groupChannel = require("@sendbird/chat/groupChannel");
11
-
12
9
  var _uikitUtils = require("@sendbird/uikit-utils");
13
-
14
10
  var _useChannelHandler = require("../../handler/useChannelHandler");
15
-
16
- var _reducer = require("./reducer");
17
-
18
- const createMessageCollection = (channel, creator) => {
19
- if (creator) return creator();
11
+ var _useChannelMessagesReducer = require("../useChannelMessagesReducer");
12
+ const MESSAGE_LIMIT = {
13
+ DEFAULT: 50,
14
+ SEARCH: 20
15
+ };
16
+ const createMessageCollection = (channel, limit, options) => {
17
+ if (options !== null && options !== void 0 && options.collectionCreator) return options === null || options === void 0 ? void 0 : options.collectionCreator({
18
+ startingPoint: options === null || options === void 0 ? void 0 : options.startingPoint
19
+ });
20
20
  const filter = new _groupChannel.MessageFilter();
21
21
  return channel.createMessageCollection({
22
22
  filter,
23
- limit: 100
23
+ limit,
24
+ startingPoint: options === null || options === void 0 ? void 0 : options.startingPoint
24
25
  });
25
26
  };
26
-
27
+ function isNotEmpty(arr) {
28
+ if (!arr) return false;
29
+ return arr.length !== 0;
30
+ }
27
31
  const useGroupChannelMessagesWithCollection = (sdk, channel, userId, options) => {
32
+ const initialStartingPoint = (options === null || options === void 0 ? void 0 : options.startingPoint) ?? Number.MAX_SAFE_INTEGER;
33
+ const initialLimit = typeof (options === null || options === void 0 ? void 0 : options.startingPoint) === 'number' ? MESSAGE_LIMIT.SEARCH : MESSAGE_LIMIT.DEFAULT;
28
34
  const forceUpdate = (0, _uikitUtils.useForceUpdate)();
29
35
  const collectionRef = (0, _react.useRef)();
36
+ const collectionInitializedRef = (0, _react.useRef)(false);
30
37
  const handlerId = (0, _uikitUtils.useUniqHandlerId)('useGroupChannelMessagesWithCollection');
31
38
  const {
32
39
  loading,
33
40
  refreshing,
34
41
  messages,
35
- nextMessages,
36
- newMessagesFromMembers,
42
+ newMessages,
37
43
  updateMessages,
38
- updateNextMessages,
39
- deleteNextMessages,
44
+ updateNewMessages,
45
+ deleteNewMessages,
40
46
  deleteMessages,
41
47
  updateLoading,
42
48
  updateRefreshing
43
- } = (0, _reducer.useGroupChannelMessagesReducer)(userId, options === null || options === void 0 ? void 0 : options.sortComparator);
44
-
49
+ } = (0, _useChannelMessagesReducer.useChannelMessagesReducer)(options === null || options === void 0 ? void 0 : options.sortComparator);
45
50
  const channelMarkAsRead = async source => {
46
51
  try {
47
52
  switch (source) {
@@ -56,149 +61,171 @@ const useGroupChannelMessagesWithCollection = (sdk, channel, userId, options) =>
56
61
  _uikitUtils.Logger.warn('[useGroupChannelMessagesWithCollection/channelMarkAsRead]', e);
57
62
  }
58
63
  };
59
-
60
- const init = (0, _react.useCallback)(async (uid, callback) => {
61
- var _collectionRef$curren;
62
-
64
+ const updateUnsendMessages = () => {
65
+ const {
66
+ pendingMessages,
67
+ failedMessages
68
+ } = collectionRef.current ?? {};
69
+ if (isNotEmpty(pendingMessages)) updateMessages(pendingMessages, false, sdk.currentUser.userId);
70
+ if (isNotEmpty(failedMessages)) updateMessages(failedMessages, false, sdk.currentUser.userId);
71
+ };
72
+ const init = (0, _uikitUtils.useFreshCallback)(async (startingPoint, limit, callback) => {
73
+ var _collectionRef$curren, _collectionRef$curren2;
63
74
  if (collectionRef.current) (_collectionRef$curren = collectionRef.current) === null || _collectionRef$curren === void 0 ? void 0 : _collectionRef$curren.dispose();
64
-
65
- if (uid) {
66
- var _collectionRef$curren2;
67
-
68
- collectionRef.current = createMessageCollection(channel, options === null || options === void 0 ? void 0 : options.collectionCreator);
69
- updateNextMessages([], true, sdk.currentUser.userId);
70
- channelMarkAsRead();
71
- (_collectionRef$curren2 = collectionRef.current) === null || _collectionRef$curren2 === void 0 ? void 0 : _collectionRef$curren2.setMessageCollectionHandler({
72
- onMessagesAdded: (_, __, messages) => {
73
- channelMarkAsRead(_.source);
74
- updateNextMessages(messages, false, sdk.currentUser.userId);
75
- },
76
- onMessagesUpdated: (_, __, messages) => {
77
- channelMarkAsRead(_.source); // NOTE: admin message is not added via onMessagesAdded handler, not checked yet is this a bug.
78
-
79
- if (_.source === _groupChannel.MessageEventSource.EVENT_MESSAGE_RECEIVED) {
80
- const nextMessageIds = nextMessages.map(it => it.messageId);
81
- const nonAddedMessagesFromReceivedEvent = messages.filter(it => nextMessageIds.indexOf(it.messageId) === -1);
82
- updateNextMessages(nonAddedMessagesFromReceivedEvent, false, sdk.currentUser.userId);
83
- } // NOTE: v4 MESSAGE_RECEIVED is called twice from onMessagesAdded and onMessagesUpdated when receiving new message.
84
- // This is not intended behavior but not bugs.
85
-
86
-
87
- if (_.source !== _groupChannel.MessageEventSource.EVENT_MESSAGE_RECEIVED) {
88
- updateMessages(messages, false, sdk.currentUser.userId);
75
+ channelMarkAsRead();
76
+ updateNewMessages([], true, sdk.currentUser.userId);
77
+ collectionInitializedRef.current = false;
78
+ collectionRef.current = createMessageCollection(channel, limit, {
79
+ collectionCreator: options === null || options === void 0 ? void 0 : options.collectionCreator,
80
+ startingPoint
81
+ });
82
+ (_collectionRef$curren2 = collectionRef.current) === null || _collectionRef$curren2 === void 0 ? void 0 : _collectionRef$curren2.setMessageCollectionHandler({
83
+ onMessagesAdded: (_, __, messages) => {
84
+ channelMarkAsRead(_.source);
85
+ const incomingMessages = messages.filter(it => {
86
+ switch (_.source) {
87
+ case _groupChannel.MessageEventSource.EVENT_MESSAGE_SENT_PENDING:
88
+ case _groupChannel.MessageEventSource.EVENT_MESSAGE_SENT_SUCCESS:
89
+ case _groupChannel.MessageEventSource.EVENT_MESSAGE_SENT_FAILED:
90
+ return !(0, _uikitUtils.isMyMessage)(it, sdk.currentUser.userId);
91
+ default:
92
+ return true;
89
93
  }
90
- },
91
- onMessagesDeleted: (_, __, messageIds) => {
92
- deleteMessages(messageIds, []);
93
- deleteNextMessages(messageIds, []);
94
- },
95
- onChannelDeleted: () => {
96
- var _options$onChannelDel;
97
-
98
- options === null || options === void 0 ? void 0 : (_options$onChannelDel = options.onChannelDeleted) === null || _options$onChannelDel === void 0 ? void 0 : _options$onChannelDel.call(options);
99
- },
100
- onChannelUpdated: (_, eventChannel) => {
101
- if (eventChannel.isGroupChannel() && !(0, _uikitUtils.isDifferentChannel)(eventChannel, channel)) {
102
- forceUpdate();
94
+ });
95
+ if (incomingMessages.length > 0) {
96
+ var _options$shouldCountN;
97
+ updateMessages(incomingMessages, false, sdk.currentUser.userId);
98
+ if (options !== null && options !== void 0 && (_options$shouldCountN = options.shouldCountNewMessages) !== null && _options$shouldCountN !== void 0 && _options$shouldCountN.call(options)) {
99
+ updateNewMessages(incomingMessages, false, sdk.currentUser.userId);
100
+ }
101
+ switch (_.source) {
102
+ case _groupChannel.MessageEventSource.EVENT_MESSAGE_RECEIVED:
103
+ case _groupChannel.MessageEventSource.SYNC_MESSAGE_FILL:
104
+ {
105
+ var _options$onMessagesRe;
106
+ options === null || options === void 0 ? void 0 : (_options$onMessagesRe = options.onMessagesReceived) === null || _options$onMessagesRe === void 0 ? void 0 : _options$onMessagesRe.call(options, incomingMessages);
107
+ }
103
108
  }
104
- },
105
- onHugeGapDetected: () => {
106
- init(uid);
107
- }
108
- });
109
- collectionRef.current.initialize(_groupChannel.MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API).onCacheResult((err, messages) => {
110
- if (err) sdk.isCacheEnabled && _uikitUtils.Logger.error('[useGroupChannelMessagesWithCollection/onCacheResult]', err);else {
111
- var _collectionRef$curren3, _collectionRef$curren4;
112
-
113
- _uikitUtils.Logger.debug('[useGroupChannelMessagesWithCollection/onCacheResult]', 'message length:', messages.length);
114
-
115
- updateMessages(messages, true, sdk.currentUser.userId);
116
- updateMessages(((_collectionRef$curren3 = collectionRef.current) === null || _collectionRef$curren3 === void 0 ? void 0 : _collectionRef$curren3.pendingMessages) ?? [], false, sdk.currentUser.userId);
117
- updateMessages(((_collectionRef$curren4 = collectionRef.current) === null || _collectionRef$curren4 === void 0 ? void 0 : _collectionRef$curren4.failedMessages) ?? [], false, sdk.currentUser.userId);
118
109
  }
119
- callback === null || callback === void 0 ? void 0 : callback();
120
- }).onApiResult((err, messages) => {
121
- if (err) _uikitUtils.Logger.warn('[useGroupChannelMessagesWithCollection/onApiResult]', err);else {
122
- _uikitUtils.Logger.debug('[useGroupChannelMessagesWithCollection/onApiResult]', 'message length:', messages.length);
123
-
124
- updateMessages(messages, true, sdk.currentUser.userId);
125
-
126
- if (sdk.isCacheEnabled) {
127
- var _collectionRef$curren5, _collectionRef$curren6;
128
-
129
- updateMessages(((_collectionRef$curren5 = collectionRef.current) === null || _collectionRef$curren5 === void 0 ? void 0 : _collectionRef$curren5.pendingMessages) ?? [], false, sdk.currentUser.userId);
130
- updateMessages(((_collectionRef$curren6 = collectionRef.current) === null || _collectionRef$curren6 === void 0 ? void 0 : _collectionRef$curren6.failedMessages) ?? [], false, sdk.currentUser.userId);
110
+ },
111
+ onMessagesUpdated: (_, __, messages) => {
112
+ channelMarkAsRead(_.source);
113
+ const incomingMessages = messages.filter(it => {
114
+ switch (_.source) {
115
+ case _groupChannel.MessageEventSource.EVENT_MESSAGE_UPDATED:
116
+ return !(0, _uikitUtils.isMyMessage)(it, sdk.currentUser.userId);
117
+ default:
118
+ return true;
119
+ }
120
+ });
121
+ if (incomingMessages.length > 0) {
122
+ var _options$shouldCountN2;
123
+ // NOTE: admin message is not added via onMessagesAdded handler, not checked yet is this a bug.
124
+ updateMessages(messages, false, sdk.currentUser.userId);
125
+ if (options !== null && options !== void 0 && (_options$shouldCountN2 = options.shouldCountNewMessages) !== null && _options$shouldCountN2 !== void 0 && _options$shouldCountN2.call(options)) {
126
+ if (_.source === _groupChannel.MessageEventSource.EVENT_MESSAGE_RECEIVED) {
127
+ updateNewMessages(messages, false, sdk.currentUser.userId);
128
+ }
131
129
  }
132
130
  }
133
- callback === null || callback === void 0 ? void 0 : callback();
134
- });
135
- }
136
- }, [sdk, channel.url, options === null || options === void 0 ? void 0 : options.collectionCreator]);
131
+ },
132
+ onMessagesDeleted: (_, __, messageIds) => {
133
+ deleteMessages(messageIds, []);
134
+ deleteNewMessages(messageIds, []);
135
+ },
136
+ onChannelDeleted: () => {
137
+ var _options$onChannelDel;
138
+ options === null || options === void 0 ? void 0 : (_options$onChannelDel = options.onChannelDeleted) === null || _options$onChannelDel === void 0 ? void 0 : _options$onChannelDel.call(options);
139
+ },
140
+ onChannelUpdated: (_, eventChannel) => {
141
+ if (eventChannel.isGroupChannel() && !(0, _uikitUtils.isDifferentChannel)(eventChannel, channel)) {
142
+ forceUpdate();
143
+ }
144
+ },
145
+ onHugeGapDetected: () => {
146
+ init(Number.MAX_SAFE_INTEGER, MESSAGE_LIMIT.DEFAULT);
147
+ }
148
+ });
149
+ collectionRef.current.initialize(_groupChannel.MessageCollectionInitPolicy.CACHE_AND_REPLACE_BY_API).onCacheResult((err, messages) => {
150
+ if (err) sdk.isCacheEnabled && _uikitUtils.Logger.error('[useGroupChannelMessagesWithCollection/onCacheResult]', err);else {
151
+ _uikitUtils.Logger.debug('[useGroupChannelMessagesWithCollection/onCacheResult]', 'message length:', messages.length);
152
+ updateMessages(messages, true, sdk.currentUser.userId);
153
+ updateUnsendMessages();
154
+ }
155
+ callback === null || callback === void 0 ? void 0 : callback();
156
+ }).onApiResult((err, messages) => {
157
+ if (err) _uikitUtils.Logger.warn('[useGroupChannelMessagesWithCollection/onApiResult]', err);else {
158
+ var _options$onMessagesRe2;
159
+ _uikitUtils.Logger.debug('[useGroupChannelMessagesWithCollection/onApiResult]', 'message length:', messages.length);
160
+ updateMessages(messages, true, sdk.currentUser.userId);
161
+ if (!(options !== null && options !== void 0 && options.startingPoint)) options === null || options === void 0 ? void 0 : (_options$onMessagesRe2 = options.onMessagesReceived) === null || _options$onMessagesRe2 === void 0 ? void 0 : _options$onMessagesRe2.call(options, messages);
162
+ if (sdk.isCacheEnabled) updateUnsendMessages();
163
+ }
164
+ collectionInitializedRef.current = true;
165
+ callback === null || callback === void 0 ? void 0 : callback();
166
+ });
167
+ });
137
168
  (0, _useChannelHandler.useChannelHandler)(sdk, handlerId, {
138
169
  onUserBanned(channel, bannedUser) {
139
170
  if (channel.isGroupChannel() && !(0, _uikitUtils.isDifferentChannel)(channel, channel)) {
140
171
  if (bannedUser.userId === sdk.currentUser.userId) {
141
172
  var _options$onChannelDel2;
142
-
143
173
  options === null || options === void 0 ? void 0 : (_options$onChannelDel2 = options.onChannelDeleted) === null || _options$onChannelDel2 === void 0 ? void 0 : _options$onChannelDel2.call(options);
144
174
  } else {
145
175
  forceUpdate();
146
176
  }
147
177
  }
148
178
  }
149
-
150
179
  });
151
180
  (0, _react.useEffect)(() => {
152
181
  // NOTE: Cache read is heavy task, and it prevents smooth ui transition
153
182
  setTimeout(async () => {
154
183
  updateLoading(true);
155
- init(userId, () => updateLoading(false));
184
+ init(initialStartingPoint, initialLimit, () => updateLoading(false));
156
185
  }, 0);
157
- }, [init, userId]);
186
+ }, [channel.url, userId]);
158
187
  (0, _react.useEffect)(() => {
159
188
  return () => {
160
- var _collectionRef$curren7;
161
-
162
- if (collectionRef.current) (_collectionRef$curren7 = collectionRef.current) === null || _collectionRef$curren7 === void 0 ? void 0 : _collectionRef$curren7.dispose();
189
+ var _collectionRef$curren3;
190
+ if (collectionRef.current) (_collectionRef$curren3 = collectionRef.current) === null || _collectionRef$curren3 === void 0 ? void 0 : _collectionRef$curren3.dispose();
163
191
  };
164
192
  }, []);
165
193
  const refresh = (0, _uikitUtils.useFreshCallback)(async () => {
166
194
  updateRefreshing(true);
167
- init(userId, () => updateRefreshing(false));
195
+ init(Number.MAX_SAFE_INTEGER, MESSAGE_LIMIT.DEFAULT, () => updateRefreshing(false));
168
196
  });
169
197
  const prev = (0, _uikitUtils.useFreshCallback)(async () => {
170
- var _collectionRef$curren8;
171
-
172
- if (collectionRef.current && (_collectionRef$curren8 = collectionRef.current) !== null && _collectionRef$curren8 !== void 0 && _collectionRef$curren8.hasPrevious) {
198
+ var _collectionRef$curren4;
199
+ if (collectionRef.current && (_collectionRef$curren4 = collectionRef.current) !== null && _collectionRef$curren4 !== void 0 && _collectionRef$curren4.hasPrevious) {
173
200
  try {
174
- var _collectionRef$curren9;
175
-
176
- const list = await ((_collectionRef$curren9 = collectionRef.current) === null || _collectionRef$curren9 === void 0 ? void 0 : _collectionRef$curren9.loadPrevious());
201
+ var _collectionRef$curren5;
202
+ const list = await ((_collectionRef$curren5 = collectionRef.current) === null || _collectionRef$curren5 === void 0 ? void 0 : _collectionRef$curren5.loadPrevious());
177
203
  updateMessages(list, false, sdk.currentUser.userId);
178
204
  } catch {}
179
205
  }
180
206
  });
207
+ const hasPrev = (0, _uikitUtils.useFreshCallback)(() => {
208
+ if (collectionInitializedRef.current && collectionRef.current) {
209
+ return collectionRef.current.hasPrevious;
210
+ } else {
211
+ return false;
212
+ }
213
+ });
181
214
  const next = (0, _uikitUtils.useFreshCallback)(async () => {
182
- var _collectionRef$curren10;
183
-
184
- const messageCandidates = [];
185
-
186
- if (collectionRef.current && (_collectionRef$curren10 = collectionRef.current) !== null && _collectionRef$curren10 !== void 0 && _collectionRef$curren10.hasNext) {
215
+ var _collectionRef$curren6;
216
+ if (collectionRef.current && (_collectionRef$curren6 = collectionRef.current) !== null && _collectionRef$curren6 !== void 0 && _collectionRef$curren6.hasNext) {
187
217
  try {
188
- var _collectionRef$curren11;
189
-
190
- const fetchedList = await ((_collectionRef$curren11 = collectionRef.current) === null || _collectionRef$curren11 === void 0 ? void 0 : _collectionRef$curren11.loadNext());
191
- messageCandidates.push(...fetchedList);
218
+ var _collectionRef$curren7;
219
+ const fetchedList = await ((_collectionRef$curren7 = collectionRef.current) === null || _collectionRef$curren7 === void 0 ? void 0 : _collectionRef$curren7.loadNext());
220
+ updateMessages(fetchedList, false, sdk.currentUser.userId);
192
221
  } catch {}
193
222
  }
194
-
195
- if (nextMessages.length > 0) {
196
- messageCandidates.push(...nextMessages);
197
- }
198
-
199
- if (messageCandidates.length > 0) {
200
- updateMessages(messageCandidates, false, sdk.currentUser.userId);
201
- updateNextMessages([], true, sdk.currentUser.userId);
223
+ });
224
+ const hasNext = (0, _uikitUtils.useFreshCallback)(() => {
225
+ if (collectionInitializedRef.current && collectionRef.current) {
226
+ return collectionRef.current.hasNext;
227
+ } else {
228
+ return false;
202
229
  }
203
230
  });
204
231
  const sendUserMessage = (0, _uikitUtils.useFreshCallback)((params, onPending) => {
@@ -213,8 +240,8 @@ const useGroupChannelMessagesWithCollection = (sdk, channel, userId, options) =>
213
240
  updateMessages([sentMessage], false, sdk.currentUser.userId);
214
241
  resolve(sentMessage);
215
242
  }
216
- }).onFailed((err, _failedMessage) => {
217
- // updateMessages([failedMessage], false, sdk.currentUser.userId);
243
+ }).onFailed((err, failedMessage) => {
244
+ updateMessages([failedMessage], false, sdk.currentUser.userId);
218
245
  reject(err);
219
246
  });
220
247
  });
@@ -231,8 +258,8 @@ const useGroupChannelMessagesWithCollection = (sdk, channel, userId, options) =>
231
258
  updateMessages([sentMessage], false, sdk.currentUser.userId);
232
259
  resolve(sentMessage);
233
260
  }
234
- }).onFailed((err, _failedMessage) => {
235
- // updateMessages([failedMessage], false, sdk.currentUser.userId);
261
+ }).onFailed((err, failedMessage) => {
262
+ updateMessages([failedMessage], false, sdk.currentUser.userId);
236
263
  reject(err);
237
264
  });
238
265
  });
@@ -261,31 +288,45 @@ const useGroupChannelMessagesWithCollection = (sdk, channel, userId, options) =>
261
288
  if (message.isFileMessage()) await channel.deleteMessage(message);
262
289
  } else {
263
290
  try {
264
- var _collectionRef$curren12;
265
-
266
- await ((_collectionRef$curren12 = collectionRef.current) === null || _collectionRef$curren12 === void 0 ? void 0 : _collectionRef$curren12.removeFailedMessage(message.reqId));
291
+ var _collectionRef$curren8;
292
+ await ((_collectionRef$curren8 = collectionRef.current) === null || _collectionRef$curren8 === void 0 ? void 0 : _collectionRef$curren8.removeFailedMessage(message.reqId));
267
293
  } finally {
268
294
  deleteMessages([message.messageId], [message.reqId]);
269
295
  }
270
296
  }
271
297
  });
298
+ const resetNewMessages = (0, _uikitUtils.useFreshCallback)(() => {
299
+ updateNewMessages([], true, sdk.currentUser.userId);
300
+ });
301
+ const resetWithStartingPoint = (0, _uikitUtils.useFreshCallback)((startingPoint, callback) => {
302
+ updateLoading(true);
303
+ updateMessages([], true, sdk.currentUser.userId);
304
+ init(startingPoint, MESSAGE_LIMIT.DEFAULT, () => {
305
+ updateLoading(false);
306
+ callback === null || callback === void 0 ? void 0 : callback();
307
+ });
308
+ });
272
309
  return {
273
310
  loading,
274
311
  refreshing,
275
312
  refresh,
276
313
  messages,
277
- nextMessages,
278
- newMessagesFromMembers,
279
314
  next,
315
+ hasNext,
280
316
  prev,
317
+ hasPrev,
318
+ newMessages,
319
+ resetNewMessages,
281
320
  sendUserMessage,
282
321
  sendFileMessage,
283
322
  updateUserMessage,
284
323
  updateFileMessage,
285
324
  resendMessage,
286
- deleteMessage
325
+ deleteMessage,
326
+ resetWithStartingPoint,
327
+ nextMessages: newMessages,
328
+ newMessagesFromMembers: newMessages
287
329
  };
288
330
  };
289
-
290
331
  exports.useGroupChannelMessagesWithCollection = useGroupChannelMessagesWithCollection;
291
332
  //# sourceMappingURL=useGroupChannelMessagesWithCollection.js.map