From aecb41ef1e16305e24ee0e836b915d93f6e116b4 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 5 Dec 2023 22:01:21 +0800 Subject: [PATCH] fix: Use Local Quote Color --- .../org/telegram/messenger/UserObject.java | 9 +++ .../org/telegram/ui/PeerColorActivity.java | 2 + .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 14 +--- .../nagram/helper/PeerColorHelper.kt | 78 ++++++++++++++++++- 4 files changed, 89 insertions(+), 14 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/UserObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/UserObject.java index 3a7bcbb195..1426deaaad 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/UserObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/UserObject.java @@ -16,6 +16,7 @@ import org.telegram.tgnet.TLRPC; import xyz.nextalone.nagram.helper.MessageHelper; +import xyz.nextalone.nagram.helper.PeerColorHelper; public class UserObject { @@ -154,22 +155,30 @@ public static MessagesController.PeerColor getPeerColorForAvatar(int currentAcco public static int getColorId(TLRPC.User user) { if (user == null) return 0; + Integer replace = PeerColorHelper.getColorId(user); + if (replace != null) return replace; if (user.color != null && (user.color.flags & 1) != 0) return user.color.color; return (int) (user.id % 7); } public static long getEmojiId(TLRPC.User user) { + Long replace = PeerColorHelper.getEmojiId(user); + if (replace != null) return replace; if (user != null && user.color != null && (user.color.flags & 2) != 0) return user.color.background_emoji_id; return 0; } public static int getProfileColorId(TLRPC.User user) { if (user == null) return 0; + Integer replace = PeerColorHelper.getProfileColorId(user); + if (replace != null) return replace; if (user.profile_color != null && (user.profile_color.flags & 1) != 0) return user.profile_color.color; return -1; } public static long getProfileEmojiId(TLRPC.User user) { + Long replace = PeerColorHelper.getProfileEmojiId(user); + if (replace != null) return replace; if (user != null && user.profile_color != null && (user.profile_color.flags & 2) != 0) return user.profile_color.background_emoji_id; return 0; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PeerColorActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PeerColorActivity.java index 445e1b22dc..c6e362ccfe 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PeerColorActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PeerColorActivity.java @@ -101,6 +101,7 @@ import java.util.List; import xyz.nextalone.nagram.NaConfig; +import xyz.nextalone.nagram.helper.PeerColorHelper; public class PeerColorActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { @@ -1178,6 +1179,7 @@ private void apply() { } })); } else { + PeerColorHelper.apply(namePage.selectedColor, namePage.selectedEmoji, profilePage.selectedColor, profilePage.selectedEmoji); final TLRPC.User me = getUserConfig().getCurrentUser(); if (me.color == null) { me.color = new TLRPC.TL_peerColor(); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index 02202b02ba..43f77e3aff 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -448,17 +448,11 @@ object NaConfig { ConfigItem.configTypeBool, false ) - val useLocalQuoteColorColor = + val useLocalQuoteColorData = addConfig( - "UseLocalQuoteColorColor", - ConfigItem.configTypeInt, - 0 - ) - val useLocalQuoteColorEmoji = - addConfig( - "useLocalQuoteColorEmoji", - ConfigItem.configTypeLong, - 0L + "useLocalQuoteColorData", + ConfigItem.configTypeString, + "" ) private fun addConfig( diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/PeerColorHelper.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/PeerColorHelper.kt index dd97ea4df4..44a549922a 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/PeerColorHelper.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/PeerColorHelper.kt @@ -1,15 +1,85 @@ package xyz.nextalone.nagram.helper +import com.google.gson.Gson +import org.telegram.tgnet.TLRPC import xyz.nextalone.nagram.NaConfig +data class LocalQuoteColorData ( + var colorId: Int?, + var emojiId: Long?, + var profileColorId: Int?, + var profileEmojiId: Long? +) + + object PeerColorHelper { + var loaded: Boolean = false + var data: LocalQuoteColorData? = null + + @JvmStatic + fun getColorId(user: TLRPC.User): Int? { + if (!NaConfig.useLocalQuoteColor.Bool()) return null + init() + if (user.self && data != null) { + return data!!.colorId + } + return null + } + + @JvmStatic + fun getEmojiId(user: TLRPC.User?): Long? { + if (!NaConfig.useLocalQuoteColor.Bool()) return null + init() + if (user != null && user.self && data != null) { + return data!!.emojiId + } + return null + } + + @JvmStatic + fun getProfileColorId(user: TLRPC.User): Int? { + if (!NaConfig.useLocalQuoteColor.Bool()) return null + init() + if (user.self && data != null) { + return data!!.profileColorId + } + return null + } + + @JvmStatic + fun getProfileEmojiId(user: TLRPC.User?): Long? { + if (!NaConfig.useLocalQuoteColor.Bool()) return null + init() + if (user != null && user.self && data != null) { + return data!!.profileEmojiId + } + return null + } + + @JvmStatic + fun init(force: Boolean = false) { + if (loaded && !force) return + loaded = true + try { + val gson = Gson() + data = gson.fromJson(NaConfig.useLocalQuoteColorData.String(), LocalQuoteColorData::class.java) + } catch (_: Exception) {} + } @JvmStatic - fun replaceColor(old: Int?): Int? { - if (NaConfig.useLocalQuoteColor.Bool()) { - return NaConfig.useLocalQuoteColorColor.Int() + fun apply(colorId: Int, emojiId: Long, profileColorId: Int, profileEmojiId: Long) { + if (!NaConfig.useLocalQuoteColor.Bool()) return + var localData = data + if (localData == null) { + localData = LocalQuoteColorData(colorId, emojiId, profileColorId, profileEmojiId) + } else { + localData.colorId = colorId + localData.emojiId = emojiId + localData.profileColorId = profileColorId + localData.profileEmojiId = profileEmojiId } - return old + NaConfig.useLocalQuoteColorData.setConfigString(Gson().toJson(localData)) + init(true) } }