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

Send and handle leave messages for XMPP MUC #246

Merged
merged 4 commits into from
Sep 1, 2021
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
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