aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
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
parente34c85e527100c0b5c44567bd951e95be41b8d7e (diff)
downloadPeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst
PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip
Follow works
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-follow.ts15
-rw-r--r--server/models/account/account-interface.ts6
-rw-r--r--server/models/account/account.ts44
3 files changed, 47 insertions, 18 deletions
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index e6abc893a..7c129ab9d 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -19,11 +19,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
19 { 19 {
20 indexes: [ 20 indexes: [
21 { 21 {
22 fields: [ 'accountId' ], 22 fields: [ 'accountId' ]
23 unique: true 23 },
24 {
25 fields: [ 'targetAccountId' ]
24 }, 26 },
25 { 27 {
26 fields: [ 'targetAccountId' ], 28 fields: [ 'accountId', 'targetAccountId' ],
27 unique: true 29 unique: true
28 } 30 }
29 ] 31 ]
@@ -31,7 +33,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
31 ) 33 )
32 34
33 const classMethods = [ 35 const classMethods = [
34 associate 36 associate,
37 loadByAccountAndTarget
35 ] 38 ]
36 addMethodsToModel(AccountFollow, classMethods) 39 addMethodsToModel(AccountFollow, classMethods)
37 40
@@ -46,7 +49,7 @@ function associate (models) {
46 name: 'accountId', 49 name: 'accountId',
47 allowNull: false 50 allowNull: false
48 }, 51 },
49 as: 'followers', 52 as: 'accountFollowers',
50 onDelete: 'CASCADE' 53 onDelete: 'CASCADE'
51 }) 54 })
52 55
@@ -55,7 +58,7 @@ function associate (models) {
55 name: 'targetAccountId', 58 name: 'targetAccountId',
56 allowNull: false 59 allowNull: false
57 }, 60 },
58 as: 'following', 61 as: 'accountFollowing',
59 onDelete: 'CASCADE' 62 onDelete: 'CASCADE'
60 }) 63 })
61} 64}
diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts
index 2468dc6e1..6fc36ae9d 100644
--- a/server/models/account/account-interface.ts
+++ b/server/models/account/account-interface.ts
@@ -12,7 +12,8 @@ export namespace AccountMethods {
12 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance> 12 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>
13 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> 13 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
14 export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance> 14 export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
15 export type LoadLocalAccountByNameAndPod = (name: string, host: string) => Bluebird<AccountInstance> 15 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
16 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
16 export type ListOwned = () => Bluebird<AccountInstance[]> 17 export type ListOwned = () => Bluebird<AccountInstance[]>
17 export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 18 export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
18 export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> > 19 export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
@@ -34,7 +35,8 @@ export interface AccountClass {
34 load: AccountMethods.Load 35 load: AccountMethods.Load
35 loadByUUID: AccountMethods.LoadByUUID 36 loadByUUID: AccountMethods.LoadByUUID
36 loadByUrl: AccountMethods.LoadByUrl 37 loadByUrl: AccountMethods.LoadByUrl
37 loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod 38 loadLocalByName: AccountMethods.LoadLocalByName
39 loadByNameAndHost: AccountMethods.LoadByNameAndHost
38 listOwned: AccountMethods.ListOwned 40 listOwned: AccountMethods.ListOwned
39 listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi 41 listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
40 listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi 42 listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
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 }