[FIX] mail: wrong use of group_based_subscription

1. `searchPartnerSuggestions` uses`authorizedGroupFullName` to see
if the channel is public or not
2. `filteredThreads` and `getThreads` uses `hasSelfAsMember`
and `is_pinned` along with the channel type
3. search should use `displayName` otherwise the search on group
with default empty name will fail
4. fix tests.

closes odoo/odoo#140495

X-original-commit: b358c410988686610638e7ffbee1fbbbeff5f0ba
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
zel-odoo
2023-11-02 18:23:12 +00:00
parent 442edacee2
commit cf86759d1d
6 changed files with 29 additions and 13 deletions
@@ -100,7 +100,7 @@ export class SuggestionService {
thread &&
(thread.type === "group" ||
thread.type === "chat" ||
(thread.type === "channel" && thread.group_based_subscription));
(thread.type === "channel" && thread.authorizedGroupFullName));
if (isNonPublicChannel) {
// Only return the channel members when in the context of a
// group restricted channel. Indeed, the message with the mention
@@ -324,6 +324,10 @@ export class Thread extends Record {
return this.name;
}
get displayToSelf() {
return this.is_pinned || (["channel", "group"].includes(this.type) && this.hasSelfAsMember);
}
/** @type {import("models").Persona[]} */
get correspondents() {
return this.channelMembers
@@ -113,7 +113,7 @@ export class MessagingMenu extends Component {
/** @type {import("@mail/core/common/thread_model").Thread[]} */
let threads = Object.values(this.store.Thread.records).filter(
(thread) =>
thread.is_pinned ||
thread.displayToSelf ||
(thread.needactionMessages.length > 0 && thread.type !== "mailbox")
);
const tab = this.store.discuss.activeTab;
@@ -84,7 +84,7 @@ export class DiscussSidebarCategories extends Component {
filteredThreads(category) {
return category.threads.filter((thread) => {
return (
(thread.is_pinned || thread.group_based_subscription) &&
thread.displayToSelf &&
(!this.state.quickSearchVal ||
cleanTerm(thread.name).includes(cleanTerm(this.state.quickSearchVal)))
);
@@ -78,7 +78,12 @@ QUnit.test("Sort partner suggestions by recent chats", async () => {
{ partner_id: partner_3 },
]);
pyEnv["discuss.channel"].create([
{ name: "General", channel_type: "channel" },
{ name: "General", channel_type: "channel", channel_member_ids: [
Command.create({ partner_id: pyEnv.currentPartnerId }),
Command.create({ partner_id: partner_1 }),
Command.create({ partner_id: partner_2 }),
Command.create({ partner_id: partner_3 }),
]},
{
channel_member_ids: [
Command.create({
@@ -299,23 +299,30 @@ QUnit.test("sidebar: open channel and leave it", async (assert) => {
assert.verifySteps(["action_unfollow"]);
});
QUnit.test("sidebar: unpin channel from bus", async () => {
QUnit.test("sidebar: unpin chat from bus", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General" });
const partnerId = pyEnv["res.partner"].create({ name: "Demo" });
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
Command.create({ partner_id: pyEnv.currentPartnerId }),
Command.create({ partner_id: partnerId }),
],
channel_type: "chat",
});
const { openDiscuss } = await start();
openDiscuss();
await contains(".o-mail-DiscussSidebarChannel", { text: "General" });
await contains(".o-mail-DiscussSidebarChannel", { text: "Demo" });
await click(".o-mail-DiscussSidebarChannel", { text: "General" });
await contains(".o-mail-Composer-input[placeholder='Message #General…']");
await contains(".o-mail-Discuss-threadName", { value: "General" });
await click(".o-mail-DiscussSidebarChannel", { text: "Demo" });
await contains(".o-mail-Composer-input[placeholder='Message Demo…']");
await contains(".o-mail-Discuss-threadName", { value: "Demo" });
// Simulate receiving a leave channel notification
// Simulate receiving a unpin chat notification
// (e.g. from user interaction from another device or browser tab)
pyEnv["bus.bus"]._sendone(pyEnv.currentPartner, "discuss.channel/unpin", { id: channelId });
await contains(".o-mail-DiscussSidebarChannel", { count: 0, text: "General" });
await contains(".o-mail-DiscussSidebarChannel", { count: 0, text: "Demo" });
await contains(".o-mail-Discuss-threadName", { count: 0, value: "General" });
await contains(".o-mail-Discuss-threadName", { count: 0, value: "Demo" });
});
QUnit.test("chat - channel should count unread message [REQUIRE FOCUS]", async () => {