Skip to content

Commit 5c3ef7b

Browse files
committed
add a value in statue db
1 parent 9de1ad5 commit 5c3ef7b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,12 @@ impl ChatSession {
11791179
}
11801180

11811181
async fn show_changelog_announcement(&mut self, os: &mut Os) -> Result<()> {
1182+
let has_used_before = os.database.has_used_chat_before()?;
1183+
if !has_used_before {
1184+
os.database.mark_chat_as_used()?;
1185+
return Ok(());
1186+
}
1187+
11821188
let current_version = env!("CARGO_PKG_VERSION");
11831189
let last_version = os.database.get_changelog_last_version()?;
11841190
let show_count = os.database.get_changelog_show_count()?.unwrap_or(0);

crates/chat-cli/src/database/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const IDC_REGION_KEY: &str = "auth.idc.region";
6363
const CUSTOMIZATION_STATE_KEY: &str = "api.selectedCustomization";
6464
const PROFILE_MIGRATION_KEY: &str = "profile.Migrated";
6565
const HEARTBEAT_DATE_KEY: &str = "telemetry.lastHeartbeatDate";
66+
const CHAT_USED_BEFORE_KEY: &str = "chat.usedBefore";
6667

6768
const MIGRATIONS: &[Migration] = migrations![
6869
"000_migration_table",
@@ -507,6 +508,20 @@ impl Database {
507508

508509
Ok(map)
509510
}
511+
512+
/// Check if chat has been used before
513+
/// Returns true if user has used chat before, false if this is the first time
514+
pub fn has_used_chat_before(&self) -> Result<bool, DatabaseError> {
515+
Ok(self
516+
.get_entry::<bool>(Table::State, CHAT_USED_BEFORE_KEY)?
517+
.unwrap_or(false))
518+
}
519+
520+
/// Mark that chat has been used
521+
pub fn mark_chat_as_used(&self) -> Result<(), DatabaseError> {
522+
self.set_entry(Table::State, CHAT_USED_BEFORE_KEY, true)?;
523+
Ok(())
524+
}
510525
}
511526

512527
fn max_migration_version<C: Deref<Target = Connection>>(conn: &C) -> Option<i64> {

0 commit comments

Comments
 (0)