Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Trader Chat row selection and unread message count #4195

Merged
merged 1 commit into from Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,26 @@ private void openChat(Trade trade) {
// Delay display to next render frame to avoid that the popup is first quickly displayed in default position
// and after a short moment in the correct position
UserThread.execute(() -> chatPopupStage.setOpacity(1));
updateChatMessageCount(trade, badgeByTrade.get(trade.getId()));
}

private void updateChatMessageCount(Trade trade, JFXBadge badge) {
if (!trade.getId().equals(tradeIdOfOpenChat)) {
updateNewChatMessagesByTradeMap();
long num = newChatMessagesByTradeMap.get(trade.getId());
if (num > 0) {
badge.setText(String.valueOf(num));
badge.setEnabled(true);
} else {
badge.setText("");
badge.setEnabled(false);
}
} else {
badge.setText("");
badge.setEnabled(false);
}
badge.refreshBadge();
}

///////////////////////////////////////////////////////////////////////////////////////////
// Private
Expand Down Expand Up @@ -729,41 +747,24 @@ public void updateItem(final PendingTradesListItem newItem, boolean empty) {
}

button.setOnAction(e -> {
tableView.getSelectionModel().select(this.getIndex());
openChat(trade);
update(trade, badge);
});

if (!listenerByTrade.containsKey(id)) {
ListChangeListener<ChatMessage> listener = c -> update(trade, badge);
ListChangeListener<ChatMessage> listener = c -> updateChatMessageCount(trade, badge);
listenerByTrade.put(id, listener);
trade.getChatMessages().addListener(listener);
}

update(trade, badge);
updateChatMessageCount(trade, badge);

setGraphic(badge);
} else {
setGraphic(null);
}
}

private void update(Trade trade, JFXBadge badge) {
if (!trade.getId().equals(tradeIdOfOpenChat)) {
updateNewChatMessagesByTradeMap();
long num = newChatMessagesByTradeMap.get(trade.getId());
if (num > 0) {
badge.setText(String.valueOf(num));
badge.setEnabled(true);
} else {
badge.setText("");
badge.setEnabled(false);
}
} else {
badge.setText("");
badge.setEnabled(false);
}
badge.refreshBadge();
}
};
}
});
Expand Down