[FIX] Chats order (#2688)
* Persist highest value on subscription.roomUpdatedAt * Update tests Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
This commit is contained in:
parent
2d6572d709
commit
999883e4d6
|
@ -15,11 +15,9 @@ export const merge = (subscription, room) => {
|
||||||
if (room) {
|
if (room) {
|
||||||
if (room._updatedAt) {
|
if (room._updatedAt) {
|
||||||
subscription.lastMessage = normalizeMessage(room.lastMessage);
|
subscription.lastMessage = normalizeMessage(room.lastMessage);
|
||||||
if (subscription.lastMessage) {
|
const updatedAt = room?._updatedAt ? new Date(room._updatedAt) : null;
|
||||||
subscription.roomUpdatedAt = subscription.lastMessage.ts;
|
const lastMessageTs = subscription?.lastMessage?.ts ? new Date(subscription.lastMessage.ts) : null;
|
||||||
} else {
|
subscription.roomUpdatedAt = Math.max(updatedAt, lastMessageTs);
|
||||||
subscription.roomUpdatedAt = room._updatedAt;
|
|
||||||
}
|
|
||||||
subscription.description = room.description;
|
subscription.description = room.description;
|
||||||
subscription.topic = room.topic;
|
subscription.topic = room.topic;
|
||||||
subscription.announcement = room.announcement;
|
subscription.announcement = room.announcement;
|
||||||
|
|
|
@ -39,7 +39,6 @@ const RoomItem = ({
|
||||||
tunread,
|
tunread,
|
||||||
tunreadUser,
|
tunreadUser,
|
||||||
tunreadGroup,
|
tunreadGroup,
|
||||||
roomUpdatedAt,
|
|
||||||
testID,
|
testID,
|
||||||
swipeEnabled,
|
swipeEnabled,
|
||||||
onPress,
|
onPress,
|
||||||
|
@ -88,7 +87,6 @@ const RoomItem = ({
|
||||||
alert={alert}
|
alert={alert}
|
||||||
/>
|
/>
|
||||||
<UpdatedAt
|
<UpdatedAt
|
||||||
roomUpdatedAt={roomUpdatedAt}
|
|
||||||
date={date}
|
date={date}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
hideUnreadStatus={hideUnreadStatus}
|
hideUnreadStatus={hideUnreadStatus}
|
||||||
|
@ -175,7 +173,6 @@ RoomItem.propTypes = {
|
||||||
tunread: PropTypes.array,
|
tunread: PropTypes.array,
|
||||||
tunreadUser: PropTypes.array,
|
tunreadUser: PropTypes.array,
|
||||||
tunreadGroup: PropTypes.array,
|
tunreadGroup: PropTypes.array,
|
||||||
roomUpdatedAt: PropTypes.instanceOf(Date),
|
|
||||||
swipeEnabled: PropTypes.bool,
|
swipeEnabled: PropTypes.bool,
|
||||||
toggleFav: PropTypes.func,
|
toggleFav: PropTypes.func,
|
||||||
toggleRead: PropTypes.func,
|
toggleRead: PropTypes.func,
|
||||||
|
|
|
@ -7,9 +7,9 @@ import { themes } from '../../constants/colors';
|
||||||
import { capitalize } from '../../utils/room';
|
import { capitalize } from '../../utils/room';
|
||||||
|
|
||||||
const UpdatedAt = React.memo(({
|
const UpdatedAt = React.memo(({
|
||||||
roomUpdatedAt, date, theme, hideUnreadStatus, alert
|
date, theme, hideUnreadStatus, alert
|
||||||
}) => {
|
}) => {
|
||||||
if (!roomUpdatedAt) {
|
if (!date) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -39,7 +39,6 @@ const UpdatedAt = React.memo(({
|
||||||
});
|
});
|
||||||
|
|
||||||
UpdatedAt.propTypes = {
|
UpdatedAt.propTypes = {
|
||||||
roomUpdatedAt: PropTypes.instanceOf(Date),
|
|
||||||
date: PropTypes.string,
|
date: PropTypes.string,
|
||||||
theme: PropTypes.string,
|
theme: PropTypes.string,
|
||||||
hideUnreadStatus: PropTypes.bool,
|
hideUnreadStatus: PropTypes.bool,
|
||||||
|
|
|
@ -136,7 +136,7 @@ class RoomItemContainer extends React.Component {
|
||||||
const name = getRoomTitle(item);
|
const name = getRoomTitle(item);
|
||||||
const avatar = getRoomAvatar(item);
|
const avatar = getRoomAvatar(item);
|
||||||
const isRead = getIsRead(item);
|
const isRead = getIsRead(item);
|
||||||
const date = item.lastMessage?.ts && formatDate(item.lastMessage.ts);
|
const date = item.roomUpdatedAt && formatDate(item.roomUpdatedAt);
|
||||||
const alert = (item.alert || item.tunread?.length);
|
const alert = (item.alert || item.tunread?.length);
|
||||||
|
|
||||||
let accessibilityLabel = name;
|
let accessibilityLabel = name;
|
||||||
|
@ -178,7 +178,6 @@ class RoomItemContainer extends React.Component {
|
||||||
status={status}
|
status={status}
|
||||||
hideUnreadStatus={item.hideUnreadStatus}
|
hideUnreadStatus={item.hideUnreadStatus}
|
||||||
alert={alert}
|
alert={alert}
|
||||||
roomUpdatedAt={item.roomUpdatedAt}
|
|
||||||
lastMessage={item.lastMessage}
|
lastMessage={item.lastMessage}
|
||||||
showLastMessage={showLastMessage}
|
showLastMessage={showLastMessage}
|
||||||
username={username}
|
username={username}
|
||||||
|
|
|
@ -17,8 +17,7 @@ const lastMessage = {
|
||||||
msg: longText
|
msg: longText
|
||||||
};
|
};
|
||||||
const updatedAt = {
|
const updatedAt = {
|
||||||
date: '10:00',
|
date: '10:00'
|
||||||
roomUpdatedAt: new Date('2020-01-01')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const RoomItem = props => (
|
const RoomItem = props => (
|
||||||
|
|
Loading…
Reference in New Issue