Skip to content

Commit 61755c2

Browse files
committed
Refactored some parts in AppScreen
1 parent 66c3381 commit 61755c2

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public AppScreen(String currentUsername, ArrayList<Chat> chats) {
5151

5252
// adding the action listeners for the +private-chat and +group-chat buttons
5353
addPrivateChat.addActionListener(e -> {
54-
PrivateChatfactory privateChatfactory = (PrivateChatfactory) new CommonPrivatechat();
54+
PrivateChatfactory privateChatfactory = new CommonPrivatechat();
5555
ChatInputBoundry inputBoundry = new ChatInteractor(privateChatfactory);
5656
ChatController controller = new ChatController(inputBoundry);
5757
new ChatView(controller, true);
@@ -165,32 +165,14 @@ public void updateChatOrder(Chat chat){
165165

166166
}
167167

168-
/**
169-
* Add a new chat to the screen, if the chat already exists (i.e. there exists a chat with the
170-
* same ID, do nothing)
171-
* @param chat The new chat to be added
172-
*/
173-
public void addNewChat(Chat chat){
174-
175-
if (!(this.chats.contains(chat))){
176-
updateChatOrder(chat);
177-
jFrame.remove(this.jScrollPane);
178-
createGateway();
179-
180-
// refresh the screen
181-
displayAppScreen();
182-
183-
}
184-
}
185-
186168
/**
187169
* Update the order of chats that appear on screen if there was a change to conversation history
188-
* This should not be called if chatID is not an ID of an existing chat that the current user has
189-
* @param chatID The ID of the given chat
170+
* This should be called if a new chat was added or if an existing chat has a new message
171+
* @param chat The chat with an update
190172
*/
191173
@Override
192-
public void updateScreen(String chatID) {
193-
updateChatOrder(getChat(chatID));
174+
public void updateScreen(Chat chat) {
175+
updateChatOrder(chat);
194176
jFrame.remove(this.jScrollPane);
195177
createGateway();
196178

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package use_cases.app_screen_use_case;
22

3+
import entities.chat.Chat;
4+
35
public interface Refresh {
4-
void updateScreen(String chatID);
6+
void updateScreen(Chat chat);
57
}

0 commit comments

Comments
 (0)