mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Implement simple avatar color picking algorithm to align with iOS.
This commit is contained in:
committed by
Cody Henthorne
parent
bf7aaddbf9
commit
290c107698
@@ -23,6 +23,7 @@ import org.signal.core.util.optionalInt
|
||||
import org.signal.core.util.optionalLong
|
||||
import org.signal.core.util.optionalString
|
||||
import org.signal.core.util.or
|
||||
import org.signal.core.util.orNull
|
||||
import org.signal.core.util.readToList
|
||||
import org.signal.core.util.readToSet
|
||||
import org.signal.core.util.readToSingleBoolean
|
||||
@@ -48,6 +49,7 @@ import org.thoughtcrime.securesms.badges.models.Badge
|
||||
import org.thoughtcrime.securesms.color.MaterialColor
|
||||
import org.thoughtcrime.securesms.color.MaterialColor.UnknownColorException
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColorHash
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors.Companion.forChatColor
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors.Id.Companion.forLongValue
|
||||
@@ -602,7 +604,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
} else {
|
||||
val values = ContentValues().apply {
|
||||
put(GROUP_ID, groupId.toString())
|
||||
put(AVATAR_COLOR, AvatarColor.random().serialize())
|
||||
put(AVATAR_COLOR, AvatarColorHash.forGroupId(groupId).serialize())
|
||||
}
|
||||
|
||||
val id = writableDatabase.insert(TABLE_NAME, null, values)
|
||||
@@ -3855,12 +3857,13 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
private fun buildContentValuesForNewUser(e164: String?, pni: PNI?, aci: ACI?): ContentValues {
|
||||
check(e164 != null || pni != null || aci != null) { "Must provide some sort of identifier!" }
|
||||
|
||||
val serviceId = (aci ?: pni)?.toString()
|
||||
val values = contentValuesOf(
|
||||
PHONE to e164,
|
||||
SERVICE_ID to (aci ?: pni)?.toString(),
|
||||
SERVICE_ID to serviceId,
|
||||
PNI_COLUMN to pni?.toString(),
|
||||
STORAGE_SERVICE_ID to Base64.encodeBytes(StorageSyncHelper.generateKey()),
|
||||
AVATAR_COLOR to AvatarColor.random().serialize()
|
||||
AVATAR_COLOR to AvatarColorHash.forAddress(serviceId, e164).serialize()
|
||||
)
|
||||
|
||||
if (pni != null || aci != null) {
|
||||
@@ -3917,14 +3920,16 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
}
|
||||
|
||||
if (isInsert) {
|
||||
put(AVATAR_COLOR, AvatarColor.random().serialize())
|
||||
put(AVATAR_COLOR, AvatarColorHash.forAddress(contact.serviceId.toString(), contact.number.orNull()).serialize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getValuesForStorageGroupV1(groupV1: SignalGroupV1Record, isInsert: Boolean): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(GROUP_ID, GroupId.v1orThrow(groupV1.groupId).toString())
|
||||
val groupId = GroupId.v1orThrow(groupV1.groupId)
|
||||
|
||||
put(GROUP_ID, groupId.toString())
|
||||
put(GROUP_TYPE, GroupType.SIGNAL_V1.id)
|
||||
put(PROFILE_SHARING, if (groupV1.isProfileSharingEnabled) "1" else "0")
|
||||
put(BLOCKED, if (groupV1.isBlocked) "1" else "0")
|
||||
@@ -3938,14 +3943,16 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
}
|
||||
|
||||
if (isInsert) {
|
||||
put(AVATAR_COLOR, AvatarColor.random().serialize())
|
||||
put(AVATAR_COLOR, AvatarColorHash.forGroupId(groupId).serialize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getValuesForStorageGroupV2(groupV2: SignalGroupV2Record, isInsert: Boolean): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(GROUP_ID, GroupId.v2(groupV2.masterKeyOrThrow).toString())
|
||||
val groupId = GroupId.v2(groupV2.masterKeyOrThrow)
|
||||
|
||||
put(GROUP_ID, groupId.toString())
|
||||
put(GROUP_TYPE, GroupType.SIGNAL_V2.id)
|
||||
put(PROFILE_SHARING, if (groupV2.isProfileSharingEnabled) "1" else "0")
|
||||
put(BLOCKED, if (groupV2.isBlocked) "1" else "0")
|
||||
@@ -3960,7 +3967,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
}
|
||||
|
||||
if (isInsert) {
|
||||
put(AVATAR_COLOR, AvatarColor.random().serialize())
|
||||
put(AVATAR_COLOR, AvatarColorHash.forGroupId(groupId).serialize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user