Implement make moderator

This commit is contained in:
Christian Pauly 2020-02-16 11:41:08 +01:00
parent e665f4adc3
commit 59628bd0c6
2 changed files with 38 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:fluffychat/i18n/i18n.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
@ -16,19 +17,34 @@ class ParticipantListItem extends StatelessWidget {
final MatrixState matrix = Matrix.of(context);
switch (action) {
case "ban":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.ban());
}
break;
case "unban":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.unban());
}
break;
case "kick":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.kick());
}
break;
case "admin":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.setPower(100));
}
break;
case "moderator":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.setPower(50));
}
break;
case "user":
if (await SimpleDialogs(context).askConfirmation()) {
await matrix.tryRequestWithLoadingDialog(user.setPower(0));
}
break;
case "message":
final String roomId = await user.startDirectChat();
@ -54,6 +70,13 @@ class ParticipantListItem extends StatelessWidget {
? I18n.of(context).admin
: user.powerLevel >= 50 ? I18n.of(context).moderator : "";
List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[];
if (user.id != Matrix.of(context).client.userID) {
items.add(
PopupMenuItem(
child: Text(I18n.of(context).sendAMessage), value: "message"),
);
}
if (user.canChangePowerLevel &&
user.room.ownPowerLevel == 100 &&
user.powerLevel != 100) {
@ -62,6 +85,14 @@ class ParticipantListItem extends StatelessWidget {
child: Text(I18n.of(context).makeAnAdmin), value: "admin"),
);
}
if (user.canChangePowerLevel &&
user.room.ownPowerLevel >= 50 &&
user.powerLevel != 50) {
items.add(
PopupMenuItem(
child: Text(I18n.of(context).makeAModerator), value: "moderator"),
);
}
if (user.canChangePowerLevel && user.powerLevel != 0) {
items.add(
PopupMenuItem(
@ -84,12 +115,6 @@ class ParticipantListItem extends StatelessWidget {
child: Text(I18n.of(context).removeExile), value: "unban"),
);
}
if (user.id != Matrix.of(context).client.userID) {
items.add(
PopupMenuItem(
child: Text(I18n.of(context).sendAMessage), value: "message"),
);
}
return PopupMenuButton(
onSelected: (action) => participantAction(context, action),
itemBuilder: (c) => items,

View File

@ -394,6 +394,8 @@ class I18n {
String get login => Intl.message("Login");
String get makeAModerator => Intl.message("Make a moderator");
String get makeAnAdmin => Intl.message("Make an admin");
String get makeSureTheIdentifierIsValid =>