mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Propagate user is writing message event
This commit is contained in:
parent
1782647f8c
commit
4014fc1454
@ -66,4 +66,5 @@ pub mod new_call_signal;
|
||||
pub mod call_peer_ready;
|
||||
pub mod call_peer_interrupted_streaming;
|
||||
pub mod res_check_password_token;
|
||||
pub mod remove_user_from_conv_message;
|
||||
pub mod removed_user_from_conv_message;
|
||||
pub mod user_is_writing_message_in_conversation;
|
22
src/api_data/user_is_writing_message_in_conversation.rs
Normal file
22
src/api_data/user_is_writing_message_in_conversation.rs
Normal file
@ -0,0 +1,22 @@
|
||||
//! # User is writing message in conversation event
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::conversation::ConvID;
|
||||
use crate::data::user::UserID;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct UserIsWritingMessageInConversation {
|
||||
user_id: u64,
|
||||
conv_id: u64,
|
||||
}
|
||||
|
||||
impl UserIsWritingMessageInConversation {
|
||||
pub fn new(user_id: &UserID, conv_id: ConvID) -> Self {
|
||||
Self {
|
||||
user_id: user_id.id(),
|
||||
conv_id: conv_id.id(),
|
||||
}
|
||||
}
|
||||
}
|
@ -7,10 +7,11 @@ use std::collections::HashSet;
|
||||
use crate::api_data::conversation_api::ConversationAPI;
|
||||
use crate::api_data::conversation_message_api::ConversationMessageAPI;
|
||||
use crate::api_data::list_unread_conversations_api::UnreadConversationAPI;
|
||||
use crate::api_data::remove_user_from_conv_message::RemovedUserFromConversationMessage;
|
||||
use crate::api_data::removed_user_from_conv_message::RemovedUserFromConversationMessage;
|
||||
use crate::api_data::res_count_unread_conversations::ResultCountUnreadConversations;
|
||||
use crate::api_data::res_create_conversation::ResCreateConversation;
|
||||
use crate::api_data::res_find_private_conversations::ResFindPrivateConversations;
|
||||
use crate::api_data::user_is_writing_message_in_conversation::UserIsWritingMessageInConversation;
|
||||
use crate::constants::{ALLOWED_CONVERSATION_FILES_TYPES, CONVERSATION_FILES_MAX_SIZE, MAX_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH};
|
||||
use crate::controllers::user_ws_controller;
|
||||
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
|
||||
@ -22,6 +23,7 @@ use crate::data::new_conversation::NewConversation;
|
||||
use crate::data::new_conversation_message::NewConversationMessage;
|
||||
use crate::data::user_ws_connection::UserWsConnection;
|
||||
use crate::data::user_ws_message::UserWsMessage;
|
||||
use crate::data::user_ws_request_handler::UserWsRequestHandler;
|
||||
use crate::helpers::{conversations_helper, events_helper};
|
||||
use crate::helpers::events_helper::Event;
|
||||
use crate::routes::RequestResult;
|
||||
@ -468,6 +470,18 @@ pub fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.success("The message has been successfully deleted!")
|
||||
}
|
||||
|
||||
/// A user is writing a message in a conversation
|
||||
pub fn member_is_writing(r: &mut UserWsRequestHandler) -> RequestResult {
|
||||
let conv_id = r.post_registered_conv_id("convID")?;
|
||||
|
||||
// Propagate event
|
||||
events_helper::propagate_event(
|
||||
&Event::UserIsWritingMessageInConversation(r.user_id_ref()?, conv_id)
|
||||
)?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
|
||||
/// Events handler
|
||||
pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||
match e {
|
||||
@ -485,6 +499,14 @@ pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||
}
|
||||
}
|
||||
|
||||
Event::UserIsWritingMessageInConversation(user_id, conv_id) => {
|
||||
user_ws_controller::send_message_to_specific_connections(
|
||||
|s| s.conversations.contains(conv_id) && s.user_id() != user_id,
|
||||
|_| UserWsMessage::no_id_message("writing_message_in_conv", UserIsWritingMessageInConversation::new(user_id, *conv_id)),
|
||||
None::<fn(&_) -> _>,
|
||||
)?;
|
||||
}
|
||||
|
||||
Event::NewConversationMessage(msg) => {
|
||||
user_ws_controller::send_message_to_specific_connections(
|
||||
|f| f.conversations.contains(&msg.conv_id),
|
||||
|
@ -5,11 +5,12 @@ use std::collections::HashMap;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::http_error::HttpError;
|
||||
use crate::routes::RequestResult;
|
||||
use crate::data::base_request_handler::{BaseRequestHandler, RequestValue};
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::conversation::ConvID;
|
||||
use crate::data::error::{Res, ResultBoxError};
|
||||
use crate::data::user_token::UserAccessToken;
|
||||
use crate::data::user_ws_connection::UserWsConnection;
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
pub enum UserWsResponseType {
|
||||
SUCCESS,
|
||||
@ -61,6 +62,17 @@ impl UserWsRequestHandler {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the ID of a conversation the user is registered to
|
||||
pub fn post_registered_conv_id(&mut self, name: &str) -> Res<ConvID> {
|
||||
let conv_id = ConvID::new(self.post_u64(name)?);
|
||||
|
||||
if !self.get_conn().conversations.contains(&conv_id) {
|
||||
self.forbidden("You are not currently registered to this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(conv_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseRequestHandler for UserWsRequestHandler {
|
||||
|
@ -38,6 +38,9 @@ pub enum Event<'a> {
|
||||
/// Deleted a conversation message
|
||||
DeleteConversationMessage(&'a ConversationMessage),
|
||||
|
||||
/// User is writing a message in a conversation
|
||||
UserIsWritingMessageInConversation(&'a UserID, ConvID),
|
||||
|
||||
/// Removed a user from a conversation
|
||||
RemovedUserFromConversation(&'a UserID, ConvID),
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use crate::controllers::{calls_controller, likes_controller, user_ws_actions};
|
||||
use crate::controllers::{calls_controller, conversations_controller, likes_controller, user_ws_actions};
|
||||
use crate::data::error::Res;
|
||||
use crate::data::user_ws_request_handler::UserWsRequestHandler;
|
||||
|
||||
@ -37,6 +37,9 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
|
||||
// Likes controller
|
||||
UserWsRoute::new("likes/update", likes_controller::update),
|
||||
|
||||
// Conversations controller
|
||||
UserWsRoute::new("conversations/is_writing", conversations_controller::member_is_writing),
|
||||
|
||||
// Calls controller
|
||||
UserWsRoute::new("calls/config", calls_controller::get_config),
|
||||
UserWsRoute::new("calls/join", calls_controller::join_call),
|
||||
|
Loading…
Reference in New Issue
Block a user