Skip to content

Commit

Permalink
Fix last issues with totals
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Jan 22, 2021
1 parent de1ed46 commit 3182111
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/api/server/v1/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, {

Meteor.runAsUser(this.userId, () => Meteor.call('cleanRoomHistory', {
roomId: findResult._id,
userId: this.userId,
latest,
oldest,
inclusive,
Expand Down
7 changes: 4 additions & 3 deletions app/lib/server/functions/cleanRoomHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function cleanRoomHistory({ rid, userId, latest, oldest, inclusive = true

let fileCount = 0;

const files = Promise.await(Message.getFiles({
const { records: files } = Promise.await(Message.getFiles({
rid,
userId,
excludePinned,
Expand All @@ -27,6 +27,7 @@ export function cleanRoomHistory({ rid, userId, latest, oldest, inclusive = true
fromUsers,
ignoreThreads,
queryOptions: {
returnTotal: false,
fields: { 'file._id': 1, pinned: 1 },
limit,
},
Expand Down Expand Up @@ -62,8 +63,8 @@ export function cleanRoomHistory({ rid, userId, latest, oldest, inclusive = true

if (!ignoreThreads) {
const threads = new Set();
Promise.await(Message.getThreadsByRoomId({ rid, userId, pinned: excludePinned, ignoreDiscussion, ts, users: fromUsers }, { fields: { _id: 1 } }))
.map(({ _id }) => threads.add(_id));
Promise.await(Message.getThreadsByRoomId({ rid, userId, pinned: excludePinned, ignoreDiscussion, ts, users: fromUsers, queryOptions: { returnTotal: false, fields: { _id: 1 } } }))
.records.map(({ _id }) => threads.add(_id));

if (threads.size > 0) {
Subscriptions.removeUnreadThreadsByRoomId(rid, [...threads]);
Expand Down
2 changes: 1 addition & 1 deletion app/livechat/server/hooks/sendToCRM.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { settings } from '../../../settings';
import { callbacks } from '../../../callbacks';
import { Messages, LivechatRooms } from '../../../models';
import { Messages, LivechatRooms } from '../../../models/server';
import { Livechat } from '../lib/Livechat';
import { normalizeMessageFileUpload } from '../../../utils/server/functions/normalizeMessageFileUpload';

Expand Down
2 changes: 1 addition & 1 deletion app/message-mark-as-unread/server/unreadMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Meteor.methods({
}

if (room) {
const lastMessage = Messages.findVisibleByRoomId(room, { limit: 1, sort: { ts: -1 } }).fetch()[0];
const lastMessage = Messages.findVisibleByRoomId({rid: room._id, queryOptions: { limit: 1, sort: { ts: -1 } }).fetch()[0];

if (lastMessage == null) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
Expand Down
3 changes: 2 additions & 1 deletion app/threads/server/methods/getThreadMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ Meteor.methods({
readThread({ userId: user._id, rid: thread.rid, tmid });

const threadQueryOptions = {
returnTotal: false,
...skip && { skip },
...limit && { limit },
sort: { ts: -1 },
};

const result = Promise.await(Message.getThreadById({ tmid, queryOptions: threadQueryOptions }));
const { records: result } = Promise.await(Message.getThreadById({ tmid, queryOptions: threadQueryOptions }));

return [thread, ...result];
},
Expand Down
2 changes: 1 addition & 1 deletion app/threads/server/methods/getThreadsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Meteor.methods({
throw new Meteor.Error('error-not-allowed', 'Not Allowed', { method: 'getThreadsList' });
}

return Promise.await(Message.getThreadsByRoomId({ rid, queryOptions: { skip, limit } }));
return Promise.await(Message.getThreadsByRoomId({ rid, queryOptions: { skip, limit } })).records;
},
});
5 changes: 3 additions & 2 deletions server/publications/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ Meteor.methods({
}

const queryOptions = {
returnTotal: false,
sort: {
ts: -1,
},
};

if (lastUpdate instanceof Date) {
return {
updated: Promise.await(Message.getUpdates({ rid, userId: fromId, timestamp: lastUpdate, queryOptions })),
deleted: Promise.await(Message.getDeleted({ rid, userId: fromId, timestamp: lastUpdate, queryOptions: { ...queryOptions, fields: { _id: 1, _deletedAt: 1 } } })),
updated: Promise.await(Message.getUpdates({ rid, userId: fromId, timestamp: lastUpdate, queryOptions })).records,
deleted: Promise.await(Message.getDeleted({ rid, userId: fromId, timestamp: lastUpdate, queryOptions: { ...queryOptions, fields: { _id: 1, _deletedAt: 1 } } })).records,
};
}

Expand Down

0 comments on commit 3182111

Please sign in to comment.