From 846c14062a424544d1aa9345c85778c17c6ba92f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 13 Jun 2018 09:28:35 +0100 Subject: [PATCH 1/2] show redacted stickers like other redacted messages Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/messages/MessageEvent.js | 3 ++- src/components/views/rooms/EventTile.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/views/messages/MessageEvent.js b/src/components/views/messages/MessageEvent.js index 38f55c9d70..babe1bbf29 100644 --- a/src/components/views/messages/MessageEvent.js +++ b/src/components/views/messages/MessageEvent.js @@ -69,7 +69,8 @@ module.exports = React.createClass({ if (msgtype && bodyTypes[msgtype]) { BodyType = bodyTypes[msgtype]; } else if (this.props.mxEvent.getType() === 'm.sticker') { - BodyType = sdk.getComponent('messages.MStickerBody'); + // if sticker is redacted, show UnknownBody otherwise it'll fall through to elif + BodyType = this.props.mxEvent.isRedacted() ? UnknownBody : sdk.getComponent('messages.MStickerBody'); } else if (content.url) { // Fallback to MFileBody if there's a content URL BodyType = bodyTypes['m.file']; diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index 589524bb9e..c43ddaad11 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -490,7 +490,7 @@ module.exports = withMatrixClient(React.createClass({ } const isSending = (['sending', 'queued', 'encrypting'].indexOf(this.props.eventSendStatus) !== -1); - const isRedacted = (eventType === 'm.room.message') && this.props.isRedacted; + const isRedacted = isMessageEvent(this.props.mxEvent) && this.props.isRedacted; const isEncryptionFailure = this.props.mxEvent.isDecryptionFailure(); const classes = classNames({ @@ -715,9 +715,15 @@ module.exports = withMatrixClient(React.createClass({ }, })); +// XXX this'll eventually be dynamic based on the fields once we have extensible event types +const messageTypes = ['m.room.message', 'm.sticker']; +function isMessageEvent(ev) { + return (messageTypes.includes(ev.getType())); +} + module.exports.haveTileForEvent = function(e) { // Only messages have a tile (black-rectangle) if redacted - if (e.isRedacted() && e.getType() !== 'm.room.message') return false; + if (e.isRedacted() && !isMessageEvent(e)) return false; const handler = getHandlerTile(e); if (handler === undefined) return false; From 20caea47f81aaa46ae04d9408b15da5b28374aa8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 13 Jun 2018 09:32:21 +0100 Subject: [PATCH 2/2] make more generic Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/messages/MessageEvent.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/views/messages/MessageEvent.js b/src/components/views/messages/MessageEvent.js index babe1bbf29..c4d29257ff 100644 --- a/src/components/views/messages/MessageEvent.js +++ b/src/components/views/messages/MessageEvent.js @@ -62,18 +62,24 @@ module.exports = React.createClass({ 'm.audio': sdk.getComponent('messages.MAudioBody'), 'm.video': sdk.getComponent('messages.MVideoBody'), }; + const evTypes = { + 'm.sticker': sdk.getComponent('messages.MStickerBody'), + }; const content = this.props.mxEvent.getContent(); + const type = this.props.mxEvent.getType(); const msgtype = content.msgtype; let BodyType = UnknownBody; - if (msgtype && bodyTypes[msgtype]) { - BodyType = bodyTypes[msgtype]; - } else if (this.props.mxEvent.getType() === 'm.sticker') { - // if sticker is redacted, show UnknownBody otherwise it'll fall through to elif - BodyType = this.props.mxEvent.isRedacted() ? UnknownBody : sdk.getComponent('messages.MStickerBody'); - } else if (content.url) { - // Fallback to MFileBody if there's a content URL - BodyType = bodyTypes['m.file']; + if (!this.props.mxEvent.isRedacted()) { + // only resolve BodyType if event is not redacted + if (msgtype && bodyTypes[msgtype]) { + BodyType = bodyTypes[msgtype]; + } else if (type && evTypes[type]) { + BodyType = evTypes[type]; + } else if (content.url) { + // Fallback to MFileBody if there's a content URL + BodyType = bodyTypes['m.file']; + } } return