diff --git a/public/config.json b/public/config.json index 29999d465e948119597049ed719822bb1ff0b6d0..38a792efa84a4292b91e4a9950d79940f0b13ba6 100644 --- a/public/config.json +++ b/public/config.json @@ -7,5 +7,6 @@ "avatar": "https://i.imgur.com/KkSYCKB.png" }, "token": "k9SL1R~GcdbjiFjC", - "invite_user": "@botuser:matrix.midhun.dev" + "invite_user": "@botuser:matrix.midhun.dev", + "encrypt_room": true } diff --git a/src/types/IChatterboxConfig.ts b/src/types/IChatterboxConfig.ts index a3d8d2bbed03de52ad658cb78fa017a3c65d41b6..6fab8eeb4f382a8e90f2a3c7f540db121dd09c05 100644 --- a/src/types/IChatterboxConfig.ts +++ b/src/types/IChatterboxConfig.ts @@ -7,6 +7,8 @@ export interface IChatterboxConfig { // If specified, chatterbox will create a dm with this user // This option takes precedence over 'auto_join_room' invite_user: string; + // If set to true, the room created for DM is encrypted + encrypt_room: boolean; // Configurations for header on chatterbox (containing title, avatar, minimize button) header: IHeader; // Token needed for token-authenticated registration diff --git a/src/viewmodels/ChatterboxViewModel.ts b/src/viewmodels/ChatterboxViewModel.ts index 1cea7c1bfef4a5fb144b2237eb62339ff48a3fef..af2de40fb1827fa761eb0a6f6f492da2289feeac 100644 --- a/src/viewmodels/ChatterboxViewModel.ts +++ b/src/viewmodels/ChatterboxViewModel.ts @@ -46,7 +46,7 @@ export class ChatterboxViewModel extends ViewModel { type: 1, //todo: use enum from hydrogen-sdk here name: undefined, topic: undefined, - isEncrypted: false, + isEncrypted: this._options.config["encrypt_room"] ?? false, isFederationDisabled: false, alias: undefined, avatar: undefined, diff --git a/src/viewmodels/tiles.ts b/src/viewmodels/tiles.ts index aad096ee8d7ba60171ae341f6856cb7bd54bfc14..b91ae0222db2b298798b5adc7d7a4c856990b3e8 100644 --- a/src/viewmodels/tiles.ts +++ b/src/viewmodels/tiles.ts @@ -1,5 +1,6 @@ -import { TextTile, ImageTile, VideoTile, FileTile, LocationTile, RedactedTile, tileClassForEntry } from "hydrogen-view-sdk"; +import { TextTile, ImageTile, VideoTile, FileTile, LocationTile, RedactedTile, EncryptionEnabledTile, tileClassForEntry } from "hydrogen-view-sdk"; +// Override all the message-tiles to show the display name as "me" class ChatterboxTextTile extends TextTile { get displayName() { return this.isOwn? "me" : super.displayName; @@ -36,6 +37,13 @@ class ChatterboxRedactedTile extends RedactedTile { } } +// We don't want to show the (long and random) user-id in this announcement! +class ChatterboxEncryptionEnabledTile extends EncryptionEnabledTile { + get announcement() { + return this.i18n`This room is end-to-end encrypted 🔒`; + } +} + export function createCustomTileClassForEntry(ownUserId: string) { return function customTileClassForEntry(entry) { switch (entry.eventType) { @@ -69,6 +77,8 @@ export function createCustomTileClassForEntry(ownUserId: string) { else { return undefined; } + case "m.room.encryption": + return ChatterboxEncryptionEnabledTile; default: return tileClassForEntry(entry);