Skip to content

Commit

Permalink
fix: Use Local Quote Color
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Dec 5, 2023
1 parent f99ded6 commit aecb41e
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.telegram.tgnet.TLRPC;

import xyz.nextalone.nagram.helper.MessageHelper;
import xyz.nextalone.nagram.helper.PeerColorHelper;

public class UserObject {

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down
14 changes: 4 additions & 10 deletions TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit aecb41e

Please sign in to comment.