package jetbrains.buildServer.serverSide; import jetbrains.buildServer.users.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.json.JSONException; import org.json.JSONWriter; import java.util.Date; /** * @author Eugene Petrenko * Created: 31.03.2010 12:43:00 */ public class ChatMessage { private User myFromUser; private User myToUser; private final Date myDate; private String myMessage; private boolean myBroadcast; public ChatMessage(@NotNull final Date date, @NotNull final String message, @Nullable final User user, User toUser) { myDate = date; myMessage = message; myFromUser = user; myToUser = toUser; } public ChatMessage setFromUser(User fromUser) { myFromUser = fromUser; return this; } public ChatMessage setToUser(User toUser) { myToUser = toUser; return this; } public ChatMessage setMessage(String message) { myMessage = message; return this; } public boolean isDisableChat() { return getMessage().contains("#be_quiet"); } @Nullable public User getFromUser() { return myFromUser; } @Nullable public User getToUser() { return myToUser; } public Date getDate() { return myDate; } @NotNull public String getMessage() { return myMessage; } @NotNull public String getUser(UserContext userNames) { return userNames.getUserName(myFromUser); } public void writeJSON(UserContext names, TimeFactory tf, JSONWriter j) throws JSONException { j.object(); j.key("date").value(tf.format(getDate())); j.key("user").value(getUser(names)); j.key("message").value(getMessage()); j.endObject(); } public boolean isBroadcast() { return myBroadcast; } public ChatMessage setBroadcast(boolean broadcast) { myBroadcast = broadcast; return this; } @Override public String toString() { return "ChatMessage{" + "myFromUser=" + myFromUser + ", myToUser=" + myToUser + ", myMessage='" + myMessage + '\'' + '}'; } }