ui: Re-implement the new conversation page
This commit is contained in:
parent
0f872908eb
commit
255d0ef8ea
@ -441,6 +441,50 @@ void handleEvent(Map<String, dynamic>? data) {
|
||||
GetIt.I.get<PreferencesService>().modifyPreferences((prefs) => command.preferences);
|
||||
}
|
||||
break;
|
||||
case addConversationActionType: {
|
||||
final command = AddConversationAction.fromJson(data);
|
||||
final database = GetIt.I.get<DatabaseService>();
|
||||
|
||||
(() async {
|
||||
final conversation = await database.getConversationByJid(command.jid);
|
||||
if (conversation != null) {
|
||||
if (!conversation.open) {
|
||||
final newConv = await database.updateConversation(
|
||||
id: conversation.id,
|
||||
open: true
|
||||
);
|
||||
final event = ConversationCreatedEvent(conversation: newConv);
|
||||
|
||||
GetIt.I.get<Logger>().fine("S2F: " + event.toString());
|
||||
FlutterBackgroundService().sendData(event.toJson());
|
||||
}
|
||||
|
||||
final doneEvent = NewConversationDoneEvent(jid: command.jid);
|
||||
GetIt.I.get<Logger>().fine("S2F: " + doneEvent.toString());
|
||||
FlutterBackgroundService().sendData(doneEvent.toJson());
|
||||
} else {
|
||||
final conversation = await database.addConversationFromData(
|
||||
command.title,
|
||||
command.lastMessageBody,
|
||||
command.avatarUrl,
|
||||
command.jid,
|
||||
0,
|
||||
-1,
|
||||
const [],
|
||||
true
|
||||
);
|
||||
|
||||
final createEvent = ConversationCreatedEvent(conversation: conversation);
|
||||
GetIt.I.get<Logger>().fine("S2F: " + createEvent.toString());
|
||||
FlutterBackgroundService().sendData(createEvent.toJson());
|
||||
|
||||
final event = NewConversationDoneEvent(jid: command.jid);
|
||||
GetIt.I.get<Logger>().fine("S2F: " + event.toString());
|
||||
FlutterBackgroundService().sendData(event.toJson());
|
||||
}
|
||||
})();
|
||||
}
|
||||
break;
|
||||
case stopActionType: {
|
||||
FlutterBackgroundService().stopBackgroundService();
|
||||
}
|
||||
|
@ -108,6 +108,37 @@ class RemoveRosterItemAction extends BaseIsolateCommand {
|
||||
};
|
||||
}
|
||||
|
||||
const addConversationActionType = "AddConversationAction";
|
||||
class AddConversationAction extends BaseIsolateCommand {
|
||||
final String jid;
|
||||
final String title;
|
||||
final String avatarUrl;
|
||||
final String lastMessageBody;
|
||||
|
||||
AddConversationAction({
|
||||
required this.jid,
|
||||
required this.title,
|
||||
required this.avatarUrl,
|
||||
required this.lastMessageBody
|
||||
});
|
||||
AddConversationAction.fromJson(Map<String, dynamic> json) :
|
||||
jid = json["jid"]!,
|
||||
title = json["title"]!,
|
||||
avatarUrl = json["avatarUrl"]!,
|
||||
lastMessageBody = json["lastMessageBody"]! {
|
||||
assert(json["type"] == addToRosterType);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {
|
||||
"type": addConversationActionType,
|
||||
"jid": jid,
|
||||
"title": title,
|
||||
"avatarUrl": avatarUrl,
|
||||
"lastMessageBody": lastMessageBody
|
||||
};
|
||||
}
|
||||
|
||||
const sendMessageActionType = "SendMessageAction";
|
||||
class SendMessageAction extends BaseIsolateCommand {
|
||||
final String jid;
|
||||
|
@ -292,3 +292,20 @@ class DownloadProgressEvent extends BaseIsolateEvent {
|
||||
"progress": progress
|
||||
};
|
||||
}
|
||||
|
||||
const newConversationDoneEventType = "NewConversationDoneEvent";
|
||||
class NewConversationDoneEvent extends BaseIsolateEvent {
|
||||
final String jid;
|
||||
|
||||
NewConversationDoneEvent({ required this.jid });
|
||||
NewConversationDoneEvent.fromJson(Map<String, dynamic> json) :
|
||||
jid = json["jid"]! {
|
||||
assert(json["type"] == newConversationDoneEventType);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {
|
||||
"type": newConversationDoneEventType,
|
||||
"jid": jid
|
||||
};
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ import "package:moxxyv2/ui/redux/account/state.dart";
|
||||
import "package:moxxyv2/ui/redux/account/actions.dart";
|
||||
import "package:moxxyv2/ui/redux/debug/actions.dart";
|
||||
import "package:moxxyv2/ui/redux/preferences/actions.dart";
|
||||
import "package:moxxyv2/ui/pages/conversation/arguments.dart";
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
import "package:get_it/get_it.dart";
|
||||
import "package:flutter_background_service/flutter_background_service.dart";
|
||||
import "package:redux/redux.dart";
|
||||
@ -51,6 +53,7 @@ void handleBackgroundServiceData(Map<String, dynamic>? data) {
|
||||
if (event.permissionsToRequest.isNotEmpty) {
|
||||
(() async {
|
||||
for (final perm in event.permissionsToRequest) {
|
||||
// TODO: Use the function that requests multiple permissions at once
|
||||
await Permission.byValue(perm).request();
|
||||
}
|
||||
})();
|
||||
@ -162,5 +165,20 @@ void handleBackgroundServiceData(Map<String, dynamic>? data) {
|
||||
GetIt.I.get<UIDownloadService>().onProgress(event.id, event.progress);
|
||||
}
|
||||
break;
|
||||
case events.newConversationDoneEventType: {
|
||||
final event = events.NewConversationDoneEvent.fromJson(data);
|
||||
|
||||
FlutterBackgroundService().sendData(
|
||||
commands.LoadMessagesForJidAction(jid: event.jid).toJson()
|
||||
);
|
||||
|
||||
store.dispatch(NavigateToAction.pushNamedAndRemoveUntil(
|
||||
conversationRoute,
|
||||
ModalRoute.withName(conversationsRoute),
|
||||
arguments: ConversationPageArguments(jid: event.jid)
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,39 @@
|
||||
import "package:moxxyv2/ui/constants.dart";
|
||||
import "package:moxxyv2/shared/commands.dart" as commands;
|
||||
import "package:moxxyv2/ui/redux/state.dart";
|
||||
import "package:moxxyv2/ui/redux/conversation/actions.dart";
|
||||
import "package:moxxyv2/ui/pages/conversation/arguments.dart";
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
import "package:redux/redux.dart";
|
||||
import "package:flutter_background_service/flutter_background_service.dart";
|
||||
import "package:flutter_redux_navigation/flutter_redux_navigation.dart";
|
||||
|
||||
void conversationsMiddleware(Store<MoxxyState> store, action, NextDispatcher next) async {
|
||||
// TODO: I think this all has to go
|
||||
if (action is AddConversationFromUIAction) {
|
||||
// TODO: Notify the backend
|
||||
} else if (action is CloseConversationAction) {
|
||||
// TODO: Notify the backend
|
||||
final jid = action.jid;
|
||||
if (store.state.conversations.containsKey(jid)) {
|
||||
// Just go there
|
||||
FlutterBackgroundService().sendData(
|
||||
commands.LoadMessagesForJidAction(jid: jid).toJson()
|
||||
);
|
||||
|
||||
store.dispatch(NavigateToAction.pushNamedAndRemoveUntil(
|
||||
conversationRoute,
|
||||
ModalRoute.withName(conversationsRoute),
|
||||
arguments: ConversationPageArguments(jid: jid)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
FlutterBackgroundService().sendData(
|
||||
commands.AddConversationAction(
|
||||
jid: action.jid,
|
||||
title: action.title,
|
||||
avatarUrl: action.avatarUrl,
|
||||
lastMessageBody: action.lastMessageBody
|
||||
).toJson()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
|
Loading…
Reference in New Issue
Block a user