Correctly handle invalid conversation ID

This commit is contained in:
Alibek Omarov 2020-02-03 13:33:52 +03:00
parent 9cc251deaa
commit d58a80f498
1 changed files with 17 additions and 8 deletions

View File

@ -327,14 +327,23 @@ public class NotificationsFragment extends SFragment implements
private void handleMuteStatusEvent(MuteStatusEvent event) {
Pair<Integer, Notification> posAndNotification = findReplyPosition(event.getStatusId());
if (posAndNotification == null) return;
//noinspection ConstantConditions
// using iterator to safely remove items while iterating
for (int i = 0; i < notifications.size(); i++) {
Notification notification = notifications.get(i).asRightOrNull();
if (notification != null && notification.getStatus() != null
&& notification.getType() == Notification.Type.MENTION) {
setMutedStatusForStatus(i, notification.getStatus(), event.getMute());
if (posAndNotification == null)
return;
int conversaionId = posAndNotification.second.getStatus().getConversationId();
if(conversationId == -1) { // invalid conversation ID
setMutedStatusForStatus(posAndNotification.first, posAndNotification.second.getStatus(), event.getMute());
} else {
//noinspection ConstantConditions
// using iterator to safely remove items while iterating
for (int i = 0; i < notifications.size(); i++) {
Notification notification = notifications.get(i).asRightOrNull();
if (notification != null && notification.getStatus() != null
&& notification.getType() == Notification.Type.MENTION &&
notification.getStatus().getConversationId() == conversaionId) {
setMutedStatusForStatus(i, notification.getStatus(), event.getMute());
}
}
}
updateAdapter();