Added BASIC group capability (#128)
* Changed serialVersionUID everywhere to 0L * Added support for GroupResizeEvents and NameChangeEvents Co-authored-by: CyB3RC0nN0R <kske@outlook.de>
This commit is contained in:
		| @@ -25,7 +25,7 @@ public class Cache<T> implements Consumer<T>, Serializable { | |||||||
| 	private transient Consumer<T>	processor; | 	private transient Consumer<T>	processor; | ||||||
|  |  | ||||||
| 	private static final Logger	logger				= EnvoyLog.getLogger(Cache.class); | 	private static final Logger	logger				= EnvoyLog.getLogger(Cache.class); | ||||||
| 	private static final long	serialVersionUID	= 0L; | 	private static final long	serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Adds an element to the cache. | 	 * Adds an element to the cache. | ||||||
|   | |||||||
| @@ -6,9 +6,8 @@ import java.util.ArrayList; | |||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import envoy.client.net.WriteProxy; | import envoy.client.net.WriteProxy; | ||||||
| import envoy.data.Message; | import envoy.data.*; | ||||||
| import envoy.data.Message.MessageStatus; | import envoy.data.Message.MessageStatus; | ||||||
| import envoy.data.User; |  | ||||||
| import envoy.event.MessageStatusChangeEvent; | import envoy.event.MessageStatusChangeEvent; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -26,7 +25,7 @@ import envoy.event.MessageStatusChangeEvent; | |||||||
|  */ |  */ | ||||||
| public final class Chat implements Serializable { | public final class Chat implements Serializable { | ||||||
|  |  | ||||||
| 	private final User			recipient; | 	private final Contact		recipient; | ||||||
| 	private final List<Message>	messages	= new ArrayList<>(); | 	private final List<Message>	messages	= new ArrayList<>(); | ||||||
|  |  | ||||||
| 	private static final long serialVersionUID = 1L; | 	private static final long serialVersionUID = 1L; | ||||||
| @@ -38,7 +37,7 @@ public final class Chat implements Serializable { | |||||||
| 	 * @param recipient the user who receives the messages | 	 * @param recipient the user who receives the messages | ||||||
| 	 * @since Envoy Client v0.1-alpha | 	 * @since Envoy Client v0.1-alpha | ||||||
| 	 */ | 	 */ | ||||||
| 	public Chat(User recipient) { this.recipient = recipient; } | 	public Chat(Contact recipient) { this.recipient = recipient; } | ||||||
|  |  | ||||||
| 	@Override | 	@Override | ||||||
| 	public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); } | 	public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); } | ||||||
| @@ -82,5 +81,17 @@ public final class Chat implements Serializable { | |||||||
| 	 * @return the recipient of a message | 	 * @return the recipient of a message | ||||||
| 	 * @since Envoy Client v0.1-alpha | 	 * @since Envoy Client v0.1-alpha | ||||||
| 	 */ | 	 */ | ||||||
| 	public User getRecipient() { return recipient; } | 	public Contact getRecipient() { return recipient; } | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * @return whether this {@link Chat} points at a {@link User} | ||||||
|  | 	 * @since Envoy Client v0.1-beta | ||||||
|  | 	 */ | ||||||
|  | 	public boolean isUserChat() { return recipient instanceof User; } | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * @return whether this {@link Chat} points at a {@link Group} | ||||||
|  | 	 * @since Envoy Client v0.1-beta | ||||||
|  | 	 */ | ||||||
|  | 	public boolean isGroupChat() { return recipient instanceof Group; } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,10 +2,8 @@ package envoy.client.data; | |||||||
|  |  | ||||||
| import java.util.*; | import java.util.*; | ||||||
|  |  | ||||||
| import envoy.data.IDGenerator; | import envoy.data.*; | ||||||
| import envoy.data.Message; | import envoy.event.*; | ||||||
| import envoy.data.User; |  | ||||||
| import envoy.event.MessageStatusChangeEvent; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Stores information about the current {@link User} and their {@link Chat}s. |  * Stores information about the current {@link User} and their {@link Chat}s. | ||||||
| @@ -155,4 +153,39 @@ public abstract class LocalDB { | |||||||
| 	public Message getMessage(long id) { | 	public Message getMessage(long id) { | ||||||
| 		return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny().orElse(null); | 		return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny().orElse(null); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Performs a contact name change if the corresponding contact is present. | ||||||
|  | 	 * | ||||||
|  | 	 * @param event the {@link NameChangeEvent} to process | ||||||
|  | 	 * @since Envoy Client v0.1-beta | ||||||
|  | 	 */ | ||||||
|  | 	public void replaceContactName(NameChangeEvent event) { | ||||||
|  | 		chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == event.getId()).findAny().ifPresent(c -> c.setName(event.get())); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Performs a group resize operation if the corresponding group is present. | ||||||
|  | 	 * | ||||||
|  | 	 * @param event the {@link GroupResizeEvent} to process | ||||||
|  | 	 * @since Envoy Client v0.1-beta | ||||||
|  | 	 */ | ||||||
|  | 	public void updateGroup(GroupResizeEvent event) { | ||||||
|  | 		chats.stream() | ||||||
|  | 			.map(Chat::getRecipient) | ||||||
|  | 			.filter(Group.class::isInstance) | ||||||
|  | 			.filter(g -> g.getID() == event.getGroupID() && g.getID() != user.getID()) | ||||||
|  | 			.map(Group.class::cast) | ||||||
|  | 			.findAny() | ||||||
|  | 			.ifPresent(group -> { | ||||||
|  | 				switch (event.getOperation()) { | ||||||
|  | 					case ADD: | ||||||
|  | 						group.getMemberIDs().add(event.get()); | ||||||
|  | 						break; | ||||||
|  | 					case REMOVE: | ||||||
|  | 						group.getMemberIDs().remove(event.get()); | ||||||
|  | 						break; | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -145,12 +145,18 @@ public class Client implements Closeable { | |||||||
| 		// Process message ID generation | 		// Process message ID generation | ||||||
| 		receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator); | 		receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator); | ||||||
|  |  | ||||||
|  | 		// Process name changes | ||||||
|  | 		receiver.registerProcessor(NameChangeEvent.class, evt -> { localDB.replaceContactName(evt); EventBus.getInstance().dispatch(evt); }); | ||||||
|  |  | ||||||
| 		// Process contact searches | 		// Process contact searches | ||||||
| 		receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch); | 		receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch); | ||||||
|  |  | ||||||
| 		receiver.registerProcessor(Contacts.class, | 		receiver.registerProcessor(Contacts.class, | ||||||
| 				contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD))); | 				contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD))); | ||||||
|  |  | ||||||
|  | 		// Process group size changes | ||||||
|  | 		receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); EventBus.getInstance().dispatch(evt); }); | ||||||
|  |  | ||||||
| 		// Send event | 		// Send event | ||||||
| 		EventBus.getInstance().register(SendEvent.class, evt -> { | 		EventBus.getInstance().register(SendEvent.class, evt -> { | ||||||
| 			try { | 			try { | ||||||
|   | |||||||
| @@ -81,7 +81,7 @@ public class Color extends java.awt.Color { | |||||||
| 	 */ | 	 */ | ||||||
| 	public static final Color blue = new Color(0, 0, 255); | 	public static final Color blue = new Color(0, 0, 255); | ||||||
|  |  | ||||||
| 	private static final long serialVersionUID = -9166233199998257344L; | 	private static final long serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	public Color(java.awt.Color other) { this(other.getRGB()); } | 	public Color(java.awt.Color other) { this(other.getRGB()); } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ public class LoginDialog extends JDialog { | |||||||
|  |  | ||||||
| 	private static final ClientConfig	config				= ClientConfig.getInstance(); | 	private static final ClientConfig	config				= ClientConfig.getInstance(); | ||||||
| 	private static final Logger			logger				= EnvoyLog.getLogger(LoginDialog.class); | 	private static final Logger			logger				= EnvoyLog.getLogger(LoginDialog.class); | ||||||
| 	private static final long			serialVersionUID	= 0L; | 	private static final long			serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Displays a dialog enabling the user to enter their user name and password. | 	 * Displays a dialog enabling the user to enter their user name and password. | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ import envoy.client.ui.Theme; | |||||||
|  */ |  */ | ||||||
| public class PrimaryScrollPane extends JScrollPane { | public class PrimaryScrollPane extends JScrollPane { | ||||||
|  |  | ||||||
| 	private static final long serialVersionUID = -4786837444056228439L; | 	private static final long serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	private int		verticalScrollBarMaximum	= getVerticalScrollBar().getMaximum(); | 	private int		verticalScrollBarMaximum	= getVerticalScrollBar().getMaximum(); | ||||||
| 	private boolean	chatOpened					= false; | 	private boolean	chatOpened					= false; | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ import javax.swing.border.EmptyBorder; | |||||||
|  */ |  */ | ||||||
| public class PrimaryTextArea extends JTextArea { | public class PrimaryTextArea extends JTextArea { | ||||||
|  |  | ||||||
| 	private static final long	serialVersionUID	= 0L; | 	private static final long	serialVersionUID = 0L; | ||||||
| 	private int					arcSize; | 	private int					arcSize; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
| @@ -30,7 +30,7 @@ public class GeneralSettingsPanel extends SettingsPanel { | |||||||
|  |  | ||||||
| 	private static final String[]	items				= { "onCloseMode", "enterToSend" }; | 	private static final String[]	items				= { "onCloseMode", "enterToSend" }; | ||||||
| 	private static final Logger		logger				= EnvoyLog.getLogger(GeneralSettingsPanel.class); | 	private static final Logger		logger				= EnvoyLog.getLogger(GeneralSettingsPanel.class); | ||||||
| 	private static final long		serialVersionUID	= 0L; | 	private static final long		serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * This is the constructor for the General class. Here the user can set general | 	 * This is the constructor for the General class. Here the user can set general | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ public class ThemeCustomizationPanel extends SettingsPanel { | |||||||
| 	private final Insets	insets	= new Insets(5, 5, 5, 5); | 	private final Insets	insets	= new Insets(5, 5, 5, 5); | ||||||
|  |  | ||||||
| 	private static final Logger	logger				= EnvoyLog.getLogger(ThemeCustomizationPanel.class); | 	private static final Logger	logger				= EnvoyLog.getLogger(ThemeCustomizationPanel.class); | ||||||
| 	private static final long	serialVersionUID	= 0L; | 	private static final long	serialVersionUID = 0L; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Initializes a {@link ThemeCustomizationPanel} that enables the user to change | 	 * Initializes a {@link ThemeCustomizationPanel} that enables the user to change | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 delvh
					delvh