use of de.catma.ui.events.CommentMessage in project catma by forTEXT.
the class CommentMessageListener method uiOnMessage.
@Override
public void uiOnMessage(Message<CommentMessage> message) {
boolean autoShowcomments = (boolean) cbAutoShowComments.getData();
if (!autoShowcomments) {
return;
}
try {
CommentMessage commentMessage = message.getMessageObject();
final String documentId = commentMessage.getDocumentId();
final boolean replyMessage = commentMessage.isReplyMessage();
final int senderId = commentMessage.getSenderId();
final boolean deleted = commentMessage.isDeleted();
final SourceDocument document = documentSupplier.get();
if ((document != null) && document.getUuid().equals(documentId)) {
User user = project.getUser();
Integer receiverId = user.getUserId();
if (!receiverId.equals(senderId)) {
final Comment comment = commentMessage.toComment();
Optional<Comment> optionalExistingComment = this.comments.stream().filter(c -> c.getUuid().equals(comment.getUuid())).findFirst();
if (replyMessage) {
if (optionalExistingComment.isPresent()) {
Comment existingComment = optionalExistingComment.get();
Reply reply = commentMessage.toReply();
Reply existingReply = existingComment.getReply(reply.getUuid());
if (existingReply != null) {
if (deleted) {
existingComment.removeReply(existingReply);
tagger.removeReply(existingComment, existingReply);
} else {
existingReply.setBody(reply.getBody());
tagger.updateReply(existingComment, existingReply);
}
} else {
existingComment.addReply(reply);
tagger.addReply(existingComment, reply);
}
}
} else {
if (deleted) {
optionalExistingComment.ifPresent(existingComment -> {
this.comments.remove(existingComment);
tagger.removeComment(existingComment);
});
} else {
if (optionalExistingComment.isPresent()) {
Comment existingComment = optionalExistingComment.get();
existingComment.setBody(comment.getBody());
tagger.updateComment(existingComment);
} else {
comments.add(comment);
tagger.addComment(comment);
}
}
}
getUi().push();
}
}
} catch (Exception e) {
logger.log(Level.WARNING, "error processing an incoming Comment", e);
}
}
use of de.catma.ui.events.CommentMessage in project catma by forTEXT.
the class TaggerView method handleReplyChange.
@Subscribe
public void handleReplyChange(ReplyChangeEvent replyChangeEvent) {
switch(replyChangeEvent.getChangeType()) {
case CREATED:
{
try {
tagger.addReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error adding Reply!", e);
}
break;
}
case UPDATED:
{
try {
tagger.updateReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error updating Reply!", e);
}
break;
}
case DELETED:
{
try {
tagger.removeReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error removing Reply!", e);
}
break;
}
}
try {
if (commentTopic != null) {
Comment comment = replyChangeEvent.getComment();
ClientComment clientComment = new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), comment.getRanges().stream().map(r -> new TextRange(r.getStartPoint(), r.getEndPoint())).collect(Collectors.toList()));
Reply reply = replyChangeEvent.getReply();
ClientCommentReply clientCommentReply = new ClientCommentReply(reply.getUuid(), reply.getBody(), reply.getUsername(), reply.getUserId(), reply.getCommentUuid());
commentTopic.publish(new CommentMessage(comment.getId(), comment.getIid(), project.getUser().getUserId(), clientComment, comment.getDocumentId(), replyChangeEvent.getChangeType() == ChangeType.DELETED, reply.getId(), clientCommentReply));
}
} catch (Exception e) {
logger.log(Level.WARNING, "error publishing a comment message", e);
}
}
use of de.catma.ui.events.CommentMessage in project catma by forTEXT.
the class TaggerView method handleCommentChange.
@Subscribe
public void handleCommentChange(CommentChangeEvent commentChangeEvent) {
switch(commentChangeEvent.getChangeType()) {
case CREATED:
{
try {
comments.add(commentChangeEvent.getComment());
tagger.addComment(commentChangeEvent.getComment());
} catch (IOException e) {
errorHandler.showAndLogError("Error adding Comment!", e);
}
break;
}
case UPDATED:
{
tagger.updateComment(commentChangeEvent.getComment());
break;
}
case DELETED:
{
this.comments.remove(commentChangeEvent.getComment());
tagger.removeComment(commentChangeEvent.getComment());
break;
}
}
try {
if (commentTopic != null) {
Comment comment = commentChangeEvent.getComment();
ClientComment clientComment = new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), comment.getRanges().stream().map(r -> new TextRange(r.getStartPoint(), r.getEndPoint())).collect(Collectors.toList()));
commentTopic.publish(new CommentMessage(comment.getId(), comment.getIid(), project.getUser().getUserId(), clientComment, comment.getDocumentId(), commentChangeEvent.getChangeType() == ChangeType.DELETED));
}
} catch (Exception e) {
logger.log(Level.WARNING, "error publishing a comment message", e);
}
}
Aggregations