diff --git a/app/components/add-chat-account-xmpp/component.js b/app/components/add-chat-account-xmpp/component.js index 1c066f77..bd4bd1d6 100644 --- a/app/components/add-chat-account-xmpp/component.js +++ b/app/components/add-chat-account-xmpp/component.js @@ -15,46 +15,11 @@ export default class AddChatAccountXmppComponent extends Component { @tracked hostname = 'kosmos.org'; @tracked password; @tracked connectError = null; - @tracked finishedSetup = false; get userAddress () { return `${this.username}@${this.hostname}`; } - async handleConnectStatus (eventName, message) { - if (this.finishedSetup) { - // TODO remove when double events fixed - console.debug('Account setup already finished, nothing to do') - return; - } - - if (message.context !== 'xmpp' || - !['message', 'completed'].includes(eventName)) { return; } - - if (message.type === 'error' && - message.object.condition === 'not-authorized' - /* && TODO message.actor.id === actor */) { - this.connectError = { - title: 'Account connection failed', - content: message.object.content - } - this.xmpp.sockethub.socket.offAny(); - } - - if (message.type === 'connect' && - message.actor.id === `${this.userAddress}/hyperchannel`) { - // Connected successfully - this.xmpp.sockethub.socket.offAny(); - - const account = await this.addAccount(); - this.addDefaultChannels(account); - this.finishedSetup = true; - - const firstChannel = this.coms.channels.filterBy('account', account).firstObject; - this.router.transitionTo('channel', firstChannel); - } - } - async addAccount () { const account = new XmppAccount({ username: this.userAddress, @@ -81,8 +46,19 @@ export default class AddChatAccountXmppComponent extends Component { submitForm (e) { e.preventDefault(); this.connectError = null; - this.xmpp.sockethub.socket.onAny(this.handleConnectStatus.bind(this)); - this.xmpp.connectWithCredentials(this.userAddress, this.password); + this.xmpp.connectWithCredentials(this.userAddress, this.password, async (message) => { + if (message.error) { + this.connectError = { + title: 'Account connection failed', + content: message.error + } + } else { + const account = await this.addAccount(); + this.addDefaultChannels(account); + const firstChannel = this.coms.channels.filterBy('account', account).firstObject; + this.router.transitionTo('channel', firstChannel); + } + }); } } diff --git a/app/services/coms.js b/app/services/coms.js index 64646fce..c9176956 100644 --- a/app/services/coms.js +++ b/app/services/coms.js @@ -47,7 +47,7 @@ export default class ComsService extends Service { return { domain: domain, channels: this.channels.filterBy('domain', domain).sortBy('name') - } + }; }); } @@ -65,9 +65,7 @@ export default class ComsService extends Service { * @public */ setupListeners () { - this.sockethub.socket.on('completed', this.handleSockethubCompleted.bind(this)); this.sockethub.socket.on('message' , this.handleSockethubMessage.bind(this)); - this.sockethub.socket.on('failure' , this.handleSockethubFailure.bind(this)); } /** @@ -204,7 +202,8 @@ export default class ComsService extends Service { removeUserFromChannelUserList (message) { // TODO handle user quit leaves (multiple channels) // e.g. target is `{ type: 'service', id: 'irc.freenode.net' }` - const channel = this.getChannel(message.target.id); + const sockethubChannelId = typeof message.target === 'object' ? message.target.id : message.target; + const channel = this.getChannel(sockethubChannelId); if (channel) { channel.removeUser(message.actor.name); } @@ -384,22 +383,6 @@ export default class ComsService extends Service { return this[protocol.toLowerCase()]; } - /* - * @private - * - * Handles completed Sockethub actions: - * - Successfully joined a channel - */ - handleSockethubCompleted (message) { - this.log(`${message.context}_completed`, message); - - switch (message.type) { - case 'join': - this[message.context].handleJoinCompleted(message); - break; - } - } - /** * Handles incoming Sockethub messages: * - Attendance list for channel @@ -418,12 +401,6 @@ export default class ComsService extends Service { this.updateChannelUserList(message); } break; - case 'join': - this.handleChannelJoin(message); - break; - case 'leave': - this.removeUserFromChannelUserList(message); - break; case 'send': switch (message.object.type) { case 'message': @@ -451,47 +428,13 @@ export default class ComsService extends Service { .handlePresenceUpdate(message) break; case 'error': - console.warn('Got error update message', message.actor.id, message.object.content); + console.warn('Received error update message', message.actor.id, message.object.content); break; } break; - // case 'error': - // switch(message.context) { - // case 'xmpp': - // this.xmpp.handleErrorMessage(message); - // break; - // } - // break; } } - /** - * Handles the various checks assosciated with channel joins - * @private - */ - handleChannelJoin (message) { - if (message.object.type && message.object.type === 'error') { - // failed to join a channel - const channel = this.getChannel(message.target.id, message.actor.id); - - if (isPresent(channel)) { - channel.connected = false; - } else { - console.warn('Could not find channel for error message', message); - } - } else { - this.addUserToChannelUserList(message); - } - } - - /** - * Handles incoming Sockethub errors/failures - * @private - */ - handleSockethubFailure (message) { - this.log('sh_failure', message); - } - /** * Utility function for easier logging * @private diff --git a/app/services/sockethub-irc.js b/app/services/sockethub-irc.js index adacbf23..20bb8aad 100644 --- a/app/services/sockethub-irc.js +++ b/app/services/sockethub-irc.js @@ -135,7 +135,7 @@ export default class SockethubIrcService extends Service { }); this.log('irc', 'joining channel', joinMsg); - this.sockethub.socket.emit('message', joinMsg); + this.sockethub.socket.emit('message', joinMsg, this.handleJoinCompleted.bind(this)); break; case 'person': channel.connected = true; diff --git a/app/services/sockethub-xmpp.js b/app/services/sockethub-xmpp.js index b95ffef1..f16d0628 100644 --- a/app/services/sockethub-xmpp.js +++ b/app/services/sockethub-xmpp.js @@ -57,7 +57,7 @@ export default class SockethubXmppService extends Service { @service logger; @service coms; - connectWithCredentials (userAddress, password) { + connectWithCredentials (userAddress, password, callback) { const sockethubPersonId = `${userAddress}/hyperchannel`; this.sockethub.ActivityStreams.Object.create({ @@ -85,8 +85,10 @@ export default class SockethubXmppService extends Service { }; this.log('xmpp', 'connecting to XMPP server...'); - this.sockethub.socket.emit('credentials', credentialsJob); - this.sockethub.socket.emit('message', connectJob); + this.sockethub.socket.emit('credentials', credentialsJob, (err) => { + if (err) { this.log('failed to store credentials: ', err); } + }); + this.sockethub.socket.emit('message', connectJob, callback); } /** @@ -123,8 +125,13 @@ export default class SockethubXmppService extends Service { }; this.log('xmpp', 'connecting to XMPP server...'); - this.sockethub.socket.emit('credentials', credentialsJob); - this.sockethub.socket.emit('message', connectJob); + this.sockethub.socket.emit('credentials', credentialsJob, (err) => { + if (err) { this.log('failed to store credentials: ', err); } + }); + this.sockethub.socket.emit('message', connectJob, (message) => { + if (message.error) { this.log('failed to connect to xmpp server: ', message); } + else { this.coms.handleSockethubMessage(message); } + }); } handleJoinCompleted (message) { @@ -158,14 +165,11 @@ export default class SockethubXmppService extends Service { id: channel.sockethubPersonId, name: channel.account.nickname }, - target: { - id: channel.sockethubChannelId, - type: type - } + target: channel.sockethubChannelId }); this.log('xmpp', 'joining channel', joinMsg); - this.sockethub.socket.emit('message', joinMsg); + this.sockethub.socket.emit('message', joinMsg, this.handleJoinCompleted.bind(this)); } /** @@ -239,12 +243,17 @@ export default class SockethubXmppService extends Service { if (!channel.isUserChannel) { const leaveMsg = buildActivityObject(channel.account, { type: 'leave', - target: channel.sockethubChannelId, - object: {} + target: channel.sockethubChannelId }); this.log('leave', 'leaving channel', leaveMsg); - this.sockethub.socket.emit('message', leaveMsg); + this.sockethub.socket.emit('message', leaveMsg, (message) => { + if (message.error) { + console.warn(message.error); + } else { + this.coms.removeUserFromChannelUserList.bind(this.coms) + } + }); } } @@ -284,7 +293,7 @@ export default class SockethubXmppService extends Service { if (message.target.type === 'room') { channel = this.coms.channels.findBy('sockethubChannelId', targetChannelId); - // TODO Find account for new channel by sockerhubPersonId + // TODO Find account for new channel by sockethubPersonId if (!channel) { console.warn('Received message for unknown channel', message); // channel = this.coms.createChannel(space, targetChannelId); diff --git a/release/index.html b/release/index.html index 4a94f4a3..a1adfea5 100644 --- a/release/index.html +++ b/release/index.html @@ -7,18 +7,17 @@ - + - + - - + diff --git a/vendor/sh-assets-local.html b/vendor/sh-assets-local.html index 421c7d43..bb2cd599 100644 --- a/vendor/sh-assets-local.html +++ b/vendor/sh-assets-local.html @@ -1,3 +1,2 @@ - diff --git a/vendor/sh-assets-remote.html b/vendor/sh-assets-remote.html index 3a6a4f6e..a7fa69af 100644 --- a/vendor/sh-assets-remote.html +++ b/vendor/sh-assets-remote.html @@ -1,3 +1,2 @@ -