From 3afc068a02e1ea5aac276d1bc2934d26f07ab599 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Tue, 3 May 2022 14:05:56 +0530 Subject: [PATCH] Fixes #430, #434, #455 --- src/app/molecules/room-intro/RoomIntro.jsx | 11 ++-- src/app/organisms/room/RoomViewContent.jsx | 64 +++++++++++++++++----- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/app/molecules/room-intro/RoomIntro.jsx b/src/app/molecules/room-intro/RoomIntro.jsx index 2c6f944..2ec46cb 100644 --- a/src/app/molecules/room-intro/RoomIntro.jsx +++ b/src/app/molecules/room-intro/RoomIntro.jsx @@ -2,7 +2,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import './RoomIntro.scss'; -import { twemojify } from '../../../util/twemojify'; import colorMXID from '../../../util/colorMXID'; import Text from '../../atoms/text/Text'; @@ -15,8 +14,8 @@ function RoomIntro({
- {twemojify(heading)} - {twemojify(desc, undefined, true)} + {heading} + {desc} { time !== null && {time}}
@@ -35,9 +34,9 @@ RoomIntro.propTypes = { PropTypes.bool, ]), name: PropTypes.string.isRequired, - heading: PropTypes.string.isRequired, - desc: PropTypes.string.isRequired, - time: PropTypes.string, + heading: PropTypes.node.isRequired, + desc: PropTypes.node.isRequired, + time: PropTypes.node, }; export default RoomIntro; diff --git a/src/app/organisms/room/RoomViewContent.jsx b/src/app/organisms/room/RoomViewContent.jsx index 96839b2..ab1dfba 100644 --- a/src/app/organisms/room/RoomViewContent.jsx +++ b/src/app/organisms/room/RoomViewContent.jsx @@ -8,6 +8,7 @@ import PropTypes from 'prop-types'; import './RoomViewContent.scss'; import dateFormat from 'dateformat'; +import { twemojify } from '../../../util/twemojify'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; @@ -50,21 +51,54 @@ function loadingMsgPlaceholders(key, count = 2) { ); } -function genRoomIntro(mEvent, roomTimeline) { +function RoomIntroContainer({ event, timeline }) { + const [, nameForceUpdate] = useForceUpdate(); const mx = initMatrix.matrixClient; - const roomTopic = roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic; - const isDM = initMatrix.roomList.directs.has(roomTimeline.roomId); - let avatarSrc = roomTimeline.room.getAvatarUrl(mx.baseUrl, 80, 80, 'crop'); - avatarSrc = isDM ? roomTimeline.room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 80, 80, 'crop') : avatarSrc; + const { roomList } = initMatrix; + const { room } = timeline; + const roomTopic = room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic; + const isDM = roomList.directs.has(timeline.roomId); + let avatarSrc = room.getAvatarUrl(mx.baseUrl, 80, 80, 'crop'); + avatarSrc = isDM ? room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 80, 80, 'crop') : avatarSrc; + + const heading = isDM ? room.name : `Welcome to ${room.name}`; + const topic = twemojify(roomTopic || '', undefined, true); + const nameJsx = twemojify(room.name); + const desc = isDM + ? ( + <> + This is the beginning of your direct message history with @ + {nameJsx} + {'. '} + {topic} + + ) + : ( + <> + {'This is the beginning of the '} + {nameJsx} + {' room. '} + {topic} + + ); + + useEffect(() => { + const handleUpdate = () => nameForceUpdate(); + + roomList.on(cons.events.roomList.ROOM_PROFILE_UPDATED, handleUpdate); + return () => { + roomList.removeListener(cons.events.roomList.ROOM_PROFILE_UPDATED, handleUpdate); + }; + }, []); + return ( ); } @@ -199,7 +233,7 @@ function usePaginate( }; roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer); return () => { - roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer); + roomTimeline.removeListener(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer); }; }, [roomTimeline]); @@ -470,12 +504,14 @@ function RoomViewContent({ eventId, roomTimeline }) { if (i === 0 && !roomTimeline.canPaginateBackward()) { if (mEvent.getType() === 'm.room.create') { - tl.push(genRoomIntro(mEvent, roomTimeline)); + tl.push( + , + ); itemCountIndex += 1; // eslint-disable-next-line no-continue continue; } else { - tl.push(genRoomIntro(undefined, roomTimeline)); + tl.push(); itemCountIndex += 1; } }