mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-02-04 19:25:37 +00:00
SPARK-2355: MessageFilter.filterOutgoing() receive a MessageBuilder because it may be modified
This commit is contained in:
committed by
Guus der Kinderen
parent
bc364b545b
commit
f82bbd7a2a
@ -20,6 +20,7 @@ import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.chat2.Chat;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smackx.chatstates.ChatState;
|
||||
import org.jivesoftware.smackx.chatstates.ChatStateListener;
|
||||
@ -470,19 +471,19 @@ public class ChatManager {
|
||||
* Notifies all <code>MessageFilter</code>s about a new outgoing message.
|
||||
*
|
||||
* @param room the <code>ChatRoom</code> the message belongs too.
|
||||
* @param message the <code>Message</code> being sent.
|
||||
* @param messageBuilder the <code>Message</code> being sent.
|
||||
*/
|
||||
public void filterOutgoingMessage( ChatRoom room, Message message )
|
||||
public void filterOutgoingMessage(ChatRoom room, MessageBuilder messageBuilder )
|
||||
{
|
||||
for ( final MessageFilter filter : messageFilters )
|
||||
{
|
||||
try
|
||||
{
|
||||
filter.filterOutgoing( room, message );
|
||||
filter.filterOutgoing( room, messageBuilder );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
Log.error( "A MessageFilter ('" + filter + "') threw an exception while processing an outgoing chat message (from '" + message.getFrom() + "') in a chat room ('" + room + "').", e );
|
||||
Log.error( "A MessageFilter ('" + filter + "') threw an exception while processing an outgoing chat message (from '" + messageBuilder.getFrom() + "') in a chat room ('" + room + "').", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
package org.jivesoftware.spark.ui;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
|
||||
/**
|
||||
* The <code>MessageFilter</code> interface is one of the interfaces extension
|
||||
@ -34,12 +35,13 @@ public interface MessageFilter {
|
||||
* Update the body of an outgoing message.
|
||||
*
|
||||
* @param room Room the message is attached to.
|
||||
* @param message the message to update.
|
||||
* @param messageBuilder the message to update.
|
||||
*/
|
||||
void filterOutgoing(ChatRoom room, Message message);
|
||||
void filterOutgoing(ChatRoom room, MessageBuilder messageBuilder);
|
||||
|
||||
/**
|
||||
* Updates the body of an incoming message.
|
||||
* TODO change message to MessageBuilder
|
||||
*
|
||||
* @param room Room the message is attached to.
|
||||
* @param message the message to update.
|
||||
|
||||
@ -18,6 +18,7 @@ package org.jivesoftware.sparkimpl.plugin.history;
|
||||
import org.jivesoftware.resource.Res;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.xml.SmackXmlParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
@ -162,7 +163,7 @@ public class ConversationHistoryPlugin implements Plugin {
|
||||
// Persist order of conversations.
|
||||
SparkManager.getChatManager().addMessageFilter(new MessageFilter() {
|
||||
@Override
|
||||
public void filterOutgoing(ChatRoom room, Message message) {
|
||||
public void filterOutgoing(ChatRoom room, MessageBuilder message) {
|
||||
addUserToHistory(room);
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import net.suuft.libretranslate.Language;
|
||||
import net.suuft.libretranslate.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.spark.ChatManager;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.plugin.Plugin;
|
||||
@ -77,14 +78,14 @@ public class TranslatorPlugin implements Plugin {
|
||||
// do the translation for outgoing messages.
|
||||
final MessageFilter messageFilter = new MessageFilter() {
|
||||
@Override
|
||||
public void filterOutgoing(ChatRoom room, Message message) {
|
||||
String currentBody = message.getBody();
|
||||
public void filterOutgoing(ChatRoom room, MessageBuilder messageBuilder) {
|
||||
String currentBody = messageBuilder.getBody();
|
||||
Language lang = (Language) translatorBox.getSelectedItem();
|
||||
if (lang != null && lang != Language.NONE) {
|
||||
try {
|
||||
currentBody = TranslatorUtil.translate(currentBody, lang);
|
||||
transcriptWindow.insertNotificationMessage("-> "+currentBody, Color.gray);
|
||||
message.setBody(currentBody);
|
||||
messageBuilder.setBody(currentBody);
|
||||
} catch (Exception e){
|
||||
transcriptWindow.insertNotificationMessage(TranslatorResource.getString("translator.error"), ChatManager.ERROR_COLOR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user