Fix update avatar

This commit is contained in:
Adrian Woźniak 2021-10-08 15:35:16 +02:00
parent 980d263c87
commit 9ba3f112e6
No known key found for this signature in database
GPG Key ID: DE43476F72AD3F6C
2 changed files with 22 additions and 17 deletions

View File

@ -39,6 +39,12 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
.unwrap_or_default()
.into();
}
Msg::ResourceChanged(ResourceKind::User, OperationKind::SingleModified, Some(id)) => {
profile_page.avatar.url = model
.users_by_id
.get(&id)
.and_then(|u| u.avatar_url.clone());
}
Msg::FileInputChanged(FieldId::Profile(UsersFieldId::Avatar), ..) => {
let file = match profile_page.avatar.file.as_ref() {
Some(f) => f,

View File

@ -169,6 +169,22 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
));
}
// user settings
WsMsg::User(WsMsgUser::AvatarUrlChanged(id, url)) => {
if let Some(user) = model.user.as_mut().filter(|u| u.id == id) {
user.avatar_url = Some(url.clone());
}
if let Some(user) = model.users_by_id.get_mut(&id) {
user.avatar_url = Some(url.clone());
}
if let Some(user) = model.users.iter_mut().find(|u| u.id == id) {
user.avatar_url = Some(url);
}
orders.send_msg(Msg::ResourceChanged(
ResourceKind::User,
OperationKind::SingleModified,
Some(id),
));
}
WsMsg::User(WsMsgUser::UserSettingUpdated(setting)) => {
model.user_settings = Some(setting);
orders.send_msg(Msg::ResourceChanged(
@ -334,23 +350,6 @@ pub fn update(msg: WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
Some(comment_id),
));
}
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());
}
}
if let Some(me) = model.user.as_mut() {
if me.id == user_id {
me.avatar_url = Some(avatar_url);
}
}
orders.send_msg(Msg::ResourceChanged(
ResourceKind::User,
OperationKind::SingleModified,
Some(user_id),
));
}
// messages
WsMsg::Message(WsMsgMessage::MessageUpdated(mut received)) => {
if let Some(idx) = model.messages.iter().position(|m| m.id == received.id) {