From c6efc97c96abd3bc35640aeae2f287cf4feb7e87 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:11:46 -0500 Subject: [PATCH] 1134 sound still playing when flagging an item (#1140) * after redacting practice activity, wait for redaction event to come through before moving forward so the same event is not shown again * don't play target token audio after flagging an activity --- .../multiple_choice_activity.dart | 14 +++++++++---- .../practice_activity_card.dart | 20 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart b/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart index e3121d81d..798c64b1a 100644 --- a/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart +++ b/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart @@ -53,10 +53,16 @@ class MultipleChoiceActivityState extends State { @override void didUpdateWidget(covariant MultipleChoiceActivity oldWidget) { super.didUpdateWidget(oldWidget); - if (widget.practiceCardController.currentCompletionRecord?.responses - .isEmpty ?? - false) { - speakTargetTokens(); + if (currentRecordModel?.responses.isEmpty ?? false) { + // This gets triggered when the activity switches and when the activity is + // flagged. Only want to speak the target tokens when the activity switches. + final activityEventFuture = + widget.practiceCardController.currentActivityCompleter?.future; + + activityEventFuture?.then((event) { + final redacted = event?.event.redacted ?? false; + if (mounted && !redacted) speakTargetTokens(); + }); setState(() => selectedChoiceIndex = null); } diff --git a/lib/pangea/widgets/practice_activity/practice_activity_card.dart b/lib/pangea/widgets/practice_activity/practice_activity_card.dart index 926e305a9..e452e0d4f 100644 --- a/lib/pangea/widgets/practice_activity/practice_activity_card.dart +++ b/lib/pangea/widgets/practice_activity/practice_activity_card.dart @@ -23,6 +23,7 @@ import 'package:fluffychat/pangea/widgets/practice_activity/no_more_practice_car import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:matrix/matrix.dart'; /// The wrapper for practice activity content. /// Handles the activities associated with a message, @@ -135,6 +136,8 @@ class PracticeActivityCardState extends State { _updateFetchingActivity(false); existingActivity.practiceActivity.targetTokens = nextActivitySpecs.tokens; + currentActivityCompleter = Completer(); + currentActivityCompleter!.complete(existingActivity); return existingActivity.practiceActivity; } @@ -268,6 +271,13 @@ class PracticeActivityCardState extends State { _setPracticeActivity(null); } + bool _isActivityRedaction(EventUpdate update, String activityId) { + return update.content.containsKey('type') && + update.content['type'] == 'm.room.redaction' && + update.content.containsKey('content') && + update.content['content']['redacts'] == activityId; + } + /// clear the current activity, record, and selection /// fetch a new activity, including the offending activity in the request Future submitFeedback(String feedback) async { @@ -278,7 +288,15 @@ class PracticeActivityCardState extends State { if (currentActivityCompleter != null) { final activityEvent = await currentActivityCompleter!.future; - await activityEvent?.event.redactEvent(reason: feedback); + if (activityEvent != null) { + await activityEvent.event.redactEvent(reason: feedback); + final eventID = activityEvent.event.eventId; + await activityEvent.event.room.client.onEvent.stream + .firstWhere( + (update) => _isActivityRedaction(update, eventID), + ) + .timeout(const Duration(milliseconds: 2500)); + } } else { debugger(when: kDebugMode); ErrorHandler.logError(