Skip to content

Commit

Permalink
Merge pull request #267 from pangeachat/suggested-toggle
Browse files Browse the repository at this point in the history
toggle to set suggested status for all spaces
  • Loading branch information
ggurdin authored Jun 4, 2024
2 parents c235842 + 003723d commit 6a3d047
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 144 deletions.
20 changes: 2 additions & 18 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3681,24 +3681,8 @@
"lockSpace": "Lock Space",
"lockChat": "Lock Chat",
"archiveSpace": "Archive Space",
"suggestTo": "Suggest to {spaceName}",
"@suggestTo": {
"placeholders": {
"spaceName": {}
}
},
"suggestChatDesc": "Suggested chats will appear in the chat list for {spaceName}",
"@suggestToDesc": {
"placeholders": {
"spaceName": {}
}
},
"suggestExchangeDesc": "Suggested exchanges will appear in the chat list for {spaceName}",
"@suggestToExchangeDesc": {
"placeholders": {
"spaceName": {}
}
},
"suggestToChat": "Suggest this chat",
"suggestToChatDesc": "Suggested chats will appear in chat lists",
"acceptSelection": "Accept Correction",
"acceptSelectionAnyway": "Use this anyway",
"makingActivity": "Making activity",
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/new_group/new_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ class NewGroupController extends State<NewGroup> {
powerLevelContentOverride:
await ClassChatPowerLevels.powerLevelOverrideForClassChat(
context,
addToSpaceKey.currentState!.parents
.map((suggestionStatus) => suggestionStatus.room)
.toList(),
addToSpaceKey.currentState!.parents,
),
invite: [
if (addConversationBotKey.currentState?.addBot ?? false)
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/new_space/new_space.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ class NewSpaceController extends State<NewSpace> {
powerLevelContentOverride: addToSpaceKey.currentState != null
? await ClassChatPowerLevels.powerLevelOverrideForClassChat(
context,
addToSpaceKey.currentState!.parents
.map((suggestionStatus) => suggestionStatus.room)
.toList(),
addToSpaceKey.currentState!.parents,
)
: null,
// initialState: [
Expand Down
5 changes: 3 additions & 2 deletions lib/pangea/controllers/class_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class ClassController extends BaseController {
Future<void> fixClassPowerLevels() async {
try {
final List<Future<void>> classFixes = [];
for (final room in (await _pangeaController
.matrixState.client.classesAndExchangesImTeaching)) {
final teacherSpaces = await _pangeaController
.matrixState.client.classesAndExchangesImTeaching;
for (final room in teacherSpaces) {
classFixes.add(room.setClassPowerLevels());
}
await Future.wait(classFixes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ extension ClassAndExchangeSettingsRoomExtension on Room {
}
final Event? currentPower = getState(EventTypes.RoomPowerLevels);
final Map<String, dynamic>? currentPowerContent =
currentPower?.content["events"] as Map<String, dynamic>?;
final spaceChildPower = currentPowerContent?[EventTypes.spaceChild];
currentPower?.content as Map<String, dynamic>?;
if (currentPowerContent == null) {
return;
}
if (!(currentPowerContent.containsKey("events"))) {
currentPowerContent["events"] = {};
}
final spaceChildPower =
currentPowerContent["events"][EventTypes.spaceChild];
final studentAnalyticsPower =
currentPowerContent?[PangeaEventTypes.studentAnalyticsSummary];
currentPowerContent[PangeaEventTypes.studentAnalyticsSummary];

if ((spaceChildPower == null || studentAnalyticsPower == null) &&
currentPowerContent != null) {
if ((spaceChildPower == null || studentAnalyticsPower == null)) {
currentPowerContent["events"][EventTypes.spaceChild] = 0;
currentPowerContent["events"]
[PangeaEventTypes.studentAnalyticsSummary] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,10 @@ extension PangeaRoom on Room {

BotOptionsModel? get botOptions => _botOptions;

Future<bool> suggestedInSpace(Room space) async =>
await _suggestedInSpace(space);
Future<void> setSuggested(bool suggested) async =>
await _setSuggested(suggested);

Future<void> setSuggestedInSpace(bool suggest, Room space) async =>
await _setSuggestedInSpace(suggest, space);
Future<bool> isSuggested() async => await _isSuggested();

// user_permissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,40 @@ extension RoomSettingsRoomExtension on Room {
);
}

Future<bool> _suggestedInSpace(Room space) async {
Future<bool> _isSuggested() async {
final List<Room> spaceParents = client.rooms
.where(
(room) =>
room.isSpace &&
room.spaceChildren.any(
(sc) => sc.roomId == id,
),
)
.toList();

for (final parent in spaceParents) {
final suggested = await _isSuggestedInSpace(parent);
if (!suggested) return false;
}
return true;
}

Future<void> _setSuggested(bool suggested) async {
final List<Room> spaceParents = client.rooms
.where(
(room) =>
room.isSpace &&
room.spaceChildren.any(
(sc) => sc.roomId == id,
),
)
.toList();
for (final parent in spaceParents) {
await _setSuggestedInSpace(suggested, parent);
}
}

Future<bool> _isSuggestedInSpace(Room space) async {
try {
final Map<String, dynamic> resp =
await client.getRoomStateWithKey(space.id, EventTypes.spaceChild, id);
Expand Down
Loading

0 comments on commit 6a3d047

Please sign in to comment.