vector-im-hydrogen-web/src/domain/session/room/timeline/tilesCreator.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-03-08 20:04:56 +01:00
import GapTile from "./tiles/GapTile.js";
import TextTile from "./tiles/TextTile.js";
import ImageTile from "./tiles/ImageTile.js";
2019-03-09 00:40:03 +01:00
import LocationTile from "./tiles/LocationTile.js";
2019-03-08 20:04:56 +01:00
import RoomNameTile from "./tiles/RoomNameTile.js";
import RoomMemberTile from "./tiles/RoomMemberTile.js";
2019-03-09 00:40:03 +01:00
export default function ({timeline, emitUpdate}) {
2019-03-08 20:04:56 +01:00
return function tilesCreator(entry) {
2019-03-09 00:40:03 +01:00
const options = {entry, emitUpdate};
2019-03-08 20:04:56 +01:00
if (entry.gap) {
2019-03-09 00:40:03 +01:00
return new GapTile(options, timeline);
2019-03-08 20:04:56 +01:00
} else if (entry.event) {
const event = entry.event;
switch (event.type) {
case "m.room.message": {
const content = event.content;
const msgtype = content && content.msgtype;
switch (msgtype) {
case "m.text":
2019-03-09 00:40:03 +01:00
case "m.notice":
return new TextTile(options);
2019-03-08 20:04:56 +01:00
case "m.image":
2019-03-09 00:40:03 +01:00
return new ImageTile(options);
case "m.location":
return new LocationTile(options);
2019-03-08 20:04:56 +01:00
default:
2019-03-09 00:40:03 +01:00
// unknown msgtype not rendered
return null;
2019-03-08 20:04:56 +01:00
}
}
case "m.room.name":
2019-03-09 00:40:03 +01:00
return new RoomNameTile(options);
2019-03-08 20:04:56 +01:00
case "m.room.member":
2019-03-09 00:40:03 +01:00
return new RoomMemberTile(options);
2019-03-08 20:04:56 +01:00
default:
2019-03-09 00:40:03 +01:00
// unknown type not rendered
2019-03-08 20:04:56 +01:00
return null;
}
}
}
}