Implemented contact list update

This commit is contained in:
DieGurke 2020-02-11 18:15:15 +01:00
parent c0954036a5
commit 5a718aa1c9
4 changed files with 43 additions and 7 deletions

View 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&aumlfer
*
* @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); }
}

View File

@ -12,9 +12,11 @@ import javax.naming.TimeLimitExceededException;
import envoy.client.data.Cache; import envoy.client.data.Cache;
import envoy.client.data.Config; import envoy.client.data.Config;
import envoy.client.data.LocalDb; import envoy.client.data.LocalDb;
import envoy.client.event.SendEvent;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.data.*; import envoy.data.*;
import envoy.event.*; import envoy.event.*;
import envoy.event.ContactOperationEvent.Operation;
import envoy.util.SerializationUtils; import envoy.util.SerializationUtils;
/** /**
@ -116,6 +118,18 @@ public class Client implements Closeable {
// Process contact searches // Process contact searches
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch); 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 // Request a generator if none is present or the existing one is consumed
if (!localDb.hasIdGenerator() || !localDb.getIdGenerator().hasNext()) requestIdGenerator(); if (!localDb.hasIdGenerator() || !localDb.getIdGenerator().hasNext()) requestIdGenerator();
} }

View File

@ -411,12 +411,6 @@ public class ChatWindow extends JFrame {
EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> { EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> {
try {
client.sendEvent(evt);
} catch (IOException e) {
e.printStackTrace();
}
User contact = (User) evt.get(); User contact = (User) evt.get();
// Clearing the search field and the searchResultList // Clearing the search field and the searchResultList

View File

@ -7,6 +7,7 @@ import java.awt.Font;
import javax.swing.*; import javax.swing.*;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.client.event.SendEvent;
import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer; import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.data.User; import envoy.data.User;
@ -61,7 +62,11 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
add.setBackground(list.getBackground()); add.setBackground(list.getBackground());
add.setForeground(list.getForeground()); 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); panel.add(add);