Skip to content

Commit 73d358a

Browse files
authored
Merge branch 'main' into 9-feature-1-user-registration
2 parents bbd6f94 + 1e1f4d9 commit 73d358a

File tree

64 files changed

+1942
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1942
-73
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
22
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
33

4-
# entities.user_entities.User-specific stuff
4+
# entities.userEntities.User-specific stuff
55
.idea/**/workspace.xml
66
.idea/**/tasks.xml
77
.idea/**/usage.statistics.xml
88
.idea/**/dictionaries
99
.idea/**/shelf
10-
11-
# AWS entities.user_entities.User-specific
10+
# AWS entities.userEntities.User-specific
1211
.idea/**/aws.xml
1312

1413
# Generated files

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
# Project Template
1+
# SOLID Chat
22

3+
## Our Progress (Last Updated on Nov 20)
4+
5+
Each of us have created one or more PRs and most of these have been merged into the main branch. Many members have functional UI's (and they are likely happy to demonstrate in tutorial) and others have a basic non-interactive UI and the inner layers of clean architecture. While they may not be able to do an interactive demo, screenshots of these user interfaces are included below.
6+
7+
### Chat UI
8+
- By Nasim, James, and Amy
9+
- The UI is rendered by ChatView
10+
- This view will appear when a user creates a new chat or visits an existing chat
11+
12+
![image](https://user-images.githubusercontent.com/18428059/202935072-ba09587d-c67d-4599-9986-9c652480356f.png)
13+
14+
15+
## Template Readme
316
This is a template repository for CSC 207 projects.
417
This repository contains starter code for a gradle project.
518
It also contains workflow documents that give instructions on how to manage your Github repository and how to use Github Projects for efficient collaboration.
619

7-
## Checklist For Your Project
20+
### Checklist For Your Project
821
- [ ] Verify the correct settings for your project repository
922
- [ ] Set up Github Projects
1023
- [ ] Create the implementation plan using issues and Github Projects
@@ -14,13 +27,13 @@ It also contains workflow documents that give instructions on how to manage your
1427

1528
**If your team has trouble with any of these steps, please ask on Piazza. For example, with how GitHub Classroom works, your team *may* not have permissions to do some of the first few steps, in which case we'll post alternative instructions as needed.**
1629

17-
## Workflow Documents
30+
### Workflow Documents
1831

1932
* Github Workflow: Please refer to the workflow that was introduced in the first lab. You should follow this when working on your code. The following document provides additional details too.
2033

2134
* [Project Planning and Development Guide](project_plan_dev.md): This document helps you to understand how to create and maintain a project plan for your class project. **This document helps you to complete the Implementation Plan Milestone.**
2235

23-
## Gradle Project
36+
### Gradle Project
2437
Import this project into your Intellij editor. It should automatically recognise this as a gradle repository.
2538
The starter code was built using SDK version 11.0.1. Ensure that you are using this version for this project. (You can, of course, change the SDK version as per your requirement if your team has all agreed to use a different version)
2639

src/main/java/TestUserDatabase2.csv

Whitespace-only changes.

src/main/java/UserAccounts.csv

Whitespace-only changes.

src/main/java/data_access/UserDatabase.java

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
import use_cases.user_login_use_case.UserCreator;
88
import interface_adapters.UserRetriever;
99

10+
import interface_adapters.Chat.ConvHistGateway;
11+
import interface_adapters.Chat.MsgSenderGateway;
12+
import interface_adapters.Chat.UserChatGateway;
13+
import interface_adapters.User.*;
14+
1015
import java.io.*;
1116
import java.util.ArrayList;
1217
import java.util.List;
13-
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList {
18+
19+
public class UserDatabase implements UserExists, UserRetriever, UserCreator, IRetrieveList, UserModificationGateway,
20+
ConvHistGateway, MsgSenderGateway, UserChatGateway {
1421
File accounts;
1522
List<User> accountList;
1623
public UserDatabase(){
@@ -38,6 +45,16 @@ public boolean UserExists(String username, String email) {
3845
return false;
3946
}
4047

48+
@Override
49+
public boolean UserExists(String username) {
50+
for(User user: this.accountList){
51+
if(user.getUsername().equals(username)){
52+
return true;
53+
}
54+
}
55+
return false;
56+
}
57+
4158
// Creates a new user with a username and password, and an email address
4259
// The order is username, password, email address, verification status, status
4360
//
@@ -62,9 +79,9 @@ public void createUser(String username, String password, String email, String ty
6279
// To be edited to get user from the array format rather than the serialized format.
6380
public User getUser(String username) {
6481
User ans = null;
65-
for (int i = 0; i < (this.getList().size()); i++) {
66-
if (this.getList().get(i).getUsername().equals(username)) {
67-
ans = this.getList().get(i);
82+
for (int i = 0; i < (this.accountList.size()); i++) {
83+
if (this.accountList.get(i).getUsername().equals(username)) {
84+
ans = this.accountList.get(i);
6885
}
6986
}
7087
return ans;
@@ -85,4 +102,72 @@ public List<User> getList() {
85102
throw new RuntimeException(ex);
86103
}
87104
}
105+
106+
@Override
107+
public void modifyUser(String oldUsername, User modified){
108+
// swap in modified user to accountList
109+
this.accountList.remove(this.getUser(oldUsername));
110+
this.accountList.add(modified);
111+
112+
// overwrite the serialized file
113+
try(FileOutputStream fileOut = new FileOutputStream(accounts)){
114+
try(ObjectOutputStream out = new ObjectOutputStream(fileOut)){
115+
out.writeObject(this.accountList);
116+
out.close();
117+
fileOut.close();
118+
}catch(Exception e){
119+
System.out.println("Error");
120+
}
121+
}catch(Exception e){
122+
System.out.println("Error");
123+
}
124+
}
125+
126+
127+
// Below two methods are used by conversation history-related interactors
128+
// (Commented as objects are not found)
129+
// /**
130+
// * Pushes a new message to a chat's conversation history (in memory not persisting storage)
131+
// * @param dsRequestModel input data containing user ID, chat ID, message content
132+
// */
133+
// public void saveMessage(MsgSenderDsRequestModel dsRequestModel) {
134+
// String userID = dsRequestModel.getUserID();
135+
// String chatID = dsRequestModel.getChatID();
136+
// Message message = dsRequestModel.getMessage();
137+
//
138+
// // Find chat under specified entities.userEntities.User
139+
// Chat chat = this.getUser(userID).getChat(chatID);
140+
//
141+
// chat.addMessage(message);
142+
// }
143+
//
144+
// /**
145+
// * Gets a chat's conversation history (from memory not persisting storage)
146+
// * @param dsRequestModel input data containing user ID, chat ID
147+
// * @return a chat's conversation history
148+
// */
149+
// public ArrayList<Message> getConversationHistory(ConvHistDsRequestModel dsRequestModel) {
150+
// String userID = dsRequestModel.getUserID();
151+
// String chatID = dsRequestModel.getChatID();
152+
//
153+
// // Find chat under specified entities.userEntities.User
154+
// Chat chat = this.getUser(userID).getChat(chatID);
155+
//
156+
// return Chat.getConversationHistory();
157+
// }
158+
159+
160+
161+
162+
// This method will get a user's chats; this will be used by AppScreenLoader to display chats and could
163+
// also be used by ChatInteractor (Chat entity is undefined here and at the moment user doesn't have chats)
164+
// @Override
165+
// public ArrayList<Chat> getUserChats(String username) {
166+
// for (entities.userEntities.User user: accountList){
167+
// if (user.getUsername().equals(username)){
168+
// return user.getChats();
169+
// }
170+
// }
171+
// throw new RuntimeException("Invalid username: user does not exist");
172+
// }
88173
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package entities.chat;
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 addtoconvHist(Message message){
51+
this.convHist.add(message);
52+
}
53+
54+
55+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package entities.chat;
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package entities.chat;
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+
*/
25+
public PrivateChat(String name, String chatID, String senderUsername, String recipientUsername ){
26+
this.name = name;
27+
this.chatID = chatID;
28+
this.senderUsername = senderUsername;
29+
this.recipientUsername = recipientUsername;
30+
this.convHist = new ArrayList<Message>();
31+
}
32+
33+
34+
/**
35+
* Get the recipient's username
36+
* @return senderRecipient
37+
*/
38+
public String getRecipientUsername(){
39+
return this.recipientUsername;
40+
}
41+
42+
public void setRecipientUsername(String recipientUsername) {
43+
this.recipientUsername= recipientUsername;
44+
}
45+
46+
public String getSendertUsername(){
47+
return this.senderUsername;
48+
}
49+
public String setSendertUsername(String recipientUsername){
50+
this.recipientUsername = recipientUsername;
51+
}
52+
53+
54+
}

0 commit comments

Comments
 (0)