Skip to content

Commit

Permalink
Merge pull request #104 from sommye-ctr/logout-when-loggedout#103
Browse files Browse the repository at this point in the history
Fixed logout error when already logged out
  • Loading branch information
Palakfs authored Jan 16, 2025
2 parents 6e8255c + 722cb27 commit fbf733b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
32 changes: 16 additions & 16 deletions bin/prompt_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ void runApp(ChatAPI api) async {
break;
}
var confirmFlag = getFlagValue("--confirm", currentCommand);
if (confirmFlag.toLowerCase() == "yes" ||
confirmFlag.toLowerCase() == "y") {
if (confirmFlag?.toLowerCase() == "yes" ||
confirmFlag?.toLowerCase() == "y") {
await api.logoutUser(currUsername);
currUsername = null;
api.deleteUser(currUsername);
Expand Down Expand Up @@ -445,23 +445,23 @@ void runApp(ChatAPI api) async {
break;
}
case "block":
{
if (currUsername == null) {
print("Please login first.");
break;
{
if (currUsername == null) {
print("Please login first.");
break;
}
await api.blockUser(currUsername, ccs[1]);
print("User blocked successfully.");
}
await api.blockUser(currUsername, ccs[1]);
print("User blocked successfully.");
}
case "unblock":
{
if (currUsername == null) {
print("Please login first.");
break;
{
if (currUsername == null) {
print("Please login first.");
break;
}
await api.unblockUser(currUsername, ccs[1]);
print("User unblocked successfully.");
}
await api.unblockUser(currUsername, ccs[1]);
print("User unblocked successfully.");
}
default:
{
print("Please enter a valid command.");
Expand Down
11 changes: 7 additions & 4 deletions lib/prompt_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ChatAPI {
// Logout a user
Future<void> logoutUser(String? username) async {
if (username == null) {
throw InvalidCredentialsException();
throw Exception("No user logged in currently!");
}
var reqUser = getUser(username);
reqUser.loggedIn = false;
Expand Down Expand Up @@ -619,7 +619,11 @@ class ChatAPI {
invite.invitedUsers.add(reqUser);
}

void sendDm(String recieverusername, String message, String senderusername) {
void sendDm(
String? recieverusername, String? message, String? senderusername) {
if (recieverusername == null || message == null || senderusername == null) {
throw Exception("Enter a valid command!");
}
User sender = getUser(senderusername);
User reciever = getUser(recieverusername);
DirectMessage dm = DirectMessage(sender, reciever, message);
Expand All @@ -634,7 +638,6 @@ class ChatAPI {
// Only show messages if sender is not blocked
if (dm.receiver.username == user.username &&
!user.blockedUsers.contains(dm.sender.username)) {

messages.add("${dm.sender.username} : ${dm.message}");
}
}
Expand Down Expand Up @@ -734,8 +737,8 @@ class ChatAPI {
throw Exception('Failed to import server data: $e');
}
}
Future<void> blockUser(String? blockerUsername, String? userToBlock) async {

Future<void> blockUser(String? blockerUsername, String? userToBlock) async {
if (blockerUsername == null || userToBlock == null) {
throw Exception("Please enter valid usernames");
}
Expand Down

0 comments on commit fbf733b

Please sign in to comment.