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

68 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-08-05 18:38:55 +02:00
/*
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 20:02:08 +02:00
import {ImageTile} from "./tiles/ImageTile.js";
2020-11-10 17:50:53 +01:00
import {FileTile} from "./tiles/FileTile.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";
2020-09-14 15:44:07 +02:00
import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js";
2019-03-08 20:04:56 +01:00
export function tilesCreator(baseOptions) {
return function tilesCreator(entry, emitUpdate) {
const options = Object.assign({entry, emitUpdate}, baseOptions);
if (entry.isGap) {
return new GapTile(options);
} else if (entry.eventType) {
switch (entry.eventType) {
2019-03-08 20:04:56 +01:00
case "m.room.message": {
const content = entry.content;
2019-03-08 20:04:56 +01:00
const msgtype = content && content.msgtype;
switch (msgtype) {
case "m.text":
2019-03-09 00:40:03 +01:00
case "m.notice":
2019-06-01 18:32:17 +02:00
case "m.emote":
2019-03-09 00:40:03 +01:00
return new TextTile(options);
2019-03-08 20:04:56 +01:00
case "m.image":
return new ImageTile(options);
2020-11-10 17:50:53 +01:00
case "m.file":
return new FileTile(options);
2019-03-09 00:40:03 +01:00
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);
case "m.room.encrypted":
return new EncryptedEventTile(options);
2020-09-14 15:44:07 +02:00
case "m.room.encryption":
return new EncryptionEnabledTile(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;
}
}
}
}