Skip to content

Commit

Permalink
Regression: Fix sort field files.list (#25687)
Browse files Browse the repository at this point in the history
Co-authored-by: Fábio Albuquerque <albuquerquefabio@icloud.com>
  • Loading branch information
ggazzo and albuquerquefabio committed May 31, 2022
1 parent 713120e commit 51845b1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
7 changes: 4 additions & 3 deletions apps/meteor/app/api/server/helpers/insertUserObject.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Meteor } from 'meteor/meteor';

import { Users } from '../../../models/server';
import { API } from '../api';

API.helperMethods.set(
'insertUserObject',
function _addUserToObject({ object, userId }: { object: { [key: string]: unknown }; userId: string }) {
Meteor.bindEnvironment(function _addUserToObject({ object, userId }: { object: { [key: string]: unknown }; userId: string }) {
// Maybe `object: { [key: string]: Meteor.User }`?

const user = Users.findOneById(userId);
if (user) {
object.user = {
Expand All @@ -16,5 +17,5 @@ API.helperMethods.set(
}

return object;
},
}),
);
38 changes: 20 additions & 18 deletions apps/meteor/app/api/server/v1/im.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,23 @@ API.v1.addRoute(

const ourQuery = query ? { rid: room._id, ...query } : { rid: room._id };

const files = await Uploads.find<IUpload & { userId: string }>(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
projection: fields,
})
.map((file): IImFilesObject | (IImFilesObject & { user: Pick<IUser, '_id' | 'name' | 'username'> }) => {
if (file.userId) {
return this.insertUserObject<IImFilesObject & { user: Pick<IUser, '_id' | 'name' | 'username'> }>({
object: { ...file },
userId: file.userId,
});
}
return file;
})
.toArray();
const files = (
await Uploads.find<IUpload & { userId: string }>(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
projection: fields,
}).toArray()
).map((file): IImFilesObject | (IImFilesObject & { user: Pick<IUser, '_id' | 'name' | 'username'> }) => {
if (file.userId) {
return this.insertUserObject<IImFilesObject & { user: Pick<IUser, '_id' | 'name' | 'username'> }>({
object: { ...file },
userId: file.userId,
});
}
return file;
});

const total = await Uploads.find(ourQuery).count();
return API.v1.success({
files,
Expand All @@ -252,14 +253,15 @@ API.v1.addRoute(

const objectParams = {
rid: room._id,
latest: latest ? new Date(latest).toISOString() : new Date().toISOString(),
oldest: oldest && new Date(oldest).toISOString(),
latest: latest ? new Date(latest) : new Date(),
oldest: oldest && new Date(oldest),
inclusive: inclusive === 'true',
offset,
count,
unreads: unreads === 'true',
showThreadMessages: showThreadMessages === 'true',
};

const result = Meteor.call('getChannelHistory', objectParams);

if (!result) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/dm/DmFileProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const isDmFileProps = ajv.compile<DmFileProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand All @@ -49,7 +49,7 @@ export const isDmFileProps = ajv.compile<DmFileProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/dm/DmMembersProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const isDmMemberProps = ajv.compile<DmMemberProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand Down Expand Up @@ -70,7 +70,7 @@ export const isDmMemberProps = ajv.compile<DmMemberProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/dm/DmMessagesProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const isDmMessagesProps = ajv.compile<DmMessagesProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand All @@ -57,7 +57,7 @@ export const isDmMessagesProps = ajv.compile<DmMessagesProps>({
type: 'string',
},
sort: {
type: 'number',
type: 'string',
},
count: {
type: 'number',
Expand Down

0 comments on commit 51845b1

Please sign in to comment.