Refactor messages
This commit is contained in:
parent
02145de39f
commit
29fe2f8562
@ -13,7 +13,8 @@ use database_actor::DbExecutor;
|
||||
#[cfg(feature = "local-storage")]
|
||||
use futures::executor::block_on;
|
||||
use futures::{StreamExt, TryStreamExt};
|
||||
use jirs_data::{User, UserId, WsMsg};
|
||||
use jirs_data::msg::WsMsgUser;
|
||||
use jirs_data::{User, UserId};
|
||||
use websocket_actor::server::InnerMsg::BroadcastToChannel;
|
||||
use websocket_actor::server::WsServer;
|
||||
|
||||
@ -72,7 +73,7 @@ pub async fn upload(
|
||||
let user = update_user_avatar(user_id, avatar_url.clone(), db).await?;
|
||||
ws.send(BroadcastToChannel(
|
||||
project_id,
|
||||
WsMsg::AvatarUrlChanged(user.id, avatar_url),
|
||||
WsMsgUser::AvatarUrlChanged(user.id, avatar_url).into(),
|
||||
))
|
||||
.await
|
||||
.map_err(|_| HttpResponse::UnprocessableEntity().finish())?;
|
||||
|
@ -3,13 +3,46 @@ use database_actor::authorize_user::AuthorizeUser;
|
||||
use database_actor::tokens::{CreateBindToken, FindBindToken};
|
||||
use database_actor::users::LookupUser;
|
||||
use futures::executor::block_on;
|
||||
use jirs_data::msg::WsError;
|
||||
use jirs_data::msg::{WsError, WsMsgSession};
|
||||
use jirs_data::{Token, WsMsg};
|
||||
use mail_actor::welcome::Welcome;
|
||||
|
||||
use crate::server::InnerMsg;
|
||||
use crate::{db_or_debug_and_return, db_or_debug_or_fallback, mail_or_debug_and_return, *};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncHandler<WsMsgSession> for WebSocketActor {
|
||||
async fn exec(&mut self, msg: WsMsgSession) -> WsResult {
|
||||
match msg {
|
||||
// auth
|
||||
WsMsgSession::BindTokenCheck(uuid) => {
|
||||
self.exec(CheckBindToken { bind_token: uuid }).await
|
||||
}
|
||||
WsMsgSession::AuthenticateRequest(email, name) => {
|
||||
self.exec(Authenticate { name, email }).await
|
||||
}
|
||||
|
||||
// register
|
||||
WsMsgSession::SignUpRequest(email, username) => {
|
||||
self.exec(Register {
|
||||
name: username,
|
||||
email,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
WsMsgSession::AuthorizeLoad(_) => Ok(None),
|
||||
WsMsgSession::AuthorizeLoaded(_) => Ok(None),
|
||||
WsMsgSession::AuthorizeExpired => Ok(None),
|
||||
WsMsgSession::AuthenticateSuccess => Ok(None),
|
||||
WsMsgSession::BindTokenBad => Ok(None),
|
||||
WsMsgSession::BindTokenOk(_) => Ok(None),
|
||||
WsMsgSession::SignUpSuccess => Ok(None),
|
||||
WsMsgSession::SignUpPairTaken => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Authenticate {
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
@ -36,7 +69,7 @@ impl AsyncHandler<Authenticate> for WebSocketActor {
|
||||
}; async
|
||||
);
|
||||
}
|
||||
Ok(Some(WsMsg::AuthenticateSuccess))
|
||||
Ok(Some(WsMsgSession::AuthenticateSuccess.into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,10 +84,10 @@ impl WsHandler<CheckAuthToken> for WebSocketActor {
|
||||
AuthorizeUser {
|
||||
access_token: msg.token,
|
||||
},
|
||||
Ok(Some(WsMsg::AuthorizeLoaded(Err(
|
||||
"Invalid auth token".to_string()
|
||||
)))),
|
||||
Ok(Some(WsMsg::AuthorizeExpired))
|
||||
Ok(Some(
|
||||
WsMsgSession::AuthorizeLoaded(Err("Invalid auth token".to_string())).into()
|
||||
)),
|
||||
Ok(Some(WsMsgSession::AuthorizeExpired.into()))
|
||||
);
|
||||
|
||||
let setting: jirs_data::UserSetting = db_or_debug_or_fallback!(
|
||||
@ -69,7 +102,9 @@ impl WsHandler<CheckAuthToken> for WebSocketActor {
|
||||
self.current_project = self.load_project().ok();
|
||||
|
||||
block_on(self.join_channel(ctx.address().recipient::<InnerMsg>()));
|
||||
Ok(Some(WsMsg::AuthorizeLoaded(Ok((user, setting)))))
|
||||
Ok(Some(
|
||||
WsMsgSession::AuthorizeLoaded(Ok((user, setting))).into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,9 +120,9 @@ impl AsyncHandler<CheckBindToken> for WebSocketActor {
|
||||
FindBindToken {
|
||||
token: msg.bind_token,
|
||||
},
|
||||
Ok(Some(WsMsg::BindTokenBad)),
|
||||
Ok(Some(WsMsgSession::BindTokenBad.into())),
|
||||
Ok(None); async
|
||||
);
|
||||
Ok(Some(WsMsg::BindTokenOk(token.access_token)))
|
||||
Ok(Some(WsMsgSession::BindTokenOk(token.access_token).into()))
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use database_actor::invitations;
|
||||
use database_actor::messages::CreateMessageReceiver;
|
||||
use futures::executor::block_on;
|
||||
use jirs_data::msg::WsMsgInvitation;
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgMessage};
|
||||
use jirs_data::{
|
||||
EmailString, InvitationId, InvitationToken, MessageType, UserRole, UsernameString, WsMsg,
|
||||
};
|
||||
@ -112,13 +112,11 @@ impl AsyncHandler<CreateInvitation> for WebSocketActor {
|
||||
})) {
|
||||
self.addr.do_send(InnerMsg::SendToUser(
|
||||
message.receiver_id,
|
||||
WsMsg::MessageUpdated(message),
|
||||
WsMsgMessage::MessageUpdated(message).into(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Some(WsMsg::Invitation(
|
||||
WsMsgInvitation::InvitationSendSuccess,
|
||||
)))
|
||||
Ok(Some(WsMsgInvitation::InvitationSendSuccess.into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,13 +186,13 @@ impl WsHandler<AcceptInvitation> for WebSocketActor {
|
||||
message_id: message.id,
|
||||
},
|
||||
|n| {
|
||||
ctx.send_msg(&WsMsg::MessageMarkedSeen(message.id, n));
|
||||
ctx.send_msg(&WsMsgMessage::MessageMarkedSeen(message.id, n).into());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Ok(Some(WsMsg::Invitation(
|
||||
WsMsgInvitation::InvitationAcceptSuccess(token.access_token),
|
||||
)))
|
||||
Ok(Some(
|
||||
WsMsgInvitation::InvitationAcceptSuccess(token.access_token).into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,23 @@
|
||||
use database_actor::messages;
|
||||
use jirs_data::{MessageId, WsMsg};
|
||||
use jirs_data::msg::WsMsgMessage;
|
||||
use jirs_data::MessageId;
|
||||
|
||||
use crate::{db_or_debug_and_return, AsyncHandler, WebSocketActor, WsResult};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncHandler<WsMsgMessage> for WebSocketActor {
|
||||
async fn exec(&mut self, msg: WsMsgMessage) -> WsResult {
|
||||
match msg {
|
||||
// messages
|
||||
WsMsgMessage::MessagesLoad => self.exec(LoadMessages).await,
|
||||
WsMsgMessage::MessageMarkSeen(id) => self.exec(MarkMessageSeen { id }).await,
|
||||
WsMsgMessage::MessageUpdated(_) => Ok(None),
|
||||
WsMsgMessage::MessagesLoaded(_) => Ok(None),
|
||||
WsMsgMessage::MessageMarkedSeen(_, _) => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoadMessages;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -10,7 +25,7 @@ impl AsyncHandler<LoadMessages> for WebSocketActor {
|
||||
async fn exec(&mut self, _msg: LoadMessages) -> WsResult {
|
||||
let user_id = self.require_user()?.id;
|
||||
let v = db_or_debug_and_return!(self, messages::LoadMessages { user_id }; async);
|
||||
Ok(Some(WsMsg::MessagesLoaded(v)))
|
||||
Ok(Some(WsMsgMessage::MessagesLoaded(v).into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +44,6 @@ impl AsyncHandler<MarkMessageSeen> for WebSocketActor {
|
||||
user_id,
|
||||
}; async
|
||||
);
|
||||
Ok(Some(WsMsg::MessageMarkedSeen(msg.id, count)))
|
||||
Ok(Some(WsMsgMessage::MessageMarkedSeen(msg.id, count).into()))
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use jirs_data::{TextEditorMode, UserId, UserSetting, WsMsg};
|
||||
use jirs_data::msg::WsMsgUser;
|
||||
use jirs_data::{TextEditorMode, UserId, UserSetting};
|
||||
|
||||
use crate::{db_or_debug_and_return, AsyncHandler, WebSocketActor, WsResult};
|
||||
|
||||
@ -25,6 +26,6 @@ impl AsyncHandler<SetTextEditorMode> for WebSocketActor {
|
||||
mode: msg.mode
|
||||
}; async
|
||||
);
|
||||
Ok(Some(WsMsg::UserSettingUpdated(setting)))
|
||||
Ok(Some(WsMsgUser::UserSettingUpdated(setting).into()))
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,31 @@
|
||||
use database_actor::users::Register as DbRegister;
|
||||
use database_actor::{self};
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgProject};
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgProject, WsMsgSession, WsMsgUser};
|
||||
use jirs_data::{UserId, UserProject, UserRole, WsMsg};
|
||||
|
||||
use crate::handlers::auth::Authenticate;
|
||||
use crate::handlers::user_settings;
|
||||
use crate::{db_or_debug_and_return, AsyncHandler, WebSocketActor, WsResult};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncHandler<WsMsgUser> for WebSocketActor {
|
||||
async fn exec(&mut self, msg: WsMsgUser) -> WsResult {
|
||||
match msg {
|
||||
// user settings
|
||||
WsMsgUser::UserSettingSetEditorMode(mode) => {
|
||||
self.exec(user_settings::SetTextEditorMode { mode }).await
|
||||
}
|
||||
|
||||
// users
|
||||
WsMsgUser::ProfileUpdate(email, name) => self.exec(ProfileUpdate { name, email }).await,
|
||||
|
||||
WsMsgUser::AvatarUrlChanged(_, _) => Ok(None),
|
||||
WsMsgUser::ProfileUpdated => Ok(None),
|
||||
WsMsgUser::UserSettingUpdated(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoadProjectUsers;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -36,7 +56,7 @@ impl AsyncHandler<Register> for WebSocketActor {
|
||||
project_id: None,
|
||||
role: UserRole::Owner,
|
||||
},
|
||||
Ok(Some(WsMsg::SignUpPairTaken)),
|
||||
Ok(Some(WsMsgSession::SignUpPairTaken.into())),
|
||||
Ok(None); async
|
||||
);
|
||||
|
||||
@ -45,7 +65,7 @@ impl AsyncHandler<Register> for WebSocketActor {
|
||||
Err(e) => return Ok(Some(e)),
|
||||
};
|
||||
|
||||
Ok(Some(WsMsg::SignUpSuccess))
|
||||
Ok(Some(WsMsgSession::SignUpSuccess.into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +104,7 @@ impl AsyncHandler<ProfileUpdate> for WebSocketActor {
|
||||
}; async
|
||||
);
|
||||
|
||||
Ok(Some(WsMsg::ProfileUpdated))
|
||||
Ok(Some(WsMsgUser::ProfileUpdated.into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use database_actor::projects::LoadCurrentProject;
|
||||
use database_actor::user_projects::CurrentUserProject;
|
||||
use database_actor::DbExecutor;
|
||||
use futures::executor::block_on as wait;
|
||||
use jirs_data::msg::WsMsgInvitation;
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgSession};
|
||||
use jirs_data::{Project, User, UserProject, WsMsg};
|
||||
use mail_actor::MailExecutor;
|
||||
|
||||
@ -84,7 +84,7 @@ impl WebSocketActor {
|
||||
match msg {
|
||||
WsMsg::Ping => return Ok(Some(WsMsg::Pong)),
|
||||
WsMsg::Pong => return Ok(Some(WsMsg::Ping)),
|
||||
WsMsg::AuthorizeLoad(uuid) => {
|
||||
WsMsg::Session(WsMsgSession::AuthorizeLoad(uuid)) => {
|
||||
return Ok(self.handle_msg(CheckAuthToken { token: uuid }, ctx)?)
|
||||
}
|
||||
WsMsg::Invitation(WsMsgInvitation::InvitationAcceptRequest(invitation_token)) => {
|
||||
@ -107,27 +107,9 @@ impl WebSocketActor {
|
||||
id: user_project_id,
|
||||
}),
|
||||
|
||||
// auth
|
||||
WsMsg::BindTokenCheck(uuid) => self.exec(CheckBindToken { bind_token: uuid }),
|
||||
WsMsg::AuthenticateRequest(email, name) => self.exec(Authenticate { name, email }),
|
||||
|
||||
// register
|
||||
WsMsg::SignUpRequest(email, username) => self.exec(Register {
|
||||
name: username,
|
||||
email,
|
||||
}),
|
||||
|
||||
// user settings
|
||||
WsMsg::UserSettingSetEditorMode(mode) => {
|
||||
self.exec(user_settings::SetTextEditorMode { mode })
|
||||
}
|
||||
|
||||
// users
|
||||
WsMsg::ProfileUpdate(email, name) => self.exec(ProfileUpdate { name, email }),
|
||||
|
||||
// messages
|
||||
WsMsg::MessagesLoad => self.exec(LoadMessages),
|
||||
WsMsg::MessageMarkSeen(id) => self.exec(MarkMessageSeen { id }),
|
||||
WsMsg::User(m) => self.exec(m),
|
||||
WsMsg::Message(m) => self.exec(m),
|
||||
WsMsg::Session(m) => self.exec(m),
|
||||
|
||||
// hi
|
||||
WsMsg::HighlightCode(lang, code) => self.exec(hi::HighlightCode(lang, code)),
|
||||
@ -169,13 +151,15 @@ impl WebSocketActor {
|
||||
}
|
||||
|
||||
fn require_user(&self) -> Result<&User, WsMsg> {
|
||||
self.current_user.as_ref().ok_or(WsMsg::AuthorizeExpired)
|
||||
self.current_user
|
||||
.as_ref()
|
||||
.ok_or(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
|
||||
fn require_user_project(&self) -> Result<&UserProject, WsMsg> {
|
||||
self.current_user_project
|
||||
.as_ref()
|
||||
.ok_or(WsMsg::AuthorizeExpired)
|
||||
.ok_or(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
|
||||
fn load_user_project(&self) -> Result<UserProject, WsMsg> {
|
||||
@ -184,11 +168,11 @@ impl WebSocketActor {
|
||||
Ok(Ok(user_project)) => Ok(user_project),
|
||||
Ok(Err(e)) => {
|
||||
error!("load_user_project encounter service error {:?}", e);
|
||||
Err(WsMsg::AuthorizeExpired)
|
||||
Err(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
Err(e) => {
|
||||
error!("load_user_project encounter mailbox error {}", e);
|
||||
Err(WsMsg::AuthorizeExpired)
|
||||
Err(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,11 +183,11 @@ impl WebSocketActor {
|
||||
Ok(Ok(project)) => Ok(project),
|
||||
Ok(Err(e)) => {
|
||||
error!("{:?}", e);
|
||||
Err(WsMsg::AuthorizeExpired)
|
||||
Err(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{:?}", e);
|
||||
Err(WsMsg::AuthorizeExpired)
|
||||
Err(WsMsgSession::AuthorizeExpired.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
#![feature(type_ascription, trait_alias, drain_filter)]
|
||||
#![feature(type_ascription, trait_alias, drain_filter, or_patterns)]
|
||||
|
||||
pub use changes::*;
|
||||
pub use components::*;
|
||||
pub use fields::*;
|
||||
pub use images::*;
|
||||
use jirs_data::msg::WsMsgSession;
|
||||
use jirs_data::*;
|
||||
use seed::prelude::*;
|
||||
use web_sys::File;
|
||||
@ -425,7 +426,11 @@ fn authorize_or_redirect(model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
let pathname = seed::document().location().unwrap().pathname().unwrap();
|
||||
match crate::shared::read_auth_token() {
|
||||
Ok(token) => {
|
||||
send_ws_msg(WsMsg::AuthorizeLoad(token), model.ws.as_ref(), orders);
|
||||
send_ws_msg(
|
||||
WsMsgSession::AuthorizeLoad(token).into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
}
|
||||
Err(..) => {
|
||||
match pathname.as_str() {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use jirs_data::msg::WsMsgUser;
|
||||
use jirs_data::{ProjectId, User, UsersFieldId, WsMsg};
|
||||
use seed::prelude::{Method, Orders, Request};
|
||||
use web_sys::FormData;
|
||||
@ -54,9 +55,8 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
|
||||
orders.perform_cmd(update_avatar(fd, model.host_url.clone()));
|
||||
orders.skip();
|
||||
}
|
||||
Msg::WebSocketChange(WebSocketChanged::WsMsg(WsMsg::AvatarUrlChanged(
|
||||
user_id,
|
||||
avatar_url,
|
||||
Msg::WebSocketChange(WebSocketChanged::WsMsg(WsMsg::User(
|
||||
WsMsgUser::AvatarUrlChanged(user_id, avatar_url),
|
||||
))) => {
|
||||
if let Some(User { id, .. }) = model.user.as_mut() {
|
||||
if *id == user_id {
|
||||
@ -69,17 +69,18 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
|
||||
}
|
||||
Msg::U32InputChanged(FieldId::Profile(UsersFieldId::TextEditorMode), v) => {
|
||||
send_ws_msg(
|
||||
WsMsg::UserSettingSetEditorMode(v.into()),
|
||||
WsMsgUser::UserSettingSetEditorMode(v.into()).into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
}
|
||||
Msg::PageChanged(PageChanged::Profile(ProfilePageChange::SubmitForm)) => {
|
||||
send_ws_msg(
|
||||
WsMsg::ProfileUpdate(
|
||||
WsMsgUser::ProfileUpdate(
|
||||
profile_page.email.value.clone(),
|
||||
profile_page.name.value.clone(),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use jirs_data::msg::{WsMsgIssueStatus, WsMsgProject};
|
||||
use jirs_data::msg::{WsMsgIssueStatus, WsMsgProject, WsMsgSession};
|
||||
use jirs_data::{IssueStatus, IssueStatusId, ProjectFieldId, UpdateProjectPayload, WsMsg};
|
||||
use seed::prelude::Orders;
|
||||
|
||||
@ -20,7 +20,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
build_page_content(model, orders);
|
||||
}
|
||||
Msg::WebSocketChange(ref change) => match change {
|
||||
WebSocketChanged::WsMsg(WsMsg::AuthorizeLoaded(..)) => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::AuthorizeLoaded(..))) => {
|
||||
board_load(model, orders);
|
||||
}
|
||||
WebSocketChanged::WsMsg(WsMsg::IssueStatus(WsMsgIssueStatus::IssueStatusCreated(
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use jirs_data::msg::WsMsgSession;
|
||||
use jirs_data::{SignInFieldId, WsMsg};
|
||||
use seed::prelude::*;
|
||||
use seed::*;
|
||||
@ -39,7 +40,7 @@ pub fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>)
|
||||
}
|
||||
Msg::SignInRequest => {
|
||||
send_ws_msg(
|
||||
WsMsg::AuthenticateRequest(page.email.clone(), page.username.clone()),
|
||||
WsMsgSession::AuthenticateRequest(page.email.clone(), page.username.clone()).into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
@ -52,13 +53,17 @@ pub fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>)
|
||||
return;
|
||||
}
|
||||
};
|
||||
send_ws_msg(WsMsg::BindTokenCheck(bind_token), model.ws.as_ref(), orders);
|
||||
send_ws_msg(
|
||||
WsMsgSession::BindTokenCheck(bind_token).into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
}
|
||||
Msg::WebSocketChange(change) => match change {
|
||||
WebSocketChanged::WsMsg(WsMsg::AuthenticateSuccess) => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::AuthenticateSuccess)) => {
|
||||
page.login_success = true;
|
||||
}
|
||||
WebSocketChanged::WsMsg(WsMsg::BindTokenOk(access_token)) => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::BindTokenOk(access_token))) => {
|
||||
match write_auth_token(Some(access_token)) {
|
||||
Ok(msg) => {
|
||||
orders.skip().send_msg(msg);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use jirs_data::msg::WsMsgSession;
|
||||
use jirs_data::{SignUpFieldId, WsMsg};
|
||||
use seed::prelude::*;
|
||||
|
||||
@ -32,16 +33,16 @@ pub fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>)
|
||||
}
|
||||
Msg::SignUpRequest => {
|
||||
send_ws_msg(
|
||||
WsMsg::SignUpRequest(page.email.clone(), page.username.clone()),
|
||||
WsMsgSession::SignUpRequest(page.email.clone(), page.username.clone()).into(),
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
);
|
||||
}
|
||||
Msg::WebSocketChange(change) => match change {
|
||||
WebSocketChanged::WsMsg(WsMsg::SignUpSuccess) => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::SignUpSuccess)) => {
|
||||
page.sign_up_success = true;
|
||||
}
|
||||
WebSocketChanged::WsMsg(WsMsg::SignUpPairTaken) => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::SignUpPairTaken)) => {
|
||||
page.error = "Pair you give is either taken or is not matching".to_string();
|
||||
}
|
||||
_ => (),
|
||||
|
@ -1,4 +1,4 @@
|
||||
use jirs_data::msg::WsMsgInvitation;
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgSession};
|
||||
use jirs_data::{InvitationState, UserRole, UsersFieldId, WsMsg};
|
||||
use seed::prelude::Orders;
|
||||
|
||||
@ -26,7 +26,9 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
invitation_load(model, orders);
|
||||
}
|
||||
Msg::WebSocketChange(change) => match change {
|
||||
WebSocketChanged::WsMsg(WsMsg::AuthorizeLoaded(Ok(_))) if model.user.is_some() => {
|
||||
WebSocketChanged::WsMsg(WsMsg::Session(WsMsgSession::AuthorizeLoaded(Ok(_))))
|
||||
if model.user.is_some() =>
|
||||
{
|
||||
invitation_load(model, orders);
|
||||
}
|
||||
WebSocketChanged::WsMsg(WsMsg::Invitation(WsMsgInvitation::InvitedUsersLoaded(
|
||||
|
@ -1,4 +1,4 @@
|
||||
use jirs_data::msg::WsMsgProject;
|
||||
use jirs_data::msg::{WsMsgMessage, WsMsgProject};
|
||||
use jirs_data::{UserRole, WsMsg};
|
||||
use seed::prelude::*;
|
||||
use seed::*;
|
||||
@ -16,7 +16,7 @@ pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
WsMsg::UserProjectsLoad,
|
||||
WsMsg::Project(WsMsgProject::ProjectsLoad),
|
||||
WsMsg::Project(WsMsgProject::ProjectUsersLoad),
|
||||
WsMsg::MessagesLoad,
|
||||
WsMsg::Message(WsMsgMessage::MessagesLoad),
|
||||
],
|
||||
model.ws.as_ref(),
|
||||
orders,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use jirs_data::msg::WsMsgInvitation;
|
||||
use jirs_data::msg::{WsMsgInvitation, WsMsgMessage};
|
||||
use jirs_data::{InvitationToken, Message, MessageType, WsMsg};
|
||||
use seed::prelude::*;
|
||||
use seed::*;
|
||||
@ -42,7 +42,7 @@ pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Msg::MessageInvitationDismiss(token) => {
|
||||
WsMsgInvitation::InvitationRejectRequest(*token).into()
|
||||
}
|
||||
Msg::MessageSeen(id) => WsMsg::MessageMarkSeen(*id),
|
||||
Msg::MessageSeen(id) => WsMsg::Message(WsMsgMessage::MessageMarkSeen(*id)),
|
||||
_ => return,
|
||||
};
|
||||
send_ws_msg(m, model.ws.as_ref(), orders);
|
||||
|
@ -1,5 +1,8 @@
|
||||
pub use init_load_sets::*;
|
||||
use jirs_data::msg::{WsMsgComment, WsMsgEpic, WsMsgIssue, WsMsgIssueStatus, WsMsgProject};
|
||||
use jirs_data::msg::{
|
||||
WsMsgComment, WsMsgEpic, WsMsgIssue, WsMsgIssueStatus, WsMsgMessage, WsMsgProject,
|
||||
WsMsgSession, WsMsgUser,
|
||||
};
|
||||
use jirs_data::*;
|
||||
use seed::prelude::*;
|
||||
|
||||
@ -92,7 +95,7 @@ pub async fn read_incoming(msg: WebSocketMessage) -> Msg {
|
||||
pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
match msg {
|
||||
// auth
|
||||
WsMsg::AuthorizeLoaded(Ok((user, setting))) => {
|
||||
WsMsg::Session(WsMsgSession::AuthorizeLoaded(Ok((user, setting)))) => {
|
||||
model.user = Some(user);
|
||||
model.user_settings = Some(setting);
|
||||
|
||||
@ -119,7 +122,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
model.user.as_ref().map(|u| u.id),
|
||||
));
|
||||
}
|
||||
WsMsg::AuthorizeExpired => {
|
||||
WsMsg::Session(WsMsgSession::AuthorizeExpired) => {
|
||||
log::warn!("Received token expired");
|
||||
if let Ok(msg) = write_auth_token(None) {
|
||||
orders.skip().send_msg(msg).send_msg(Msg::ResourceChanged(
|
||||
@ -166,7 +169,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
));
|
||||
}
|
||||
// user settings
|
||||
WsMsg::UserSettingUpdated(setting) => {
|
||||
WsMsg::User(WsMsgUser::UserSettingUpdated(setting)) => {
|
||||
model.user_settings = Some(setting);
|
||||
orders.send_msg(Msg::ResourceChanged(
|
||||
ResourceKind::UserSetting,
|
||||
@ -331,7 +334,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Some(comment_id),
|
||||
));
|
||||
}
|
||||
WsMsg::AvatarUrlChanged(user_id, avatar_url) => {
|
||||
WsMsg::User(WsMsgUser::AvatarUrlChanged(user_id, avatar_url)) => {
|
||||
for user in model.users.iter_mut() {
|
||||
if user.id == user_id {
|
||||
user.avatar_url = Some(avatar_url.clone());
|
||||
@ -349,7 +352,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
));
|
||||
}
|
||||
// messages
|
||||
WsMsg::MessageUpdated(mut received) => {
|
||||
WsMsg::Message(WsMsgMessage::MessageUpdated(mut received)) => {
|
||||
if let Some(idx) = model.messages.iter().position(|m| m.id == received.id) {
|
||||
std::mem::swap(&mut model.messages[idx], &mut received);
|
||||
}
|
||||
@ -360,7 +363,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
Some(received.id),
|
||||
));
|
||||
}
|
||||
WsMsg::MessagesLoaded(v) => {
|
||||
WsMsg::Message(WsMsgMessage::MessagesLoaded(v)) => {
|
||||
model.messages = v;
|
||||
model.messages.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
orders.send_msg(Msg::ResourceChanged(
|
||||
@ -369,7 +372,7 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
None,
|
||||
));
|
||||
}
|
||||
WsMsg::MessageMarkedSeen(id, _count) => {
|
||||
WsMsg::Message(WsMsgMessage::MessageMarkedSeen(id, _count)) => {
|
||||
if let Some(idx) = model.messages.iter().position(|m| m.id == id) {
|
||||
model.messages.remove(idx);
|
||||
}
|
||||
|
@ -247,11 +247,7 @@ impl From<WsMsgProject> for WsMsg {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum WsMsg {
|
||||
Ping,
|
||||
Pong,
|
||||
Die,
|
||||
|
||||
pub enum WsMsgSession {
|
||||
// auth
|
||||
AuthorizeLoad(Uuid),
|
||||
AuthorizeLoaded(Result<(User, UserSetting), String>),
|
||||
@ -266,22 +262,16 @@ pub enum WsMsg {
|
||||
SignUpRequest(EmailString, UsernameString),
|
||||
SignUpSuccess,
|
||||
SignUpPairTaken,
|
||||
}
|
||||
|
||||
// invitations
|
||||
Invitation(WsMsgInvitation),
|
||||
|
||||
// project page
|
||||
Project(WsMsgProject),
|
||||
|
||||
// issue
|
||||
Issue(WsMsgIssue),
|
||||
|
||||
// issue status
|
||||
IssueStatus(WsMsgIssueStatus),
|
||||
|
||||
// comments
|
||||
Comment(WsMsgComment),
|
||||
impl From<WsMsgSession> for WsMsg {
|
||||
fn from(msg: WsMsgSession) -> WsMsg {
|
||||
WsMsg::Session(msg)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum WsMsgUser {
|
||||
// users
|
||||
AvatarUrlChanged(UserId, AvatarUrl),
|
||||
ProfileUpdate(EmailString, UsernameString),
|
||||
@ -290,23 +280,52 @@ pub enum WsMsg {
|
||||
// user settings
|
||||
UserSettingUpdated(UserSetting),
|
||||
UserSettingSetEditorMode(TextEditorMode),
|
||||
}
|
||||
|
||||
// user projects
|
||||
UserProjectsLoad,
|
||||
UserProjectsLoaded(Vec<UserProject>),
|
||||
UserProjectSetCurrent(UserProjectId),
|
||||
UserProjectCurrentChanged(UserProject),
|
||||
impl From<WsMsgUser> for WsMsg {
|
||||
fn from(msg: WsMsgUser) -> WsMsg {
|
||||
WsMsg::User(msg)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum WsMsgMessage {
|
||||
// messages
|
||||
MessageUpdated(Message),
|
||||
MessagesLoad,
|
||||
MessagesLoaded(Vec<Message>),
|
||||
MessageMarkSeen(MessageId),
|
||||
MessageMarkedSeen(MessageId, NumberOfDeleted),
|
||||
}
|
||||
|
||||
// epics
|
||||
impl From<WsMsgMessage> for WsMsg {
|
||||
fn from(msg: WsMsgMessage) -> WsMsg {
|
||||
WsMsg::Message(msg)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum WsMsg {
|
||||
Ping,
|
||||
Pong,
|
||||
Die,
|
||||
|
||||
Session(WsMsgSession),
|
||||
Invitation(WsMsgInvitation),
|
||||
Project(WsMsgProject),
|
||||
Issue(WsMsgIssue),
|
||||
IssueStatus(WsMsgIssueStatus),
|
||||
Comment(WsMsgComment),
|
||||
User(WsMsgUser),
|
||||
Message(WsMsgMessage),
|
||||
Epic(WsMsgEpic),
|
||||
|
||||
// user projects
|
||||
UserProjectsLoad,
|
||||
UserProjectsLoaded(Vec<UserProject>),
|
||||
UserProjectSetCurrent(UserProjectId),
|
||||
UserProjectCurrentChanged(UserProject),
|
||||
|
||||
// highlight
|
||||
HighlightCode(Lang, Code),
|
||||
HighlightedCode(HighlightedCode),
|
||||
|
Loading…
Reference in New Issue
Block a user