Implement badge gifting behind feature flag.

This commit is contained in:
Alex Hart
2022-05-02 14:29:42 -03:00
committed by Greyson Parrelli
parent 5d16d1cd23
commit a4a4665aaa
164 changed files with 4999 additions and 486 deletions

View File

@@ -7,6 +7,7 @@ import org.thoughtcrime.securesms.database.model.Mention
import org.thoughtcrime.securesms.database.model.ParentStoryId
import org.thoughtcrime.securesms.database.model.StoryType
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge
import org.thoughtcrime.securesms.groups.GroupId
import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.recipients.RecipientId
@@ -37,7 +38,8 @@ class IncomingMediaMessage(
attachments: List<Attachment> = emptyList(),
sharedContacts: List<Contact> = emptyList(),
linkPreviews: List<LinkPreview> = emptyList(),
mentions: List<Mention> = emptyList()
mentions: List<Mention> = emptyList(),
val giftBadge: GiftBadge? = null
) {
val attachments: List<Attachment> = ArrayList(attachments)
@@ -77,7 +79,7 @@ class IncomingMediaMessage(
isViewOnce = viewOnce,
serverGuid = null,
attachments = ArrayList(attachments),
sharedContacts = ArrayList(sharedContacts.orElse(emptyList()))
sharedContacts = ArrayList(sharedContacts.orElse(emptyList())),
)
constructor(
@@ -101,7 +103,8 @@ class IncomingMediaMessage(
linkPreviews: Optional<List<LinkPreview>>,
mentions: Optional<List<Mention>>,
sticker: Optional<Attachment>,
serverGuid: String?
serverGuid: String?,
giftBadge: GiftBadge?
) : this(
from = from,
groupId = if (group.isPresent) GroupUtil.idFromGroupContextOrThrow(group.get()) else null,
@@ -123,6 +126,7 @@ class IncomingMediaMessage(
attachments = PointerAttachment.forPointers(attachments).apply { if (sticker.isPresent) add(sticker.get()) },
sharedContacts = sharedContacts.orElse(emptyList()),
linkPreviews = linkPreviews.orElse(emptyList()),
mentions = mentions.orElse(emptyList())
mentions = mentions.orElse(emptyList()),
giftBadge = giftBadge
)
}

View File

@@ -23,7 +23,8 @@ public class OutgoingExpirationUpdateMessage extends OutgoingSecureMediaMessage
null,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList());
Collections.emptyList(),
null);
}
@Override

View File

@@ -45,7 +45,8 @@ public final class OutgoingGroupUpdateMessage extends OutgoingSecureMediaMessage
quote,
contacts,
previews,
mentions);
mentions,
null);
this.messageGroupContext = groupContext;
}

View File

@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.database.documents.NetworkFailure;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.ParentStoryId;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.Recipient;
@@ -34,6 +35,7 @@ public class OutgoingMediaMessage {
private final StoryType storyType;
private final ParentStoryId parentStoryId;
private final boolean isStoryReaction;
private final GiftBadge giftBadge;
private final Set<NetworkFailure> networkFailures = new HashSet<>();
private final Set<IdentityKeyMismatch> identityKeyMismatches = new HashSet<>();
@@ -57,7 +59,8 @@ public class OutgoingMediaMessage {
@NonNull List<LinkPreview> linkPreviews,
@NonNull List<Mention> mentions,
@NonNull Set<NetworkFailure> networkFailures,
@NonNull Set<IdentityKeyMismatch> identityKeyMismatches)
@NonNull Set<IdentityKeyMismatch> identityKeyMismatches,
@Nullable GiftBadge giftBadge)
{
this.recipient = recipient;
this.body = message;
@@ -71,6 +74,7 @@ public class OutgoingMediaMessage {
this.storyType = storyType;
this.parentStoryId = parentStoryId;
this.isStoryReaction = isStoryReaction;
this.giftBadge = giftBadge;
this.contacts.addAll(contacts);
this.linkPreviews.addAll(linkPreviews);
@@ -93,7 +97,8 @@ public class OutgoingMediaMessage {
@Nullable QuoteModel outgoingQuote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> linkPreviews,
@NonNull List<Mention> mentions)
@NonNull List<Mention> mentions,
@Nullable GiftBadge giftBadge)
{
this(recipient,
buildMessage(slideDeck, message),
@@ -111,7 +116,8 @@ public class OutgoingMediaMessage {
linkPreviews,
mentions,
new HashSet<>(),
new HashSet<>());
new HashSet<>(),
giftBadge);
}
public OutgoingMediaMessage(OutgoingMediaMessage that) {
@@ -127,6 +133,7 @@ public class OutgoingMediaMessage {
this.storyType = that.storyType;
this.parentStoryId = that.parentStoryId;
this.isStoryReaction = that.isStoryReaction;
this.giftBadge = that.giftBadge;
this.identityKeyMismatches.addAll(that.identityKeyMismatches);
this.networkFailures.addAll(that.networkFailures);
@@ -153,7 +160,8 @@ public class OutgoingMediaMessage {
linkPreviews,
mentions,
networkFailures,
identityKeyMismatches
identityKeyMismatches,
giftBadge
);
}
@@ -237,6 +245,10 @@ public class OutgoingMediaMessage {
return identityKeyMismatches;
}
public @Nullable GiftBadge getGiftBadge() {
return giftBadge;
}
private static String buildMessage(SlideDeck slideDeck, String message) {
if (!TextUtils.isEmpty(message) && !TextUtils.isEmpty(slideDeck.getBody())) {
return slideDeck.getBody() + "\n\n" + message;

View File

@@ -8,6 +8,7 @@ import org.thoughtcrime.securesms.contactshare.Contact;
import org.thoughtcrime.securesms.database.model.Mention;
import org.thoughtcrime.securesms.database.model.ParentStoryId;
import org.thoughtcrime.securesms.database.model.StoryType;
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.recipients.Recipient;
@@ -29,9 +30,10 @@ public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
@Nullable QuoteModel quote,
@NonNull List<Contact> contacts,
@NonNull List<LinkPreview> previews,
@NonNull List<Mention> mentions)
@NonNull List<Mention> mentions,
@Nullable GiftBadge giftBadge)
{
super(recipient, body, attachments, sentTimeMillis, -1, expiresIn, viewOnce, distributionType, storyType, parentStoryId, isStoryReaction, quote, contacts, previews, mentions, Collections.emptySet(), Collections.emptySet());
super(recipient, body, attachments, sentTimeMillis, -1, expiresIn, viewOnce, distributionType, storyType, parentStoryId, isStoryReaction, quote, contacts, previews, mentions, Collections.emptySet(), Collections.emptySet(), giftBadge);
}
public OutgoingSecureMediaMessage(OutgoingMediaMessage base) {
@@ -58,7 +60,8 @@ public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
getOutgoingQuote(),
getSharedContacts(),
getLinkPreviews(),
getMentions());
getMentions(),
getGiftBadge());
}
public @NonNull OutgoingSecureMediaMessage withSentTimestamp(long sentTimestamp) {
@@ -75,6 +78,7 @@ public class OutgoingSecureMediaMessage extends OutgoingMediaMessage {
getOutgoingQuote(),
getSharedContacts(),
getLinkPreviews(),
getMentions());
getMentions(),
getGiftBadge());
}
}

View File

@@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.giph.model.ChunkedImageUrl;
import org.thoughtcrime.securesms.glide.BadgeLoader;
import org.thoughtcrime.securesms.glide.ChunkedImageUrlLoader;
import org.thoughtcrime.securesms.glide.ContactPhotoLoader;
import org.thoughtcrime.securesms.glide.GiftBadgeModel;
import org.thoughtcrime.securesms.glide.OkHttpUrlLoader;
import org.thoughtcrime.securesms.glide.cache.ApngBufferCacheDecoder;
import org.thoughtcrime.securesms.glide.cache.ApngFrameDrawableTranscoder;
@@ -90,6 +91,7 @@ public class SignalGlideComponents implements RegisterGlideComponents {
registry.append(StickerRemoteUri.class, InputStream.class, new StickerRemoteUriLoader.Factory());
registry.append(BlurHash.class, BlurHash.class, new BlurHashModelLoader.Factory());
registry.append(Badge.class, InputStream.class, BadgeLoader.createFactory());
registry.append(GiftBadgeModel.class, InputStream.class, GiftBadgeModel.createFactory());
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
}