Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate servername#96 #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
.env
.env

/app_logs.log
35 changes: 18 additions & 17 deletions lib/prompt_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class ChatAPI {
// Register a user
Future<void> registerUser(String? username, String? password) async {
if (username == null || password == null) {

throw InvalidCredentialsException();
}
if (!isPasswordValid(password)) {
print("Password must be atleast 8 characters long, having atleast a number & a special character. Please try again.");
throw WeakPasswordException();
print(
"Password must be atleast 8 characters long, having atleast a number & a special character. Please try again.");
throw WeakPasswordException();
}
validUsername(username);
var newUser = User(username, password, false);
Expand Down Expand Up @@ -221,6 +221,9 @@ class ChatAPI {
throw Exception(
"Please enter the required credentials, or login to continue.");
}
if (servers.any((element) => element.serverName == serverName)) {
throw Exception("Server with same name already exists!");
}
JoinPerm joinPerm = getJoinPerm(serverPerm);
var creator = getUser(userName);
var newServer = createNewServer(serverName, joinPerm);
Expand Down Expand Up @@ -567,20 +570,18 @@ class ChatAPI {
var reqServer = getServer(servername);
var reqUser = getUser(username);
reqServer.checkAccessLevels(username, [1, 2]);
var inviteCode = InviteCode(reqUser, "",reqServer);
for(var invitecode in reqServer.inviteCodes ){
if(invitecode.code == inviteCode.code){
var inviteCode = InviteCode(reqUser, "", reqServer);
for (var invitecode in reqServer.inviteCodes) {
if (invitecode.code == inviteCode.code) {
return createInviteCode(servername, username);
}
else if (invitecode.inviter == reqUser){
} else if (invitecode.inviter == reqUser) {
return invitecode.code;
}
}
reqServer.inviteCodes.add(inviteCode);
await DatabaseIO.addToDB(inviteCode,"invitecodes");
await DatabaseIO.addToDB(inviteCode, "invitecodes");
inviteCodes.add(inviteCode);
return inviteCode.code;

}

// join server using invite code
Expand All @@ -596,32 +597,32 @@ class ChatAPI {
invite.invitedUsers.add(reqUser);
}

void sendDm(String recieverusername, String message, String senderusername){
void sendDm(String recieverusername, String message, String senderusername) {
User sender = getUser(senderusername);
User reciever = getUser(recieverusername);
DirectMessage dm = DirectMessage(sender, reciever, message);
print(dm);
dm.send();
}

Future<List<String>> getRecievedDms(String username) async{
Future<List<String>> getRecievedDms(String username) async {
User user = getUser(username);
List<DirectMessage> dms = await DirectMessage.getMessages(user);
List<String> messages = [];
for(DirectMessage dm in dms){
if(dm.receiver.username == user.username){
for (DirectMessage dm in dms) {
if (dm.receiver.username == user.username) {
messages.add("${dm.sender.username} : ${dm.message}");
}
}
return messages;
}

Future<List<String>> getSentDms(String username) async{
Future<List<String>> getSentDms(String username) async {
User user = getUser(username);
List<DirectMessage> dms = await DirectMessage.getMessages(user);
List<String> messages = [];
for(DirectMessage dm in dms){
if(dm.sender.username == user.username){
for (DirectMessage dm in dms) {
if (dm.sender.username == user.username) {
messages.add("${dm.receiver.username} : ${dm.message}");
}
}
Expand Down