ui: (Kinda) make the last message text work
This commit is contained in:
parent
dae1b1d178
commit
262cf685b7
@ -5,4 +5,13 @@ class Conversation {
|
||||
final String 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -7,13 +7,13 @@ class ConversationRepository {
|
||||
// TODO: Remove
|
||||
"houshou.marine@hololive.tv": Conversation(
|
||||
title: "Houshou Marine",
|
||||
lastMessageBody: "UwU",
|
||||
lastMessageBody: "",
|
||||
avatarUrl: "https://vignette.wikia.nocookie.net/virtualyoutuber/images/4/4e/Houshou_Marine_-_Portrait.png/revision/latest?cb=20190821035347",
|
||||
jid: "houshou.marine@hololive.tv"
|
||||
),
|
||||
"nakiri.ayame@hololive.tv": Conversation(
|
||||
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",
|
||||
jid: "nakiri.ayame@hololive.tv"
|
||||
)
|
||||
|
@ -88,17 +88,19 @@ class _ConversationPageState extends State<ConversationPage> {
|
||||
var args = ModalRoute.of(context)!.settings.arguments as ConversationPageArguments;
|
||||
|
||||
Conversation conversation = GetIt.I.get<ConversationRepository>().getConversation(args.jid)!;
|
||||
String jid = conversation.jid;
|
||||
|
||||
return StoreConnector<MoxxyState, _MessageListViewModel>(
|
||||
converter: (store) => _MessageListViewModel(
|
||||
// TODO
|
||||
messages: store.state.messages.containsKey("") ? store.state.messages[""]! : [],
|
||||
messages: store.state.messages.containsKey(jid) ? store.state.messages[jid]! : [],
|
||||
sendMessage: (body) => store.dispatch(
|
||||
// TODO
|
||||
AddMessageAction(
|
||||
from: "UwU",
|
||||
timestamp: "12:00",
|
||||
body: body,
|
||||
jid: jid
|
||||
)
|
||||
)
|
||||
),
|
||||
|
@ -25,6 +25,8 @@ class NewConversationPage extends StatelessWidget {
|
||||
|
||||
if (conversation == null) {
|
||||
// TODO
|
||||
// TODO: Install a middleware to make sure that the conversation gets added to the
|
||||
// repository. Also handle updates
|
||||
conversation = Conversation(
|
||||
title: jid,
|
||||
jid: jid,
|
||||
|
@ -40,6 +40,7 @@ class ConversationsListRow extends StatelessWidget {
|
||||
this.name,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17),
|
||||
),
|
||||
// TODO: Change color, font size and truncate the text when too long
|
||||
Text(this.lastMessageBody)
|
||||
]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user