Renamed classes with a two-letter initialism according to convention

This commit is contained in:
delvh 2020-03-24 18:38:47 +01:00
parent 2b501f0329
commit c5a6978a85
10 changed files with 79 additions and 77 deletions

File diff suppressed because one or more lines are too long

View File

@ -81,15 +81,15 @@ public class Startup {
EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier()); EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier());
// Initialize the local database // Initialize the local database
LocalDb localDb; LocalDB localDB;
if (config.isIgnoreLocalDB()) { if (config.isIgnoreLocalDB()) {
localDb = new TransientLocalDb(); localDB = new TransientLocalDB();
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
"Ignoring local database.\nMessages will not be saved!", "Ignoring local database.\nMessages will not be saved!",
"Local database warning", "Local database warning",
JOptionPane.WARNING_MESSAGE); JOptionPane.WARNING_MESSAGE);
} else try { } else try {
localDb = new PersistentLocalDb(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath()));
} catch (IOException e3) { } catch (IOException e3) {
logger.log(Level.SEVERE, "Could not initialize local database", e3); logger.log(Level.SEVERE, "Could not initialize local database", e3);
JOptionPane.showMessageDialog(null, "Could not initialize local database!\n" + e3, "Local database error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "Could not initialize local database!\n" + e3, "Local database error", JOptionPane.ERROR_MESSAGE);
@ -102,16 +102,16 @@ public class Startup {
Cache<Message> cache = new Cache<>(); Cache<Message> cache = new Cache<>();
// Try to connect to the server // Try to connect to the server
new LoginDialog(client, localDb, cache); new LoginDialog(client, localDB, cache);
SwingUtilities.invokeLater(() -> chatWindow.setVisible(true)); SwingUtilities.invokeLater(() -> chatWindow.setVisible(true));
// Set client user in local database // Set client user in local database
localDb.setUser(client.getSender()); localDB.setUser(client.getSender());
// Initialize chats in local database // Initialize chats in local database
try { try {
localDb.initializeUserStorage(); localDB.initializeUserStorage();
localDb.loadUserData(); localDB.loadUserData();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// The local database file has not yet been created, probably first login // The local database file has not yet been created, probably first login
} catch (Exception e) { } catch (Exception e) {
@ -123,21 +123,21 @@ public class Startup {
} }
// Initialize write proxy // Initialize write proxy
final WriteProxy writeProxy = client.createWriteProxy(localDb); final WriteProxy writeProxy = client.createWriteProxy(localDB);
if (client.isOnline()) { if (client.isOnline()) {
// Save all users to the local database and flush cache // Save all users to the local database and flush cache
localDb.setUsers(client.getUsers()); localDB.setUsers(client.getUsers());
writeProxy.flushCache(); writeProxy.flushCache();
} else } else
// Set all contacts to offline mode // Set all contacts to offline mode
localDb.getUsers().values().stream().filter(u -> u != localDb.getUser()).forEach(u -> u.setStatus(UserStatus.OFFLINE)); localDB.getUsers().values().stream().filter(u -> u != localDB.getUser()).forEach(u -> u.setStatus(UserStatus.OFFLINE));
// Display ChatWindow and StatusTrayIcon // Display ChatWindow and StatusTrayIcon
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {
try { try {
chatWindow.initContent(client, localDb, writeProxy); chatWindow.initContent(client, localDB, writeProxy);
// Relay unread messages from cache // Relay unread messages from cache
if (cache != null && client.isOnline()) cache.relay(); if (cache != null && client.isOnline()) cache.relay();
@ -160,14 +160,14 @@ public class Startup {
} }
}); });
// Save Settings and PersistentLocalDb on shutdown // Save Settings and PersistentLocalDB on shutdown
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { try {
logger.info("Closing connection..."); logger.info("Closing connection...");
client.close(); client.close();
logger.info("Saving local database and settings..."); logger.info("Saving local database and settings...");
localDb.save(); localDB.save();
Settings.getInstance().save(); Settings.getInstance().save();
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Unable to save local files", e); logger.log(Level.SEVERE, "Unable to save local files", e);

View File

@ -12,13 +12,13 @@ import envoy.event.MessageStatusChangeEvent;
* For message ID generation a {@link IdGenerator} is stored as well.<br> * For message ID generation a {@link IdGenerator} is stored as well.<br>
* <br> * <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>LocalDb.java</strong><br> * File: <strong>LocalDB.java</strong><br>
* Created: <strong>3 Feb 2020</strong><br> * Created: <strong>3 Feb 2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public abstract class LocalDb { public abstract class LocalDB {
protected User user; protected User user;
protected Map<String, User> users = new HashMap<>(); protected Map<String, User> users = new HashMap<>();

View File

@ -10,18 +10,18 @@ import envoy.data.IdGenerator;
import envoy.util.SerializationUtils; import envoy.util.SerializationUtils;
/** /**
* Implements a {@link LocalDb} in a way that stores all information inside a * Implements a {@link LocalDB} in a way that stores all information inside a
* folder on the local file system.<br> * folder on the local file system.<br>
* <br> * <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>PersistentLocalDb.java</strong><br> * File: <strong>PersistentLocalDB.java</strong><br>
* Created: <strong>27.10.2019</strong><br> * Created: <strong>27.10.2019</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
public class PersistentLocalDb extends LocalDb { public class PersistentLocalDB extends LocalDB {
private File localDBDir, localDBFile, usersFile, idGeneratorFile, messageCacheFile, statusCacheFile; private File localDBDir, localDBFile, usersFile, idGeneratorFile, messageCacheFile, statusCacheFile;
@ -34,17 +34,17 @@ public class PersistentLocalDb extends LocalDb {
* *
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public PersistentLocalDb() {} public PersistentLocalDB() {}
/** /**
* Constructs an empty local database. To serialize any chats to the file * Constructs an empty local database. To serialize any chats to the file
* system, call {@link PersistentLocalDb#initializeUserStorage()}. * system, call {@link PersistentLocalDB#initializeUserStorage()}.
* *
* @param localDbDir the directory in which to store users and chats * @param localDbDir the directory in which to store users and chats
* @throws IOException if the PersistentLocalDb could not be initialized * @throws IOException if the PersistentLocalDB could not be initialized
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
public PersistentLocalDb(File localDbDir) throws IOException { public PersistentLocalDB(File localDbDir) throws IOException {
localDBDir = localDbDir; localDBDir = localDbDir;
// Initialize local database directory // Initialize local database directory

View File

@ -1,15 +1,15 @@
package envoy.client.data; package envoy.client.data;
/** /**
* Implements a {@link LocalDb} in a way that does not persist any information * Implements a {@link LocalDB} in a way that does not persist any information
* after application shutdown.<br> * after application shutdown.<br>
* <br> * <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>TransientLocalDb.java</strong><br> * File: <strong>TransientLocalDB.java</strong><br>
* Created: <strong>3 Feb 2020</strong><br> * Created: <strong>3 Feb 2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public class TransientLocalDb extends LocalDb { public class TransientLocalDB extends LocalDB {
} }

View File

@ -11,7 +11,7 @@ import javax.naming.TimeLimitExceededException;
import envoy.client.data.Cache; import envoy.client.data.Cache;
import envoy.client.data.ClientConfig; import envoy.client.data.ClientConfig;
import envoy.client.data.LocalDb; import envoy.client.data.LocalDB;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.data.*; import envoy.data.*;
import envoy.event.*; import envoy.event.*;
@ -117,7 +117,7 @@ public class Client implements Closeable {
* Initializes the {@link Receiver} used to process data sent from the server to * Initializes the {@link Receiver} used to process data sent from the server to
* this client. * this client.
* *
* @param localDb the local database used to persist the current * @param localDB the local database used to persist the current
* {@link IdGenerator} * {@link IdGenerator}
* @param receivedMessageCache a message cache containing all unread messages * @param receivedMessageCache a message cache containing all unread messages
* from the server that can be relayed after * from the server that can be relayed after
@ -126,7 +126,7 @@ public class Client implements Closeable {
* requested from the server * requested from the server
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
*/ */
public void initReceiver(LocalDb localDb, Cache<Message> receivedMessageCache) throws IOException { public void initReceiver(LocalDB localDB, Cache<Message> receivedMessageCache) throws IOException {
checkOnline(); checkOnline();
// Process incoming messages // Process incoming messages
@ -140,10 +140,10 @@ public class Client implements Closeable {
receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor()); receiver.registerProcessor(MessageStatusChangeEvent.class, new MessageStatusChangeEventProcessor());
// Process user status changes // Process user status changes
receiver.registerProcessor(UserStatusChangeEvent.class, new UserStatusChangeProcessor(localDb)); receiver.registerProcessor(UserStatusChangeEvent.class, new UserStatusChangeProcessor(localDB));
// Process message ID generation // Process message ID generation
receiver.registerProcessor(IdGenerator.class, localDb::setIdGenerator); receiver.registerProcessor(IdGenerator.class, localDB::setIdGenerator);
// Process contact searches // Process contact searches
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch); receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
@ -161,19 +161,19 @@ public class Client implements Closeable {
}); });
// 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();
} }
/** /**
* Creates a new write proxy that uses this client to communicate with the * Creates a new write proxy that uses this client to communicate with the
* server. * server.
* *
* @param localDb the local database that the write proxy will use to access * @param localDB the local database that the write proxy will use to access
* caches * caches
* @return a new write proxy * @return a new write proxy
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public WriteProxy createWriteProxy(LocalDb localDb) { return new WriteProxy(this, localDb); } public WriteProxy createWriteProxy(LocalDB localDB) { return new WriteProxy(this, localDB); }
/** /**
* Sends a message to the server. The message's status will be incremented once * Sends a message to the server. The message's status will be incremented once

View File

@ -2,7 +2,7 @@ package envoy.client.net;
import java.util.function.Consumer; import java.util.function.Consumer;
import envoy.client.data.LocalDb; import envoy.client.data.LocalDB;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.UserStatusChangeEvent; import envoy.event.UserStatusChangeEvent;
@ -16,17 +16,17 @@ import envoy.event.UserStatusChangeEvent;
*/ */
public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent> { public class UserStatusChangeProcessor implements Consumer<UserStatusChangeEvent> {
private final LocalDb localDb; private final LocalDB localDB;
/** /**
* @param localDb the local database in which status updates will by applied * @param localDB the local database in which status updates will by applied
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public UserStatusChangeProcessor(LocalDb localDb) { this.localDb = localDb; } public UserStatusChangeProcessor(LocalDB localDB) { this.localDB = localDB; }
@Override @Override
public void accept(UserStatusChangeEvent evt) { public void accept(UserStatusChangeEvent evt) {
localDb.getUsers().values().stream().filter(u -> u.getId() == evt.getId()).findFirst().get().setStatus(evt.get()); localDB.getUsers().values().stream().filter(u -> u.getId() == evt.getId()).findFirst().get().setStatus(evt.get());
EventBus.getInstance().dispatch(evt); EventBus.getInstance().dispatch(evt);
} }
} }

View File

@ -4,7 +4,7 @@ import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.data.LocalDb; import envoy.client.data.LocalDB;
import envoy.data.Message; import envoy.data.Message;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChangeEvent;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
@ -12,7 +12,7 @@ import envoy.util.EnvoyLog;
/** /**
* Implements methods to send {@link Message}s and * Implements methods to send {@link Message}s and
* {@link MessageStatusChangeEvent}s to the server or cache them inside a * {@link MessageStatusChangeEvent}s to the server or cache them inside a
* {@link LocalDb} depending on the online status.<br> * {@link LocalDB} depending on the online status.<br>
* <br> * <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>WriteProxy.java</strong><br> * File: <strong>WriteProxy.java</strong><br>
@ -24,7 +24,7 @@ import envoy.util.EnvoyLog;
public class WriteProxy { public class WriteProxy {
private final Client client; private final Client client;
private final LocalDb localDb; private final LocalDB localDB;
private static final Logger logger = EnvoyLog.getLogger(WriteProxy.class); private static final Logger logger = EnvoyLog.getLogger(WriteProxy.class);
@ -34,27 +34,27 @@ public class WriteProxy {
* *
* @param client the client used to send messages and message status change * @param client the client used to send messages and message status change
* events * events
* @param localDb the local database used to cache messages and message status * @param localDB the local database used to cache messages and message status
* change events * change events
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public WriteProxy(Client client, LocalDb localDb) { public WriteProxy(Client client, LocalDB localDB) {
this.client = client; this.client = client;
this.localDb = localDb; this.localDB = localDB;
// Initialize cache processors for messages and message status change events // Initialize cache processors for messages and message status change events
localDb.getMessageCache().setProcessor(msg -> { localDB.getMessageCache().setProcessor(msg -> {
try { try {
logger.finer("Sending cached " + msg); logger.finer("Sending cached " + msg);
client.sendMessage(msg); client.sendMessage(msg);
// Update message state to SENT in local db // Update message state to SENT in local db
localDb.getMessage(msg.getId()).nextStatus(); localDB.getMessage(msg.getId()).nextStatus();
} catch (IOException e) { } catch (IOException e) {
logger.log(Level.SEVERE, "Could not send cached message", e); logger.log(Level.SEVERE, "Could not send cached message", e);
} }
}); });
localDb.getStatusCache().setProcessor(evt -> { localDB.getStatusCache().setProcessor(evt -> {
logger.finer("Sending cached " + evt); logger.finer("Sending cached " + evt);
try { try {
client.sendEvent(evt); client.sendEvent(evt);
@ -72,10 +72,10 @@ public class WriteProxy {
*/ */
public void flushCache() { public void flushCache() {
// Send messages // Send messages
localDb.getMessageCache().relay(); localDB.getMessageCache().relay();
// Send message status change events // Send message status change events
localDb.getStatusCache().relay(); localDB.getStatusCache().relay();
} }
/** /**
@ -88,7 +88,7 @@ public class WriteProxy {
*/ */
public void writeMessage(Message message) throws IOException { public void writeMessage(Message message) throws IOException {
if (client.isOnline()) client.sendMessage(message); if (client.isOnline()) client.sendMessage(message);
else localDb.getMessageCache().accept(message); else localDB.getMessageCache().accept(message);
} }
/** /**
@ -101,6 +101,6 @@ public class WriteProxy {
*/ */
public void writeMessageStatusChangeEvent(MessageStatusChangeEvent evt) throws IOException { public void writeMessageStatusChangeEvent(MessageStatusChangeEvent evt) throws IOException {
if (client.isOnline()) client.sendEvent(evt); if (client.isOnline()) client.sendEvent(evt);
else localDb.getStatusCache().accept(evt); else localDB.getStatusCache().accept(evt);
} }
} }

View File

@ -17,7 +17,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import envoy.client.data.Chat; import envoy.client.data.Chat;
import envoy.client.data.LocalDb; import envoy.client.data.LocalDB;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
@ -63,7 +63,7 @@ public class ChatWindow extends JFrame {
// User specific objects // User specific objects
private Client client; private Client client;
private WriteProxy writeProxy; private WriteProxy writeProxy;
private LocalDb localDb; private LocalDB localDB;
private Chat currentChat; private Chat currentChat;
// GUI components // GUI components
@ -132,7 +132,7 @@ public class ChatWindow extends JFrame {
Map<String, ActionListener> commands = Map.of("forward selected message", evt -> { Map<String, ActionListener> commands = Map.of("forward selected message", evt -> {
final Message selectedMessage = messageList.getSingleSelectedElement(); final Message selectedMessage = messageList.getSingleSelectedElement();
List<User> chosenContacts = ContactsChooserDialog List<User> chosenContacts = ContactsChooserDialog
.showForwardingDialog("Forward selected message to", null, selectedMessage, localDb.getUsers().values()); .showForwardingDialog("Forward selected message to", null, selectedMessage, localDB.getUsers().values());
if (chosenContacts != null && chosenContacts.size() > 0) forwardMessage(selectedMessage, chosenContacts.toArray(new User[0])); if (chosenContacts != null && chosenContacts.size() > 0) forwardMessage(selectedMessage, chosenContacts.toArray(new User[0]));
}, "copy", evt -> { }, "copy", evt -> {
// TODO should be enhanced to allow also copying of message attachments, // TODO should be enhanced to allow also copying of message attachments,
@ -242,7 +242,7 @@ public class ChatWindow extends JFrame {
userList.setCellRenderer(new UserListRenderer()); userList.setCellRenderer(new UserListRenderer());
userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
userList.addListSelectionListener((listSelectionEvent) -> { userList.addListSelectionListener((listSelectionEvent) -> {
if (client != null && localDb != null && !listSelectionEvent.getValueIsAdjusting()) { if (client != null && localDB != null && !listSelectionEvent.getValueIsAdjusting()) {
final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource(); final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource();
final User user = selectedUserList.getSelectedValue(); final User user = selectedUserList.getSelectedValue();
@ -250,7 +250,7 @@ public class ChatWindow extends JFrame {
if (contentPane.getComponent(i).equals(searchPane)) drawChatBox(gbc_scrollPane); if (contentPane.getComponent(i).equals(searchPane)) drawChatBox(gbc_scrollPane);
if (user != null) { if (user != null) {
// Select current chat // Select current chat
currentChat = localDb.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get(); currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get();
// Read current chat // Read current chat
readCurrentChat(); readCurrentChat();
@ -412,7 +412,7 @@ public class ChatWindow extends JFrame {
// Listen to received messages // Listen to received messages
EventBus.getInstance().register(MessageCreationEvent.class, evt -> { EventBus.getInstance().register(MessageCreationEvent.class, evt -> {
Message message = evt.get(); Message message = evt.get();
Chat chat = localDb.getChats().stream().filter(c -> c.getRecipient().getId() == message.getSenderId()).findFirst().get(); Chat chat = localDB.getChats().stream().filter(c -> c.getRecipient().getId() == message.getSenderId()).findFirst().get();
chat.appendMessage(message); chat.appendMessage(message);
// Read message and update UI if in current chat // Read message and update UI if in current chat
@ -427,7 +427,7 @@ public class ChatWindow extends JFrame {
final long id = evt.getId(); final long id = evt.getId();
final MessageStatus status = evt.get(); final MessageStatus status = evt.get();
for (Chat c : localDb.getChats()) for (Chat c : localDB.getChats())
for (Message m : c.getModel()) for (Message m : c.getModel())
if (m.getId() == id) { if (m.getId() == id) {
@ -466,8 +466,8 @@ public class ChatWindow extends JFrame {
// Update LocalDB // Update LocalDB
userListModel.addElement(contact); userListModel.addElement(contact);
localDb.getUsers().put(contact.getName(), contact); localDB.getUsers().put(contact.getName(), contact);
localDb.getChats().add(new Chat(contact)); localDB.getChats().add(new Chat(contact));
revalidate(); revalidate();
repaint(); repaint();
@ -543,7 +543,7 @@ public class ChatWindow extends JFrame {
if (!text.isEmpty()) checkMessageTextLength(); if (!text.isEmpty()) checkMessageTextLength();
// Create message // Create message
final Message message = new MessageBuilder(localDb.getUser().getId(), currentChat.getRecipient().getId(), localDb.getIdGenerator()) final Message message = new MessageBuilder(localDB.getUser().getId(), currentChat.getRecipient().getId(), localDB.getIdGenerator())
.setText(text) .setText(text)
.build(); .build();
sendMessage(message); sendMessage(message);
@ -561,7 +561,7 @@ public class ChatWindow extends JFrame {
*/ */
private void forwardMessage(Message message, User... recipients) { private void forwardMessage(Message message, User... recipients) {
Arrays.stream(recipients).forEach(recipient -> { Arrays.stream(recipients).forEach(recipient -> {
if (message != null && recipients != null) sendMessage(new MessageBuilder(message, recipient.getId(), localDb.getIdGenerator()).build()); if (message != null && recipients != null) sendMessage(new MessageBuilder(message, recipient.getId(), localDB.getIdGenerator()).build());
else throw new NullPointerException("No recipient or no message selected"); else throw new NullPointerException("No recipient or no message selected");
}); });
@ -583,7 +583,7 @@ public class ChatWindow extends JFrame {
// Send message // Send message
writeProxy.writeMessage(message); writeProxy.writeMessage(message);
// Add message to PersistentLocalDb and update UI // Add message to PersistentLocalDB and update UI
currentChat.appendMessage(message); currentChat.appendMessage(message);
// Update UI // Update UI
@ -591,7 +591,7 @@ public class ChatWindow extends JFrame {
repaint(); repaint();
// Request a new id generator if all IDs were used // Request a new id generator if all IDs were used
if (!localDb.getIdGenerator().hasNext()) client.requestIdGenerator(); if (!localDB.getIdGenerator().hasNext()) client.requestIdGenerator();
} catch (Exception e) { } catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error sending message:\n" + e.toString(), "Message sending error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "Error sending message:\n" + e.toString(), "Message sending error", JOptionPane.ERROR_MESSAGE);
@ -634,27 +634,27 @@ public class ChatWindow extends JFrame {
* This will trigger the display of the contact list. * This will trigger the display of the contact list.
* *
* @param client the client used to send and receive messages * @param client the client used to send and receive messages
* @param localDb the local database used to manage stored messages * @param localDB the local database used to manage stored messages
* and users * and users
* @param writeProxy the write proxy used to send messages and status change * @param writeProxy the write proxy used to send messages and status change
* events to the server or cache them inside the local * events to the server or cache them inside the local
* database * database
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void initContent(Client client, LocalDb localDb, WriteProxy writeProxy) { public void initContent(Client client, LocalDB localDB, WriteProxy writeProxy) {
this.client = client; this.client = client;
this.localDb = localDb; this.localDB = localDB;
this.writeProxy = writeProxy; this.writeProxy = writeProxy;
messageList.setRenderer((list, message) -> new MessageComponent(list, message, client.getSender().getId())); messageList.setRenderer((list, message) -> new MessageComponent(list, message, client.getSender().getId()));
// Load users and chats // Load users and chats
new Thread(() -> { new Thread(() -> {
localDb.getUsers().values().forEach(user -> { localDB.getUsers().values().forEach(user -> {
userListModel.addElement(user); userListModel.addElement(user);
// Check if user exists in local DB // Check if user exists in local DB
if (localDb.getChats().stream().noneMatch(c -> c.getRecipient().getId() == user.getId())) localDb.getChats().add(new Chat(user)); if (localDB.getChats().stream().noneMatch(c -> c.getRecipient().getId() == user.getId())) localDB.getChats().add(new Chat(user));
}); });
SwingUtilities.invokeLater(() -> userList.setModel(userListModel)); SwingUtilities.invokeLater(() -> userList.setModel(userListModel));

View File

@ -60,7 +60,7 @@ public class LoginDialog extends JDialog {
private LoginCredentials credentials; private LoginCredentials credentials;
private final Client client; private final Client client;
private final LocalDb localDb; private final LocalDB localDB;
private final Cache<Message> receivedMessageCache; private final Cache<Message> receivedMessageCache;
private static final ClientConfig config = ClientConfig.getInstance(); private static final ClientConfig config = ClientConfig.getInstance();
@ -71,18 +71,18 @@ public class LoginDialog extends JDialog {
* 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.
* *
* @param client the client used to perform the handshake * @param client the client used to perform the handshake
* @param localDb the local database in which data is persisted * @param localDB the local database in which data is persisted
* @param receivedMessageCache the cache that stored messages received during * @param receivedMessageCache the cache that stored messages received during
* the handshake * the handshake
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public LoginDialog(Client client, LocalDb localDb, Cache<Message> receivedMessageCache) { public LoginDialog(Client client, LocalDB localDB, Cache<Message> receivedMessageCache) {
this.client = client; this.client = client;
this.localDb = localDb; this.localDB = localDB;
this.receivedMessageCache = receivedMessageCache; this.receivedMessageCache = receivedMessageCache;
// Prepare handshake // Prepare handshake
localDb.loadIdGenerator(); localDB.loadIdGenerator();
addWindowListener(new WindowAdapter() { addWindowListener(new WindowAdapter() {
@ -134,7 +134,7 @@ public class LoginDialog extends JDialog {
try { try {
client.performHandshake(credentials, receivedMessageCache); client.performHandshake(credentials, receivedMessageCache);
if (client.isOnline()) { if (client.isOnline()) {
client.initReceiver(localDb, receivedMessageCache); client.initReceiver(localDB, receivedMessageCache);
dispose(); dispose();
} }
} catch (IOException | InterruptedException | TimeLimitExceededException e) { } catch (IOException | InterruptedException | TimeLimitExceededException e) {
@ -142,8 +142,8 @@ public class LoginDialog extends JDialog {
e.printStackTrace(); e.printStackTrace();
try { try {
// Try entering offline mode // Try entering offline mode
localDb.loadUsers(); localDB.loadUsers();
User clientUser = localDb.getUsers().get(credentials.getIdentifier()); User clientUser = localDB.getUsers().get(credentials.getIdentifier());
if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown"); if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown");
client.setSender(clientUser); client.setSender(clientUser);
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,