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

feat(chat) add support for sending and receiving reactions #2553

Merged
merged 19 commits into from
Aug 12, 2024
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
12 changes: 12 additions & 0 deletions JitsiConference.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I remove receiverId since the reactions that are attached to private messages will not be visible to others anyways?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, because we want the sender to decide to whom a reaction should be sent.

Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,18 @@ JitsiConference.prototype.sendTextMessage = function(message, elementName = 'bod
}
};

/**
* Sends a reaction to the other participants in the conference
* @param reaction the reaction.
* @param messageId the ID of the message to attach the reaction to.
* @param receiverId the intended recipient, if the message is private.
*/
JitsiConference.prototype.sendReaction = function(reaction, messageId, receiverId) {
if (this.room) {
this.room.sendReaction(reaction, messageId, receiverId);
}
};

/**
* Send private text message to another participant of the conference
* @param id the id of the participant to send a private message.
Expand Down
10 changes: 10 additions & 0 deletions JitsiConferenceEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
participantId, txt, ts, nick, isGuest, messageId);
});

chatRoom.addListener(
XMPPEvents.REACTION_RECEIVED,

(jid, reactionList, messageId) => {

conference.eventEmitter.emit(
JitsiConferenceEvents.REACTION_RECEIVED,
jid, reactionList, messageId);
});

chatRoom.addListener(
XMPPEvents.PRIVATE_MESSAGE_RECEIVED,

Expand Down
5 changes: 5 additions & 0 deletions JitsiConferenceEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export enum JitsiConferenceEvents {
*/
MESSAGE_RECEIVED = 'conference.messageReceived',

/**
* New reaction was received.
*/
REACTION_RECEIVED = 'conference.reactionReceived',

/**
* Event fired when the conference metadata is updated.
*/
Expand Down
38 changes: 38 additions & 0 deletions modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,26 @@ export default class ChatRoom extends Listenable {
this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, message);
}

/**
* Sends a reaction message to the other participants in the conference.
* @param {string} reaction - The reaction being sent.
* @param {string} messageId - The id of the message being sent.
* @param {string} receiverId - The receiver of the message if it is private.
*/
sendReaction(reaction, messageId, receiverId) {
// Adds the 'to' attribute depending on if the message is private or not.
const msg = receiverId ? $msg({ to: `${this.roomjid}/${receiverId}`,
type: 'chat' }) : $msg({ to: this.roomjid,
type: 'groupchat' });

msg.c('reactions', { id: messageId,
xmlns: 'urn:xmpp:reactions:0' })
.c('reaction', {}, reaction)
.up().c('store', { xmlns: 'urn:xmpp:hints' });

this.connection.send(msg);
}

/* eslint-disable max-params */
/**
* Send private text message to another participant of the conference
Expand Down Expand Up @@ -1144,6 +1164,24 @@ export default class ChatRoom extends Listenable {
return true;
}

const reactions = $(msg).find('>[xmlns="urn:xmpp:reactions:0"]>reaction');

if (reactions.length > 0) {
const messageId = $(msg).find('>[xmlns="urn:xmpp:reactions:0"]').attr('id');
const reactionList = [];

reactions.each((_, reactionElem) => {
const reaction = $(reactionElem).text();

reactionList.push(reaction);
});

this.eventEmitter.emit(XMPPEvents.REACTION_RECEIVED, from, reactionList, messageId);

return true;
}


const txt = $(msg).find('>body').text();
const subject = $(msg).find('>subject');

Expand Down
4 changes: 4 additions & 0 deletions service/xmpp/XMPPEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export enum XMPPEvents {
// received.
MESSAGE_RECEIVED = 'xmpp.message_received',

// Designates an event indicating that a reaction XMPP message in the MUC
// was received.
REACTION_RECEIVED = "xmpp.reaction_received",

// Designates an event indicating that an invite XMPP message in the MUC was
// received.
INVITE_MESSAGE_RECEIVED = 'xmpp.invite_message_received',
Expand Down