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 "service" #1080

Merged
merged 1 commit into from
Apr 27, 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
2 changes: 1 addition & 1 deletion app/page/template/_dist/app.htm
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<script src="/script/config.js"></script>
<!-- Client -->
<script src="/script/service/BackendClientError.js"></script>
<script src="/script/service/BackendClient.js"></script>
<script src="/script/service/BackendEnvironment.js"></script>
<script src="/script/service/Client.js"></script>
<script src="/script/service/RequestQueueBlockedState.js"></script>
<!-- Events -->
<script src="/script/event/Backend.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/script/assets/AssetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ z.assets.AssetService = class AssetService {

/**
* Construct a new Asset Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.cancel_asset_upload = this.cancel_asset_upload.bind(this);
Expand Down
8 changes: 4 additions & 4 deletions app/script/auth/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ z.auth.AuthService = class AuthService {
};

config.error = (jqXHR, textStatus, errorThrown) => {
if (jqXHR.status === z.service.BackendClientError.prototype.STATUS_CODE.FORBIDDEN) {
if (jqXHR.status === z.service.BackendClientError.STATUS_CODE.FORBIDDEN) {
this.logger.error(`Requesting access token failed after ${retry_attempt} attempt(s): ${errorThrown}`, jqXHR);
reject(new z.auth.AccessTokenError(z.auth.AccessTokenError.TYPE.REQUEST_FORBIDDEN));
}
Expand All @@ -114,9 +114,9 @@ z.auth.AuthService = class AuthService {
.then(resolve)
.catch(reject);

if (jqXHR.status === z.service.BackendClientError.prototype.STATUS_CODE.CONNECTIVITY_PROBLEM) {
if (jqXHR.status === z.service.BackendClientError.STATUS_CODE.CONNECTIVITY_PROBLEM) {
this.logger.warn('Access token refresh delayed due to suspected connectivity issue');
return this.client.execute_on_connectivity(z.service.Client.prototype.CONNECTIVITY_CHECK_TRIGGER.ACCESS_TOKEN_REFRESH)
return this.client.execute_on_connectivity(z.service.BackendClient.CONNECTIVITY_CHECK_TRIGGER.ACCESS_TOKEN_REFRESH)
.then(() => {
this.logger.info('Continuing access token refresh after verifying connectivity');
return _retry();
Expand Down Expand Up @@ -209,7 +209,7 @@ z.auth.AuthService = class AuthService {
resolve(data);
})
.fail((jqXHR, textStatus, errorThrown) => {
if (jqXHR.status === z.service.BackendClientError.prototype.STATUS_CODE.TOO_MANY_REQUESTS && login.email) {
if (jqXHR.status === z.service.BackendClientError.STATUS_CODE.TOO_MANY_REQUESTS && login.email) {
// Backend blocked our user account from login, so we have to reset our cookies
this.post_cookies_remove(login.email, login.password, undefined).then(() => {
reject(jqXHR.responseJSON || errorThrown);
Expand Down
2 changes: 1 addition & 1 deletion app/script/calling/entities/Flow.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class z.calling.entities.Flow

on_failure = (error) =>
@logger.warn "Failed to send local '#{@local_sdp().type}' SDP"
if error.code is z.service.BackendClientError::STATUS_CODE.NOT_FOUND
if error.code is z.service.BackendClientError.STATUS_CODE.NOT_FOUND
return @reset_flow()
@has_sent_local_sdp false

Expand Down
2 changes: 1 addition & 1 deletion app/script/calling/handler/CallSignalingHandler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class z.calling.handler.CallSignalingHandler
@logger.debug 'Flow was released - We need implement posting for flows to renegotiate'
return response
.catch (error) =>
if error.label is z.service.BackendClientError::LABEL.IN_USE
if error.label is z.service.BackendClientError.LABEL.IN_USE
@logger.warn "DELETEing flow '#{flow_info.flow_id}' would have to be forced"
flow_info.reason = z.calling.payloads.FlowDeletionReason.RELEASED
return @delete_flow flow_info
Expand Down
6 changes: 3 additions & 3 deletions app/script/calling/handler/CallStateHandler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ class z.calling.handler.CallStateHandler
@v2_call_center.telemetry.track_event z.tracking.EventName.CALLING.FAILED_REQUEST, undefined, attributes
@v2_call_center.media_stream_handler.release_media_stream()
switch error.label
when z.service.BackendClientError::LABEL.CONVERSATION_TOO_BIG
when z.service.BackendClientError.LABEL.CONVERSATION_TOO_BIG
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.CALL_FULL_CONVERSATION,
data: error.max_members
throw new z.calling.v2.CallError z.calling.v2.CallError::TYPE.CONVERSATION_TOO_BIG
when z.service.BackendClientError::LABEL.INVALID_OPERATION
when z.service.BackendClientError.LABEL.INVALID_OPERATION
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.CALL_EMPTY_CONVERSATION
@delete_call conversation_id
throw new z.calling.v2.CallError z.calling.v2.CallError::TYPE.CONVERSATION_EMPTY
when z.service.BackendClientError::LABEL.VOICE_CHANNEL_FULL
when z.service.BackendClientError.LABEL.VOICE_CHANNEL_FULL
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.CALL_FULL_VOICE_CHANNEL,
data: error.max_joined
throw new z.calling.v2.CallError z.calling.v2.CallError::TYPE.VOICE_CHANNEL_FULL
Expand Down
6 changes: 3 additions & 3 deletions app/script/client/ClientRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ z.client.ClientRepository = class ClientRepository {
const client_et = this.current_client();
this.current_client(undefined);

if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.NOT_FOUND) {
if (error.code === z.service.BackendClientError.STATUS_CODE.NOT_FOUND) {
this.logger.warn(`Local client '${client_et.id}' (${client_et.type}) no longer exists on the backend`, error);
return Promise.resolve()
.then(() => {
Expand Down Expand Up @@ -289,7 +289,7 @@ z.client.ClientRepository = class ClientRepository {
return this.client_service.post_clients(this._create_registration_payload(client_type, password, keys));
})
.catch((error) => {
if (error.label === z.service.BackendClientError.prototype.LABEL.TOO_MANY_CLIENTS) {
if (error.label === z.service.BackendClientError.LABEL.TOO_MANY_CLIENTS) {
throw new z.client.ClientError(z.client.ClientError.TYPE.TOO_MANY_CLIENTS);
}
this.logger.error(`Client registration request failed: ${error.message}`, error);
Expand Down Expand Up @@ -471,7 +471,7 @@ z.client.ClientRepository = class ClientRepository {
this.logger.error(`Unable to delete client '${client_id}': ${error.message}`, error);
amplify.publish(z.event.WebApp.ANALYTICS.EVENT, z.tracking.EventName.SETTINGS.REMOVED_DEVICE, {outcome: 'fail'});

if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.FORBIDDEN) {
if (error.code === z.service.BackendClientError.STATUS_CODE.FORBIDDEN) {
error = new z.client.ClientError(z.client.ClientError.TYPE.REQUEST_FORBIDDEN);
} else {
error = new z.client.ClientError(z.client.ClientError.TYPE.REQUEST_FAILURE);
Expand Down
6 changes: 3 additions & 3 deletions app/script/connect/ConnectRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ z.connect.ConnectRepository = class ConnectRepository {
case z.connect.ConnectError.TYPE.NO_CONTACTS:
return {};
default:
if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.TOO_MANY_REQUESTS) {
if (error.code === z.service.BackendClientError.STATUS_CODE.TOO_MANY_REQUESTS) {
this.logger.error('Backend refused Gmail contacts upload: Endpoint used too frequent', error);
} else {
this.logger.error('Gmail contacts upload failed', error);
Expand Down Expand Up @@ -106,7 +106,7 @@ z.connect.ConnectRepository = class ConnectRepository {
case z.connect.ConnectError.TYPE.NO_CONTACTS:
return {};
default:
if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.TOO_MANY_REQUESTS) {
if (error.code === z.service.BackendClientError.STATUS_CODE.TOO_MANY_REQUESTS) {
this.logger.error('Backend refused macOS contacts upload: Endpoint used too frequent', error);
} else {
this.logger.error('macOS contacts upload failed', error);
Expand Down Expand Up @@ -138,7 +138,7 @@ z.connect.ConnectRepository = class ConnectRepository {
case z.connect.ConnectError.TYPE.NO_CONTACTS:
return {};
default:
if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.TOO_MANY_REQUESTS) {
if (error.code === z.service.BackendClientError.STATUS_CODE.TOO_MANY_REQUESTS) {
this.logger.error('Backend refused macOS contacts upload: Endpoint used too frequent');
} else {
this.logger.error('macOS contacts upload failed', error);
Expand Down
7 changes: 3 additions & 4 deletions app/script/conversation/ConversationRepository.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class z.conversation.ConversationRepository
@filtered_conversations().sort z.util.sort_groups_by_last_event

@receiving_queue = new z.util.PromiseQueue()
@sending_queue = new z.util.PromiseQueue()
@sending_queue.pause()
@sending_queue = new z.util.PromiseQueue paused: true

# @note Only use the client request queue as to unblock if not blocked by event handling or the cryptographic order of messages will be ruined and sessions might be deleted
@conversation_service.client.request_queue_blocked_state.subscribe (state) =>
Expand Down Expand Up @@ -591,7 +590,7 @@ class z.conversation.ConversationRepository
.then (response) ->
amplify.publish z.event.WebApp.EVENT.INJECT, response
.catch (error_response) ->
if error_response.label is z.service.BackendClientError::LABEL.TOO_MANY_MEMBERS
if error_response.label is z.service.BackendClientError.LABEL.TOO_MANY_MEMBERS
amplify.publish z.event.WebApp.WARNING.MODAL, z.ViewModel.ModalType.TOO_MANY_MEMBERS,
data:
max: z.config.MAXIMUM_CONVERSATION_SIZE
Expand Down Expand Up @@ -1400,7 +1399,7 @@ class z.conversation.ConversationRepository
payload.native_push = native_push
@_send_encrypted_message conversation_id, generic_message, payload, precondition_option
.catch (error) =>
if error?.code is z.service.BackendClientError::STATUS_CODE.REQUEST_TOO_LARGE
if error.code is z.service.BackendClientError.STATUS_CODE.REQUEST_TOO_LARGE
return @_send_external_generic_message conversation_id, generic_message, user_client_map, precondition_option, native_push
throw error

Expand Down
2 changes: 1 addition & 1 deletion app/script/conversation/ConversationService.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class z.conversation.ConversationService
###
Construct a new Conversation Service.
@param client [z.service.Client] Client for the API calls
@param client [z.service.BackendClient] Client for the API calls
###
constructor: (@client, @storage_service) ->
@logger = new z.util.Logger 'z.conversation.ConversationService', z.config.LOGGER.OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion app/script/cryptography/CryptographyRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ z.cryptography.CryptographyRepository = class CryptographyRepository {
get_users_pre_keys(user_client_map) {
return this.cryptography_service.get_users_pre_keys(user_client_map)
.catch((error) => {
if (error.code === z.service.BackendClientError.prototype.STATUS_CODE.NOT_FOUND) {
if (error.code === z.service.BackendClientError.STATUS_CODE.NOT_FOUND) {
throw new z.user.UserError(z.user.UserError.prototype.TYPE.PRE_KEY_NOT_FOUND);
}
this.logger.error(`Failed to get pre-key from backend: ${error.message}`);
Expand Down
2 changes: 1 addition & 1 deletion app/script/cryptography/CryptographyService.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ z.cryptography.CryptographyService = class CryptographyService {

/**
* Construct a new Cryptography Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.client = client;
Expand Down
2 changes: 1 addition & 1 deletion app/script/event/EventRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ z.event.EventRepository = class EventRepository {
return _got_notifications(error_response);
}

if (error_response.code === z.service.BackendClientError.prototype.STATUS_CODE.NOT_FOUND) {
if (error_response.code === z.service.BackendClientError.STATUS_CODE.NOT_FOUND) {
this.logger.info(`No notifications found since '${notification_id}'`, error_response);
return reject(new z.event.EventError(z.event.EventError.TYPE.NO_NOTIFICATIONS));
}
Expand Down
2 changes: 1 addition & 1 deletion app/script/event/NotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ z.event.NotificationService = class NotificationService {
/**
* Construct a new Notification Service.
*
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
* @param {z.storage.StorageService} storage_service - Service for all storage related tasks
*/
constructor(client, storage_service) {
Expand Down
2 changes: 1 addition & 1 deletion app/script/event/WebSocketService.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ z.event.WebSocketService = class WebSocketService {

/**
* Construct a new WebSocket Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.client = client;
Expand Down
2 changes: 1 addition & 1 deletion app/script/extension/GiphyService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ z.extension.GiphyService = class GiphyService {

/**
* Construct a new Giphy Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.client = client;
Expand Down
8 changes: 4 additions & 4 deletions app/script/main/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ z.main.App = class App {
this.logger.debug(`App reload: '${is_reload}', Document referrer: '${document.referrer}', Location: '${window.location.href}'`);

if (is_reload && ![z.client.ClientError.TYPE.MISSING_ON_BACKEND, z.client.ClientError.TYPE.NO_LOCAL_CLIENT].includes(error.type)) {
return this.auth.client.execute_on_connectivity(z.service.Client.prototype.CONNECTIVITY_CHECK_TRIGGER.APP_INIT_RELOAD).then(() => window.location.reload(false));
return this.auth.client.execute_on_connectivity(z.service.BackendClient.CONNECTIVITY_CHECK_TRIGGER.APP_INIT_RELOAD).then(() => window.location.reload(false));
}

if (navigator.onLine) {
Expand Down Expand Up @@ -315,7 +315,7 @@ z.main.App = class App {
*/
on_internet_connection_gained() {
this.logger.info('Internet connection regained. Re-establishing WebSocket connection...');
this.auth.client.execute_on_connectivity(z.service.Client.prototype.CONNECTIVITY_CHECK_TRIGGER.CONNECTION_REGAINED)
this.auth.client.execute_on_connectivity(z.service.BackendClient.CONNECTIVITY_CHECK_TRIGGER.CONNECTION_REGAINED)
.then(() => {
amplify.publish(z.event.WebApp.WARNING.DISMISS, z.ViewModel.WarningType.NO_INTERNET);
amplify.publish(z.event.WebApp.WARNING.SHOW, z.ViewModel.WarningType.CONNECTIVITY_RECONNECT);
Expand Down Expand Up @@ -420,7 +420,7 @@ z.main.App = class App {
return this._redirect_to_login(true);
}
this.logger.warn('Connectivity issues. Trigger reload on regained connectivity.', error);
return this.auth.client.execute_on_connectivity(z.service.Client.prototype.CONNECTIVITY_CHECK_TRIGGER.ACCESS_TOKEN_RETRIEVAL)
return this.auth.client.execute_on_connectivity(z.service.BackendClient.CONNECTIVITY_CHECK_TRIGGER.ACCESS_TOKEN_RETRIEVAL)
.then(function() {
window.location.reload(false);
});
Expand Down Expand Up @@ -599,7 +599,7 @@ z.main.App = class App {
*/
_redirect_to_login(session_expired) {
this.logger.info(`Redirecting to login after connectivity verification. Session expired: ${session_expired}`);
this.auth.client.execute_on_connectivity(z.service.Client.prototype.CONNECTIVITY_CHECK_TRIGGER.LOGIN_REDIRECT)
this.auth.client.execute_on_connectivity(z.service.BackendClient.CONNECTIVITY_CHECK_TRIGGER.LOGIN_REDIRECT)
.then(function() {
let url = `/auth/${location.search}`;
if (session_expired) {
Expand Down
2 changes: 1 addition & 1 deletion app/script/main/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ z.main.Auth = class Auth {
constructor(settings) {
this.settings = settings;
this.audio = new z.audio.AudioRepository();
this.client = new z.service.Client(this.settings);
this.client = new z.service.BackendClient(this.settings);
this.service = new z.auth.AuthService(this.client);
this.repository = new z.auth.AuthRepository(this.service);
return this;
Expand Down
2 changes: 1 addition & 1 deletion app/script/properties/PropertiesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ z.properties.PropertiesService = class PropertiesService {

/**
* Construct a new Properties Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.client = client;
Expand Down
2 changes: 1 addition & 1 deletion app/script/search/SearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ window.z.search = z.search || {};
z.search.SearchService = class SearchService {
/**
* Construct a new Search Service.
* @param {z.service.Client} client - Client for the API calls
* @param {z.service.BackendClient} client - Client for the API calls
*/
constructor(client) {
this.client = client;
Expand Down
Loading