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.
|
|
|
|
*/
|
|
|
|
|
2020-04-20 21:26:39 +02:00
|
|
|
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";
|
2020-04-20 21:26:39 +02:00
|
|
|
import {LocationTile} from "./tiles/LocationTile.js";
|
|
|
|
import {RoomNameTile} from "./tiles/RoomNameTile.js";
|
|
|
|
import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
|
2020-08-17 17:41:57 +02:00
|
|
|
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
|
2020-09-14 15:44:07 +02:00
|
|
|
import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js";
|
2020-11-19 14:42:29 +01:00
|
|
|
import {MissingAttachmentTile} from "./tiles/MissingAttachmentTile.js";
|
2019-03-08 20:04:56 +01:00
|
|
|
|
2020-10-28 17:37:45 +01:00
|
|
|
export function tilesCreator(baseOptions) {
|
2019-06-12 21:57:13 +02:00
|
|
|
return function tilesCreator(entry, emitUpdate) {
|
2020-10-28 17:37:45 +01:00
|
|
|
const options = Object.assign({entry, emitUpdate}, baseOptions);
|
2019-06-01 18:29:02 +02:00
|
|
|
if (entry.isGap) {
|
2020-10-28 17:37:45 +01:00
|
|
|
return new GapTile(options);
|
2020-11-19 14:42:29 +01:00
|
|
|
} else if (entry.isPending && entry.pendingEvent.isMissingAttachments) {
|
|
|
|
return new MissingAttachmentTile(options);
|
2019-07-29 10:27:12 +02:00
|
|
|
} else if (entry.eventType) {
|
|
|
|
switch (entry.eventType) {
|
2019-03-08 20:04:56 +01:00
|
|
|
case "m.room.message": {
|
2019-07-29 10:27:12 +02:00
|
|
|
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":
|
2020-08-20 15:40:43 +02:00
|
|
|
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);
|
2020-08-17 17:41:57 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|