ui: (Kinda) make the last message text work

This commit is contained in:
2021-12-23 17:19:24 +01:00
parent dae1b1d178
commit 262cf685b7
8 changed files with 32 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ class AddMessageAction extends MessageAction {
final String body;
final String timestamp;
final String from;
final String jid;
AddMessageAction({ required this.from, required this.body, required this.timestamp });
AddMessageAction({ required this.from, required this.body, required this.timestamp, required this.jid });
}

View File

@@ -14,14 +14,13 @@ HashMap<String, List<Message>> messageReducer(HashMap<String, List<Message>> sta
sent: true
);
// TODO
if (!map.containsKey("")) {
map[""] = [ msg ];
String jid = action.jid;
if (!map.containsKey(jid)) {
map[jid] = [ msg ];
return map;
}
// TODO
map[""]!.add(msg);
map[jid]!.add(msg);
return map;
}

View File

@@ -1,5 +1,6 @@
import "package:moxxyv2/models/conversation.dart";
import "package:moxxyv2/redux/conversations/actions.dart";
import "package:moxxyv2/redux/conversation/actions.dart";
List<Conversation> conversationReducer(List<Conversation> state, dynamic action) {
if (action is AddConversationAction) {
@@ -9,6 +10,14 @@ List<Conversation> conversationReducer(List<Conversation> state, dynamic action)
avatarUrl: action.avatarUrl,
jid: action.jid
));
} else if (action is AddMessageAction) {
return state.map((element) {
if (element.jid == action.jid) {
return element.copyWith(lastMessageBody: action.body);
}
return element;
}).toList();
}
return state;