From 549d9922930cea689faebc1ca3cba7d2032146ba Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 21 Oct 2015 17:50:40 +0100 Subject: [PATCH] API change: Make EventTiles which hold stuff common to all events that appear in a room timeline. --- src/controllers/molecules/EventTile.js | 28 ++++++++++++++++++++++++ src/controllers/molecules/MessageTile.js | 11 ---------- src/controllers/organisms/RoomView.js | 20 +++++++---------- 3 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 src/controllers/molecules/EventTile.js diff --git a/src/controllers/molecules/EventTile.js b/src/controllers/molecules/EventTile.js new file mode 100644 index 0000000000..953e33b516 --- /dev/null +++ b/src/controllers/molecules/EventTile.js @@ -0,0 +1,28 @@ +/* +Copyright 2015 OpenMarket Ltd + +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. +*/ + +'use strict'; + +var MatrixClientPeg = require("../../MatrixClientPeg"); + +module.exports = { + shouldHighlight: function() { + var actions = MatrixClientPeg.get().getPushActionsForEvent(this.props.mxEvent); + if (!actions || !actions.tweaks) { return false; } + return actions.tweaks.highlight; + } +}; + diff --git a/src/controllers/molecules/MessageTile.js b/src/controllers/molecules/MessageTile.js index 4a7ce7e1df..7f3416d6db 100644 --- a/src/controllers/molecules/MessageTile.js +++ b/src/controllers/molecules/MessageTile.js @@ -19,16 +19,5 @@ limitations under the License. var MatrixClientPeg = require("../../MatrixClientPeg"); module.exports = { - shouldHighlight: function() { - var actions = MatrixClientPeg.get().getPushActionsForEvent(this.props.mxEvent); - if (!actions || !actions.tweaks) { return false; } - return actions.tweaks.highlight; - }, - - getInitialState: function() { - return { - resending: false - }; - } }; diff --git a/src/controllers/organisms/RoomView.js b/src/controllers/organisms/RoomView.js index 8ca2d7233b..931dbb5bcb 100644 --- a/src/controllers/organisms/RoomView.js +++ b/src/controllers/organisms/RoomView.js @@ -316,21 +316,18 @@ module.exports = { }, getEventTiles: function() { - var tileTypes = { - 'm.room.message': sdk.getComponent('molecules.MessageTile'), - 'm.room.member' : sdk.getComponent('molecules.EventAsTextTile'), - 'm.call.invite' : sdk.getComponent('molecules.EventAsTextTile'), - 'm.call.answer' : sdk.getComponent('molecules.EventAsTextTile'), - 'm.call.hangup' : sdk.getComponent('molecules.EventAsTextTile'), - 'm.room.topic' : sdk.getComponent('molecules.EventAsTextTile'), - }; - var ret = []; var count = 0; + var EventTile = sdk.getComponent('molecules.EventTile'); + for (var i = this.state.room.timeline.length-1; i >= 0 && count < this.state.messageCap; --i) { var mxEv = this.state.room.timeline[i]; - var TileType = tileTypes[mxEv.getType()]; + + if (!EventTile.supportsEventType(mxEv.getType())) { + continue; + } + var continuation = false; var last = false; if (i == this.state.room.timeline.length - 1) { @@ -348,9 +345,8 @@ module.exports = { continuation = true; } } - if (!TileType) continue; ret.unshift( -
  • +
  • ); ++count; }