mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Can update admin status of a user
This commit is contained in:
parent
bd73e265cc
commit
fdec22c28a
@ -67,6 +67,16 @@ class ConversationsHelper {
|
||||
.addInt("userID", userID)
|
||||
.execWithThrow();
|
||||
|
||||
/// Update admin status of a user in a conversation
|
||||
///
|
||||
/// Throws in case of failure
|
||||
static Future<void> setAdmin(int convID, int userID, bool admin) async =>
|
||||
await APIRequest.withLogin("conversations/setAdmin")
|
||||
.addInt("convID", convID)
|
||||
.addInt("userID", userID)
|
||||
.addBool("setAdmin", admin)
|
||||
.execWithThrow();
|
||||
|
||||
/// Update an existing conversation
|
||||
///
|
||||
/// Throws in case of failure
|
||||
|
@ -66,6 +66,9 @@ class Conversation extends SerializableElement<Conversation> {
|
||||
/// Check if the last message has been seen or not
|
||||
bool get sawLastMessage => lastActivity <= membership.lastAccessTime;
|
||||
|
||||
/// Check out whether a conversation is managed or not
|
||||
bool get isManaged => groupID != null;
|
||||
|
||||
Conversation.fromJson(Map<String, dynamic> map)
|
||||
: id = map["id"],
|
||||
name = map["name"],
|
||||
|
@ -63,7 +63,9 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
|
||||
get isAdmin => !isUpdating || _conversation.isAdmin;
|
||||
|
||||
bool get _canAddMembers => isAdmin || _conversation.canEveryoneAddMembers;
|
||||
bool get _canAddMembers =>
|
||||
(isAdmin || _conversation.canEveryoneAddMembers) &&
|
||||
(!isUpdating || !_conversation.isManaged);
|
||||
|
||||
get _isValid => _members.length > 0;
|
||||
|
||||
@ -221,7 +223,7 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
break;
|
||||
|
||||
case _MembersMenuChoices.TOGGLE_ADMIN_STATUS:
|
||||
// TODO: Handle this case.
|
||||
_toggleAdminStatus(user);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -255,6 +257,23 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
void _toggleAdminStatus(User user) async {
|
||||
try {
|
||||
final setAdmin = !_admins.contains(user.id);
|
||||
await ConversationsHelper.setAdmin(_conversation.id, user.id, setAdmin);
|
||||
|
||||
setState(() {
|
||||
if (!setAdmin)
|
||||
_admins.remove(user.id);
|
||||
else
|
||||
_admins.add(user.id);
|
||||
});
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
snack(context, tr("Failed to toggle admin status of user!"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Submit the conversation
|
||||
Future<void> _submitForm() async {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user