import PropTypes from 'prop-types';
import './RoomIntro.scss';
-import { twemojify } from '../../../util/twemojify';
import colorMXID from '../../../util/colorMXID';
import Text from '../../atoms/text/Text';
<div className="room-intro">
<Avatar imageSrc={avatarSrc} text={name} bgColor={colorMXID(roomId)} size="large" />
<div className="room-intro__content">
- <Text className="room-intro__name" variant="h1" weight="medium" primary>{twemojify(heading)}</Text>
- <Text className="room-intro__desc" variant="b1">{twemojify(desc, undefined, true)}</Text>
+ <Text className="room-intro__name" variant="h1" weight="medium" primary>{heading}</Text>
+ <Text className="room-intro__desc" variant="b1">{desc}</Text>
{ time !== null && <Text className="room-intro__time" variant="b3">{time}</Text>}
</div>
</div>
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;
import './RoomViewContent.scss';
import dateFormat from 'dateformat';
+import { twemojify } from '../../../util/twemojify';
import initMatrix from '../../../client/initMatrix';
import cons from '../../../client/state/cons';
);
}
-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 @
+ <b>{nameJsx}</b>
+ {'. '}
+ {topic}
+ </>
+ )
+ : (
+ <>
+ {'This is the beginning of the '}
+ <b>{nameJsx}</b>
+ {' 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 (
<RoomIntro
- key={mEvent ? mEvent.getId() : 'room-intro'}
- roomId={roomTimeline.roomId}
+ roomId={timeline.roomId}
avatarSrc={avatarSrc}
- name={roomTimeline.room.name}
- heading={`Welcome to ${roomTimeline.room.name}`}
- desc={`This is the beginning of the ${roomTimeline.room.name} room.${typeof roomTopic !== 'undefined' ? (` Topic: ${roomTopic}`) : ''}`}
- time={mEvent ? `Created at ${dateFormat(mEvent.getDate(), 'dd mmmm yyyy, hh:MM TT')}` : null}
+ name={room.name}
+ heading={twemojify(heading)}
+ desc={desc}
+ time={event ? `Created at ${dateFormat(event.getDate(), 'dd mmmm yyyy, hh:MM TT')}` : null}
/>
);
}
};
roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
return () => {
- roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
+ roomTimeline.removeListener(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
};
}, [roomTimeline]);
if (i === 0 && !roomTimeline.canPaginateBackward()) {
if (mEvent.getType() === 'm.room.create') {
- tl.push(genRoomIntro(mEvent, roomTimeline));
+ tl.push(
+ <RoomIntroContainer key={mEvent.getId()} event={mEvent} timeline={roomTimeline} />,
+ );
itemCountIndex += 1;
// eslint-disable-next-line no-continue
continue;
} else {
- tl.push(genRoomIntro(undefined, roomTimeline));
+ tl.push(<RoomIntroContainer key="room-intro" event={null} timeline={roomTimeline} />);
itemCountIndex += 1;
}
}