From ebe19168c26fb43c20738004836a3b858e203d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 10:39:45 +0200 Subject: [PATCH 01/10] Add allowClose to payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/dispatcher/payloads/SetRightPanelPhasePayload.ts | 5 +++++ src/stores/RightPanelStore.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/payloads/SetRightPanelPhasePayload.ts b/src/dispatcher/payloads/SetRightPanelPhasePayload.ts index a4dcb8cfe1..ea997e4ed1 100644 --- a/src/dispatcher/payloads/SetRightPanelPhasePayload.ts +++ b/src/dispatcher/payloads/SetRightPanelPhasePayload.ts @@ -27,6 +27,11 @@ export interface SetRightPanelPhasePayload extends ActionPayload { phase: RightPanelPhases; refireParams?: SetRightPanelPhaseRefireParams; + + /** + * By default SetRightPanelPhase can close the panel, this allows overriding that behaviour + */ + allowClose?: boolean; } export interface SetRightPanelPhaseRefireParams { diff --git a/src/stores/RightPanelStore.ts b/src/stores/RightPanelStore.ts index c539fcdb40..2bad0572b1 100644 --- a/src/stores/RightPanelStore.ts +++ b/src/stores/RightPanelStore.ts @@ -161,6 +161,7 @@ export default class RightPanelStore extends Store { case Action.SetRightPanelPhase: { let targetPhase = payload.phase; let refireParams = payload.refireParams; + const allowClose = payload.allowClose ?? true; // redirect to EncryptionPanel if there is an ongoing verification request if (targetPhase === RightPanelPhases.RoomMemberInfo && payload.refireParams) { const {member} = payload.refireParams; @@ -192,7 +193,7 @@ export default class RightPanelStore extends Store { }); } } else { - if (targetPhase === this.state.lastRoomPhase && !refireParams) { + if (targetPhase === this.state.lastRoomPhase && !refireParams && allowClose) { this.setState({ showRoomPanel: !this.state.showRoomPanel, previousPhase: null, From 8d47ea63c2aeb2e31798d10dfd7d430da878fa8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 10:40:30 +0200 Subject: [PATCH 02/10] Make pinned message text clickable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- res/css/views/messages/_TextualEvent.scss | 5 ++++ src/{TextForEvent.ts => TextForEvent.tsx} | 34 ++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) rename src/{TextForEvent.ts => TextForEvent.tsx} (96%) diff --git a/res/css/views/messages/_TextualEvent.scss b/res/css/views/messages/_TextualEvent.scss index be7565b3c5..e87fed90de 100644 --- a/res/css/views/messages/_TextualEvent.scss +++ b/res/css/views/messages/_TextualEvent.scss @@ -17,4 +17,9 @@ limitations under the License. .mx_TextualEvent { opacity: 0.5; overflow-y: hidden; + + a { + color: $accent-color; + cursor: pointer; + } } diff --git a/src/TextForEvent.ts b/src/TextForEvent.tsx similarity index 96% rename from src/TextForEvent.ts rename to src/TextForEvent.tsx index 649c53664e..ee9bd53250 100644 --- a/src/TextForEvent.ts +++ b/src/TextForEvent.tsx @@ -13,6 +13,8 @@ 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 {MatrixClientPeg} from './MatrixClientPeg'; import { _t } from './languageHandler'; import * as Roles from './Roles'; @@ -20,6 +22,10 @@ import {isValid3pidInvite} from "./RoomInvite"; import SettingsStore from "./settings/SettingsStore"; import {ALL_RULE_TYPES, ROOM_RULE_TYPES, SERVER_RULE_TYPES, USER_RULE_TYPES} from "./mjolnir/BanList"; import {WIDGET_LAYOUT_EVENT_TYPE} from "./stores/widgets/WidgetLayoutStore"; +import { RightPanelPhases } from './stores/RightPanelStorePhases'; +import { Action } from './dispatcher/actions'; +import defaultDispatcher from './dispatcher/dispatcher'; +import { SetRightPanelPhasePayload } from './dispatcher/payloads/SetRightPanelPhasePayload'; // These functions are frequently used just to check whether an event has // any text to display at all. For this reason they return deferred values @@ -466,9 +472,29 @@ function textForPowerEvent(event): () => string | null { }); } -function textForPinnedEvent(event): () => string | null { +function textForPinnedEvent(event): () => JSX.Element | null { + if (!SettingsStore.getValue("feature_pinning")) return null; + const senderName = event.sender ? event.sender.name : event.getSender(); - return () => _t("%(senderName)s changed the pinned messages for the room.", {senderName}); + const onPinnedMessagesClick = () => { + defaultDispatcher.dispatch({ + action: Action.SetRightPanelPhase, + phase: RightPanelPhases.PinnedMessages, + allowClose: false, + }); + } + + return () => ( + + { + _t( + "%(senderName)s changed the pinned messages for the room.", + { senderName }, + { "a": (sub) => { sub } }, + ) + } + + ); } function textForWidgetEvent(event): () => string | null { @@ -594,7 +620,7 @@ function textForMjolnirEvent(event): () => string | null { } interface IHandlers { - [type: string]: (ev: any) => (() => string | null); + [type: string]: (ev: any) => (() => string | JSX.Element | null); } const handlers: IHandlers = { @@ -635,7 +661,7 @@ export function hasText(ev): boolean { return Boolean(handler?.(ev)); } -export function textForEvent(ev): string { +export function textForEvent(ev): string | JSX.Element { const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; return handler?.(ev)?.() || ''; } From 7eb36426926f3310de0ede9f65e7e6a0782205a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 10:40:35 +0200 Subject: [PATCH 03/10] i18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7751c2eb32..c092c2b592 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -558,7 +558,7 @@ "%(senderName)s made future room history visible to unknown (%(visibility)s).": "%(senderName)s made future room history visible to unknown (%(visibility)s).", "%(senderName)s changed the power level of %(powerLevelDiffText)s.": "%(senderName)s changed the power level of %(powerLevelDiffText)s.", "%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s": "%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s", - "%(senderName)s changed the pinned messages for the room.": "%(senderName)s changed the pinned messages for the room.", + "%(senderName)s changed the pinned messages for the room.": "%(senderName)s changed the pinned messages for the room.", "%(widgetName)s widget modified by %(senderName)s": "%(widgetName)s widget modified by %(senderName)s", "%(widgetName)s widget added by %(senderName)s": "%(widgetName)s widget added by %(senderName)s", "%(widgetName)s widget removed by %(senderName)s": "%(widgetName)s widget removed by %(senderName)s", From a8b2c6d36b490b2a0453954dde8b5f37f8b7e10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 12:24:42 +0200 Subject: [PATCH 04/10] Type event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TextForEvent.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index ee9bd53250..b7e9deda8d 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -26,6 +26,7 @@ import { RightPanelPhases } from './stores/RightPanelStorePhases'; import { Action } from './dispatcher/actions'; import defaultDispatcher from './dispatcher/dispatcher'; import { SetRightPanelPhasePayload } from './dispatcher/payloads/SetRightPanelPhasePayload'; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; // These functions are frequently used just to check whether an event has // any text to display at all. For this reason they return deferred values @@ -472,7 +473,7 @@ function textForPowerEvent(event): () => string | null { }); } -function textForPinnedEvent(event): () => JSX.Element | null { +function textForPinnedEvent(event: MatrixEvent): () => JSX.Element | null { if (!SettingsStore.getValue("feature_pinning")) return null; const senderName = event.sender ? event.sender.name : event.getSender(); From 6333d4aa364717715df59823093dd74e10df9d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 14:02:06 +0200 Subject: [PATCH 05/10] Iterate PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TextForEvent.tsx | 53 +++++++++++-------- src/components/views/messages/TextualEvent.js | 2 +- src/i18n/strings/en_EN.json | 1 + 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index b7e9deda8d..50bdae8ca9 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -473,29 +473,36 @@ function textForPowerEvent(event): () => string | null { }); } -function textForPinnedEvent(event: MatrixEvent): () => JSX.Element | null { +function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string | JSX.Element | null { if (!SettingsStore.getValue("feature_pinning")) return null; - const senderName = event.sender ? event.sender.name : event.getSender(); - const onPinnedMessagesClick = () => { - defaultDispatcher.dispatch({ - action: Action.SetRightPanelPhase, - phase: RightPanelPhases.PinnedMessages, - allowClose: false, - }); - } - return () => ( - - { - _t( - "%(senderName)s changed the pinned messages for the room.", - { senderName }, - { "a": (sub) => { sub } }, - ) - } - - ); + if (allowJSX) { + const onPinnedMessagesClick = () => { + defaultDispatcher.dispatch({ + action: Action.SetRightPanelPhase, + phase: RightPanelPhases.PinnedMessages, + allowClose: false, + }); + } + + return () => ( + + { + _t( + "%(senderName)s changed the pinned messages for the room.", + { senderName }, + { "a": (sub) => { sub } }, + ) + } + + ); + } else { + return () => _t( + "%(senderName)s changed the pinned messages for the room.", + { senderName }, + ); + } } function textForWidgetEvent(event): () => string | null { @@ -621,7 +628,7 @@ function textForMjolnirEvent(event): () => string | null { } interface IHandlers { - [type: string]: (ev: any) => (() => string | JSX.Element | null); + [type: string]: (ev: MatrixEvent, allowJSX?: boolean) => (() => string | JSX.Element | null); } const handlers: IHandlers = { @@ -662,7 +669,7 @@ export function hasText(ev): boolean { return Boolean(handler?.(ev)); } -export function textForEvent(ev): string | JSX.Element { +export function textForEvent(ev: MatrixEvent, allowJSX = false): string | JSX.Element { const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; - return handler?.(ev)?.() || ''; + return handler?.(ev, allowJSX)?.() || ''; } diff --git a/src/components/views/messages/TextualEvent.js b/src/components/views/messages/TextualEvent.js index a020cc6c52..25da18da0d 100644 --- a/src/components/views/messages/TextualEvent.js +++ b/src/components/views/messages/TextualEvent.js @@ -28,7 +28,7 @@ export default class TextualEvent extends React.Component { }; render() { - const text = TextForEvent.textForEvent(this.props.mxEvent); + const text = TextForEvent.textForEvent(this.props.mxEvent, true); if (text == null || text.length === 0) return null; return (
{ text }
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c092c2b592..73bf948778 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -559,6 +559,7 @@ "%(senderName)s changed the power level of %(powerLevelDiffText)s.": "%(senderName)s changed the power level of %(powerLevelDiffText)s.", "%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s": "%(userId)s from %(fromPowerLevel)s to %(toPowerLevel)s", "%(senderName)s changed the pinned messages for the room.": "%(senderName)s changed the pinned messages for the room.", + "%(senderName)s changed the pinned messages for the room.": "%(senderName)s changed the pinned messages for the room.", "%(widgetName)s widget modified by %(senderName)s": "%(widgetName)s widget modified by %(senderName)s", "%(widgetName)s widget added by %(senderName)s": "%(widgetName)s widget added by %(senderName)s", "%(widgetName)s widget removed by %(senderName)s": "%(widgetName)s widget removed by %(senderName)s", From 0542c69b66686b3c28eba20861a013230b579dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 14:13:27 +0200 Subject: [PATCH 06/10] Fix types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/Notifier.ts | 2 +- src/TextForEvent.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Notifier.ts b/src/Notifier.ts index 4f55046e72..2afc7d9901 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -68,7 +68,7 @@ export const Notifier = { // or not pendingEncryptedEventIds: [], - notificationMessageForEvent: function(ev: MatrixEvent) { + notificationMessageForEvent: function(ev: MatrixEvent): string { if (typehandlers.hasOwnProperty(ev.getContent().msgtype)) { return typehandlers[ev.getContent().msgtype](ev); } diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 50bdae8ca9..4c2c264439 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -669,6 +669,7 @@ export function hasText(ev): boolean { return Boolean(handler?.(ev)); } +export function textForEvent(ev: MatrixEvent): string export function textForEvent(ev: MatrixEvent, allowJSX = false): string | JSX.Element { const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; return handler?.(ev, allowJSX)?.() || ''; From e436e28f01dcbc4bdc7290d99f0394b7a64e5eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 14:31:04 +0200 Subject: [PATCH 07/10] Make TS happy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TextForEvent.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 4c2c264439..10c787bcb6 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -669,7 +669,8 @@ export function hasText(ev): boolean { return Boolean(handler?.(ev)); } -export function textForEvent(ev: MatrixEvent): string +export function textForEvent(ev: MatrixEvent): string; +export function textForEvent(ev: MatrixEvent, allowJSX: true): string | JSX.Element; export function textForEvent(ev: MatrixEvent, allowJSX = false): string | JSX.Element { const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; return handler?.(ev, allowJSX)?.() || ''; From cc1f68296e84885a18a48828bbe7fc277744c53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 16:58:56 +0200 Subject: [PATCH 08/10] Iterate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TextForEvent.tsx | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 10c787bcb6..4721e13cec 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -473,19 +473,19 @@ function textForPowerEvent(event): () => string | null { }); } +const onPinnedMessagesClick = (): void => { + defaultDispatcher.dispatch({ + action: Action.SetRightPanelPhase, + phase: RightPanelPhases.PinnedMessages, + allowClose: false, + }); +} + function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string | JSX.Element | null { if (!SettingsStore.getValue("feature_pinning")) return null; const senderName = event.sender ? event.sender.name : event.getSender(); if (allowJSX) { - const onPinnedMessagesClick = () => { - defaultDispatcher.dispatch({ - action: Action.SetRightPanelPhase, - phase: RightPanelPhases.PinnedMessages, - allowClose: false, - }); - } - return () => ( { @@ -498,10 +498,7 @@ function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string ); } else { - return () => _t( - "%(senderName)s changed the pinned messages for the room.", - { senderName }, - ); + return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName }); } } From e282c4aa54cf15d160ab2da00493d7e4309e3ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 17:23:42 +0200 Subject: [PATCH 09/10] Simplifie code Co-authored-by: Michael Telatynski <7t3chguy@googlemail.com> --- src/TextForEvent.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 038c69ac15..ea669d4050 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -510,9 +510,9 @@ function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string } ); - } else { - return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName }); } + + return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName }); } function textForWidgetEvent(event): () => string | null { From ff11244de82c8459399d94bb300ba1bb53a167f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 24 Jun 2021 17:27:53 +0200 Subject: [PATCH 10/10] Trailing spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/TextForEvent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index ea669d4050..def0ac2cb8 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -511,7 +511,7 @@ function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string ); } - + return () => _t("%(senderName)s changed the pinned messages for the room.", { senderName }); }