Apply prettier formatting

This commit is contained in:
Michael Weimann 2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
No known key found for this signature in database
GPG key ID: 53F535A266BB9584
1576 changed files with 65385 additions and 62478 deletions

View file

@ -51,9 +51,7 @@ const NewRoomIntro = () => {
const { room, roomId } = useContext(RoomContext);
const isLocalRoom = room instanceof LocalRoom;
const dmPartner = isLocalRoom
? room.targets[0]?.userId
: DMRoomMap.shared().getUserIdForRoomId(roomId);
const dmPartner = isLocalRoom ? room.targets[0]?.userId : DMRoomMap.shared().getUserIdForRoomId(roomId);
let body: JSX.Element;
if (dmPartner) {
@ -62,43 +60,54 @@ const NewRoomIntro = () => {
if (isLocalRoom) {
introMessage = _t("Send your first message to invite <displayName/> to chat");
} else if ((room.getJoinedMemberCount() + room.getInvitedMemberCount()) === 2) {
} else if (room.getJoinedMemberCount() + room.getInvitedMemberCount() === 2) {
caption = _t("Only the two of you are in this conversation, unless either of you invites anyone to join.");
}
const member = room?.getMember(dmPartner);
const displayName = room?.name || member?.rawDisplayName || dmPartner;
body = <React.Fragment>
<RoomAvatar
room={room}
width={AVATAR_SIZE}
height={AVATAR_SIZE}
onClick={() => {
defaultDispatcher.dispatch<ViewUserPayload>({
action: Action.ViewUser,
// XXX: We should be using a real member object and not assuming what the receiver wants.
member: member || { userId: dmPartner } as User,
});
}}
/>
body = (
<React.Fragment>
<RoomAvatar
room={room}
width={AVATAR_SIZE}
height={AVATAR_SIZE}
onClick={() => {
defaultDispatcher.dispatch<ViewUserPayload>({
action: Action.ViewUser,
// XXX: We should be using a real member object and not assuming what the receiver wants.
member: member || ({ userId: dmPartner } as User),
});
}}
/>
<h2>{ room.name }</h2>
<h2>{room.name}</h2>
<p>{ _t(introMessage, {}, {
displayName: () => <b>{ displayName }</b>,
}) }</p>
{ caption && <p>{ caption }</p> }
</React.Fragment>;
<p>
{_t(
introMessage,
{},
{
displayName: () => <b>{displayName}</b>,
},
)}
</p>
{caption && <p>{caption}</p>}
</React.Fragment>
);
} else {
const inRoom = room && room.getMyMembership() === "join";
const topic = room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic;
const canAddTopic = inRoom && room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getUserId());
const onTopicClick = () => {
defaultDispatcher.dispatch({
action: "open_room_settings",
room_id: roomId,
}, true);
defaultDispatcher.dispatch(
{
action: "open_room_settings",
room_id: roomId,
},
true,
);
// focus the topic field to help the user find it as it'll gain an outline
setImmediate(() => {
window.document.getElementById("profileTopic").focus();
@ -107,15 +116,31 @@ const NewRoomIntro = () => {
let topicText;
if (canAddTopic && topic) {
topicText = _t("Topic: %(topic)s (<a>edit</a>)", { topic }, {
a: sub => <AccessibleButton kind="link_inline" onClick={onTopicClick}>{ sub }</AccessibleButton>,
});
topicText = _t(
"Topic: %(topic)s (<a>edit</a>)",
{ topic },
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={onTopicClick}>
{sub}
</AccessibleButton>
),
},
);
} else if (topic) {
topicText = _t("Topic: %(topic)s ", { topic });
} else if (canAddTopic) {
topicText = _t("<a>Add a topic</a> to help people know what it is about.", {}, {
a: sub => <AccessibleButton kind="link_inline" onClick={onTopicClick}>{ sub }</AccessibleButton>,
});
topicText = _t(
"<a>Add a topic</a> to help people know what it is about.",
{},
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={onTopicClick}>
{sub}
</AccessibleButton>
),
},
);
}
const creator = room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
@ -140,38 +165,44 @@ const NewRoomIntro = () => {
let buttons;
if (parentSpace && shouldShowComponent(UIComponent.InviteUsers)) {
buttons = <div className="mx_NewRoomIntro_buttons">
<AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary"
onClick={() => {
showSpaceInvite(parentSpace);
}}
>
{ _t("Invite to %(spaceName)s", { spaceName: parentSpace.name }) }
</AccessibleButton>
{ room.canInvite(cli.getUserId()) && <AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary_outline"
onClick={() => {
defaultDispatcher.dispatch({ action: "view_invite", roomId });
}}
>
{ _t("Invite to just this room") }
</AccessibleButton> }
</div>;
buttons = (
<div className="mx_NewRoomIntro_buttons">
<AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary"
onClick={() => {
showSpaceInvite(parentSpace);
}}
>
{_t("Invite to %(spaceName)s", { spaceName: parentSpace.name })}
</AccessibleButton>
{room.canInvite(cli.getUserId()) && (
<AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary_outline"
onClick={() => {
defaultDispatcher.dispatch({ action: "view_invite", roomId });
}}
>
{_t("Invite to just this room")}
</AccessibleButton>
)}
</div>
);
} else if (room.canInvite(cli.getUserId()) && shouldShowComponent(UIComponent.InviteUsers)) {
buttons = <div className="mx_NewRoomIntro_buttons">
<AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary"
onClick={() => {
defaultDispatcher.dispatch({ action: "view_invite", roomId });
}}
>
{ _t("Invite to this room") }
</AccessibleButton>
</div>;
buttons = (
<div className="mx_NewRoomIntro_buttons">
<AccessibleButton
className="mx_NewRoomIntro_inviteButton"
kind="primary"
onClick={() => {
defaultDispatcher.dispatch({ action: "view_invite", roomId });
}}
>
{_t("Invite to this room")}
</AccessibleButton>
</div>
);
}
const avatarUrl = room.currentState.getStateEvents(EventType.RoomAvatar, "")?.getContent()?.url;
@ -180,26 +211,37 @@ const NewRoomIntro = () => {
);
if (!avatarUrl) {
avatar = <MiniAvatarUploader
hasAvatar={false}
noAvatarLabel={_t("Add a photo, so people can easily spot your room.")}
setAvatarUrl={url => cli.sendStateEvent(roomId, EventType.RoomAvatar, { url }, '')}
>
{ avatar }
</MiniAvatarUploader>;
avatar = (
<MiniAvatarUploader
hasAvatar={false}
noAvatarLabel={_t("Add a photo, so people can easily spot your room.")}
setAvatarUrl={(url) => cli.sendStateEvent(roomId, EventType.RoomAvatar, { url }, "")}
>
{avatar}
</MiniAvatarUploader>
);
}
body = <React.Fragment>
{ avatar }
body = (
<React.Fragment>
{avatar}
<h2>{ room.name }</h2>
<h2>{room.name}</h2>
<p>{ createdText } { _t("This is the start of <roomName/>.", {}, {
roomName: () => <b>{ room.name }</b>,
}) }</p>
<p>{ topicText }</p>
{ buttons }
</React.Fragment>;
<p>
{createdText}{" "}
{_t(
"This is the start of <roomName/>.",
{},
{
roomName: () => <b>{room.name}</b>,
},
)}
</p>
<p>{topicText}</p>
{buttons}
</React.Fragment>
);
}
function openRoomSettings(event) {
@ -211,33 +253,40 @@ const NewRoomIntro = () => {
}
const subText = _t(
"Your private messages are normally encrypted, but this room isn't. "+
"Usually this is due to an unsupported device or method being used, " +
"like email invites.",
"Your private messages are normally encrypted, but this room isn't. " +
"Usually this is due to an unsupported device or method being used, " +
"like email invites.",
);
let subButton;
if (room.currentState.mayClientSendStateEvent(EventType.RoomEncryption, MatrixClientPeg.get()) && !isLocalRoom) {
subButton = (
<AccessibleButton kind='link_inline' onClick={openRoomSettings}>{ _t("Enable encryption in settings.") }</AccessibleButton>
<AccessibleButton kind="link_inline" onClick={openRoomSettings}>
{_t("Enable encryption in settings.")}
</AccessibleButton>
);
}
const subtitle = (
<span> { subText } { subButton } </span>
<span>
{" "}
{subText} {subButton}{" "}
</span>
);
return <li className="mx_NewRoomIntro">
{ !hasExpectedEncryptionSettings(cli, room) && (
<EventTileBubble
className="mx_cryptoEvent mx_cryptoEvent_icon_warning"
title={_t("End-to-end encryption isn't enabled")}
subtitle={subtitle}
/>
) }
return (
<li className="mx_NewRoomIntro">
{!hasExpectedEncryptionSettings(cli, room) && (
<EventTileBubble
className="mx_cryptoEvent mx_cryptoEvent_icon_warning"
title={_t("End-to-end encryption isn't enabled")}
subtitle={subtitle}
/>
)}
{ body }
</li>;
{body}
</li>
);
};
export default NewRoomIntro;