mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Can update conversation settings
This commit is contained in:
parent
fdec22c28a
commit
0b2f939376
@ -41,7 +41,7 @@ class ConversationsHelper {
|
||||
"name": settings.name ?? "",
|
||||
"follow": settings.follow ? "true" : "false",
|
||||
"users": settings.members.join(","),
|
||||
"color": colorToHex(settings.color) ?? ","
|
||||
"color": colorToHex(settings.color)
|
||||
})
|
||||
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers)
|
||||
.execWithThrow();
|
||||
@ -80,7 +80,8 @@ class ConversationsHelper {
|
||||
/// Update an existing conversation
|
||||
///
|
||||
/// Throws in case of failure
|
||||
Future<void> updateConversation(NewConversationsSettings settings) async {
|
||||
static Future<void> updateConversation(
|
||||
NewConversationsSettings settings) async {
|
||||
final request = APIRequest.withLogin("conversations/updateSettings")
|
||||
.addInt("conversationID", settings.convID)
|
||||
.addBool("following", settings.following);
|
||||
@ -90,7 +91,7 @@ class ConversationsHelper {
|
||||
request
|
||||
.addString("name", settings.name ?? "")
|
||||
.addBool("canEveryoneAddMembers", settings.canEveryoneAddMembers)
|
||||
.addString("color", settings.color ?? "");
|
||||
.addString("color", colorToHex(settings.color));
|
||||
|
||||
await request.execWithThrow();
|
||||
|
||||
|
@ -10,7 +10,7 @@ class NewConversationsSettings {
|
||||
final bool isComplete;
|
||||
final String name;
|
||||
final bool canEveryoneAddMembers;
|
||||
final String color;
|
||||
final Color color;
|
||||
|
||||
const NewConversationsSettings({
|
||||
@required this.convID,
|
||||
@ -23,5 +23,5 @@ class NewConversationsSettings {
|
||||
assert(convID > 0),
|
||||
assert(following != null),
|
||||
assert(isComplete != null),
|
||||
assert(!isComplete && canEveryoneAddMembers != null);
|
||||
assert(!isComplete || canEveryoneAddMembers != null);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/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/ui/dialogs/color_picker_dialog.dart';
|
||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||
@ -85,6 +86,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
_admins = _conversation.adminsID;
|
||||
_followConversation = _conversation.following;
|
||||
_canEveryoneAddMembers = _conversation.canEveryoneAddMembers;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
@ -289,45 +292,22 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
|
||||
MainController.of(context).popPage();
|
||||
MainController.of(context).openConversation(conversationID);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO : reimplement
|
||||
/* final settings = Conversation(
|
||||
id: isUpdating ? widget.initialSettings.id : 0,
|
||||
ownerID: isUpdating ? widget.initialSettings.ownerID : 0,
|
||||
name: _nameController.text,
|
||||
// Update conversation settings
|
||||
final newSettings = NewConversationsSettings(
|
||||
convID: _conversation.id,
|
||||
following: _followConversation,
|
||||
members: _members.usersID,
|
||||
isComplete: isAdmin,
|
||||
name: _nameController.text,
|
||||
canEveryoneAddMembers: _canEveryoneAddMembers,
|
||||
color: _color,
|
||||
);
|
||||
|
||||
// Give random value to these fields as they are ignored here
|
||||
lastActive: 0,
|
||||
sawLastMessage: true);
|
||||
await ConversationsHelper.updateConversation(newSettings);
|
||||
|
||||
// Create the conversation
|
||||
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);*/
|
||||
MainController.of(context).popPage();
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
snack(context, tr("Failed to update conversation settings!"));
|
||||
|
Loading…
Reference in New Issue
Block a user