Skip to content

Commit

Permalink
'#2337: Review WhatsApp Message compareTo() to avoid exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Oct 15, 2024
1 parent cdb5ebe commit 61efb96
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) {
}

public long getSortId() {
return sortId;
return sortId == 0 ? id : sortId;
}

public void setSortId(long sortId) {
Expand Down Expand Up @@ -690,18 +690,14 @@ public static enum MessageQuotedType {

@Override
public int compareTo(Message o) {
if (getSortId() != 0 && o.getSortId() != 0) {
int comp = Long.compare(getSortId(), o.getSortId());
if (comp != 0) {
return comp;
}
int comp = Long.compare(getSortId(), o.getSortId());
if (comp != 0) {
return comp;
}
if (getTimeStamp() != null && o.getTimeStamp() != null) {
int comp = getTimeStamp().compareTo(o.getTimeStamp());
if (comp != 0) {
return comp;
}
}
return Long.compare(getId(), o.getId());
return Long.compare(getTime(), o.getTime());
}

private long getTime() {
return timeStamp == null ? 0 : timeStamp.getTime();
}
}

0 comments on commit 61efb96

Please sign in to comment.