[FIX] Threads not being updated and other related issues (#2636)

* Fix parent title on thread header breaking lines

* Fix https://github.com/RocketChat/Rocket.Chat.ReactNative/issues/2519

* Fix thread badge not being updated
This commit is contained in:
Diego Mello 2020-11-12 11:17:32 -03:00 committed by GitHub
parent ef67665f58
commit 8cac76601f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 23 deletions

View File

@ -19,11 +19,10 @@ const Thread = React.memo(({
} }
const { const {
getBadgeColor, toggleFollowThread, user, replies threadBadgeColor, toggleFollowThread, user, replies
} = useContext(MessageContext); } = useContext(MessageContext);
const time = formatDateThreads(tlm); const time = formatDateThreads(tlm);
const buttonText = formatMessageCount(tcount, THREAD); const buttonText = formatMessageCount(tcount, THREAD);
const badgeColor = getBadgeColor?.(id);
const isFollowing = replies?.find(u => u === user.id); const isFollowing = replies?.find(u => u === user.id);
return ( return (
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
@ -35,7 +34,7 @@ const Thread = React.memo(({
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{buttonText}</Text> <Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{buttonText}</Text>
</View> </View>
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text> <Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
{badgeColor ? <View style={[styles.threadBadge, { backgroundColor: badgeColor }]} /> : null} {threadBadgeColor ? <View style={[styles.threadBadge, { backgroundColor: threadBadgeColor }]} /> : null}
<Touchable onPress={() => toggleFollowThread(isFollowing, id)}> <Touchable onPress={() => toggleFollowThread(isFollowing, id)}>
<CustomIcon <CustomIcon
name={isFollowing ? 'notification' : 'notification-disabled'} name={isFollowing ? 'notification' : 'notification-disabled'}

View File

@ -48,7 +48,7 @@ class MessageContainer extends React.Component {
callJitsi: PropTypes.func, callJitsi: PropTypes.func,
blockAction: PropTypes.func, blockAction: PropTypes.func,
theme: PropTypes.string, theme: PropTypes.string,
getBadgeColor: PropTypes.func, threadBadgeColor: PropTypes.string,
toggleFollowThread: PropTypes.func toggleFollowThread: PropTypes.func
} }
@ -84,10 +84,13 @@ class MessageContainer extends React.Component {
} }
shouldComponentUpdate(nextProps) { shouldComponentUpdate(nextProps) {
const { theme } = this.props; const { theme, threadBadgeColor } = this.props;
if (nextProps.theme !== theme) { if (nextProps.theme !== theme) {
return true; return true;
} }
if (nextProps.threadBadgeColor !== threadBadgeColor) {
return true;
}
return false; return false;
} }
@ -244,7 +247,7 @@ class MessageContainer extends React.Component {
render() { render() {
const { const {
item, user, style, archived, baseUrl, useRealName, broadcast, fetchThreadName, showAttachment, timeFormat, isReadReceiptEnabled, autoTranslateRoom, autoTranslateLanguage, navToRoomInfo, getCustomEmoji, isThreadRoom, callJitsi, blockAction, rid, theme, getBadgeColor, toggleFollowThread item, user, style, archived, baseUrl, useRealName, broadcast, fetchThreadName, showAttachment, timeFormat, isReadReceiptEnabled, autoTranslateRoom, autoTranslateLanguage, navToRoomInfo, getCustomEmoji, isThreadRoom, callJitsi, blockAction, rid, theme, threadBadgeColor, toggleFollowThread
} = this.props; } = this.props;
const { const {
id, msg, ts, attachments, urls, reactions, t, avatar, emoji, u, alias, editedBy, role, drid, dcount, dlm, tmid, tcount, tlm, tmsg, mentions, channels, unread, blocks, autoTranslate: autoTranslateMessage, replies id, msg, ts, attachments, urls, reactions, t, avatar, emoji, u, alias, editedBy, role, drid, dcount, dlm, tmid, tcount, tlm, tmsg, mentions, channels, unread, blocks, autoTranslate: autoTranslateMessage, replies
@ -271,7 +274,7 @@ class MessageContainer extends React.Component {
onEncryptedPress: this.onEncryptedPress, onEncryptedPress: this.onEncryptedPress,
onDiscussionPress: this.onDiscussionPress, onDiscussionPress: this.onDiscussionPress,
onReactionLongPress: this.onReactionLongPress, onReactionLongPress: this.onReactionLongPress,
getBadgeColor, threadBadgeColor,
toggleFollowThread, toggleFollowThread,
replies replies
}} }}

View File

@ -140,7 +140,7 @@ const Header = React.memo(({
roomUserId={roomUserId} roomUserId={roomUserId}
theme={theme} theme={theme}
/> />
<Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]}>{parentTitle}</Text> <Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>{parentTitle}</Text>
</View> </View>
); );
} }

View File

@ -30,6 +30,7 @@ class List extends React.Component {
loading: PropTypes.bool, loading: PropTypes.bool,
listRef: PropTypes.func, listRef: PropTypes.func,
hideSystemMessages: PropTypes.array, hideSystemMessages: PropTypes.array,
tunread: PropTypes.array,
navigation: PropTypes.object, navigation: PropTypes.object,
showMessageInMainThread: PropTypes.bool showMessageInMainThread: PropTypes.bool
}; };
@ -76,7 +77,7 @@ class List extends React.Component {
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
const { loading, end, refreshing } = this.state; const { loading, end, refreshing } = this.state;
const { hideSystemMessages, theme } = this.props; const { hideSystemMessages, theme, tunread } = this.props;
if (theme !== nextProps.theme) { if (theme !== nextProps.theme) {
return true; return true;
} }
@ -92,6 +93,9 @@ class List extends React.Component {
if (!isEqual(hideSystemMessages, nextProps.hideSystemMessages)) { if (!isEqual(hideSystemMessages, nextProps.hideSystemMessages)) {
return true; return true;
} }
if (!isEqual(tunread, nextProps.tunread)) {
return true;
}
return false; return false;
} }

View File

@ -73,7 +73,7 @@ const stateAttrsUpdate = [
'readOnly', 'readOnly',
'member' 'member'
]; ];
const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles', 'bannerClosed', 'visitor']; const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'tunread', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles', 'bannerClosed', 'visitor'];
class RoomView extends React.Component { class RoomView extends React.Component {
static propTypes = { static propTypes = {
@ -909,7 +909,7 @@ class RoomView extends React.Component {
getCustomEmoji={this.getCustomEmoji} getCustomEmoji={this.getCustomEmoji}
callJitsi={this.callJitsi} callJitsi={this.callJitsi}
blockAction={this.blockAction} blockAction={this.blockAction}
getBadgeColor={this.getBadgeColor} threadBadgeColor={this.getBadgeColor(item?.id)}
toggleFollowThread={this.toggleFollowThread} toggleFollowThread={this.toggleFollowThread}
/> />
); );
@ -1053,7 +1053,7 @@ class RoomView extends React.Component {
t={t} t={t}
tmid={this.tmid} tmid={this.tmid}
theme={theme} theme={theme}
room={room} tunread={room?.tunread}
renderRow={this.renderItem} renderRow={this.renderItem}
loading={loading} loading={loading}
navigation={navigation} navigation={navigation}

View File

@ -157,7 +157,7 @@ class RoomsListView extends React.Component {
searching: false, searching: false,
search: [], search: [],
loading: true, loading: true,
chatsOrder: [], chatsUpdate: [],
chats: [], chats: [],
item: {} item: {}
}; };
@ -224,7 +224,7 @@ class RoomsListView extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
const { chatsOrder, searching, item } = this.state; const { chatsUpdate, searching, item } = this.state;
// eslint-disable-next-line react/destructuring-assignment // eslint-disable-next-line react/destructuring-assignment
const propsUpdated = shouldUpdateProps.some(key => nextProps[key] !== this.props[key]); const propsUpdated = shouldUpdateProps.some(key => nextProps[key] !== this.props[key]);
if (propsUpdated) { if (propsUpdated) {
@ -232,7 +232,7 @@ class RoomsListView extends React.Component {
} }
// Compare changes only once // Compare changes only once
const chatsNotEqual = !isEqual(nextState.chatsOrder, chatsOrder); const chatsNotEqual = !isEqual(nextState.chatsUpdate, chatsUpdate);
// If they aren't equal, set to update if focused // If they aren't equal, set to update if focused
if (chatsNotEqual) { if (chatsNotEqual) {
@ -437,7 +437,7 @@ class RoomsListView extends React.Component {
observable = await db.collections observable = await db.collections
.get('subscriptions') .get('subscriptions')
.query(...defaultWhereClause) .query(...defaultWhereClause)
.observe(); .observeWithColumns(['alert']);
// When we're NOT grouping // When we're NOT grouping
} else { } else {
@ -456,11 +456,20 @@ class RoomsListView extends React.Component {
let tempChats = []; let tempChats = [];
let chats = data; let chats = data;
/** let chatsUpdate = [];
* We trigger re-render only when chats order changes if (showUnread) {
* RoomItem handles its own re-render /**
*/ * If unread on top, we trigger re-render based on order changes and sub.alert
const chatsOrder = data.map(item => item.rid); * RoomItem handles its own re-render
*/
chatsUpdate = data.map(item => ({ rid: item.rid, alert: item.alert }));
} else {
/**
* Otherwise, we trigger re-render only when chats order changes
* RoomItem handles its own re-render
*/
chatsUpdate = data.map(item => item.rid);
}
const isOmnichannelAgent = user?.roles?.includes('livechat-agent'); const isOmnichannelAgent = user?.roles?.includes('livechat-agent');
if (isOmnichannelAgent) { if (isOmnichannelAgent) {
@ -501,7 +510,7 @@ class RoomsListView extends React.Component {
this.internalSetState({ this.internalSetState({
chats: tempChats, chats: tempChats,
chatsOrder, chatsUpdate,
loading: false loading: false
}); });
}); });

View File

@ -64,7 +64,7 @@ const messageDecorator = story => (
onReactionPress: () => {}, onReactionPress: () => {},
onDiscussionPress: () => {}, onDiscussionPress: () => {},
onReactionLongPress: () => {}, onReactionLongPress: () => {},
getBadgeColor: () => themes.light.tunreadBackground threadBadgeColor: themes.light.tunreadBackground
}} }}
> >
{story()} {story()}