forked from Henry-Hiles/nexus
working decryption
This commit is contained in:
parent
b55c990b24
commit
715bb15738
1 changed files with 12 additions and 14 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
import "dart:developer";
|
|
||||||
|
|
||||||
import "package:flutter_chat_core/flutter_chat_core.dart";
|
import "package:flutter_chat_core/flutter_chat_core.dart";
|
||||||
import "package:nexus/controllers/client_controller.dart";
|
import "package:nexus/controllers/client_controller.dart";
|
||||||
import "package:nexus/models/event.dart";
|
import "package:nexus/models/event.dart";
|
||||||
|
|
@ -31,17 +29,19 @@ extension EventToMessage on Event {
|
||||||
);
|
);
|
||||||
|
|
||||||
final author = await client.getProfile(event.authorId);
|
final author = await client.getProfile(event.authorId);
|
||||||
final newContent = event.content["m.new_content"] as Map?;
|
final content = (decrypted ?? this.content);
|
||||||
|
final type = (decryptedType ?? this.type);
|
||||||
|
final newContent = content["m.new_content"] as Map?;
|
||||||
final metadata = {
|
final metadata = {
|
||||||
"formatted":
|
"formatted":
|
||||||
newContent?["formatted_body"] ??
|
newContent?["formatted_body"] ??
|
||||||
newContent?["body"] ??
|
newContent?["body"] ??
|
||||||
event.content["formatted_body"] ??
|
content["formatted_body"] ??
|
||||||
event.content["body"] ??
|
content["body"] ??
|
||||||
"",
|
"",
|
||||||
"reply": await replyEvent?.toMessage(client, mustBeText: true),
|
"reply": await replyEvent?.toMessage(client, mustBeText: true),
|
||||||
"body": newContent?["body"] ?? event.content["body"],
|
"body": newContent?["body"] ?? content["body"],
|
||||||
"eventType": event.type,
|
"eventType": type,
|
||||||
"avatarUrl": author?.avatarUrl,
|
"avatarUrl": author?.avatarUrl,
|
||||||
"displayName": author?.displayName ?? authorId,
|
"displayName": author?.displayName ?? authorId,
|
||||||
"txnId": transactionId,
|
"txnId": transactionId,
|
||||||
|
|
@ -66,7 +66,7 @@ extension EventToMessage on Event {
|
||||||
id: eventId,
|
id: eventId,
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
text: redactedBy == null
|
text: redactedBy == null
|
||||||
? event.content["body"] ?? ""
|
? content["body"] ?? ""
|
||||||
: "This message has been deleted...",
|
: "This message has been deleted...",
|
||||||
replyToMessageId: replyId,
|
replyToMessageId: replyId,
|
||||||
deliveredAt: timestamp,
|
deliveredAt: timestamp,
|
||||||
|
|
@ -74,8 +74,6 @@ extension EventToMessage on Event {
|
||||||
)
|
)
|
||||||
as TextMessage;
|
as TextMessage;
|
||||||
|
|
||||||
final content = (decrypted ?? this.content);
|
|
||||||
|
|
||||||
if (mustBeText) return asText;
|
if (mustBeText) return asText;
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
"m.room.encrypted" => asText.copyWith(
|
"m.room.encrypted" => asText.copyWith(
|
||||||
|
|
@ -101,13 +99,13 @@ extension EventToMessage on Event {
|
||||||
source: "(await getAttachmentUri()).toString()", // TODO
|
source: "(await getAttachmentUri()).toString()", // TODO
|
||||||
replyToMessageId: replyId,
|
replyToMessageId: replyId,
|
||||||
deliveredAt: timestamp,
|
deliveredAt: timestamp,
|
||||||
blurhash: (event.content["info"] as Map?)?["xyz.amorgan.blurhash"],
|
blurhash: (content["info"] as Map?)?["xyz.amorgan.blurhash"],
|
||||||
),
|
),
|
||||||
"m.audio" => Message.audio(
|
"m.audio" => Message.audio(
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
id: eventId,
|
id: eventId,
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
text: event.content["body"],
|
text: content["body"],
|
||||||
replyToMessageId: replyId,
|
replyToMessageId: replyId,
|
||||||
source: "(await event.getAttachmentUri()).toString()", // TODO
|
source: "(await event.getAttachmentUri()).toString()", // TODO
|
||||||
deliveredAt: timestamp,
|
deliveredAt: timestamp,
|
||||||
|
|
@ -115,7 +113,7 @@ extension EventToMessage on Event {
|
||||||
duration: Duration(hours: 1),
|
duration: Duration(hours: 1),
|
||||||
),
|
),
|
||||||
"m.file" => Message.file(
|
"m.file" => Message.file(
|
||||||
name: event.content["filename"].toString(),
|
name: content["filename"].toString(),
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
id: eventId,
|
id: eventId,
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
|
|
@ -131,7 +129,7 @@ extension EventToMessage on Event {
|
||||||
authorId: authorId,
|
authorId: authorId,
|
||||||
deliveredAt: timestamp,
|
deliveredAt: timestamp,
|
||||||
text:
|
text:
|
||||||
"${content["displayname"] ?? event.stateKey} ${switch (event.content["membership"]) {
|
"${content["displayname"] ?? event.stateKey} ${switch (content["membership"]) {
|
||||||
"invite" => "was invited to",
|
"invite" => "was invited to",
|
||||||
"join" => "joined",
|
"join" => "joined",
|
||||||
"leave" => "left",
|
"leave" => "left",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue