websocket::{
server::{JoinCommunityRoom, SendComment},
UserOperation,
- WebsocketInfo,
},
+ ConnectionId,
DbPool,
LemmyContext,
LemmyError,
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &CreateComment = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
form_id: data.form_id.to_owned(),
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendComment {
- op: UserOperation::CreateComment,
- comment: res.clone(),
- my_id: ws.id,
- });
+ context.chat_server().do_send(SendComment {
+ op: UserOperation::CreateComment,
+ comment: res.clone(),
+ websocket_id,
+ });
- // strip out the recipient_ids, so that
- // users don't get double notifs
- res.recipient_ids = Vec::new();
- }
+ // strip out the recipient_ids, so that
+ // users don't get double notifs
+ res.recipient_ids = Vec::new();
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &EditComment = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
form_id: data.form_id.to_owned(),
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendComment {
- op: UserOperation::EditComment,
- comment: res.clone(),
- my_id: ws.id,
- });
+ context.chat_server().do_send(SendComment {
+ op: UserOperation::EditComment,
+ comment: res.clone(),
+ websocket_id,
+ });
- // strip out the recipient_ids, so that
- // users don't get double notifs
- res.recipient_ids = Vec::new();
- }
+ // strip out the recipient_ids, so that
+ // users don't get double notifs
+ res.recipient_ids = Vec::new();
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &DeleteComment = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
form_id: None,
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendComment {
- op: UserOperation::DeleteComment,
- comment: res.clone(),
- my_id: ws.id,
- });
+ context.chat_server().do_send(SendComment {
+ op: UserOperation::DeleteComment,
+ comment: res.clone(),
+ websocket_id,
+ });
- // strip out the recipient_ids, so that
- // users don't get double notifs
- res.recipient_ids = Vec::new();
- }
+ // strip out the recipient_ids, so that
+ // users don't get double notifs
+ res.recipient_ids = Vec::new();
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &RemoveComment = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
form_id: None,
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendComment {
- op: UserOperation::RemoveComment,
- comment: res.clone(),
- my_id: ws.id,
- });
+ context.chat_server().do_send(SendComment {
+ op: UserOperation::RemoveComment,
+ comment: res.clone(),
+ websocket_id,
+ });
- // strip out the recipient_ids, so that
- // users don't get double notifs
- res.recipient_ids = Vec::new();
- }
+ // strip out the recipient_ids, so that
+ // users don't get double notifs
+ res.recipient_ids = Vec::new();
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &MarkCommentAsRead = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &SaveComment = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &CreateCommentLike = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
form_id: None,
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendComment {
- op: UserOperation::CreateCommentLike,
- comment: res.clone(),
- my_id: ws.id,
- });
+ context.chat_server().do_send(SendComment {
+ op: UserOperation::CreateCommentLike,
+ comment: res.clone(),
+ websocket_id,
+ });
- // strip out the recipient_ids, so that
- // users don't get double notifs
- res.recipient_ids = Vec::new();
- }
+ // strip out the recipient_ids, so that
+ // users don't get double notifs
+ res.recipient_ids = Vec::new();
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<GetCommentsResponse, LemmyError> {
let data: &GetComments = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
Err(_) => return Err(APIError::err("couldnt_get_comments").into()),
};
- if let Some(ws) = websocket_info {
+ if let Some(id) = websocket_id {
// You don't need to join the specific community room, bc this is already handled by
// GetCommunity
if data.community_id.is_none() {
- if let Some(id) = ws.id {
- // 0 is the "all" community
- ws.chatserver.do_send(JoinCommunityRoom {
- community_id: 0,
- id,
- });
- }
+ // 0 is the "all" community
+ context.chat_server().do_send(JoinCommunityRoom {
+ community_id: 0,
+ id,
+ });
}
}
websocket::{
server::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
UserOperation,
- WebsocketInfo,
},
+ ConnectionId,
};
use anyhow::Context;
use lemmy_db::{
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<GetCommunityResponse, LemmyError> {
let data: &GetCommunity = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
};
- let online = if let Some(ws) = websocket_info {
- if let Some(id) = ws.id {
- ws.chatserver.do_send(JoinCommunityRoom {
- community_id: community.id,
- id,
- });
- }
- ws.chatserver
- .send(GetCommunityUsersOnline { community_id })
- .await
- .unwrap_or(1)
- } else {
- 0
- };
+ if let Some(id) = websocket_id {
+ context
+ .chat_server()
+ .do_send(JoinCommunityRoom { community_id, id });
+ }
+
+ let online = context
+ .chat_server()
+ .send(GetCommunityUsersOnline { community_id })
+ .await
+ .unwrap_or(1);
let res = GetCommunityResponse {
community: community_view,
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
let data: &CreateCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
let data: &EditCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
community: community_view,
};
- send_community_websocket(&res, websocket_info, UserOperation::EditCommunity);
+ send_community_websocket(&res, context, websocket_id, UserOperation::EditCommunity);
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
let data: &DeleteCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
community: community_view,
};
- send_community_websocket(&res, websocket_info, UserOperation::DeleteCommunity);
+ send_community_websocket(&res, context, websocket_id, UserOperation::DeleteCommunity);
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
let data: &RemoveCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
community: community_view,
};
- send_community_websocket(&res, websocket_info, UserOperation::RemoveCommunity);
+ send_community_websocket(&res, context, websocket_id, UserOperation::RemoveCommunity);
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<ListCommunitiesResponse, LemmyError> {
let data: &ListCommunities = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<CommunityResponse, LemmyError> {
let data: &FollowCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
let data: &GetFollowedCommunities = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<BanFromCommunityResponse, LemmyError> {
let data: &BanFromCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
banned: data.ban,
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendCommunityRoomMessage {
- op: UserOperation::BanFromCommunity,
- response: res.clone(),
- community_id: data.community_id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendCommunityRoomMessage {
+ op: UserOperation::BanFromCommunity,
+ response: res.clone(),
+ community_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<AddModToCommunityResponse, LemmyError> {
let data: &AddModToCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = AddModToCommunityResponse { moderators };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendCommunityRoomMessage {
- op: UserOperation::AddModToCommunity,
- response: res.clone(),
- community_id: data.community_id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendCommunityRoomMessage {
+ op: UserOperation::AddModToCommunity,
+ response: res.clone(),
+ community_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetCommunityResponse, LemmyError> {
let data: &TransferCommunity = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
pub fn send_community_websocket(
res: &CommunityResponse,
- websocket_info: Option<WebsocketInfo>,
+ context: &Data<LemmyContext>,
+ websocket_id: Option<ConnectionId>,
op: UserOperation,
) {
- if let Some(ws) = websocket_info {
- // Strip out the user id and subscribed when sending to others
- let mut res_sent = res.clone();
- res_sent.community.user_id = None;
- res_sent.community.subscribed = None;
-
- ws.chatserver.do_send(SendCommunityRoomMessage {
- op,
- response: res_sent,
- community_id: res.community.id,
- my_id: ws.id,
- });
- }
+ // Strip out the user id and subscribed when sending to others
+ let mut res_sent = res.clone();
+ res_sent.community.user_id = None;
+ res_sent.community.subscribed = None;
+
+ context.chat_server().do_send(SendCommunityRoomMessage {
+ op,
+ response: res_sent,
+ community_id: res.community.id,
+ websocket_id,
+ });
}
-use crate::{
- api::claims::Claims,
- blocking,
- websocket::WebsocketInfo,
- DbPool,
- LemmyContext,
- LemmyError,
-};
+use crate::{api::claims::Claims, blocking, ConnectionId, DbPool, LemmyContext, LemmyError};
use actix_web::web::Data;
use lemmy_db::{
community::*,
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}
websocket::{
server::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
UserOperation,
- WebsocketInfo,
},
+ ConnectionId,
LemmyContext,
LemmyError,
};
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &CreatePost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::CreatePost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::CreatePost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<GetPostResponse, LemmyError> {
let data: &GetPost = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
})
.await??;
- let online = if let Some(ws) = websocket_info {
- if let Some(id) = ws.id {
- ws.chatserver.do_send(JoinPostRoom {
- post_id: data.id,
- id,
- });
- }
- ws.chatserver
- .send(GetPostUsersOnline { post_id: data.id })
- .await
- .unwrap_or(1)
- } else {
- 0
- };
+ if let Some(id) = websocket_id {
+ context.chat_server().do_send(JoinPostRoom {
+ post_id: data.id,
+ id,
+ });
+ }
+
+ let online = context
+ .chat_server()
+ .send(GetPostUsersOnline { post_id: data.id })
+ .await
+ .unwrap_or(1);
// Return the jwt
Ok(GetPostResponse {
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<GetPostsResponse, LemmyError> {
let data: &GetPosts = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
};
- if let Some(ws) = websocket_info {
+ if let Some(id) = websocket_id {
// You don't need to join the specific community room, bc this is already handled by
// GetCommunity
if data.community_id.is_none() {
- if let Some(id) = ws.id {
- // 0 is the "all" community
- ws.chatserver.do_send(JoinCommunityRoom {
- community_id: 0,
- id,
- });
- }
+ // 0 is the "all" community
+ context.chat_server().do_send(JoinCommunityRoom {
+ community_id: 0,
+ id,
+ });
}
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &CreatePostLike = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::CreatePostLike,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::CreatePostLike,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &EditPost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::EditPost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::EditPost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &DeletePost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::DeletePost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::DeletePost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &RemovePost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::RemovePost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::RemovePost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &LockPost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::LockPost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::LockPost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &StickyPost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PostResponse { post: post_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendPost {
- op: UserOperation::StickyPost,
- post: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendPost {
+ op: UserOperation::StickyPost,
+ post: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<PostResponse, LemmyError> {
let data: &SavePost = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
websocket::{
server::{GetUsersOnline, SendAllMessage},
UserOperation,
- WebsocketInfo,
},
+ ConnectionId,
LemmyContext,
LemmyError,
};
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<ListCategoriesResponse, LemmyError> {
let _data: &ListCategories = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetModlogResponse, LemmyError> {
let data: &GetModlog = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<SiteResponse, LemmyError> {
let data: &CreateSite = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<SiteResponse, LemmyError> {
let data: &EditSite = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = SiteResponse { site: site_view };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendAllMessage {
- op: UserOperation::EditSite,
- response: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendAllMessage {
+ op: UserOperation::EditSite,
+ response: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<GetSiteResponse, LemmyError> {
let data: &GetSite = &self;
captcha_uuid: None,
captcha_answer: None,
};
- let login_response = register.perform(context, websocket_info.clone()).await?;
+ let login_response = register.perform(context, websocket_id).await?;
info!("Admin {} created", setup.admin_username);
let create_site = CreateSite {
enable_nsfw: true,
auth: login_response.jwt,
};
- create_site.perform(context, websocket_info.clone()).await?;
+ create_site.perform(context, websocket_id).await?;
info!("Site {} created", setup.site_name);
Some(blocking(context.pool(), move |conn| SiteView::read(conn)).await??)
} else {
let banned = blocking(context.pool(), move |conn| UserView::banned(conn)).await??;
- let online = if let Some(ws) = websocket_info {
- ws.chatserver.send(GetUsersOnline).await.unwrap_or(1)
- } else {
- 0
- };
+ let online = context
+ .chat_server()
+ .send(GetUsersOnline)
+ .await
+ .unwrap_or(1);
let my_user = get_user_from_jwt_opt(&data.auth, context.pool())
.await?
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<SearchResponse, LemmyError> {
let data: &Search = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetSiteResponse, LemmyError> {
let data: &TransferSite = &self;
let mut user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetSiteConfigResponse, LemmyError> {
let data: &GetSiteConfig = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetSiteConfigResponse, LemmyError> {
let data: &SaveSiteConfig = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
websocket::{
server::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
UserOperation,
- WebsocketInfo,
},
+ ConnectionId,
LemmyContext,
LemmyError,
};
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &Login = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &Register = &self;
// If its not the admin, check the captcha
if !data.admin && Settings::get().captcha.enabled {
- match websocket_info {
- Some(ws) => {
- let check = ws
- .chatserver
- .send(CheckCaptcha {
- uuid: data
- .captcha_uuid
- .to_owned()
- .unwrap_or_else(|| "".to_string()),
- answer: data
- .captcha_answer
- .to_owned()
- .unwrap_or_else(|| "".to_string()),
- })
- .await?;
- if !check {
- return Err(APIError::err("captcha_incorrect").into());
- }
- }
- None => return Err(APIError::err("captcha_incorrect").into()),
- };
+ let check = context
+ .chat_server()
+ .send(CheckCaptcha {
+ uuid: data
+ .captcha_uuid
+ .to_owned()
+ .unwrap_or_else(|| "".to_string()),
+ answer: data
+ .captcha_answer
+ .to_owned()
+ .unwrap_or_else(|| "".to_string()),
+ })
+ .await?;
+ if !check {
+ return Err(APIError::err("captcha_incorrect").into());
+ }
}
check_slurs(&data.username)?;
async fn perform(
&self,
- _context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ context: &Data<LemmyContext>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError> {
let captcha_settings = Settings::get().captcha;
expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(captcha_item);
- }
+ // Stores the captcha item on the queue
+ context.chat_server().do_send(captcha_item);
Ok(GetCaptchaResponse {
ok: Some(CaptchaResponse { png, uuid, wav }),
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &SaveUserSettings = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetUserDetailsResponse, LemmyError> {
let data: &GetUserDetails = &self;
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<AddAdminResponse, LemmyError> {
let data: &AddAdmin = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = AddAdminResponse { admins };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendAllMessage {
- op: UserOperation::AddAdmin,
- response: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendAllMessage {
+ op: UserOperation::AddAdmin,
+ response: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<BanUserResponse, LemmyError> {
let data: &BanUser = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
banned: data.ban,
};
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendAllMessage {
- op: UserOperation::BanUser,
- response: res.clone(),
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendAllMessage {
+ op: UserOperation::BanUser,
+ response: res.clone(),
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
let data: &GetReplies = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetUserMentionsResponse, LemmyError> {
let data: &GetUserMentions = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<UserMentionResponse, LemmyError> {
let data: &MarkUserMentionAsRead = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<GetRepliesResponse, LemmyError> {
let data: &MarkAllAsRead = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &DeleteAccount = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<PasswordResetResponse, LemmyError> {
let data: &PasswordReset = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> {
let data: &PasswordChange = &self;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &CreatePrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PrivateMessageResponse { message };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendUserRoomMessage {
- op: UserOperation::CreatePrivateMessage,
- response: res.clone(),
- recipient_id: recipient_user.id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendUserRoomMessage {
+ op: UserOperation::CreatePrivateMessage,
+ response: res.clone(),
+ recipient_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &EditPrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PrivateMessageResponse { message };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendUserRoomMessage {
- op: UserOperation::EditPrivateMessage,
- response: res.clone(),
- recipient_id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendUserRoomMessage {
+ op: UserOperation::EditPrivateMessage,
+ response: res.clone(),
+ recipient_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &DeletePrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PrivateMessageResponse { message };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendUserRoomMessage {
- op: UserOperation::DeletePrivateMessage,
- response: res.clone(),
- recipient_id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendUserRoomMessage {
+ op: UserOperation::DeletePrivateMessage,
+ response: res.clone(),
+ recipient_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &MarkPrivateMessageAsRead = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
let res = PrivateMessageResponse { message };
- if let Some(ws) = websocket_info {
- ws.chatserver.do_send(SendUserRoomMessage {
- op: UserOperation::MarkPrivateMessageAsRead,
- response: res.clone(),
- recipient_id,
- my_id: ws.id,
- });
- }
+ context.chat_server().do_send(SendUserRoomMessage {
+ op: UserOperation::MarkPrivateMessageAsRead,
+ response: res.clone(),
+ recipient_id,
+ websocket_id,
+ });
Ok(res)
}
async fn perform(
&self,
context: &Data<LemmyContext>,
- _websocket_info: Option<WebsocketInfo>,
+ _websocket_id: Option<ConnectionId>,
) -> Result<PrivateMessagesResponse, LemmyError> {
let data: &GetPrivateMessages = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
async fn perform(
&self,
context: &Data<LemmyContext>,
- websocket_info: Option<WebsocketInfo>,
+ websocket_id: Option<ConnectionId>,
) -> Result<UserJoinResponse, LemmyError> {
let data: &UserJoin = &self;
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
- if let Some(ws) = websocket_info {
- if let Some(id) = ws.id {
- ws.chatserver.do_send(JoinUserRoom {
- user_id: user.id,
- id,
- });
- }
+ if let Some(ws_id) = websocket_id {
+ context.chat_server().do_send(JoinUserRoom {
+ user_id: user.id,
+ id: ws_id,
+ });
}
Ok(UserJoinResponse { user_id: user.id })
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(create, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::CreateComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(create, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::EditPost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(delete, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::EditComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(delete, &user, context).await?;
op: UserOperation::EditCommunity,
response: res,
community_id,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(delete, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePostLike,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(dislike, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::CreateCommentLike,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(dislike, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePostLike,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(like, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::CreateCommentLike,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(like, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::EditPost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(remove, &mod_, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::EditComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(remove, &mod_, context).await?;
op: UserOperation::EditCommunity,
response: res,
community_id,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(remove, &mod_, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::EditComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::EditComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &mod_, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::EditPost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::EditPost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &mod_, context).await?;
op: UserOperation::EditCommunity,
response: res,
community_id,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
op: UserOperation::EditCommunity,
response: res,
community_id,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &mod_, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::CreateCommentLike,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePostLike,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::CreateCommentLike,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePostLike,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(undo, &user, context).await?;
context.chat_server().do_send(SendPost {
op: UserOperation::EditPost,
post: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(update, &user, context).await?;
context.chat_server().do_send(SendComment {
op: UserOperation::EditComment,
comment: res,
- my_id: None,
+ websocket_id: None,
});
announce_if_community_is_local(update, &user, context).await?;
op: UserOperation::CreatePrivateMessage,
response: res,
recipient_id,
- my_id: None,
+ websocket_id: None,
});
Ok(HttpResponse::Ok().finish())
op: UserOperation::EditPrivateMessage,
response: res,
recipient_id,
- my_id: None,
+ websocket_id: None,
});
Ok(HttpResponse::Ok().finish())
op: UserOperation::EditPrivateMessage,
response: res,
recipient_id,
- my_id: None,
+ websocket_id: None,
});
Ok(HttpResponse::Ok().finish())
op: UserOperation::EditPrivateMessage,
response: res,
recipient_id,
- my_id: None,
+ websocket_id: None,
});
Ok(HttpResponse::Ok().finish())
settings.bind, settings.port
);
+ let chat_server =
+ ChatServer::startup(pool.clone(), rate_limiter.clone(), Client::default()).start();
+
// Create Http server with websocket support
HttpServer::new(move || {
- let chat_server =
- ChatServer::startup(pool.clone(), rate_limiter.clone(), Client::default()).start();
- let context = LemmyContext::create(pool.clone(), chat_server, Client::default());
+ let context = LemmyContext::create(pool.clone(), chat_server.to_owned(), Client::default());
let settings = Settings::get();
let rate_limiter = rate_limiter.clone();
App::new()
use crate::{
api::{comment::*, community::*, post::*, site::*, user::*, Perform},
rate_limit::RateLimit,
- websocket::WebsocketInfo,
LemmyContext,
};
use actix_web::{error::ErrorBadRequest, *};
Request: Perform,
Request: Send + 'static,
{
- let ws_info = WebsocketInfo {
- chatserver: context.chat_server().to_owned(),
- id: None,
- };
-
let res = data
- .perform(&context, Some(ws_info))
+ .perform(&context, None)
.await
.map(|json| HttpResponse::Ok().json(json))
.map_err(ErrorBadRequest)?;
pub mod server;
-use crate::ConnectionId;
use actix::prelude::*;
use diesel::{
r2d2::{ConnectionManager, Pool},
use rand::{rngs::ThreadRng, Rng};
use serde::{Deserialize, Serialize};
use serde_json::Value;
-use server::ChatServer;
use std::{
collections::{HashMap, HashSet},
str::FromStr,
GetSiteConfig,
SaveSiteConfig,
}
-
-#[derive(Clone)]
-pub struct WebsocketInfo {
- pub chatserver: Addr<ChatServer>,
- pub id: Option<ConnectionId>,
-}
pub struct SendAllMessage<Response> {
pub op: UserOperation,
pub response: Response,
- pub my_id: Option<ConnectionId>,
+ pub websocket_id: Option<ConnectionId>,
}
#[derive(Message)]
pub op: UserOperation,
pub response: Response,
pub recipient_id: UserId,
- pub my_id: Option<ConnectionId>,
+ pub websocket_id: Option<ConnectionId>,
}
#[derive(Message)]
pub op: UserOperation,
pub response: Response,
pub community_id: CommunityId,
- pub my_id: Option<ConnectionId>,
+ pub websocket_id: Option<ConnectionId>,
}
#[derive(Message)]
pub struct SendPost {
pub op: UserOperation,
pub post: PostResponse,
- pub my_id: Option<ConnectionId>,
+ pub websocket_id: Option<ConnectionId>,
}
#[derive(Message)]
pub struct SendComment {
pub op: UserOperation,
pub comment: CommentResponse,
- pub my_id: Option<ConnectionId>,
+ pub websocket_id: Option<ConnectionId>,
}
#[derive(Message)]
op: &UserOperation,
response: &Response,
post_id: PostId,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError>
where
Response: Serialize,
let res_str = &to_json_string(op, response)?;
if let Some(sessions) = self.post_rooms.get(&post_id) {
for id in sessions {
- if let Some(my_id) = my_id {
+ if let Some(my_id) = websocket_id {
if *id == my_id {
continue;
}
op: &UserOperation,
response: &Response,
community_id: CommunityId,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError>
where
Response: Serialize,
let res_str = &to_json_string(op, response)?;
if let Some(sessions) = self.community_rooms.get(&community_id) {
for id in sessions {
- if let Some(my_id) = my_id {
+ if let Some(my_id) = websocket_id {
if *id == my_id {
continue;
}
&self,
op: &UserOperation,
response: &Response,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError>
where
Response: Serialize,
{
let res_str = &to_json_string(op, response)?;
for id in self.sessions.keys() {
- if let Some(my_id) = my_id {
+ if let Some(my_id) = websocket_id {
if *id == my_id {
continue;
}
op: &UserOperation,
response: &Response,
recipient_id: UserId,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError>
where
Response: Serialize,
let res_str = &to_json_string(op, response)?;
if let Some(sessions) = self.user_rooms.get(&recipient_id) {
for id in sessions {
- if let Some(my_id) = my_id {
+ if let Some(my_id) = websocket_id {
if *id == my_id {
continue;
}
&self,
user_operation: &UserOperation,
comment: &CommentResponse,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError> {
let mut comment_reply_sent = comment.clone();
comment_reply_sent.comment.my_vote = None;
user_operation,
&comment_post_sent,
comment_post_sent.comment.post_id,
- my_id,
+ websocket_id,
)?;
// Send it to the recipient(s) including the mentioned users
for recipient_id in &comment_reply_sent.recipient_ids {
- self.send_user_room_message(user_operation, &comment_reply_sent, *recipient_id, my_id)?;
+ self.send_user_room_message(
+ user_operation,
+ &comment_reply_sent,
+ *recipient_id,
+ websocket_id,
+ )?;
}
// Send it to the community too
- self.send_community_room_message(user_operation, &comment_post_sent, 0, my_id)?;
+ self.send_community_room_message(user_operation, &comment_post_sent, 0, websocket_id)?;
self.send_community_room_message(
user_operation,
&comment_post_sent,
comment.comment.community_id,
- my_id,
+ websocket_id,
)?;
Ok(())
&self,
user_operation: &UserOperation,
post: &PostResponse,
- my_id: Option<ConnectionId>,
+ websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError> {
let community_id = post.post.community_id;
post_sent.post.user_id = None;
// Send it to /c/all and that community
- self.send_community_room_message(user_operation, &post_sent, 0, my_id)?;
- self.send_community_room_message(user_operation, &post_sent, community_id, my_id)?;
+ self.send_community_room_message(user_operation, &post_sent, 0, websocket_id)?;
+ self.send_community_room_message(user_operation, &post_sent, community_id, websocket_id)?;
// Send it to the post room
- self.send_post_room_message(user_operation, &post_sent, post.post.id, my_id)?;
+ self.send_post_room_message(user_operation, &post_sent, post.post.id, websocket_id)?;
Ok(())
}
client,
};
let args = Args {
- context: &context,
+ context,
rate_limiter,
id: msg.id,
ip,
}
struct Args<'a> {
- context: &'a LemmyContext,
+ context: LemmyContext,
rate_limiter: RateLimit,
id: ConnectionId,
ip: IPAddr,
data,
} = args;
- let ws_info = WebsocketInfo {
- chatserver: context.chat_server().to_owned(),
- id: Some(id),
- };
-
let data = data.to_string();
let op2 = op.clone();
let fut = async move {
let parsed_data: Data = serde_json::from_str(&data)?;
let res = parsed_data
- .perform(&web::Data::new(context.to_owned()), Some(ws_info))
+ .perform(&web::Data::new(context), Some(id))
.await?;
to_json_string(&op, &res)
};
fn handle(&mut self, msg: SendAllMessage<Response>, _: &mut Context<Self>) {
self
- .send_all_message(&msg.op, &msg.response, msg.my_id)
+ .send_all_message(&msg.op, &msg.response, msg.websocket_id)
.ok();
}
}
fn handle(&mut self, msg: SendUserRoomMessage<Response>, _: &mut Context<Self>) {
self
- .send_user_room_message(&msg.op, &msg.response, msg.recipient_id, msg.my_id)
+ .send_user_room_message(&msg.op, &msg.response, msg.recipient_id, msg.websocket_id)
.ok();
}
}
fn handle(&mut self, msg: SendCommunityRoomMessage<Response>, _: &mut Context<Self>) {
self
- .send_community_room_message(&msg.op, &msg.response, msg.community_id, msg.my_id)
+ .send_community_room_message(&msg.op, &msg.response, msg.community_id, msg.websocket_id)
.ok();
}
}
type Result = ();
fn handle(&mut self, msg: SendPost, _: &mut Context<Self>) {
- self.send_post(&msg.op, &msg.post, msg.my_id).ok();
+ self.send_post(&msg.op, &msg.post, msg.websocket_id).ok();
}
}
type Result = ();
fn handle(&mut self, msg: SendComment, _: &mut Context<Self>) {
- self.send_comment(&msg.op, &msg.comment, msg.my_id).ok();
+ self
+ .send_comment(&msg.op, &msg.comment, msg.websocket_id)
+ .ok();
}
}