chore: stop inviting the bot to all spaces (#2713)
This commit is contained in:
parent
a24ee27f9b
commit
b724342955
6 changed files with 0 additions and 171 deletions
|
|
@ -10,7 +10,6 @@ import 'package:matrix/matrix.dart';
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/new_group/new_group_view.dart';
|
||||
import 'package:fluffychat/pangea/activity_planner/activity_plan_model.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/chat/constants/default_power_level.dart';
|
||||
import 'package:fluffychat/pangea/common/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
|
|
@ -238,14 +237,6 @@ class NewGroupController extends State<NewGroup> {
|
|||
}
|
||||
if (room == null) return;
|
||||
GoogleAnalytics.createClass(room.name, room.classCode(context));
|
||||
try {
|
||||
await room.invite(BotName.byEnvironment);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to invite pangea bot to new space",
|
||||
data: {"spaceId": spaceId, "error": err},
|
||||
);
|
||||
}
|
||||
|
||||
// if a timeout happened, don't redirect to the space
|
||||
if (error != null) return;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
|||
import 'package:fluffychat/pangea/guard/p_vguard.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/controllers/language_controller.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/utils/p_language_store.dart';
|
||||
import 'package:fluffychat/pangea/spaces/constants/space_constants.dart';
|
||||
import 'package:fluffychat/pangea/spaces/controllers/space_controller.dart';
|
||||
import 'package:fluffychat/pangea/subscription/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/toolbar/controllers/speech_to_text_controller.dart';
|
||||
|
|
@ -83,7 +82,6 @@ class PangeaController {
|
|||
subscriptionController.initialize();
|
||||
|
||||
startChatWithBotIfNotPresent();
|
||||
inviteBotToExistingSpaces();
|
||||
setPangeaPushRules();
|
||||
// joinSupportSpace();
|
||||
}
|
||||
|
|
@ -344,52 +342,6 @@ class PangeaController {
|
|||
_clearCachedData();
|
||||
}
|
||||
});
|
||||
|
||||
// matrixState.client.onSyncStatus.stream
|
||||
// .where((SyncStatusUpdate event) => event.status == SyncStatus.finished)
|
||||
// .listen(_handleSyncStatusFinished);
|
||||
|
||||
//PTODO - listen to incoming invites and autojoin if in class
|
||||
// matrixState.client.onSync.stream
|
||||
// .where((event) => event.rooms?.invite?.isNotEmpty ?? false)
|
||||
// .listen((SyncUpdate event) {
|
||||
// });
|
||||
|
||||
// matrixState.client.onSync.stream.listen(_handleOnSyncUpdate);
|
||||
}
|
||||
|
||||
Future<void> inviteBotToExistingSpaces() async {
|
||||
final List<Room> spaces =
|
||||
matrixState.client.rooms.where((room) => room.isSpace).toList();
|
||||
for (final Room space in spaces) {
|
||||
if (space.ownPowerLevel < SpaceConstants.powerLevelOfAdmin ||
|
||||
!space.canInvite) {
|
||||
continue;
|
||||
}
|
||||
List<User> participants;
|
||||
try {
|
||||
participants = await space.requestParticipants();
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to fetch participants for space ${space.id}",
|
||||
data: {
|
||||
"spaceID": space.id,
|
||||
},
|
||||
);
|
||||
continue;
|
||||
}
|
||||
final List<String> userIds = participants.map((user) => user.id).toList();
|
||||
if (!userIds.contains(BotName.byEnvironment)) {
|
||||
try {
|
||||
await space.invite(BotName.byEnvironment);
|
||||
} catch (err) {
|
||||
ErrorHandler.logError(
|
||||
e: "Failed to invite pangea bot to existing space",
|
||||
data: {"spaceId": space.id, "error": err},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setPangeaPushRules() async {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,6 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension RoomInformationRoomExtension on Room {
|
||||
Future<int> get numNonAdmins async {
|
||||
return (await requestParticipants())
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel < SpaceConstants.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList()
|
||||
.length;
|
||||
}
|
||||
|
||||
DateTime? get creationTime {
|
||||
final dynamic roomCreate = getState(EventTypes.RoomCreate);
|
||||
if (roomCreate is! Event) return null;
|
||||
return roomCreate.originServerTs;
|
||||
}
|
||||
|
||||
String? get creatorId => getState(EventTypes.RoomCreate)?.senderId;
|
||||
|
||||
bool isFirstOrSecondChild(String roomId) {
|
||||
|
|
|
|||
|
|
@ -14,32 +14,6 @@ extension RoomSettingsRoomExtension on Room {
|
|||
return t is int ? t : null;
|
||||
}
|
||||
|
||||
PangeaRoomRules? get pangeaRoomRules {
|
||||
try {
|
||||
final Map<String, dynamic>? content = pangeaRoomRulesStateEvent?.content;
|
||||
if (content != null) {
|
||||
final PangeaRoomRules roomRules = PangeaRoomRules.fromJson(content);
|
||||
return roomRules;
|
||||
}
|
||||
return null;
|
||||
} catch (err, s) {
|
||||
Sentry.addBreadcrumb(
|
||||
Breadcrumb(
|
||||
message: "Error in pangeaRoomRules",
|
||||
data: {"room": toJson()},
|
||||
),
|
||||
);
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
s: s,
|
||||
data: {
|
||||
"roomID": id,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
IconData? get roomTypeIcon {
|
||||
if (membership == Membership.invite) return Icons.add;
|
||||
if (isSpace) return Icons.school;
|
||||
|
|
|
|||
|
|
@ -42,12 +42,4 @@ extension SpaceRoomExtension on Room {
|
|||
.toList()
|
||||
: participants;
|
||||
}
|
||||
|
||||
Event? get pangeaRoomRulesStateEvent {
|
||||
final dynamic roomRules = getState(PangeaEventTypes.rules);
|
||||
if (roomRules is Event) {
|
||||
return roomRules;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,71 +1,8 @@
|
|||
part of "pangea_room_extension.dart";
|
||||
|
||||
extension UserPermissionsRoomExtension on Room {
|
||||
// If there are no other admins, and at least one non-admin, return true
|
||||
Future<bool> isOnlyAdmin() async {
|
||||
if (!isRoomAdmin) {
|
||||
return false;
|
||||
}
|
||||
final List<User> participants = await requestParticipants();
|
||||
|
||||
return ((participants
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel == SpaceConstants.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList()
|
||||
.length) ==
|
||||
1) &&
|
||||
(participants
|
||||
.where(
|
||||
(e) =>
|
||||
e.powerLevel < SpaceConstants.powerLevelOfAdmin &&
|
||||
e.id != BotName.byEnvironment,
|
||||
)
|
||||
.toList())
|
||||
.isNotEmpty;
|
||||
}
|
||||
|
||||
bool isMadeByUser(String userId) =>
|
||||
getState(EventTypes.RoomCreate)?.senderId == userId;
|
||||
|
||||
//if the user is an admin of the room or any immediate parent of the room
|
||||
//Question: check parents of parents?
|
||||
//check logic
|
||||
bool get isSpaceAdmin {
|
||||
if (isSpace) return isRoomAdmin;
|
||||
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
if (parent.isRoomAdmin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (final parent in pangeaSpaceParents) {
|
||||
for (final parent2 in parent.pangeaSpaceParents) {
|
||||
if (parent2.isRoomAdmin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isUserRoomAdmin(String userId) => getParticipants().any(
|
||||
(e) =>
|
||||
e.id == userId && e.powerLevel == SpaceConstants.powerLevelOfAdmin,
|
||||
);
|
||||
|
||||
bool get isRoomAdmin => ownPowerLevel == SpaceConstants.powerLevelOfAdmin;
|
||||
|
||||
// Overriding the default canSendEvent to check power levels
|
||||
bool pangeaCanSendEvent(String eventType) {
|
||||
final powerLevelsMap = getState(EventTypes.RoomPowerLevels)?.content;
|
||||
if (powerLevelsMap == null) return 0 <= ownPowerLevel;
|
||||
final pl = powerLevelsMap
|
||||
.tryGetMap<String, dynamic>('events')
|
||||
?.tryGet<int>(eventType) ??
|
||||
100;
|
||||
return ownPowerLevel >= pl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue