feat: add config base free instead of user profile

This commit is contained in:
0x330a 2022-12-16 16:53:12 +11:00
parent bd2a4fcfd6
commit 1b2e734453
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
5 changed files with 44 additions and 11 deletions

View File

@ -1,4 +0,0 @@
package org.thoughtcrime.securesms.dependencies;
public interface InjectableType {
}

View File

@ -0,0 +1,30 @@
package org.thoughtcrime.securesms.dependencies
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityRetainedComponent
import dagger.hilt.android.scopes.ActivityRetainedScoped
import network.loki.messenger.libsession_util.UserProfile
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.crypto.KeyPairUtilities
@Module
@InstallIn(ActivityRetainedComponent::class)
abstract class SessionUtilModule {
private fun maybeUserEdSecretKey(context: ApplicationContext): ByteArray? {
val edKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return null
return edKey.secretKey.asBytes
}
@Provides
@ActivityRetainedScoped
fun provideUser(context: ApplicationContext): UserProfile {
val key = maybeUserEdSecretKey(context)
return UserProfile.newInstance(key ?: byteArrayOf())
}
}

View File

@ -33,6 +33,12 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_push(JNIEnv *env, jobjec
return returnObject;
}
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_free(JNIEnv *env, jobject thiz) {
auto config = ptrToConfigBase(env, thiz);
delete config;
}
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_dump(JNIEnv *env, jobject thiz) {
auto config = ptrToConfigBase(env, thiz);

View File

@ -54,12 +54,6 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jo
return returnString;
}
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_free(JNIEnv *env, jobject thiz) {
auto profile = ptrToProfile(env, thiz);
delete profile;
}
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, jobject thiz) {
auto profile = ptrToProfile(env, thiz);

View File

@ -23,6 +23,14 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
// Singular merge
external fun merge(toMerge: ByteArray): Int
external fun free()
@Override
fun finalize() {
free()
}
}
class Contacts(pointer: Long) : ConfigBase(pointer) {
@ -53,7 +61,6 @@ class UserProfile(pointer: Long) : ConfigBase(pointer) {
external fun setName(newName: String)
external fun getName(): String?
external fun free()
external fun getPic(): UserPic?
external fun setPic(userPic: UserPic)
}