-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 @@ | ||
package team.elrant.bubbles.xmpp; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jivesoftware.smack.chat2.Chat; | ||
import org.jivesoftware.smack.chat2.IncomingChatMessageListener; | ||
import org.jivesoftware.smack.packet.Message; | ||
import org.jxmpp.jid.BareJid; | ||
import org.jxmpp.jid.EntityBareJid; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class ChatListener implements IncomingChatMessageListener { | ||
private static final Logger logger = LogManager.getLogger(ChatListener.class); | ||
public BareJid contactJid; | ||
Consumer<String> updateChatDisplay; | ||
|
||
public ChatListener(BareJid contactJid, Consumer<String> updateChatDisplay){ | ||
this.contactJid = contactJid; | ||
this.updateChatDisplay = updateChatDisplay; | ||
} | ||
|
||
/** | ||
* @param from The JID of the sender | ||
* @param message The message contents | ||
* @param chat The chat channel | ||
*/ | ||
@Override | ||
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) { | ||
try { | ||
if (from != null && from.equals(contactJid) && message.getBody() != null) { | ||
updateChatDisplay.accept(message.getBody()); | ||
logger.info("Received message from {}: {}", from, message.getBody()); | ||
} | ||
} catch (Exception e) { | ||
logger.error("Error updating chat display: {}", e.getMessage()); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
39 changes: 21 additions & 18 deletions
39
src/main/resources/team/elrant/bubbles/gui/views/ChatView.fxml
This file contains 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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.text.Font?> | ||
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="300.0" prefWidth="800.0" | ||
xmlns="http://javafx.com/javafx/17.0.2-ea" fx:controller="team.elrant.bubbles.gui.ChatViewController"> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.image.*?> | ||
<?import javafx.scene.layout.*?> | ||
<?import javafx.scene.text.*?> | ||
|
||
<AnchorPane prefHeight="300.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="team.elrant.bubbles.gui.ChatViewController"> | ||
<TextArea fx:id="chatTextArea" editable="false" layoutX="7.0" layoutY="10.0" prefHeight="584.0" prefWidth="630.0"> | ||
<font> | ||
<Font name="Segoe UI" size="12.0"/> | ||
<Font name="Segoe UI" size="12.0" /> | ||
</font> | ||
</TextArea> | ||
<AnchorPane layoutY="600.0" prefHeight="100.0" prefWidth="800.0"> | ||
<AnchorPane layoutX="4.0" layoutY="600.0" prefHeight="100.0" prefWidth="800.0"> | ||
<children> | ||
<TextArea fx:id="messageTextArea" layoutX="7.0" prefHeight="94.0" prefWidth="630.0"> | ||
<font> | ||
<Font name="Segoe UI" size="12.0"/> | ||
<Font name="Segoe UI" size="12.0" /> | ||
</font> | ||
</TextArea> | ||
<Button fx:id="sendButton" layoutX="643.0" layoutY="5.0" onAction="#sendMessage" prefHeight="88.0" | ||
prefWidth="149.0" text="Send"> | ||
<font> | ||
<Font name="Segoe UI Semibold" size="12.0"/> | ||
</font> | ||
</Button> | ||
<AnchorPane layoutX="645.0" layoutY="2.0" prefHeight="56.0" prefWidth="50.0"> | ||
<children> | ||
<Button fx:id="sendButton" onAction="#sendMessage" prefHeight="50.0" prefWidth="50.0" text="Send"> | ||
<graphic> | ||
<ImageView fitHeight="55" fitWidth="55.0"> | ||
<Image url="@sendicon.png" /> | ||
</ImageView> | ||
</graphic> | ||
</Button> | ||
</children> | ||
</AnchorPane> | ||
</children> | ||
</AnchorPane> | ||
<Label fx:id="failedSendMessageLabel" layoutX="320" layoutY="650" text="Failed to send message!" textFill="red" | ||
visible="false"/> | ||
<Label fx:id="failedSendMessageLabel" layoutX="320" layoutY="650" text="Failed to send message!" textFill="red" visible="false" /> | ||
</AnchorPane> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.