Show sticker emoji in notification.

master
Greyson Parrelli 2020-09-03 10:02:33 -04:00 committed by Cody Henthorne
parent 12dfcaf7e7
commit 2fd46b196b
11 changed files with 77 additions and 20 deletions

View File

@ -2876,7 +2876,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
}
private void sendSticker(@NonNull StickerRecord stickerRecord, boolean clearCompose) {
sendSticker(new StickerLocator(stickerRecord.getPackId(), stickerRecord.getPackKey(), stickerRecord.getStickerId()), stickerRecord.getContentType(), stickerRecord.getUri(), stickerRecord.getSize(), clearCompose);
sendSticker(new StickerLocator(stickerRecord.getPackId(), stickerRecord.getPackKey(), stickerRecord.getStickerId(), stickerRecord.getEmoji()), stickerRecord.getContentType(), stickerRecord.getUri(), stickerRecord.getSize(), clearCompose);
SignalExecutors.BOUNDED.execute(() ->
DatabaseFactory.getStickerDatabase(getApplicationContext())

View File

@ -118,6 +118,7 @@ public class AttachmentDatabase extends Database {
public static final String STICKER_PACK_ID = "sticker_pack_id";
public static final String STICKER_PACK_KEY = "sticker_pack_key";
static final String STICKER_ID = "sticker_id";
static final String STICKER_EMOJI = "sticker_emoji";
static final String FAST_PREFLIGHT_ID = "fast_preflight_id";
public static final String DATA_RANDOM = "data_random";
private static final String THUMBNAIL_RANDOM = "thumbnail_random";
@ -150,7 +151,7 @@ public class AttachmentDatabase extends Database {
THUMBNAIL_ASPECT_RATIO, UNIQUE_ID, DIGEST,
FAST_PREFLIGHT_ID, VOICE_NOTE, BORDERLESS, QUOTE, DATA_RANDOM,
THUMBNAIL_RANDOM, WIDTH, HEIGHT, CAPTION, STICKER_PACK_ID,
STICKER_PACK_KEY, STICKER_ID, DATA_HASH, VISUAL_HASH,
STICKER_PACK_KEY, STICKER_ID, STICKER_EMOJI, DATA_HASH, VISUAL_HASH,
TRANSFORM_PROPERTIES, TRANSFER_FILE, DISPLAY_ORDER,
UPLOAD_TIMESTAMP };
@ -187,6 +188,7 @@ public class AttachmentDatabase extends Database {
STICKER_PACK_ID + " TEXT DEFAULT NULL, " +
STICKER_PACK_KEY + " DEFAULT NULL, " +
STICKER_ID + " INTEGER DEFAULT -1, " +
STICKER_EMOJI + " STRING DEFAULT NULL, " +
DATA_HASH + " TEXT DEFAULT NULL, " +
VISUAL_HASH + " TEXT DEFAULT NULL, " +
TRANSFORM_PROPERTIES + " TEXT DEFAULT NULL, " +
@ -1196,7 +1198,8 @@ public class AttachmentDatabase extends Database {
object.getInt(STICKER_ID) >= 0
? new StickerLocator(object.getString(STICKER_PACK_ID),
object.getString(STICKER_PACK_KEY),
object.getInt(STICKER_ID))
object.getInt(STICKER_ID),
object.getString(STICKER_EMOJI))
: null,
MediaUtil.isAudioType(contentType) ? null : BlurHash.parseOrNull(object.getString(VISUAL_HASH)),
MediaUtil.isAudioType(contentType) ? AudioHash.parseOrNull(object.getString(VISUAL_HASH)) : null,
@ -1231,9 +1234,10 @@ public class AttachmentDatabase extends Database {
cursor.getInt(cursor.getColumnIndexOrThrow(QUOTE)) == 1,
cursor.getString(cursor.getColumnIndexOrThrow(CAPTION)),
cursor.getInt(cursor.getColumnIndexOrThrow(STICKER_ID)) >= 0
? new StickerLocator(cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_ID)),
cursor.getString(cursor.getColumnIndexOrThrow(STICKER_PACK_KEY)),
cursor.getInt(cursor.getColumnIndexOrThrow(STICKER_ID)))
? new StickerLocator(CursorUtil.requireString(cursor, STICKER_PACK_ID),
CursorUtil.requireString(cursor, STICKER_PACK_KEY),
CursorUtil.requireInt(cursor, STICKER_ID),
CursorUtil.requireString(cursor, STICKER_EMOJI))
: null,
MediaUtil.isAudioType(contentType) ? null : BlurHash.parseOrNull(cursor.getString(cursor.getColumnIndexOrThrow(VISUAL_HASH))),
MediaUtil.isAudioType(contentType) ? AudioHash.parseOrNull(cursor.getString(cursor.getColumnIndexOrThrow(VISUAL_HASH))) : null,
@ -1311,6 +1315,7 @@ public class AttachmentDatabase extends Database {
contentValues.put(STICKER_PACK_ID, attachment.getSticker().getPackId());
contentValues.put(STICKER_PACK_KEY, attachment.getSticker().getPackKey());
contentValues.put(STICKER_ID, attachment.getSticker().getStickerId());
contentValues.put(STICKER_EMOJI, attachment.getSticker().getEmoji());
}
if (dataInfo != null) {

View File

@ -44,6 +44,7 @@ public class MediaDatabase extends Database {
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_ID + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_KEY + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_ID + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_EMOJI + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.VISUAL_HASH + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.TRANSFORM_PROPERTIES + ", "
+ AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.DISPLAY_ORDER + ", "

View File

@ -234,6 +234,7 @@ public class MmsDatabase extends MessageDatabase {
"'" + AttachmentDatabase.STICKER_PACK_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_ID+ ", " +
"'" + AttachmentDatabase.STICKER_PACK_KEY + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_KEY + ", " +
"'" + AttachmentDatabase.STICKER_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_ID + ", " +
"'" + AttachmentDatabase.STICKER_EMOJI + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_EMOJI + ", " +
"'" + AttachmentDatabase.VISUAL_HASH + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.VISUAL_HASH + ", " +
"'" + AttachmentDatabase.TRANSFORM_PROPERTIES + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.TRANSFORM_PROPERTIES + ", " +
"'" + AttachmentDatabase.DISPLAY_ORDER + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.DISPLAY_ORDER + ", " +

View File

@ -393,6 +393,7 @@ public class MmsSmsDatabase extends Database {
"'" + AttachmentDatabase.STICKER_PACK_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_ID + ", " +
"'" + AttachmentDatabase.STICKER_PACK_KEY + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_PACK_KEY + ", " +
"'" + AttachmentDatabase.STICKER_ID + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_ID + ", " +
"'" + AttachmentDatabase.STICKER_EMOJI + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.STICKER_EMOJI + ", " +
"'" + AttachmentDatabase.VISUAL_HASH + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.VISUAL_HASH + ", " +
"'" + AttachmentDatabase.TRANSFORM_PROPERTIES + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.TRANSFORM_PROPERTIES + ", " +
"'" + AttachmentDatabase.DISPLAY_ORDER + "', " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.DISPLAY_ORDER + ", " +

View File

@ -4,9 +4,11 @@ import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.Emoji;
import org.thoughtcrime.securesms.components.emoji.EmojiStrings;
import org.thoughtcrime.securesms.contactshare.Contact;
import org.thoughtcrime.securesms.contactshare.ContactUtil;
@ -15,7 +17,11 @@ import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.GifSlide;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.StickerSlide;
import org.thoughtcrime.securesms.util.MessageRecordUtil;
import org.thoughtcrime.securesms.util.Util;
import java.util.Objects;
public final class ThreadBodyUtil {
@ -42,7 +48,8 @@ public final class ThreadBodyUtil {
} else if (record.getSlideDeck().getAudioSlide() != null) {
return format(context, record, EmojiStrings.AUDIO, R.string.ThreadRecord_voice_message);
} else if (MessageRecordUtil.hasSticker(record)) {
return format(context, record, EmojiStrings.STICKER, R.string.ThreadRecord_sticker);
String emoji = getStickerEmoji(record);
return format(context, record, emoji, R.string.ThreadRecord_sticker);
}
boolean hasImage = false;
@ -81,4 +88,11 @@ public final class ThreadBodyUtil {
private static @NonNull String getBody(@NonNull Context context, @NonNull MessageRecord record) {
return MentionUtil.updateBodyWithDisplayNames(context, record, record.getBody()).toString();
}
private static @NonNull String getStickerEmoji(@NonNull MessageRecord record) {
StickerSlide slide = Objects.requireNonNull(((MmsMessageRecord) record).getSlideDeck().getStickerSlide());
return Util.isEmpty(slide.getEmoji()) ? EmojiStrings.STICKER
: slide.getEmoji();
}
}

View File

@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.mms.StickerSlide;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientDetails;
import org.thoughtcrime.securesms.recipients.RecipientId;
@ -67,6 +68,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@ -1109,7 +1111,8 @@ public class ThreadDatabase extends Database {
} else if (record.isRemoteDelete()) {
return Extra.forRemoteDelete();
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
return Extra.forSticker();
StickerSlide slide = Objects.requireNonNull(((MmsMessageRecord) record).getSlideDeck().getStickerSlide());
return Extra.forSticker(slide.getEmoji());
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() > 1) {
return Extra.forAlbum();
}
@ -1275,6 +1278,7 @@ public class ThreadDatabase extends Database {
@JsonProperty private final boolean isRevealable;
@JsonProperty private final boolean isSticker;
@JsonProperty private final String stickerEmoji;
@JsonProperty private final boolean isAlbum;
@JsonProperty private final boolean isRemoteDelete;
@JsonProperty private final boolean isMessageRequestAccepted;
@ -1283,6 +1287,7 @@ public class ThreadDatabase extends Database {
public Extra(@JsonProperty("isRevealable") boolean isRevealable,
@JsonProperty("isSticker") boolean isSticker,
@JsonProperty("stickerEmoji") String stickerEmoji,
@JsonProperty("isAlbum") boolean isAlbum,
@JsonProperty("isRemoteDelete") boolean isRemoteDelete,
@JsonProperty("isMessageRequestAccepted") boolean isMessageRequestAccepted,
@ -1291,6 +1296,7 @@ public class ThreadDatabase extends Database {
{
this.isRevealable = isRevealable;
this.isSticker = isSticker;
this.stickerEmoji = stickerEmoji;
this.isAlbum = isAlbum;
this.isRemoteDelete = isRemoteDelete;
this.isMessageRequestAccepted = isMessageRequestAccepted;
@ -1299,31 +1305,31 @@ public class ThreadDatabase extends Database {
}
public static @NonNull Extra forViewOnce() {
return new Extra(true, false, false, false, true, false, null);
return new Extra(true, false, null, false, false, true, false, null);
}
public static @NonNull Extra forSticker() {
return new Extra(false, true, false, false, true, false, null);
public static @NonNull Extra forSticker(@Nullable String emoji) {
return new Extra(false, true, emoji, false, false, true, false, null);
}
public static @NonNull Extra forAlbum() {
return new Extra(false, false, true, false, true, false, null);
return new Extra(false, false, null, true, false, true, false, null);
}
public static @NonNull Extra forRemoteDelete() {
return new Extra(false, false, false, true, true, false, null);
return new Extra(false, false, null, false, true, true, false, null);
}
public static @NonNull Extra forMessageRequest() {
return new Extra(false, false, false, false, false, false, null);
return new Extra(false, false, null, false, false, false, false, null);
}
public static @NonNull Extra forGroupMessageRequest(RecipientId recipientId) {
return new Extra(false, false, false, false, false, false, recipientId.serialize());
return new Extra(false, false, null, false, false, false, false, recipientId.serialize());
}
public static @NonNull Extra forGroupV2invite(RecipientId recipientId) {
return new Extra(false, false, false, false, false, true, recipientId.serialize());
return new Extra(false, false, null, false, false, false, true, recipientId.serialize());
}
public boolean isViewOnce() {
@ -1334,6 +1340,10 @@ public class ThreadDatabase extends Database {
return isSticker;
}
public @Nullable String getStickerEmoji() {
return stickerEmoji;
}
public boolean isAlbum() {
return isAlbum;
}

View File

@ -145,8 +145,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int MENTION_GLOBAL_SETTING_MIGRATION = 70;
private static final int UNKNOWN_STORAGE_FIELDS = 71;
private static final int STICKER_CONTENT_TYPE = 72;
private static final int STICKER_EMOJI_IN_NOTIFICATIONS = 73;
private static final int DATABASE_VERSION = 72;
private static final int DATABASE_VERSION = 73;
private static final String DATABASE_NAME = "signal.db";
private final Context context;
@ -1018,6 +1019,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE sticker ADD COLUMN content_type TEXT DEFAULT NULL");
}
if (oldVersion < STICKER_EMOJI_IN_NOTIFICATIONS) {
db.execSQL("ALTER TABLE part ADD COLUMN sticker_emoji TEXT DEFAULT NULL");
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();

View File

@ -1660,7 +1660,8 @@ public final class PushProcessMessageJob extends BaseJob {
String packId = Hex.toStringCondensed(sticker.get().getPackId());
String packKey = Hex.toStringCondensed(sticker.get().getPackKey());
int stickerId = sticker.get().getStickerId();
StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId);
String emoji = sticker.get().getEmoji();
StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId, emoji);
StickerDatabase stickerDatabase = DatabaseFactory.getStickerDatabase(context);
StickerRecord stickerRecord = stickerDatabase.getSticker(stickerLocator.getPackId(), stickerLocator.getStickerId(), false);

View File

@ -13,17 +13,23 @@ import org.thoughtcrime.securesms.blurhash.BlurHash;
import org.thoughtcrime.securesms.stickers.StickerLocator;
import org.thoughtcrime.securesms.util.MediaUtil;
import java.util.Objects;
public class StickerSlide extends Slide {
public static final int WIDTH = 512;
public static final int HEIGHT = 512;
private final StickerLocator stickerLocator;
public StickerSlide(@NonNull Context context, @NonNull Attachment attachment) {
super(context, attachment);
this.stickerLocator = Objects.requireNonNull(attachment.getSticker());
}
public StickerSlide(Context context, Uri uri, long size, @NonNull StickerLocator stickerLocator, @NonNull String contentType) {
super(context, constructAttachmentFromUri(context, uri, contentType, size, WIDTH, HEIGHT, true, null, null, stickerLocator, null, null, false, false, false));
this.stickerLocator = Objects.requireNonNull(attachment.getSticker());
}
@Override
@ -50,4 +56,8 @@ public class StickerSlide extends Slide {
public @NonNull String getContentDescription() {
return context.getString(R.string.Slide_sticker);
}
public @Nullable String getEmoji() {
return stickerLocator.getEmoji();
}
}

View File

@ -3,23 +3,27 @@ package org.thoughtcrime.securesms.stickers;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class StickerLocator implements Parcelable {
private final String packId;
private final String packKey;
private final int stickerId;
private final String emoji;
public StickerLocator(@NonNull String packId, @NonNull String packKey, int stickerId) {
public StickerLocator(@NonNull String packId, @NonNull String packKey, int stickerId, @Nullable String emoji) {
this.packId = packId;
this.packKey = packKey;
this.stickerId = stickerId;
this.emoji = emoji;
}
private StickerLocator(Parcel in) {
packId = in.readString();
packKey = in.readString();
stickerId = in.readInt();
emoji = in.readString();
}
public @NonNull String getPackId() {
@ -30,10 +34,14 @@ public class StickerLocator implements Parcelable {
return packKey;
}
public @NonNull int getStickerId() {
public int getStickerId() {
return stickerId;
}
public @Nullable String getEmoji() {
return emoji;
}
@Override
public int describeContents() {
return 0;
@ -44,6 +52,7 @@ public class StickerLocator implements Parcelable {
dest.writeString(packId);
dest.writeString(packKey);
dest.writeInt(stickerId);
dest.writeString(emoji);
}
public static final Creator<StickerLocator> CREATOR = new Creator<StickerLocator>() {