summaryrefslogtreecommitdiff
path: root/www/app/models/account.js
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-09-05 17:34:11 -0700
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-06 13:55:16 -0400
commit65c2c18653feb5f6485710e9656b19e368bb2826 (patch)
treea279d6f4eb502b30606870cd34af2896eef7321d /www/app/models/account.js
parentb047beb3e50a541564d2ab6ff17491608a630101 (diff)
[feature] webkit support: get the js and css working in older webkit engines
Diffstat (limited to 'www/app/models/account.js')
-rw-r--r--www/app/models/account.js67
1 files changed, 61 insertions, 6 deletions
diff --git a/www/app/models/account.js b/www/app/models/account.js
index 367961bf..fa3b9813 100644
--- a/www/app/models/account.js
+++ b/www/app/models/account.js
@@ -8,11 +8,7 @@ import bitmask from 'lib/bitmask'
export default class Account {
constructor(address, props={}) {
- if (!address.match('@')) {
- this._address = '@' + address
- } else {
- this._address = address
- }
+ this.address = address
this._authenticated = props.authenticated
}
@@ -34,6 +30,14 @@ export default class Account {
return this._address
}
+ set address(address) {
+ if (!address.match('@')) {
+ this._address = '@' + address
+ } else {
+ this._address = address
+ }
+ }
+
get userpart() {
return this._address.split('@')[0]
}
@@ -42,6 +46,10 @@ export default class Account {
return this._authenticated
}
+ get hasEmail() {
+ return true
+ }
+
//
// returns a promise, fulfill is passed account object
//
@@ -71,6 +79,33 @@ export default class Account {
}
//
+ // returns the matching account in the list of accounts, or adds it
+ // if it is not already present.
+ //
+ static find(address) {
+ // search by full address
+ let account = Account.list.find(i => {
+ return i.address == address
+ })
+ // failing that, search by domain
+ if (!account) {
+ let domain = '@' + address.split('@')[1]
+ account = Account.list.find(i => {
+ return i.address == domain
+ })
+ if (account) {
+ account.address = address
+ }
+ }
+ // failing that, create new account
+ if (!account) {
+ account = new Account(address)
+ Account.list.push(account)
+ }
+ return account
+ }
+
+ //
// returns a promise, fullfill is passed account object
//
static active() {
@@ -85,4 +120,24 @@ export default class Account {
)
}
-} \ No newline at end of file
+ static add(account) {
+ if (!Account.list.find(i => {return i.id == account.id})) {
+ Account.list.push(account)
+ }
+ }
+
+ static remove(account) {
+ Account.list = Account.list.filter(i => {
+ return i.id != account.id
+ })
+ }
+ // return Account.list
+ // return new Promise(function(resolve, reject) {
+ // window.setTimeout(function() {
+ // resolve(['@blah', '@lala'])
+ // }, 1000)
+ // })
+ // }
+}
+
+Account.list = [] \ No newline at end of file