xmpp: ALLOW SENDING MESSAGES
This commit is contained in:
@@ -16,11 +16,9 @@ class SetShowScrollToEndButtonAction {
|
||||
class SendMessageAction {
|
||||
final String body;
|
||||
final int timestamp;
|
||||
final String from;
|
||||
final String jid;
|
||||
final int cid;
|
||||
|
||||
SendMessageAction({ required this.from, required this.body, required this.timestamp, required this.jid, required this.cid });
|
||||
SendMessageAction({ required this.body, required this.timestamp, required this.jid });
|
||||
}
|
||||
|
||||
class ReceiveMessageAction {
|
||||
|
||||
@@ -6,10 +6,10 @@ import "package:moxxyv2/redux/conversation/actions.dart";
|
||||
|
||||
HashMap<String, List<Message>> messageReducer(HashMap<String, List<Message>> state, dynamic action) {
|
||||
if (action is AddMessageAction) {
|
||||
if (!state.containsKey(action.message.from)) {
|
||||
state[action.message.from] = List.from([ action.message ]);
|
||||
if (!state.containsKey(action.message.conversationJid)) {
|
||||
state[action.message.conversationJid] = List.from([ action.message ]);
|
||||
} else {
|
||||
state[action.message.from] = state[action.message.from]!..add(action.message);
|
||||
state[action.message.conversationJid] = state[action.message.conversationJid]!..add(action.message);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
@@ -5,6 +5,7 @@ import "package:moxxyv2/repositories/conversation.dart";
|
||||
import "package:moxxyv2/models/conversation.dart";
|
||||
import "package:moxxyv2/models/message.dart";
|
||||
import "package:moxxyv2/redux/messages/actions.dart";
|
||||
import "package:moxxyv2/xmpp/connection.dart";
|
||||
import "package:moxxyv2/helpers.dart";
|
||||
|
||||
import "package:redux/redux.dart";
|
||||
@@ -12,9 +13,8 @@ import "package:flutter_redux_navigation/flutter_redux_navigation.dart";
|
||||
import "package:get_it/get_it.dart";
|
||||
|
||||
void messageMiddleware(Store<MoxxyState> store, action, NextDispatcher next) async {
|
||||
final repo = GetIt.I.get<DatabaseRepository>();
|
||||
if (action is ReceiveMessageAction) {
|
||||
// TODO: Check if the conversation already exists
|
||||
final repo = GetIt.I.get<DatabaseRepository>();
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
final bareJidString = action.from.toBare().toString();
|
||||
|
||||
@@ -22,6 +22,7 @@ void messageMiddleware(Store<MoxxyState> store, action, NextDispatcher next) asy
|
||||
action.body,
|
||||
now,
|
||||
bareJidString,
|
||||
bareJidString,
|
||||
false
|
||||
);
|
||||
|
||||
@@ -30,7 +31,7 @@ void messageMiddleware(Store<MoxxyState> store, action, NextDispatcher next) asy
|
||||
final conversation = await repo.addConversationFromData(
|
||||
action.from.local,
|
||||
action.body,
|
||||
"",
|
||||
"", // TODO
|
||||
bareJidString,
|
||||
1,
|
||||
now,
|
||||
@@ -56,6 +57,17 @@ void messageMiddleware(Store<MoxxyState> store, action, NextDispatcher next) asy
|
||||
));
|
||||
}
|
||||
|
||||
store.dispatch(AddMessageAction(message: message));
|
||||
} else if (action is SendMessageAction) {
|
||||
final message = await repo.addMessageFromData(
|
||||
action.body,
|
||||
action.timestamp,
|
||||
"", // TODO
|
||||
action.jid,
|
||||
true
|
||||
);
|
||||
GetIt.I.get<XmppConnection>().sendMessage(action.body, action.jid);
|
||||
|
||||
store.dispatch(AddMessageAction(message: message));
|
||||
} else if (action is LoadMessagesAction) {
|
||||
GetIt.I.get<DatabaseRepository>().loadMessagesForJid(action.jid);
|
||||
|
||||
Reference in New Issue
Block a user