Skip to content

Commit

Permalink
Merge pull request #246 from 67P/feature/239-xmpp_leave
Browse files Browse the repository at this point in the history
Send and handle leave messages for XMPP MUC
  • Loading branch information
raucao authored Sep 1, 2021
2 parents 0c50f4f + c682bf2 commit 68bc9ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
10 changes: 2 additions & 8 deletions app/services/coms.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,8 @@ export default class ComsService extends Service {
}

leaveChannel (channel) {
switch (channel.protocol) {
case 'XMPP':
// TODO implement
break;
case 'IRC':
this.irc.leave(channel);
break;
}
this.getServiceForSockethubPlatform(channel.protocol)
.leave(channel);
}

changeTopic (channel, topic) {
Expand Down
8 changes: 0 additions & 8 deletions app/services/sockethub-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions app/services/sockethub-xmpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -201,6 +214,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)
*
Expand Down

0 comments on commit 68bc9ba

Please sign in to comment.