1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Can update conversation settings

This commit is contained in:
Pierre HUBERT 2021-03-13 11:08:08 +01:00
parent fdec22c28a
commit 0b2f939376
3 changed files with 19 additions and 38 deletions

View File

@ -41,7 +41,7 @@ class ConversationsHelper {
"name": settings.name ?? "", "name": settings.name ?? "",
"follow": settings.follow ? "true" : "false", "follow": settings.follow ? "true" : "false",
"users": settings.members.join(","), "users": settings.members.join(","),
"color": colorToHex(settings.color) ?? "," "color": colorToHex(settings.color)
}) })
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers) .addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers)
.execWithThrow(); .execWithThrow();
@ -80,7 +80,8 @@ class ConversationsHelper {
/// Update an existing conversation /// Update an existing conversation
/// ///
/// Throws in case of failure /// Throws in case of failure
Future<void> updateConversation(NewConversationsSettings settings) async { static Future<void> updateConversation(
NewConversationsSettings settings) async {
final request = APIRequest.withLogin("conversations/updateSettings") final request = APIRequest.withLogin("conversations/updateSettings")
.addInt("conversationID", settings.convID) .addInt("conversationID", settings.convID)
.addBool("following", settings.following); .addBool("following", settings.following);
@ -90,7 +91,7 @@ class ConversationsHelper {
request request
.addString("name", settings.name ?? "") .addString("name", settings.name ?? "")
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers) .addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers)
.addString("color", settings.color ?? ""); .addString("color", colorToHex(settings.color));
await request.execWithThrow(); await request.execWithThrow();

View File

@ -10,7 +10,7 @@ class NewConversationsSettings {
final bool isComplete; final bool isComplete;
final String name; final String name;
final bool canEveryoneAddMembers; final bool canEveryoneAddMembers;
final String color; final Color color;
const NewConversationsSettings({ const NewConversationsSettings({
@required this.convID, @required this.convID,
@ -23,5 +23,5 @@ class NewConversationsSettings {
assert(convID > 0), assert(convID > 0),
assert(following != null), assert(following != null),
assert(isComplete != null), assert(isComplete != null),
assert(!isComplete && canEveryoneAddMembers != null); assert(!isComplete || canEveryoneAddMembers != null);
} }

View File

@ -3,6 +3,7 @@ import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart'; import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/new_conversation.dart'; import 'package:comunic/models/new_conversation.dart';
import 'package:comunic/models/new_conversation_settings.dart';
import 'package:comunic/models/user.dart'; import 'package:comunic/models/user.dart';
import 'package:comunic/ui/dialogs/color_picker_dialog.dart'; import 'package:comunic/ui/dialogs/color_picker_dialog.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart';
@ -85,6 +86,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
_admins = _conversation.adminsID; _admins = _conversation.adminsID;
_followConversation = _conversation.following; _followConversation = _conversation.following;
_canEveryoneAddMembers = _conversation.canEveryoneAddMembers; _canEveryoneAddMembers = _conversation.canEveryoneAddMembers;
setState(() {});
} }
@override @override
@ -289,45 +292,22 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
MainController.of(context).popPage(); MainController.of(context).popPage();
MainController.of(context).openConversation(conversationID); MainController.of(context).openConversation(conversationID);
return;
} }
// TODO : reimplement // Update conversation settings
/* final settings = Conversation( final newSettings = NewConversationsSettings(
id: isUpdating ? widget.initialSettings.id : 0, convID: _conversation.id,
ownerID: isUpdating ? widget.initialSettings.ownerID : 0,
name: _nameController.text,
following: _followConversation, following: _followConversation,
members: _members.usersID, isComplete: isAdmin,
name: _nameController.text,
canEveryoneAddMembers: _canEveryoneAddMembers, canEveryoneAddMembers: _canEveryoneAddMembers,
color: _color,
);
// Give random value to these fields as they are ignored here await ConversationsHelper.updateConversation(newSettings);
lastActive: 0,
sawLastMessage: true);
// Create the conversation MainController.of(context).popPage();
var conversationID = settings.id;
bool error = false;
if (isUpdating)
error = !(await ConversationsHelper().updateConversation(settings));
else {
conversationID = await ConversationsHelper().createConversation(settings);
if (conversationID < 1) error = true;
}
// Check for errors
if (error)
return Scaffold.of(context).showSnackBar(SnackBar(
content: Text(isUpdating
? tr("Could not update the conversation!")
: tr("Could not create the conversation!")),
duration: Duration(seconds: 1),
));
// Open the conversation
MainController.of(context).popPage();
if (!isUpdating)
MainController.of(context).openConversation(conversationID);*/
} catch (e, s) { } catch (e, s) {
logError(e, s); logError(e, s);
snack(context, tr("Failed to update conversation settings!")); snack(context, tr("Failed to update conversation settings!"));