mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-07 23:08:33 +00:00
Fix mention parsing for quotes.
This commit is contained in:
parent
97eb9154b2
commit
e2cfd247c3
@ -347,7 +347,7 @@ public final class SignalServiceContent {
|
|||||||
SignalServiceDataMessage.Quote quote = createQuote(content);
|
SignalServiceDataMessage.Quote quote = createQuote(content);
|
||||||
List<SharedContact> sharedContacts = createSharedContacts(content);
|
List<SharedContact> sharedContacts = createSharedContacts(content);
|
||||||
List<SignalServiceDataMessage.Preview> previews = createPreviews(content);
|
List<SignalServiceDataMessage.Preview> previews = createPreviews(content);
|
||||||
List<SignalServiceDataMessage.Mention> mentions = createMentions(content);
|
List<SignalServiceDataMessage.Mention> mentions = createMentions(content.getBodyRangesList(), content.getBody());
|
||||||
SignalServiceDataMessage.Sticker sticker = createSticker(content);
|
SignalServiceDataMessage.Sticker sticker = createSticker(content);
|
||||||
SignalServiceDataMessage.Reaction reaction = createReaction(content);
|
SignalServiceDataMessage.Reaction reaction = createReaction(content);
|
||||||
SignalServiceDataMessage.RemoteDelete remoteDelete = createRemoteDelete(content);
|
SignalServiceDataMessage.RemoteDelete remoteDelete = createRemoteDelete(content);
|
||||||
@ -665,7 +665,7 @@ public final class SignalServiceContent {
|
|||||||
address,
|
address,
|
||||||
content.getQuote().getText(),
|
content.getQuote().getText(),
|
||||||
attachments,
|
attachments,
|
||||||
createMentions(content));
|
createMentions(content.getQuote().getBodyRangesList(), content.getQuote().getText()));
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Quote was missing an author! Returning null.");
|
Log.w(TAG, "Quote was missing an author! Returning null.");
|
||||||
return null;
|
return null;
|
||||||
@ -694,15 +694,17 @@ public final class SignalServiceContent {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<SignalServiceDataMessage.Mention> createMentions(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
|
private static List<SignalServiceDataMessage.Mention> createMentions(List<SignalServiceProtos.DataMessage.BodyRange> bodyRanges, String body) throws ProtocolInvalidMessageException {
|
||||||
if (content.getBodyRangesCount() <= 0 || !content.hasBody()) return null;
|
if (bodyRanges == null || bodyRanges.isEmpty() || body == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
List<SignalServiceDataMessage.Mention> mentions = new LinkedList<>();
|
List<SignalServiceDataMessage.Mention> mentions = new LinkedList<>();
|
||||||
|
|
||||||
for (SignalServiceProtos.DataMessage.BodyRange bodyRange : content.getBodyRangesList()) {
|
for (SignalServiceProtos.DataMessage.BodyRange bodyRange : bodyRanges) {
|
||||||
if (bodyRange.hasMentionUuid()) {
|
if (bodyRange.hasMentionUuid()) {
|
||||||
try {
|
try {
|
||||||
validateBodyRange(content, bodyRange);
|
validateBodyRange(body, bodyRange);
|
||||||
mentions.add(new SignalServiceDataMessage.Mention(UuidUtil.parseOrThrow(bodyRange.getMentionUuid()), bodyRange.getStart(), bodyRange.getLength()));
|
mentions.add(new SignalServiceDataMessage.Mention(UuidUtil.parseOrThrow(bodyRange.getMentionUuid()), bodyRange.getStart(), bodyRange.getLength()));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new ProtocolInvalidMessageException(new InvalidMessageException(e), null, 0);
|
throw new ProtocolInvalidMessageException(new InvalidMessageException(e), null, 0);
|
||||||
@ -713,8 +715,8 @@ public final class SignalServiceContent {
|
|||||||
return mentions;
|
return mentions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void validateBodyRange(SignalServiceProtos.DataMessage content, SignalServiceProtos.DataMessage.BodyRange bodyRange) throws ProtocolInvalidMessageException {
|
private static void validateBodyRange(String body, SignalServiceProtos.DataMessage.BodyRange bodyRange) throws ProtocolInvalidMessageException {
|
||||||
int incomingBodyLength = content.hasBody() ? content.getBody().length() : -1;
|
int incomingBodyLength = body != null ? body.length() : -1;
|
||||||
int start = bodyRange.hasStart() ? bodyRange.getStart() : -1;
|
int start = bodyRange.hasStart() ? bodyRange.getStart() : -1;
|
||||||
int length = bodyRange.hasLength() ? bodyRange.getLength() : -1;
|
int length = bodyRange.hasLength() ? bodyRange.getLength() : -1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user