Handle nullable sticker emoji.

This commit is contained in:
Greyson Parrelli
2026-09-15 18:26:03 -04:00
parent cf386353c4
commit aec7c5eaa2
6 changed files with 39 additions and 11 deletions
@@ -171,7 +171,7 @@ class StickerTables(
val values = contentValuesOf(
Sticker.PACK_ID to sticker.packId,
Sticker.STICKER_ID to sticker.stickerId,
Sticker.EMOJI to sticker.emoji,
Sticker.EMOJI to (sticker.emoji ?: ""),
Sticker.CONTENT_TYPE to sticker.contentType,
Sticker.COVER to if (sticker.isCover) 1 else 0,
Sticker.FILE_PATH to fileInfo.file.absolutePath,
@@ -6,7 +6,7 @@ data class IncomingSticker(
val packTitle: String,
val packAuthor: String,
val stickerId: Int,
val emoji: String,
val emoji: String?,
val contentType: String?,
val isCover: Boolean,
val isInstalled: Boolean
@@ -69,11 +69,11 @@ public final class StickerManifest {
private final String contentType;
private final Optional<Uri> uri;
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji, @Nullable String contentType) {
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @Nullable String emoji, @Nullable String contentType) {
this(packId, packKey, id, emoji, contentType, null);
}
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji, @Nullable String contentType, @Nullable Uri uri) {
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @Nullable String emoji, @Nullable String contentType, @Nullable Uri uri) {
this.packId = packId;
this.packKey = packKey;
this.id = id;
@@ -94,7 +94,7 @@ public final class StickerManifest {
return id;
}
public String getEmoji() {
public @Nullable String getEmoji() {
return emoji;
}
@@ -100,7 +100,7 @@ public class StickerRolloverTouchListener implements RecyclerView.OnItemTouchLis
}
}
private void showSticker(@NonNull RecyclerView recyclerView, @NonNull Object toLoad, @NonNull String emoji) {
private void showSticker(@NonNull RecyclerView recyclerView, @NonNull Object toLoad, @Nullable String emoji) {
if (!popup.isShowing()) {
popup.showAtLocation(recyclerView, Gravity.NO_GRAVITY, 0, 0);
eventListener.onStickerPopupStarted();
@@ -266,6 +266,28 @@ class StickerTablesTest {
assertThat(installedPackIds()).isEqualTo(listOf(packId1, packId3, packId2))
}
@Test
fun `given a sticker with no emoji, when I insert it, then I expect an empty emoji`() {
installPack(packId1, packKey1)
insertSticker(packId1, packKey1, stickerId = 1, emoji = null)
assertThat(SignalDatabase.stickers.getSticker(packId1, 1, false)!!.emoji).isEqualTo("")
}
@Test
fun `given a sticker with no emoji, when I search by emoji, then I expect only the sticker that has one`() {
installPack(packId1, packKey1)
insertSticker(packId1, packKey1, stickerId = 1, emoji = null)
insertSticker(packId1, packKey1, stickerId = 2, emoji = "\uD83D\uDC4D")
val results = StickerTables.StickerRecordReader(SignalDatabase.stickers.getStickersByEmoji("\uD83D\uDC4D")).use { reader ->
generateSequence { reader.getNext() }.map { it.stickerId }.toList()
}
assertThat(results).isEqualTo(listOf(2))
}
private fun installedPackIds(): List<String> {
return StickerTables.StickerPackRecordReader(SignalDatabase.stickers.getInstalledStickerPacks()).use { reader ->
reader.asSequence().map { it.packId }.toList()
@@ -273,16 +295,20 @@ class StickerTablesTest {
}
private fun installPack(packId: String, packKey: String) {
insertSticker(packId, packKey, stickerId = 0, emoji = "", isCover = true)
}
private fun insertSticker(packId: String, packKey: String, stickerId: Int, emoji: String?, isCover: Boolean = false) {
SignalDatabase.stickers.insertSticker(
sticker = IncomingSticker(
packId = packId,
packKey = packKey,
packTitle = "Title",
packAuthor = "Author",
stickerId = 0,
emoji = "",
stickerId = stickerId,
emoji = emoji,
contentType = "image/webp",
isCover = true,
isCover = isCover,
isInstalled = true
),
dataStream = ByteArrayInputStream(byteArrayOf(1, 2, 3, 4)),
@@ -2,6 +2,8 @@ package org.whispersystems.signalservice.api.messages;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -42,7 +44,7 @@ public class SignalServiceStickerManifest {
private final String emoji;
private final String contentType;
public StickerInfo(int id, String emoji, String contentType) {
public StickerInfo(int id, @Nullable String emoji, String contentType) {
this.id = id;
this.emoji = emoji;
this.contentType = contentType;
@@ -52,7 +54,7 @@ public class SignalServiceStickerManifest {
return id;
}
public String getEmoji() {
public @Nullable String getEmoji() {
return emoji;
}