Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6: migrated "client" #976

Merged
merged 10 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ globals:
LRUCache: true
moment: true
pako: true
platform: true
Raygun: true
twttr: true
wire: true
Expand Down
79 changes: 0 additions & 79 deletions app/script/client/Client.coffee

This file was deleted.

91 changes: 91 additions & 0 deletions app/script/client/Client.js
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;
}
};
62 changes: 0 additions & 62 deletions app/script/client/ClientError.coffee

This file was deleted.

80 changes: 80 additions & 0 deletions app/script/client/ClientError.js
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',
};
}
};
59 changes: 0 additions & 59 deletions app/script/client/ClientMapper.coffee

This file was deleted.

Loading