feat: Chat request implementation #14
2 changed files with 5 additions and 5 deletions
|
@ -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
|
|||||||
|
@ -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(())
|
||||||
|
|
|
@ -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
Amjad50
commented
Maybe would be better to move this to Maybe would be better to move this to `WsError` easier to manage errors
there are also others below this
awiteb
commented
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
awiteb
commented
I'll remove I'll remove `Message` event it is actually useless. I don't know why I thought it was good.
awiteb
commented
Well, I remembered when I added it, it was a pain to add a new error (before > 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()
|
||||||
|
|
Loading…
Reference in a new issue
should return
true
based on the name and description of the funcsmall nitpick (also applies to
have_chat_request_to
below)I would name it
get_chat_request_to
, ashave
seems that it would be boolean