ui: (Kinda) make the last message text work

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

View File

@ -5,4 +5,13 @@ class Conversation {
final String jid; final String jid;
const Conversation({ required this.title, required this.lastMessageBody, required this.avatarUrl, required this.jid }); const Conversation({ required this.title, required this.lastMessageBody, required this.avatarUrl, required this.jid });
Conversation copyWith({ String? lastMessageBody }) {
return Conversation(
title: this.title,
lastMessageBody: lastMessageBody ?? this.lastMessageBody,
avatarUrl: this.avatarUrl,
jid: this.jid
);
}
} }

View File

@ -4,6 +4,7 @@ class AddMessageAction extends MessageAction {
final String body; final String body;
final String timestamp; final String timestamp;
final String from; 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 sent: true
); );
// TODO String jid = action.jid;
if (!map.containsKey("")) { if (!map.containsKey(jid)) {
map[""] = [ msg ]; map[jid] = [ msg ];
return map; return map;
} }
// TODO map[jid]!.add(msg);
map[""]!.add(msg);
return map; return map;
} }

View File

@ -1,5 +1,6 @@
import "package:moxxyv2/models/conversation.dart"; import "package:moxxyv2/models/conversation.dart";
import "package:moxxyv2/redux/conversations/actions.dart"; import "package:moxxyv2/redux/conversations/actions.dart";
import "package:moxxyv2/redux/conversation/actions.dart";
List<Conversation> conversationReducer(List<Conversation> state, dynamic action) { List<Conversation> conversationReducer(List<Conversation> state, dynamic action) {
if (action is AddConversationAction) { if (action is AddConversationAction) {
@ -9,6 +10,14 @@ List<Conversation> conversationReducer(List<Conversation> state, dynamic action)
avatarUrl: action.avatarUrl, avatarUrl: action.avatarUrl,
jid: action.jid 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; return state;

View File

@ -7,13 +7,13 @@ class ConversationRepository {
// TODO: Remove // TODO: Remove
"houshou.marine@hololive.tv": Conversation( "houshou.marine@hololive.tv": Conversation(
title: "Houshou Marine", title: "Houshou Marine",
lastMessageBody: "UwU", lastMessageBody: "",
avatarUrl: "https://vignette.wikia.nocookie.net/virtualyoutuber/images/4/4e/Houshou_Marine_-_Portrait.png/revision/latest?cb=20190821035347", avatarUrl: "https://vignette.wikia.nocookie.net/virtualyoutuber/images/4/4e/Houshou_Marine_-_Portrait.png/revision/latest?cb=20190821035347",
jid: "houshou.marine@hololive.tv" jid: "houshou.marine@hololive.tv"
), ),
"nakiri.ayame@hololive.tv": Conversation( "nakiri.ayame@hololive.tv": Conversation(
title: "Nakiri Ayame", title: "Nakiri Ayame",
lastMessageBody: "Yodayo~", lastMessageBody: "",
avatarUrl: "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fi.pinimg.com%2Foriginals%2F2a%2F77%2F0a%2F2a770a77b0d873331583dfb88b05829f.jpg&f=1&nofb=1", avatarUrl: "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fi.pinimg.com%2Foriginals%2F2a%2F77%2F0a%2F2a770a77b0d873331583dfb88b05829f.jpg&f=1&nofb=1",
jid: "nakiri.ayame@hololive.tv" jid: "nakiri.ayame@hololive.tv"
) )

View File

@ -88,17 +88,19 @@ class _ConversationPageState extends State<ConversationPage> {
var args = ModalRoute.of(context)!.settings.arguments as ConversationPageArguments; var args = ModalRoute.of(context)!.settings.arguments as ConversationPageArguments;
Conversation conversation = GetIt.I.get<ConversationRepository>().getConversation(args.jid)!; Conversation conversation = GetIt.I.get<ConversationRepository>().getConversation(args.jid)!;
String jid = conversation.jid;
return StoreConnector<MoxxyState, _MessageListViewModel>( return StoreConnector<MoxxyState, _MessageListViewModel>(
converter: (store) => _MessageListViewModel( converter: (store) => _MessageListViewModel(
// TODO // TODO
messages: store.state.messages.containsKey("") ? store.state.messages[""]! : [], messages: store.state.messages.containsKey(jid) ? store.state.messages[jid]! : [],
sendMessage: (body) => store.dispatch( sendMessage: (body) => store.dispatch(
// TODO // TODO
AddMessageAction( AddMessageAction(
from: "UwU", from: "UwU",
timestamp: "12:00", timestamp: "12:00",
body: body, body: body,
jid: jid
) )
) )
), ),

View File

@ -25,6 +25,8 @@ class NewConversationPage extends StatelessWidget {
if (conversation == null) { if (conversation == null) {
// TODO // TODO
// TODO: Install a middleware to make sure that the conversation gets added to the
// repository. Also handle updates
conversation = Conversation( conversation = Conversation(
title: jid, title: jid,
jid: jid, jid: jid,

View File

@ -40,6 +40,7 @@ class ConversationsListRow extends StatelessWidget {
this.name, this.name,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17),
), ),
// TODO: Change color, font size and truncate the text when too long
Text(this.lastMessageBody) Text(this.lastMessageBody)
] ]
) )