This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/domain/session/room/timeline/tilesCreator.js

63 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-08-05 22:08:55 +05:30
/*
Copyright 2020 Bruno Windels <bruno@windels.cloud>
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";
2020-05-09 23:32:08 +05:30
import {ImageTile} from "./tiles/ImageTile.js";
import {LocationTile} from "./tiles/LocationTile.js";
import {RoomNameTile} from "./tiles/RoomNameTile.js";
import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
2019-03-09 00:34:56 +05:30
export function tilesCreator({room, ownUserId, clock}) {
return function tilesCreator(entry, emitUpdate) {
const options = {entry, emitUpdate, ownUserId, clock,
mediaRepository: room.mediaRepository};
if (entry.isGap) {
2020-03-22 04:10:40 +05:30
return new GapTile(options, room);
} else if (entry.eventType) {
switch (entry.eventType) {
2019-03-09 00:34:56 +05:30
case "m.room.message": {
const content = entry.content;
2019-03-09 00:34:56 +05:30
const msgtype = content && content.msgtype;
switch (msgtype) {
case "m.text":
2019-03-09 05:10:03 +05:30
case "m.notice":
2019-06-01 22:02:17 +05:30
case "m.emote":
2019-03-09 05:10:03 +05:30
return new TextTile(options);
2019-03-09 00:34:56 +05:30
case "m.image":
return new ImageTile(options);
2019-03-09 05:10:03 +05:30
case "m.location":
return new LocationTile(options);
2019-03-09 00:34:56 +05:30
default:
2019-03-09 05:10:03 +05:30
// unknown msgtype not rendered
return null;
2019-03-09 00:34:56 +05:30
}
}
case "m.room.name":
2019-03-09 05:10:03 +05:30
return new RoomNameTile(options);
2019-03-09 00:34:56 +05:30
case "m.room.member":
2019-03-09 05:10:03 +05:30
return new RoomMemberTile(options);
case "m.room.encrypted":
return new EncryptedEventTile(options);
2019-03-09 00:34:56 +05:30
default:
2019-03-09 05:10:03 +05:30
// unknown type not rendered
2019-03-09 00:34:56 +05:30
return null;
}
}
}
}