Skip to content

Commit 9547065

Browse files
authored
Merge pull request #208 from sendbird/feat/support-stream-scrolling
[AC-4084] feat: add scrolling for streaming message update
2 parents 6f74a16 + c4924bc commit 9547065

File tree

10 files changed

+44
-13
lines changed

10 files changed

+44
-13
lines changed

docs-validation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@react-native-firebase/messaging": "^14.7.0",
1515
"@react-navigation/native": "^6.1.17",
1616
"@react-navigation/native-stack": "^6.10.0",
17-
"@sendbird/chat": "^4.12.9",
17+
"@sendbird/chat": "^4.13.3",
1818
"date-fns": "^4.1.0",
1919
"react": "18.2.0",
2020
"react-native": "0.74.3",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
]
9999
},
100100
"resolutions": {
101-
"@sendbird/chat": "4.12.9",
101+
"@sendbird/chat": "4.13.3",
102102
"@types/react": "^18"
103103
}
104104
}

packages/uikit-chat-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"typescript": "5.2.2"
5656
},
5757
"peerDependencies": {
58-
"@sendbird/chat": "^4.12.9",
58+
"@sendbird/chat": "^4.13.3",
5959
"react": ">=16.13.1"
6060
},
6161
"react-native-builder-bob": {

packages/uikit-react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"@react-native-clipboard/clipboard": ">=1.8.5",
110110
"@react-native-community/netinfo": ">=9.3.0",
111111
"@react-native-firebase/messaging": ">=14.4.0",
112-
"@sendbird/chat": "^4.12.9",
112+
"@sendbird/chat": "^4.13.3",
113113
"@sendbird/react-native-scrollview-enhancer": "*",
114114
"date-fns": ">=2.28.0",
115115
"expo-av": ">=12.0.4",

packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => {
7575
});
7676

7777
useEffect(() => {
78-
return subscribe(({ type }) => {
78+
return subscribe(({ type, data }) => {
7979
switch (type) {
8080
case 'TYPING_BUBBLE_RENDERED':
8181
case 'MESSAGES_RECEIVED': {
@@ -84,6 +84,22 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => {
8484
}
8585
break;
8686
}
87+
case 'MESSAGES_UPDATED': {
88+
const lastMessage = props.channel.lastMessage;
89+
const [updatedMessage] = data.messages;
90+
91+
const lastMessageUpdated =
92+
updatedMessage && lastMessage && lastMessage.messageId === updatedMessage.messageId;
93+
94+
const isMaybeStreaming = props.channel.hasAiBot && lastMessageUpdated;
95+
96+
if (isMaybeStreaming) {
97+
scrollToBottom(false);
98+
} else if (!props.scrolledAwayFromBottom && lastMessageUpdated) {
99+
scrollToBottom(true);
100+
}
101+
break;
102+
}
87103
case 'MESSAGE_SENT_SUCCESS':
88104
case 'MESSAGE_SENT_PENDING': {
89105
scrollToBottom(false);

packages/uikit-react-native/src/domain/groupChannelThread/component/GroupChannelThreadMessageList.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const GroupChannelThreadMessageList = (props: GroupChannelThreadProps['MessageLi
6969
});
7070

7171
useEffect(() => {
72-
return subscribe(({ type }) => {
72+
return subscribe(({ type, data }) => {
7373
switch (type) {
7474
case 'TYPING_BUBBLE_RENDERED':
7575
case 'MESSAGES_RECEIVED': {
@@ -78,6 +78,21 @@ const GroupChannelThreadMessageList = (props: GroupChannelThreadProps['MessageLi
7878
}
7979
break;
8080
}
81+
case 'MESSAGES_UPDATED': {
82+
const lastMessage = props.channel.lastMessage;
83+
const [updatedMessage] = data.messages;
84+
85+
const lastMessageUpdated =
86+
updatedMessage && lastMessage && lastMessage.messageId === updatedMessage.messageId;
87+
const isMaybeStreaming = props.channel.hasAiBot && lastMessageUpdated;
88+
89+
if (isMaybeStreaming) {
90+
scrollToBottom(false);
91+
} else if (!props.scrolledAwayFromBottom && lastMessageUpdated) {
92+
scrollToBottom(true);
93+
}
94+
break;
95+
}
8196
case 'MESSAGE_SENT_SUCCESS':
8297
case 'MESSAGE_SENT_PENDING': {
8398
scrollToBottom(false);

packages/uikit-testing-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"access": "public"
4040
},
4141
"devDependencies": {
42-
"@sendbird/chat": "^4.12.9",
42+
"@sendbird/chat": "^4.13.3",
4343
"@sendbird/uikit-utils": "3.7.4",
4444
"@types/jest": "^29.4.0",
4545
"@types/react": "*",

packages/uikit-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"typescript": "5.2.2"
5757
},
5858
"peerDependencies": {
59-
"@sendbird/chat": "^4.12.9",
59+
"@sendbird/chat": "^4.13.3",
6060
"date-fns": ">=2.28.0",
6161
"react": ">=17.0.2",
6262
"react-native": ">=0.65.0"

sample/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@react-navigation/bottom-tabs": "^6.6.0",
2929
"@react-navigation/native": "^6.1.17",
3030
"@react-navigation/native-stack": "^6.10.0",
31-
"@sendbird/chat": "^4.12.9",
31+
"@sendbird/chat": "^4.13.3",
3232
"@storybook/addon-actions": "^6.4.19",
3333
"@storybook/addon-controls": "^6.4.19",
3434
"@storybook/addon-ondevice-actions": "^6.0.1-alpha.7",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,10 +4703,10 @@
47034703
mkdirp "^1.0.4"
47044704
rimraf "^3.0.2"
47054705

4706-
"@sendbird/chat@4.12.9", "@sendbird/chat@^4.12.9":
4707-
version "4.12.9"
4708-
resolved "https://registry.yarnpkg.com/@sendbird/chat/-/chat-4.12.9.tgz#7f1b8f70f647c35dd9e8729a9f772868593dc739"
4709-
integrity sha512-vHU18zfCmxxU65vNVz0URH/MUh+0nfz13uUaXOTrbw9ABw2KqiYko27O9c+ptc9Z9E+LhlhAhJIxB7LIdh+YCQ==
4706+
"@sendbird/chat@4.13.3", "@sendbird/chat@^4.13.3":
4707+
version "4.13.3"
4708+
resolved "https://registry.yarnpkg.com/@sendbird/chat/-/chat-4.13.3.tgz#d8cc7b58ea0562e3661303d73bc1a0722bae37d9"
4709+
integrity sha512-JRlhmyEMrHxoLNZIl+C94I9TzXOFVnWVz0NErcv8L/JD9ryzcgq6pJi0z8kOYCJZKs/YTpCISV9wHEUo6dI8xw==
47104710

47114711
"@sendbird/uikit-tools@0.0.1-alpha.77":
47124712
version "0.0.1-alpha.77"

0 commit comments

Comments
 (0)