1. Steven! Ragnarök
  2. messageme

Commits

Steven! Ragnarök  committed 69ab482

Implement broadcast bonus\!

  • Participants
  • Parent commits 6220e9b
  • Branches default

Comments (0)

Files changed (2)

File src/main/java/com/nuclearsandwich/messageme/App.java

View file
 		printSendUsage();
 		printExitUsage();
 		printConnectDisconnectUsage();
+		printBroadcastUsage();
 	}
 
 	public static void loop() {
 			connect(argList);
 		} else if (command.equals("disconnect")) {
 			disconnect(argList);
+		} else if (command.equals("broadcast")) {
+			broadcast(argList);
 		}
 	}
 
 		User.by(argList).disconnectPhone();
 	}
 
+	public static void broadcast(String argList) {
+		String[] args = argList.split(" ", 2);
+		User sender = User.by(args[0]);
+		String body = args[1].replace("'", "");
+
+		for (User recipient : User.allBut(sender)) {
+			Message msg = new Message(sender, recipient, body);
+			recipient.getInbox().add(msg);
+			recipient.getPhone().newMessage(msg);
+		}
+	}
+
 
 	public static void printInboxUsage() {
 		System.out.println("inbox USER_NAME");
 		System.out.println("exit");
 	}
 
+	public static void printBroadcastUsage() {
+		System.out.println("broadcast SENDER MESSAGE");
+	}
+
 	public static void printConnectDisconnectUsage() {
 		System.out.println("connect USER_NAME");
 		System.out.println("disconnect USER_NAME");

File src/main/java/com/nuclearsandwich/messageme/User.java

View file
 		return null;
 	}
 
+	public static ArrayList<User> allBut(User u) {
+		ArrayList<User> allBut = new ArrayList<User>();
+		for (User usr : userList) {
+			if (u != usr) {
+				allBut.add(usr);
+			}
+		}
+
+		return allBut;
+	}
+
 	private static final ArrayList<User> userList = new ArrayList<User>();
 
 }