@@ -227,7 +227,7 @@ var INIT_USER = 'INIT_USER';
227227var RESET_USER = 'RESET_USER';
228228var UPDATE_USER_INFO = 'UPDATE_USER_INFO';
229229
230- var APP_VERSION_STRING = '1.3.1 ';
230+ var APP_VERSION_STRING = '1.3.2 ';
231231var disconnectSdk = function disconnectSdk(_ref) {
232232 var sdkDispatcher = _ref.sdkDispatcher,
233233 userDispatcher = _ref.userDispatcher,
@@ -6829,17 +6829,24 @@ function reducer$3(state, action) {
68296829 {
68306830 var _action$payload = action.payload,
68316831 channel = _action$payload.channel,
6832- message = _action$payload.message;
6832+ message = _action$payload.message,
6833+ scrollToEnd = _action$payload.scrollToEnd;
6834+ var unreadCount = 0;
68336835
68346836 var _state$currentGroupCh = state.currentGroupChannel,
68356837 _currentGroupChannel = _state$currentGroupCh === void 0 ? {} : _state$currentGroupCh,
6836- unreadCount = state.unreadCount,
68376838 unreadSince = state.unreadSince;
68386839
68396840 var currentGroupChannelUrl = _currentGroupChannel.url;
68406841
68416842 if (!compareIds(channel.url, currentGroupChannelUrl)) {
68426843 return state;
6844+ }
6845+
6846+ unreadCount = state.unreadCount + 1; // reset unreadCount if have to scrollToEnd
6847+
6848+ if (scrollToEnd) {
6849+ unreadCount = 0;
68436850 } // Excluded overlapping messages
68446851
68456852
@@ -6856,8 +6863,8 @@ function reducer$3(state, action) {
68566863 }
68576864
68586865 return _objectSpread2({}, state, {
6859- unreadCount: unreadCount + 1 ,
6860- unreadSince: unreadCount === 0 ? format(new Date(), 'p MMM dd') : unreadSince,
6866+ unreadCount: unreadCount,
6867+ unreadSince: unreadCount === 1 ? format(new Date(), 'p MMM dd') : unreadSince,
68616868 allMessages: passUnsuccessfullMessages(state.allMessages, message)
68626869 });
68636870 }
@@ -6946,7 +6953,8 @@ function useHandleChannelEvents(_ref, _ref2) {
69466953 sdkInit = _ref.sdkInit;
69476954 var messagesDispatcher = _ref2.messagesDispatcher,
69486955 sdk = _ref2.sdk,
6949- logger = _ref2.logger;
6956+ logger = _ref2.logger,
6957+ scrollRef = _ref2.scrollRef;
69506958 var channelUrl = currentGroupChannel && currentGroupChannel.url;
69516959 React.useEffect(function () {
69526960 var messageReciverId = uuidv4();
@@ -6958,13 +6966,33 @@ function useHandleChannelEvents(_ref, _ref2) {
69586966 ChannelHandler.onMessageReceived = function (channel, message) {
69596967 if (compareIds(channel.url, currentGroupChannel.url)) {
69606968 logger.info('Channel | useHandleChannelEvents: onMessageReceived', message);
6969+ var scrollToEnd = false;
6970+
6971+ try {
6972+ var current = scrollRef.current;
6973+ scrollToEnd = current.offsetHeight + current.scrollTop >= current.scrollHeight;
6974+ } catch (error) {//
6975+ }
6976+
69616977 messagesDispatcher({
69626978 type: ON_MESSAGE_RECEIVED,
69636979 payload: {
69646980 channel: channel,
6965- message: message
6981+ message: message,
6982+ scrollToEnd: scrollToEnd
69666983 }
69676984 });
6985+
6986+ if (scrollToEnd) {
6987+ try {
6988+ setTimeout(function () {
6989+ currentGroupChannel.markAsRead();
6990+ scrollIntoLast('.sendbird-msg--scroll-ref');
6991+ });
6992+ } catch (error) {
6993+ logger.warn('Channel | onMessageReceived | scroll to end failed');
6994+ }
6995+ }
69686996 }
69696997 };
69706998
@@ -11370,7 +11398,7 @@ MessageHoc.propTypes = {
1137011398 updateMessage: PropTypes.func.isRequired,
1137111399 resendMessage: PropTypes.func.isRequired,
1137211400 renderCustomMessage: PropTypes.func,
11373- currentGroupChannel: PropTypes.shape,
11401+ currentGroupChannel: PropTypes.shape({}) ,
1137411402 status: PropTypes.string,
1137511403 useReaction: PropTypes.bool.isRequired,
1137611404 chainTop: PropTypes.bool.isRequired,
@@ -12058,12 +12086,12 @@ var ConversationPanel = function ConversationPanel(props) {
1205812086
1205912087 useHandleChannelEvents({
1206012088 currentGroupChannel: currentGroupChannel,
12061- sdkInit: sdkInit,
12062- userId: userId
12089+ sdkInit: sdkInit
1206312090 }, {
1206412091 messagesDispatcher: messagesDispatcher,
1206512092 sdk: sdk,
12066- logger: logger
12093+ logger: logger,
12094+ scrollRef: scrollRef
1206712095 });
1206812096 useInitialMessagesFetch({
1206912097 currentGroupChannel: currentGroupChannel,
0 commit comments