Reboot, I64 instead of Option<I64>
This commit is contained in:
Alex Emmet 2025-12-18 17:00:48 +01:00
commit 1f878b9314
13 changed files with 512 additions and 452 deletions

View file

@ -1,9 +1,9 @@
use json::{self, JsonValue};
use json::{self, JsonValue, number::Number};
use std::time::{SystemTime, UNIX_EPOCH};
#[derive(Debug, Clone)]
pub struct Contact {
pub user_id: Option<i64>,
pub user_id: i64,
pub user_name: Option<String>,
pub last_message_at: Option<i64>,
}
@ -15,7 +15,7 @@ impl Default for Contact {
.unwrap()
.as_millis() as i64;
Contact {
user_id: None,
user_id: 0,
user_name: None,
last_message_at: Some(now),
}
@ -25,7 +25,7 @@ impl Default for Contact {
impl Contact {
pub fn new(user_id: i64) -> Self {
Contact {
user_id: Some(user_id),
user_id: user_id,
user_name: None,
last_message_at: None,
}
@ -36,19 +36,17 @@ impl Contact {
pub fn to_json(&self) -> JsonValue {
let mut obj = JsonValue::new_object();
if let Some(id) = &self.user_id {
obj["user_id"] = JsonValue::from(id.to_string());
}
obj["user_id"] = JsonValue::Number(Number::from(self.user_id));
if let Some(name) = &self.user_name {
obj["user_name"] = JsonValue::from(name.as_str());
}
if let Some(ts) = &self.last_message_at {
obj["last_message_at"] = JsonValue::from(ts.to_string());
obj["last_message_at"] = JsonValue::Number(Number::from(*ts));
}
obj
}
pub fn from_json(o: &JsonValue) -> Contact {
let user_id = o["user_id"].as_i64();
let user_id = o["user_id"].as_i64().unwrap_or(0);
let user_name = o["user_name"].as_str().map(|s| s.to_string());

View file

@ -1,9 +1,9 @@
use crate::RECONNECT;
use crate::auth::{auth_connector, crypto_helper};
use crate::gui::log_panel::log_message;
use crate::users::user_profile::UserProfile;
use crate::util::config_util::CONFIG;
use crate::util::file_util::{load_file, save_file};
use crate::{RELOAD, SHUTDOWN};
use base64::{Engine as _, engine::general_purpose::STANDARD};
use hex::{self};
use json::JsonValue;
@ -71,7 +71,8 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
);
auth_connector::complete_register(&up, &CONFIG.read().await.get_iota_id().to_string()).await;
*RECONNECT.write().await = true;
*SHUTDOWN.write().await = true;
*RELOAD.write().await = true;
log_message("Created User");
save_file(
"",