feat: Chat request implementation #14

Manually merged
awiteb merged 55 commits from awiteb/chat-request-and-response into master 2024-07-18 14:21:39 +02:00 AGit
2 changed files with 5 additions and 5 deletions
Showing only changes of commit 39e7861917 - Show all commits

View file

@ -27,7 +27,7 @@ use crate::{errors::ServerResult, websocket::errors::WsError};
pub trait OutChatRequestsExt { pub trait OutChatRequestsExt {
/// Returns the outgoing chat request if the `user` have a sent chat request /// Returns the outgoing chat request if the `user` have a sent chat request
/// to the `recipient` /// to the `recipient`
async fn have_chat_request_to( async fn get_chat_request_to(
&self, &self,
requester: &UserModel, requester: &UserModel,
recipient: &PublicKey, recipient: &PublicKey,
awiteb marked this conversation as resolved
Review

should return true based on the name and description of the func

should return `true` based on the name and description of the func
Review

small nitpick (also applies to have_chat_request_to below)
I would name it get_chat_request_to, as have seems that it would be boolean

small nitpick (also applies to `have_chat_request_to` below) I would name it `get_chat_request_to`, as `have` seems that it would be boolean
@ -50,7 +50,7 @@ pub trait OutChatRequestsExt {
impl OutChatRequestsExt for DatabaseConnection { impl OutChatRequestsExt for DatabaseConnection {
#[logcall::logcall] #[logcall::logcall]
async fn have_chat_request_to( async fn get_chat_request_to(
&self, &self,
requester: &UserModel, requester: &UserModel,
recipient: &PublicKey, recipient: &PublicKey,
@ -94,7 +94,7 @@ impl OutChatRequestsExt for DatabaseConnection {
requester: &UserModel, requester: &UserModel,
recipient: &PublicKey, recipient: &PublicKey,
) -> ServerResult<()> { ) -> ServerResult<()> {
if let Some(out_model) = self.have_chat_request_to(requester, recipient).await? { if let Some(out_model) = self.get_chat_request_to(requester, recipient).await? {
out_model.delete(self).await?; out_model.delete(self).await?;
} }
Ok(()) Ok(())

View file

@ -49,7 +49,7 @@ pub async fn handle_chat_request(
// FIXME: When change the entity public key to a PublicKey type, change this // FIXME: When change the entity public key to a PublicKey type, change this
let from_public_key = PublicKey::from_str(&from_user.public_key).expect("Is valid public key"); let from_public_key = PublicKey::from_str(&from_user.public_key).expect("Is valid public key");
if try_ws!(Some db.have_chat_request_to(from_user, to_public_key).await).is_some() { if try_ws!(Some db.get_chat_request_to(from_user, to_public_key).await).is_some() {
return Some(WsError::AlreadySendChatRequest.into()); return Some(WsError::AlreadySendChatRequest.into());
awiteb marked this conversation as resolved
Review

Maybe would be better to move this to WsError easier to manage errors
there are also others below this

Maybe would be better to move this to `WsError` easier to manage errors there are also others below this
Review

Right, this should be an error, not a message. I don't know how is this happened

Right, this should be an error, not a message. I don't know how is this happened
Review

I'll remove Message event it is actually useless. I don't know why I thought it was good.

I'll remove `Message` event it is actually useless. I don't know why I thought it was good.
Review

I don't know why I thought it was good.

Well, I remembered when I added it, it was a pain to add a new error (before ws_error macro) so I thought it was good for simple messages.

> I don't know why I thought it was good. Well, I remembered when I added it, it was a pain to add a new error (before `ws_error` macro) so I thought it was good for simple messages.
} }
@ -99,7 +99,7 @@ pub async fn handle_chat_response(
PublicKey::from_str(&recipient_user.public_key).expect("Is valid public key"); PublicKey::from_str(&recipient_user.public_key).expect("Is valid public key");
if try_ws!(Some if try_ws!(Some
db.have_chat_request_to(&sender_user, &recipient_public_key) db.get_chat_request_to(&sender_user, &recipient_public_key)
.await .await
) )
.is_none() .is_none()