[Fix] Local & Remote message handling is now propper
This commit is contained in:
parent
d79a625e32
commit
3c11800af5
6 changed files with 176 additions and 102 deletions
|
|
@ -1,13 +1,12 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use tokio::sync::oneshot;
|
||||
use iota_cli::ui::UI;
|
||||
use iota_cli::screens::terms_checker::{TermsCheckerScreen, UserChoice};
|
||||
use iota_cli::screens::terms_updater::{TermsUpdaterScreen, UpdateDecision};
|
||||
use iota_terms::{Doc, get_current_docs, get_newest_docs, TermsType as Type};
|
||||
use iota_cli::ui::UI;
|
||||
use iota_terms::{Doc, TermsType as Type, get_current_docs, get_newest_docs};
|
||||
use iota_util::file_util::{load_file, save_file};
|
||||
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
pub async fn check(ui: Arc<UI>) -> (bool, bool) {
|
||||
let mut state = ConsentState::load_state();
|
||||
|
|
@ -211,7 +210,6 @@ async fn get_updates() -> Option<(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConsentState {
|
||||
pub eula: Option<Doc>,
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ pub async fn load_from_tu(username: &str) -> Result<(), ()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_user(user: UserProfile) { USERS.lock().unwrap().push(user); }
|
||||
pub fn add_user(user: UserProfile) {
|
||||
USERS.lock().unwrap().push(user);
|
||||
}
|
||||
pub fn get_user_by_username(username: &str) -> Option<UserProfile> {
|
||||
USERS
|
||||
.lock()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use iota_util::file_util::{has_file, load_file, used_dir_space};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use iota_util::file_util::{has_file, load_file, used_dir_space};
|
||||
use json::{JsonValue, object};
|
||||
use rand::Rng;
|
||||
use rand::rngs::OsRng;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
pub mod terms_getter;
|
||||
|
||||
pub use terms_getter::Type as TermsType;
|
||||
|
|
|
|||
|
|
@ -569,6 +569,9 @@ impl OmikronConnection {
|
|||
|
||||
let height = cv.get_data(DataTypes::height).as_number().unwrap_or(0) as i64;
|
||||
|
||||
let is_local = iota_storage::users::user_manager::get_user(receiver_id).is_some();
|
||||
|
||||
if is_local {
|
||||
// persist message for the receiver (storage_owner = receiver_id)
|
||||
chat_files::add_message(
|
||||
timestamp_u128,
|
||||
|
|
@ -578,6 +581,7 @@ impl OmikronConnection {
|
|||
&content,
|
||||
height,
|
||||
);
|
||||
}
|
||||
|
||||
// persist message for the sender (storage_owner = sender_id)
|
||||
chat_files::add_message(
|
||||
|
|
@ -595,6 +599,77 @@ impl OmikronConnection {
|
|||
.with_receiver(sender_id as u64);
|
||||
self.send_message(&conf_msg).await;
|
||||
|
||||
if !is_local {
|
||||
let fw_msg = CommunicationValue::new(CommunicationType::message_other_iota)
|
||||
.with_id(cv.get_id())
|
||||
.with_receiver(receiver_id as u64)
|
||||
.with_sender(sender_id as u64)
|
||||
.add_data(DataTypes::height, DataValue::Number(height))
|
||||
.add_data(DataTypes::content, DataValue::Str(content))
|
||||
.add_data(DataTypes::send_time, DataValue::Number(timestamp_i64));
|
||||
|
||||
let other_iota_resp = self
|
||||
.clone()
|
||||
.await_response(&fw_msg, Some(Duration::from_secs(10)))
|
||||
.await;
|
||||
|
||||
if let Ok(resp) = other_iota_resp {
|
||||
let ms_raw = resp
|
||||
.get_data(DataTypes::message_state)
|
||||
.as_string()
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
let ms = MessageState::from_str(&ms_raw).upgrade(MessageState::Received);
|
||||
|
||||
let _ = chat_files::change_message_state(
|
||||
timestamp_i64,
|
||||
sender_id as i64,
|
||||
receiver_id as i64,
|
||||
ms.clone(),
|
||||
);
|
||||
|
||||
self.send_message(
|
||||
&CommunicationValue::new(CommunicationType::message_state)
|
||||
.with_id(cv.get_id())
|
||||
.with_receiver(sender_id as u64)
|
||||
.with_sender(receiver_id as u64)
|
||||
.add_data(
|
||||
DataTypes::chat_partner_id,
|
||||
DataValue::Number(receiver_id as i64),
|
||||
)
|
||||
.add_data(DataTypes::send_time, DataValue::Number(timestamp_i64))
|
||||
.add_data(
|
||||
DataTypes::message_state,
|
||||
DataValue::Str(ms.as_str().to_string()),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
let _ = chat_files::change_message_state(
|
||||
timestamp_i64,
|
||||
sender_id as i64,
|
||||
receiver_id as i64,
|
||||
MessageState::Sent,
|
||||
);
|
||||
|
||||
self.send_message(
|
||||
&CommunicationValue::new(CommunicationType::message_state)
|
||||
.with_id(cv.get_id())
|
||||
.with_receiver(sender_id as u64)
|
||||
.with_sender(receiver_id as u64)
|
||||
.add_data(
|
||||
DataTypes::chat_partner_id,
|
||||
DataValue::Number(receiver_id as i64),
|
||||
)
|
||||
.add_data(DataTypes::send_time, DataValue::Number(timestamp_i64))
|
||||
.add_data(
|
||||
DataTypes::message_state,
|
||||
DataValue::Str(MessageState::Sent.as_str().to_string()),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// Build a live-delivery message for the local client (recipient)
|
||||
let user_forward = CommunicationValue::new(CommunicationType::message_live)
|
||||
.with_id(cv.get_id())
|
||||
|
|
@ -686,6 +761,7 @@ impl OmikronConnection {
|
|||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if cv.is_type(CommunicationType::message_other_iota) {
|
||||
let sender_id = &cv.get_sender();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::omikron_connection::OmikronConnection;
|
||||
use iota_state::APP_STATE;
|
||||
use iota_logger::log;
|
||||
use dashmap::DashMap;
|
||||
use iota_logger::log;
|
||||
use iota_state::APP_STATE;
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Instant;
|
||||
use tokio::time::Duration;
|
||||
|
|
|
|||
Loading…
Reference in a new issue