[Fix] add chats
This commit is contained in:
parent
4b6ca2e0e7
commit
c914e866d4
3 changed files with 36 additions and 15 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -605,9 +605,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cmake"
|
name = "cmake"
|
||||||
version = "0.1.57"
|
version = "0.1.58"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d"
|
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
@ -3876,7 +3876,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttp-core"
|
name = "ttp-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/Tensamin/TTP.git#c127d196082401f37b51ca5417b341ecbdb74318"
|
source = "git+https://github.com/Tensamin/TTP.git#9c0ed7a5b6c8735e4b674d4503bd7b936ee3656b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
|
@ -3888,7 +3888,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ttp-native"
|
name = "ttp-native"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/Tensamin/TTP.git#c127d196082401f37b51ca5417b341ecbdb74318"
|
source = "git+https://github.com/Tensamin/TTP.git#9c0ed7a5b6c8735e4b674d4503bd7b936ee3656b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quinn",
|
"quinn",
|
||||||
"rustls",
|
"rustls",
|
||||||
|
|
@ -3942,9 +3942,9 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-segmentation"
|
name = "unicode-segmentation"
|
||||||
version = "1.13.1"
|
version = "1.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "da36089a805484bcccfffe0739803392c8298778a2d2f09febf76fac5ad9025b"
|
checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-truncate"
|
name = "unicode-truncate"
|
||||||
|
|
|
||||||
|
|
@ -589,21 +589,43 @@ impl OmikronConnection {
|
||||||
if cv.is_type(CommunicationType::get_chats) {
|
if cv.is_type(CommunicationType::get_chats) {
|
||||||
let user_id = cv.get_sender();
|
let user_id = cv.get_sender();
|
||||||
let users = chats_util::get_users(user_id as i64);
|
let users = chats_util::get_users(user_id as i64);
|
||||||
|
let mut user_array = Vec::new();
|
||||||
|
for user in users {
|
||||||
|
let mut container = Vec::new();
|
||||||
|
container.push((DataTypes::user_id, DataValue::Number(user.user_id)));
|
||||||
|
if let Some(name) = user.user_name {
|
||||||
|
container.push((DataTypes::username, DataValue::Str(name)));
|
||||||
|
}
|
||||||
|
if let Some(ts) = user.last_message_at {
|
||||||
|
container.push((DataTypes::last_message_at, DataValue::Number(ts)));
|
||||||
|
}
|
||||||
|
user_array.push(DataValue::Container(container));
|
||||||
|
}
|
||||||
let resp = CommunicationValue::new(CommunicationType::get_chats)
|
let resp = CommunicationValue::new(CommunicationType::get_chats)
|
||||||
.with_id(cv.get_id())
|
.with_id(cv.get_id())
|
||||||
.with_receiver(user_id)
|
.with_receiver(user_id)
|
||||||
.add_data(DataTypes::user_ids, DataValue::Str(users.dump()));
|
.add_data(DataTypes::user_ids, DataValue::Array(user_array));
|
||||||
self.send_message(&resp).await;
|
self.send_message(&resp).await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cv.is_type(CommunicationType::add_conversation) {
|
if cv.is_type(CommunicationType::add_conversation) {
|
||||||
let user_id = cv.get_sender();
|
let user_id = cv.get_sender();
|
||||||
let other_id = cv
|
let other_id = match cv.get_data(DataTypes::chat_partner_id).as_number() {
|
||||||
.get_data(DataTypes::chat_partner_id)
|
Some(n) => n as i64,
|
||||||
.as_number()
|
None => cv
|
||||||
.unwrap_or(0);
|
.get_data(DataTypes::chat_partner_id)
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or("0")
|
||||||
|
.parse()
|
||||||
|
.unwrap_or(0),
|
||||||
|
};
|
||||||
let mut contact = get_user(user_id as i64, other_id).unwrap_or(Contact::new(other_id));
|
let mut contact = get_user(user_id as i64, other_id).unwrap_or(Contact::new(other_id));
|
||||||
|
|
||||||
|
if let Some(name) = cv.get_data(DataTypes::chat_partner_name).as_str() {
|
||||||
|
contact.user_name = Some(name.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
contact.set_last_message_at(
|
contact.set_last_message_at(
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::users::contact::Contact;
|
use crate::users::contact::Contact;
|
||||||
use crate::util::file_util::get_directory;
|
use crate::util::file_util::get_directory;
|
||||||
use json::{JsonValue, array};
|
|
||||||
use rusqlite::{Connection, params};
|
use rusqlite::{Connection, params};
|
||||||
|
|
||||||
fn db_path() -> String {
|
fn db_path() -> String {
|
||||||
|
|
@ -87,8 +86,8 @@ pub fn get_user(storage_owner: i64, user_id: i64) -> Option<Contact> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_users(storage_owner: i64) -> JsonValue {
|
pub fn get_users(storage_owner: i64) -> Vec<Contact> {
|
||||||
let mut contacts_out = array![];
|
let mut contacts_out = Vec::new();
|
||||||
|
|
||||||
let conn = match open_db() {
|
let conn = match open_db() {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
|
|
@ -126,7 +125,7 @@ pub fn get_users(storage_owner: i64) -> JsonValue {
|
||||||
|
|
||||||
for row in rows {
|
for row in rows {
|
||||||
if let Ok(contact) = row {
|
if let Ok(contact) = row {
|
||||||
let _ = contacts_out.push(contact.to_json());
|
contacts_out.push(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue