mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
The Chat view's tree listed the open board's swimlanes, lists and cards, and every other board as a link that left for that board. Now: - The tree is workspaces > boards > swimlanes > lists > cards, holding the cards that have a conversation on every board the member sees (server/chatView.js chatViewChannels). Every board without one is under Other boards; its first message moves it up to its place. - Each level has a caret before its icon - after it, mirrored, in a right-to-left language - and folds open and shut with a slide (none for a member who asked for reduced motion). Clicking a board folds it; it no longer leaves the Chat view. The board the member is on, its workspaces, swimlanes and lists start open; what they open or close is kept in their browser. - The board the member is on shows all its cards, from the board's own data, so a conversation can start on any card and a dragged card moves in the tree at once; its button shows only the cards with messages. Another board opened from Other boards shows all its cards (chatViewBoardChannels) for the same reason. - Every level shows the messages this member has not read: others' messages after they last opened the card, all of them on a card never opened; opening the card - or a message arriving while it is open - reads it. - Every name, and the chat's header, renders as Markdown (inlineViewer). - Only what the member may read: boards they see in All Boards, only their own cards on an assigned-only board, no conversation where their role reads no comments. Tests: tests/chatView.test.cjs (the tree, Other boards, a first message moving a board up, unread sums, the full board, carets, folding rows, no navigation), server/lib/tests/chatViewChannels.tests.js (unread counts, never my own, the role and assigned-only limits, a board I do not see refused), email-chat-views.e2e.js (folding without leaving the view, the move up, unread badges, Markdown names). New strings translated in all locales. Thanks to xet7 !
88 lines
5.7 KiB
JavaScript
88 lines
5.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { DDP } from 'meteor/ddp';
|
|
import { Random } from 'meteor/random';
|
|
import Boards from '/models/boards';
|
|
import Lists from '/models/lists';
|
|
import Cards from '/models/cards';
|
|
import CardComments from '/models/cardComments';
|
|
import Swimlanes from '/models/swimlanes';
|
|
|
|
// Board View / Chat, the channel tree (server/chatView.js): which cards
|
|
// have a conversation, how much of it this member has not read, and only
|
|
// what they may read.
|
|
describe('Chat view channels', function () {
|
|
this.timeout(60000);
|
|
it('counts conversations and unread messages, and keeps to what the member may read', async function () {
|
|
if (!Meteor.isAppTest) this.skip();
|
|
const me = Random.id(), friend = Random.id();
|
|
const talk = Random.id(), quiet = Random.id(), muted = Random.id(), limited = Random.id(), hidden = Random.id();
|
|
const boardIds = [talk, quiet, muted, limited, hidden];
|
|
const as = userId => (name, ...args) => DDP._CurrentMethodInvocation.withValue(
|
|
{ userId, isSimulation: false, connection: null, setUserId() {}, unblock() {} },
|
|
() => Meteor.server.method_handlers[name].apply({ userId }, args));
|
|
const call = as(me);
|
|
const member = (userId, extra = {}) => ({ userId, isAdmin: false, isActive: true, ...extra });
|
|
try {
|
|
await Meteor.users.rawCollection().insertMany([
|
|
{ _id: me, username: `me-${me}`, profile: { cardLastViews: {} } },
|
|
{ _id: friend, username: `friend-${friend}`, profile: {} },
|
|
]);
|
|
await Boards.rawCollection().insertMany([
|
|
{ _id: talk, title: 'Talk', slug: 'talk', type: 'board', archived: false, permission: 'private', members: [member(me), member(friend)] },
|
|
{ _id: quiet, title: 'Quiet', slug: 'quiet', type: 'board', archived: false, permission: 'private', members: [member(me)] },
|
|
{ _id: muted, title: 'Muted', slug: 'muted', type: 'board', archived: false, permission: 'private', members: [member(me, { isNoComments: true })] },
|
|
{ _id: limited, title: 'Limited', slug: 'limited', type: 'board', archived: false, permission: 'private', members: [member(me, { isNormalAssignedOnly: true })] },
|
|
{ _id: hidden, title: 'Hidden', slug: 'hidden', type: 'board', archived: false, permission: 'private', members: [member(friend)] },
|
|
]);
|
|
const lane = boardId => ({ _id: `${boardId}-s`, boardId, title: 'Lane', sort: 0, archived: false });
|
|
const list = boardId => ({ _id: `${boardId}-l`, boardId, title: 'List', sort: 0, archived: false });
|
|
await Swimlanes.rawCollection().insertMany(boardIds.map(lane));
|
|
await Lists.rawCollection().insertMany(boardIds.map(list));
|
|
const card = (boardId, id, title, extra = {}) => ({ _id: id, boardId, swimlaneId: `${boardId}-s`, listId: `${boardId}-l`, title,
|
|
sort: 0, archived: false, ...extra });
|
|
await Cards.rawCollection().insertMany([
|
|
card(talk, 'c-talk', 'Plan'), card(quiet, 'c-quiet', 'Nothing'), card(muted, 'c-muted', 'Secret'),
|
|
card(limited, 'c-mine', 'Mine', { assignees: [me] }), card(limited, 'c-theirs', 'Theirs', { assignees: [friend] }),
|
|
card(hidden, 'c-hidden', 'Hidden'),
|
|
]);
|
|
const comment = (boardId, cardId, userId, minutesAgo) => ({ _id: Random.id(), boardId, cardId, userId, text: 'x',
|
|
createdAt: new Date(Date.now() - minutesAgo * 60000), modifiedAt: new Date() });
|
|
await CardComments.rawCollection().insertMany([
|
|
comment(talk, 'c-talk', friend, 30), comment(talk, 'c-talk', friend, 5), comment(talk, 'c-talk', me, 4),
|
|
comment(muted, 'c-muted', friend, 1),
|
|
comment(limited, 'c-mine', friend, 1), comment(limited, 'c-theirs', friend, 1),
|
|
comment(hidden, 'c-hidden', friend, 1),
|
|
]);
|
|
// Read up to 10 minutes ago: one of the friend's two messages is new; mine never counts.
|
|
await Meteor.users.rawCollection().updateOne({ _id: me }, { $set: { 'profile.cardLastViews.c-talk': new Date(Date.now() - 10 * 60000) } });
|
|
|
|
const summary = await call('chatViewChannels');
|
|
const byCard = new Map(summary.channels.map(c => [c.cardId, c]));
|
|
assert.deepEqual([byCard.get('c-talk').comments, byCard.get('c-talk').unread], [3, 1]);
|
|
assert.equal(byCard.get('c-mine').unread, 1, 'never opened: every message from others is unread');
|
|
// Negative: no conversation from a board whose role reads no comments,
|
|
// nobody else's card on an assigned-only board, nothing from a board I do not see.
|
|
assert.equal(byCard.has('c-muted'), false);
|
|
assert.equal(byCard.has('c-theirs'), false);
|
|
assert.equal(byCard.has('c-hidden'), false);
|
|
assert.equal(summary.boards.some(b => b._id === hidden), false);
|
|
assert.equal(summary.boards.some(b => b._id === quiet), true, 'a board without a conversation is listed, for Other boards');
|
|
|
|
// A whole board, for a board opened with all its cards.
|
|
const full = await call('chatViewBoardChannels', quiet);
|
|
assert.deepEqual(full.cards.map(c => c.title), ['Nothing']);
|
|
assert.deepEqual([full.swimlanes.length, full.lists.length], [1, 1]);
|
|
const mine = await call('chatViewBoardChannels', limited);
|
|
assert.deepEqual(mine.cards.map(c => c.title), ['Mine'], 'assigned-only: only my cards');
|
|
// Negative: not a board I see, and not signed in.
|
|
await assert.rejects(call('chatViewBoardChannels', hidden), /not-authorized/);
|
|
await assert.rejects(as(null)('chatViewChannels'), /not-authorized/);
|
|
} finally {
|
|
for (const model of [Cards, CardComments, Lists, Swimlanes]) await model.rawCollection().deleteMany({ boardId: { $in: boardIds } });
|
|
await Boards.rawCollection().deleteMany({ _id: { $in: boardIds } });
|
|
await Meteor.users.rawCollection().deleteMany({ _id: { $in: [me, friend] } });
|
|
}
|
|
});
|
|
});
|