aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 17:31:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (patch)
treef4191f3c04a5230fcf8ca3d6ca3248643fc4151d /server/models/account/account.ts
parente34c85e527100c0b5c44567bd951e95be41b8d7e (diff)
downloadPeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip
Follow works
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r--server/models/account/account.ts44
1 files changed, 34 insertions, 10 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index cd6c822f1..d2293a939 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -31,7 +31,8 @@ let load: AccountMethods.Load
31let loadApplication: AccountMethods.LoadApplication 31let loadApplication: AccountMethods.LoadApplication
32let loadByUUID: AccountMethods.LoadByUUID 32let loadByUUID: AccountMethods.LoadByUUID
33let loadByUrl: AccountMethods.LoadByUrl 33let loadByUrl: AccountMethods.LoadByUrl
34let loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod 34let loadLocalByName: AccountMethods.LoadLocalByName
35let loadByNameAndHost: AccountMethods.LoadByNameAndHost
35let listOwned: AccountMethods.ListOwned 36let listOwned: AccountMethods.ListOwned
36let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi 37let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
37let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi 38let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
@@ -88,7 +89,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
88 }, 89 },
89 privateKey: { 90 privateKey: {
90 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max), 91 type: DataTypes.STRING(CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY.max),
91 allowNull: false, 92 allowNull: true,
92 validate: { 93 validate: {
93 privateKeyValid: value => { 94 privateKeyValid: value => {
94 const res = isAccountPrivateKeyValid(value) 95 const res = isAccountPrivateKeyValid(value)
@@ -199,7 +200,8 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
199 load, 200 load,
200 loadByUUID, 201 loadByUUID,
201 loadByUrl, 202 loadByUrl,
202 loadLocalAccountByNameAndPod, 203 loadLocalByName,
204 loadByNameAndHost,
203 listOwned, 205 listOwned,
204 listAcceptedFollowerUrlsForApi, 206 listAcceptedFollowerUrlsForApi,
205 listAcceptedFollowingUrlsForApi, 207 listAcceptedFollowingUrlsForApi,
@@ -330,6 +332,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
330 include: [ 332 include: [
331 { 333 {
332 model: Account['sequelize'].models.AccountFollow, 334 model: Account['sequelize'].models.AccountFollow,
335 required: true,
336 as: 'followers',
333 where: { 337 where: {
334 targetAccountId: this.id 338 targetAccountId: this.id
335 } 339 }
@@ -387,7 +391,7 @@ listFollowingForApi = function (id: number, start: number, count: number, sort:
387 include: [ 391 include: [
388 { 392 {
389 model: Account['sequelize'].models.Account, 393 model: Account['sequelize'].models.Account,
390 as: 'following', 394 as: 'accountFollowing',
391 required: true, 395 required: true,
392 include: [ Account['sequelize'].models.Pod ] 396 include: [ Account['sequelize'].models.Pod ]
393 } 397 }
@@ -418,7 +422,7 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
418 include: [ 422 include: [
419 { 423 {
420 model: Account['sequelize'].models.Account, 424 model: Account['sequelize'].models.Account,
421 as: 'followers', 425 as: 'accountFollowers',
422 required: true, 426 required: true,
423 include: [ Account['sequelize'].models.Pod ] 427 include: [ Account['sequelize'].models.Pod ]
424 } 428 }
@@ -439,7 +443,7 @@ loadApplication = function () {
439 return Account.findOne({ 443 return Account.findOne({
440 include: [ 444 include: [
441 { 445 {
442 model: Account['sequelize'].model.Application, 446 model: Account['sequelize'].models.Application,
443 required: true 447 required: true
444 } 448 }
445 ] 449 ]
@@ -460,17 +464,37 @@ loadByUUID = function (uuid: string) {
460 return Account.findOne(query) 464 return Account.findOne(query)
461} 465}
462 466
463loadLocalAccountByNameAndPod = function (name: string, host: string) { 467loadLocalByName = function (name: string) {
464 const query: Sequelize.FindOptions<AccountAttributes> = { 468 const query: Sequelize.FindOptions<AccountAttributes> = {
465 where: { 469 where: {
466 name, 470 name,
467 userId: { 471 [Sequelize.Op.or]: [
468 [Sequelize.Op.ne]: null 472 {
469 } 473 userId: {
474 [Sequelize.Op.ne]: null
475 }
476 },
477 {
478 applicationId: {
479 [Sequelize.Op.ne]: null
480 }
481 }
482 ]
483 }
484 }
485
486 return Account.findOne(query)
487}
488
489loadByNameAndHost = function (name: string, host: string) {
490 const query: Sequelize.FindOptions<AccountAttributes> = {
491 where: {
492 name
470 }, 493 },
471 include: [ 494 include: [
472 { 495 {
473 model: Account['sequelize'].models.Pod, 496 model: Account['sequelize'].models.Pod,
497 required: true,
474 where: { 498 where: {
475 host 499 host
476 } 500 }