Skip to content

Commit eadc1a4

Browse files
SessionHero01SessionHero01
authored andcommitted
Pro features
1 parent f432973 commit eadc1a4

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

library/src/main/cpp/protocol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ static jobject serializeDecodedEnvelope(JNIEnv *env, const session::DecodedEnvel
5353
jmethodID init = env->GetMethodID(
5454
envelopClass.get(),
5555
"<init>",
56-
"(Lnetwork/loki/messenger/libsession_util/protocol/Envelope;Lnetwork/loki/messenger/libsession_util/pro/ProProof$Status;Lnetwork/loki/messenger/libsession_util/pro/ProProof;[B[B[BJ)V"
56+
"(Lnetwork/loki/messenger/libsession_util/protocol/Envelope;ILnetwork/loki/messenger/libsession_util/pro/ProProof;J[B[B[BJ)V"
5757
);
5858

5959
return env->NewObject(envelopClass.get(), init,
6060
serializeEnvelop(env, envelop.envelope).get(),
6161
envelop.pro ? static_cast<jint>(envelop.pro->status)
6262
: static_cast<jint>(-1),
6363
envelop.pro ? serializeProProof(env, envelop.pro->proof).get() : nullptr,
64+
static_cast<jlong>(envelop.pro ? envelop.pro->features : 0),
6465
content.get(),
6566
sender_ed25519.get(),
6667
sender_x25519.get(),
@@ -165,7 +166,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForC
165166
jmethodID init = env->GetMethodID(
166167
envelopClass.get(),
167168
"<init>",
168-
"(Lnetwork/loki/messenger/libsession_util/protocol/pro/ProProof$Status;Lnetwork/loki/messenger/libsession_util/protocol/pro/ProProof;[B)V"
169+
"(Lnetwork/loki/messenger/libsession_util/protocol/pro/ProProof$Status;Lnetwork/loki/messenger/libsession_util/protocol/pro/ProProof;J[B)V"
169170
);
170171

171172
return env->NewObject(
@@ -174,6 +175,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForC
174175
decoded.pro ? static_cast<jint>(decoded.pro->status)
175176
: static_cast<jint>(-1),
176177
decoded.pro ? serializeProProof(env, decoded.pro->proof).get() : nullptr,
178+
static_cast<jlong>(decoded.pro ? decoded.pro->features : 0),
177179
util::bytes_from_vector(env, decoded.content_plaintext)
178180
);
179181
});

library/src/main/java/network/loki/messenger/libsession_util/protocol/DecodedCommunityMessage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import java.util.EnumSet
88
data class DecodedCommunityMessage(
99
val proStatus: ProProof.Status?,
1010
val proProof: ProProof?,
11+
val proFeatures: ProFeatures,
1112
val contentPlainText: Bytes,
1213
) {
1314
@Keep
1415
constructor(
1516
status: Int,
1617
proProof: ProProof?,
18+
proFeatures: Long,
1719
contentPlainText: ByteArray,
1820
): this(
1921
proStatus = ProProof.Status.fromNativeValueOrNull(status),
2022
proProof = proProof,
23+
proFeatures = ProFeatures(proFeatures),
2124
contentPlainText = Bytes(contentPlainText),
2225
)
2326

library/src/main/java/network/loki/messenger/libsession_util/protocol/DecodedEnvelope.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ data class DecodedEnvelope(
1010
val envelope: Envelope,
1111
val proStatus: ProProof.Status?,
1212
val proProof: ProProof?,
13+
val proFeatures: ProFeatures,
1314
val contentPlainText: Bytes,
1415
val senderEd25519PubKey: Bytes,
1516
val senderX25519PubKey: Bytes,
@@ -20,6 +21,7 @@ data class DecodedEnvelope(
2021
envelope: Envelope,
2122
proStatus: Int,
2223
proProof: ProProof?,
24+
proFeatures: Long,
2325
contentPlainText: ByteArray,
2426
senderEd25519PubKey: ByteArray,
2527
senderX25519PubKey: ByteArray,
@@ -28,6 +30,7 @@ data class DecodedEnvelope(
2830
envelope = envelope,
2931
proStatus = ProProof.Status.fromNativeValueOrNull(proStatus),
3032
proProof = proProof,
33+
proFeatures = ProFeatures(proFeatures),
3134
contentPlainText = Bytes(contentPlainText),
3235
senderEd25519PubKey = Bytes(senderEd25519PubKey),
3336
senderX25519PubKey = Bytes(senderX25519PubKey),

library/src/main/java/network/loki/messenger/libsession_util/protocol/ProFeatures.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
package network.loki.messenger.libsession_util.protocol
22

3+
import kotlinx.serialization.Serializable
4+
35

46
enum class ProFeature(internal val bitIndex: Int) {
57
HIGHER_CHARACTER_LIMIT(0),
68
PRO_BADGE(1),
79
ANIMATED_AVATAR(2),
810
}
911

12+
@Serializable
13+
@JvmInline
14+
value class ProFeatures(val rawValue: Long) {
15+
companion object {
16+
val NONE = ProFeatures(0L)
17+
}
18+
19+
fun contains(feature: ProFeature): Boolean {
20+
return (rawValue and (1L shl feature.bitIndex)) != 0L
21+
}
22+
23+
fun toSet(): Set<ProFeature> {
24+
return rawValue.toFeatures()
25+
}
26+
}
27+
1028
internal fun Long.toFeatures(): Set<ProFeature> {
1129
return buildSet(ProFeature.entries.size) {
1230
for (entry in ProFeature.entries) {

0 commit comments

Comments
 (0)