blob: 31411763383ef6fad0c8a3bbcb44bcda6b54dcf0 [file] [log] [blame]
Adrien BĂ©raud6ecaa402021-04-06 17:37:25 -04001class Account {
2 constructor(id, details, volatileDetails) {
3 this.id = id
4 this.details = details
5 this.volatileDetails = volatileDetails
6 }
7
8 static from(object) {
9 return new Account(object.id, object.details, object.volatileDetails)
10 }
11
12 update(data) {
13 this.details = data.details
14 this.volatileDetails = data.volatileDetails
15 }
16
17 getId() { return this.id }
18
19 getType() { return this.details["Account.type"] }
20
21 getUri() { return this.details["Account.username"] }
22
23 getRegisteredName() { return this.volatileDetails["Account.registeredName"] }
24
25 isRendezVous() { return this.details["Account.rendezVous"] === Account.BOOL_TRUE }
26 isPublicIn() { return this.details["DHT.PublicInCalls"] === Account.BOOL_TRUE }
27
28 getObject() {
29 return {
30 id: this.id,
31 details: this.details,
32 volatileDetails: this.volatileDetails
33 }
34 }
35
36 getSummary() {
37 return this.getObject()
38 }
39
40 getDisplayName() {
41 return this.details["Account.displayName"] || this.getDisplayUri()
42 }
43
44 getDisplayUri() {
45 return this.getRegisteredName() || this.getUri()
46 }
47}
48
49Account.TYPE_JAMI = "RING"
50Account.TYPE_SIP = "SIP"
51
52Account.BOOL_TRUE = "true"
53Account.BOOL_FALSE = "false"
54
55module.exports = Account;