stream-chat-react-native-core 5.5.0-beta.1 → 5.5.0-beta.3

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.
@@ -55,7 +55,7 @@ var useConnectionRecovered = function useConnectionRecovered(_ref) {
55
55
  });
56
56
  cids = (0, _getAllChannelIds.getAllChannelIds)();
57
57
 
58
- if (!lastSyncedAt) {
58
+ if (!(lastSyncedAt && cids != null && cids.length)) {
59
59
  _context.next = 16;
60
60
  break;
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useConnectionRecovered.ts"],"names":["useConnectionRecovered","client","enableOfflineSupport","connectionRecoveredCallbacks","setConnectionRecoveredCallbacks","sync","user","lastSyncedAt","currentUserId","id","cids","Date","toISOString","result","queries","events","reduce","event","concat","length","QuickSqliteClient","executeSqlBatch","resetDB","toString","handleEvent","forEach","c","connectionChangedListener","on","online","unsubscribe","subscribeConnectionRecoveredCallback","listener","callbacks","filter","el"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AASO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,OAKJ;AAAA,MAFhCC,MAEgC,QAFhCA,MAEgC;AAAA,MADhCC,oBACgC,QADhCA,oBACgC;;AAChC,kBAAwE,qBAEtE,EAFsE,CAAxE;AAAA;AAAA,MAAOC,4BAAP;AAAA,MAAqCC,+BAArC;;AAIA,wBAAU,YAAM;AACd,QAAMC,IAAI;AAAA,kFAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBACNJ,MADM,YACNA,MAAM,CAAEK,IADF;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAGLC,gBAAAA,YAHK,GAGU,sCAAgB;AACnCC,kBAAAA,aAAa,EAAEP,MAAM,CAACK,IAAP,CAAYG;AADQ,iBAAhB,CAHV;AAMLC,gBAAAA,IANK,GAME,yCANF;;AAAA,qBAQPH,YARO;AAAA;AAAA;AAAA;;AAAA;AAA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,CAAC2B,EAAP,CAAU,oBAAV,EAAgC,UAACX,KAAD,EAAW;AACrE,YAAIA,KAAK,CAACY,MAAV,EAAkB;AAChBL,UAAAA,WAAW,CAACP,KAAD,CAAX;AACD;AACF,OAJ2B,CAA5B;AAKD;;AAED,WAAO,YAAM;AAAA;;AACX,+BAAAU,yBAAyB,SAAzB,kCAA2BG,WAA3B,0CAA2BA,WAA3B;AACD,KAFD;AAGD,GApDD,EAoDG,CAAC7B,MAAD,EAASE,4BAA4B,CAACgB,MAAtC,CApDH;AAsDA,SAAO;AACLY,IAAAA,oCAAoC,EAAE,8CAACC,QAAD,EAAgD;AACpF5B,MAAAA,+BAA+B,CAAC,UAAC6B,SAAD;AAAA,6DAAmBA,SAAnB,IAA8BD,QAA9B;AAAA,OAAD,CAA/B;AAEA,aAAO,YAAM;AACX5B,QAAAA,+BAA+B,CAAC,UAAC6B,SAAD;AAAA,iBAAeA,SAAS,CAACC,MAAV,CAAiB,UAACC,EAAD;AAAA,mBAAQA,EAAE,KAAKH,QAAf;AAAA,WAAjB,CAAf;AAAA,SAAD,CAA/B;AACD,OAFD;AAGD;AAPI,GAAP;AASD,CAzEM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Event, EventHandler, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from './handleEventToSyncDB';\n\nimport { getAllChannelIds } from '../../../store/apis/getAllChannelIds';\nimport { getLastSyncedAt } from '../../../store/apis/getLastSyncedAt';\nimport { upsertLastSyncedAt } from '../../../store/apis/upsertLastSyncedAt';\nimport { QuickSqliteClient } from '../../../store/QuickSqliteClient';\nimport type { PreparedQueries } from '../../../store/types';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\ntype Params<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {\n client: StreamChat<StreamChatGenerics>;\n enableOfflineSupport: boolean;\n};\n\nexport const useConnectionRecovered = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n client,\n enableOfflineSupport,\n}: Params<StreamChatGenerics>) => {\n const [connectionRecoveredCallbacks, setConnectionRecoveredCallbacks] = useState<\n EventHandler<StreamChatGenerics>[]\n >([]);\n\n useEffect(() => {\n const sync = async () => {\n if (!client?.user) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: client.user.id,\n });\n const cids = getAllChannelIds();\n\n if (lastSyncedAt) {\n try {\n const result = await client.sync(cids, new Date(lastSyncedAt).toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // do nothing\n QuickSqliteClient.resetDB();\n }\n }\n upsertLastSyncedAt({\n currentUserId: client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n const handleEvent = async (event: Event<StreamChatGenerics>) => {\n if (enableOfflineSupport) {\n await sync();\n }\n\n connectionRecoveredCallbacks.forEach((c) => c(event));\n };\n\n let connectionChangedListener: ReturnType<StreamChat['on']>;\n\n if (client) {\n connectionChangedListener = client.on('connection.changed', (event) => {\n if (event.online) {\n handleEvent(event);\n }\n });\n }\n\n return () => {\n connectionChangedListener?.unsubscribe?.();\n };\n }, [client, connectionRecoveredCallbacks.length]);\n\n return {\n subscribeConnectionRecoveredCallback: (listener: EventHandler<StreamChatGenerics>) => {\n setConnectionRecoveredCallbacks((callbacks) => [...callbacks, listener]);\n\n return () => {\n setConnectionRecoveredCallbacks((callbacks) => callbacks.filter((el) => el !== listener));\n };\n },\n };\n};\n"]}
1
+ {"version":3,"sources":["useConnectionRecovered.ts"],"names":["useConnectionRecovered","client","enableOfflineSupport","connectionRecoveredCallbacks","setConnectionRecoveredCallbacks","sync","user","lastSyncedAt","currentUserId","id","cids","length","Date","toISOString","result","queries","events","reduce","event","concat","QuickSqliteClient","executeSqlBatch","resetDB","toString","handleEvent","forEach","c","connectionChangedListener","on","online","un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AA,+BAA+B,CAAC,UAAC6B,SAAD;AAAA,iBAAeA,SAAS,CAACC,MAAV,CAAiB,UAACC,EAAD;AAAA,mBAAQA,EAAE,KAAKH,QAAf;AAAA,WAAjB,CAAf;AAAA,SAAD,CAA/B;AACD,OAFD;AAGD;AAPI,GAAP;AASD,CAzEM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Event, EventHandler, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from './handleEventToSyncDB';\n\nimport { getAllChannelIds } from '../../../store/apis/getAllChannelIds';\nimport { getLastSyncedAt } from '../../../store/apis/getLastSyncedAt';\nimport { upsertLastSyncedAt } from '../../../store/apis/upsertLastSyncedAt';\nimport { QuickSqliteClient } from '../../../store/QuickSqliteClient';\nimport type { PreparedQueries } from '../../../store/types';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\ntype Params<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {\n client: StreamChat<StreamChatGenerics>;\n enableOfflineSupport: boolean;\n};\n\nexport const useConnectionRecovered = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n client,\n enableOfflineSupport,\n}: Params<StreamChatGenerics>) => {\n const [connectionRecoveredCallbacks, setConnectionRecoveredCallbacks] = useState<\n EventHandler<StreamChatGenerics>[]\n >([]);\n\n useEffect(() => {\n const sync = async () => {\n if (!client?.user) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: client.user.id,\n });\n const cids = getAllChannelIds();\n\n if (lastSyncedAt && cids?.length) {\n try {\n const result = await client.sync(cids, new Date(lastSyncedAt).toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // do nothing\n QuickSqliteClient.resetDB();\n }\n }\n upsertLastSyncedAt({\n currentUserId: client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n const handleEvent = async (event: Event<StreamChatGenerics>) => {\n if (enableOfflineSupport) {\n await sync();\n }\n\n connectionRecoveredCallbacks.forEach((c) => c(event));\n };\n\n let connectionChangedListener: ReturnType<StreamChat['on']>;\n\n if (client) {\n connectionChangedListener = client.on('connection.changed', (event) => {\n if (event.online) {\n handleEvent(event);\n }\n });\n }\n\n return () => {\n connectionChangedListener?.unsubscribe?.();\n };\n }, [client, connectionRecoveredCallbacks.length]);\n\n return {\n subscribeConnectionRecoveredCallback: (listener: EventHandler<StreamChatGenerics>) => {\n setConnectionRecoveredCallbacks((callbacks) => [...callbacks, listener]);\n\n return () => {\n setConnectionRecoveredCallbacks((callbacks) => callbacks.filter((el) => el !== listener));\n };\n },\n };\n};\n"]}
@@ -40,7 +40,7 @@ var getReadStates = function getReadStates(clientUserId, messages, read) {
40
40
  return "continue";
41
41
  }
42
42
 
43
- if (message.updated_at < member.last_read) {
43
+ if (message.created_at < member.last_read) {
44
44
  var numberOfReads = Object.keys(read).length;
45
45
 
46
46
  if (numberOfReads === 1) {
@@ -1 +1 @@
1
- {"version":3,"sources":["getReadStates.ts"],"names":["getReadStates","clientUserId","messages","read","readData","reduce","acc","cur","id","filteredMessagesReversed","filter","msg","updated_at","reverse","members","Object","values","memberReadCount","message","length","member","last_read","numberOfReads","keys","currentMessageReadData","userIndex","findIndex","user","splice"],"mappings":";;;;;;;;;;;AAKO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAG3BC,YAH2B,EAI3BC,QAJ2B,EAO3BC,IAP2B,EAQxB;AACH,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,MAAT,CAAgB,UAACC,GAAD,EAAMC,GAAN,EAAc;AAC7C,QAAIA,GAAG,CAACC,EAAR,EAAY;AACVF,MAAAA,GAAG,CAACC,GAAG,CAACC,EAAL,CAAH,GAAc,KAAd;AACD;;AACD,WAAOF,GAAP;AACD,GALgB,EAKd,EALc,CAAjB;AAOA,MAAMG,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AAY,aAAanB,EAAzB,CAAd;AAAA,aAAlB,CAAlB;;AACA,gBAAIiB,SAAS,KAAK,CAAC,CAAnB,EAAsB;AACpBX,cAAAA,OAAO,CAACc,MAAR,CAAeH,SAAf,EAA0B,CAA1B;;AACA,kBAAIH,aAAa,GAAG,CAApB,EAAuB;AACrBL,gBAAAA,eAAe,IAAI,CAAnB;AACD;AACF;AACF;AAtCE;;AACL,8DAAqBH,OAArB,2CAA8B;AAAA,cAAnBM,MAAmB;;AAAA,2BAAnBA,MAAmB;;AAAA,mCAO1B;AA+BH;;AAOD,YAAIhB,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,KAAyB,KAA7B,EAAoC;AAClCJ,UAAAA,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,GAAuBS,eAAe,IAAI,KAA1C;AACD;AACF;AACF;AACF;;AAED,SAAOb,QAAP;AACD,CArGM","sourcesContent":["import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\nexport const getReadStates = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n clientUserId: string | undefined,\n messages:\n | PaginatedMessageListContextValue<StreamChatGenerics>['messages']\n | ThreadContextValue<StreamChatGenerics>['threadMessages'],\n read?: ChannelContextValue<StreamChatGenerics>['read'],\n) => {\n const readData = messages.reduce((acc, cur) => {\n if (cur.id) {\n acc[cur.id] = false;\n }\n return acc;\n }, {} as { [key: string]: boolean | number });\n\n const filteredMessagesReversed = messages.filter((msg) => msg.updated_at).reverse();\n\n if (read) {\n /**\n * Channel read state is stored by user and we only care about users who aren't the client\n */\n if (clientUserId) {\n delete read[clientUserId];\n }\n const members = Object.values(read);\n\n /**\n * Track number of members who have read previous messages\n */\n let memberReadCount = 0;\n\n /**\n * Array is in reverse order so newest message is at 0,\n * we find the index of the first message that is older\n * than the last read and then set last read to that, or\n * if there are no newer messages, the first message is\n * last read message.\n */\n for (const message of filteredMessagesReversed) {\n /**\n * If all members are removed then they have read these\n * messages. We do not increment memberReadCount for 1:1\n * chats, so this should be true, not a number in that case.\n */\n if (!members.length) {\n readData[message.id] = memberReadCount || true;\n } else {\n for (const member of members) {\n /**\n * If no last read continue, we can't remove the user\n * because this would mark all messages in a new channel\n * true until at least one other user reads a message.\n */\n if (!member.last_read) {\n continue;\n }\n\n /**\n * If there there is a last read message add the user\n * to the array of last reads for that message and remove\n * the user from the list of users being checked\n */\n if (message.updated_at < member.last_read) {\n /**\n * if this is a direct message the length will be 1\n * as we already deleted the current user from the object\n */\n const numberOfReads = Object.keys(read).length;\n if (numberOfReads === 1) {\n readData[message.id] = true;\n } else {\n const currentMessageReadData = readData[message.id];\n readData[message.id] =\n typeof currentMessageReadData === 'boolean'\n ? memberReadCount + 1\n : currentMessageReadData + 1;\n }\n const userIndex = members.findIndex(({ user }) => user.id === member.user?.id);\n if (userIndex !== -1) {\n members.splice(userIndex, 1);\n if (numberOfReads > 1) {\n memberReadCount += 1;\n }\n }\n }\n }\n\n /**\n * If this is not the last message for a user this will still be\n * set to false. But if other users have read further the number\n * should be how many have read beyond this message.\n */\n if (readData[message.id] === false) {\n readData[message.id] = memberReadCount || false;\n }\n }\n }\n }\n\n return readData;\n};\n"]}
1
+ {"version":3,"sources":["getReadStates.ts"],"names":["getReadStates","clientUserId","messages","read","readData","reduce","acc","cur","id","filteredMessagesReversed","filter","msg","updated_at","reverse","members","Object","values","memberReadCount","message","length","member","last_read","created_at","numberOfReads","keys","currentMessageReadData","userIndex","findIndex","user","splice"],"mappings":";;;;;;;;;;;AAKO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAG3BC,YAH2B,EAI3BC,QAJ2B,EAO3BC,IAP2B,EAQxB;AACH,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,MAAT,CAAgB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B,GAEIQ,sBAAsB,GAAG,CAH/B;AAID;;AACD,gBAAMC,SAAS,GAAGZ,OAAO,CAACa,SAAR,CAAkB;AAAA;;AAAA,kBAAGC,IAAH,QAAGA,IAAH;AAAA,qBAAcA,IAAI,CAACpB,EAAL,sBAAYY,MAAM,CAACQ,IAAnB,qBAAY,aAAapB,EAAzB,CAAd;AAAA,aAAlB,CAAlB;;AACA,gBAAIkB,SAAS,KAAK,CAAC,CAAnB,EAAsB;AACpBZ,cAAAA,OAAO,CAACe,MAAR,CAAeH,SAAf,EAA0B,CAA1B;;AACA,kBAAIH,aAAa,GAAG,CAApB,EAAuB;AACrBN,gBAAAA,eAAe,IAAI,CAAnB;AACD;AACF;AACF;AAtCE;;AACL,8DAAqBH,OAArB,2CAA8B;AAAA,cAAnBM,MAAmB;;AAAA,2BAAnBA,MAAmB;;AAAA,mCAO1B;AA+BH;;AAOD,YAAIhB,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,KAAyB,KAA7B,EAAoC;AAClCJ,UAAAA,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,GAAuBS,eAAe,IAAI,KAA1C;AACD;AACF;AACF;AACF;;AAED,SAAOb,QAAP;AACD,CArGM","sourcesContent":["import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\nexport const getReadStates = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n clientUserId: string | undefined,\n messages:\n | PaginatedMessageListContextValue<StreamChatGenerics>['messages']\n | ThreadContextValue<StreamChatGenerics>['threadMessages'],\n read?: ChannelContextValue<StreamChatGenerics>['read'],\n) => {\n const readData = messages.reduce((acc, cur) => {\n if (cur.id) {\n acc[cur.id] = false;\n }\n return acc;\n }, {} as { [key: string]: boolean | number });\n\n const filteredMessagesReversed = messages.filter((msg) => msg.updated_at).reverse();\n\n if (read) {\n /**\n * Channel read state is stored by user and we only care about users who aren't the client\n */\n if (clientUserId) {\n delete read[clientUserId];\n }\n const members = Object.values(read);\n\n /**\n * Track number of members who have read previous messages\n */\n let memberReadCount = 0;\n\n /**\n * Array is in reverse order so newest message is at 0,\n * we find the index of the first message that is older\n * than the last read and then set last read to that, or\n * if there are no newer messages, the first message is\n * last read message.\n */\n for (const message of filteredMessagesReversed) {\n /**\n * If all members are removed then they have read these\n * messages. We do not increment memberReadCount for 1:1\n * chats, so this should be true, not a number in that case.\n */\n if (!members.length) {\n readData[message.id] = memberReadCount || true;\n } else {\n for (const member of members) {\n /**\n * If no last read continue, we can't remove the user\n * because this would mark all messages in a new channel\n * true until at least one other user reads a message.\n */\n if (!member.last_read) {\n continue;\n }\n\n /**\n * If there there is a last read message add the user\n * to the array of last reads for that message and remove\n * the user from the list of users being checked\n */\n if (message.created_at < member.last_read) {\n /**\n * if this is a direct message the length will be 1\n * as we already deleted the current user from the object\n */\n const numberOfReads = Object.keys(read).length;\n if (numberOfReads === 1) {\n readData[message.id] = true;\n } else {\n const currentMessageReadData = readData[message.id];\n readData[message.id] =\n typeof currentMessageReadData === 'boolean'\n ? memberReadCount + 1\n : currentMessageReadData + 1;\n }\n const userIndex = members.findIndex(({ user }) => user.id === member.user?.id);\n if (userIndex !== -1) {\n members.splice(userIndex, 1);\n if (numberOfReads > 1) {\n memberReadCount += 1;\n }\n }\n }\n }\n\n /**\n * If this is not the last message for a user this will still be\n * set to false. But if other users have read further the number\n * should be how many have read beyond this message.\n */\n if (readData[message.id] === false) {\n readData[message.id] = memberReadCount || false;\n }\n }\n }\n }\n\n return readData;\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.5.0-beta.1"
2
+ "version": "5.5.0-beta.3"
3
3
  }
@@ -55,7 +55,7 @@ var useConnectionRecovered = function useConnectionRecovered(_ref) {
55
55
  });
56
56
  cids = (0, _getAllChannelIds.getAllChannelIds)();
57
57
 
58
- if (!lastSyncedAt) {
58
+ if (!(lastSyncedAt && cids != null && cids.length)) {
59
59
  _context.next = 16;
60
60
  break;
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useConnectionRecovered.ts"],"names":["useConnectionRecovered","client","enableOfflineSupport","connectionRecoveredCallbacks","setConnectionRecoveredCallbacks","sync","user","lastSyncedAt","currentUserId","id","cids","Date","toISOString","result","queries","events","reduce","event","concat","length","QuickSqliteClient","executeSqlBatch","resetDB","toString","handleEvent","forEach","c","connectionChangedListener","on","online","unsubscribe","subscribeConnectionRecoveredCallback","listener","callbacks","filter","el"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AASO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,OAKJ;AAAA,MAFhCC,MAEgC,QAFhCA,MAEgC;AAAA,MADhCC,oBACgC,QADhCA,oBACgC;;AAChC,kBAAwE,qBAEtE,EAFsE,CAAxE;AAAA;AAAA,MAAOC,4BAAP;AAAA,MAAqCC,+BAArC;;AAIA,wBAAU,YAAM;AACd,QAAMC,IAAI;AAAA,kFAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBACNJ,MADM,YACNA,MAAM,CAAEK,IADF;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAGLC,gBAAAA,YAHK,GAGU,sCAAgB;AACnCC,kBAAAA,aAAa,EAAEP,MAAM,CAACK,IAAP,CAAYG;AADQ,iBAAhB,CAHV;AAMLC,gBAAAA,IANK,GAME,yCANF;;AAAA,qBAQPH,YARO;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,uBAUcN,MAAM,CAACI,IAAP,CAAYK,IAAZ,EAAkB,IAAIC,IAAJ,CAASJ,YAAT,EAAuBK,WAAvB,EAAlB,CAVd;;AAAA;AAUDC,gBAAAA,MAVC;AAWDC,gBAAAA,OAXC,GAWSD,MAAM,CAACE,MAAP,CAAc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BAAAU,yBAAyB,SAAzB,kCAA2BG,WAA3B,0CAA2BA,WAA3B;AACD,KAFD;AAGD,GApDD,EAoDG,CAAC7B,MAAD,EAASE,4BAA4B,CAACgB,MAAtC,CApDH;AAsDA,SAAO;AACLY,IAAAA,oCAAoC,EAAE,8CAACC,QAAD,EAAgD;AACpF5B,MAAAA,+BAA+B,CAAC,UAAC6B,SAAD;AAAA,6DAAmBA,SAAnB,IAA8BD,QAA9B;AAAA,OAAD,CAA/B;AAEA,aAAO,YAAM;AACX5B,QAAAA,+BAA+B,CAAC,UAAC6B,SAAD;AAAA,iBAAeA,SAAS,CAACC,MAAV,CAAiB,UAACC,EAAD;AAAA,mBAAQA,EAAE,KAAKH,QAAf;AAAA,WAAjB,CAAf;AAAA,SAAD,CAA/B;AACD,OAFD;AAGD;AAPI,GAAP;AASD,CAzEM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Event, EventHandler, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from './handleEventToSyncDB';\n\nimport { getAllChannelIds } from '../../../store/apis/getAllChannelIds';\nimport { getLastSyncedAt } from '../../../store/apis/getLastSyncedAt';\nimport { upsertLastSyncedAt } from '../../../store/apis/upsertLastSyncedAt';\nimport { QuickSqliteClient } from '../../../store/QuickSqliteClient';\nimport type { PreparedQueries } from '../../../store/types';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\ntype Params<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {\n client: StreamChat<StreamChatGenerics>;\n enableOfflineSupport: boolean;\n};\n\nexport const useConnectionRecovered = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n client,\n enableOfflineSupport,\n}: Params<StreamChatGenerics>) => {\n const [connectionRecoveredCallbacks, setConnectionRecoveredCallbacks] = useState<\n EventHandler<StreamChatGenerics>[]\n >([]);\n\n useEffect(() => {\n const sync = async () => {\n if (!client?.user) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: client.user.id,\n });\n const cids = getAllChannelIds();\n\n if (lastSyncedAt) {\n try {\n const result = await client.sync(cids, new Date(lastSyncedAt).toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // do nothing\n QuickSqliteClient.resetDB();\n }\n }\n upsertLastSyncedAt({\n currentUserId: client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n const handleEvent = async (event: Event<StreamChatGenerics>) => {\n if (enableOfflineSupport) {\n await sync();\n }\n\n connectionRecoveredCallbacks.forEach((c) => c(event));\n };\n\n let connectionChangedListener: ReturnType<StreamChat['on']>;\n\n if (client) {\n connectionChangedListener = client.on('connection.changed', (event) => {\n if (event.online) {\n handleEvent(event);\n }\n });\n }\n\n return () => {\n connectionChangedListener?.unsubscribe?.();\n };\n }, [client, connectionRecoveredCallbacks.length]);\n\n return {\n subscribeConnectionRecoveredCallback: (listener: EventHandler<StreamChatGenerics>) => {\n setConnectionRecoveredCallbacks((callbacks) => [...callbacks, listener]);\n\n return () => {\n setConnectionRecoveredCallbacks((callbacks) => callbacks.filter((el) => el !== listener));\n };\n },\n };\n};\n"]}
1
+ {"version":3,"sources":["useConnectionRecovered.ts"],"names":["useConnectionRecovered","client","enableOfflineSupport","connectionRecoveredCallbacks","setConnectionRecoveredCallbacks","sync","user","lastSyncedAt","currentUserId","id","cids","length","Date","toISOString","result","queries","events","reduce","event","concat","QuickSqliteClient","executeSqlBatch","resetDB","toString","handleEvent","forEach","c","connectionChangedListener","on","online","unsubscribe","subscribeConnectionRecoveredCallback","listener","callbacks","filter","el"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AASO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,OAKJ;AAAA,MAFhCC,MAEgC,QAFhCA,MAEg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EM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Event, EventHandler, StreamChat } from 'stream-chat';\n\nimport { handleEventToSyncDB } from './handleEventToSyncDB';\n\nimport { getAllChannelIds } from '../../../store/apis/getAllChannelIds';\nimport { getLastSyncedAt } from '../../../store/apis/getLastSyncedAt';\nimport { upsertLastSyncedAt } from '../../../store/apis/upsertLastSyncedAt';\nimport { QuickSqliteClient } from '../../../store/QuickSqliteClient';\nimport type { PreparedQueries } from '../../../store/types';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\ntype Params<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {\n client: StreamChat<StreamChatGenerics>;\n enableOfflineSupport: boolean;\n};\n\nexport const useConnectionRecovered = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n client,\n enableOfflineSupport,\n}: Params<StreamChatGenerics>) => {\n const [connectionRecoveredCallbacks, setConnectionRecoveredCallbacks] = useState<\n EventHandler<StreamChatGenerics>[]\n >([]);\n\n useEffect(() => {\n const sync = async () => {\n if (!client?.user) return;\n\n const lastSyncedAt = getLastSyncedAt({\n currentUserId: client.user.id,\n });\n const cids = getAllChannelIds();\n\n if (lastSyncedAt && cids?.length) {\n try {\n const result = await client.sync(cids, new Date(lastSyncedAt).toISOString());\n const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {\n queries = queries.concat(handleEventToSyncDB(event, false));\n return queries;\n }, []);\n\n if (queries.length) {\n QuickSqliteClient.executeSqlBatch(queries);\n }\n } catch (e) {\n // do nothing\n QuickSqliteClient.resetDB();\n }\n }\n upsertLastSyncedAt({\n currentUserId: client.user.id,\n lastSyncedAt: new Date().toString(),\n });\n };\n\n const handleEvent = async (event: Event<StreamChatGenerics>) => {\n if (enableOfflineSupport) {\n await sync();\n }\n\n connectionRecoveredCallbacks.forEach((c) => c(event));\n };\n\n let connectionChangedListener: ReturnType<StreamChat['on']>;\n\n if (client) {\n connectionChangedListener = client.on('connection.changed', (event) => {\n if (event.online) {\n handleEvent(event);\n }\n });\n }\n\n return () => {\n connectionChangedListener?.unsubscribe?.();\n };\n }, [client, connectionRecoveredCallbacks.length]);\n\n return {\n subscribeConnectionRecoveredCallback: (listener: EventHandler<StreamChatGenerics>) => {\n setConnectionRecoveredCallbacks((callbacks) => [...callbacks, listener]);\n\n return () => {\n setConnectionRecoveredCallbacks((callbacks) => callbacks.filter((el) => el !== listener));\n };\n },\n };\n};\n"]}
@@ -40,7 +40,7 @@ var getReadStates = function getReadStates(clientUserId, messages, read) {
40
40
  return "continue";
41
41
  }
42
42
 
43
- if (message.updated_at < member.last_read) {
43
+ if (message.created_at < member.last_read) {
44
44
  var numberOfReads = Object.keys(read).length;
45
45
 
46
46
  if (numberOfReads === 1) {
@@ -1 +1 @@
1
- {"version":3,"sources":["getReadStates.ts"],"names":["getReadStates","clientUserId","messages","read","readData","reduce","acc","cur","id","filteredMessagesReversed","filter","msg","updated_at","reverse","members","Object","values","memberReadCount","message","length","member","last_read","numberOfReads","keys","currentMessageReadData","userIndex","findIndex","user","splice"],"mappings":";;;;;;;;;;;AAKO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAG3BC,YAH2B,EAI3BC,QAJ2B,EAO3BC,IAP2B,EAQxB;AACH,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,MAAT,CAAgB,UAACC,GAAD,EAAMC,GAAN,EAAc;AAC7C,QAAIA,GAAG,CAACC,EAAR,EAAY;AACVF,MAAAA,GAAG,CAACC,GAAG,CAACC,EAAL,CAAH,GAAc,KAAd;AACD;;AACD,WAAOF,GAAP;AACD,GALgB,EAKd,EALc,CAAjB;AAOA,MAAMG,wBAAwB,GAAGP,QAAQ,CAACQ,MAAT,CAAgB,UAACC,GAAD;AAAA,WAASA,GAAG,CAACC,UAAb;AAAA,GAAhB,EAAyCC,OAAzC,EAAjC;;AAEA,MAAIV,IAAJ,EAAU;AAIR,QAAIF,YAAJ,EAAkB;AAChB,aAAOE,IAA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AACrBL,gBAAAA,eAAe,IAAI,CAAnB;AACD;AACF;AACF;AAtCE;;AACL,8DAAqBH,OAArB,2CAA8B;AAAA,cAAnBM,MAAmB;;AAAA,2BAAnBA,MAAmB;;AAAA,mCAO1B;AA+BH;;AAOD,YAAIhB,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,KAAyB,KAA7B,EAAoC;AAClCJ,UAAAA,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,GAAuBS,eAAe,IAAI,KAA1C;AACD;AACF;AACF;AACF;;AAED,SAAOb,QAAP;AACD,CArGM","sourcesContent":["import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\nexport const getReadStates = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n clientUserId: string | undefined,\n messages:\n | PaginatedMessageListContextValue<StreamChatGenerics>['messages']\n | ThreadContextValue<StreamChatGenerics>['threadMessages'],\n read?: ChannelContextValue<StreamChatGenerics>['read'],\n) => {\n const readData = messages.reduce((acc, cur) => {\n if (cur.id) {\n acc[cur.id] = false;\n }\n return acc;\n }, {} as { [key: string]: boolean | number });\n\n const filteredMessagesReversed = messages.filter((msg) => msg.updated_at).reverse();\n\n if (read) {\n /**\n * Channel read state is stored by user and we only care about users who aren't the client\n */\n if (clientUserId) {\n delete read[clientUserId];\n }\n const members = Object.values(read);\n\n /**\n * Track number of members who have read previous messages\n */\n let memberReadCount = 0;\n\n /**\n * Array is in reverse order so newest message is at 0,\n * we find the index of the first message that is older\n * than the last read and then set last read to that, or\n * if there are no newer messages, the first message is\n * last read message.\n */\n for (const message of filteredMessagesReversed) {\n /**\n * If all members are removed then they have read these\n * messages. We do not increment memberReadCount for 1:1\n * chats, so this should be true, not a number in that case.\n */\n if (!members.length) {\n readData[message.id] = memberReadCount || true;\n } else {\n for (const member of members) {\n /**\n * If no last read continue, we can't remove the user\n * because this would mark all messages in a new channel\n * true until at least one other user reads a message.\n */\n if (!member.last_read) {\n continue;\n }\n\n /**\n * If there there is a last read message add the user\n * to the array of last reads for that message and remove\n * the user from the list of users being checked\n */\n if (message.updated_at < member.last_read) {\n /**\n * if this is a direct message the length will be 1\n * as we already deleted the current user from the object\n */\n const numberOfReads = Object.keys(read).length;\n if (numberOfReads === 1) {\n readData[message.id] = true;\n } else {\n const currentMessageReadData = readData[message.id];\n readData[message.id] =\n typeof currentMessageReadData === 'boolean'\n ? memberReadCount + 1\n : currentMessageReadData + 1;\n }\n const userIndex = members.findIndex(({ user }) => user.id === member.user?.id);\n if (userIndex !== -1) {\n members.splice(userIndex, 1);\n if (numberOfReads > 1) {\n memberReadCount += 1;\n }\n }\n }\n }\n\n /**\n * If this is not the last message for a user this will still be\n * set to false. But if other users have read further the number\n * should be how many have read beyond this message.\n */\n if (readData[message.id] === false) {\n readData[message.id] = memberReadCount || false;\n }\n }\n }\n }\n\n return readData;\n};\n"]}
1
+ {"version":3,"sources":["getReadStates.ts"],"names":["getReadStates","clientUserId","messages","read","readData","reduce","acc","cur","id","filteredMessagesReversed","filter","msg","updated_at","reverse","members","Object","values","memberReadCount","message","length","member","last_read","created_at","numberOfReads","keys","currentMessageReadData","userIndex","findIndex","user","splice"],"mappings":";;;;;;;;;;;AAKO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAG3BC,YAH2B,EAI3BC,QAJ2B,EAO3BC,IAP2B,EAQxB;AACH,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,MAAT,CAAgB,UAACC,GAAD,EAAMC,GAAN,EAAc;AAC7C,QAAIA,GAAG,CAACC,EAAR,EAAY;AACVF,MAAAA,GAAG,CAACC,GAAG,CAACC,EAAL,CAAH,GAAc,KAAd;AACD;;AACD,WAAOF,GAAP;AACD,GALgB,EAKd,EALc,CAAjB;AAOA,MA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,qBAAY,aAAapB,EAAzB,CAAd;AAAA,aAAlB,CAAlB;;AACA,gBAAIkB,SAAS,KAAK,CAAC,CAAnB,EAAsB;AACpBZ,cAAAA,OAAO,CAACe,MAAR,CAAeH,SAAf,EAA0B,CAA1B;;AACA,kBAAIH,aAAa,GAAG,CAApB,EAAuB;AACrBN,gBAAAA,eAAe,IAAI,CAAnB;AACD;AACF;AACF;AAtCE;;AACL,8DAAqBH,OAArB,2CAA8B;AAAA,cAAnBM,MAAmB;;AAAA,2BAAnBA,MAAmB;;AAAA,mCAO1B;AA+BH;;AAOD,YAAIhB,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,KAAyB,KAA7B,EAAoC;AAClCJ,UAAAA,QAAQ,CAACc,OAAO,CAACV,EAAT,CAAR,GAAuBS,eAAe,IAAI,KAA1C;AACD;AACF;AACF;AACF;;AAED,SAAOb,QAAP;AACD,CArGM","sourcesContent":["import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\n\nexport const getReadStates = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n clientUserId: string | undefined,\n messages:\n | PaginatedMessageListContextValue<StreamChatGenerics>['messages']\n | ThreadContextValue<StreamChatGenerics>['threadMessages'],\n read?: ChannelContextValue<StreamChatGenerics>['read'],\n) => {\n const readData = messages.reduce((acc, cur) => {\n if (cur.id) {\n acc[cur.id] = false;\n }\n return acc;\n }, {} as { [key: string]: boolean | number });\n\n const filteredMessagesReversed = messages.filter((msg) => msg.updated_at).reverse();\n\n if (read) {\n /**\n * Channel read state is stored by user and we only care about users who aren't the client\n */\n if (clientUserId) {\n delete read[clientUserId];\n }\n const members = Object.values(read);\n\n /**\n * Track number of members who have read previous messages\n */\n let memberReadCount = 0;\n\n /**\n * Array is in reverse order so newest message is at 0,\n * we find the index of the first message that is older\n * than the last read and then set last read to that, or\n * if there are no newer messages, the first message is\n * last read message.\n */\n for (const message of filteredMessagesReversed) {\n /**\n * If all members are removed then they have read these\n * messages. We do not increment memberReadCount for 1:1\n * chats, so this should be true, not a number in that case.\n */\n if (!members.length) {\n readData[message.id] = memberReadCount || true;\n } else {\n for (const member of members) {\n /**\n * If no last read continue, we can't remove the user\n * because this would mark all messages in a new channel\n * true until at least one other user reads a message.\n */\n if (!member.last_read) {\n continue;\n }\n\n /**\n * If there there is a last read message add the user\n * to the array of last reads for that message and remove\n * the user from the list of users being checked\n */\n if (message.created_at < member.last_read) {\n /**\n * if this is a direct message the length will be 1\n * as we already deleted the current user from the object\n */\n const numberOfReads = Object.keys(read).length;\n if (numberOfReads === 1) {\n readData[message.id] = true;\n } else {\n const currentMessageReadData = readData[message.id];\n readData[message.id] =\n typeof currentMessageReadData === 'boolean'\n ? memberReadCount + 1\n : currentMessageReadData + 1;\n }\n const userIndex = members.findIndex(({ user }) => user.id === member.user?.id);\n if (userIndex !== -1) {\n members.splice(userIndex, 1);\n if (numberOfReads > 1) {\n memberReadCount += 1;\n }\n }\n }\n }\n\n /**\n * If this is not the last message for a user this will still be\n * set to false. But if other users have read further the number\n * should be how many have read beyond this message.\n */\n if (readData[message.id] === false) {\n readData[message.id] = memberReadCount || false;\n }\n }\n }\n }\n\n return readData;\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.5.0-beta.1"
2
+ "version": "5.5.0-beta.3"
3
3
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stream-chat-react-native-core",
3
3
  "description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
4
- "version": "5.5.0-beta.1",
4
+ "version": "5.5.0-beta.3",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -35,7 +35,7 @@ export const useConnectionRecovered = <
35
35
  });
36
36
  const cids = getAllChannelIds();
37
37
 
38
- if (lastSyncedAt) {
38
+ if (lastSyncedAt && cids?.length) {
39
39
  try {
40
40
  const result = await client.sync(cids, new Date(lastSyncedAt).toISOString());
41
41
  const queries = result.events.reduce<PreparedQueries[]>((queries, event) => {
@@ -66,7 +66,7 @@ export const getReadStates = <
66
66
  * to the array of last reads for that message and remove
67
67
  * the user from the list of users being checked
68
68
  */
69
- if (message.updated_at < member.last_read) {
69
+ if (message.created_at < member.last_read) {
70
70
  /**
71
71
  * if this is a direct message the length will be 1
72
72
  * as we already deleted the current user from the object
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.5.0-beta.1"
2
+ "version": "5.5.0-beta.3"
3
3
  }