forked from Henry-Hiles/nexus
dont fail to parse on invalid reply
This commit is contained in:
parent
95d3d2c0b9
commit
4087d6ca11
1 changed files with 190 additions and 181 deletions
|
|
@ -14,6 +14,7 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Message?> build() async {
|
Future<Message?> build() async {
|
||||||
|
try {
|
||||||
if (config.event.relationType == "m.replace" && !config.includeEdits) {
|
if (config.event.relationType == "m.replace" && !config.includeEdits) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -31,9 +32,9 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
config.event.content["m.relates_to"]?["m.in_reply_to"]?["event_id"];
|
config.event.content["m.relates_to"]?["m.in_reply_to"]?["event_id"];
|
||||||
final replyEvent = replyId == null
|
final replyEvent = replyId == null
|
||||||
? null
|
? null
|
||||||
: await client.getEvent(
|
: await client
|
||||||
GetEventRequest(room: config.room, eventId: replyId),
|
.getEvent(GetEventRequest(room: config.room, eventId: replyId))
|
||||||
);
|
.onError((_, _) => null);
|
||||||
|
|
||||||
if (!ref.mounted) return null;
|
if (!ref.mounted) return null;
|
||||||
|
|
||||||
|
|
@ -47,7 +48,9 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
final type = (config.event.decryptedType ?? config.event.type);
|
final type = (config.event.decryptedType ?? config.event.type);
|
||||||
final newContent = content["m.new_content"] as Map?;
|
final newContent = content["m.new_content"] as Map?;
|
||||||
|
|
||||||
final homeserver = ref.read(ClientStateController.provider)?.homeserverUrl;
|
final homeserver = ref
|
||||||
|
.read(ClientStateController.provider)
|
||||||
|
?.homeserverUrl;
|
||||||
final source = homeserver == null || content["url"] == null
|
final source = homeserver == null || content["url"] == null
|
||||||
? "null"
|
? "null"
|
||||||
: Uri.parse(content["url"]).mxcToHttps(homeserver).toString();
|
: Uri.parse(content["url"]).mxcToHttps(homeserver).toString();
|
||||||
|
|
@ -83,10 +86,13 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
|
|
||||||
if (!ref.mounted) return null;
|
if (!ref.mounted) return null;
|
||||||
|
|
||||||
final editedAt = event.relationType == "m.replace" ? event.timestamp : null;
|
final editedAt = event.relationType == "m.replace"
|
||||||
|
? event.timestamp
|
||||||
|
: null;
|
||||||
|
|
||||||
if ((event.redactedBy != null && !config.alwaysReturn) ||
|
if ((event.redactedBy != null && !config.alwaysReturn) ||
|
||||||
(!config.includeEdits && (config.event.relationType == "m.replace"))) {
|
(!config.includeEdits &&
|
||||||
|
(config.event.relationType == "m.replace"))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +136,7 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
// ),
|
// ),
|
||||||
("m.sticker" || "m.room.message") => switch (content["msgtype"]) {
|
("m.sticker" || "m.room.message") => switch (content["msgtype"]) {
|
||||||
null || "m.image" => Message.image(
|
null || "m.image" => Message.image(
|
||||||
id: "${config.event.eventId}-image",
|
id: config.event.eventId,
|
||||||
authorId: event.authorId,
|
authorId: event.authorId,
|
||||||
source: source,
|
source: source,
|
||||||
replyToMessageId: replyId,
|
replyToMessageId: replyId,
|
||||||
|
|
@ -205,6 +211,9 @@ class MessageController extends AsyncNotifier<Message?> {
|
||||||
)
|
)
|
||||||
: null),
|
: null),
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider = AsyncNotifierProvider.family
|
static final provider = AsyncNotifierProvider.family
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue