initial work on auto-enroll users in support space (#1097)
* initial work on auto-enroll users in support space * made the joining of help space automatic * don't try to join the space if you've previously left it
This commit is contained in:
parent
7ff4efadbc
commit
4ac9a6e005
9 changed files with 70 additions and 3 deletions
2
.env
2
.env
|
|
@ -11,3 +11,5 @@ RC_STRIPE_KEY = 'strp_YWZxWUeEfvagiefDNoofinaRCOl'
|
|||
RC_OFFERING_NAME = 'test'
|
||||
|
||||
STRIPE_MANAGEMENT_LINK = 'https://billing.stripe.com/p/login/test_9AQaI8d3O9lmaXe5kk'
|
||||
|
||||
SUPPORT_SPACE_ID = '!gqSNSkvwTpgumyjLsV:staging.pangea.chat'
|
||||
|
|
@ -11,3 +11,5 @@ RC_STRIPE_KEY = 'strp_YWZxWUeEfvagiefDNoofinaRCOl'
|
|||
RC_OFFERING_NAME = 'test'
|
||||
|
||||
STRIPE_MANAGEMENT_LINK = 'https://billing.stripe.com/p/login/test_9AQaI8d3O9lmaXe5kk'
|
||||
|
||||
SUPPORT_SPACE_ID = '!gqSNSkvwTpgumyjLsV:staging.pangea.chat'
|
||||
|
|
|
|||
|
|
@ -333,7 +333,6 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
),
|
||||
);
|
||||
}
|
||||
await Matrix.of(context).client.roomsLoading;
|
||||
});
|
||||
// Pangea#
|
||||
tryLoadTimeline();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart' as sdk;
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
enum AliasActions { copy, delete, setCanonical }
|
||||
|
|
@ -226,6 +227,23 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> setVisibility(sdk.Visibility visibility) async {
|
||||
if (roomId == null) return;
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!);
|
||||
if (room == null) return;
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async {
|
||||
await room.client.setRoomVisibilityOnDirectory(
|
||||
room.id,
|
||||
visibility: visibility,
|
||||
);
|
||||
},
|
||||
);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future<void> toggleMute() async {
|
||||
final client = Matrix.of(context).client;
|
||||
final Room? room = client.getRoomById(roomId!);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,11 @@ class Environment {
|
|||
'https://billing.stripe.com/p/login/dR6dSkf5p6rBc4EcMM';
|
||||
}
|
||||
|
||||
static String get supportSpaceId {
|
||||
return dotenv.env["SUPPORT_SPACE_ID"] ??
|
||||
'!gqSNSkvwTpgumyjLsV:staging.pangea.chat';
|
||||
}
|
||||
|
||||
static String get supportUserId {
|
||||
return isStaging ? '@support:staging.pangea.chat' : '@support:pangea.chat';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class ModelKey {
|
|||
static const String userSourceLanguage = 'source_language';
|
||||
static const String userSpeaks = 'speaks';
|
||||
static const String userCountry = 'country';
|
||||
static const String hasJoinedHelpSpace = 'has_joined_help_space';
|
||||
static const String userInterests = 'interests';
|
||||
static const String l2LanguageKey = 'target_language';
|
||||
static const String l1LanguageKey = 'source_language';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:developer';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/constants/bot_mode.dart';
|
||||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
|
|
@ -92,6 +93,7 @@ class PangeaController {
|
|||
startChatWithBotIfNotPresent();
|
||||
inviteBotToExistingSpaces();
|
||||
setPangeaPushRules();
|
||||
joinSupportSpace();
|
||||
}
|
||||
|
||||
/// Initialize controllers
|
||||
|
|
@ -426,4 +428,39 @@ class PangeaController {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Joins the user to the support space if they are
|
||||
/// not already a member and have not previously left.
|
||||
Future<void> joinSupportSpace() async {
|
||||
// if the user is already in the space, return
|
||||
await matrixState.client.roomsLoading;
|
||||
final isInSupportSpace = matrixState.client.rooms.any(
|
||||
(room) => room.id == Environment.supportSpaceId,
|
||||
);
|
||||
if (isInSupportSpace) return;
|
||||
|
||||
// if the user has previously joined the space, return
|
||||
final bool previouslyJoined =
|
||||
userController.profile.userSettings.hasJoinedHelpSpace ?? false;
|
||||
if (previouslyJoined) return;
|
||||
|
||||
// join the space
|
||||
try {
|
||||
await matrixState.client.joinRoomById(Environment.supportSpaceId);
|
||||
final room = matrixState.client.getRoomById(Environment.supportSpaceId);
|
||||
if (room == null) {
|
||||
await matrixState.client.waitForRoomInSync(
|
||||
Environment.supportSpaceId,
|
||||
join: true,
|
||||
);
|
||||
}
|
||||
userController.updateProfile((profile) {
|
||||
profile.userSettings.hasJoinedHelpSpace = true;
|
||||
return profile;
|
||||
});
|
||||
} catch (err, s) {
|
||||
ErrorHandler.logError(e: err, s: s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class UserSettings {
|
|||
String? targetLanguage;
|
||||
String? sourceLanguage;
|
||||
String? country;
|
||||
bool? hasJoinedHelpSpace;
|
||||
|
||||
UserSettings({
|
||||
this.dateOfBirth,
|
||||
|
|
@ -29,6 +30,7 @@ class UserSettings {
|
|||
this.targetLanguage,
|
||||
this.sourceLanguage,
|
||||
this.country,
|
||||
this.hasJoinedHelpSpace,
|
||||
});
|
||||
|
||||
factory UserSettings.fromJson(Map<String, dynamic> json) => UserSettings(
|
||||
|
|
@ -43,6 +45,7 @@ class UserSettings {
|
|||
targetLanguage: json[ModelKey.l2LanguageKey],
|
||||
sourceLanguage: json[ModelKey.l1LanguageKey],
|
||||
country: json[ModelKey.userCountry],
|
||||
hasJoinedHelpSpace: json[ModelKey.hasJoinedHelpSpace],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -56,6 +59,7 @@ class UserSettings {
|
|||
data[ModelKey.l2LanguageKey] = targetLanguage;
|
||||
data[ModelKey.l1LanguageKey] = sourceLanguage;
|
||||
data[ModelKey.userCountry] = country;
|
||||
data[ModelKey.hasJoinedHelpSpace] = hasJoinedHelpSpace;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -316,10 +316,9 @@ class PangeaChatDetailsView extends StatelessWidget {
|
|||
if (room.isRoomAdmin)
|
||||
VisibilityToggle(
|
||||
room: room,
|
||||
setVisibility: (_) async {},
|
||||
setVisibility: controller.setVisibility,
|
||||
setJoinRules: controller.setJoinRules,
|
||||
iconColor: iconColor,
|
||||
showSearchToggle: false,
|
||||
),
|
||||
if (room.isRoomAdmin)
|
||||
Divider(color: theme.dividerColor, height: 1),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue