Skip to content

Commit ba7d744

Browse files
Reload channel upon connection.changed
Related to - #494 v2.2.1 fixed the issue on reloading the ChannelList in case of connection.changed event. Although it skipped following two cases - If user is on Channel screen, the updated messages will reflect on ChannelList, but not on Channel component. This is because there no way for Channel component to know when ChannelList has refreshed. - If app has standalone Channel component. These two scenarios have been covered here.
1 parent 8529f9a commit ba7d744

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/components/Channel/Channel.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ export const Channel = <
393393
// The more complex sync logic is done in Chat.js
394394
// listen to client.connection.recovered and all channel events
395395
client.on('connection.recovered', handleEvent);
396+
client.on('connection.changed', (e) => {
397+
if (e.online) {
398+
reloadChannel();
399+
}
400+
});
396401
channel?.on(handleEvent);
397402
};
398403

@@ -418,6 +423,21 @@ export const Channel = <
418423
}
419424
};
420425

426+
const reloadChannel = async () => {
427+
setError(false);
428+
if (channel && channel.cid) {
429+
try {
430+
await channel.watch();
431+
} catch (err) {
432+
setError(err);
433+
return;
434+
}
435+
436+
setLastRead(new Date());
437+
copyChannelState();
438+
}
439+
};
440+
421441
/**
422442
* MESSAGE METHODS
423443
*/

0 commit comments

Comments
 (0)