aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r--server/models/account/account.ts58
1 files changed, 30 insertions, 28 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 8c244d432..c72f9c63d 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -1,5 +1,4 @@
1import * as Bluebird from 'bluebird' 1import { FindOptions, Includeable, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
2import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequelize'
3import { 2import {
4 AllowNull, 3 AllowNull,
5 BeforeDestroy, 4 BeforeDestroy,
@@ -73,28 +72,29 @@ export type SummaryOptions = {
73 required: false 72 required: false
74 } 73 }
75 74
76 const query: FindOptions = { 75 const queryInclude: Includeable[] = [
77 attributes: [ 'id', 'name', 'actorId' ], 76 {
78 include: [ 77 attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
79 { 78 model: ActorModel.unscoped(),
80 attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], 79 required: options.actorRequired ?? true,
81 model: ActorModel.unscoped(), 80 where: whereActor,
82 required: options.actorRequired ?? true, 81 include: [
83 where: whereActor, 82 serverInclude,
84 include: [
85 serverInclude,
86 83
87 { 84 {
88 model: AvatarModel.unscoped(), 85 model: AvatarModel.unscoped(),
89 required: false 86 required: false
90 } 87 }
91 ] 88 ]
92 } 89 }
93 ] 90 ]
91
92 const query: FindOptions = {
93 attributes: [ 'id', 'name', 'actorId' ]
94 } 94 }
95 95
96 if (options.withAccountBlockerIds) { 96 if (options.withAccountBlockerIds) {
97 query.include.push({ 97 queryInclude.push({
98 attributes: [ 'id' ], 98 attributes: [ 'id' ],
99 model: AccountBlocklistModel.unscoped(), 99 model: AccountBlocklistModel.unscoped(),
100 as: 'BlockedAccounts', 100 as: 'BlockedAccounts',
@@ -120,6 +120,8 @@ export type SummaryOptions = {
120 ] 120 ]
121 } 121 }
122 122
123 query.include = queryInclude
124
123 return query 125 return query
124 } 126 }
125})) 127}))
@@ -138,7 +140,7 @@ export type SummaryOptions = {
138 } 140 }
139 ] 141 ]
140}) 142})
141export class AccountModel extends Model<AccountModel> { 143export class AccountModel extends Model {
142 144
143 @AllowNull(false) 145 @AllowNull(false)
144 @Column 146 @Column
@@ -244,11 +246,11 @@ export class AccountModel extends Model<AccountModel> {
244 return undefined 246 return undefined
245 } 247 }
246 248
247 static load (id: number, transaction?: Transaction): Bluebird<MAccountDefault> { 249 static load (id: number, transaction?: Transaction): Promise<MAccountDefault> {
248 return AccountModel.findByPk(id, { transaction }) 250 return AccountModel.findByPk(id, { transaction })
249 } 251 }
250 252
251 static loadByNameWithHost (nameWithHost: string): Bluebird<MAccountDefault> { 253 static loadByNameWithHost (nameWithHost: string): Promise<MAccountDefault> {
252 const [ accountName, host ] = nameWithHost.split('@') 254 const [ accountName, host ] = nameWithHost.split('@')
253 255
254 if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) 256 if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
@@ -256,7 +258,7 @@ export class AccountModel extends Model<AccountModel> {
256 return AccountModel.loadByNameAndHost(accountName, host) 258 return AccountModel.loadByNameAndHost(accountName, host)
257 } 259 }
258 260
259 static loadLocalByName (name: string): Bluebird<MAccountDefault> { 261 static loadLocalByName (name: string): Promise<MAccountDefault> {
260 const fun = () => { 262 const fun = () => {
261 const query = { 263 const query = {
262 where: { 264 where: {
@@ -296,7 +298,7 @@ export class AccountModel extends Model<AccountModel> {
296 }) 298 })
297 } 299 }
298 300
299 static loadByNameAndHost (name: string, host: string): Bluebird<MAccountDefault> { 301 static loadByNameAndHost (name: string, host: string): Promise<MAccountDefault> {
300 const query = { 302 const query = {
301 include: [ 303 include: [
302 { 304 {
@@ -321,7 +323,7 @@ export class AccountModel extends Model<AccountModel> {
321 return AccountModel.findOne(query) 323 return AccountModel.findOne(query)
322 } 324 }
323 325
324 static loadByUrl (url: string, transaction?: Transaction): Bluebird<MAccountDefault> { 326 static loadByUrl (url: string, transaction?: Transaction): Promise<MAccountDefault> {
325 const query = { 327 const query = {
326 include: [ 328 include: [
327 { 329 {
@@ -354,7 +356,7 @@ export class AccountModel extends Model<AccountModel> {
354 }) 356 })
355 } 357 }
356 358
357 static loadAccountIdFromVideo (videoId: number): Bluebird<MAccount> { 359 static loadAccountIdFromVideo (videoId: number): Promise<MAccount> {
358 const query = { 360 const query = {
359 include: [ 361 include: [
360 { 362 {
@@ -377,7 +379,7 @@ export class AccountModel extends Model<AccountModel> {
377 return AccountModel.findOne(query) 379 return AccountModel.findOne(query)
378 } 380 }
379 381
380 static listLocalsForSitemap (sort: string): Bluebird<MAccountActor[]> { 382 static listLocalsForSitemap (sort: string): Promise<MAccountActor[]> {
381 const query = { 383 const query = {
382 attributes: [ ], 384 attributes: [ ],
383 offset: 0, 385 offset: 0,