-
Notifications
You must be signed in to change notification settings - Fork 880
Implement XEP-0444: Message Reactions in Smack #647
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
Open
ismael221
wants to merge
3
commits into
igniterealtime:master
Choose a base branch
from
ismael221:dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/ReactionsListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| } | ||
364 changes: 364 additions & 0 deletions
364
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/ReactionsManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/element/Reaction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
ismael221 marked this conversation as resolved.
Outdated
|
||
|
|
||
| public static final String ELEMENT = "reaction"; | ||
| public static final String NAMESPACE = StreamOpen.CLIENT_NAMESPACE; | ||
|
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) { | ||
|
ismael221 marked this conversation as resolved.
Outdated
|
||
| return message.getExtension(Reaction.class); | ||
| } | ||
| } | ||
123 changes: 123 additions & 0 deletions
123
...xperimental/src/main/java/org/jivesoftware/smackx/reactions/element/ReactionsElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
|
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); | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/element/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
39 changes: 39 additions & 0 deletions
39
...-experimental/src/main/java/org/jivesoftware/smackx/reactions/filter/ReactionsFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
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); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/filter/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
21 changes: 21 additions & 0 deletions
21
smack-experimental/src/main/java/org/jivesoftware/smackx/reactions/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.