Fix editing custom reactions.

This commit is contained in:
Michelle Tang
2025-01-24 11:06:36 -05:00
committed by Greyson Parrelli
parent 8be946e43f
commit f65cebdada
2 changed files with 9 additions and 3 deletions

View File

@@ -72,6 +72,10 @@ public class EmojiValues extends SignalStoreValues {
return getString(PREFIX + canonical, emoji); return getString(PREFIX + canonical, emoji);
} }
public void removePreferredVariation(@NonNull String emoji) {
getStore().beginWrite().remove(PREFIX + emoji).apply();
}
/** /**
* Returns a list usable emoji that the user has selected as their defaults. If any stored reactions are unreadable, it will provide a default. * Returns a list usable emoji that the user has selected as their defaults. If any stored reactions are unreadable, it will provide a default.
* For raw access to the unfiltered list of reactions, see {@link #getRawReactions()}. * For raw access to the unfiltered list of reactions, see {@link #getRawReactions()}.

View File

@@ -27,9 +27,7 @@ class EditReactionsViewModel : ViewModel() {
fun onEmojiSelected(emoji: String) { fun onEmojiSelected(emoji: String) {
store.update { state -> store.update { state ->
if (state.selection != NO_SELECTION && state.selection in state.reactions.indices) { if (state.selection != NO_SELECTION && state.selection in state.reactions.indices) {
if (emoji != EmojiUtil.getCanonicalRepresentation(emoji)) { emojiValues.setPreferredVariation(emoji)
emojiValues.setPreferredVariation(emoji)
}
val preferredEmoji: String = emojiValues.getPreferredVariation(emoji) val preferredEmoji: String = emojiValues.getPreferredVariation(emoji)
val newReactions: List<String> = state.reactions.toMutableList().apply { set(state.selection, preferredEmoji) } val newReactions: List<String> = state.reactions.toMutableList().apply { set(state.selection, preferredEmoji) }
state.copy(reactions = newReactions) state.copy(reactions = newReactions)
@@ -40,6 +38,10 @@ class EditReactionsViewModel : ViewModel() {
} }
fun resetToDefaults() { fun resetToDefaults() {
EmojiValues.DEFAULT_REACTIONS_LIST.forEach { emoji ->
emojiValues.removePreferredVariation(EmojiUtil.getCanonicalRepresentation(emoji))
}
store.update { it.copy(reactions = EmojiValues.DEFAULT_REACTIONS_LIST) } store.update { it.copy(reactions = EmojiValues.DEFAULT_REACTIONS_LIST) }
} }