From e79ad34fbd91e799d3347fab1fc89b0ddc00b76b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 13 Apr 2021 09:34:37 +0100 Subject: [PATCH 1/2] EventTile make use of EventType enum Removes m.room.encryption from non-state list as it makes no sense --- src/components/views/rooms/EventTile.js | 58 ++++++++++++------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index d51f4c00f1..901a231e7d 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -1,8 +1,6 @@ /* -Copyright 2015, 2016 OpenMarket Ltd -Copyright 2017 New Vector Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> -Copyright 2019, 2020 The Matrix.org Foundation C.I.C. +Copyright 2019 - 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. @@ -17,18 +15,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -import ReplyThread from "../elements/ReplyThread"; import React, {createRef} from 'react'; import PropTypes from 'prop-types'; import classNames from "classnames"; import {EventType} from "matrix-js-sdk/src/@types/event"; +import {EventStatus} from 'matrix-js-sdk/src/models/event'; + +import ReplyThread from "../elements/ReplyThread"; import { _t } from '../../../languageHandler'; import * as TextForEvent from "../../../TextForEvent"; import * as sdk from "../../../index"; import dis from '../../../dispatcher/dispatcher'; import SettingsStore from "../../../settings/SettingsStore"; import {Layout, LayoutPropType} from "../../../settings/Layout"; -import {EventStatus} from 'matrix-js-sdk/src/models/event'; import {formatTime} from "../../../DateUtils"; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import {ALL_RULE_TYPES} from "../../../mjolnir/BanList"; @@ -43,37 +42,36 @@ import {replaceableComponent} from "../../../utils/replaceableComponent"; import Tooltip from "../elements/Tooltip"; const eventTileTypes = { - 'm.room.message': 'messages.MessageEvent', - 'm.sticker': 'messages.MessageEvent', - 'm.key.verification.cancel': 'messages.MKeyVerificationConclusion', - 'm.key.verification.done': 'messages.MKeyVerificationConclusion', - 'm.room.encryption': 'messages.EncryptionEvent', - 'm.call.invite': 'messages.TextualEvent', - 'm.call.answer': 'messages.TextualEvent', - 'm.call.hangup': 'messages.TextualEvent', - 'm.call.reject': 'messages.TextualEvent', + [EventType.RoomMessage]: 'messages.MessageEvent', + [EventType.Sticker]: 'messages.MessageEvent', + [EventType.KeyVerificationCancel]: 'messages.MKeyVerificationConclusion', + [EventType.KeyVerificationDone]: 'messages.MKeyVerificationConclusion', + [EventType.CallInvite]: 'messages.TextualEvent', + [EventType.CallAnswer]: 'messages.TextualEvent', + [EventType.CallHangup]: 'messages.TextualEvent', + [EventType.CallReject]: 'messages.TextualEvent', }; const stateEventTileTypes = { - 'm.room.encryption': 'messages.EncryptionEvent', - 'm.room.canonical_alias': 'messages.TextualEvent', - 'm.room.create': 'messages.RoomCreate', - 'm.room.member': 'messages.TextualEvent', - 'm.room.name': 'messages.TextualEvent', - 'm.room.avatar': 'messages.RoomAvatarEvent', - 'm.room.third_party_invite': 'messages.TextualEvent', - 'm.room.history_visibility': 'messages.TextualEvent', - 'm.room.topic': 'messages.TextualEvent', - 'm.room.power_levels': 'messages.TextualEvent', - 'm.room.pinned_events': 'messages.TextualEvent', - 'm.room.server_acl': 'messages.TextualEvent', + [EventType.RoomEncryption]: 'messages.EncryptionEvent', + [EventType.RoomCanonicalAlias]: 'messages.TextualEvent', + [EventType.RoomCreate]: 'messages.RoomCreate', + [EventType.RoomMember]: 'messages.TextualEvent', + [EventType.RoomName]: 'messages.TextualEvent', + [EventType.RoomAvatar]: 'messages.RoomAvatarEvent', + [EventType.RoomThirdPartyInvite]: 'messages.TextualEvent', + [EventType.RoomHistoryVisibility]: 'messages.TextualEvent', + [EventType.RoomTopic]: 'messages.TextualEvent', + [EventType.RoomPowerLevels]: 'messages.TextualEvent', + [EventType.RoomPinnedEvents]: 'messages.TextualEvent', + [EventType.RoomServerAcl]: 'messages.TextualEvent', // TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111) 'im.vector.modular.widgets': 'messages.TextualEvent', [WIDGET_LAYOUT_EVENT_TYPE]: 'messages.TextualEvent', - 'm.room.tombstone': 'messages.TextualEvent', - 'm.room.join_rules': 'messages.TextualEvent', - 'm.room.guest_access': 'messages.TextualEvent', - 'm.room.related_groups': 'messages.TextualEvent', + [EventType.RoomTombstone]: 'messages.TextualEvent', + [EventType.RoomJoinRules]: 'messages.TextualEvent', + [EventType.RoomGuestAccess]: 'messages.TextualEvent', + 'm.room.related_groups': 'messages.TextualEvent', // legacy communities flair }; // Add all the Mjolnir stuff to the renderer From c25df51534353ebd9c78b1f2a1d8e545fc13b00d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 13 Apr 2021 09:40:44 +0100 Subject: [PATCH 2/2] Prevent state events being rendered with invalid state keys --- src/components/views/rooms/EventTile.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index 901a231e7d..46c5caa926 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -74,6 +74,24 @@ const stateEventTileTypes = { 'm.room.related_groups': 'messages.TextualEvent', // legacy communities flair }; +const stateEventSingular = new Set([ + EventType.RoomEncryption, + EventType.RoomCanonicalAlias, + EventType.RoomCreate, + EventType.RoomName, + EventType.RoomAvatar, + EventType.RoomHistoryVisibility, + EventType.RoomTopic, + EventType.RoomPowerLevels, + EventType.RoomPinnedEvents, + EventType.RoomServerAcl, + WIDGET_LAYOUT_EVENT_TYPE, + EventType.RoomTombstone, + EventType.RoomJoinRules, + EventType.RoomGuestAccess, + 'm.room.related_groups', +]); + // Add all the Mjolnir stuff to the renderer for (const evType of ALL_RULE_TYPES) { stateEventTileTypes[evType] = 'messages.TextualEvent'; @@ -130,7 +148,12 @@ export function getHandlerTile(ev) { } } - return ev.isState() ? stateEventTileTypes[type] : eventTileTypes[type]; + if (ev.isState()) { + if (stateEventSingular.has(type) && ev.getStateKey() !== "") return undefined; + return stateEventTileTypes[type]; + } + + return eventTileTypes[type]; } const MAX_READ_AVATARS = 5;