Implemented method to forward a message
This commit is contained in:
		@@ -501,28 +501,52 @@ public class ChatWindow extends JFrame {
 | 
			
		||||
		scrollForPossibleContacts.applyTheme(theme);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sends a new message to the server based on the text entered in the textArea.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private void postMessage() {
 | 
			
		||||
		if (userList.isSelectionEmpty()) {
 | 
			
		||||
			JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!messageEnterTextArea.getText().isEmpty()) try {
 | 
			
		||||
			checkMessageTextLength();
 | 
			
		||||
			// Create message
 | 
			
		||||
			final Message message = new MessageBuilder(localDb.getUser().getId(), currentChat.getRecipient().getId(), localDb.getIdGenerator())
 | 
			
		||||
				.setText(messageEnterTextArea.getText())
 | 
			
		||||
				.build();
 | 
			
		||||
		if (!messageEnterTextArea.getText().isEmpty()) checkMessageTextLength();
 | 
			
		||||
		// Create message
 | 
			
		||||
		final Message message = new MessageBuilder(localDb.getUser().getId(), currentChat.getRecipient().getId(), localDb.getIdGenerator())
 | 
			
		||||
			.setText(messageEnterTextArea.getText())
 | 
			
		||||
			.build();
 | 
			
		||||
		sendMessage(message);
 | 
			
		||||
		// Clear text field
 | 
			
		||||
		messageEnterTextArea.setText("");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Forwards a message.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param msg       the message to forward
 | 
			
		||||
	 * @param recipient the new recipient of the message
 | 
			
		||||
	 * @since Envoy v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private void forwardMessage(Message msg, User recipient) {
 | 
			
		||||
		sendMessage(new MessageBuilder(msg, recipient.getId(), localDb.getIdGenerator()).build());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sends a {@link Message} to the server.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param message the message to send
 | 
			
		||||
	 * @since Envoy v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	private void sendMessage(final Message message) {
 | 
			
		||||
		try {
 | 
			
		||||
			// Send message
 | 
			
		||||
			writeProxy.writeMessage(message);
 | 
			
		||||
 | 
			
		||||
			// Add message to PersistentLocalDb and update UI
 | 
			
		||||
			currentChat.appendMessage(message);
 | 
			
		||||
 | 
			
		||||
			// Clear text field
 | 
			
		||||
			messageEnterTextArea.setText("");
 | 
			
		||||
 | 
			
		||||
			// Update UI
 | 
			
		||||
			revalidate();
 | 
			
		||||
			repaint();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user