Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW][ENTERPRISE] Hide message history for new channel members #20253

Merged
merged 61 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
3df0fab
refactor find visible messages
g-thome Jan 10, 2021
1704c99
Merge branch 'develop' into feat/filter-messages
sampaiodiego Jan 14, 2021
1cca418
Create Message DB service
sampaiodiego Jan 14, 2021
116d68c
Use Message DB service to get messages
sampaiodiego Jan 14, 2021
1dceb5f
Potential places to use Message DB service
sampaiodiego Jan 14, 2021
595ca58
rename notContainingTypes key to excludeTypes
g-thome Jan 15, 2021
6e1954c
add new field in room document
g-thome Jan 15, 2021
77f4c88
apply business logic for findVisibleByRoomId
g-thome Jan 15, 2021
59d96a5
missing todos
g-thome Jan 15, 2021
5aee38a
findVisibleByMentionAndRoomId
g-thome Jan 18, 2021
fb3b220
refactor and replace of snippeted
g-thome Jan 18, 2021
ddf9767
linter errors
g-thome Jan 18, 2021
14b43b7
more linting
g-thome Jan 18, 2021
6cb4e38
Merge branch 'develop' into db-service
sampaiodiego Jan 18, 2021
428a731
Fix TS lint
sampaiodiego Jan 18, 2021
a5f22ae
Postpone some points
sampaiodiego Jan 18, 2021
c827914
allow for custom queries
g-thome Jan 19, 2021
ae6c143
...ById
g-thome Jan 20, 2021
87dcc86
add unimplemented methods
g-thome Jan 20, 2021
dedfbff
linting errors
g-thome Jan 20, 2021
cdfac5a
fix typecheck
g-thome Jan 20, 2021
484195c
remove logs
g-thome Jan 20, 2021
5bfc49c
fix typo
g-thome Jan 20, 2021
c5aa860
fix getThreadsList
g-thome Jan 20, 2021
fe99e29
fix getDeleted
g-thome Jan 20, 2021
5cd1c63
fix threads
g-thome Jan 21, 2021
6869316
fix files
g-thome Jan 21, 2021
3b58590
increase timeout for oembed test
g-thome Jan 21, 2021
0964199
Added option to enable history hiding when creating a new room
pierre-lehnen-rc Jan 21, 2021
a1b9aa7
add cursor count
g-thome Jan 22, 2021
f0209fe
missing count
g-thome Jan 22, 2021
d1ee2fd
revert breaking change
g-thome Jan 22, 2021
d5503b8
remove duplicate timestamp logic
g-thome Jan 22, 2021
a8b0e63
Merge remote-tracking branch 'origin/develop' into db-service
rodrigok Jan 22, 2021
87bf788
Remove uncessary TODOs
rodrigok Jan 22, 2021
be628f0
Remove uncessary change
rodrigok Jan 22, 2021
b4b3cf7
Solve LGTM problems
rodrigok Jan 22, 2021
4e844f5
Merge remote-tracking branch 'origin/develop' into db-service
rodrigok Jan 22, 2021
82a046a
pt-br localization
pierre-lehnen-rc Jan 22, 2021
efa3385
Simplify excludeTypes
rodrigok Jan 22, 2021
9a94f15
Merge branch 'db-service' of https://github.com/RocketChat/Rocket.Cha…
rodrigok Jan 22, 2021
529f65f
Undo uncessary change
rodrigok Jan 22, 2021
d013983
Fix Message.get and total
rodrigok Jan 22, 2021
de1ed46
Fix return of totals
rodrigok Jan 22, 2021
b74c4fc
Fix last issues with totals
rodrigok Jan 22, 2021
4d7debe
Small fixes
rodrigok Jan 22, 2021
032328b
Fix error on tests
rodrigok Jan 22, 2021
4fe6189
Fix find for snippets
rodrigok Jan 22, 2021
1cf019c
Fix findThreads
rodrigok Jan 22, 2021
6290630
Fix issue with chat.syncThreadsList and chat.syncThreadMessages
rodrigok Jan 22, 2021
ba9b29a
Fix tests
rodrigok Jan 22, 2021
ea6957a
Undo cleanRoomHistory
rodrigok Jan 22, 2021
767b91d
add filter for pinned messages
g-thome Jan 22, 2021
55206ad
Put back new model methods in cleanRoomHistory
rodrigok Jan 22, 2021
71f1b49
Merge branch 'db-service' of https://github.com/RocketChat/Rocket.Cha…
rodrigok Jan 22, 2021
97c3cf6
fix typecheck
g-thome Jan 22, 2021
2c2de91
Simplify services
rodrigok Jan 22, 2021
9119cf4
Add option to hide/show history on discussions too.
pierre-lehnen-rc Jan 23, 2021
ca4e988
Option to enable/disable history for new users through the room sidebar.
pierre-lehnen-rc Jan 23, 2021
7dfc684
Merge branch 'develop' into db-service
sampaiodiego Jan 23, 2021
7a90530
Remove console.log
sampaiodiego Jan 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 20 additions & 21 deletions app/api/server/lib/messages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom';
import { Rooms, Messages, Users } from '../../../models/server/raw';
import { getValue } from '../../../settings/server/raw';
import { Message } from '../../../../server/sdk';

export async function findMentionedMessages({ uid, roomId, pagination: { offset, count, sort } }) {
const room = await Rooms.findOneById(roomId);
Expand All @@ -12,16 +13,16 @@ export async function findMentionedMessages({ uid, roomId, pagination: { offset,
throw new Error('invalid-user');
}

const cursor = await Messages.findVisibleByMentionAndRoomId(user.username, roomId, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
const { records: messages, total } = await Message.get(uid, {
rodrigok marked this conversation as resolved.
Show resolved Hide resolved
rid: roomId,
mentionsUsername: user.username,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
},
});

const total = await cursor.count();

const messages = await cursor.toArray();

return {
messages,
count: messages.length,
Expand Down Expand Up @@ -98,15 +99,13 @@ export async function findSnippetedMessages({ uid, roomId, pagination: { offset,
throw new Error('error-not-allowed');
}

const cursor = await Messages.findSnippetedByRoom(roomId, {
const queryOptions = {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
});

const total = await cursor.count();
};

const messages = await cursor.toArray();
const { records: messages, total } = await Message.get(uid, { snippeted: true, queryOptions });

return {
messages,
Expand All @@ -123,16 +122,16 @@ export async function findDiscussionsFromRoom({ uid, roomId, text, pagination: {
throw new Error('error-not-allowed');
}

const cursor = Messages.findDiscussionsByRoomAndText(roomId, text, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
const { records: messages, total } = await Message.getDiscussions({
rid: roomId,
text,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
},
});

const total = await cursor.count();

const messages = await cursor.toArray();

return {
messages,
count: messages.length,
Expand Down
24 changes: 13 additions & 11 deletions app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mountIntegrationQueryBasedOnPermissions } from '../../../integrations/s
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { API } from '../api';
import { settings } from '../../../settings';
import { Message } from '../../../../server/sdk';


// Returns the channel IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Expand Down Expand Up @@ -337,12 +338,12 @@ API.v1.addRoute('channels.history', { authRequired: true }, {
get() {
const findResult = findChannelByIdOrName({ params: this.requestParams(), checkedArchived: false });

let latestDate = new Date();
let latestDate;
if (this.queryParams.latest) {
latestDate = new Date(this.queryParams.latest);
}

let oldestDate = undefined;
let oldestDate;
if (this.queryParams.oldest) {
oldestDate = new Date(this.queryParams.oldest);
}
Expand Down Expand Up @@ -576,15 +577,16 @@ API.v1.addRoute('channels.messages', { authRequired: true }, {
return API.v1.unauthorized();
}

const cursor = Messages.find(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
});

const total = cursor.count();
const messages = cursor.fetch();
const { records: messages, total } = Promise.await(Message.customQuery({
query: ourQuery,
userId: this.userId,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
messages: normalizeMessagesForUser(messages, this.userId),
Expand Down
53 changes: 31 additions & 22 deletions app/api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';

import { Messages } from '../../../models';
import { Message } from '../../../../server/sdk';
import { canAccessRoom, hasPermission } from '../../../authorization';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { processWebhookMessage } from '../../../lib/server';
Expand Down Expand Up @@ -408,6 +409,7 @@ API.v1.addRoute('chat.getPinnedMessages', { authRequired: true }, {
throw new Meteor.Error('error-not-allowed', 'Not allowed');
}

// TODO evaluate limit history visibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement the filter here

const cursor = Messages.findPinnedByRoom(room._id, {
skip: offset,
limit: count,
Expand Down Expand Up @@ -456,16 +458,17 @@ API.v1.addRoute('chat.getThreadsList', { authRequired: true }, {
};

const threadQuery = { ...query, ...typeThread, rid, tcount: { $exists: true } };
const cursor = Messages.find(threadQuery, {
sort: sort || { tlm: -1 },
skip: offset,
limit: count,
fields,
});

const total = cursor.count();

const threads = cursor.fetch();
const { records: threads, total } = Promise.await(Message.customQuery({
query: threadQuery,
userId: this.userId,
queryOptions: {
sort: sort || { tlm: -1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
threads,
Expand Down Expand Up @@ -501,11 +504,12 @@ API.v1.addRoute('chat.syncThreadsList', { authRequired: true }, {
if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not Allowed');
}
const threadQuery = Object.assign({}, query, { rid, tcount: { $exists: true } });
const threadQuery = { ...query, rid, tcount: { $exists: true } };

return API.v1.success({
threads: {
update: Messages.find({ ...threadQuery, _updatedAt: { $gt: updatedSinceDate } }, { fields, sort }).fetch(),
remove: Messages.trashFindDeletedAfter(updatedSinceDate, threadQuery, { fields, sort }).fetch(),
update: Promise.await(Message.customQuery({ query: { ...threadQuery, _updatedAt: { $gt: updatedSinceDate } }, queryOptions: { returnTotal: false, fields, sort } })).records,
remove: Promise.await(Message.getDeleted({ rid, userId: this.userId, timestamp: updatedSinceDate, query: threadQuery, queryOptions: { returnTotal: false, fields, sort } })).records,
},
});
},
Expand Down Expand Up @@ -533,16 +537,19 @@ API.v1.addRoute('chat.getThreadMessages', { authRequired: true }, {
if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not Allowed');
}
const cursor = Messages.find({ ...query, tmid }, {
sort: sort || { ts: 1 },
skip: offset,
limit: count,
fields,
});

const total = cursor.count();
const ourQuery = Object.assign({}, query, { rid: thread.rid, tmid });

const messages = cursor.fetch();
const { records: messages, total } = Promise.await(Message.customQuery({
query: ourQuery,
userId: this.userId,
queryOptions: {
sort: sort || { ts: 1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
messages,
Expand Down Expand Up @@ -573,6 +580,7 @@ API.v1.addRoute('chat.syncThreadMessages', { authRequired: true }, {
} else {
updatedSinceDate = new Date(updatedSince);
}

const thread = Messages.findOneById(tmid, { fields: { rid: 1 } });
if (!thread || !thread.rid) {
throw new Meteor.Error('error-invalid-message', 'Invalid Message');
Expand All @@ -583,10 +591,11 @@ API.v1.addRoute('chat.syncThreadMessages', { authRequired: true }, {
if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not Allowed');
}

return API.v1.success({
messages: {
update: Messages.find({ ...query, tmid, _updatedAt: { $gt: updatedSinceDate } }, { fields, sort }).fetch(),
remove: Messages.trashFindDeletedAfter(updatedSinceDate, { ...query, tmid }, { fields, sort }).fetch(),
update: Promise.await(Message.customQuery({ query: { ...query, tmid, _updatedAt: { $gt: updatedSinceDate } }, queryOptions: { returnTotal: false, fields, sort } })).records,
remove: Promise.await(Message.getDeleted({ rid: thread.rid, timestamp: updatedSinceDate, query: { ...query, tmid }, queryOptions: { returnTotal: false, fields, sort } })).records,
},
});
},
Expand Down
19 changes: 12 additions & 7 deletions app/api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Subscriptions, Rooms, Messages, Uploads, Integrations, Users } from '..
import { hasPermission, hasAtLeastOnePermission, canAccessRoom } from '../../../authorization/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { API } from '../api';
import { Message } from '../../../../server/sdk';

// Returns the private group subscription IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
export function findPrivateGroupByIdOrName({ params, userId, checkedArchived = true }) {
Expand Down Expand Up @@ -525,18 +526,22 @@ API.v1.addRoute('groups.messages', { authRequired: true }, {

const ourQuery = Object.assign({}, query, { rid: findResult.rid });

const messages = Messages.find(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
}).fetch();
const { records: messages, total } = Promise.await(Message.customQuery({
query: ourQuery,
userId: this.userId,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
messages: normalizeMessagesForUser(messages, this.userId),
count: messages.length,
offset,
total: Messages.find(ourQuery).count(),
total,
});
},
});
Expand Down
39 changes: 24 additions & 15 deletions app/api/server/v1/im.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Meteor } from 'meteor/meteor';

import { Subscriptions, Uploads, Users, Messages, Rooms } from '../../../models';
import { Subscriptions, Uploads, Users, Rooms } from '../../../models';
import { hasPermission } from '../../../authorization';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { settings } from '../../../settings';
import { API } from '../api';
import { getDirectMessageByNameOrIdWithOptionToJoin } from '../../../lib/server/functions/getDirectMessageByNameOrIdWithOptionToJoin';
import { Message } from '../../../../server/sdk';

function findDirectMessageRoom(params, user) {
if ((!params.roomId || !params.roomId.trim()) && (!params.username || !params.username.trim())) {
Expand Down Expand Up @@ -234,18 +235,22 @@ API.v1.addRoute(['dm.messages', 'im.messages'], { authRequired: true }, {

const ourQuery = Object.assign({}, query, { rid: findResult.room._id });

const messages = Messages.find(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
}).fetch();
const { records: messages, total } = Promise.await(Message.customQuery({
query: ourQuery,
userId: this.userId,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
messages: normalizeMessagesForUser(messages, this.userId),
count: messages.length,
offset,
total: Messages.find(ourQuery).count(),
total,
});
},
});
Expand Down Expand Up @@ -274,18 +279,22 @@ API.v1.addRoute(['dm.messages.others', 'im.messages.others'], { authRequired: tr
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, { rid: room._id });

const msgs = Messages.find(ourQuery, {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
}).fetch();
const { records: msgs, total } = Promise.await(Message.customQuery({
query: ourQuery,
userId: this.userId,
queryOptions: {
sort: sort || { ts: -1 },
skip: offset,
limit: count,
fields,
},
}));

return API.v1.success({
messages: normalizeMessagesForUser(msgs, this.userId),
offset,
count: msgs.length,
total: Messages.find(ourQuery).count(),
total,
});
},
});
Expand Down