fix: remove analyticsRoom getter from PangeaToken (#1516)

pull/1593/head
ggurdin 10 months ago committed by GitHub
parent f7a7987277
commit 426e37b1a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -11,6 +11,7 @@ import 'package:fluffychat/pangea/chat_settings/constants/pangea_room_types.dart
import 'package:fluffychat/pangea/common/constants/model_keys.dart'; import 'package:fluffychat/pangea/common/constants/model_keys.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
extension AnalyticsClientExtension on Client { extension AnalyticsClientExtension on Client {
/// Get the logged in user's analytics room matching /// Get the logged in user's analytics room matching
@ -24,11 +25,19 @@ extension AnalyticsClientExtension on Client {
/// Get local analytics room for a given langCode and /// Get local analytics room for a given langCode and
/// optional userId (if not specified, uses current user). /// optional userId (if not specified, uses current user).
/// If user is invited to the room, joins the room. /// If user is invited to the room, joins the room.
Room? analyticsRoomLocal(String langCode, [String? userIdParam]) { Room? analyticsRoomLocal([String? langCode, String? userIdParam]) {
langCode ??=
MatrixState.pangeaController.languageController.userL2?.langCode;
if (langCode == null) {
debugger(when: kDebugMode);
return null;
}
final Room? analyticsRoom = rooms.firstWhereOrNull((e) { final Room? analyticsRoom = rooms.firstWhereOrNull((e) {
return e.isAnalyticsRoom && return e.isAnalyticsRoom &&
e.isAnalyticsRoomOfUser(userIdParam ?? userID!) && e.isAnalyticsRoomOfUser(userIdParam ?? userID!) &&
e.isMadeForLang(langCode); e.isMadeForLang(langCode!);
}); });
if (analyticsRoom != null && if (analyticsRoom != null &&
analyticsRoom.membership == Membership.invite) { analyticsRoom.membership == Membership.invite) {

@ -566,37 +566,20 @@ class PangeaToken {
category: pos, category: pos,
); );
Room? get analyticsRoom {
final String? l2 =
MatrixState.pangeaController.languageController.userL2?.langCode;
if (l2 == null) {
debugger(when: kDebugMode);
return null;
}
final Room? analyticsRoom =
MatrixState.pangeaController.matrixState.client.analyticsRoomLocal(l2);
if (analyticsRoom == null) {
debugger(when: kDebugMode);
}
return analyticsRoom;
}
/// [setEmoji] sets the emoji for the lemma /// [setEmoji] sets the emoji for the lemma
/// NOTE: assumes that the language of the lemma is the same as the user's current l2 /// NOTE: assumes that the language of the lemma is the same as the user's current l2
Future<void> setEmoji(String emoji) async { Future<void> setEmoji(String emoji) async {
final analyticsRoom =
MatrixState.pangeaController.matrixState.client.analyticsRoomLocal();
if (analyticsRoom == null) return; if (analyticsRoom == null) return;
try { try {
final client = MatrixState.pangeaController.matrixState.client; final client = MatrixState.pangeaController.matrixState.client;
final syncFuture = client.onRoomState.stream.firstWhere((event) { final syncFuture = client.onRoomState.stream.firstWhere((event) {
return event.roomId == analyticsRoom!.id && return event.roomId == analyticsRoom.id &&
event.state.type == PangeaEventTypes.userChosenEmoji; event.state.type == PangeaEventTypes.userChosenEmoji;
}); });
client.setRoomStateWithKey( client.setRoomStateWithKey(
analyticsRoom!.id, analyticsRoom.id,
PangeaEventTypes.userChosenEmoji, PangeaEventTypes.userChosenEmoji,
vocabConstructID.string, vocabConstructID.string,
{ModelKey.emoji: emoji}, {ModelKey.emoji: emoji},
@ -618,6 +601,8 @@ class PangeaToken {
/// [getEmoji] gets the emoji for the lemma /// [getEmoji] gets the emoji for the lemma
/// NOTE: assumes that the language of the lemma is the same as the user's current l2 /// NOTE: assumes that the language of the lemma is the same as the user's current l2
String? getEmoji() { String? getEmoji() {
final analyticsRoom =
MatrixState.pangeaController.matrixState.client.analyticsRoomLocal();
return analyticsRoom return analyticsRoom
?.getState(PangeaEventTypes.userChosenEmoji, vocabConstructID.string) ?.getState(PangeaEventTypes.userChosenEmoji, vocabConstructID.string)
?.content ?.content

Loading…
Cancel
Save