do not synchronize twice when adding status and date bubbles
This commit is contained in:
parent
d8010d7a33
commit
7c35f28633
|
@ -2279,110 +2279,102 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(getActivity(), action, status));
|
this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(getActivity(), action, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateDateSeparators() {
|
|
||||||
synchronized (this.messageList) {
|
|
||||||
DateSeparator.addAll(this.messageList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateStatusMessages() {
|
protected void updateStatusMessages() {
|
||||||
updateDateSeparators();
|
DateSeparator.addAll(this.messageList);
|
||||||
synchronized (this.messageList) {
|
if (showLoadMoreMessages(conversation)) {
|
||||||
if (showLoadMoreMessages(conversation)) {
|
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
|
||||||
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
|
}
|
||||||
}
|
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
ChatState state = conversation.getIncomingChatState();
|
||||||
ChatState state = conversation.getIncomingChatState();
|
if (state == ChatState.COMPOSING) {
|
||||||
if (state == ChatState.COMPOSING) {
|
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName())));
|
||||||
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName())));
|
} else if (state == ChatState.PAUSED) {
|
||||||
} else if (state == ChatState.PAUSED) {
|
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName())));
|
||||||
this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName())));
|
|
||||||
} else {
|
|
||||||
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
||||||
final Message message = this.messageList.get(i);
|
|
||||||
if (message.getType() != Message.TYPE_STATUS) {
|
|
||||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (message.getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
|
||||||
this.messageList.add(i + 1,
|
|
||||||
Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
final MucOptions mucOptions = conversation.getMucOptions();
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
||||||
final List<MucOptions.User> allUsers = mucOptions.getUsers();
|
final Message message = this.messageList.get(i);
|
||||||
final Set<ReadByMarker> addedMarkers = new HashSet<>();
|
if (message.getType() != Message.TYPE_STATUS) {
|
||||||
ChatState state = ChatState.COMPOSING;
|
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||||
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
return;
|
||||||
if (users.size() == 0) {
|
|
||||||
state = ChatState.PAUSED;
|
|
||||||
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
|
||||||
}
|
|
||||||
if (mucOptions.isPrivateAndNonAnonymous()) {
|
|
||||||
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
|
||||||
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
|
|
||||||
final List<MucOptions.User> shownMarkers = new ArrayList<>();
|
|
||||||
for (ReadByMarker marker : markersForMessage) {
|
|
||||||
if (!ReadByMarker.contains(marker, addedMarkers)) {
|
|
||||||
addedMarkers.add(marker); //may be put outside this condition. set should do dedup anyway
|
|
||||||
MucOptions.User user = mucOptions.findUser(marker);
|
|
||||||
if (user != null && !users.contains(user)) {
|
|
||||||
shownMarkers.add(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
|
|
||||||
final Message statusMessage;
|
|
||||||
final int size = shownMarkers.size();
|
|
||||||
if (size > 1) {
|
|
||||||
final String body;
|
|
||||||
if (size <= 4) {
|
|
||||||
body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
|
|
||||||
} else if (ReadByMarker.allUsersRepresented(allUsers, markersForMessage, markerForSender)) {
|
|
||||||
body = getString(R.string.everyone_has_read_up_to_this_point);
|
|
||||||
} else {
|
|
||||||
body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
|
|
||||||
}
|
|
||||||
statusMessage = Message.createStatusMessage(conversation, body);
|
|
||||||
statusMessage.setCounterparts(shownMarkers);
|
|
||||||
} else if (size == 1) {
|
|
||||||
statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
|
|
||||||
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
|
|
||||||
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
|
|
||||||
} else {
|
} else {
|
||||||
statusMessage = null;
|
if (message.getStatus() == Message.STATUS_SEND_DISPLAYED) {
|
||||||
}
|
this.messageList.add(i + 1,
|
||||||
if (statusMessage != null) {
|
Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName())));
|
||||||
this.messageList.add(i + 1, statusMessage);
|
return;
|
||||||
}
|
}
|
||||||
addedMarkers.add(markerForSender);
|
|
||||||
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (users.size() > 0) {
|
|
||||||
Message statusMessage;
|
|
||||||
if (users.size() == 1) {
|
|
||||||
MucOptions.User user = users.get(0);
|
|
||||||
int id = state == ChatState.COMPOSING ? R.string.contact_is_typing : R.string.contact_has_stopped_typing;
|
|
||||||
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.getDisplayName(user)));
|
|
||||||
statusMessage.setTrueCounterpart(user.getRealJid());
|
|
||||||
statusMessage.setCounterpart(user.getFullJid());
|
|
||||||
} else {
|
|
||||||
int id = state == ChatState.COMPOSING ? R.string.contacts_are_typing : R.string.contacts_have_stopped_typing;
|
|
||||||
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.concatNames(users)));
|
|
||||||
statusMessage.setCounterparts(users);
|
|
||||||
}
|
|
||||||
this.messageList.add(statusMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
final MucOptions mucOptions = conversation.getMucOptions();
|
||||||
|
final List<MucOptions.User> allUsers = mucOptions.getUsers();
|
||||||
|
final Set<ReadByMarker> addedMarkers = new HashSet<>();
|
||||||
|
ChatState state = ChatState.COMPOSING;
|
||||||
|
List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
||||||
|
if (users.size() == 0) {
|
||||||
|
state = ChatState.PAUSED;
|
||||||
|
users = conversation.getMucOptions().getUsersWithChatState(state, 5);
|
||||||
|
}
|
||||||
|
if (mucOptions.isPrivateAndNonAnonymous()) {
|
||||||
|
for (int i = this.messageList.size() - 1; i >= 0; --i) {
|
||||||
|
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
|
||||||
|
final List<MucOptions.User> shownMarkers = new ArrayList<>();
|
||||||
|
for (ReadByMarker marker : markersForMessage) {
|
||||||
|
if (!ReadByMarker.contains(marker, addedMarkers)) {
|
||||||
|
addedMarkers.add(marker); //may be put outside this condition. set should do dedup anyway
|
||||||
|
MucOptions.User user = mucOptions.findUser(marker);
|
||||||
|
if (user != null && !users.contains(user)) {
|
||||||
|
shownMarkers.add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
|
||||||
|
final Message statusMessage;
|
||||||
|
final int size = shownMarkers.size();
|
||||||
|
if (size > 1) {
|
||||||
|
final String body;
|
||||||
|
if (size <= 4) {
|
||||||
|
body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
|
||||||
|
} else if (ReadByMarker.allUsersRepresented(allUsers, markersForMessage, markerForSender)) {
|
||||||
|
body = getString(R.string.everyone_has_read_up_to_this_point);
|
||||||
|
} else {
|
||||||
|
body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
|
||||||
|
}
|
||||||
|
statusMessage = Message.createStatusMessage(conversation, body);
|
||||||
|
statusMessage.setCounterparts(shownMarkers);
|
||||||
|
} else if (size == 1) {
|
||||||
|
statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
|
||||||
|
statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
|
||||||
|
statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
|
||||||
|
} else {
|
||||||
|
statusMessage = null;
|
||||||
|
}
|
||||||
|
if (statusMessage != null) {
|
||||||
|
this.messageList.add(i + 1, statusMessage);
|
||||||
|
}
|
||||||
|
addedMarkers.add(markerForSender);
|
||||||
|
if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (users.size() > 0) {
|
||||||
|
Message statusMessage;
|
||||||
|
if (users.size() == 1) {
|
||||||
|
MucOptions.User user = users.get(0);
|
||||||
|
int id = state == ChatState.COMPOSING ? R.string.contact_is_typing : R.string.contact_has_stopped_typing;
|
||||||
|
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.getDisplayName(user)));
|
||||||
|
statusMessage.setTrueCounterpart(user.getRealJid());
|
||||||
|
statusMessage.setCounterpart(user.getFullJid());
|
||||||
|
} else {
|
||||||
|
int id = state == ChatState.COMPOSING ? R.string.contacts_are_typing : R.string.contacts_have_stopped_typing;
|
||||||
|
statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.concatNames(users)));
|
||||||
|
statusMessage.setCounterparts(users);
|
||||||
|
}
|
||||||
|
this.messageList.add(statusMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue