Commits

Steven! Ragnarök committed 69ab482

Implement broadcast bonus\!

Comments (0)

Files changed (2)

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

 		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");

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

 		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>();
 
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.