Skip to content

Commit

Permalink
ES6: migrated "user" (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored May 3, 2017
1 parent 8d7025f commit 48e5067
Show file tree
Hide file tree
Showing 18 changed files with 1,718 additions and 1,335 deletions.
30 changes: 0 additions & 30 deletions app/script/user/ConnectionStatus.coffee

This file was deleted.

33 changes: 33 additions & 0 deletions app/script/user/ConnectionStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.user = z.user || {};

z.user.ConnectionStatus = {
ACCEPTED: 'accepted',
BLOCKED: 'blocked',
CANCELLED: 'cancelled',
IGNORED: 'ignored',
PENDING: 'pending',
SENT: 'sent',
UNKNOWN: '',
};
64 changes: 0 additions & 64 deletions app/script/user/UserConnectionMapper.coffee

This file was deleted.

71 changes: 71 additions & 0 deletions app/script/user/UserConnectionMapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.user = z.user || {};

/**
* Connection mapper to convert all server side JSON connections into core connection entities.
* @class z.user.UserConnectionMapper
*/
z.user.UserConnectionMapper = class UserConnectionMapper {
// Construct a new user mapper.
constructor() {
this.logger = new z.util.Logger('z.user.UserConnectionMapper', z.config.LOGGER.OPTIONS);

/**
* Converts JSON connection into connection entity.
* @param {JSON} data - Connection data
* @returns {z.entity.Connection} Mapped connection entity
*/
this.map_user_connection_from_json = function(data) {
const connection_et = new z.entity.Connection();
return this.update_user_connection_from_json(connection_et, data);
};

/**
* Convert multiple JSON connections into connection entities.
* @param {Object} data - Connection data
* @returns {Array<z.entity.Connection>} Mapped connection entities
*/
this.map_user_connections_from_json = function(data) {
return data
.filter((connection) => connection !== undefined)
.map((connection) => this.map_user_connection_from_json(connection));
};

/**
* Maps JSON connection into a blank connection entity or updates an existing one.
* @param {z.entity.Connection} connection_et - Connection entity that the info shall be mapped to
* @param {JSON} data - Connection data
* @returns {z.entity.Connection} Mapped connection entity
*/
this.update_user_connection_from_json = function(connection_et, data) {
connection_et.status(data.status);
connection_et.conversation_id = data.conversation;
connection_et.to = data.to;
connection_et.from = data.from;
connection_et.last_update = data.last_update;
connection_et.message = data.message;
return connection_et;
};
}
};
47 changes: 0 additions & 47 deletions app/script/user/UserError.coffee

This file was deleted.

60 changes: 60 additions & 0 deletions app/script/user/UserError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.user = z.user || {};

z.user.UserError = class UserError extends Error {
constructor(type) {
super();

this.name = this.constructor.name;
this.stack = (new Error()).stack;
this.type = type || z.user.UserError.TYPE.UNKNOWN;

switch (this.type) {
case z.user.UserError.TYPE.PRE_KEY_NOT_FOUND:
this.message = 'Pre-key not found';
break;
case z.user.UserError.TYPE.REQUEST_FAILURE:
this.message = 'User related backend request failure';
break;
case z.user.UserError.TYPE.USER_NOT_FOUND:
this.message = 'User not found';
break;
case z.user.UserError.TYPE.USERNAME_TAKEN:
this.message = 'Username is already taken';
break;
default:
this.message = 'Unknown UserError';
}
}

static get TYPE() {
return {
PRE_KEY_NOT_FOUND: 'z.user.UserError.TYPE.PRE_KEY_NOT_FOUND',
REQUEST_FAILURE: 'z.user.UserError.TYPE.REQUEST_FAILURE',
UNKNOWN: 'z.user.UserError.TYPE.UNKNOWN',
USER_NOT_FOUND: 'z.user.UserError.TYPE.USER_NOT_FOUND',
USERNAME_TAKEN: 'z.user.UserError.TYPE.USERNAME_TAKEN',
};
}
};
Loading

0 comments on commit 48e5067

Please sign in to comment.