fix: remove analyticsRoom getter from PangeaToken (#1516)
This commit is contained in:
parent
f7a7987277
commit
426e37b1a5
2 changed files with 17 additions and 23 deletions
|
|
@ -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/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
extension AnalyticsClientExtension on Client {
|
||||
/// 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
|
||||
/// optional userId (if not specified, uses current user).
|
||||
/// 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) {
|
||||
return e.isAnalyticsRoom &&
|
||||
e.isAnalyticsRoomOfUser(userIdParam ?? userID!) &&
|
||||
e.isMadeForLang(langCode);
|
||||
e.isMadeForLang(langCode!);
|
||||
});
|
||||
if (analyticsRoom != null &&
|
||||
analyticsRoom.membership == Membership.invite) {
|
||||
|
|
|
|||
|
|
@ -566,37 +566,20 @@ class PangeaToken {
|
|||
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
|
||||
/// NOTE: assumes that the language of the lemma is the same as the user's current l2
|
||||
Future<void> setEmoji(String emoji) async {
|
||||
final analyticsRoom =
|
||||
MatrixState.pangeaController.matrixState.client.analyticsRoomLocal();
|
||||
if (analyticsRoom == null) return;
|
||||
try {
|
||||
final client = MatrixState.pangeaController.matrixState.client;
|
||||
final syncFuture = client.onRoomState.stream.firstWhere((event) {
|
||||
return event.roomId == analyticsRoom!.id &&
|
||||
return event.roomId == analyticsRoom.id &&
|
||||
event.state.type == PangeaEventTypes.userChosenEmoji;
|
||||
});
|
||||
client.setRoomStateWithKey(
|
||||
analyticsRoom!.id,
|
||||
analyticsRoom.id,
|
||||
PangeaEventTypes.userChosenEmoji,
|
||||
vocabConstructID.string,
|
||||
{ModelKey.emoji: emoji},
|
||||
|
|
@ -618,6 +601,8 @@ class PangeaToken {
|
|||
/// [getEmoji] gets the emoji for the lemma
|
||||
/// NOTE: assumes that the language of the lemma is the same as the user's current l2
|
||||
String? getEmoji() {
|
||||
final analyticsRoom =
|
||||
MatrixState.pangeaController.matrixState.client.analyticsRoomLocal();
|
||||
return analyticsRoom
|
||||
?.getState(PangeaEventTypes.userChosenEmoji, vocabConstructID.string)
|
||||
?.content
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue