Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings #1293

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
rustflags: ''

- name: Check out code
uses: actions/checkout@v4
Expand Down Expand Up @@ -158,7 +157,6 @@ jobs:
with:
toolchain: stable
target: aarch64-unknown-linux-gnu
rustflags: ''

- name: Setup C compiler, linker and pkgconfig
run: |
Expand Down Expand Up @@ -252,7 +250,7 @@ jobs:

- name: Build click (${{ matrix.arch }})
# workaround https://github.com/actions/runner/issues/1479#issuecomment-969306629
uses: ChristopherHX/conditional@b4a9649204f81002ec9a4ef7d4bf7d6b2ab7fa55
uses: ChristopherHX/conditional@01004426dfbc58dc9bfe0713f146f1429eb5025e # main
with:
step: |
uses: docker://clickable/ci-20.04-${{ matrix.arch }}:8.2.0
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ edition = "2021"
description = """\
This is a cross-platform Signal client."""
license = "GPL-3"
rust = "1.71"

[source.crates-io]
registry = "git://github.com/rust-lang/crates.io-index.git"
rust-version = "1.75"

[build-dependencies]
tauri-build = { version = "2.0.0-rc.6", features = [], optional = true }
Expand Down
167 changes: 62 additions & 105 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ impl Handler {
log::error!("Too many errors, exiting or sender is none {:?}", count);
// Exit this loop
exit(0);
break;
}
count += 1;

Expand Down Expand Up @@ -838,24 +837,6 @@ impl Handler {
Ok(())
}

async fn thread_metadata(
&self,
thread: &Thread,
) -> Result<Option<ThreadMetadata>, ApplicationError> {
let manager = match self.manager_thread.get() {
Some(m) => m,
None => {
log::error!("Manager not initialized");
return Err(ApplicationError::RegistrationError(
"Manager not initialized".to_string(),
));
}
};
match manager.thread_metadata(thread).await {
Ok(metadata) => Ok(metadata),
Err(e) => Err(ApplicationError::from(e)),
}
}
// update_contact_name updates the name of a contact and also updates the thread metadata title
async fn update_contact_name(
&self,
Expand Down Expand Up @@ -1342,67 +1323,58 @@ impl Handler {
let thread_metadata = manager.thread_metadata(&thread).await.unwrap();
if thread_metadata.is_none() {
self.create_thread_metadata(&thread).await.unwrap();
match thread {
Thread::Contact(uuid) => {
let contact = match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!("handle_get_message_list: Contact not found");
return Err(ApplicationError::InvalidRequest);
}
};
match self.update_contact_name(contact).await {
Ok(_) => (),
Err(e) => {
log::error!(
"handle_get_message_list: Error updating contact name: {}",
e
);
}
if let Thread::Contact(uuid) = thread {
let contact = match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!("handle_get_message_list: Contact not found");
return Err(ApplicationError::InvalidRequest);
}
};
match self.update_contact_name(contact).await {
Ok(_) => (),
Err(e) => {
log::error!(
"handle_get_message_list: Error updating contact name: {}",
e
);
}
}
_ => (),
}
} else {
let mut thread_metadata = thread_metadata.unwrap();
match thread_metadata.title.clone() {
Some(title) => {
// check if title is a valid uuid
match thread {
Thread::Contact(uuid) => {
if Uuid::parse_str(&title).is_ok() || title.is_empty() {
let mut contact =
match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!(
"handle_get_message_list: Contact not found"
);
return Err(ApplicationError::InvalidRequest);
}
};
contact = match self.update_contact_name(contact).await {
Ok(c) => c.unwrap(),
Err(e) => {
log::error!("Error updating contact name: {}", e);
if let Thread::Contact(uuid) = thread {
if Uuid::parse_str(&title).is_ok() || title.is_empty() {
let contact = match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!("handle_get_message_list: Contact not found");
return Err(ApplicationError::InvalidRequest);
}
};
_ = match self.update_contact_name(contact).await {
Ok(c) => c.unwrap(),
Err(e) => {
log::error!("Error updating contact name: {}", e);
return Err(ApplicationError::InvalidRequest);
}
};

// retrieve updated thread metadata
thread_metadata =
match manager.thread_metadata(&thread).await.unwrap() {
Some(tm) => tm,
None => {
log::error!(
"handle_get_message_list: Thread metadata not found"
);
return Err(ApplicationError::InvalidRequest);
}
};

// retrieve updated thread metadata
thread_metadata =
match manager.thread_metadata(&thread).await.unwrap() {
Some(tm) => tm,
None => {
log::error!(
"handle_get_message_list: Thread metadata not found"
);
return Err(ApplicationError::InvalidRequest);
}
};
}
}
_ => (),
}
}

Expand Down Expand Up @@ -1613,32 +1585,27 @@ impl Handler {
}

let mut response_data = thread_metadata.unwrap();
match response_data.thread {
Thread::Contact(uuid) => {
if response_data.title.is_none() || response_data.title.clone().unwrap().len() == 36
{
log::debug!("Updating contact from profile {:?}", uuid);
let contact = match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!("No contact found");
return Err(ApplicationError::RegistrationError(
"No contact found".to_string(),
));
}
};
match self.update_contact_name(contact).await {
Ok(_) => {
response_data =
manager.thread_metadata(&thread).await.unwrap().unwrap();
}
Err(e) => {
log::error!("Error updating contact name: {}", e);
}
if let Thread::Contact(uuid) = response_data.thread {
if response_data.title.is_none() || response_data.title.clone().unwrap().len() == 36 {
log::debug!("Updating contact from profile {:?}", uuid);
let contact = match manager.get_contact_by_id(uuid).await.unwrap() {
Some(c) => c,
None => {
log::error!("No contact found");
return Err(ApplicationError::RegistrationError(
"No contact found".to_string(),
));
}
};
match self.update_contact_name(contact).await {
Ok(_) => {
response_data = manager.thread_metadata(&thread).await.unwrap().unwrap();
}
Err(e) => {
log::error!("Error updating contact name: {}", e);
}
}
}
_ => {}
}

let response = AxolotlResponse {
Expand All @@ -1662,8 +1629,8 @@ impl Handler {
) -> Result<Option<AxolotlResponse>, ApplicationError> {
log::info!("Getting config");
// let my_uuid = manager.uuid();
let mut platform = "".to_string();
platform = "linux".to_string();
#[allow(unused_mut, unused_assignments)]
let mut platform = "linux".to_string();
#[cfg(target_os = "windows")]
{
platform = "windows".to_string();
Expand All @@ -1680,9 +1647,9 @@ impl Handler {
{
platform = "ios".to_string();
}
let mut feature = "".to_string();
feature = "desktop".to_string();

#[allow(unused_mut, unused_assignments)]
let mut feature = "desktop".to_string();
#[cfg(feature = "tauri")]
{
feature = "tauri".to_string();
Expand Down Expand Up @@ -1762,17 +1729,7 @@ impl Handler {
} else {
"Invalid message"
};
struct Wrapper<T>(Cell<Option<T>>);

impl<I, P> Serialize for Wrapper<I>
where
I: IntoIterator<Item = P>,
P: Serialize,
{
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.collect_seq(self.0.take().unwrap())
}
}
// Check the type of request
if let Ok::<AxolotlRequest, SerdeError>(axolotl_request) = serde_json::from_str(msg) {
// Axolotl request
Expand Down
3 changes: 2 additions & 1 deletion src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::manager_thread::ManagerThread;
use crate::requests::{AxolotlMessage, AxolotlResponse, SendMessageResponse};
use presage::prelude::*;
use presage::proto::{DataMessage, GroupContextV2};
use presage::store::ContentsStore;
use presage::{Manager, Thread};
use presage_store_sled::SledStore;
use std::time::UNIX_EPOCH;
Expand Down Expand Up @@ -123,7 +124,7 @@ pub async fn send_message_to_group(
..Default::default()
};

match manager.group(&master_key) {
match manager.store().group(master_key) {
Ok(group) => match group {
Some(_) => {
manager
Expand Down
Loading