Skip to content

Commit

Permalink
bug: can't save chats after ending the stream (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit authored Oct 7, 2024
1 parent aad9b37 commit cab375d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
4 changes: 1 addition & 3 deletions lib/data/model/chat/history/history.ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ extension ChatHistoryX on ChatHistory {
);
}

void save() {
Stores.history.put(this);
}
void save() => Stores.history.put(this);

bool containsKeywords(List<String> keywords) {
return items.any(
Expand Down
1 change: 0 additions & 1 deletion lib/view/page/backup/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ final class BackupPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(title: Text(libL10n.backup)),
body: _buildBody(context),
);
}
Expand Down
30 changes: 19 additions & 11 deletions lib/view/page/home/req.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,29 @@ Future<void> _onCreateText(

_autoScroll(chatId);
},
onDone: () async {
_onStopStreamSub(chatId);
_loadingChatIds.remove(chatId);
_loadingChatIds.remove(assistReply.id);
_loadingChatIdRN.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;

_storeChat(chatId);
// Wait for db to store the chat
await Future.delayed(const Duration(milliseconds: 300));
BakSync.instance.sync();
},
onError: (e, s) {
_onErr(e, s, chatId, 'Listen text stream');
_loadingChatIds.remove(chatId);
_loadingChatIds.remove(assistReply.id);
_loadingChatIdRN.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;
},
);
} catch (e, s) {
_onErr(e, s, chatId, 'Listen text stream');
_loadingChatIds.remove(chatId);
} finally {
_onStopStreamSub(chatId);
_loadingChatIds.remove(chatId);
_loadingChatIds.remove(assistReply.id);
_loadingChatIdRN.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;

_storeChat(chatId);
// Wait for db to store the chat
await Future.delayed(const Duration(milliseconds: 300));
BakSync.instance.sync();
}
}

Expand Down
13 changes: 13 additions & 0 deletions lib/view/page/settings/def.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum SettingsTab {
app,
profile,
tool,
bak,
res,
about,
;
Expand All @@ -22,9 +23,21 @@ enum SettingsTab {
app => libL10n.app,
profile => l10n.profile,
tool => l10n.tool,
bak => libL10n.backup,
res => l10n.res,
about => libL10n.about,
};

Widget get page => switch (this) {
app => const AppSettingsPage(),
profile => const ProfilePage(),
tool => const ToolPage(),
bak => const BackupPage(),
res => const ResPage(),
about => const AboutPage(),
};

static List<Tab> get tabs => values.map((e) => Tab(text: e.i18n)).toList();

static List<Widget> get pages => values.map((e) => e.page).toList();
}
12 changes: 2 additions & 10 deletions lib/view/page/settings/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:gpt_box/data/res/rnode.dart';
import 'package:gpt_box/data/res/url.dart';
import 'package:gpt_box/data/store/all.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:gpt_box/view/page/backup/view.dart';
import 'package:gpt_box/view/widget/audio.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:shortid/shortid.dart';
Expand Down Expand Up @@ -66,16 +67,7 @@ class _SettingsPageState extends State<SettingsPage>
isScrollable: true,
),
),
body: TabBarView(
controller: _tabCtrl,
children: const [
AppSettingsPage(),
ProfilePage(),
ToolPage(),
ResPage(),
AboutPage(),
],
),
body: TabBarView(controller: _tabCtrl, children: SettingsTab.pages),
);
}
}
Expand Down

0 comments on commit cab375d

Please sign in to comment.