Skip to content

Commit

Permalink
Reload conversation after fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin committed Jan 14, 2025
1 parent 38b0e1a commit a14f5d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
3 changes: 2 additions & 1 deletion app/lib/backend/http/api/conversations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ Future<(List<ServerConversation>, int, int)> searchConversationsServer(
String query, {
int? page,
int? limit,
bool includeDiscarded = false,
bool includeDiscarded = true,
}) async {
debugPrint(Env.apiBaseUrl);
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/memories/search',
headers: {},
Expand Down
10 changes: 5 additions & 5 deletions app/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 9 additions & 22 deletions app/lib/providers/conversation_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
return;
}

if (query == previousQuery) {
return;
}

setIsFetchingConversations(true);
previousQuery = query;
var (convos, current, total) = await searchConversationsServer(query, includeDiscarded: showDiscardedConversations);
Expand Down Expand Up @@ -154,9 +150,9 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
showDiscardedConversations = !showDiscardedConversations;

if (previousQuery.isNotEmpty) {
groupSearchConvosByDate();
searchConversations(previousQuery);
} else {
groupConversationsByDate();
fetchConversations();
}

MixpanelManager().showDiscardedMemoriesToggled(showDiscardedConversations);
Expand All @@ -167,14 +163,12 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
notifyListeners();
}

Future getInitialConversations() async {
// reset search
Future fetchConversations() async {
previousQuery = "";
currentSearchPage = 0;
totalSearchPages = 0;
searchedConversations = [];

// fetch convos
conversations = await getConversationsFromServer();

processingConversations = conversations.where((m) => m.status == ConversationStatus.processing).toList();
Expand All @@ -189,23 +183,16 @@ class ConversationProvider extends ChangeNotifier implements IWalServiceListener
searchedConversations = conversations;
}
_groupConversationsByDateWithoutNotify();

notifyListeners();
}

Future getInitialConversations() async {
await fetchConversations();
}

List<ServerConversation> _filterOutConvos(List<ServerConversation> convos) {
var havingFilters = true;
if (showDiscardedConversations) {
havingFilters = false;
}
if (!havingFilters) {
return convos;
}
return convos.where((convo) {
if (!showDiscardedConversations && (convo.discarded && !convo.isNew)) {
return false;
}
return true;
}).toList();
return convos;
}

void _groupSearchConvosByDateWithoutNotify() {
Expand Down

0 comments on commit a14f5d0

Please sign in to comment.