ui: (Kinda) make the last message text work
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user