1
0
Fork 0
forked from Mirrors/gomuks

web/statestore: flip decrypted content fields

This commit is contained in:
Tulir Asokan 2024-10-10 00:07:38 +03:00
parent ca13912b07
commit 1942fc464d
5 changed files with 17 additions and 11 deletions

View file

@ -18,6 +18,7 @@ import type {
ContentURI,
DBEvent,
DBRoom,
EncryptedEventContent,
EventID,
EventRowID,
EventType,
@ -82,6 +83,11 @@ export class RoomStateStore {
}
applyEvent(evt: DBEvent) {
if (evt.type === "m.room.encrypted" && evt.decrypted && evt.decrypted_type) {
evt.type = evt.decrypted_type
evt.encrypted = evt.content as EncryptedEventContent
evt.content = evt.decrypted
}
this.eventsByRowID.set(evt.rowid, evt)
this.eventsByID.set(evt.event_id, evt)
}

View file

@ -82,6 +82,14 @@ export interface DBRoom {
prev_batch: string
}
export interface EncryptedEventContent {
algorithm: "m.megolm.v1.aes-sha2"
ciphertext: string
session_id: string
sender_key?: string
device_id?: DeviceID
}
export interface DBEvent {
rowid: EventRowID
timeline_rowid: TimelineRowID
@ -96,6 +104,7 @@ export interface DBEvent {
content: unknown
decrypted?: unknown
decrypted_type?: EventType
encrypted?: EncryptedEventContent
unsigned: EventUnsigned
transaction_id?: string

View file

@ -26,12 +26,9 @@ function makePreviewText(evt?: DBEvent): string {
if (!evt) {
return ""
}
if (evt.type === "m.room.message") {
if (evt.type === "m.room.message" || evt.type === "m.sticker") {
// @ts-expect-error TODO add content types
return evt.content.body
} else if (evt.decrypted_type === "m.room.message") {
// @ts-expect-error TODO add content types
return evt.decrypted.body
}
return ""
}

View file

@ -28,12 +28,6 @@ export interface TimelineEventProps {
function getBodyType(evt: DBEvent): React.FunctionComponent<EventContentProps> {
switch (evt.type) {
case "m.room.encrypted":
switch (evt.decrypted_type) {
case "m.room.message":
return MessageBody
}
break
case "m.room.message":
return MessageBody
case "m.sticker":

View file

@ -60,7 +60,7 @@ interface LocationMessageEventContent extends BaseMessageEventContent {
type MessageEventContent = TextMessageEventContent | MediaMessageEventContent | LocationMessageEventContent
const MessageBody = ({ event }: EventContentProps) => {
const content = (event.decrypted ?? event.content) as MessageEventContent
const content = event.content as MessageEventContent
switch (content.msgtype) {
case "m.text":
case "m.emote":