feat: finish latest wrappers fix tests and continue building default generation functions. refactor defaults to be used if no stored data blob in DB

This commit is contained in:
0x330a
2023-03-03 16:41:57 +11:00
parent c1434648dc
commit 2a701f2cc3
6 changed files with 70 additions and 41 deletions

View File

@@ -188,6 +188,7 @@ class InstrumentedTests {
userProfile.setName("Kallie")
val newUserPic = UserPic("http://example.org/omg-pic-123.bmp", "secret78901234567890123456789012".encodeToByteArray())
userProfile.setPic(newUserPic)
userProfile.setNtsPriority(9)
// Retrieve them just to make sure they set properly:
assertEquals("Kallie", userProfile.getName())
@@ -205,20 +206,22 @@ class InstrumentedTests {
Hex.fromStringCondensed("ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965")
val expectedPush1Decrypted = ("d" +
"1:#" + "i1e"+
"1:&" + "d"+
"1:n" + "6:Kallie"+
"1:p" + "34:http://example.org/omg-pic-123.bmp"+
"1:q" + "32:secret78901234567890123456789012"+
"1:#"+ "i1e" +
"1:&"+ "d"+
"1:+"+ "i9e"+
"1:n"+ "6:Kallie"+
"1:p"+ "34:http://example.org/omg-pic-123.bmp"+
"1:q"+ "32:secret78901234567890123456789012"+
"e"+
"1:<"+ "l"+
"l"+ "i0e"+ "32:").encodeToByteArray() + expHash0 + ("de"+ "e"+
"e"+
"1:="+ "d"+
"1:+" +"0:"+
"1:n" +"0:"+
"1:p" +"0:"+
"1:q" +"0:"+
"e"+
"1:<" + "l"+
"l" + "i0e" + "32:").encodeToByteArray() + expHash0 + ("de" + "e" +
"e" +
"1:=" + "d" +
"1:n" + "0:" +
"1:p" + "0:" +
"1:q" + "0:" +
"e" +
"e").encodeToByteArray()
assertEquals(1, newSeqNo)
@@ -227,19 +230,20 @@ class InstrumentedTests {
// We did call push but we haven't confirmed it as stored yet, so this will still return true:
assertTrue(userProfile.needsPush())
userProfile.confirmPushed(newSeqNo, "fakehash1")
val dump = userProfile.dump()
// (in a real client we'd now store this to disk)
assertFalse(userProfile.needsDump())
val expectedDump = ("d" +
"1:!i2e" +
"1:!"+ "i2e" +
"1:$").encodeToByteArray() + expectedPush1Decrypted.size.toString().encodeToByteArray() +
":".encodeToByteArray() + expectedPush1Decrypted +
"1:(0:1:)le".encodeToByteArray()+
"e".encodeToByteArray()
assertArrayEquals(expectedDump, dump)
userProfile.confirmPushed(newSeqNo, "fakehash1")
val newConf = UserProfile.newInstance(edSk)
val accepted = newConf.merge("fakehash1" to newToPush)
@@ -258,16 +262,16 @@ class InstrumentedTests {
val conf = userProfile.push()
val conf2 = newConf.push()
userProfile.confirmPushed(conf.seqNo, "fakehash1")
newConf.confirmPushed(conf2.seqNo, "fakehash2")
userProfile.confirmPushed(conf.seqNo, "fakehash2")
newConf.confirmPushed(conf2.seqNo, "fakehash3")
userProfile.dump()
userProfile.dump()
assertFalse(conf.config.contentEquals(conf2.config))
newConf.merge("fakehash1" to conf.config)
userProfile.merge("fakehash2" to conf2.config)
newConf.merge("fakehash2" to conf.config)
userProfile.merge("fakehash3" to conf2.config)
assertTrue(newConf.needsPush())
assertTrue(userProfile.needsPush())
@@ -276,20 +280,20 @@ class InstrumentedTests {
assertEquals(3, newSeq1.seqNo)
userProfile.confirmPushed(newSeq1.seqNo, "fakehash3")
userProfile.confirmPushed(newSeq1.seqNo, "fakehash4")
// assume newConf push gets rejected as it was last to write and clear previous config by hash on oxenss
newConf.merge("fakehash3" to newSeq1.config)
newConf.merge("fakehash4" to newSeq1.config)
val newSeqMerge = newConf.push()
newConf.confirmPushed(newSeqMerge.seqNo, "fakehash4")
newConf.confirmPushed(newSeqMerge.seqNo, "fakehash5")
assertEquals("Nibbler", newConf.getName())
assertEquals(4, newSeqMerge.seqNo)
// userProfile device polls and merges
userProfile.merge("fakehash4" to newSeqMerge.config)
userProfile.merge("fakehash5" to newSeqMerge.config)
val userConfigMerge = userProfile.push()

View File

@@ -75,4 +75,18 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, job
env->ReleaseStringUTFChars(pic.first, url);
}
}
extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setNtsPriority(JNIEnv *env, jobject thiz,
jint priority) {
auto profile = ptrToProfile(env, thiz);
profile->set_nts_priority(priority);
}
extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setNtsHidden(JNIEnv *env, jobject thiz,
jboolean is_hidden) {
auto profile = ptrToProfile(env, thiz);
profile->set_nts_hidden(is_hidden);
}

View File

@@ -43,11 +43,6 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
external fun free()
@Override
fun finalize() {
free()
}
}
class Contacts(pointer: Long) : ConfigBase(pointer) {
@@ -98,6 +93,8 @@ class UserProfile(pointer: Long) : ConfigBase(pointer) {
external fun getName(): String?
external fun getPic(): UserPic
external fun setPic(userPic: UserPic)
external fun setNtsPriority(priority: Int)
external fun setNtsHidden(isHidden: Boolean)
}
class ConversationVolatileConfig(pointer: Long): ConfigBase(pointer) {