Update chat colors.

This commit is contained in:
Alex Hart
2021-05-03 11:34:41 -03:00
committed by Greyson Parrelli
parent 36fe150678
commit bcc5d485ab
164 changed files with 5817 additions and 1476 deletions

View File

@@ -0,0 +1,42 @@
package org.thoughtcrime.securesms.keyvalue
import com.google.protobuf.InvalidProtocolBufferException
import org.thoughtcrime.securesms.conversation.colors.ChatColors
import org.thoughtcrime.securesms.database.model.databaseprotos.ChatColor
internal class ChatColorsValues internal constructor(store: KeyValueStore) : SignalStoreValues(store) {
companion object {
private const val KEY_CHAT_COLORS = "chat_colors.chat_colors"
private const val KEY_CHAT_COLORS_ID = "chat_colors.chat_colors.id"
}
override fun onFirstEverAppLaunch() = Unit
override fun getKeysToIncludeInBackup(): MutableList<String> = mutableListOf()
val hasChatColors: Boolean
@JvmName("hasChatColors")
get() = chatColors != null
var chatColors: ChatColors?
get() = getBlob(KEY_CHAT_COLORS, null)?.let { bytes ->
try {
ChatColors.forChatColor(chatColorsId, ChatColor.parseFrom(bytes))
} catch (e: InvalidProtocolBufferException) {
null
}
}
set(value) {
if (value != null) {
putBlob(KEY_CHAT_COLORS, value.serialize().toByteArray())
chatColorsId = value.id
} else {
remove(KEY_CHAT_COLORS)
}
}
private var chatColorsId: ChatColors.Id
get() = ChatColors.Id.forLongValue(getLong(KEY_CHAT_COLORS_ID, ChatColors.Id.NotSet.longValue))
set(value) = putLong(KEY_CHAT_COLORS_ID, value.longValue)
}

View File

@@ -36,6 +36,7 @@ public final class SignalStore {
private final PaymentsValues paymentsValues;
private final ProxyValues proxyValues;
private final RateLimitValues rateLimitValues;
private final ChatColorsValues chatColorsValues;
private SignalStore() {
this.store = new KeyValueStore(ApplicationDependencies.getApplication());
@@ -57,6 +58,7 @@ public final class SignalStore {
this.paymentsValues = new PaymentsValues(store);
this.proxyValues = new ProxyValues(store);
this.rateLimitValues = new RateLimitValues(store);
this.chatColorsValues = new ChatColorsValues(store);
}
public static void onFirstEverAppLaunch() {
@@ -78,6 +80,7 @@ public final class SignalStore {
paymentsValues().onFirstEverAppLaunch();
proxy().onFirstEverAppLaunch();
rateLimit().onFirstEverAppLaunch();
chatColorsValues().onFirstEverAppLaunch();
}
public static List<String> getKeysToIncludeInBackup() {
@@ -100,6 +103,7 @@ public final class SignalStore {
keys.addAll(paymentsValues().getKeysToIncludeInBackup());
keys.addAll(proxy().getKeysToIncludeInBackup());
keys.addAll(rateLimit().getKeysToIncludeInBackup());
keys.addAll(chatColorsValues().getKeysToIncludeInBackup());
return keys;
}
@@ -184,6 +188,10 @@ public final class SignalStore {
return INSTANCE.rateLimitValues;
}
public static @NonNull ChatColorsValues chatColorsValues() {
return INSTANCE.chatColorsValues;
}
public static @NonNull GroupsV2AuthorizationSignalStoreCache groupsV2AuthorizationCache() {
return new GroupsV2AuthorizationSignalStoreCache(getStore());
}

View File

@@ -69,6 +69,6 @@ abstract class SignalStoreValues {
}
void remove(@NonNull String key) {
store.beginWrite().remove(key);
store.beginWrite().remove(key).apply();
}
}