Skip to content

Commit

Permalink
Revert "ES6: migrated "client" (#976)"
Browse files Browse the repository at this point in the history
This reverts commit bf3b69t d3b3d8b2180c47fd0b25fe0fe405f7c63e.
  • Loading branch information
rehez committed Apr 10, 2017
1 parent 9b8abc9 commit a0990ff
Show file tree
Hide file tree
Showing 17 changed files with 1,002 additions and 1,201 deletions.
1 change: 0 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ globals:
LRUCache: true
moment: true
pako: true
platform: true
Raygun: true
twttr: true
wire: true
Expand Down
79 changes: 79 additions & 0 deletions app/script/client/Client.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Wire
# Copyright (C) 2016 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/.
#

window.z ?= {}
z.client ?= {}

class z.client.Client
constructor: (payload = {}) ->
if payload.address
@class = payload.class or '?'
@label = payload.label or '?'
@model = payload.model or '?'

@[member] = payload[member] for member of payload

# Metadata maintained by us
@meta =
is_verified: ko.observable false
primary_key: undefined

@session = {}

return @

###
Splits an ID into user ID & client ID.
@param id [String] ID
@return [Object] Object containing the user ID & client ID
###
@dismantle_user_client_id: (id) ->
id_parts = id?.split('@') or []
return {
user_id: id_parts[0]
client_id: id_parts[1]
}

###
@return [Boolean] True, if the client is the self user's permanent client.
###
is_permanent: ->
return @type is z.client.ClientType.PERMANENT

###
@return [Boolean] True, if it is NOT the client of the self user.
###
is_remote: ->
return not @is_permanent() and not @is_temporary()

###
@return [Boolean] True, if the client is the self user's temporary client.
###
is_temporary: ->
return @type is z.client.ClientType.TEMPORARY

###
This method returns a JSON object which can be stored in our local database.
@return [JSON] JSON object
###
to_json: ->
json = ko.toJSON @
real_json = JSON.parse json
delete real_json.session
return real_json
91 changes: 0 additions & 91 deletions app/script/client/Client.js

This file was deleted.

62 changes: 62 additions & 0 deletions app/script/client/ClientError.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Wire
# Copyright (C) 2016 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/.
#

window.z ?= {}
z.client ?= {}

class z.client.ClientError
constructor: (type) ->
@name = @constructor.name
@stack = (new Error()).stack
@type = type or z.client.ClientError::TYPE.UNKNOWN

@message = switch @type
when z.client.ClientError::TYPE.CLIENT_NOT_SET
'Local client is not yet set'
when z.client.ClientError::TYPE.DATABASE_FAILURE
'Client related database transaction failed'
when z.client.ClientError::TYPE.MISSING_ON_BACKEND
'Local client does not exist on backend'
when z.client.ClientError::TYPE.NO_CLIENT_ID
'Client ID is not defined'
when z.client.ClientError::TYPE.NO_LOCAL_CLIENT
'No local client found in database'
when z.client.ClientError::TYPE.NO_USER_ID
'User ID is not defined'
when z.client.ClientError::TYPE.REQUEST_FAILURE
'Client related backend request failed'
when z.client.ClientError::TYPE.REQUEST_FORBIDDEN
'Client related backend request forbidden'
when z.client.ClientError::TYPE.TOO_MANY_CLIENTS
'User has reached the maximum of allowed clients'
else
'Unknown ClientError'

@:: = new Error()
@::constructor = @
@::TYPE =
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'
80 changes: 0 additions & 80 deletions app/script/client/ClientError.js

This file was deleted.

59 changes: 59 additions & 0 deletions app/script/client/ClientMapper.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Wire
# Copyright (C) 2016 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/.
#

window.z ?= {}
z.client ?= {}

class z.client.ClientMapper

###
Maps a JSON into a Client entity.
@param client_payload [JSON] Client payload
@return [z.client.Client] Client entity
###
map_client: (client_payload) ->
client_et = new z.client.Client client_payload

if client_payload.meta
client_et.meta.is_verified client_payload.meta.is_verified
client_et.meta.primary_key = client_payload.meta.primary_key
client_et.meta.user_id = (z.client.Client.dismantle_user_client_id client_payload.meta.primary_key).user_id

return client_et

###
Maps an object of client IDs with their payloads to client entities.
@param clients_payload [Array<JSON>] Client payloads
@return [Array<z.client.Client>] Array of client entities
###
map_clients: (clients_payload) ->
return (@map_client client_payload for client_payload in clients_payload)

###
Update a client entity or object from JSON.
@param client [z.client.Client or Object] Client
@param update_payload [JSON] JSON possibly containing updates
@return [Array<z.client.Client|Object, Boolean>] An array that contains the client and whether there was a change
###
update_client: (client, update_payload) ->
contains_update = false
for member of update_payload when JSON.stringify(client[member]) isnt JSON.stringify update_payload[member]
contains_update = true
client[member] = update_payload[member]
return [client, contains_update]
Loading

0 comments on commit a0990ff

Please sign in to comment.