Skip to content

Commit

Permalink
Merge branch 'main' into konrad/group_operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kkohbrok authored Jan 20, 2025
2 parents 2da2cf7 + a93d192 commit 5bbde58
Show file tree
Hide file tree
Showing 28 changed files with 479 additions and 582 deletions.
7 changes: 3 additions & 4 deletions applogic/src/api/conversation_details_cubit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use phnxcoreclient::{
store::{Store, StoreEntityId, StoreOperation},
};
use phnxcoreclient::{store::StoreNotification, ConversationId};
use phnxtypes::identifiers::SafeTryInto;
use tokio::sync::watch;
use tokio_stream::{Stream, StreamExt};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -91,10 +90,10 @@ impl ConversationDetailsCubitBase {
.map(|c| c.conversation_type.clone());
match conversation_type {
Some(
UiConversationType::UnconfirmedConnection(username)
| UiConversationType::Connection(username),
UiConversationType::UnconfirmedConnection(user_name)
| UiConversationType::Connection(user_name),
) => {
let qualified_username = SafeTryInto::try_into(username)?;
let qualified_username = user_name.parse()?;
let profile = self.store.user_profile(&qualified_username).await?;
Ok(profile.map(|profile| UiUserProfile::from_profile(&profile)))
}
Expand Down
2 changes: 1 addition & 1 deletion applogic/src/api/conversation_list_cubit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ConversationListCubitBase {
// Cubit methods

pub async fn create_connection(&self, user_name: String) -> anyhow::Result<ConversationId> {
let id = self.context.store.add_contact(user_name).await?;
let id = self.context.store.add_contact(user_name.parse()?).await?;
self.context.load_and_emit_state().await;
Ok(id)
}
Expand Down
6 changes: 3 additions & 3 deletions applogic/src/api/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::future::Future;

use anyhow::{anyhow, Result};
use phnxcoreclient::{store::Store, Conversation, ConversationId};
use phnxtypes::identifiers::{QualifiedUserName, SafeTryInto};
use phnxtypes::identifiers::QualifiedUserName;

use crate::notifier::dispatch_message_notifications;

Expand Down Expand Up @@ -62,7 +62,7 @@ impl User {
conversation_id,
&user_names
.into_iter()
.map(<String as SafeTryInto<QualifiedUserName>>::try_into)
.map(|s| s.parse())
.collect::<Result<Vec<QualifiedUserName>, _>>()?,
)
.await?;
Expand All @@ -81,7 +81,7 @@ impl User {
conversation_id,
&user_names
.into_iter()
.map(<String as SafeTryInto<QualifiedUserName>>::try_into)
.map(|s| s.parse())
.collect::<Result<Vec<QualifiedUserName>, _>>()?,
)
.await?;
Expand Down
5 changes: 2 additions & 3 deletions applogic/src/api/user/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

use anyhow::Result;
use phnxtypes::identifiers::{QualifiedUserName, SafeTryInto};

use crate::api::types::{UiContact, UiUserProfile};

Expand All @@ -21,13 +20,13 @@ impl User {
}

pub async fn contact(&self, user_name: String) -> Option<UiContact> {
let user_name = <String as SafeTryInto<QualifiedUserName>>::try_into(user_name).unwrap();
let user_name = user_name.parse().unwrap();
self.user.contact(&user_name).await.map(|c| c.into())
}

/// Get the user profile of the user with the given [`QualifiedUserName`].
pub async fn user_profile(&self, user_name: String) -> Result<Option<UiUserProfile>> {
let user_name = SafeTryInto::try_into(user_name)?;
let user_name = user_name.parse()?;
let user_profile = self
.user
.user_profile(&user_name)
Expand Down
4 changes: 2 additions & 2 deletions applogic/src/api/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use phnxcoreclient::{
Asset, UserProfile,
};
use phnxtypes::{
identifiers::{QualifiedUserName, SafeTryInto},
identifiers::QualifiedUserName,
messages::{client_ds::QsWsMessage, push_token::PushTokenOperator},
};
use tracing::error;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl User {
display_name: Option<String>,
profile_picture: Option<Vec<u8>>,
) -> Result<User> {
let user_name: QualifiedUserName = SafeTryInto::try_into(user_name)?;
let user_name: QualifiedUserName = user_name.parse()?;
let user_profile = UserProfile::new(
user_name.clone(),
display_name.map(TryFrom::try_from).transpose()?,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

31 changes: 14 additions & 17 deletions backend/src/ds/group_state/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use super::StorableDsGroupData;
impl StorableDsGroupData {
pub(super) async fn store(&self, connection: impl PgExecutor<'_>) -> Result<(), StorageError> {
sqlx::query!(
"INSERT INTO
encrypted_groups
"INSERT INTO
encrypted_groups
(group_id, ciphertext, last_used, deleted_queues)
VALUES
VALUES
($1, $2, $3, $4)
ON CONFLICT (group_id) DO NOTHING",
self.group_id,
Expand All @@ -37,11 +37,11 @@ impl StorableDsGroupData {
qgid: &QualifiedGroupId,
) -> Result<Option<StorableDsGroupData>, StorageError> {
let Some(group_data_record) = sqlx::query!(
"SELECT
"SELECT
group_id, ciphertext, last_used, deleted_queues
FROM
FROM
encrypted_groups
WHERE
WHERE
group_id = $1",
qgid.group_uuid()
)
Expand All @@ -61,11 +61,11 @@ impl StorableDsGroupData {

pub(crate) async fn update(&self, connection: impl PgExecutor<'_>) -> Result<(), StorageError> {
sqlx::query!(
"UPDATE
"UPDATE
encrypted_groups
SET
SET
ciphertext = $2, last_used = $3, deleted_queues = $4
WHERE
WHERE
group_id = $1",
self.group_id,
PhnxCodec::to_vec(&self.encrypted_group_state)?,
Expand All @@ -82,9 +82,9 @@ impl StorableDsGroupData {
qgid: &QualifiedGroupId,
) -> Result<(), StorageError> {
sqlx::query!(
"DELETE FROM
"DELETE FROM
encrypted_groups
WHERE
WHERE
group_id = $1",
qgid.group_uuid()
)
Expand All @@ -96,10 +96,7 @@ impl StorableDsGroupData {

#[cfg(test)]
mod test {
use phnxtypes::{
crypto::ear::Ciphertext,
identifiers::{Fqdn, QualifiedGroupId},
};
use phnxtypes::{crypto::ear::Ciphertext, identifiers::QualifiedGroupId};
use sqlx::PgPool;
use uuid::Uuid;

Expand All @@ -113,7 +110,7 @@ mod test {

#[sqlx::test]
async fn reserve_group_id(pool: PgPool) {
let ds = Ds::new_from_pool(pool, Fqdn::try_from("example.com").unwrap())
let ds = Ds::new_from_pool(pool, "example.com".parse().unwrap())
.await
.expect("Error creating ephemeral Ds instance.");

Expand All @@ -132,7 +129,7 @@ mod test {

#[sqlx::test]
async fn group_state_lifecycle(pool: PgPool) {
let ds = Ds::new_from_pool(pool, Fqdn::try_from("example.com").unwrap())
let ds = Ds::new_from_pool(pool, "example.com".parse().unwrap())
.await
.expect("Error creating ephemeral Ds instance.");

Expand Down
10 changes: 2 additions & 8 deletions coreclient/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use phnxtypes::{
},
identifiers::{
AsClientId, ClientConfig, QsClientId, QsClientReference, QsUserId, QualifiedUserName,
SafeTryInto,
},
messages::{
client_as::{ConnectionPackageTbs, UserConnectionPackagesParams},
Expand Down Expand Up @@ -118,13 +117,12 @@ impl CoreUser {
/// Create a new user with the given `user_name`. If a user with this name
/// already exists, this will overwrite that user.
pub async fn new(
user_name: impl SafeTryInto<QualifiedUserName>,
user_name: QualifiedUserName,
password: &str,
server_url: impl ToString,
db_path: &str,
push_token: Option<PushToken>,
) -> Result<Self> {
let user_name = user_name.try_into()?;
let as_client_id = AsClientId::random(user_name)?;
// Open the phnx db to store the client record
let phnx_db_connection = open_phnx_db(db_path)?;
Expand Down Expand Up @@ -619,11 +617,7 @@ impl CoreUser {
///
/// Returns the [`ConversationId`] of the newly created connection
/// conversation.
pub async fn add_contact(
&self,
user_name: impl SafeTryInto<QualifiedUserName>,
) -> Result<ConversationId> {
let user_name = user_name.try_into()?;
pub async fn add_contact(&self, user_name: QualifiedUserName) -> Result<ConversationId> {
let params = UserConnectionPackagesParams {
user_name: user_name.clone(),
};
Expand Down
7 changes: 2 additions & 5 deletions coreclient/src/clients/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use crate::{
},
};
use phnxserver_test_harness::utils::setup::TestBackend;
use phnxtypes::{
codec::PhnxCodec,
identifiers::{AsClientId, SafeTryInto},
};
use phnxtypes::{codec::PhnxCodec, identifiers::AsClientId};
use rusqlite::Connection;

#[actix_rt::test]
Expand All @@ -23,7 +20,7 @@ async fn user_stages() {
let setup = TestBackend::single().await;

let user_name = "[email protected]";
let as_client_id = AsClientId::random(SafeTryInto::try_into(user_name).unwrap()).unwrap();
let as_client_id = AsClientId::random(user_name.parse().unwrap()).unwrap();

let phnx_db_connection = Connection::open_in_memory().unwrap();
let mut client_db_connection = Connection::open_in_memory().unwrap();
Expand Down
Loading

0 comments on commit 5bbde58

Please sign in to comment.