package chat.rocket.android.layouthelper.chatroom;

import android.content.Context;

import chat.rocket.android.R;
import chat.rocket.android.model.ddp.Message;

/**
 * message type.
 */
public enum MessageType {
  ROOM_NAME_CHANGED("r") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_room_name_changed,
          message.getMessage(), message.getUser().getUsername());
    }
  },
  USER_ADDED("au") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_user_added_by,
          message.getMessage(), message.getUser().getUsername());
    }
  },
  USER_REMOVED("ru") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_user_removed_by,
          message.getMessage(), message.getUser().getUsername());
    }
  },
  USER_JOINED("uj") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_user_joined_channel);
    }
  },
  USER_LEFT("ul") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_user_left);
    }
  },
  WELCOME("wm") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_welcome, message.getUser().getUsername());
    }
  },
  MESSAGE_REMOVED("rm") {
    @Override
    public String getString(Context context, Message message) {
      return context.getString(R.string.message_removed);
    }
  },
  UNSPECIFIED("");
  //------------

  private final String value;

  MessageType(String value) {
    this.value = value;
  }

  public String getValue() {
    return value;
  }

  public static MessageType parse(String value) {
    for (MessageType type : MessageType.values()) {
      if (type.value.equals(value)) return type;
    }
    return UNSPECIFIED;
  }

  public String getString(Context context, Message message) {
    return "";
  }
}

@@ -410,34 +410,16 @@
 sage(), 
-message.getUser().
 getUsern
@@ -414,32 +414,39 @@
 (), getUsername(
+message
 ));%0A    %7D%0A  %7D,%0A 
@@ -638,34 +638,16 @@
 sage(), 
-message.getUser().
 getUsern
@@ -642,32 +642,39 @@
 (), getUsername(
+message
 ));%0A    %7D%0A  %7D,%0A 
@@ -870,34 +870,16 @@
 sage(), 
-message.getUser().
 getUsern
@@ -874,32 +874,39 @@
 (), getUsername(
+message
 ));%0A    %7D%0A  %7D,%0A 
@@ -1411,26 +1411,8 @@
 me, 
-message.getUser().
 getU
@@ -1419,16 +1419,23 @@
 sername(
+message
 ));%0A    
@@ -2037,24 +2037,24 @@
  message) %7B%0A
-
     return %22
@@ -2059,11 +2059,209 @@
  %22%22;%0A  %7D
+%0A%0A  private static String getUsername(Message message) %7B%0A    if (message != null && message.getUser() != null) %7B%0A      return message.getUser().getUsername();%0A    %7D else %7B%0A      return %22%22;%0A    %7D%0A  %7D
 %0A%7D%0A

fix NPE