working edits

This commit is contained in:
Henry Hiles 2026-01-06 11:20:17 -05:00
commit f9f4a4b48e
No known key found for this signature in database
4 changed files with 19 additions and 5 deletions

View file

@ -40,7 +40,16 @@ class RoomChatController extends AsyncNotifier<ChatController> {
if (oldMessage == null || message == null) return; if (oldMessage == null || message == null) return;
return await updateMessage( return await updateMessage(
oldMessage, oldMessage,
message.copyWith(id: oldMessage.id), message.copyWith(
id: oldMessage.id,
replyToMessageId: oldMessage.replyToMessageId,
metadata: {
...(oldMessage.metadata ?? {}),
...((message.metadata ?? {}).filterMap(
(key, value) => value == null ? null : MapEntry(key, value),
)),
},
),
); );
} }
if (message != null) { if (message != null) {
@ -119,8 +128,9 @@ class RoomChatController extends AsyncNotifier<ChatController> {
await room.sendTextEvent( await room.sendTextEvent(
taggedMessage, taggedMessage,
editEventId: relationType == RelationType.edit ? relation?.id : null, editEventId: relationType == RelationType.edit ? relation?.id : null,
inReplyTo: (relationType == RelationType.reply && relation != null) displayPendingEvent: relationType != RelationType.edit,
? await room.getEventById(relation.id) inReplyTo: (relationType == RelationType.reply)
? await room.getEventById(relation!.id)
: null, : null,
); );
} }

View file

@ -9,7 +9,6 @@ extension EventToMessage on Event {
bool includeEdits = false, bool includeEdits = false,
}) async { }) async {
final replyId = inReplyToEventId(); final replyId = inReplyToEventId();
final newEvent = (unsigned?["m.relations"] as Map?)?["m.replace"]; final newEvent = (unsigned?["m.relations"] as Map?)?["m.replace"];
final event = newEvent == null ? this : Event.fromJson(newEvent, room); final event = newEvent == null ? this : Event.fromJson(newEvent, room);

View file

@ -35,9 +35,13 @@ class ChatBox extends HookConsumerWidget {
relatedMessage is TextMessage && relatedMessage is TextMessage &&
controller.value.text.isEmpty) { controller.value.text.isEmpty) {
final text = (relatedMessage as TextMessage).text; final text = (relatedMessage as TextMessage).text;
controller.value.text = relatedMessage?.replyToMessageId == null final splitText = relatedMessage?.replyToMessageId == null
? text ? text
: text.split("\n\n").sublist(1).join("\n\n"); : text.split("\n\n").sublist(1).join("\n\n");
final notEmpty = splitText.isEmpty ? text : splitText;
controller.value.text = notEmpty.startsWith("* ")
? notEmpty.substring(2)
: notEmpty;
} }
void send() { void send() {

View file

@ -67,6 +67,7 @@ class RoomChat extends HookConsumerWidget {
title: Text("Reply"), title: Text("Reply"),
), ),
), ),
// Should check if is state event (has state_key), if so, don't show edit option
if (message.authorId == room.roomData.client.userID) if (message.authorId == room.roomData.client.userID)
PopupMenuItem( PopupMenuItem(
onTap: () { onTap: () {