public class MessagePresenter extends BasePresenter<MessageView, PlayerBoardEventBus> {
private ScenePresenter parent;
private MessageDTO message;
public void mergeMessage(MessageDTO messageToMerge) {
final MessageAction actionToMerge = messageToMerge.getAction();
if (this.message == null) {
// Init
this.message = messageToMerge;
// Author
final Long authorId = messageToMerge.getAuthor();
if (authorId != null) {
final CharacterHeaderDTO character = this.parent.getCharacter(authorId);
this.view.setCharacter(character.getName(), character.getIcon(),character.getId());
}
// Type
final MessageType type = message.getType();
if (MessageType.ACTION.equals(type)) {
final MessageAction action = message.getAction();
if (action != null) {
this.view.setAction(actionToMerge.toLocaleString());
}
} else if (MessageType.DICEROLL.equals(type)) {
updateDice(type);
}
// Content
this.view.setContent("(" + messageToMerge.getId() + ")(" + messageToMerge.getIndex() + ") "
+ messageToMerge.getContent());
} else {
// Update
final long indexToMerge = messageToMerge.getIndex();
if (message.getIndex() != indexToMerge) {
// Message need to be moved by its scene
this.parent.moveMessage((int) message.getIndex(), (int) indexToMerge);
this.view.setContent("(" + messageToMerge.getId() + ")(" + messageToMerge.getIndex() + ") "
+ message.getContent());
}
final String contentToMerge = messageToMerge.getContent();
if (!message.getContent().equals(contentToMerge)) {
message.setContent(contentToMerge);
this.view.setContent("(" + messageToMerge.getId() + ")(" + messageToMerge.getIndex() + ") "
+ contentToMerge);
}
final MessageType type = message.getType();
if (MessageType.ACTION.equals(type)) {
final MessageAction action = message.getAction();
if (action != null && !action.equals(actionToMerge)) {
message.setAction(actionToMerge);
this.view.setAction(actionToMerge.toLocaleString());
}
} else if (MessageType.DICEROLL.equals(type)) {
updateDice(type);