Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/org/session/libsession/snode/SnodeClock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class SnodeClock @Inject constructor(
return currentTimeMills() / 1000
}

fun currentTime(): java.time.Instant {
return java.time.Instant.ofEpochMilli(currentTimeMills())
}

private class Instant(
val systemUptime: Long,
val networkTime: Long,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class Recipient(
* it will always return [GroupMemberRole.STANDARD].
*/
val currentUserRole: GroupMemberRole get() = when (data) {
is RecipientData.Group -> if (data.partial.isAdmin) GroupMemberRole.ADMIN else GroupMemberRole.STANDARD
is RecipientData.Group -> if (data.isAdmin) GroupMemberRole.ADMIN else GroupMemberRole.STANDARD
is RecipientData.Community -> when {
data.roomInfo?.admin == true -> GroupMemberRole.ADMIN
data.roomInfo?.moderator == true -> GroupMemberRole.MODERATOR
Expand All @@ -60,7 +60,7 @@ data class Recipient(
val expiryMode: ExpiryMode get() = when (data) {
is RecipientData.Self -> data.expiryMode
is RecipientData.Contact -> data.expiryMode
is RecipientData.Group -> data.partial.expiryMode
is RecipientData.Group -> data.expiryMode
else -> ExpiryMode.NONE
}

Expand All @@ -71,12 +71,13 @@ data class Recipient(
address is Address.CommunityBlindedId -> true

data is RecipientData.Contact -> data.approved
data is RecipientData.Group -> data.partial.approved
data is RecipientData.Group -> data.approved

else -> false
}

val proStatus: ProStatus get() = data.proStatus
val isPro: Boolean get() = data.proData != null
val shouldShowProBadge: Boolean get() = data.proData?.showProBadge == true

val approvedMe: Boolean get() {
return when (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ sealed interface RecipientData {
val priority: Long
val profileUpdatedAt: Instant?

val proStatus: ProStatus
val proData: ProData?

// Marker interface to distinguish between config-based and other recipient data.
sealed interface ConfigBased
fun setProData(proData: ProData): RecipientData

/**
* Represents a group-like recipient, which can be a group or community.
Expand All @@ -50,19 +49,23 @@ sealed interface RecipientData {
val displayName: String = "",
override val avatar: RemoteFile? = null,
override val priority: Long = PRIORITY_VISIBLE,
override val proStatus: ProStatus = ProStatus.None,
override val proData: ProData? = null,
val acceptsBlindedCommunityMessageRequests: Boolean = false,
override val profileUpdatedAt: Instant? = null,
) : RecipientData
) : RecipientData {
override fun setProData(proData: ProData): Generic = copy(proData = proData)
}

data class BlindedContact(
val displayName: String,
override val avatar: RemoteFile.Encrypted?,
override val priority: Long,
override val proStatus: ProStatus,
override val proData: ProData?,
val acceptsBlindedCommunityMessageRequests: Boolean,
override val profileUpdatedAt: Instant?
) : ConfigBased, RecipientData
) : RecipientData {
override fun setProData(proData: ProData): BlindedContact = copy(proData = proData)
}

data class Community(
val serverUrl: String,
Expand Down Expand Up @@ -95,6 +98,11 @@ sealed interface RecipientData {
override val profileUpdatedAt: Instant?
get() = null

override val proData: ProData?
get() = null

override fun setProData(proData: ProData): Community = this

override fun hasAdmin(user: AccountId): Boolean {
return roomInfo != null && (roomInfo.details.admins.contains(user.hexString) ||
roomInfo.details.moderators.contains(user.hexString) ||
Expand All @@ -106,9 +114,6 @@ sealed interface RecipientData {
return roomInfo != null && (roomInfo.details.admins.contains(user.hexString) ||
roomInfo.details.moderators.contains(user.hexString))
}

override val proStatus: ProStatus
get() = ProStatus.None
}

/**
Expand All @@ -119,9 +124,11 @@ sealed interface RecipientData {
override val avatar: RemoteFile.Encrypted?,
val expiryMode: ExpiryMode,
override val priority: Long,
override val proStatus: ProStatus,
override val proData: ProData?,
override val profileUpdatedAt: Instant?
) : ConfigBased, RecipientData
) : RecipientData {
override fun setProData(proData: ProData): Self = copy(proData = proData)
}

/**
* A recipient that was saved in your contact config.
Expand All @@ -135,11 +142,13 @@ sealed interface RecipientData {
val blocked: Boolean,
val expiryMode: ExpiryMode,
override val priority: Long,
override val proStatus: ProStatus,
override val proData: ProData?,
override val profileUpdatedAt: Instant?,
) : ConfigBased, RecipientData {
) : RecipientData {
val displayName: String
get() = nickname?.takeIf { it.isNotBlank() } ?: name

override fun setProData(proData: ProData): Contact = copy(proData = proData)
}

data class GroupMemberInfo(
Expand All @@ -156,55 +165,40 @@ sealed interface RecipientData {
)
}


/**
* Group data fetched from the config. It's named as "partial" because it does not include
* all the information we need to resemble a full group recipient, hence not implementing the
* [RecipientData] interface.
* Full group data that includes additional information that may not be present in the config.
*/
data class PartialGroup(
data class Group(
val name: String,
private val groupInfo: GroupInfo.ClosedGroupInfo,
val avatar: RemoteFile.Encrypted?,
override val avatar: RemoteFile.Encrypted?,
val expiryMode: ExpiryMode,
val proStatus: ProStatus,
val members: List<GroupMemberInfo>,
val description: String?,
) : ConfigBased {
override val proData: ProData?,
override val firstMember: Recipient?, // Used primarily to assemble the profile picture for the group.
override val secondMember: Recipient?, // Used primarily to assemble the profile picture for the group.
) : RecipientData, GroupLike {
val approved: Boolean get() = !groupInfo.invited
val priority: Long get() = groupInfo.priority
override val priority: Long get() = groupInfo.priority
val isAdmin: Boolean get() = groupInfo.hasAdminKey()
val kicked: Boolean get() = groupInfo.kicked
val destroyed: Boolean get() = groupInfo.destroyed
val shouldPoll: Boolean get() = groupInfo.shouldPoll
}

/**
* Full group data that includes additional information that may not be present in the config.
*/
data class Group(
val partial: PartialGroup,
override val firstMember: Recipient, // Used primarily to assemble the profile picture for the group.
override val secondMember: Recipient?, // Used primarily to assemble the profile picture for the group.
) : RecipientData, GroupLike {
override val avatar: RemoteFile?
get() = partial.avatar

override val priority: Long
get() = partial.priority

override val proStatus: ProStatus
get() = partial.proStatus

override val profileUpdatedAt: Instant?
get() = null

override fun hasAdmin(user: AccountId): Boolean {
return partial.members.any { it.address.accountId == user && it.isAdmin }
return members.any { it.address.accountId == user && it.isAdmin }
}

override fun shouldShowAdminCrown(user: AccountId): Boolean {
return hasAdmin(user)
}

override fun setProData(proData: ProData): Group = copy(proData = proData)
}

data class LegacyGroup(
Expand All @@ -218,9 +212,6 @@ sealed interface RecipientData {
override val avatar: RemoteFile?
get() = null

override val proStatus: ProStatus
get() = ProStatus.None

override fun hasAdmin(user: AccountId): Boolean {
return members[user]?.canModerate == true
}
Expand All @@ -231,5 +222,15 @@ sealed interface RecipientData {

override val profileUpdatedAt: Instant?
get() = null

override val proData: ProData?
get() = null

override fun setProData(proData: ProData): LegacyGroup = this
}


data class ProData(
val showProBadge: Boolean,
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun Recipient.displayName(
is RecipientData.Self -> data.name
is RecipientData.Contact -> data.displayName
is RecipientData.LegacyGroup -> data.name
is RecipientData.Group -> data.partial.name
is RecipientData.Group -> data.name
is RecipientData.Generic -> data.displayName
is RecipientData.Community -> data.roomInfo?.details?.name ?: data.room
is RecipientData.BlindedContact -> data.displayName
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.session.libsession.utilities.serializable

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.session.libsignal.utilities.Hex
import org.session.libsignal.utilities.toHexString

class ByteArrayAsHexSerializer : KSerializer<ByteArray> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor(javaClass.name, PrimitiveKind.STRING)

override fun serialize(
encoder: Encoder,
value: ByteArray
) {
encoder.encodeString(value.toHexString())
}

override fun deserialize(decoder: Decoder): ByteArray {
return decoder.decodeString().let(Hex::fromStringCondensed)
}
}

This file was deleted.

Loading