Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.reactions;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smackx.reactions.element.ReactionsElement;

public interface ReactionsListener {

/**
* Listener method that gets called when a {@link Message} containing a {@link ReactionsElement} is received.
* @param reactionsElement reactionsElement
* @param message message
*/
void onReactionReceived(Message message, ReactionsElement reactionsElement);
Comment thread
ismael221 marked this conversation as resolved.
Outdated

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.reactions.element;

import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.StreamOpen;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.XmlStringBuilder;

/**
* Represents a reaction in the form of an emoji to be associated with a message in XMPP. This class
* is used to handle the individual reaction data, including the emoji and its associated message.
* It is an extension element used in XMPP messages.
*
* @see ExtensionElement
* @see Message
*/
public class Reaction implements ExtensionElement {
Comment thread
ismael221 marked this conversation as resolved.
Outdated

public static final String ELEMENT = "reaction";
public static final String NAMESPACE = StreamOpen.CLIENT_NAMESPACE;
Comment thread
ismael221 marked this conversation as resolved.
Outdated

private final String emoji;

/**
* Constructs a new Reaction with the specified emoji.
*
* @param emoji The emoji representing the reaction.
*/
public Reaction(String emoji) {
this.emoji = emoji;
}

/**
* Retrieves the emoji associated with this reaction.
*
* @return The emoji as a string.
*/
public String getEmoji() {
return emoji;
}

/**
* Returns the namespace for this extension element. As the namespace is empty, it returns an empty string.
*
* @return The namespace of the reaction element, which is an empty string.
*/
@Override
public String getNamespace() {
return NAMESPACE;
}

/**
* Returns the name of the XML element for this reaction, which is "reaction".
*
* @return The name of the XML element, which is "reaction".
*/
@Override
public String getElementName() {
return ELEMENT;
}

/**
* Converts this Reaction into an XML representation that can be included in an XMPP message.
*
* @param xmlEnvironment The XML environment for serializing the element.
* @return The XML string builder containing the XML representation of the reaction element.
*/
@Override
public CharSequence toXML(XmlEnvironment xmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
if (getEmoji() == null) {
xml.closeEmptyElement();
} else {
xml.rightAngleBracket();
xml.append(getEmoji());
xml.closeElement(this);
}
return xml;
}

/**
* Retrieves the Reaction extension from an XMPP message.
*
* @param message The XMPP message from which to extract the reaction.
* @return The Reaction extension from the message, or {@code null} if not present.
*/
public static Reaction fromMessage(Message message) {
Comment thread
ismael221 marked this conversation as resolved.
Outdated
return message.getExtension(Reaction.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.reactions.element;

import java.util.Collections;
import java.util.List;

import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.XmlStringBuilder;

/**
* Represents the reactions element in an XMPP message. This class is used to manage and serialize
* the list of reactions associated with a message, including the reactions' emojis and their identifiers.
* It is used as an extension element in XMPP messages to allow reactions to be sent and received.
*
* @see Reaction
* @see Message
* @see ExtensionElement
*/
public class ReactionsElement implements ExtensionElement {

public static final String ELEMENT = "reactions";
public static final String NAMESPACE = "urn:xmpp:reactions:0";

private final List<Reaction> reactions;
private final String id;

/**
* Constructs a new ReactionsElement with a list of reactions and an identifier.
*
* @param reactions A list of reactions associated with a message.
* @param id The ID of the message being reacted to.
*/
public ReactionsElement(List<Reaction> reactions, String id) {
this.reactions = Collections.unmodifiableList(reactions);
this.id = id;
}

/**
* Retrieves the list of reactions in this element.
*
* @return The list of reactions.
*/
public List<Reaction> getReactions() {
return reactions;
}

/**
* Retrieves the ID of the original message being reacted to.
*
* @return The ID of the original message.
*/
public String getId() {
return id;
}

/**
* Returns the namespace for this extension element.
*
* @return The namespace of the reactions element.
*/
@Override
public String getNamespace() {
return NAMESPACE;
}

/**
* Returns the name of the XML element associated with this extension.
*
* @return The element name for this extension, which is "reactions".
*/
@Override
public String getElementName() {
return ELEMENT;
}

/**
* Converts this ReactionsElement into an XML representation that can be included in an XMPP message.
*
* @param xmlEnvironment The XML environment for serialization.
* @return The XML string builder with the XML representation of the element.
*/
@Override
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("id", id);

xml.rightAngleBracket();
for (Reaction reaction : reactions) {
if (reaction != null) {
Comment thread
ismael221 marked this conversation as resolved.
Outdated
xml.append(reaction.toXML());
}
}
xml.closeElement(this);
return xml;
}

/**
* Retrieves the ReactionsElement from an XMPP message.
*
* @param message The XMPP message from which the reactions element is extracted.
* @return The ReactionsElement from the message, or {@code null} if not present.
*/
public static ReactionsElement fromMessage(Message message) {
return message.getExtension(ReactionsElement.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Smacks implementation of XEP-0444: Message Reactions.
*/
package org.jivesoftware.smackx.reactions.element;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.reactions.filter;

import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.filter.StanzaFilter;

import org.jivesoftware.smackx.reactions.element.ReactionsElement;

/**
* Message Reactions filter class.
*
* @see <a href="http://xmpp.org/extensions/xep-0313.html">XEP-0444: Message
* Reactions</a>
* @author Ismael Nunes Campos
*
*/
public final class ReactionsFilter extends StanzaExtensionFilter {
Comment thread
ismael221 marked this conversation as resolved.
Outdated

public static final StanzaFilter INSTANCE = new ReactionsFilter(ReactionsElement.ELEMENT, ReactionsElement.NAMESPACE);

private ReactionsFilter(String element, String namespace) {
super(element, namespace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Chat Markers elements (XEP-0444).
*
* @see <a href="https://xmpp.org/extensions/xep-0444.html">XEP-0444: Message
* Reactions</a>
*
*/
package org.jivesoftware.smackx.reactions.filter;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
*
* Copyright 2025 Ismael Nunes Campos
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Smack's API for XEP-0444: Message Reactions.
*/
package org.jivesoftware.smackx.reactions;
Loading