Implemented contact list update
This commit is contained in:
parent
8a6f729abf
commit
577ee6364d
23
src/main/java/envoy/client/event/SendEvent.java
Normal file
23
src/main/java/envoy/client/event/SendEvent.java
Normal file
@ -0,0 +1,23 @@
|
||||
package envoy.client.event;
|
||||
|
||||
import envoy.event.Event;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>SendEvent.java</strong><br>
|
||||
* Created: <strong>11.02.2020</strong><br>
|
||||
*
|
||||
* @author: Maximilian Käfer
|
||||
*
|
||||
* @since Envoy v0.3-alpha
|
||||
*/
|
||||
public class SendEvent extends Event<Event<?>> {
|
||||
|
||||
private static final long serialVersionUID = 8372746924138839060L;
|
||||
|
||||
/**
|
||||
* @param value the event to send to the server
|
||||
*/
|
||||
public SendEvent(Event<?> value) { super(value); }
|
||||
|
||||
}
|
@ -12,9 +12,11 @@ import javax.naming.TimeLimitExceededException;
|
||||
import envoy.client.data.Cache;
|
||||
import envoy.client.data.Config;
|
||||
import envoy.client.data.LocalDb;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.client.util.EnvoyLog;
|
||||
import envoy.data.*;
|
||||
import envoy.event.*;
|
||||
import envoy.event.ContactOperationEvent.Operation;
|
||||
import envoy.util.SerializationUtils;
|
||||
|
||||
/**
|
||||
@ -116,6 +118,18 @@ public class Client implements Closeable {
|
||||
// Process contact searches
|
||||
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
|
||||
|
||||
receiver.registerProcessor(Contacts.class,
|
||||
contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD)));
|
||||
|
||||
// Send event
|
||||
EventBus.getInstance().register(SendEvent.class, evt -> {
|
||||
try {
|
||||
sendEvent(((SendEvent) evt).get());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
// Request a generator if none is present or the existing one is consumed
|
||||
if (!localDb.hasIdGenerator() || !localDb.getIdGenerator().hasNext()) requestIdGenerator();
|
||||
}
|
||||
|
@ -411,12 +411,6 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> {
|
||||
|
||||
try {
|
||||
client.sendEvent(evt);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
User contact = (User) evt.get();
|
||||
|
||||
// Clearing the search field and the searchResultList
|
||||
|
@ -7,6 +7,7 @@ import java.awt.Font;
|
||||
import javax.swing.*;
|
||||
|
||||
import envoy.client.Settings;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentListCellRenderer;
|
||||
import envoy.data.User;
|
||||
@ -61,7 +62,11 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||
add.setBackground(list.getBackground());
|
||||
add.setForeground(list.getForeground());
|
||||
|
||||
add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD)); });
|
||||
add.addActionListener(evt -> {
|
||||
ContactOperationEvent contactsOperationEvent = new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD);
|
||||
EventBus.getInstance().dispatch(contactsOperationEvent);
|
||||
EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent));
|
||||
});
|
||||
|
||||
panel.add(add);
|
||||
|
||||
|
Reference in New Issue
Block a user