db: FINALLY ADD A DATABASE
This commit is contained in:
@@ -16,6 +16,7 @@ class AddMessageAction {
|
||||
final int timestamp;
|
||||
final String from;
|
||||
final String jid;
|
||||
final int cid;
|
||||
|
||||
AddMessageAction({ required this.from, required this.body, required this.timestamp, required this.jid });
|
||||
AddMessageAction({ required this.from, required this.body, required this.timestamp, required this.jid, required this.cid });
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@ class AddConversationAction {
|
||||
final String lastMessageBody;
|
||||
final String avatarUrl;
|
||||
final String jid;
|
||||
final int id;
|
||||
final int unreadCounter;
|
||||
final List<String> sharedMediaPaths;
|
||||
final int lastChangeTimestamp;
|
||||
final bool triggeredByDatabase;
|
||||
|
||||
AddConversationAction({ required this.title, required this.lastMessageBody, required this.avatarUrl, required this.jid, required this.sharedMediaPaths, required this.lastChangeTimestamp });
|
||||
AddConversationAction({ required this.title, required this.lastMessageBody, required this.avatarUrl, required this.jid, required this.sharedMediaPaths, required this.lastChangeTimestamp, required this.id, this.unreadCounter = 0, this.triggeredByDatabase = false });
|
||||
}
|
||||
|
||||
28
lib/redux/conversations/middlewares.dart
Normal file
28
lib/redux/conversations/middlewares.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import "package:moxxyv2/redux/state.dart";
|
||||
import "package:moxxyv2/redux/conversations/actions.dart";
|
||||
import "package:moxxyv2/redux/conversation/actions.dart";
|
||||
import "package:moxxyv2/repositories/conversation.dart";
|
||||
|
||||
import "package:redux/redux.dart";
|
||||
import "package:get_it/get_it.dart";
|
||||
|
||||
void conversationsMiddleware(Store<MoxxyState> store, action, NextDispatcher next) {
|
||||
var repo = GetIt.I.get<DatabaseRepository>();
|
||||
|
||||
if (action is AddConversationAction && !action.triggeredByDatabase) {
|
||||
if (repo.hasConversation(action.id)) {
|
||||
// TODO
|
||||
} else {
|
||||
repo.addConversationFromAction(action);
|
||||
}
|
||||
} else if (action is AddMessageAction) {
|
||||
if (repo.hasConversation(action.cid)) {
|
||||
repo.updateConversation(id: action.cid, lastMessageBody: action.body, lastChangeTimestamp: action.timestamp);
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
next(action);
|
||||
}
|
||||
@@ -13,7 +13,8 @@ List<Conversation> conversationReducer(List<Conversation> state, dynamic action)
|
||||
// TODO: Correct?
|
||||
unreadCounter: 0,
|
||||
sharedMediaPaths: action.sharedMediaPaths,
|
||||
lastChangeTimestamp: action.lastChangeTimestamp
|
||||
lastChangeTimestamp: action.lastChangeTimestamp,
|
||||
id: action.id
|
||||
));
|
||||
} else if (action is AddMessageAction) {
|
||||
return state.map((element) {
|
||||
|
||||
Reference in New Issue
Block a user