Skip to content

Commit 581e260

Browse files
author
Nasim Bondar Sahebi
committed
Merge remote-tracking branch 'origin/chat-initiation' into chat-initiation
2 parents 29075bb + 3be8c5b commit 581e260

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

src/main/java/entities/Chat.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package entities;
2+
import java.util.ArrayList;
3+
// Chat is an abstract class
4+
public class Chat {
5+
6+
protected String name;
7+
protected String chatID;
8+
protected String senderUsername;
9+
10+
// chat's conversation history
11+
protected ArrayList<Message> convHist;
12+
13+
14+
/**
15+
* Get the chat's name
16+
* @return name
17+
*/
18+
public String getName(){
19+
return this.name;
20+
}
21+
22+
/**
23+
* Get the chat's ID
24+
* @return chatID
25+
*/
26+
public String getChatID(){
27+
return this.chatID;
28+
}
29+
30+
/**
31+
* Get the sender's username
32+
* @return senderUsername
33+
*/
34+
public String getSenderUsername(){
35+
return this.senderUsername;
36+
}
37+
38+
/**
39+
* Return this conversation history of the chat
40+
* @return convHist
41+
*/
42+
public ArrayList<Message> getConvHist(){
43+
return new ArrayList<Message>(this.convHist);
44+
}
45+
46+
/**
47+
* Add a message to the chat's conversation history when a message is sent or received
48+
* @param message Message that is sent or received
49+
*/
50+
public void sendRecieveMessage(Message message){
51+
this.convHist.add(message);
52+
}
53+
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package entities;
2+
3+
import java.util.ArrayList;
4+
5+
public class GroupChat extends Chat{
6+
7+
/*
8+
From Chat, GroupChat has:
9+
String name;
10+
String chatID;
11+
String senderUsername;
12+
Arraylist<Message> convHist;
13+
*/
14+
public ArrayList<String> groupMembers;
15+
16+
/**
17+
* Create a private chat
18+
* @param name The name of the chat
19+
* @param chatID The ID of the chat
20+
* @param senderUsername The username of the user sending the messages
21+
*/
22+
public GroupChat(String name, String chatID, String senderUsername){
23+
this.name = name;
24+
this.chatID = chatID;
25+
this.senderUsername = senderUsername;
26+
this.convHist = new ArrayList<Message>();
27+
this.groupMembers = new ArrayList<>();
28+
}
29+
30+
/**
31+
* Return an arraylist of all the usernames of group members (not including the sender) in a group chat
32+
*
33+
* @return groupMembers
34+
*/
35+
public ArrayList<String> getGroupMembers(){
36+
return new ArrayList<String>(this.groupMembers);
37+
}
38+
39+
/**
40+
* Add a member to a group chat
41+
* @param user The user to be added
42+
*/
43+
public void addMember(String user){
44+
try {
45+
this.groupMembers.add(user);
46+
} catch (Exception e) {
47+
throw new RuntimeException(e);
48+
}
49+
}
50+
51+
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package entities;
2+
3+
import java.util.ArrayList;
4+
5+
public class PrivateChat extends Chat{
6+
7+
/*
8+
From Chat, PrivateChat has:
9+
String name;
10+
String chatID;
11+
String senderUsername;
12+
Arraylist<Message> convHist;
13+
*/
14+
protected String recipientUsername;
15+
16+
/**
17+
* Create a private chat
18+
*
19+
* @param name The name of the chat (also the username of the recipient)
20+
* @param chatID The ID of the chat
21+
* @param senderUsername The user sending the messages
22+
* @param recipientUsername The user receiving the messages
23+
*/
24+
public PrivateChat(String name, String chatID, String senderUsername, String recipientUsername){
25+
this.name = name;
26+
this.chatID = chatID;
27+
this.senderUsername = senderUsername;
28+
this.recipientUsername = recipientUsername;
29+
this.convHist = new ArrayList<Message>();
30+
}
31+
32+
/**
33+
* Get the recipient's username
34+
* @return senderRecipient
35+
*/
36+
public String getRecipientUsername(){
37+
return this.recipientUsername;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)