diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2022-02-28 08:34:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-28 08:34:43 +0100 |
commit | d0800f7661f13fabe7bb6f4aa0ea50764f106405 (patch) | |
tree | d43e6b0b6f4a5a32e03487e6464edbcaf288be2a /server/models/abuse/abuse-message.ts | |
parent | 5cad2ca9db9b9d138f8a33058d10b94a9fd50c69 (diff) | |
download | PeerTube-d0800f7661f13fabe7bb6f4aa0ea50764f106405.tar.gz PeerTube-d0800f7661f13fabe7bb6f4aa0ea50764f106405.tar.zst PeerTube-d0800f7661f13fabe7bb6f4aa0ea50764f106405.zip |
Implement avatar miniatures (#4639)
* client: remove unused file
* refactor(client/my-actor-avatar): size from input
Read size from component input instead of scss, to make it possible to
use smaller avatar images when implemented.
* implement avatar miniatures
close #4560
* fix(test): max file size
* fix(search-index): normalize res acc to avatarMini
* refactor avatars to an array
* client/search: resize channel avatar to 120
* refactor(client/videos): remove unused function
* client(actor-avatar): set default size
* fix tests and avatars full result
When findOne is used only an array containting one avatar is returned.
* update migration version and version notations
* server/search: harmonize normalizing
* Cleanup avatar miniature PR
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/models/abuse/abuse-message.ts')
-rw-r--r-- | server/models/abuse/abuse-message.ts | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/server/models/abuse/abuse-message.ts b/server/models/abuse/abuse-message.ts index 6a441a210..d9eb25f0f 100644 --- a/server/models/abuse/abuse-message.ts +++ b/server/models/abuse/abuse-message.ts | |||
@@ -1,11 +1,12 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' | 2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' |
3 | import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' | 3 | import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/typescript-utils' | ||
5 | import { AbuseMessage } from '@shared/models' | 4 | import { AbuseMessage } from '@shared/models' |
5 | import { AttributesOnly } from '@shared/typescript-utils' | ||
6 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' | 6 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' |
7 | import { getSort, throwIfNotValid } from '../utils' | 7 | import { getSort, throwIfNotValid } from '../utils' |
8 | import { AbuseModel } from './abuse' | 8 | import { AbuseModel } from './abuse' |
9 | import { FindOptions } from 'sequelize/dist' | ||
9 | 10 | ||
10 | @Table({ | 11 | @Table({ |
11 | tableName: 'abuseMessage', | 12 | tableName: 'abuseMessage', |
@@ -62,21 +63,28 @@ export class AbuseMessageModel extends Model<Partial<AttributesOnly<AbuseMessage | |||
62 | Abuse: AbuseModel | 63 | Abuse: AbuseModel |
63 | 64 | ||
64 | static listForApi (abuseId: number) { | 65 | static listForApi (abuseId: number) { |
65 | const options = { | 66 | const getQuery = (forCount: boolean) => { |
66 | where: { abuseId }, | 67 | const query: FindOptions = { |
68 | where: { abuseId }, | ||
69 | order: getSort('createdAt') | ||
70 | } | ||
67 | 71 | ||
68 | order: getSort('createdAt'), | 72 | if (forCount !== true) { |
73 | query.include = [ | ||
74 | { | ||
75 | model: AccountModel.scope(AccountScopeNames.SUMMARY), | ||
76 | required: false | ||
77 | } | ||
78 | ] | ||
79 | } | ||
69 | 80 | ||
70 | include: [ | 81 | return query |
71 | { | ||
72 | model: AccountModel.scope(AccountScopeNames.SUMMARY), | ||
73 | required: false | ||
74 | } | ||
75 | ] | ||
76 | } | 82 | } |
77 | 83 | ||
78 | return AbuseMessageModel.findAndCountAll(options) | 84 | return Promise.all([ |
79 | .then(({ rows, count }) => ({ data: rows, total: count })) | 85 | AbuseMessageModel.count(getQuery(true)), |
86 | AbuseMessageModel.findAll(getQuery(false)) | ||
87 | ]).then(([ total, data ]) => ({ total, data })) | ||
80 | } | 88 | } |
81 | 89 | ||
82 | static loadByIdAndAbuseId (messageId: number, abuseId: number): Promise<MAbuseMessage> { | 90 | static loadByIdAndAbuseId (messageId: number, abuseId: number): Promise<MAbuseMessage> { |