From 793c1064a7a7963e656cfc05c0bd444947da8038 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Tue, 31 Aug 2021 14:20:41 +0200 Subject: [PATCH 1/4] Send leave message for XMPP MUC Closes #239 --- app/services/coms.js | 2 +- app/services/sockethub-xmpp.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/services/coms.js b/app/services/coms.js index 81c8a756..8cb92b1a 100644 --- a/app/services/coms.js +++ b/app/services/coms.js @@ -173,7 +173,7 @@ export default class ComsService extends Service { leaveChannel (channel) { switch (channel.protocol) { case 'XMPP': - // TODO implement + this.xmpp.leave(channel); break; case 'IRC': this.irc.leave(channel); diff --git a/app/services/sockethub-xmpp.js b/app/services/sockethub-xmpp.js index 15dbb397..d1bfed73 100644 --- a/app/services/sockethub-xmpp.js +++ b/app/services/sockethub-xmpp.js @@ -201,6 +201,19 @@ export default class SockethubXmppService extends Service { channel.addMessage(channelMessage); } + leave (channel) { + if (!channel.isUserChannel) { + const leaveMsg = buildActivityObject(channel.account, { + '@type': 'leave', + target: channel.sockethubChannelId, + object: {} + }); + + this.log('leave', 'leaving channel', leaveMsg); + this.sockethub.socket.emit('message', leaveMsg); + } + } + /** * Ask for a channel's attendance list (users currently joined) * From 22ba0a282558734394057dabe9491f0f0cab7bf9 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Tue, 31 Aug 2021 14:22:09 +0200 Subject: [PATCH 2/4] Remove unnecessary AS object creation Creating the ActivityStream object is not needed when leaving an IRC room. --- app/services/sockethub-irc.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/services/sockethub-irc.js b/app/services/sockethub-irc.js index 0f180810..5c0d82b7 100644 --- a/app/services/sockethub-irc.js +++ b/app/services/sockethub-irc.js @@ -194,14 +194,6 @@ export default class SockethubIrcService extends Service { */ leave (channel) { if (!channel.isUserChannel) { - // TODO Do we really need to create this room for leaving? It should - // already have been created when joining. - this.sockethub.ActivityStreams.Object.create({ - '@type': "room", - '@id': channel.sockethubChannelId, - displayName: channel.name - }); - let leaveMsg = buildActivityObject(channel.account, { '@type': 'leave', target: channel.sockethubChannelId, From e4556388fb0f068073c477edf18c431b21034b45 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Tue, 31 Aug 2021 16:12:42 +0200 Subject: [PATCH 3/4] Remove obsolete switch statement --- app/services/coms.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/services/coms.js b/app/services/coms.js index 8cb92b1a..ecd90be5 100644 --- a/app/services/coms.js +++ b/app/services/coms.js @@ -171,14 +171,8 @@ export default class ComsService extends Service { } leaveChannel (channel) { - switch (channel.protocol) { - case 'XMPP': - this.xmpp.leave(channel); - break; - case 'IRC': - this.irc.leave(channel); - break; - } + this.getServiceForSockethubPlatform(channel.protocol) + .leave(channel); } changeTopic (channel, topic) { From c682bf28dbac4bb11929518d96258ea6a54eea3a Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Tue, 31 Aug 2021 19:58:48 +0200 Subject: [PATCH 4/4] Handle incoming presence unavailable updates --- app/services/sockethub-xmpp.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/services/sockethub-xmpp.js b/app/services/sockethub-xmpp.js index d1bfed73..2b4cc7e8 100644 --- a/app/services/sockethub-xmpp.js +++ b/app/services/sockethub-xmpp.js @@ -174,6 +174,19 @@ export default class SockethubXmppService extends Service { channel.addUser(message.actor.displayName); } } + } else if (message.actor['@type'] === 'person' && message.actor['@id'].match(/\/(.+)$/)) { + const sockethubActorId = message.actor['@id']; + const targetChannelId = sockethubActorId.match(/^(.+)\//)[1]; + const channel = this.coms.getChannel(targetChannelId); + const displayName = sockethubActorId.match(/\/(.+)$/)[1]; + + if (channel) { + if (message.object.presence === 'unavailable') { + channel.removeUser(displayName); + } else { + channel.addUser(displayName); + } + } } else { this.log('xmpp', 'presence update from contact:', message.actor['@id'], message.object.presence, message.object.status); }