aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-interface.ts
blob: d49dfbe1764690de30334dc95ef887eeda5157f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as Bluebird from 'bluebird'
import * as Sequelize from 'sequelize'
import { Account as FormattedAccount, ActivityPubActor } from '../../../shared'
import { ResultList } from '../../../shared/models/result-list.model'
import { PodInstance } from '../pod/pod-interface'
import { VideoChannelInstance } from '../video/video-channel-interface'

export namespace AccountMethods {
  export type LoadApplication = () => Bluebird<AccountInstance>

  export type Load = (id: number) => Bluebird<AccountInstance>
  export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>
  export type LoadByUrl = (url: string) => Bluebird<AccountInstance>
  export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
  export type LoadLocalAccountByNameAndPod = (name: string, host: string) => Bluebird<AccountInstance>
  export type ListOwned = () => Bluebird<AccountInstance[]>
  export type ListFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
  export type ListFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
  export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
  export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >

  export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
  export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
  export type IsOwned = (this: AccountInstance) => boolean
  export type GetFollowerSharedInboxUrls = (this: AccountInstance) => Bluebird<string[]>
  export type GetFollowingUrl = (this: AccountInstance) => string
  export type GetFollowersUrl = (this: AccountInstance) => string
  export type GetPublicKeyUrl = (this: AccountInstance) => string
}

export interface AccountClass {
  loadApplication: AccountMethods.LoadApplication
  loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID
  load: AccountMethods.Load
  loadByUUID: AccountMethods.LoadByUUID
  loadByUrl: AccountMethods.LoadByUrl
  loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod
  listOwned: AccountMethods.ListOwned
  listFollowerUrlsForApi: AccountMethods.ListFollowerUrlsForApi
  listFollowingUrlsForApi: AccountMethods.ListFollowingUrlsForApi
  listFollowingForApi: AccountMethods.ListFollowingForApi
  listFollowersForApi: AccountMethods.ListFollowersForApi
}

export interface AccountAttributes {
  name: string
  url: string
  publicKey: string
  privateKey: string
  followersCount: number
  followingCount: number
  inboxUrl: string
  outboxUrl: string
  sharedInboxUrl: string
  followersUrl: string
  followingUrl: string

  uuid?: string

  podId?: number
  userId?: number
  applicationId?: number
}

export interface AccountInstance extends AccountClass, AccountAttributes, Sequelize.Instance<AccountAttributes> {
  isOwned: AccountMethods.IsOwned
  toActivityPubObject: AccountMethods.ToActivityPubObject
  toFormattedJSON: AccountMethods.ToFormattedJSON
  getFollowerSharedInboxUrls: AccountMethods.GetFollowerSharedInboxUrls
  getFollowingUrl: AccountMethods.GetFollowingUrl
  getFollowersUrl: AccountMethods.GetFollowersUrl
  getPublicKeyUrl: AccountMethods.GetPublicKeyUrl

  id: number
  createdAt: Date
  updatedAt: Date

  Pod: PodInstance
  VideoChannels: VideoChannelInstance[]
}

export interface AccountModel extends AccountClass, Sequelize.Model<AccountInstance, AccountAttributes> {}