Add some Swoon blessed packs.

master
Greyson Parrelli 2020-02-10 15:29:15 -05:00
parent 7ecb50a3fe
commit 66a668f55b
6 changed files with 126 additions and 10 deletions

View File

@ -254,6 +254,8 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
SignalStore.registrationValues().onNewInstall();
ApplicationDependencies.getJobManager().add(StickerPackDownloadJob.forInstall(BlessedPacks.ZOZO.getPackId(), BlessedPacks.ZOZO.getPackKey(), false));
ApplicationDependencies.getJobManager().add(StickerPackDownloadJob.forInstall(BlessedPacks.BANDIT.getPackId(), BlessedPacks.BANDIT.getPackKey(), false));
ApplicationDependencies.getJobManager().add(StickerPackDownloadJob.forReference(BlessedPacks.SWOON_HANDS.getPackId(), BlessedPacks.SWOON_HANDS.getPackKey()));
ApplicationDependencies.getJobManager().add(StickerPackDownloadJob.forReference(BlessedPacks.SWOON_FACES.getPackId(), BlessedPacks.SWOON_FACES.getPackKey()));
}
Log.i(TAG, "Setting first install version to " + BuildConfig.CANONICAL_VERSION_CODE);

View File

@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.migrations.MigrationCompleteJob;
import org.thoughtcrime.securesms.migrations.RecipientSearchMigrationJob;
import org.thoughtcrime.securesms.migrations.RegistrationPinV2MigrationJob;
import org.thoughtcrime.securesms.migrations.StickerLaunchMigrationJob;
import org.thoughtcrime.securesms.migrations.StickerAdditionMigrationJob;
import org.thoughtcrime.securesms.migrations.UuidMigrationJob;
import java.util.Arrays;
@ -100,16 +101,17 @@ public final class JobManagerFactories {
put(ProfileUploadJob.KEY, new ProfileUploadJob.Factory());
// Migrations
put(Argon2TestMigrationJob.KEY, new Argon2TestMigrationJob.Factory());
put(AvatarMigrationJob.KEY, new AvatarMigrationJob.Factory());
put(CachedAttachmentsMigrationJob.KEY, new CachedAttachmentsMigrationJob.Factory());
put(DatabaseMigrationJob.KEY, new DatabaseMigrationJob.Factory());
put(LegacyMigrationJob.KEY, new LegacyMigrationJob.Factory());
put(MigrationCompleteJob.KEY, new MigrationCompleteJob.Factory());
put(RecipientSearchMigrationJob.KEY, new RecipientSearchMigrationJob.Factory());
put(StickerLaunchMigrationJob.KEY, new StickerLaunchMigrationJob.Factory());
put(UuidMigrationJob.KEY, new UuidMigrationJob.Factory());
put(RegistrationPinV2MigrationJob.KEY, new RegistrationPinV2MigrationJob.Factory());
put(Argon2TestMigrationJob.KEY, new Argon2TestMigrationJob.Factory());
put(StickerLaunchMigrationJob.KEY, new StickerLaunchMigrationJob.Factory());
put(StickerAdditionMigrationJob.KEY, new StickerAdditionMigrationJob.Factory());
put(UuidMigrationJob.KEY, new UuidMigrationJob.Factory());
// Dead jobs
put("PushContentReceiveJob", new FailingJob.Factory());

View File

@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.stickers.BlessedPacks;
import org.thoughtcrime.securesms.util.Hex;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
@ -101,7 +102,7 @@ public class StickerPackDownloadJob extends BaseJob {
@Override
protected void onRun() throws IOException, InvalidMessageException {
if (isReferencePack && !DatabaseFactory.getAttachmentDatabase(context).containsStickerPackId(packId)) {
if (isReferencePack && !DatabaseFactory.getAttachmentDatabase(context).containsStickerPackId(packId) && !BlessedPacks.contains(packId)) {
Log.w(TAG, "There are no attachments with the requested packId present for this reference pack. Skipping.");
return;
}

View File

@ -12,6 +12,7 @@ import org.greenrobot.eventbus.ThreadMode;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobs.Argon2TestJob;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.stickers.BlessedPacks;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VersionTracker;
@ -39,7 +40,7 @@ public class ApplicationMigrations {
private static final int LEGACY_CANONICAL_VERSION = 455;
public static final int CURRENT_VERSION = 9;
public static final int CURRENT_VERSION = 10;
private static final class Version {
static final int LEGACY = 1;
@ -51,6 +52,7 @@ public class ApplicationMigrations {
static final int CACHED_ATTACHMENTS = 7;
static final int STICKERS_LAUNCH = 8;
static final int TEST_ARGON2 = 9;
static final int SWOON_STICKERS = 10;
}
/**
@ -199,6 +201,10 @@ public class ApplicationMigrations {
jobs.put(Version.TEST_ARGON2, new Argon2TestMigrationJob());
}
if (lastSeenVersion < Version.SWOON_STICKERS) {
jobs.put(Version.SWOON_STICKERS, new StickerAdditionMigrationJob(BlessedPacks.SWOON_HANDS, BlessedPacks.SWOON_FACES));
}
return jobs;
}

View File

@ -0,0 +1,82 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobs.StickerPackDownloadJob;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.stickers.BlessedPacks;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Migration job for installing new blessed packs as references. This means that the packs will
* show up in the list as available blessed packs, but they *won't* be auto-installed.
*/
public class StickerAdditionMigrationJob extends MigrationJob {
public static final String KEY = "StickerInstallMigrationJob";
private static String TAG = Log.tag(StickerAdditionMigrationJob.class);
private static final String KEY_PACKS = "packs";
private final List<BlessedPacks.Pack> packs;
StickerAdditionMigrationJob(@NonNull BlessedPacks.Pack... packs) {
this(new Parameters.Builder().build(), Arrays.asList(packs));
}
private StickerAdditionMigrationJob(@NonNull Parameters parameters, @NonNull List<BlessedPacks.Pack> packs) {
super(parameters);
this.packs = packs;
}
@Override
public boolean isUiBlocking() {
return false;
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public @NonNull Data serialize() {
String[] packsRaw = Stream.of(packs).map(BlessedPacks.Pack::toJson).toArray(String[]::new);
return new Data.Builder().putStringArray(KEY_PACKS, packsRaw).build();
}
@Override
public void performMigration() {
JobManager jobManager = ApplicationDependencies.getJobManager();
for (BlessedPacks.Pack pack : packs) {
Log.i(TAG, "Installing reference for blessed pack: " + pack.getPackId());
jobManager.add(StickerPackDownloadJob.forReference(pack.getPackId(), pack.getPackKey()));
}
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static class Factory implements Job.Factory<StickerAdditionMigrationJob> {
@Override
public @NonNull StickerAdditionMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
String[] raw = data.getStringArray(KEY_PACKS);
List<BlessedPacks.Pack> packs = Stream.of(raw).map(BlessedPacks.Pack::fromJson).toList();
return new StickerAdditionMigrationJob(parameters, packs);
}
}
}

View File

@ -2,6 +2,11 @@ package org.thoughtcrime.securesms.stickers;
import androidx.annotation.NonNull;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.whispersystems.signalservice.internal.util.JsonUtil;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@ -10,12 +15,16 @@ import java.util.Set;
*/
public final class BlessedPacks {
public static final Pack ZOZO = new Pack("fb535407d2f6497ec074df8b9c51dd1d", "17e971c134035622781d2ee249e6473b774583750b68c11bb82b7509c68b6dfd");
public static final Pack BANDIT = new Pack("9acc9e8aba563d26a4994e69263e3b25", "5a6dff3948c28efb9b7aaf93ecc375c69fc316e78077ed26867a14d10a0f6a12");
public static final Pack ZOZO = new Pack("fb535407d2f6497ec074df8b9c51dd1d", "17e971c134035622781d2ee249e6473b774583750b68c11bb82b7509c68b6dfd");
public static final Pack BANDIT = new Pack("9acc9e8aba563d26a4994e69263e3b25", "5a6dff3948c28efb9b7aaf93ecc375c69fc316e78077ed26867a14d10a0f6a12");
public static final Pack SWOON_HANDS = new Pack("e61fa0867031597467ccc036cc65d403", "13ae7b1a7407318280e9b38c1261ded38e0e7138b9f964a6ccbb73e40f737a9b");
public static final Pack SWOON_FACES = new Pack("cca32f5b905208b7d0f1e17f23fdc185", "8bf8e95f7a45bdeafe0c8f5b002ef01ab95b8f1b5baac4019ccd6b6be0b1837a");
private static final Set<String> BLESSED_PACK_IDS = new HashSet<String>() {{
add(ZOZO.getPackId());
add(BANDIT.getPackId());
add(SWOON_HANDS.getPackId());
add(SWOON_FACES.getPackId());
}};
public static boolean contains(@NonNull String packId) {
@ -23,10 +32,12 @@ public final class BlessedPacks {
}
public static class Pack {
private final String packId;
private final String packKey;
@JsonProperty private final String packId;
@JsonProperty private final String packKey;
public Pack(@NonNull String packId, @NonNull String packKey) {
public Pack(@NonNull @JsonProperty("packId") String packId,
@NonNull @JsonProperty("packKey") String packKey)
{
this.packId = packId;
this.packKey = packKey;
}
@ -38,5 +49,17 @@ public final class BlessedPacks {
public @NonNull String getPackKey() {
return packKey;
}
public @NonNull String toJson() {
return JsonUtil.toJson(this);
}
public static @NonNull Pack fromJson(@NonNull String json) {
try {
return JsonUtil.fromJson(json, Pack.class);
} catch (IOException e) {
throw new AssertionError(e);
}
}
}
}