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.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
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";
|
2020-04-21 00:56:39 +05:30
|
|
|
import {LocationTile} from "./tiles/LocationTile.js";
|
|
|
|
import {RoomNameTile} from "./tiles/RoomNameTile.js";
|
|
|
|
import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
|
2020-08-17 21:11:57 +05:30
|
|
|
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
|
2019-03-09 00:34:56 +05:30
|
|
|
|
2020-08-19 13:58:09 +05:30
|
|
|
export function tilesCreator({room, ownUserId, clock}) {
|
2019-06-13 01:27:13 +05:30
|
|
|
return function tilesCreator(entry, emitUpdate) {
|
2020-08-20 19:10:43 +05:30
|
|
|
const options = {entry, emitUpdate, ownUserId, clock,
|
|
|
|
mediaRepository: room.mediaRepository};
|
2019-06-01 21:59:02 +05:30
|
|
|
if (entry.isGap) {
|
2020-03-22 04:10:40 +05:30
|
|
|
return new GapTile(options, room);
|
2019-07-29 13:57:12 +05:30
|
|
|
} else if (entry.eventType) {
|
|
|
|
switch (entry.eventType) {
|
2019-03-09 00:34:56 +05:30
|
|
|
case "m.room.message": {
|
2019-07-29 13:57:12 +05:30
|
|
|
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":
|
2020-08-20 19:10:43 +05:30
|
|
|
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);
|
2020-08-17 21:11:57 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|