-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24fdeb4
commit bf3b69d
Showing
17 changed files
with
1,201 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ globals: | |
LRUCache: true | ||
moment: true | ||
pako: true | ||
platform: true | ||
Raygun: true | ||
twttr: true | ||
wire: true | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2017 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
window.z = window.z || {}; | ||
window.z.client = z.client || {}; | ||
|
||
z.client.Client = class Client { | ||
constructor(payload = {}) { | ||
if (payload.address) { | ||
this.class = payload.class || '?'; | ||
this.label = payload.label || '?'; | ||
this.model = payload.model || '?'; | ||
} | ||
|
||
for (let member in payload) { | ||
this[member] = payload[member]; | ||
} | ||
|
||
// Metadata maintained by us | ||
this.meta = { | ||
is_verified: ko.observable(false), | ||
primary_key: undefined, | ||
}; | ||
|
||
this.session = {}; | ||
} | ||
|
||
/* | ||
Splits an ID into user ID & client ID. | ||
@param {string} id | ||
@return {Object} Object containing the user ID & client ID | ||
*/ | ||
static dismantle_user_client_id(id) { | ||
let [user_id, client_id] = (id != null ? id.split('@') : undefined) || []; | ||
return { | ||
user_id, | ||
client_id, | ||
}; | ||
} | ||
|
||
/* | ||
@return {boolean} - True, if the client is the self user's permanent client. | ||
*/ | ||
is_permanent() { | ||
return this.type === z.client.ClientType.PERMANENT; | ||
} | ||
|
||
/* | ||
@return {boolean} - True, if it is NOT the client of the self user. | ||
*/ | ||
is_remote() { | ||
return !this.is_permanent() && !this.is_temporary(); | ||
} | ||
|
||
/* | ||
@return {boolean} - True, if the client is the self user's temporary client. | ||
*/ | ||
is_temporary() { | ||
return this.type === z.client.ClientType.TEMPORARY; | ||
} | ||
|
||
/* | ||
This method returns a JSON object which can be stored in our local database. | ||
@return {Object} | ||
*/ | ||
to_json() { | ||
let json = ko.toJSON(this); | ||
let real_json = JSON.parse(json); | ||
delete real_json.session; | ||
return real_json; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2017 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
window.z = window.z || {}; | ||
window.z.client = z.client || {}; | ||
|
||
z.client.ClientError = class ClientError extends Error { | ||
constructor(type) { | ||
super(); | ||
|
||
this.name = this.constructor.name; | ||
this.stack = (new Error()).stack; | ||
this.type = type || z.client.ClientError.TYPE.UNKNOWN; | ||
|
||
switch (this.type) { | ||
case z.client.ClientError.TYPE.CLIENT_NOT_SET: | ||
this.message = 'Local client is not yet set'; | ||
break; | ||
case z.client.ClientError.TYPE.DATABASE_FAILURE: | ||
this.message = 'Client related database transaction failed'; | ||
break; | ||
case z.client.ClientError.TYPE.MISSING_ON_BACKEND: | ||
this.message = 'Local client does not exist on backend'; | ||
break; | ||
case z.client.ClientError.TYPE.NO_CLIENT_ID: | ||
this.message = 'Client ID is not defined'; | ||
break; | ||
case z.client.ClientError.TYPE.NO_LOCAL_CLIENT: | ||
this.message = 'No local client found in database'; | ||
break; | ||
case z.client.ClientError.TYPE.NO_USER_ID: | ||
this.message = 'User ID is not defined'; | ||
break; | ||
case z.client.ClientError.TYPE.REQUEST_FAILURE: | ||
this.message = 'Client related backend request failed'; | ||
break; | ||
case z.client.ClientError.TYPE.REQUEST_FORBIDDEN: | ||
this.message = 'Client related backend request forbidden'; | ||
break; | ||
case z.client.ClientError.TYPE.TOO_MANY_CLIENTS: | ||
this.message = 'User has reached the maximum of allowed clients'; | ||
break; | ||
default: | ||
this.message = 'Unknown ClientError'; | ||
} | ||
} | ||
|
||
static get TYPE() { | ||
return { | ||
CLIENT_NOT_SET: 'z.client.ClientError.TYPE.CLIENT_NOT_SET', | ||
DATABASE_FAILURE: 'z.client.ClientError.TYPE.DATABASE_FAILURE', | ||
MISSING_ON_BACKEND: 'z.client.ClientError.TYPE.MISSING_ON_BACKEND', | ||
NO_CLIENT_ID: 'z.client.ClientError.TYPE.NO_CLIENT_ID', | ||
NO_LOCAL_CLIENT: 'z.client.ClientError.TYPE.NO_LOCAL_CLIENT', | ||
NO_USER_ID: 'z.client.ClientError.TYPE.NO_USER_ID', | ||
REQUEST_FAILURE: 'z.client.ClientError.TYPE.REQUEST_FAILURE', | ||
REQUEST_FORBIDDEN: 'z.client.ClientError.TYPE.REQUEST_FORBIDDEN', | ||
TOO_MANY_CLIENTS: 'z.client.ClientError.TYPE.TOO_MANY_CLIENTS', | ||
UNKNOWN: 'z.client.ClientError.TYPE.UNKNOWN', | ||
}; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.