Skip to content

Commit 6fa9584

Browse files
committed
Added a method to get the timestamp of a chat's last message
1 parent 4a67da6 commit 6fa9584

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package entities.chat;
22
import entities.message.Message;
33

4+
import java.time.LocalDateTime;
45
import java.util.ArrayList;
56
// Chat is an abstract class
67
public class Chat {
@@ -53,5 +54,17 @@ public void addtoconvHist(Message message){
5354
this.convHist.add(message);
5455
}
5556

57+
/**
58+
* Return of the timestamp of a chat's last updated to conversation history. If conversation
59+
* history is empty, return null
60+
* @return timestamp of last update (or null if empty)
61+
*/
62+
public LocalDateTime getLastUpdated(){
63+
if (this.convHist.size() != 0) {
64+
return this.convHist.get(this.convHist.size() - 1).getTimestamp();
65+
}
66+
return null;
67+
}
68+
5669

5770
}

src/main/java/entities/chat/PrivateChat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public void setRecipientUsername(String recipientUsername) {
4545
this.recipientUsername= recipientUsername;
4646
}
4747

48-
public String getSendertUsername(){
48+
public String getSenderUsername(){
4949
return this.senderUsername;
5050
}
51-
public void setSendertUsername(String recipientUsername){
51+
public void setSenderUsername(String recipientUsername){
5252
this.recipientUsername = recipientUsername;
5353
}
5454

src/main/java/use_cases/chat_initiation_use_case/ChatInteractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void setRecipientUsername(String recipientUsername) {
3131
// Update the message history when the type in put in message txtfieled and click send button.
3232
public void setMessage(String content) {
3333
MsgFactory msgfactory = new MsgFactory("text");
34-
privatechat.addtoconvHist(msgfactory.createMsg(privatechat.getSendertUsername(), content));
34+
privatechat.addtoconvHist(msgfactory.createMsg(privatechat.getSenderUsername(), content));
3535
}
3636

3737

0 commit comments

Comments
 (0)