FEATURE: propagate user status via message bus (#16944)
This commit is contained in:
parent
46302f0d40
commit
943cae82da
|
@ -112,6 +112,10 @@ export default {
|
||||||
user.updateDoNotDisturbStatus(data.ends_at);
|
user.updateDoNotDisturbStatus(data.ends_at);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bus.subscribe(`/user-status/${user.id}`, (data) => {
|
||||||
|
user.updateStatus(data);
|
||||||
|
});
|
||||||
|
|
||||||
const site = container.lookup("site:main");
|
const site = container.lookup("site:main");
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
const router = container.lookup("router:main");
|
const router = container.lookup("router:main");
|
||||||
|
|
|
@ -1002,6 +1002,11 @@ const User = RestModel.extend({
|
||||||
this.appEvents.trigger("do-not-disturb:changed", this.do_not_disturb_until);
|
this.appEvents.trigger("do-not-disturb:changed", this.do_not_disturb_until);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateStatus(status) {
|
||||||
|
this.set("status", status);
|
||||||
|
this.appEvents.trigger("user-status:changed");
|
||||||
|
},
|
||||||
|
|
||||||
isInDoNotDisturb() {
|
isInDoNotDisturb() {
|
||||||
return (
|
return (
|
||||||
this.do_not_disturb_until &&
|
this.do_not_disturb_until &&
|
||||||
|
|
|
@ -11,8 +11,7 @@ export default class UserStatusService extends Service {
|
||||||
data: { description: status.description },
|
data: { description: status.description },
|
||||||
});
|
});
|
||||||
|
|
||||||
this.currentUser.set("status", status);
|
this.currentUser.updateStatus(status);
|
||||||
this.appEvents.trigger("do-not-disturb:changed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async clear() {
|
async clear() {
|
||||||
|
@ -21,7 +20,6 @@ export default class UserStatusService extends Service {
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.currentUser.set("status", null);
|
this.currentUser.updateStatus(null);
|
||||||
this.appEvents.trigger("do-not-disturb:changed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -653,6 +653,14 @@ class User < ActiveRecord::Base
|
||||||
MessageBus.publish("/do-not-disturb/#{id}", { ends_at: ends_at&.httpdate }, user_ids: [id])
|
MessageBus.publish("/do-not-disturb/#{id}", { ends_at: ends_at&.httpdate }, user_ids: [id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publish_user_status(status)
|
||||||
|
payload = status ?
|
||||||
|
{ description: status.description, emoji: status.emoji } :
|
||||||
|
nil
|
||||||
|
|
||||||
|
MessageBus.publish("/user-status/#{id}", payload, user_ids: [id])
|
||||||
|
end
|
||||||
|
|
||||||
def password=(password)
|
def password=(password)
|
||||||
# special case for passwordless accounts
|
# special case for passwordless accounts
|
||||||
unless password.blank?
|
unless password.blank?
|
||||||
|
@ -1503,6 +1511,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
def clear_status!
|
def clear_status!
|
||||||
user_status.destroy! if user_status
|
user_status.destroy! if user_status
|
||||||
|
publish_user_status(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_status!(description)
|
def set_status!(description)
|
||||||
|
@ -1516,6 +1525,8 @@ class User < ActiveRecord::Base
|
||||||
set_at: now
|
set_at: now
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
publish_user_status(user_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -47,6 +47,15 @@ describe UserStatusController do
|
||||||
user.reload
|
user.reload
|
||||||
expect(user.user_status.description).to eq(new_status)
|
expect(user.user_status.description).to eq(new_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "publishes to message bus" do
|
||||||
|
status = "off to dentist"
|
||||||
|
messages = MessageBus.track_publish { put "/user-status.json", params: { description: status } }
|
||||||
|
|
||||||
|
expect(messages.size).to eq(1)
|
||||||
|
expect(messages[0].channel).to eq("/user-status/#{user.id}")
|
||||||
|
expect(messages[0].data[:description]).to eq(status)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,6 +90,14 @@ describe UserStatusController do
|
||||||
user.reload
|
user.reload
|
||||||
expect(user.user_status).to be_nil
|
expect(user.user_status).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "publishes to message bus" do
|
||||||
|
messages = MessageBus.track_publish { delete "/user-status.json" }
|
||||||
|
|
||||||
|
expect(messages.size).to eq(1)
|
||||||
|
expect(messages[0].channel).to eq("/user-status/#{user.id}")
|
||||||
|
expect(messages[0].data).to eq(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue