Messaging-App
README.md

Messaging App

Part 1 - Running the App

Before running the app, ensure that these 8 files are in your working directory:

1. MessagingServer.java

2. MessagingClient.java

3. Customer.java

4. User.java

5. Seller.java

6. Store.java

7. Message.java

8. NewMessage.java

Then, in your terminal run:
javac MessagingServer.java MessagingClient.java Seller.java Store.java Customer.java User.java Message.java NewMessage.java

To start the server, run:
java MessagingServer

To start the client, run:
java MessagingClient

Note:

The client is originally set to connect to localhost. If you wish to connect to a server on a different computer (but same network), simply change "localhost" in MessagingClient.java (line 2189) to the IP address of the server.

Once you've entered the application, follow the prompts to create an account as either a seller or customer, sign in, and explore the features we've built! Feel free to create multiple accounts and launch several instances of MessagingClient to try out real-time messaging and experiment with how different accounts interact with each other.

Part 2 - How this all works

1. MessagingClient.java

The MessagingClient class stores the client-side program of our application. MessagingClient is in charge of displaying the GUI and accepting user input. All its methods and fields are created to build an engaging user interface. Although MessagingClient validates some inputs, like empty JTextFields, almost no other processing is done in the client. User input is received and sent to the server to be handled. The client then reads a response from the server and displays the next appropriate JFrame or JOptionPane. Certain frames in MessagingClient also periodically requests for the latest information from the server. As such, message history, the count of new messages and user statistics all update in real-time, without needing any action by the user.

2. MessagingServer.java

The MessagingServer class is our application's the server-side program. It handles all the processing in our app by instantiating and utilizing the methods and fields in the User, Customer, Seller, Store, Message, and NewMessage classes. The server is also in charge of handling concurrency. Each instance of a client runs on its own MessagingServer Thread, allowing multiple clients to interact with the server at once. There are also synchronized code blocks within MessagingServer to prevent race conditions between multiple clients. In each thread, the server reads user input sent by the client, processes it, and sends an appropriate response back. An example of this would be sending a string array of messages back to the client to be displayed as a conversation history between a store and a customer.

3. User.java

User is a superclass which holds all the core functionality that a user (customer ort seller) can perform in our app. Some of these functionalities include sending, editing and deleting messages, file import/export, blocking and becoming invisible to other users, and modifying their own account. Additionally, the User class keeps track of the number of new messages a user has, and displays the data on a user's main menu. To accomplish all this, the User class handles a majority of the read/write operations in our application.

4. Customer.java

Customer is a subclass of User, and has all the functionalities and fields a user has, but also has more features tailored specifically to customers of our app. The main feature of a Customer is displaying a customer statistics dashboard, which can be sorted by the number of messages received and sent to a store. Every instance of a Customer object also serves as a gatekeeper for that customer's messaging file, i.e., only one Thread can edit a customer's message files at a time.

5. Seller.java

Seller is a subclass of User, and has all the functionalities and fields a user has, but also has more features tailored specifically to sellers of our app. The main feature of a Seller is to create and store an ArrayList of stores, which have a lot more functionality (see 6. Store.java) and are used as an interface to message Customers.

6. Store.java

The Store class stores all the fields and features of a Seller's store in our app. You can think about the Store class as an extension of a Seller. We designed our app such that Customers cannot contact a Seller personally, and must instead contact a seller through their store. The Store class is responsible for producing a statistics dashboard that a seller can view. This dashboard contains the top 10 most common words in all conversation histories between a seller's store and customer. Each store's dashboard can also be sorted by the number of messages received from a customer.

7. Message.java

The Message class is used to store all the information that a message would contain. This includes the sender's ID and name, a time stamp of when the message was sent, whether the message is new or disappearing, and finally the message's content. When a user sends a message, a new instance of a message class is created and written to a file. When retrieving message data from a file (to edit a message for example), file data is read into a Message object for ease of processing.

8. NewMessage.java

The NewMessage class is used to implement our new-messages feature for users. It stores both a Customer and Store object and the number of new messages between the two parties. This set up allows us to make conversations with new messages accessible from the new message button in a user's menu (please watch our presentation for a more detailed example).