Merge pull request #101 from pangeachat/admin-invite-fix

use mode to control invited user's power level
pull/1011/head
wcjord 2 years ago committed by GitHub
commit a81dfb2b5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -111,7 +111,15 @@ class ChatListItem extends StatelessWidget {
if (room.membership == Membership.join) { if (room.membership == Membership.join) {
// Share content into this room // Share content into this room
final shareContent = Matrix.of(context).shareContent; // #Pangea
// final shareContent = Matrix.of(context).shareContent;
Map<String, dynamic>? shareContent;
try {
shareContent = Matrix.of(context).shareContent;
} catch (e) {
shareContent = null;
}
// Pangea#
if (shareContent != null) { if (shareContent != null) {
final shareFile = shareContent.tryGet<MatrixFile>('file'); final shareFile = shareContent.tryGet<MatrixFile>('file');
if (shareContent.tryGet<String>('msgtype') == if (shareContent.tryGet<String>('msgtype') ==

@ -75,7 +75,9 @@ class InvitationSelectionController extends State<InvitationSelection> {
} }
final eligibleStudents = <User>[]; final eligibleStudents = <User>[];
final spaceParents = room.pangeaSpaceParents; final spaceParents = room?.pangeaSpaceParents;
if (spaceParents == null) return eligibleStudents;
final userId = Matrix.of(context).client.userID; final userId = Matrix.of(context).client.userID;
for (final Room space in spaceParents) { for (final Room space in spaceParents) {
eligibleStudents.addAll( eligibleStudents.addAll(
@ -115,15 +117,25 @@ class InvitationSelectionController extends State<InvitationSelection> {
); );
} }
List<User> studentsInRoom(BuildContext context) => room List<User?> studentsInRoom(BuildContext context) =>
.getParticipants() room
.where( ?.getParticipants()
(u) => [Membership.join, Membership.invite].contains(u.membership), .where(
) (u) => [Membership.join, Membership.invite].contains(u.membership),
.toList(); )
.toList() ??
<User>[];
//Pangea# //Pangea#
void inviteAction(BuildContext context, String id, String displayname) async { // #Pangea
// void inviteAction(BuildContext context, String id, String displayname) async {
void inviteAction(
BuildContext context,
String id,
String displayname, {
InvitationSelectionMode? mode,
}) async {
// Pangea#
final room = Matrix.of(context).client.getRoomById(roomId!)!; final room = Matrix.of(context).client.getRoomById(roomId!)!;
if (OkCancelResult.ok != if (OkCancelResult.ok !=
await showOkCancelAlertDialog( await showOkCancelAlertDialog(
@ -144,25 +156,12 @@ class InvitationSelectionController extends State<InvitationSelection> {
context: context, context: context,
//#Pangea //#Pangea
// future: () => room.invite(id), // future: () => room.invite(id),
future: () => Future.wait([ future: () async {
room.invite(id), await room.invite(id);
room.setPower(id, ClassDefaultValues.powerLevelOfAdmin), if (mode == InvitationSelectionMode.admin) {
if (room.isSpace) await inviteTeacherAction(room, id);
...room.spaceChildren }
.map( },
(e) => roomId != null
? Matrix.of(context).client.getRoomById(e.roomId!)
: null,
)
.where((element) => element != null)
.cast<Room>()
.map(
(e) => Future.wait([
e.invite(id),
e.setPower(id, ClassDefaultValues.powerLevelOfAdmin),
]),
),
]),
// Pangea# // Pangea#
); );
if (success.error == null) { if (success.error == null) {
@ -174,6 +173,26 @@ class InvitationSelectionController extends State<InvitationSelection> {
} }
} }
// #Pangea
Future<void> inviteTeacherAction(Room room, String id) async {
room.setPower(id, ClassDefaultValues.powerLevelOfAdmin);
if (room.isSpace) {
for (final spaceChild in room.spaceChildren) {
if (spaceChild.roomId == null) continue;
final spaceChildRoom =
Matrix.of(context).client.getRoomById(spaceChild.roomId!);
if (spaceChildRoom != null) {
await spaceChildRoom.invite(id);
await spaceChildRoom.setPower(
id,
ClassDefaultValues.powerLevelOfAdmin,
);
}
}
}
}
// Pangea#
void searchUserWithCoolDown(String text) async { void searchUserWithCoolDown(String text) async {
coolDown?.cancel(); coolDown?.cancel();
coolDown = Timer( coolDown = Timer(
@ -224,8 +243,8 @@ class InvitationSelectionController extends State<InvitationSelection> {
//#Pangea //#Pangea
final participants = Matrix.of(context) final participants = Matrix.of(context)
.client .client
.getRoomById(roomId!)! .getRoomById(roomId!)
.getParticipants() ?.getParticipants()
.where( .where(
(user) => (user) =>
[Membership.join, Membership.invite].contains(user.membership), [Membership.join, Membership.invite].contains(user.membership),
@ -233,7 +252,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
.toList(); .toList();
foundProfiles.removeWhere( foundProfiles.removeWhere(
(profile) => (profile) =>
participants.indexWhere((u) => u.id == profile.userId) != -1 && participants?.indexWhere((u) => u.id == profile.userId) != -1 &&
BotName.byEnvironment != profile.userId, BotName.byEnvironment != profile.userId,
); );
//Pangea# //Pangea#
@ -242,17 +261,19 @@ class InvitationSelectionController extends State<InvitationSelection> {
//#Pangea //#Pangea
Room? _room; Room? _room;
Room get room => _room ??= Matrix.of(context).client.getRoomById(roomId!)!; Room? get room => _room ??= Matrix.of(context).client.getRoomById(roomId!);
// request participants for all parent spaces // request participants for all parent spaces
Future<void> requestParentSpaceParticipants() async { Future<void> requestParentSpaceParticipants() async {
final spaceParents = room.pangeaSpaceParents; final spaceParents = room?.pangeaSpaceParents;
await Future.wait([ if (spaceParents != null) {
...spaceParents.map((r) async { await Future.wait([
await r.requestParticipants(); ...spaceParents.map((r) async {
}), await r.requestParticipants();
room.requestParticipants(), }),
]); room!.requestParticipants(),
]);
}
} }
InvitationSelectionMode mode = InvitationSelectionMode.member; InvitationSelectionMode mode = InvitationSelectionMode.member;
@ -263,7 +284,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
Future.delayed( Future.delayed(
Duration.zero, Duration.zero,
() => setState( () => setState(
() => mode = room.isSpace () => mode = room?.isSpace ?? false
? InvitationSelectionMode.admin ? InvitationSelectionMode.admin
: InvitationSelectionMode.member, : InvitationSelectionMode.member,
), ),
@ -275,9 +296,11 @@ class InvitationSelectionController extends State<InvitationSelection> {
.where( .where(
(event) => (event) =>
event.rooms?.join?.keys.any( event.rooms?.join?.keys.any(
(ithRoomId) => room.pangeaSpaceParents (ithRoomId) =>
.map((e) => e.id) room?.pangeaSpaceParents
.contains(ithRoomId), .map((e) => e.id)
.contains(ithRoomId) ??
false,
) ?? ) ??
false, false,
) )

@ -106,6 +106,9 @@ class InvitationSelectionView extends StatelessWidget {
controller.foundProfiles[i].displayName ?? controller.foundProfiles[i].displayName ??
controller.foundProfiles[i].userId.localpart ?? controller.foundProfiles[i].userId.localpart ??
L10n.of(context)!.user, L10n.of(context)!.user,
// #Pangea
mode: controller.mode,
// Pangea#
), ),
), ),
) )
@ -143,6 +146,9 @@ class InvitationSelectionView extends StatelessWidget {
contacts[i].displayName ?? contacts[i].displayName ??
contacts[i].id.localpart ?? contacts[i].id.localpart ??
L10n.of(context)!.user, L10n.of(context)!.user,
// #Pangea
mode: controller.mode,
// Pangea#
), ),
), ),
); );

Loading…
Cancel
Save