diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account-follow-interface.ts | 11 | ||||
-rw-r--r-- | server/models/account/account-follow.ts | 26 |
2 files changed, 30 insertions, 7 deletions
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts index 21fda98ce..6f228c790 100644 --- a/server/models/account/account-follow-interface.ts +++ b/server/models/account/account-follow-interface.ts | |||
@@ -1,18 +1,19 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
3 | import { FollowState } from '../../../shared/models/accounts/follow.model' | 2 | import * as Sequelize from 'sequelize' |
3 | import { AccountFollow, FollowState } from '../../../shared/models/accounts/follow.model' | ||
4 | import { ResultList } from '../../../shared/models/result-list.model' | 4 | import { ResultList } from '../../../shared/models/result-list.model' |
5 | import { AccountInstance } from './account-interface' | 5 | import { AccountInstance } from './account-interface' |
6 | 6 | ||
7 | export namespace AccountFollowMethods { | 7 | export namespace AccountFollowMethods { |
8 | export type LoadByAccountAndTarget = (accountId: number, targetAccountId: number) => Bluebird<AccountFollowInstance> | 8 | export type LoadByAccountAndTarget = (accountId: number, targetAccountId: number) => Bluebird<AccountFollowInstance> |
9 | 9 | ||
10 | export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > | 10 | export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> |
11 | export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > | 11 | export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>> |
12 | 12 | ||
13 | export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > | 13 | export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > |
14 | export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > | 14 | export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> > |
15 | export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> > | 15 | export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> > |
16 | export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow | ||
16 | } | 17 | } |
17 | 18 | ||
18 | export interface AccountFollowClass { | 19 | export interface AccountFollowClass { |
@@ -38,6 +39,8 @@ export interface AccountFollowInstance extends AccountFollowClass, AccountFollow | |||
38 | 39 | ||
39 | AccountFollower?: AccountInstance | 40 | AccountFollower?: AccountInstance |
40 | AccountFollowing?: AccountInstance | 41 | AccountFollowing?: AccountInstance |
42 | |||
43 | toFormattedJSON: AccountFollowMethods.ToFormattedJSON | ||
41 | } | 44 | } |
42 | 45 | ||
43 | export interface AccountFollowModel extends AccountFollowClass, Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> {} | 46 | export interface AccountFollowModel extends AccountFollowClass, Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> {} |
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts index f00c7dcd9..34ba3f8db 100644 --- a/server/models/account/account-follow.ts +++ b/server/models/account/account-follow.ts | |||
@@ -12,6 +12,7 @@ let listFollowersForApi: AccountFollowMethods.ListFollowersForApi | |||
12 | let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi | 12 | let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi |
13 | let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi | 13 | let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi |
14 | let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls | 14 | let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls |
15 | let toFormattedJSON: AccountFollowMethods.ToFormattedJSON | ||
15 | 16 | ||
16 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 17 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
17 | AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow', | 18 | AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow', |
@@ -46,7 +47,10 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
46 | listAcceptedFollowingUrlsForApi, | 47 | listAcceptedFollowingUrlsForApi, |
47 | listAcceptedFollowerSharedInboxUrls | 48 | listAcceptedFollowerSharedInboxUrls |
48 | ] | 49 | ] |
49 | addMethodsToModel(AccountFollow, classMethods) | 50 | const instanceMethods = [ |
51 | toFormattedJSON | ||
52 | ] | ||
53 | addMethodsToModel(AccountFollow, classMethods, instanceMethods) | ||
50 | 54 | ||
51 | return AccountFollow | 55 | return AccountFollow |
52 | } | 56 | } |
@@ -73,6 +77,22 @@ function associate (models) { | |||
73 | }) | 77 | }) |
74 | } | 78 | } |
75 | 79 | ||
80 | toFormattedJSON = function (this: AccountFollowInstance) { | ||
81 | const follower = this.AccountFollower.toFormattedJSON() | ||
82 | const following = this.AccountFollowing.toFormattedJSON() | ||
83 | |||
84 | const json = { | ||
85 | id: this.id, | ||
86 | follower, | ||
87 | following, | ||
88 | state: this.state, | ||
89 | createdAt: this.createdAt, | ||
90 | updatedAt: this.updatedAt | ||
91 | } | ||
92 | |||
93 | return json | ||
94 | } | ||
95 | |||
76 | loadByAccountAndTarget = function (accountId: number, targetAccountId: number) { | 96 | loadByAccountAndTarget = function (accountId: number, targetAccountId: number) { |
77 | const query = { | 97 | const query = { |
78 | where: { | 98 | where: { |
@@ -122,7 +142,7 @@ listFollowingForApi = function (id: number, start: number, count: number, sort: | |||
122 | 142 | ||
123 | return AccountFollow.findAndCountAll(query).then(({ rows, count }) => { | 143 | return AccountFollow.findAndCountAll(query).then(({ rows, count }) => { |
124 | return { | 144 | return { |
125 | data: rows.map(r => r.AccountFollowing), | 145 | data: rows, |
126 | total: count | 146 | total: count |
127 | } | 147 | } |
128 | }) | 148 | }) |
@@ -154,7 +174,7 @@ listFollowersForApi = function (id: number, start: number, count: number, sort: | |||
154 | 174 | ||
155 | return AccountFollow.findAndCountAll(query).then(({ rows, count }) => { | 175 | return AccountFollow.findAndCountAll(query).then(({ rows, count }) => { |
156 | return { | 176 | return { |
157 | data: rows.map(r => r.AccountFollower), | 177 | data: rows, |
158 | total: count | 178 | total: count |
159 | } | 179 | } |
160 | }) | 180 | }) |