From c353b6daadf5fde1f6e3ab0eaae97146e3723358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 26 Aug 2021 17:39:48 +0200 Subject: [PATCH 01/23] Render guest settings only in public rooms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../tabs/room/SecurityRoomSettingsTab.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index d9e97d570b..cade206dad 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -616,6 +616,22 @@ export default class SecurityRoomSettingsTab extends React.Component + + { this.state.showAdvancedSection ? _t("Hide advanced") : _t("Show advanced") } + + { this.state.showAdvancedSection && this.renderAdvanced() } + + ); + } + return (
{ _t("Security & Privacy") }
@@ -641,15 +657,7 @@ export default class SecurityRoomSettingsTab extends React.Component - - { this.state.showAdvancedSection ? _t("Hide advanced") : _t("Show advanced") } - - { this.state.showAdvancedSection && this.renderAdvanced() } - + { advanced } { historySection }
); From 4f1ff134dc9b7505dc21e6e64d61ebe0b84c99dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 26 Aug 2021 17:39:54 +0200 Subject: [PATCH 02/23] Render guest settings only in public spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../spaces/SpaceSettingsVisibilityTab.tsx | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx index b48f5c79c6..90d598cb16 100644 --- a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx +++ b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx @@ -94,30 +94,32 @@ const SpaceSettingsVisibilityTab = ({ matrixClient: cli, space }: IProps) => { const canonicalAliasEv = space.currentState.getStateEvents(EventType.RoomCanonicalAlias, ""); let advancedSection; - if (showAdvancedSection) { - advancedSection = <> - - { _t("Hide advanced") } - + if (visibility === SpaceVisibility.Unlisted) { + if (showAdvancedSection) { + advancedSection = <> + + { _t("Hide advanced") } + - -

- { _t("Guests can join a space without having an account.") } -
- { _t("This may be useful for public spaces.") } -

- ; - } else { - advancedSection = <> - - { _t("Show advanced") } - - ; + +

+ { _t("Guests can join a space without having an account.") } +
+ { _t("This may be useful for public spaces.") } +

+ ; + } else { + advancedSection = <> + + { _t("Show advanced") } + + ; + } } let addressesSection; From 329292eb9b731489abc9605ed3ba05d87e274c3d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 6 Sep 2021 22:11:35 -0600 Subject: [PATCH 03/23] Revert "Revert "Create narrow mode for Composer"" --- res/css/views/rooms/_MessageComposer.scss | 14 ++ .../views/rooms/MessageComposer.tsx | 178 +++++++++++++++--- src/components/views/rooms/Stickerpicker.tsx | 96 ++++------ .../views/rooms/VoiceRecordComposerTile.tsx | 26 +-- src/i18n/strings/en_EN.json | 7 +- 5 files changed, 209 insertions(+), 112 deletions(-) diff --git a/res/css/views/rooms/_MessageComposer.scss b/res/css/views/rooms/_MessageComposer.scss index 9445242306..5c8f6809de 100644 --- a/res/css/views/rooms/_MessageComposer.scss +++ b/res/css/views/rooms/_MessageComposer.scss @@ -237,6 +237,15 @@ limitations under the License. mask-image: url('$(res)/img/element-icons/room/composer/sticker.svg'); } +.mx_MessageComposer_buttonMenu::before { + mask-image: url('$(res)/img/image-view/more.svg'); +} + +.mx_MessageComposer_closeButtonMenu::before { + transform: rotate(90deg); + transform-origin: center; +} + .mx_MessageComposer_sendMessage { cursor: pointer; position: relative; @@ -356,3 +365,8 @@ limitations under the License. margin-right: 0; } } + +.mx_MessageComposer_Menu .mx_CallContextMenu_item { + display: flex; + align-items: center; +} diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 466675ac64..6b66ae4ba3 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import React from 'react'; +import React, { createRef } from 'react'; import classNames from 'classnames'; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; @@ -27,7 +27,13 @@ import { makeRoomPermalink, RoomPermalinkCreator } from '../../../utils/permalin import ContentMessages from '../../../ContentMessages'; import E2EIcon from './E2EIcon'; import SettingsStore from "../../../settings/SettingsStore"; -import { aboveLeftOf, ContextMenu, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu"; +import { + aboveLeftOf, + ContextMenu, + ContextMenuTooltipButton, + useContextMenu, + MenuItem, +} from "../../structures/ContextMenu"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import ReplyPreview from "./ReplyPreview"; import { UIFeature } from "../../../settings/UIFeature"; @@ -45,6 +51,9 @@ import { Action } from "../../../dispatcher/actions"; import EditorModel from "../../../editor/model"; import EmojiPicker from '../emojipicker/EmojiPicker'; import MemberStatusMessageAvatar from "../avatars/MemberStatusMessageAvatar"; +import UIStore, { UI_EVENTS } from '../../../stores/UIStore'; + +const NARROW_MODE_BREAKPOINT = 500; interface IComposerAvatarProps { me: object; @@ -71,13 +80,13 @@ function SendButton(props: ISendButtonProps) { ); } -const EmojiButton = ({ addEmoji }) => { +const EmojiButton = ({ addEmoji, menuPosition }) => { const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu(); let contextMenu; if (menuDisplayed) { - const buttonRect = button.current.getBoundingClientRect(); - contextMenu = + const position = menuPosition ?? aboveLeftOf(button.current.getBoundingClientRect()); + contextMenu = ; } @@ -196,6 +205,9 @@ interface IState { haveRecording: boolean; recordingTimeLeftSeconds?: number; me?: RoomMember; + narrowMode?: boolean; + isMenuOpen: boolean; + showStickers: boolean; } @replaceableComponent("views.rooms.MessageComposer") @@ -203,6 +215,7 @@ export default class MessageComposer extends React.Component { private dispatcherRef: string; private messageComposerInput: SendMessageComposer; private voiceRecordingButton: VoiceRecordComposerTile; + private ref: React.RefObject = createRef(); static defaultProps = { replyInThread: false, @@ -220,6 +233,8 @@ export default class MessageComposer extends React.Component { isComposerEmpty: true, haveRecording: false, recordingTimeLeftSeconds: null, // when set to a number, shows a toast + isMenuOpen: false, + showStickers: false, }; } @@ -227,8 +242,21 @@ export default class MessageComposer extends React.Component { this.dispatcherRef = dis.register(this.onAction); MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents); this.waitForOwnMember(); + UIStore.instance.trackElementDimensions("MessageComposer", this.ref.current); + UIStore.instance.on("MessageComposer", this.onResize); } + private onResize = (type: UI_EVENTS, entry: ResizeObserverEntry) => { + if (type === UI_EVENTS.Resize) { + const narrowMode = entry.contentRect.width <= NARROW_MODE_BREAKPOINT; + this.setState({ + narrowMode, + isMenuOpen: !narrowMode ? false : this.state.isMenuOpen, + showStickers: false, + }); + } + }; + private onAction = (payload: ActionPayload) => { if (payload.action === 'reply_to_event') { // add a timeout for the reply preview to be rendered, so @@ -263,6 +291,8 @@ export default class MessageComposer extends React.Component { } VoiceRecordingStore.instance.off(UPDATE_EVENT, this.onVoiceStoreUpdate); dis.unregister(this.dispatcherRef); + UIStore.instance.stopTrackingElementDimensions("MessageComposer"); + UIStore.instance.removeListener("MessageComposer", this.onResize); } private onRoomStateEvents = (ev, state) => { @@ -369,6 +399,96 @@ export default class MessageComposer extends React.Component { } }; + private shouldShowStickerPicker = (): boolean => { + return SettingsStore.getValue(UIFeature.Widgets) + && SettingsStore.getValue("MessageComposerInput.showStickersButton") + && !this.state.haveRecording; + }; + + private showStickers = (showStickers: boolean) => { + this.setState({ showStickers }); + }; + + private toggleButtonMenu = (): void => { + this.setState({ + isMenuOpen: !this.state.isMenuOpen, + }); + }; + + private renderButtons(menuPosition): JSX.Element | JSX.Element[] { + const buttons = new Map(); + if (!this.state.haveRecording) { + buttons.set( + _t("Send File"), + , + ); + buttons.set( + _t("Show Emojis"), + , + ); + } + if (this.shouldShowStickerPicker()) { + buttons.set( + _t("Show Stickers"), + this.showStickers(!this.state.showStickers)} + title={this.state.showStickers ? _t("Hide Stickers") : _t("Show Stickers")} + />, + ); + } + if (!this.state.haveRecording && !this.state.narrowMode) { + buttons.set( + _t("Send voice message"), + this.voiceRecordingButton?.onRecordStartEndClick()} + title={_t("Send voice message")} + />, + ); + } + + if (!this.state.narrowMode) { + return Array.from(buttons.values()); + } else { + const classnames = classNames({ + mx_MessageComposer_button: true, + mx_MessageComposer_buttonMenu: true, + mx_MessageComposer_closeButtonMenu: this.state.isMenuOpen, + }); + + return <> + { buttons[0] } + + { this.state.isMenuOpen && ( + + { Array.from(buttons).slice(1).map(([label, button]) => ( + + { button } + { label } + + )) } + + ) } + ; + } + } + render() { const controls = [ this.state.me && !this.props.compact ? : null, @@ -377,6 +497,12 @@ export default class MessageComposer extends React.Component { null, ]; + let menuPosition; + if (this.ref.current) { + const contentRect = this.ref.current.getBoundingClientRect(); + menuPosition = aboveLeftOf(contentRect); + } + if (!this.state.tombstone && this.state.canSendMessages) { controls.push( { />, ); - if (!this.state.haveRecording) { - controls.push( - , - , - ); - } - - if (SettingsStore.getValue(UIFeature.Widgets) && - SettingsStore.getValue("MessageComposerInput.showStickersButton") && - !this.state.haveRecording) { - controls.push(); - } - controls.push( this.voiceRecordingButton = c} room={this.props.room} />); - - if (!this.state.isComposerEmpty || this.state.haveRecording) { - controls.push( - , - ); - } } else if (this.state.tombstone) { const replacementRoomId = this.state.tombstone.getContent()['replacement_room']; @@ -459,6 +562,15 @@ export default class MessageComposer extends React.Component { yOffset={-50} />; } + controls.push( + , + ); + + const showSendButton = !this.state.isComposerEmpty || this.state.haveRecording; const classes = classNames({ "mx_MessageComposer": true, @@ -467,7 +579,7 @@ export default class MessageComposer extends React.Component { }); return ( -
+
{ recordingTooltip }
{ this.props.showReplyPreview && ( @@ -475,6 +587,14 @@ export default class MessageComposer extends React.Component { ) }
{ controls } + { this.renderButtons(menuPosition) } + { showSendButton && ( + + ) }
diff --git a/src/components/views/rooms/Stickerpicker.tsx b/src/components/views/rooms/Stickerpicker.tsx index 33367c1151..0806b4ab9d 100644 --- a/src/components/views/rooms/Stickerpicker.tsx +++ b/src/components/views/rooms/Stickerpicker.tsx @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ import React from 'react'; -import classNames from 'classnames'; import { Room } from 'matrix-js-sdk/src/models/room'; import { _t, _td } from '../../../languageHandler'; import AppTile from '../elements/AppTile'; @@ -27,7 +26,6 @@ import { IntegrationManagers } from "../../../integrations/IntegrationManagers"; import SettingsStore from "../../../settings/SettingsStore"; import { ChevronFace, ContextMenu } from "../../structures/ContextMenu"; import { WidgetType } from "../../../widgets/WidgetType"; -import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import { Action } from "../../../dispatcher/actions"; import { WidgetMessagingStore } from "../../../stores/widgets/WidgetMessagingStore"; import { replaceableComponent } from "../../../utils/replaceableComponent"; @@ -44,10 +42,12 @@ const PERSISTED_ELEMENT_KEY = "stickerPicker"; interface IProps { room: Room; + showStickers: boolean; + menuPosition?: any; + setShowStickers: (showStickers: boolean) => void; } interface IState { - showStickers: boolean; imError: string; stickerpickerX: number; stickerpickerY: number; @@ -72,7 +72,6 @@ export default class Stickerpicker extends React.PureComponent { constructor(props: IProps) { super(props); this.state = { - showStickers: false, imError: null, stickerpickerX: null, stickerpickerY: null, @@ -114,7 +113,7 @@ export default class Stickerpicker extends React.PureComponent { console.warn('No widget ID specified, not disabling assets'); } - this.setState({ showStickers: false }); + this.props.setShowStickers(false); WidgetUtils.removeStickerpickerWidgets().then(() => { this.forceUpdate(); }).catch((e) => { @@ -146,15 +145,15 @@ export default class Stickerpicker extends React.PureComponent { } public componentDidUpdate(prevProps: IProps, prevState: IState): void { - this.sendVisibilityToWidget(this.state.showStickers); + this.sendVisibilityToWidget(this.props.showStickers); } private imError(errorMsg: string, e: Error): void { console.error(errorMsg, e); this.setState({ - showStickers: false, imError: _t(errorMsg), }); + this.props.setShowStickers(false); } private updateWidget = (): void => { @@ -194,12 +193,12 @@ export default class Stickerpicker extends React.PureComponent { this.forceUpdate(); break; case "stickerpicker_close": - this.setState({ showStickers: false }); + this.props.setShowStickers(false); break; case Action.AfterRightPanelPhaseChange: case "show_left_panel": case "hide_left_panel": - this.setState({ showStickers: false }); + this.props.setShowStickers(false); break; } }; @@ -338,8 +337,8 @@ export default class Stickerpicker extends React.PureComponent { const y = (buttonRect.top + (buttonRect.height / 2) + window.pageYOffset) - 19; + this.props.setShowStickers(true); this.setState({ - showStickers: true, stickerpickerX: x, stickerpickerY: y, stickerpickerChevronOffset, @@ -351,8 +350,8 @@ export default class Stickerpicker extends React.PureComponent { * @param {Event} ev Event that triggered the function call */ private onHideStickersClick = (ev: React.MouseEvent): void => { - if (this.state.showStickers) { - this.setState({ showStickers: false }); + if (this.props.showStickers) { + this.props.setShowStickers(false); } }; @@ -360,8 +359,8 @@ export default class Stickerpicker extends React.PureComponent { * Called when the window is resized */ private onResize = (): void => { - if (this.state.showStickers) { - this.setState({ showStickers: false }); + if (this.props.showStickers) { + this.props.setShowStickers(false); } }; @@ -369,8 +368,8 @@ export default class Stickerpicker extends React.PureComponent { * The stickers picker was hidden */ private onFinished = (): void => { - if (this.state.showStickers) { - this.setState({ showStickers: false }); + if (this.props.showStickers) { + this.props.setShowStickers(false); } }; @@ -395,54 +394,23 @@ export default class Stickerpicker extends React.PureComponent { }; public render(): JSX.Element { - let stickerPicker; - let stickersButton; - const className = classNames( - "mx_MessageComposer_button", - "mx_MessageComposer_stickers", - "mx_Stickers_hideStickers", - "mx_MessageComposer_button_highlight", - ); - if (this.state.showStickers) { - // Show hide-stickers button - stickersButton = - ; + if (!this.props.showStickers) return null; - stickerPicker = - - ; - } else { - // Show show-stickers button - stickersButton = - ; - } - return - { stickersButton } - { stickerPicker } - ; + return + + ; } } diff --git a/src/components/views/rooms/VoiceRecordComposerTile.tsx b/src/components/views/rooms/VoiceRecordComposerTile.tsx index bd573fa474..288d97fc50 100644 --- a/src/components/views/rooms/VoiceRecordComposerTile.tsx +++ b/src/components/views/rooms/VoiceRecordComposerTile.tsx @@ -20,7 +20,6 @@ import React, { ReactNode } from "react"; import { IUpload, RecordingState, VoiceRecording } from "../../../audio/VoiceRecording"; import { Room } from "matrix-js-sdk/src/models/room"; import { MatrixClientPeg } from "../../../MatrixClientPeg"; -import classNames from "classnames"; import LiveRecordingWaveform from "../audio_messages/LiveRecordingWaveform"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import LiveRecordingClock from "../audio_messages/LiveRecordingClock"; @@ -137,7 +136,7 @@ export default class VoiceRecordComposerTile extends React.PureComponent { + public onRecordStartEndClick = async () => { if (this.state.recorder) { await this.state.recorder.stop(); return; @@ -215,27 +214,23 @@ export default class VoiceRecordComposerTile extends React.PureComponent; if (this.state.recorder && !this.state.recorder?.isRecording) { - stopOrRecordBtn = null; + stopBtn = null; } } @@ -264,13 +259,10 @@ export default class VoiceRecordComposerTile extends React.PureComponent; } - // The record button (mic icon) is meant to be on the right edge, but we also want the - // stop button to be left of the waveform area. Luckily, none of the surrounding UI is - // rendered when we're not recording, so the record button ends up in the correct spot. return (<> { uploadIndicator } { deleteButton } - { stopOrRecordBtn } + { stopBtn } { this.renderWaveformArea() } ); } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7d754a618a..1f8104da1d 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1564,7 +1564,12 @@ "Send a reply…": "Send a reply…", "Send an encrypted message…": "Send an encrypted message…", "Send a message…": "Send a message…", + "Send File": "Send File", + "Show Emojis": "Show Emojis", + "Show Stickers": "Show Stickers", + "Hide Stickers": "Hide Stickers", "Send voice message": "Send voice message", + "Composer menu": "Composer menu", "The conversation continues here.": "The conversation continues here.", "This room has been replaced and is no longer active.": "This room has been replaced and is no longer active.", "You do not have permission to post to this room": "You do not have permission to post to this room", @@ -1725,8 +1730,6 @@ "You don't currently have any stickerpacks enabled": "You don't currently have any stickerpacks enabled", "Add some now": "Add some now", "Stickerpack": "Stickerpack", - "Hide Stickers": "Hide Stickers", - "Show Stickers": "Show Stickers", "Failed to revoke invite": "Failed to revoke invite", "Could not revoke the invite. The server may be experiencing a temporary problem or you do not have sufficient permissions to revoke the invite.": "Could not revoke the invite. The server may be experiencing a temporary problem or you do not have sufficient permissions to revoke the invite.", "Admin Tools": "Admin Tools", From 646ef197fe5212ebac395966f38d918785016414 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Tue, 7 Sep 2021 16:02:26 +0100 Subject: [PATCH 04/23] Fix PR UI defects --- res/css/views/rooms/_MessageComposer.scss | 6 +++- src/components/structures/RightPanel.tsx | 5 ++- src/components/structures/RoomView.tsx | 3 +- src/components/structures/ThreadView.tsx | 3 ++ .../views/rooms/MessageComposer.tsx | 33 ++++++++++++------- src/i18n/strings/en_EN.json | 12 ++++--- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/res/css/views/rooms/_MessageComposer.scss b/res/css/views/rooms/_MessageComposer.scss index 5c8f6809de..26db5dbafe 100644 --- a/res/css/views/rooms/_MessageComposer.scss +++ b/res/css/views/rooms/_MessageComposer.scss @@ -358,12 +358,16 @@ limitations under the License. margin-right: 0; .mx_MessageComposer_wrapper { - padding: 0; + padding: 0 0 0 25px; } .mx_MessageComposer_button:last-child { margin-right: 0; } + + .mx_MessageComposer_e2eIcon { + left: 0; + } } .mx_MessageComposer_Menu .mx_CallContextMenu_item { diff --git a/src/components/structures/RightPanel.tsx b/src/components/structures/RightPanel.tsx index 67634c63d2..114d020c66 100644 --- a/src/components/structures/RightPanel.tsx +++ b/src/components/structures/RightPanel.tsx @@ -53,6 +53,7 @@ import PinnedMessagesCard from "../views/right_panel/PinnedMessagesCard"; import { throttle } from 'lodash'; import SpaceStore from "../../stores/SpaceStore"; import { RoomPermalinkCreator } from '../../utils/permalinks/Permalinks'; +import { E2EStatus } from '../../utils/ShieldUtils'; interface IProps { room?: Room; // if showing panels for a given room, this is set @@ -60,6 +61,7 @@ interface IProps { user?: User; // used if we know the user ahead of opening the panel resizeNotifier: ResizeNotifier; permalinkCreator?: RoomPermalinkCreator; + e2eStatus?: E2EStatus; } interface IState { @@ -319,7 +321,8 @@ export default class RightPanel extends React.Component { resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} mxEvent={this.state.event} - permalinkCreator={this.props.permalinkCreator} />; + permalinkCreator={this.props.permalinkCreator} + e2eStatus={this.props.e2eStatus} />; break; case RightPanelPhases.ThreadPanel: diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 8223c12e77..9dea4b1d1d 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -2054,7 +2054,8 @@ export default class RoomView extends React.Component { ? + permalinkCreator={this.getPermalinkCreatorForRoom(this.state.room)} + e2eStatus={this.state.e2eStatus} /> : null; const timelineClasses = classNames("mx_RoomView_timeline", { diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 134f018aed..304479cce3 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -33,6 +33,7 @@ import { ActionPayload } from '../../dispatcher/payloads'; import { SetRightPanelPhasePayload } from '../../dispatcher/payloads/SetRightPanelPhasePayload'; import { Action } from '../../dispatcher/actions'; import { MatrixClientPeg } from '../../MatrixClientPeg'; +import { E2EStatus } from '../../utils/ShieldUtils'; interface IProps { room: Room; @@ -40,6 +41,7 @@ interface IProps { resizeNotifier: ResizeNotifier; mxEvent: MatrixEvent; permalinkCreator?: RoomPermalinkCreator; + e2eStatus?: E2EStatus; } interface IState { @@ -144,6 +146,7 @@ export default class ThreadView extends React.Component { replyToEvent={this.state?.thread?.replyToEvent} showReplyPreview={false} permalinkCreator={this.props.permalinkCreator} + e2eStatus={this.props.e2eStatus} compact={true} /> diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 6b66ae4ba3..49acb13592 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -53,6 +53,7 @@ import EmojiPicker from '../emojipicker/EmojiPicker'; import MemberStatusMessageAvatar from "../avatars/MemberStatusMessageAvatar"; import UIStore, { UI_EVENTS } from '../../../stores/UIStore'; +let instanceCount = 0; const NARROW_MODE_BREAKPOINT = 500; interface IComposerAvatarProps { @@ -216,6 +217,7 @@ export default class MessageComposer extends React.Component { private messageComposerInput: SendMessageComposer; private voiceRecordingButton: VoiceRecordComposerTile; private ref: React.RefObject = createRef(); + private instanceId: number; static defaultProps = { replyInThread: false, @@ -236,14 +238,16 @@ export default class MessageComposer extends React.Component { isMenuOpen: false, showStickers: false, }; + + this.instanceId = instanceCount++; } componentDidMount() { this.dispatcherRef = dis.register(this.onAction); MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents); this.waitForOwnMember(); - UIStore.instance.trackElementDimensions("MessageComposer", this.ref.current); - UIStore.instance.on("MessageComposer", this.onResize); + UIStore.instance.trackElementDimensions(`MessageComposer${this.instanceId}`, this.ref.current); + UIStore.instance.on(`MessageComposer${this.instanceId}`, this.onResize); } private onResize = (type: UI_EVENTS, entry: ResizeObserverEntry) => { @@ -291,8 +295,8 @@ export default class MessageComposer extends React.Component { } VoiceRecordingStore.instance.off(UPDATE_EVENT, this.onVoiceStoreUpdate); dis.unregister(this.dispatcherRef); - UIStore.instance.stopTrackingElementDimensions("MessageComposer"); - UIStore.instance.removeListener("MessageComposer", this.onResize); + UIStore.instance.stopTrackingElementDimensions(`MessageComposer${this.instanceId}`); + UIStore.instance.removeListener(`MessageComposer${this.instanceId}`, this.onResize); } private onRoomStateEvents = (ev, state) => { @@ -342,7 +346,11 @@ export default class MessageComposer extends React.Component { private renderPlaceholderText = () => { if (this.props.replyToEvent) { - if (this.props.e2eStatus) { + if (this.props.replyInThread && this.props.e2eStatus) { + return _t('Reply to encrypted thread…'); + } else if (this.props.replyInThread) { + return _t('Reply to thread…'); + } else if (this.props.e2eStatus) { return _t('Send an encrypted reply…'); } else { return _t('Send a reply…'); @@ -419,17 +427,17 @@ export default class MessageComposer extends React.Component { const buttons = new Map(); if (!this.state.haveRecording) { buttons.set( - _t("Send File"), + _t("Send a file"), , ); buttons.set( - _t("Show Emojis"), + _t("Add emoji"), , ); } if (this.shouldShowStickerPicker()) { buttons.set( - _t("Show Stickers"), + _t("Send a sticker"), { } if (!this.state.haveRecording && !this.state.narrowMode) { buttons.set( - _t("Send voice message"), + _t("Send a voice message"), this.voiceRecordingButton?.onRecordStartEndClick()} @@ -450,8 +458,9 @@ export default class MessageComposer extends React.Component { ); } + const buttonsArray = Array.from(buttons.values()); if (!this.state.narrowMode) { - return Array.from(buttons.values()); + return buttonsArray; } else { const classnames = classNames({ mx_MessageComposer_button: true, @@ -460,11 +469,11 @@ export default class MessageComposer extends React.Component { }); return <> - { buttons[0] } + { buttonsArray[0] } { this.state.isMenuOpen && ( diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 1f8104da1d..b4b1071013 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1560,16 +1560,20 @@ "Send message": "Send message", "Emoji picker": "Emoji picker", "Upload file": "Upload file", + "Reply to encrypted thread…": "Reply to encrypted thread…", + "Reply to thread…": "Reply to thread…", "Send an encrypted reply…": "Send an encrypted reply…", "Send a reply…": "Send a reply…", "Send an encrypted message…": "Send an encrypted message…", "Send a message…": "Send a message…", - "Send File": "Send File", - "Show Emojis": "Show Emojis", - "Show Stickers": "Show Stickers", + "Send a file": "Send a file", + "Add emoji": "Add emoji", + "Send a sticker": "Send a sticker", "Hide Stickers": "Hide Stickers", + "Show Stickers": "Show Stickers", + "Send a voice message": "Send a voice message", "Send voice message": "Send voice message", - "Composer menu": "Composer menu", + "More options": "More options", "The conversation continues here.": "The conversation continues here.", "This room has been replaced and is no longer active.": "This room has been replaced and is no longer active.", "You do not have permission to post to this room": "You do not have permission to post to this room", From bbf66a001136cb6240b06b86085891678fce08f7 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Tue, 7 Sep 2021 17:10:09 +0100 Subject: [PATCH 05/23] Make label clickable on narrow mode context menu --- res/css/views/rooms/_MessageComposer.scss | 22 ++++++-- .../elements/AccessibleTooltipButton.tsx | 4 +- .../views/rooms/MessageComposer.tsx | 52 +++++++++++-------- src/i18n/strings/en_EN.json | 6 +-- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/res/css/views/rooms/_MessageComposer.scss b/res/css/views/rooms/_MessageComposer.scss index 26db5dbafe..faa3171d67 100644 --- a/res/css/views/rooms/_MessageComposer.scss +++ b/res/css/views/rooms/_MessageComposer.scss @@ -186,11 +186,14 @@ limitations under the License. } .mx_MessageComposer_button { + --size: 26px; position: relative; margin-right: 6px; cursor: pointer; - height: 26px; - width: 26px; + height: var(--size); + line-height: var(--size); + width: auto; + padding-left: calc(var(--size) + 5px); border-radius: 100%; &::before { @@ -207,8 +210,21 @@ limitations under the License. mask-position: center; } + &::after { + content: ''; + position: absolute; + left: 0; + top: 0; + z-index: 0; + width: var(--size); + height: var(--size); + border-radius: 50%; + } + &:hover { - background: rgba($accent-color, 0.1); + &::after { + background: rgba($accent-color, 0.1); + } &::before { background-color: $accent-color; diff --git a/src/components/views/elements/AccessibleTooltipButton.tsx b/src/components/views/elements/AccessibleTooltipButton.tsx index 8ac41ad1a2..d2a4801a2d 100644 --- a/src/components/views/elements/AccessibleTooltipButton.tsx +++ b/src/components/views/elements/AccessibleTooltipButton.tsx @@ -25,6 +25,7 @@ import { replaceableComponent } from "../../../utils/replaceableComponent"; interface ITooltipProps extends React.ComponentProps { title: string; tooltip?: React.ReactNode; + label?: React.ReactNode; tooltipClassName?: string; forceHide?: boolean; yOffset?: number; @@ -84,7 +85,8 @@ export default class AccessibleTooltipButton extends React.PureComponent { children } - { tip } + { this.props.label } + { (tooltip || title) && tip } ); } diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 49acb13592..6372ecc1f5 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -81,7 +81,13 @@ function SendButton(props: ISendButtonProps) { ); } -const EmojiButton = ({ addEmoji, menuPosition }) => { +interface IEmojiButtonProps { + addEmoji: (unicode: string) => boolean; + menuPosition: any; // TODO: Types + narrowMode: boolean; +} + +const EmojiButton: React.FC = ({ addEmoji, menuPosition, narrowMode }) => { const [menuDisplayed, button, openMenu, closeMenu] = useContextMenu(); let contextMenu; @@ -103,12 +109,11 @@ const EmojiButton = ({ addEmoji, menuPosition }) => { // TODO: replace ContextMenuTooltipButton with a unified representation of // the header buttons and the right panel buttons return - { contextMenu } @@ -364,11 +369,12 @@ export default class MessageComposer extends React.Component { } }; - private addEmoji(emoji: string) { + private addEmoji(emoji: string): boolean { dis.dispatch({ action: Action.ComposerInsert, text: emoji, }); + return true; } private sendMessage = async () => { @@ -424,32 +430,34 @@ export default class MessageComposer extends React.Component { }; private renderButtons(menuPosition): JSX.Element | JSX.Element[] { - const buttons = new Map(); + const buttons: JSX.Element[] = []; if (!this.state.haveRecording) { - buttons.set( - _t("Send a file"), + buttons.push( , ); - buttons.set( - _t("Add emoji"), - , + buttons.push( + , ); } if (this.shouldShowStickerPicker()) { - buttons.set( - _t("Send a sticker"), + let title; + if (!this.state.narrowMode) { + title = this.state.showStickers ? _t("Hide Stickers") : _t("Show Stickers"); + } + + buttons.push( this.showStickers(!this.state.showStickers)} - title={this.state.showStickers ? _t("Hide Stickers") : _t("Show Stickers")} + title={title} + label={this.state.narrowMode && _t("Send a sticker")} />, ); } if (!this.state.haveRecording && !this.state.narrowMode) { - buttons.set( - _t("Send a voice message"), + buttons.push( this.voiceRecordingButton?.onRecordStartEndClick()} @@ -458,9 +466,8 @@ export default class MessageComposer extends React.Component { ); } - const buttonsArray = Array.from(buttons.values()); if (!this.state.narrowMode) { - return buttonsArray; + return buttons; } else { const classnames = classNames({ mx_MessageComposer_button: true, @@ -469,7 +476,7 @@ export default class MessageComposer extends React.Component { }); return <> - { buttonsArray[0] } + { buttons[0] } { menuWidth={150} wrapperClassName="mx_MessageComposer_Menu" > - { Array.from(buttons).slice(1).map(([label, button]) => ( - + { buttons.slice(1).map((button, index) => ( + { button } - { label } )) } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b4b1071013..1200042f2f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1559,6 +1559,7 @@ "%(userName)s (power %(powerLevelNumber)s)": "%(userName)s (power %(powerLevelNumber)s)", "Send message": "Send message", "Emoji picker": "Emoji picker", + "Send an emoji": "Send an emoji", "Upload file": "Upload file", "Reply to encrypted thread…": "Reply to encrypted thread…", "Reply to thread…": "Reply to thread…", @@ -1566,12 +1567,9 @@ "Send a reply…": "Send a reply…", "Send an encrypted message…": "Send an encrypted message…", "Send a message…": "Send a message…", - "Send a file": "Send a file", - "Add emoji": "Add emoji", - "Send a sticker": "Send a sticker", "Hide Stickers": "Hide Stickers", "Show Stickers": "Show Stickers", - "Send a voice message": "Send a voice message", + "Send an sticker": "Send an sticker", "Send voice message": "Send voice message", "More options": "More options", "The conversation continues here.": "The conversation continues here.", From 8bd1f384b94d37ad150874ca64e2f3f962a2ae23 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 10:16:20 +0100 Subject: [PATCH 06/23] Improve tooltips on space quick actions and explore button --- src/components/structures/LeftPanel.tsx | 4 +++- src/components/views/rooms/RoomList.tsx | 12 ++++++++---- src/i18n/strings/en_EN.json | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/structures/LeftPanel.tsx b/src/components/structures/LeftPanel.tsx index d955271249..9a2ebd45e2 100644 --- a/src/components/structures/LeftPanel.tsx +++ b/src/components/structures/LeftPanel.tsx @@ -399,7 +399,9 @@ export default class LeftPanel extends React.Component { mx_LeftPanel_exploreButton_space: !!this.state.activeSpace, })} onClick={this.onExplore} - title={_t("Explore rooms")} + title={this.state.activeSpace + ? _t("Explore %(spaceName)s", { spaceName: this.state.activeSpace.name }) + : _t("Explore rooms")} />
); diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index 4988ea6691..541d0e1d9d 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -48,6 +48,7 @@ import SpaceStore, { ISuggestedRoom, SUGGESTED_ROOMS } from "../../../stores/Spa import { showAddExistingRooms, showCreateNewRoom, showSpaceInvite } from "../../../utils/space"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import RoomAvatar from "../avatars/RoomAvatar"; +import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; interface IProps { onKeyDown: (ev: React.KeyboardEvent) => void; @@ -522,20 +523,23 @@ export default class RoomList extends React.PureComponent { } else if ( this.props.activeSpace?.canInvite(userId) || this.props.activeSpace?.getMyMembership() === "join" ) { + const spaceName = this.props.activeSpace.name; explorePrompt =
{ _t("Quick actions") }
- { this.props.activeSpace.canInvite(userId) && { _t("Invite people") } - } - { this.props.activeSpace.getMyMembership() === "join" && } + { this.props.activeSpace.getMyMembership() === "join" && { _t("Explore rooms") } - } + }
; } else if (Object.values(this.state.sublists).some(list => list.length > 0)) { const unfilteredLists = RoomListStore.instance.unfilteredLists; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7d754a618a..b2f09686bb 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1643,6 +1643,7 @@ "Start a new chat": "Start a new chat", "Explore all public rooms": "Explore all public rooms", "Quick actions": "Quick actions", + "Explore %(spaceName)s": "Explore %(spaceName)s", "Use the + to make a new room or explore existing ones below": "Use the + to make a new room or explore existing ones below", "%(count)s results in all spaces|other": "%(count)s results in all spaces", "%(count)s results in all spaces|one": "%(count)s result in all spaces", From 47fd11050fe0634e3cc2872a527622dcceec4826 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 8 Sep 2021 11:43:46 +0100 Subject: [PATCH 07/23] Switch type check to GitHub Actions and add (working) type check for release mode js-sdk types --- .github/workflows/lint.yaml | 25 +++++++++++++++++++++++++ scripts/ci/js-sdk-to-release.js | 17 +++++++++++++++++ scripts/ci/js-sdk-to-release.sh | 21 --------------------- 3 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100755 scripts/ci/js-sdk-to-release.js delete mode 100755 scripts/ci/js-sdk-to-release.sh diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000000..e7f12ab65d --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,25 @@ +name: Lint +on: + pull_request: + branches: [develop] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: c-hive/gha-yarn-cache@v2 + - name: Install Deps + run: "./scripts/ci/install-deps.sh --ignore-scripts" + - name: Typecheck + run: "yarn run lint:types" + - name: Switch js-sdk to release mode + run: | + scripts/ci/js-sdk-to-release.js + pushd node_modules/matrix-js-sdk + yarn install + yarn run build:compile + yarn run build:types + popd + - name: Typecheck (release mode) + run: "yarn run lint:types" + diff --git a/scripts/ci/js-sdk-to-release.js b/scripts/ci/js-sdk-to-release.js new file mode 100755 index 0000000000..e1fecfde03 --- /dev/null +++ b/scripts/ci/js-sdk-to-release.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +const fsProm = require('fs/promises'); + +const PKGJSON = 'node_modules/matrix-js-sdk/package.json'; + +async function main() { + const pkgJson = JSON.parse(await fsProm.readFile(PKGJSON, 'utf8')); + for (const field of ['main', 'typings']) { + if (pkgJson["matrix_lib_"+field] !== undefined) { + pkgJson[field] = pkgJson["matrix_lib_"+field]; + } + } + await fsProm.writeFile(PKGJSON, JSON.stringify(pkgJson, null, 2)); +} + +main(); diff --git a/scripts/ci/js-sdk-to-release.sh b/scripts/ci/js-sdk-to-release.sh deleted file mode 100755 index a03165bd82..0000000000 --- a/scripts/ci/js-sdk-to-release.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# This changes the js-sdk into 'release mode', that is: -# * The entry point for the library is the babel-compiled lib/index.js rather than src/index.ts -# * There's a 'typings' entry referencing the types output by tsc -# We do this so we can test that each PR still builds / type checks correctly when built -# against the released js-sdk, because if you do things like `import { User } from 'matrix-js-sdk';` -# rather than `import { User } from 'matrix-js-sdk/src/models/user';` it will work fine with the -# js-sdk in development mode but then break at release time. -# We can't use the last release of the js-sdk though: it might not be up to date enough. - -cd node_modules/matrix-js-sdk -for i in main typings -do - lib_value=$(jq -r ".matrix_lib_$i" package.json) - if [ "$lib_value" != "null" ]; then - jq ".$i = .matrix_lib_$i" package.json > package.json.new && mv package.json.new package.json - fi -done -yarn run build:compile -yarn run build:types From f3abb13dc9619a32eee8308cc7eb9e4c0a51bd13 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 12:34:44 +0100 Subject: [PATCH 08/23] Convert crypto/verification/* to Typescript --- .../views/right_panel/EncryptionPanel.tsx | 2 +- .../views/right_panel/VerificationPanel.tsx | 38 ++++++------------- .../verification/VerificationShowSas.tsx | 4 +- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/components/views/right_panel/EncryptionPanel.tsx b/src/components/views/right_panel/EncryptionPanel.tsx index b1c8d427bf..8beb089b38 100644 --- a/src/components/views/right_panel/EncryptionPanel.tsx +++ b/src/components/views/right_panel/EncryptionPanel.tsx @@ -57,7 +57,7 @@ const EncryptionPanel: React.FC = (props: IProps) => { // state to show a spinner immediately after clicking "start verification", // before we have a request const [isRequesting, setRequesting] = useState(false); - const [phase, setPhase] = useState(request && request.phase); + const [phase, setPhase] = useState(request?.phase); useEffect(() => { setRequest(verificationRequest); if (verificationRequest) { diff --git a/src/components/views/right_panel/VerificationPanel.tsx b/src/components/views/right_panel/VerificationPanel.tsx index 395bdc21e0..a29bdea90b 100644 --- a/src/components/views/right_panel/VerificationPanel.tsx +++ b/src/components/views/right_panel/VerificationPanel.tsx @@ -29,43 +29,27 @@ import VerificationQRCode from "../elements/crypto/VerificationQRCode"; import { _t } from "../../../languageHandler"; import SdkConfig from "../../../SdkConfig"; import E2EIcon from "../rooms/E2EIcon"; -import { - PHASE_READY, - PHASE_DONE, - PHASE_STARTED, - PHASE_CANCELLED, -} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; +import { Phase } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; import Spinner from "../elements/Spinner"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import AccessibleButton from "../elements/AccessibleButton"; import VerificationShowSas from "../verification/VerificationShowSas"; -// XXX: Should be defined in matrix-js-sdk -enum VerificationPhase { - PHASE_UNSENT, - PHASE_REQUESTED, - PHASE_READY, - PHASE_DONE, - PHASE_STARTED, - PHASE_CANCELLED, -} - interface IProps { layout: string; request: VerificationRequest; member: RoomMember | User; - phase: VerificationPhase; + phase: Phase; onClose: () => void; isRoomEncrypted: boolean; inDialog: boolean; - key: number; } interface IState { - sasEvent?: SAS; + sasEvent?: SAS["sasEvent"]; emojiButtonClicked?: boolean; reciprocateButtonClicked?: boolean; - reciprocateQREvent?: ReciprocateQRCode; + reciprocateQREvent?: ReciprocateQRCode["reciprocateQREvent"]; } @replaceableComponent("views.right_panel.VerificationPanel") @@ -321,9 +305,9 @@ export default class VerificationPanel extends React.PureComponent { const { request } = this.props; - const { sasEvent, reciprocateQREvent } = request.verifier; + const sasEvent = (request.verifier as SAS).sasEvent; + const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent; request.verifier.off('show_sas', this.updateVerifierState); request.verifier.off('show_reciprocate_qr', this.updateVerifierState); this.setState({ sasEvent, reciprocateQREvent }); @@ -402,7 +387,8 @@ export default class VerificationPanel extends React.PureComponent void; onCancel: () => void; - sas: SAS.sas; + sas: IGeneratedSas; isSelf?: boolean; inDialog?: boolean; // whether this component is being shown in a dialog and to use DialogButtons } From 83912daced7bafdea313436ac1270229c1585065 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 13:16:31 +0100 Subject: [PATCH 09/23] Improve the upgrade for restricted user experience --- .../views/dialogs/RoomSettingsDialog.tsx | 5 +- .../tabs/room/SecurityRoomSettingsTab.tsx | 18 ++++++- src/utils/RoomUpgrade.ts | 51 ++++++++++++------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/components/views/dialogs/RoomSettingsDialog.tsx b/src/components/views/dialogs/RoomSettingsDialog.tsx index a426dce5c7..a73f0a595b 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.tsx +++ b/src/components/views/dialogs/RoomSettingsDialog.tsx @@ -79,7 +79,10 @@ export default class RoomSettingsDialog extends React.Component { ROOM_SECURITY_TAB, _td("Security & Privacy"), "mx_RoomSettingsDialog_securityIcon", - , + this.props.onFinished(true)} + />, )); tabs.push(new Tab( ROOM_ROLES_TAB, diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index 081b1a8698..5cb76ebc25 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -39,9 +39,12 @@ import { arrayHasDiff } from "../../../../../utils/arrays"; import SettingsFlag from '../../../elements/SettingsFlag'; import createRoom, { IOpts } from '../../../../../createRoom'; import CreateRoomDialog from '../../../dialogs/CreateRoomDialog'; +import dis from "../../../../../dispatcher/dispatcher"; +import { ROOM_SECURITY_TAB } from "../../../dialogs/RoomSettingsDialog"; interface IProps { roomId: string; + closeSettingsFn: () => void; } interface IState { @@ -220,9 +223,20 @@ export default class SecurityRoomSettingsTab extends React.Component { + onFinished: async (resp) => { if (!resp?.continue) return; - upgradeRoom(room, targetVersion, resp.invite); + const roomId = await upgradeRoom(room, targetVersion, resp.invite, true, true, true); + this.props.closeSettingsFn(); + // switch to the new room in the background + dis.dispatch({ + action: "view_room", + room_id: roomId, + }); + // open new settings on this tab + dis.dispatch({ + action: "open_room_settings", + initial_tab_id: ROOM_SECURITY_TAB, + }); }, }); return; diff --git a/src/utils/RoomUpgrade.ts b/src/utils/RoomUpgrade.ts index e632ec6345..4dd2a880a0 100644 --- a/src/utils/RoomUpgrade.ts +++ b/src/utils/RoomUpgrade.ts @@ -22,6 +22,7 @@ import Modal from "../Modal"; import { _t } from "../languageHandler"; import ErrorDialog from "../components/views/dialogs/ErrorDialog"; import SpaceStore from "../stores/SpaceStore"; +import Spinner from "../components/views/elements/Spinner"; export async function upgradeRoom( room: Room, @@ -29,8 +30,10 @@ export async function upgradeRoom( inviteUsers = false, handleError = true, updateSpaces = true, + awaitRoom = false, ): Promise { const cli = room.client; + const modal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner"); let newRoomId: string; try { @@ -46,27 +49,36 @@ export async function upgradeRoom( throw e; } - // We have to wait for the js-sdk to give us the room back so - // we can more effectively abuse the MultiInviter behaviour - // which heavily relies on the Room object being available. - if (inviteUsers) { - const checkForUpgradeFn = async (newRoom: Room): Promise => { - // The upgradePromise should be done by the time we await it here. - if (newRoom.roomId !== newRoomId) return; - - const toInvite = [ - ...room.getMembersWithMembership("join"), - ...room.getMembersWithMembership("invite"), - ].map(m => m.userId).filter(m => m !== cli.getUserId()); - - if (toInvite.length > 0) { - // Errors are handled internally to this function - await inviteUsersToRoom(newRoomId, toInvite); + if (awaitRoom || inviteUsers) { + await new Promise(resolve => { + // already have the room + if (room.client.getRoom(newRoomId)) { + resolve(); + return; } - cli.removeListener('Room', checkForUpgradeFn); - }; - cli.on('Room', checkForUpgradeFn); + // We have to wait for the js-sdk to give us the room back so + // we can more effectively abuse the MultiInviter behaviour + // which heavily relies on the Room object being available. + const checkForRoomFn = (newRoom: Room) => { + if (newRoom.roomId !== newRoomId) return; + resolve(); + cli.off("Room", checkForRoomFn); + }; + cli.on("Room", checkForRoomFn); + }); + } + + if (inviteUsers) { + const toInvite = [ + ...room.getMembersWithMembership("join"), + ...room.getMembersWithMembership("invite"), + ].map(m => m.userId).filter(m => m !== cli.getUserId()); + + if (toInvite.length > 0) { + // Errors are handled internally to this function + await inviteUsersToRoom(newRoomId, toInvite); + } } if (updateSpaces) { @@ -89,5 +101,6 @@ export async function upgradeRoom( } } + modal.close(); return newRoomId; } From d4bac4752d0eabf8304f6bb310505ad06406233d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 13:34:26 +0100 Subject: [PATCH 10/23] Make space members and user info behave more expectedly --- src/components/structures/RightPanel.tsx | 2 +- .../views/context_menus/SpaceContextMenu.tsx | 2 +- src/components/views/right_panel/UserInfo.tsx | 13 ++++++++----- src/i18n/strings/en_EN.json | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RightPanel.tsx b/src/components/structures/RightPanel.tsx index 67634c63d2..5b12e542bd 100644 --- a/src/components/structures/RightPanel.tsx +++ b/src/components/structures/RightPanel.tsx @@ -269,7 +269,7 @@ export default class RightPanel extends React.Component { case RightPanelPhases.EncryptionPanel: panel = { defaultDispatcher.dispatch({ action: Action.SetRightPanelPhase, phase: RightPanelPhases.SpaceMemberList, - refireParams: { space: space }, + refireParams: { space }, }); onFinished(); }; diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index d15f349d62..f90643f1df 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -1278,7 +1278,9 @@ const BasicUserInfo: React.FC<{ // hide the Roles section for DMs as it doesn't make sense there if (!DMRoomMap.shared().getUserIdForRoomId((member as RoomMember).roomId)) { memberDetails =
-

{ _t("Role") }

+

{ _t("Role in ", {}, { + RoomName: () => { room.name }, + }) }

= ({ // We have no previousPhase for when viewing a UserInfo from a Group or without a Room at this time if (room && phase === RightPanelPhases.EncryptionPanel) { previousPhase = RightPanelPhases.RoomMemberInfo; - refireParams = { member: member }; + refireParams = { member }; + } else if (room?.isSpaceRoom() && SpaceStore.spacesEnabled) { + previousPhase = previousPhase = RightPanelPhases.SpaceMemberList; + refireParams = { space: room }; } else if (room) { - previousPhase = previousPhase = SpaceStore.spacesEnabled && room.isSpaceRoom() - ? RightPanelPhases.SpaceMemberList - : RightPanelPhases.RoomMemberList; + previousPhase = RightPanelPhases.RoomMemberList; } const onEncryptionPanelClose = () => { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7d754a618a..10152193a3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1866,7 +1866,7 @@ "Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?": "Deactivating this user will log them out and prevent them from logging back in. Additionally, they will leave all the rooms they are in. This action cannot be reversed. Are you sure you want to deactivate this user?", "Deactivate user": "Deactivate user", "Failed to deactivate user": "Failed to deactivate user", - "Role": "Role", + "Role in ": "Role in ", "This client does not support end-to-end encryption.": "This client does not support end-to-end encryption.", "Edit devices": "Edit devices", "Security": "Security", From 17e0a4b3d772cdf96043fac3029d13c19bc9d1d7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 17:14:51 +0100 Subject: [PATCH 11/23] iterate PR based on feedback --- src/utils/RoomUpgrade.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/RoomUpgrade.ts b/src/utils/RoomUpgrade.ts index 4dd2a880a0..366f49d892 100644 --- a/src/utils/RoomUpgrade.ts +++ b/src/utils/RoomUpgrade.ts @@ -33,7 +33,7 @@ export async function upgradeRoom( awaitRoom = false, ): Promise { const cli = room.client; - const modal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner"); + const spinnerModal = Modal.createDialog(Spinner, null, "mx_Dialog_spinner"); let newRoomId: string; try { @@ -101,6 +101,6 @@ export async function upgradeRoom( } } - modal.close(); + spinnerModal.close(); return newRoomId; } From 21e33362e5a92c22dcf659d83ee4d4578d99407d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 8 Sep 2021 11:26:54 -0600 Subject: [PATCH 12/23] Add config option to turn on in-room event sending timing metrics This is intended to be hooked up to an external system. Due to the extra events and metadata concerns, this is only available if turned on from the config. See `sendTimePerformanceMetrics.ts` for event schemas. --- src/ContentMessages.tsx | 11 +++++ .../views/rooms/SendMessageComposer.tsx | 10 ++++ src/sendTimePerformanceMetrics.ts | 48 +++++++++++++++++++ src/settings/Settings.tsx | 4 ++ 4 files changed, 73 insertions(+) create mode 100644 src/sendTimePerformanceMetrics.ts diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 14a0c1ed51..40f8e307a5 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -39,6 +39,8 @@ import { import { IUpload } from "./models/IUpload"; import { IAbortablePromise, IImageInfo } from "matrix-js-sdk/src/@types/partials"; import { BlurhashEncoder } from "./BlurhashEncoder"; +import SettingsStore from "./settings/SettingsStore"; +import { decorateStartSendingTime, sendRoundTripMetric } from "./sendTimePerformanceMetrics"; const MAX_WIDTH = 800; const MAX_HEIGHT = 600; @@ -539,6 +541,10 @@ export default class ContentMessages { msgtype: "", // set later }; + if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) { + decorateStartSendingTime(content); + } + // if we have a mime type for the file, add it to the message metadata if (file.type) { content.info.mimetype = file.type; @@ -614,6 +620,11 @@ export default class ContentMessages { }).then(function() { if (upload.canceled) throw new UploadCanceledError(); const prom = matrixClient.sendMessage(roomId, content); + if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) { + prom.then(resp => { + sendRoundTripMetric(matrixClient, roomId, resp.event_id); + }); + } CountlyAnalytics.instance.trackSendMessage(startTime, prom, roomId, false, false, content); return prom; }, function(err) { diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index aca397b6b2..bb5d537895 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -54,6 +54,7 @@ import { Room } from 'matrix-js-sdk/src/models/room'; import ErrorDialog from "../dialogs/ErrorDialog"; import QuestionDialog from "../dialogs/QuestionDialog"; import { ActionPayload } from "../../../dispatcher/payloads"; +import { decorateStartSendingTime, sendRoundTripMetric } from "../../../sendTimePerformanceMetrics"; function addReplyToMessageContent( content: IContent, @@ -418,6 +419,10 @@ export default class SendMessageComposer extends React.Component { // don't bother sending an empty message if (!content.body.trim()) return; + if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) { + decorateStartSendingTime(content); + } + const prom = this.context.sendMessage(roomId, content); if (replyToEvent) { // Clear reply_to_event as we put the message into the queue @@ -433,6 +438,11 @@ export default class SendMessageComposer extends React.Component { dis.dispatch({ action: `effects.${effect.command}` }); } }); + if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) { + prom.then(resp => { + sendRoundTripMetric(this.context, roomId, resp.event_id); + }); + } CountlyAnalytics.instance.trackSendMessage(startTime, prom, roomId, false, !!replyToEvent, content); } diff --git a/src/sendTimePerformanceMetrics.ts b/src/sendTimePerformanceMetrics.ts new file mode 100644 index 0000000000..ef461db939 --- /dev/null +++ b/src/sendTimePerformanceMetrics.ts @@ -0,0 +1,48 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { MatrixClient } from "matrix-js-sdk"; + +/** + * Decorates the given event content object with the "send start time". The + * object will be modified in-place. + * @param {object} content The event content. + */ +export function decorateStartSendingTime(content: object) { + content['io.element.performance_metrics'] = { + sendStartTs: Date.now(), + }; +} + +/** + * Called when an event decorated with `decorateStartSendingTime()` has been sent + * by the server (the client now knows the event ID). + * @param {MatrixClient} client The client to send as. + * @param {string} inRoomId The room ID where the original event was sent. + * @param {string} forEventId The event ID for the decorated event. + */ +export function sendRoundTripMetric(client: MatrixClient, inRoomId: string, forEventId: string) { + // noinspection JSIgnoredPromiseFromCall + client.sendEvent(inRoomId, 'io.element.performance_metric', { + // XXX: We stick all of this into `m.relates_to` so it doesn't end up encrypted. + "m.relates_to": { + rel_type: "io.element.metric", + event_id: forEventId, + responseTs: Date.now(), + kind: 'send_time', + } as any, // override types because we're actually allowed to add extra metadata to relates_to + }); +} diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 40f57a0a1c..6dbefd4b8e 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -759,6 +759,10 @@ export const SETTINGS: {[setting: string]: ISetting} = { default: true, controller: new ReducedMotionController(), }, + "Performance.addSendMessageTimingMetadata": { + supportedLevels: [SettingLevel.CONFIG], + default: false, + }, "Widgets.pinned": { // deprecated supportedLevels: LEVELS_ROOM_OR_ACCOUNT, default: {}, From 70e28e7e137ced3700c4fd8473f00683edf8e92e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 8 Sep 2021 11:31:37 -0600 Subject: [PATCH 13/23] Move fields into consistent location for js-sdk to target --- src/sendTimePerformanceMetrics.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sendTimePerformanceMetrics.ts b/src/sendTimePerformanceMetrics.ts index ef461db939..a8846d3cbf 100644 --- a/src/sendTimePerformanceMetrics.ts +++ b/src/sendTimePerformanceMetrics.ts @@ -37,12 +37,10 @@ export function decorateStartSendingTime(content: object) { export function sendRoundTripMetric(client: MatrixClient, inRoomId: string, forEventId: string) { // noinspection JSIgnoredPromiseFromCall client.sendEvent(inRoomId, 'io.element.performance_metric', { - // XXX: We stick all of this into `m.relates_to` so it doesn't end up encrypted. - "m.relates_to": { - rel_type: "io.element.metric", - event_id: forEventId, + "io.element.performance_metrics": { + forEventId: forEventId, responseTs: Date.now(), kind: 'send_time', - } as any, // override types because we're actually allowed to add extra metadata to relates_to + }, }); } From b4f42e1103262b0f55a5e06e7dd0d254d986e638 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 8 Sep 2021 11:35:25 -0600 Subject: [PATCH 14/23] Appease the linter --- src/sendTimePerformanceMetrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sendTimePerformanceMetrics.ts b/src/sendTimePerformanceMetrics.ts index a8846d3cbf..ee5caa05a9 100644 --- a/src/sendTimePerformanceMetrics.ts +++ b/src/sendTimePerformanceMetrics.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixClient } from "matrix-js-sdk"; +import { MatrixClient } from "matrix-js-sdk/src"; /** * Decorates the given event content object with the "send start time". The From 8f221a484940b610d3f8ace353d20925872fb948 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 8 Sep 2021 18:37:13 +0100 Subject: [PATCH 15/23] Rename type checking script 'cos it's type chekcing, not linting --- .github/workflows/{lint.yaml => typecheck.yaml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{lint.yaml => typecheck.yaml} (97%) diff --git a/.github/workflows/lint.yaml b/.github/workflows/typecheck.yaml similarity index 97% rename from .github/workflows/lint.yaml rename to .github/workflows/typecheck.yaml index e7f12ab65d..bbbf7185d7 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/typecheck.yaml @@ -1,4 +1,4 @@ -name: Lint +name: Type Check on: pull_request: branches: [develop] From b67883b4f19abe2aa2c59d3c8baf36443c826670 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Sep 2021 09:41:11 +0100 Subject: [PATCH 16/23] Remove unnecessary pushd type: task --- .github/workflows/typecheck.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/typecheck.yaml b/.github/workflows/typecheck.yaml index bbbf7185d7..2e08418cf6 100644 --- a/.github/workflows/typecheck.yaml +++ b/.github/workflows/typecheck.yaml @@ -15,11 +15,10 @@ jobs: - name: Switch js-sdk to release mode run: | scripts/ci/js-sdk-to-release.js - pushd node_modules/matrix-js-sdk + cd node_modules/matrix-js-sdk yarn install yarn run build:compile yarn run build:types - popd - name: Typecheck (release mode) run: "yarn run lint:types" From 82cd7acdae5cb6047f52ad0219213d195e1ecaaf Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 9 Sep 2021 11:40:43 +0100 Subject: [PATCH 17/23] Use cursor:pointer on space panel buttons --- res/css/structures/_SpacePanel.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/res/css/structures/_SpacePanel.scss b/res/css/structures/_SpacePanel.scss index 702936523d..bbb1867f16 100644 --- a/res/css/structures/_SpacePanel.scss +++ b/res/css/structures/_SpacePanel.scss @@ -114,6 +114,7 @@ $activeBorderColor: $secondary-content; align-items: center; padding: 4px 4px 4px 0; width: 100%; + cursor: pointer; &.mx_SpaceButton_active { &:not(.mx_SpaceButton_narrow) .mx_SpaceButton_selectionWrapper { From aa534442670f817ff700a509721a31ace645e61f Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 9 Sep 2021 13:27:25 +0100 Subject: [PATCH 18/23] Improve narrow composer usability --- res/css/views/rooms/_EventTile.scss | 4 ++++ res/css/views/rooms/_MessageComposer.scss | 4 ++-- src/components/views/rooms/MessageComposer.tsx | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/res/css/views/rooms/_EventTile.scss b/res/css/views/rooms/_EventTile.scss index 351abc5cd9..4495ec4f29 100644 --- a/res/css/views/rooms/_EventTile.scss +++ b/res/css/views/rooms/_EventTile.scss @@ -733,4 +733,8 @@ $hover-select-border: 4px; padding-bottom: 5px; margin-bottom: 5px; } + + .mx_MessageComposer_sendMessage { + margin-right: 0; + } } diff --git a/res/css/views/rooms/_MessageComposer.scss b/res/css/views/rooms/_MessageComposer.scss index faa3171d67..9ba966c083 100644 --- a/res/css/views/rooms/_MessageComposer.scss +++ b/res/css/views/rooms/_MessageComposer.scss @@ -221,7 +221,8 @@ limitations under the License. border-radius: 50%; } - &:hover { + &:hover, + &.mx_MessageComposer_closeButtonMenu { &::after { background: rgba($accent-color, 0.1); } @@ -265,7 +266,6 @@ limitations under the License. .mx_MessageComposer_sendMessage { cursor: pointer; position: relative; - margin-right: 6px; width: 32px; height: 32px; border-radius: 100%; diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 6372ecc1f5..dd6ce10825 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -30,7 +30,6 @@ import SettingsStore from "../../../settings/SettingsStore"; import { aboveLeftOf, ContextMenu, - ContextMenuTooltipButton, useContextMenu, MenuItem, } from "../../structures/ContextMenu"; @@ -113,7 +112,7 @@ const EmojiButton: React.FC = ({ addEmoji, menuPosition, narr className={className} onClick={openMenu} title={!narrowMode && _t('Emoji picker')} - label={narrowMode && _t("Send an emoji")} + label={narrowMode && _t("Add emoji")} /> { contextMenu } From b5bed3297390091d3c1a6418a5274195e64d5ddb Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 9 Sep 2021 13:40:07 +0100 Subject: [PATCH 19/23] Fix i18n --- src/i18n/strings/en_EN.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a2262a6afa..f3ae9424e0 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1559,7 +1559,7 @@ "%(userName)s (power %(powerLevelNumber)s)": "%(userName)s (power %(powerLevelNumber)s)", "Send message": "Send message", "Emoji picker": "Emoji picker", - "Send an emoji": "Send an emoji", + "Add emoji": "Add emoji", "Upload file": "Upload file", "Reply to encrypted thread…": "Reply to encrypted thread…", "Reply to thread…": "Reply to thread…", @@ -1569,7 +1569,7 @@ "Send a message…": "Send a message…", "Hide Stickers": "Hide Stickers", "Show Stickers": "Show Stickers", - "Send an sticker": "Send an sticker", + "Send a sticker": "Send a sticker", "Send voice message": "Send voice message", "More options": "More options", "The conversation continues here.": "The conversation continues here.", From a4aa6dfcd744d40195e102c54f2831411873f491 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Sep 2021 15:58:19 +0100 Subject: [PATCH 20/23] Debounce read marker update on scroll Reverts https://github.com/matrix-org/matrix-react-sdk/pull/6751 in favour of debouncing the updates to read markers, because it seems allowing the scroll to be 1px away from the bottom was important for some browsers and meant they never got to the bottom. We can fix the problem instead by debouncing the update to read markers, because the scroll state gets reset back to the bottom when componentDidUpdate() runs which happens after the read marker code does a setState(). This should probably be debounced anyway since it doesn't need to be run that frequently. Fixes https://github.com/vector-im/element-web/issues/18961 Type: bugfix --- src/components/structures/ScrollPanel.tsx | 2 +- src/components/structures/TimelinePanel.tsx | 42 ++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/components/structures/ScrollPanel.tsx b/src/components/structures/ScrollPanel.tsx index abc71bfcb2..193553361d 100644 --- a/src/components/structures/ScrollPanel.tsx +++ b/src/components/structures/ScrollPanel.tsx @@ -276,7 +276,7 @@ export default class ScrollPanel extends React.Component { // for scrollTop happen on certain browsers/platforms // when scrolled all the way down. E.g. Chrome 72 on debian. // so check difference < 1; - return Math.abs(sn.scrollHeight - (sn.scrollTop + sn.clientHeight)) < 1; + return Math.abs(sn.scrollHeight - (sn.scrollTop + sn.clientHeight)) <= 1; }; // returns the vertical height in the given direction that can be removed from diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index e5fa6967dc..0dfb5c414a 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -47,11 +47,14 @@ import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks"; import Spinner from "../views/elements/Spinner"; import EditorStateTransfer from '../../utils/EditorStateTransfer'; import ErrorDialog from '../views/dialogs/ErrorDialog'; +import { debounce } from 'lodash'; const PAGINATE_SIZE = 20; const INITIAL_SIZE = 20; const READ_RECEIPT_INTERVAL_MS = 500; +const READ_MARKER_DEBOUNCE_MS = 100; + const DEBUG = false; let debuglog = function(...s: any[]) {}; @@ -475,22 +478,35 @@ class TimelinePanel extends React.Component { } if (this.props.manageReadMarkers) { - const rmPosition = this.getReadMarkerPosition(); - // we hide the read marker when it first comes onto the screen, but if - // it goes back off the top of the screen (presumably because the user - // clicks on the 'jump to bottom' button), we need to re-enable it. - if (rmPosition < 0) { - this.setState({ readMarkerVisible: true }); - } - - // if read marker position goes between 0 and -1/1, - // (and user is active), switch timeout - const timeout = this.readMarkerTimeout(rmPosition); - // NO-OP when timeout already has set to the given value - this.readMarkerActivityTimer.changeTimeout(timeout); + this.doManageReadMarkers(); } }; + /* + * Debounced function to manage read markers because we don't need to + * do this on every tiny scroll update. It also sets state which causes + * a component update, which can in turn reset the scroll position, so + * it's important we allow the browser to scroll a bit before running this + * (hence trailing edge only and debounce rather than throttle because + * we really only need to update this once the user has finished scrolling, + * not periodically while they scroll). + */ + private doManageReadMarkers = debounce(() => { + const rmPosition = this.getReadMarkerPosition(); + // we hide the read marker when it first comes onto the screen, but if + // it goes back off the top of the screen (presumably because the user + // clicks on the 'jump to bottom' button), we need to re-enable it. + if (rmPosition < 0) { + this.setState({ readMarkerVisible: true }); + } + + // if read marker position goes between 0 and -1/1, + // (and user is active), switch timeout + const timeout = this.readMarkerTimeout(rmPosition); + // NO-OP when timeout already has set to the given value + this.readMarkerActivityTimer.changeTimeout(timeout); + }, READ_MARKER_DEBOUNCE_MS, { leading: false, trailing: true }); + private onAction = (payload: ActionPayload): void => { switch (payload.action) { case "ignore_state_changed": From 672dab199866fd81f67cb7e77da39480647b7948 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 9 Sep 2021 17:31:05 +0100 Subject: [PATCH 21/23] Force refresh threads timeline Fixes vector-im/element-web#18947 In the absence of a proper pending events / remote echo setup it seems fairly difficult to get the timeline to update Adding a temporary helper to force refresh the timeline and not swallow local events when sending a message from the thread sidebar --- src/components/structures/ThreadView.tsx | 11 ++++++++--- src/components/structures/TimelinePanel.tsx | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 134f018aed..48e08f075f 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -50,6 +50,7 @@ interface IState { @replaceableComponent("structures.ThreadView") export default class ThreadView extends React.Component { private dispatcherRef: string; + private timelinePanelRef: React.RefObject = React.createRef(); constructor(props: IProps) { super(props); @@ -110,10 +111,13 @@ export default class ThreadView extends React.Component { private updateThread = (thread?: Thread) => { if (thread) { - this.setState({ thread }); - } else { - this.forceUpdate(); + this.setState({ + thread, + replyToEvent: thread.replyToEvent, + }); } + + this.timelinePanelRef.current?.refreshTimeline(); }; public render(): JSX.Element { @@ -126,6 +130,7 @@ export default class ThreadView extends React.Component { > { this.state.thread && ( { this.setState(this.getEvents()); } + // Force refresh the timeline before threads support pending events + public refreshTimeline(): void { + this.loadTimeline(); + this.reloadEvents(); + } + // get the list of events from the timeline window and the pending event list private getEvents(): Pick { const events: MatrixEvent[] = this.timelineWindow.getEvents(); From bd5d02d69076900bd46c2f735ba5b1b1670154e8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Sep 2021 18:15:51 +0100 Subject: [PATCH 22/23] Update comment too Co-authored-by: Travis Ralston --- src/components/structures/ScrollPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/ScrollPanel.tsx b/src/components/structures/ScrollPanel.tsx index 193553361d..112f8d2c21 100644 --- a/src/components/structures/ScrollPanel.tsx +++ b/src/components/structures/ScrollPanel.tsx @@ -275,7 +275,7 @@ export default class ScrollPanel extends React.Component { // fractional values (both too big and too small) // for scrollTop happen on certain browsers/platforms // when scrolled all the way down. E.g. Chrome 72 on debian. - // so check difference < 1; + // so check difference <= 1; return Math.abs(sn.scrollHeight - (sn.scrollTop + sn.clientHeight)) <= 1; }; From def1c68c16d02108b3deff2ebee9abb07fc91ed9 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Thu, 9 Sep 2021 16:11:36 -0400 Subject: [PATCH 23/23] Fix message bubble corners being wrong in the presence of hidden events Signed-off-by: Robin Townsend --- src/components/structures/MessagePanel.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/MessagePanel.tsx b/src/components/structures/MessagePanel.tsx index 7da0b75407..589947af73 100644 --- a/src/components/structures/MessagePanel.tsx +++ b/src/components/structures/MessagePanel.tsx @@ -705,9 +705,9 @@ export default class MessagePanel extends React.Component { let willWantDateSeparator = false; let lastInSection = true; - if (nextEvent) { - willWantDateSeparator = this.wantsDateSeparator(mxEv, nextEvent.getDate() || new Date()); - lastInSection = willWantDateSeparator || mxEv.getSender() !== nextEvent.getSender(); + if (nextEventWithTile) { + willWantDateSeparator = this.wantsDateSeparator(mxEv, nextEventWithTile.getDate() || new Date()); + lastInSection = willWantDateSeparator || mxEv.getSender() !== nextEventWithTile.getSender(); } // is this a continuation of the previous message?