FIX: correctly show unread and presence (#22441)
- Presence needs to be explicitly set on the component now - We were not checking and testing correctly the presence of the unread indicator in the menu
This commit is contained in:
parent
4cec091f1a
commit
cfdf5b9518
|
@ -74,11 +74,14 @@ class Search {
|
||||||
#loadExistingChannels() {
|
#loadExistingChannels() {
|
||||||
return this.chatChannelsManager.allChannels
|
return this.chatChannelsManager.allChannels
|
||||||
.map((channel) => {
|
.map((channel) => {
|
||||||
|
let chatable;
|
||||||
if (channel.chatable?.users?.length === 1) {
|
if (channel.chatable?.users?.length === 1) {
|
||||||
return ChatChatable.createUser(channel.chatable.users[0]);
|
chatable = ChatChatable.createUser(channel.chatable.users[0]);
|
||||||
|
chatable.tracking = this.#injectTracking(chatable);
|
||||||
|
} else {
|
||||||
|
chatable = ChatChatable.createChannel(channel);
|
||||||
|
chatable.tracking = channel.tracking;
|
||||||
}
|
}
|
||||||
const chatable = ChatChatable.createChannel(channel);
|
|
||||||
chatable.tracking = channel.tracking;
|
|
||||||
return chatable;
|
return chatable;
|
||||||
})
|
})
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
{{#if (gt @content.tracking.unreadCount 0)}}
|
{{#if (gt @content.tracking.unreadCount 0)}}
|
||||||
<div
|
<div
|
||||||
class={{concat-class
|
class={{concat-class "unread-indicator" (if this.isUrgent "-urgent")}}
|
||||||
"unread-indicator"
|
|
||||||
(if
|
|
||||||
(or
|
|
||||||
@content.model.isDirectMessageChannel
|
|
||||||
(gt @content.model.tracking.mentionCount 0)
|
|
||||||
)
|
|
||||||
"-urgent"
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
></div>
|
></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,12 @@ export default class ChatMessageCreatorChannelRow extends Component {
|
||||||
get openChannelLabel() {
|
get openChannelLabel() {
|
||||||
return htmlSafe(I18n.t("chat.new_message_modal.open_channel"));
|
return htmlSafe(I18n.t("chat.new_message_modal.open_channel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isUrgent() {
|
||||||
|
return (
|
||||||
|
this.args.content.model.isDirectMessageChannel ||
|
||||||
|
(this.args.content.model.isCategoryChannel &&
|
||||||
|
this.args.content.model.tracking.mentionCount > 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<ChatUserDisplayName @user={{@content.model}} />
|
<ChatUserDisplayName @user={{@content.model}} />
|
||||||
|
|
||||||
{{#if (gt @content.tracking.unreadCount 0)}}
|
{{#if (gt @content.tracking.unreadCount 0)}}
|
||||||
<div class="unread-indicator"></div>
|
<div class="unread-indicator -urgent"></div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{user-status @content.model currentUser=this.currentUser}}
|
{{user-status @content.model currentUser=this.currentUser}}
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
{{#if @message.chatWebhookEvent.emoji}}
|
{{#if @message.chatWebhookEvent.emoji}}
|
||||||
<ChatEmojiAvatar @emoji={{@message.chatWebhookEvent.emoji}} />
|
<ChatEmojiAvatar @emoji={{@message.chatWebhookEvent.emoji}} />
|
||||||
{{else}}
|
{{else}}
|
||||||
<ChatUserAvatar @user={{@message.user}} @avatarSize="medium" />
|
<ChatUserAvatar
|
||||||
|
@showPresence={{true}}
|
||||||
|
@user={{@message.user}}
|
||||||
|
@avatarSize="medium"
|
||||||
|
/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
|
@ -37,22 +37,35 @@ RSpec.describe "New message", type: :system do
|
||||||
chat_page.open_new_message
|
chat_page.open_new_message
|
||||||
|
|
||||||
expect(chat_page.message_creator).to be_listing(channel_1)
|
expect(chat_page.message_creator).to be_listing(channel_1)
|
||||||
# it lists user_1 instead of this channel as it's a 1:1 channel
|
|
||||||
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
||||||
expect(chat_page.message_creator).to be_not_listing(
|
expect(chat_page.message_creator).to be_not_listing(direct_message_channel_2)
|
||||||
direct_message_channel_1,
|
|
||||||
current_user: current_user,
|
|
||||||
)
|
|
||||||
expect(chat_page.message_creator).to be_not_listing(
|
|
||||||
direct_message_channel_2,
|
|
||||||
current_user: current_user,
|
|
||||||
)
|
|
||||||
expect(chat_page.message_creator).to be_listing(user_1)
|
expect(chat_page.message_creator).to be_listing(user_1)
|
||||||
expect(chat_page.message_creator).to be_not_listing(user_2)
|
expect(chat_page.message_creator).to be_not_listing(user_2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with no selection" do
|
context "with no selection" do
|
||||||
|
context "with unread state" do
|
||||||
|
fab!(:user_1) { Fabricate(:user) }
|
||||||
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||||
|
fab!(:channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
channel_1.add(user_1)
|
||||||
|
channel_1.add(current_user)
|
||||||
|
Fabricate(:chat_message, chat_channel: channel_1, user: user_1)
|
||||||
|
Fabricate(:chat_message, chat_channel: channel_2, user: user_1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows the correct state" do
|
||||||
|
visit("/")
|
||||||
|
chat_page.open_new_message
|
||||||
|
|
||||||
|
expect(chat_page.message_creator).to have_unread_row(channel_1, urgent: false)
|
||||||
|
expect(chat_page.message_creator).to have_unread_row(user_1, urgent: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when clicking a row" do
|
context "when clicking a row" do
|
||||||
context "when the row is a channel" do
|
context "when the row is a channel" do
|
||||||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||||
|
|
|
@ -25,6 +25,7 @@ module PageObjects
|
||||||
|
|
||||||
def open_new_message
|
def open_new_message
|
||||||
send_keys([MODIFIER, "k"])
|
send_keys([MODIFIER, "k"])
|
||||||
|
find(".chat-new-message-modal")
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_drawer?(channel_id: nil, expanded: true)
|
def has_drawer?(channel_id: nil, expanded: true)
|
||||||
|
|
|
@ -84,6 +84,14 @@ module PageObjects
|
||||||
component.find(build_row_selector(chatable, **args)).click(:shift)
|
component.find(build_row_selector(chatable, **args)).click(:shift)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_unread_row?(chatable, **args)
|
||||||
|
unread_selector = build_row_selector(chatable, **args)
|
||||||
|
unread_selector += " .unread-indicator"
|
||||||
|
unread_selector += ".-urgent" if args[:urgent]
|
||||||
|
unread_selector += ":not(.-urgent)" unless args[:urgent]
|
||||||
|
component.has_css?(unread_selector)
|
||||||
|
end
|
||||||
|
|
||||||
def build_item_selector(chatable, **args)
|
def build_item_selector(chatable, **args)
|
||||||
selector = ".chat-message-creator__selection-item"
|
selector = ".chat-message-creator__selection-item"
|
||||||
selector += content_selector(**args)
|
selector += content_selector(**args)
|
||||||
|
@ -94,7 +102,7 @@ module PageObjects
|
||||||
def build_row_selector(chatable, **args)
|
def build_row_selector(chatable, **args)
|
||||||
selector = ".chat-message-creator__row"
|
selector = ".chat-message-creator__row"
|
||||||
selector += content_selector(**args)
|
selector += content_selector(**args)
|
||||||
selector += chatable_selector(chatable)
|
selector += chatable_selector(chatable, **args)
|
||||||
selector
|
selector
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,7 +119,7 @@ module PageObjects
|
||||||
selector
|
selector
|
||||||
end
|
end
|
||||||
|
|
||||||
def chatable_selector(chatable)
|
def chatable_selector(chatable, **args)
|
||||||
selector = ""
|
selector = ""
|
||||||
if chatable.try(:category_channel?)
|
if chatable.try(:category_channel?)
|
||||||
selector += ".-channel"
|
selector += ".-channel"
|
||||||
|
|
|
@ -4,6 +4,7 @@ RSpec.describe "User presence", type: :system do
|
||||||
fab!(:channel_1) { Fabricate(:chat_channel) }
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||||
fab!(:current_user) { Fabricate(:user) }
|
fab!(:current_user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
||||||
let(:channel) { PageObjects::Pages::ChatChannel.new }
|
let(:channel) { PageObjects::Pages::ChatChannel.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -13,20 +14,20 @@ RSpec.describe "User presence", type: :system do
|
||||||
|
|
||||||
it "shows presence indicator" do
|
it "shows presence indicator" do
|
||||||
sign_in(current_user)
|
sign_in(current_user)
|
||||||
chat.visit_channel(channel_1)
|
chat_page.visit_channel(channel_1)
|
||||||
channel.send_message("Am I present?")
|
channel.send_message("Am I present?")
|
||||||
|
|
||||||
expect(page).to have_selector(".chat-user-avatar.is-online")
|
expect(page).to have_css(".chat-message .chat-user-avatar.is-online")
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when user hides presence" do
|
context "when user hides presence" do
|
||||||
it "hides the presence indicator" do
|
it "hides the presence indicator" do
|
||||||
current_user.user_option.update!(hide_profile_and_presence: true)
|
current_user.user_option.update!(hide_profile_and_presence: true)
|
||||||
sign_in(current_user)
|
sign_in(current_user)
|
||||||
chat.visit_channel(channel_1)
|
chat_page.visit_channel(channel_1)
|
||||||
channel.send_message("Am I present?")
|
channel.send_message("Am I present?")
|
||||||
|
|
||||||
expect(page).to have_no_selector(".chat-user-avatar.is-online")
|
expect(page).to have_no_css(".chat-user-avatar.is-online")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue