Add support for replying to gift badges.

This commit is contained in:
Alex Hart
2022-05-10 10:10:35 -03:00
parent 0c1edd6a56
commit 8ca0f4baf4
22 changed files with 247 additions and 54 deletions

View File

@@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import java.util.Collections;
import java.util.List;
@@ -19,14 +20,23 @@ public class QuoteModel {
private final boolean missing;
private final List<Attachment> attachments;
private final List<Mention> mentions;
private final Type type;
public QuoteModel(long id, @NonNull RecipientId author, String text, boolean missing, @Nullable List<Attachment> attachments, @Nullable List<Mention> mentions) {
public QuoteModel(long id,
@NonNull RecipientId author,
String text,
boolean missing,
@Nullable List<Attachment> attachments,
@Nullable List<Mention> mentions,
@NonNull Type type)
{
this.id = id;
this.author = author;
this.text = text;
this.missing = missing;
this.attachments = attachments;
this.mentions = mentions != null ? mentions : Collections.emptyList();
this.type = type;
}
public long getId() {
@@ -52,4 +62,49 @@ public class QuoteModel {
public @NonNull List<Mention> getMentions() {
return mentions;
}
public Type getType() {
return type;
}
public enum Type {
NORMAL(0, SignalServiceDataMessage.Quote.Type.NORMAL),
GIFT_BADGE(1, SignalServiceDataMessage.Quote.Type.GIFT_BADGE);
private final int code;
private final SignalServiceDataMessage.Quote.Type dataMessageType;
Type(int code, @NonNull SignalServiceDataMessage.Quote.Type dataMessageType) {
this.code = code;
this.dataMessageType = dataMessageType;
}
public int getCode() {
return code;
}
public @NonNull SignalServiceDataMessage.Quote.Type getDataMessageType() {
return dataMessageType;
}
public static Type fromCode(int code) {
for (final Type value : values()) {
if (value.code == code) {
return value;
}
}
throw new IllegalArgumentException("Invalid code: " + code);
}
public static Type fromDataMessageType(@NonNull SignalServiceDataMessage.Quote.Type dataMessageType) {
for (final Type value : values()) {
if (value.dataMessageType == dataMessageType) {
return value;
}
}
return NORMAL;
}
}
}