Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 59790a7

Browse files
author
Sravan S
committed
[1.3.2](Jan 21, 2021)
<Channel /> : Autoscroll on message received if user is at end of scroll
1 parent 94a67f0 commit 59790a7

File tree

7 files changed

+87
-26
lines changed

7 files changed

+87
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.3.2](Jan 21, 2021)
4+
5+
- Bugfixes:
6+
* Scroll to end of list if user is at end of the conversation
7+
38
## [1.3.0](Nov 9, 2020)
49

510
- Features:

dist/index.es.js

Lines changed: 39 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ var INIT_USER = 'INIT_USER';
227227
var RESET_USER = 'RESET_USER';
228228
var UPDATE_USER_INFO = 'UPDATE_USER_INFO';
229229

230-
var APP_VERSION_STRING = '1.3.1';
230+
var APP_VERSION_STRING = '1.3.2';
231231
var 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,

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sendbird-uikit",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "React based UI kit for sendbird",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.js",

0 commit comments

Comments
 (0)