Skip to content

Commit 14fc3c1

Browse files
author
Nasim Bondar Sahebi
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # src/main/java/screens/app_screen/AppScreen.java # src/main/java/use_cases/chat_initiation_use_case/ChatInteractor.java
2 parents 276362d + 16df25d commit 14fc3c1

File tree

14 files changed

+137
-71
lines changed

14 files changed

+137
-71
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ Each of us have created one or more PRs and most of these have been merged into
4242
- By Amy
4343
- The App Screen UI is the screen that acts as a proxy between the user's login screen and their individual chats
4444
- Upon logging in, a user will will be rendered with a view of app screen
45-
- App Screen provides an ordered list of a user's chats, allowing the user to open an individual chat by clicking the chat button
46-
- ChatView(the window referenced above) will open, displaying the chats's GUI
47-
- Apart from that, app screen also provides buttons that allow a user to create new chats
45+
- App screen provides an ordered list of a user's chats and also allows a user to create new chats
46+
- Each chat button will also display a date indicating the date of the last message in a chat's conversation history, or no date if a chat has no messages
47+
- ChatView (the window referenced above) will open upon clicking an existing chat to display the chats's GUI
48+
- With respect to ChatView, clicking on the +Private Chat and +Group Chat buttons will also open an instance of ChatView for a user to create a new chat
49+
50+
<img width="214" alt="appscreen-nov 25" src="https://user-images.githubusercontent.com/71410005/204060542-82bb8432-09fc-4379-aee6-7a9039e58029.png">
51+
52+
4853

4954
### User Registration and Login
5055
- By Madhav

accounts

966 Bytes
Binary file not shown.

src/main/java/data_access/UserDatabase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ public void modifyUser(String oldUsername, User modified){
146146
@Override
147147
public ArrayList<Chat> getUserChats(String username) {
148148
for (User user: accountList){
149-
//if(getUser(username).equals(user)){
150149
if(user.getUsername().equals(username)){
151-
return user.getUserChats();
150+
return user.getChats();
152151
}
153152
}
154153
throw new RuntimeException("Invalid username");

src/main/java/entities/chat/Chat.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package entities.chat;
22
import entities.message.Message;
33

4+
import java.io.Serializable;
45
import java.time.LocalDateTime;
56
import java.util.ArrayList;
67
// Chat is an abstract class
7-
public class Chat {
8+
public class Chat implements Serializable {
89

910
protected String name;
1011
protected String chatID;
@@ -43,14 +44,14 @@ public String getSenderUsername(){
4344
* @return convHist
4445
*/
4546
public ArrayList<Message> getConvHist(){
46-
return new ArrayList<Message>(this.convHist);
47+
return new ArrayList<>(this.convHist);
4748
}
4849

4950
/**
5051
* Add a message to the chat's conversation history when a message is sent or received
5152
* @param message Message that is sent or received
5253
*/
53-
public void addtoconvHist(Message message){
54+
public void addToConvHist(Message message){
5455
this.convHist.add(message);
5556
}
5657

src/main/java/entities/message/Message.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package entities.message;
22

3+
import java.io.Serializable;
34
import java.time.LocalDateTime;
45

56
/**
67
* Message (abstract class) containing the message content and associated metadata
78
* The type of the message content is dependent on which child(ren) of Message the message is
89
* The metadata is universal for all message types and includes the ID of the sender, timestamp, ID of message
910
*/
10-
public abstract class Message {
11+
public abstract class Message implements Serializable{
1112
/**
1213
* ID of message sender (UUID)
1314
*/

src/main/java/entities/user_entities/User.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import interface_adapters.login_interface_adapters.Login;
77
import use_cases.user_attribute_modification_use_case.Changeable;
88
import interface_adapters.app_screen_interface_adapters.UserAppScreenGateway;
9-
import entities.chat.*;
109

1110
import java.io.File;
1211
import java.io.Serializable;
@@ -57,7 +56,8 @@ public Boolean PasswordMatch(String attempt){
5756
}
5857

5958
public void login(){
60-
UserAppScreenGateway appScreenGateway = new UserAppScreenGateway(this.getUsername(), new UserDatabase(new File("test9")));
59+
UserAppScreenGateway appScreenGateway = new UserAppScreenGateway(this.getUsername(), new UserDatabase(new File("accounts")));
60+
appScreenGateway.login();
6161
}
6262

6363
public ArrayList<Chat> getChats() {

src/main/java/interface_adapters/app_screen_interface_adapters/UserAppScreenGateway.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import data_access.UserDatabase;
44
import entities.chat.Chat;
5+
import entities.user_entities.User;
56
import interface_adapters.login_interface_adapters.Login;
67

78
import java.util.ArrayList;
@@ -17,7 +18,6 @@ public class UserAppScreenGateway implements Login {
1718
public UserAppScreenGateway(String username, UserDatabase userDatabase){
1819
this.username = username;
1920
this.userDatabase = userDatabase;
20-
login();
2121
}
2222

2323
/**
@@ -28,4 +28,11 @@ public void login(){
2828
AppScreenLoader appScreenLoader = new AppScreenLoader(this.username, userChats);
2929
}
3030

31+
public void updateUserChatList(String username, ArrayList<Chat> userChats){
32+
User currentUser = this.userDatabase.getUser(username);
33+
currentUser.getUserChats().clear();
34+
currentUser.getUserChats().addAll(userChats);
35+
this.userDatabase.modifyUser(username, currentUser);
36+
37+
}
3138
}

src/main/java/interface_adapters/login_interface_adapters/UserLoginController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public void allowLogin(){
2121
try{
2222
boolean allowLogin = user.PasswordMatch(this.password);
2323
if(allowLogin){
24-
System.out.println("made it here");
2524
user.login();
2625
}else{
2726
accessDenied("Wrong Password");

src/main/java/screens/app_screen/AppScreen.java

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package screens.app_screen;
22

33

4+
import data_access.UserDatabase;
45
import entities.chat.Chat;
5-
import entities.chat.CommonPrivatechat;
6-
import entities.chat.PrivateChatfactory;
7-
import screens.chat_screen.ChatController;
6+
import interface_adapters.app_screen_interface_adapters.UserAppScreenGateway;
87
import screens.chat_screen.ChatView;
98
import use_cases.app_screen_use_case.*;
10-
import use_cases.chat_initiation_use_case.ChatInputBoundry;
11-
import use_cases.chat_initiation_use_case.ChatInteractor;
129

1310
import javax.swing.*;
1411
import java.awt.*;
12+
import java.io.File;
1513
import java.time.LocalDateTime;
1614
import java.util.ArrayList;
1715

@@ -48,14 +46,8 @@ public AppScreen(String currentUsername, ArrayList<Chat> chats) {
4846

4947
// adding the action listeners for the +private-chat and +group-chat buttons
5048
addPrivateChat.addActionListener(e -> {
51-
//TODO AMY please double check this part(Nasim)
52-
53-
PrivateChatfactory chatfactory = new CommonPrivatechat();
54-
ChatInputBoundry Interactor = new ChatInteractor(chatfactory);
55-
ChatController controller = new ChatController(Interactor);
56-
new ChatView(controller,true);
57-
ChatView newChat = new ChatView(controller,true);
58-
49+
ChatView newChat = new ChatView(true);
50+
newChat.chatDisplay();
5951

6052
});
6153
//TODO: add groupchat action
@@ -176,6 +168,7 @@ public void addNewChat(Chat chat){
176168
if (!(this.chats.contains(chat))){
177169
updateChatOrder(chat);
178170
jFrame.remove(this.jScrollPane);
171+
createGateway();
179172

180173
// refresh the screen
181174
displayAppScreen();
@@ -190,28 +183,12 @@ public void addNewChat(Chat chat){
190183
*/
191184
@Override
192185
public void updateScreen(String chatID) {
193-
if (hasUpdate(chatID)){
194-
195-
updateChatOrder(getChat(chatID));
196-
jFrame.remove(this.jScrollPane);
186+
updateChatOrder(getChat(chatID));
187+
jFrame.remove(this.jScrollPane);
188+
createGateway();
197189

198-
// refresh the screen
199-
displayAppScreen();
200-
}
201-
}
202-
203-
/**
204-
* Return true if the given existing chat has an update to its conversation history
205-
* @param chatID The ID of the given chat
206-
* @return true/false
207-
*/
208-
@Override
209-
public boolean hasUpdate(String chatID) {
210-
Chat chat = getChat(chatID);
211-
if (!(this.chats.isEmpty())) {
212-
return !(this.chats.get(this.chats.size() - 1).equals(chat));
213-
}
214-
return true;
190+
// refresh the screen
191+
displayAppScreen();
215192
}
216193

217194
/**
@@ -229,4 +206,20 @@ public Chat getChat(String chatID) {
229206
throw new RuntimeException("User does not currently have this chat");
230207
}
231208

209+
/**
210+
* Create the gateway to save a user's chat list order in the user database
211+
*/
212+
public void createGateway(){
213+
UserAppScreenGateway gateway = new UserAppScreenGateway(currentUsername,
214+
new UserDatabase(new File("accounts")));
215+
try{
216+
gateway.updateUserChatList(currentUsername, this.chats);
217+
} catch (NullPointerException e) {
218+
throw new NullPointerException("New chat list is empty");
219+
}
220+
catch (Exception e){
221+
throw new RuntimeException("Unable to update chat order");
222+
}
223+
}
224+
232225
}

src/main/java/screens/login_screen/UserLoginUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public void getLoginCredentials(){
4747
JButton loginButton = new JButton("login");
4848
loginButton.setBounds(210, 95, 100, 25);
4949
loginPanel.add(loginButton);
50-
loginButton.addActionListener(this::actionPerformed);
50+
loginButton.addActionListener(this);
5151
loginFrame.setVisible(true);
5252

5353
}
5454

5555
public static void main(String[] args){
56-
UserRetriever testDB = new UserDatabase(new File("Test9"));
56+
UserRetriever testDB = new UserDatabase(new File("accounts"));
5757
UserLoginUI screen = new UserLoginUI(testDB);
5858
screen.getLoginCredentials();
5959
}

0 commit comments

Comments
 (0)