Skip to content

Commit 3afc068

Browse files
committed
1 parent 5cdad44 commit 3afc068

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

src/app/molecules/room-intro/RoomIntro.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import './RoomIntro.scss';
44

5-
import { twemojify } from '../../../util/twemojify';
65
import colorMXID from '../../../util/colorMXID';
76

87
import Text from '../../atoms/text/Text';
@@ -15,8 +14,8 @@ function RoomIntro({
1514
<div className="room-intro">
1615
<Avatar imageSrc={avatarSrc} text={name} bgColor={colorMXID(roomId)} size="large" />
1716
<div className="room-intro__content">
18-
<Text className="room-intro__name" variant="h1" weight="medium" primary>{twemojify(heading)}</Text>
19-
<Text className="room-intro__desc" variant="b1">{twemojify(desc, undefined, true)}</Text>
17+
<Text className="room-intro__name" variant="h1" weight="medium" primary>{heading}</Text>
18+
<Text className="room-intro__desc" variant="b1">{desc}</Text>
2019
{ time !== null && <Text className="room-intro__time" variant="b3">{time}</Text>}
2120
</div>
2221
</div>
@@ -35,9 +34,9 @@ RoomIntro.propTypes = {
3534
PropTypes.bool,
3635
]),
3736
name: PropTypes.string.isRequired,
38-
heading: PropTypes.string.isRequired,
39-
desc: PropTypes.string.isRequired,
40-
time: PropTypes.string,
37+
heading: PropTypes.node.isRequired,
38+
desc: PropTypes.node.isRequired,
39+
time: PropTypes.node,
4140
};
4241

4342
export default RoomIntro;

src/app/organisms/room/RoomViewContent.jsx

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
88
import './RoomViewContent.scss';
99

1010
import dateFormat from 'dateformat';
11+
import { twemojify } from '../../../util/twemojify';
1112

1213
import initMatrix from '../../../client/initMatrix';
1314
import cons from '../../../client/state/cons';
@@ -50,21 +51,54 @@ function loadingMsgPlaceholders(key, count = 2) {
5051
);
5152
}
5253

53-
function genRoomIntro(mEvent, roomTimeline) {
54+
function RoomIntroContainer({ event, timeline }) {
55+
const [, nameForceUpdate] = useForceUpdate();
5456
const mx = initMatrix.matrixClient;
55-
const roomTopic = roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic;
56-
const isDM = initMatrix.roomList.directs.has(roomTimeline.roomId);
57-
let avatarSrc = roomTimeline.room.getAvatarUrl(mx.baseUrl, 80, 80, 'crop');
58-
avatarSrc = isDM ? roomTimeline.room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 80, 80, 'crop') : avatarSrc;
57+
const { roomList } = initMatrix;
58+
const { room } = timeline;
59+
const roomTopic = room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic;
60+
const isDM = roomList.directs.has(timeline.roomId);
61+
let avatarSrc = room.getAvatarUrl(mx.baseUrl, 80, 80, 'crop');
62+
avatarSrc = isDM ? room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 80, 80, 'crop') : avatarSrc;
63+
64+
const heading = isDM ? room.name : `Welcome to ${room.name}`;
65+
const topic = twemojify(roomTopic || '', undefined, true);
66+
const nameJsx = twemojify(room.name);
67+
const desc = isDM
68+
? (
69+
<>
70+
This is the beginning of your direct message history with @
71+
<b>{nameJsx}</b>
72+
{'. '}
73+
{topic}
74+
</>
75+
)
76+
: (
77+
<>
78+
{'This is the beginning of the '}
79+
<b>{nameJsx}</b>
80+
{' room. '}
81+
{topic}
82+
</>
83+
);
84+
85+
useEffect(() => {
86+
const handleUpdate = () => nameForceUpdate();
87+
88+
roomList.on(cons.events.roomList.ROOM_PROFILE_UPDATED, handleUpdate);
89+
return () => {
90+
roomList.removeListener(cons.events.roomList.ROOM_PROFILE_UPDATED, handleUpdate);
91+
};
92+
}, []);
93+
5994
return (
6095
<RoomIntro
61-
key={mEvent ? mEvent.getId() : 'room-intro'}
62-
roomId={roomTimeline.roomId}
96+
roomId={timeline.roomId}
6397
avatarSrc={avatarSrc}
64-
name={roomTimeline.room.name}
65-
heading={`Welcome to ${roomTimeline.room.name}`}
66-
desc={`This is the beginning of the ${roomTimeline.room.name} room.${typeof roomTopic !== 'undefined' ? (` Topic: ${roomTopic}`) : ''}`}
67-
time={mEvent ? `Created at ${dateFormat(mEvent.getDate(), 'dd mmmm yyyy, hh:MM TT')}` : null}
98+
name={room.name}
99+
heading={twemojify(heading)}
100+
desc={desc}
101+
time={event ? `Created at ${dateFormat(event.getDate(), 'dd mmmm yyyy, hh:MM TT')}` : null}
68102
/>
69103
);
70104
}
@@ -199,7 +233,7 @@ function usePaginate(
199233
};
200234
roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
201235
return () => {
202-
roomTimeline.on(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
236+
roomTimeline.removeListener(cons.events.roomTimeline.PAGINATED, handlePaginatedFromServer);
203237
};
204238
}, [roomTimeline]);
205239

@@ -470,12 +504,14 @@ function RoomViewContent({ eventId, roomTimeline }) {
470504

471505
if (i === 0 && !roomTimeline.canPaginateBackward()) {
472506
if (mEvent.getType() === 'm.room.create') {
473-
tl.push(genRoomIntro(mEvent, roomTimeline));
507+
tl.push(
508+
<RoomIntroContainer key={mEvent.getId()} event={mEvent} timeline={roomTimeline} />,
509+
);
474510
itemCountIndex += 1;
475511
// eslint-disable-next-line no-continue
476512
continue;
477513
} else {
478-
tl.push(genRoomIntro(undefined, roomTimeline));
514+
tl.push(<RoomIntroContainer key="room-intro" event={null} timeline={roomTimeline} />);
479515
itemCountIndex += 1;
480516
}
481517
}

0 commit comments

Comments
 (0)