Hook up UI to all the server creation logic etc

pull/557/head
Beaudan Brown 6 years ago
parent 4e70b66131
commit 363cd81ccc

@ -37,7 +37,7 @@ class LokiAppDotNetAPI extends EventEmitter {
thisServer = new LokiAppDotNetServerAPI(this, serverUrl);
const gotToken = await thisServer.getOrRefreshServerToken();
if (!gotToken) {
log.error(`Invalid server ${serverUrl}`);
log.warn(`Invalid server ${serverUrl}`);
return null;
}
log.info(`set token ${thisServer.token}`);

@ -1,8 +1,9 @@
/* global log */
const LokiAppDotNetAPI = require('./loki_app_dot_net_api');
const DEVICE_MAPPING_ANNOTATION_KEY = 'network.loki.messenger.devicemapping';
class LokiFileServerAPI {
constructor(ourKey) {
this.ourKey = ourKey;
@ -13,7 +14,7 @@ class LokiFileServerAPI {
this._server = await this._adnApi.findOrCreateServer(serverUrl);
// TODO: Handle this failure gracefully
if (!this._server) {
// console.error('Failed to establish connection to file server');
log.error('Failed to establish connection to file server');
}
}

@ -29,16 +29,48 @@
};
},
confirm() {
const serverUrl = this.$('#server-url').val();
console.log(`You confirmed the adding of a new server: ${serverUrl}`);
const dialog = new Whisper.ConnectingToServerDialogView({ serverUrl });
// Remove error if there is one
this.showError(null);
const serverUrl = this.$('#server-url').val().toLowerCase();
// TODO: Make this not hard coded
const channelId = 1;
const dialog = new Whisper.ConnectingToServerDialogView({
serverUrl,
channelId,
});
const dialogDelayTimer = setTimeout(() => {
this.el.append(dialog.el);
},
async validateServer() {
}, 200);
dialog.once('connectionResult', result => {
clearTimeout(dialogDelayTimer);
if (result.cancelled) {
this.showError(null);
return;
}
if (result.errorCode) {
this.showError(result.errorCode);
return;
}
window.Whisper.events.trigger('showToast', {
message: i18n('connectToServerSuccess'),
});
this.close();
});
dialog.trigger('attemptConnection');
},
close() {
this.remove();
},
showError(message) {
if (_.isEmpty(message)) {
this.$('.error').text('');
this.$('.error').hide();
} else {
this.$('.error').text(`Error: ${message}`);
this.$('.error').show();
}
this.$('input').focus();
},
onKeyup(event) {
switch (event.key) {
case 'Enter':

@ -10,18 +10,55 @@
templateName: 'connecting-to-server-template',
className: 'loki-dialog connecting-to-server modal',
initialize(options = {}) {
console.log(`Add server init: ${options}`);
this.title = i18n('loading');
this.title = i18n('connectingLoad');
this.cancelText = options.cancelText || i18n('cancel');
this.render();
this.$('.connecting-to-server').bind('keyup', event => this.onKeyup(event));
const serverAPI = lokiPublicChatAPI.findOrCreateServer(
options.serverUrl
this.serverUrl = options.serverUrl;
this.channelId = options.channelId;
this.once('attemptConnection', () =>
this.attemptConnection(options.serverUrl, options.channelId)
);
this.render();
},
events: {
keyup: 'onKeyup',
'click .cancel': 'close',
},
async attemptConnection(serverUrl, channelId) {
const rawServerUrl = serverUrl
.replace(/^https?:\/\//i, '')
.replace(/[/\\]+$/i, '');
const sslServerUrl = `https://${rawServerUrl}`;
const conversationId = `publicChat:${channelId}@${rawServerUrl}`;
const conversationExists = ConversationController.get(conversationId);
if (conversationExists) {
// We are already a member of this public chat
return this.resolveWith({ errorCode: i18n('publicChatExists') });
}
const serverAPI = await lokiPublicChatAPI.findOrCreateServer(
sslServerUrl
);
if (!serverAPI) {
// Url incorrect or server not compatible
return this.resolveWith({ errorCode: i18n('connectToServerFail') });
}
const conversation = await ConversationController.getOrCreateAndWait(
conversationId,
'group'
);
serverAPI.findOrCreateChannel(channelId, conversationId);
await conversation.setPublicSource(sslServerUrl, channelId);
await conversation.setFriendRequestStatus(
friends.friendRequestStatusEnum.friends
);
return this.resolveWith({ conversation });
},
resolveWith(result) {
this.trigger('connectionResult', result);
this.remove();
},
render_attributes() {
return {
title: this.title,
@ -29,6 +66,7 @@
};
},
close() {
this.trigger('connectionResult', { cancelled: true });
this.remove();
},
onKeyup(event) {

Loading…
Cancel
Save