AnsweredAssumed Answered

Spark Plug-In - How does MessageListener and messageReceived work?

Question asked by Thomas on May 17, 2016
Latest reply on May 19, 2016 by Thomas

Hi,

I'm trying to develop a simple Spark Plug-In to enable file sharing and sharing screenshots in our corporate network. Source code can be found here: GitHub - Speedy-Gonzalez/MUCFileUpload

Sharing files via network share works perfect. Now I want to integrate a functionality to automatically insert pictures in a MUC room when the Plug-In recognizes that a picture was uploaded to the network share.

 

I'm trying to listen for messages that end with JPG, JPEG or PNG (because my send functionality just works like that) and it works quite well. This is the code I use for that functionality MUCFileUpload/MUCFileUpload.java at develop · Speedy-Gonzalez/MUCFileUpload · GitHub :

public void chatRoomOpened(final ChatRoom room) {
    String roomId = room.getRoomname();
    Log.warning("chatRoomOpened:  " + roomId);
    if (roomId.indexOf('/') == -1) {
        decorators.put(roomId, new ChatRoomDecorator(room, url));
        if ("groupchat".equals(room.getChatType().toString())) {
            room.addMessageListener(new MessageListener() {
                public void messageReceived(ChatRoom room, Message message) {
                    Path path = Paths.get(message.getBody());
                    String ext = FilenameUtils.getExtension(path.toString());
                    if (ext.toUpperCase().equals("PNG") || ext.toUpperCase().equals("JPG") || ext.toUpperCase().equals("JPEG")){
                           
                        TranscriptWindow transcriptWindow = room.getTranscriptWindow();
                        transcriptWindow.insertIcon(new ImageIcon(path.toString()));
                    }
                }
                public void messageSent(ChatRoom room, Message message) {
                }
            });
        }
    }
}

 

My problem is, that when I integrate this Plug-In into Spark, I can't see all MUC messages that I receive.

E.g. I can't see messages like ":D" or "http://....". Messages with characters like !, :, § are mostly not displayed. Why mostly. Because messages like (yeah I've tried some very unlikely messages ) "D:D" are shown correctly, even when a ":" is in the message.

 

I can't really explain, why this is happening.

 

Is my code wrong? Do I implement the "MessageListener" wrong?

 

Thanks.

 

Best regards

Speedy

Outcomes