/* Copyright 2020 Bruno Windels 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 {GapTile} from "./tiles/GapTile.js"; import {TextTile} from "./tiles/TextTile.js"; import {ImageTile} from "./tiles/ImageTile.js"; import {LocationTile} from "./tiles/LocationTile.js"; import {RoomNameTile} from "./tiles/RoomNameTile.js"; import {RoomMemberTile} from "./tiles/RoomMemberTile.js"; export function tilesCreator({room, ownUserId}) { return function tilesCreator(entry, emitUpdate) { const options = {entry, emitUpdate, ownUserId}; if (entry.isGap) { return new GapTile(options, room); } else if (entry.eventType) { switch (entry.eventType) { case "m.room.message": { const content = entry.content; const msgtype = content && content.msgtype; switch (msgtype) { case "m.text": case "m.notice": case "m.emote": return new TextTile(options); case "m.image": return new ImageTile(options, room); case "m.location": return new LocationTile(options); default: // unknown msgtype not rendered return null; } } case "m.room.name": return new RoomNameTile(options); case "m.room.member": return new RoomMemberTile(options); default: // unknown type not rendered return null; } } } }