Skip to content

Commit

Permalink
New convos should be loaded at the app resumed (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin authored Jan 22, 2025
2 parents c017b15 + 63fe74e commit 9ae0669
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 1 addition & 9 deletions app/lib/pages/conversations/widgets/capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class LiteCaptureWidget extends StatefulWidget {
State<LiteCaptureWidget> createState() => LiteCaptureWidgetState();
}

class LiteCaptureWidgetState extends State<LiteCaptureWidget>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
class LiteCaptureWidgetState extends State<LiteCaptureWidget> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;

Expand All @@ -31,7 +30,6 @@ class LiteCaptureWidgetState extends State<LiteCaptureWidget>
@override
void initState() {
WavBytesUtil.clearTempWavFiles();
WidgetsBinding.instance.addObserver(this);
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (context.read<DeviceProvider>().connectedDevice != null) {
context.read<OnboardingProvider>().stopScanDevices();
Expand All @@ -47,12 +45,6 @@ class LiteCaptureWidgetState extends State<LiteCaptureWidget>
super.initState();
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

Future<BleAudioCodec> _getAudioCodec(String deviceId) async {
var connection = await ServiceManager.instance().device.ensureConnection(deviceId);
if (connection == null) {
Expand Down
6 changes: 6 additions & 0 deletions app/lib/pages/home/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
event = 'App is paused';
} else if (state == AppLifecycleState.resumed) {
event = 'App is resumed';

// Reload convos
if (mounted) {
debugPrint('Reload convos');
Provider.of<ConversationProvider>(context, listen: false).fetchNewConversations();
}
} else if (state == AppLifecycleState.hidden) {
event = 'App is hidden';
} else if (state == AppLifecycleState.detached) {
Expand Down
12 changes: 12 additions & 0 deletions app/lib/providers/conversation_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
notifyListeners();
}

Future fetchNewConversations() async {
List<ServerConversation> newConversations = await getConversationsFromServer();
List<ServerConversation> upsertConvos =
newConversations.where((c) => conversations.indexWhere((cc) => cc.id == c.id) == -1).toList();
if (upsertConvos.isEmpty) {
return;
}
conversations.insertAll(0, upsertConvos);
_groupConversationsByDateWithoutNotify();
notifyListeners();
}

Future fetchConversations() async {
previousQuery = "";
currentSearchPage = 0;
Expand Down

0 comments on commit 9ae0669

Please sign in to comment.