Merge remote-tracking branch 'origin/libsession-integration' into libsession-integration

This commit is contained in:
0x330a 2023-07-14 13:34:24 +10:00
commit 6ed093072a
17 changed files with 116 additions and 26 deletions

View File

@ -156,7 +156,7 @@ dependencies {
testImplementation 'org.robolectric:shadows-multidex:4.4'
}
def canonicalVersionCode = 352
def canonicalVersionCode = 353
def canonicalVersionName = "1.17.0"
def postFixSize = 10

View File

@ -32,10 +32,10 @@ class ProfilePictureView @JvmOverloads constructor(
var isLarge = false
private val profilePicturesCache = mutableMapOf<String, String?>()
private val unknownRecipientDrawable = ResourceContactPhoto(R.drawable.ic_profile_default)
.asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context), false)
private val unknownOpenGroupDrawable = ResourceContactPhoto(R.drawable.ic_notification)
.asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context), false)
private val unknownRecipientDrawable by lazy { ResourceContactPhoto(R.drawable.ic_profile_default)
.asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context), false) }
private val unknownOpenGroupDrawable by lazy { ResourceContactPhoto(R.drawable.ic_notification)
.asDrawable(context, ContactColors.UNKNOWN_COLOR.toConversationColor(context), false) }
// endregion
@ -120,7 +120,7 @@ class ProfilePictureView @JvmOverloads constructor(
if (signalProfilePicture != null && avatar != "0" && avatar != "") {
glide.clear(imageView)
glide.load(signalProfilePicture)
.placeholder(R.drawable.ic_profile_default)
.placeholder(unknownRecipientDrawable)
.centerCrop()
.error(glide.load(placeholder))
.diskCacheStrategy(DiskCacheStrategy.NONE)
@ -128,20 +128,22 @@ class ProfilePictureView @JvmOverloads constructor(
.into(imageView)
} else if (recipient.isOpenGroupRecipient && recipient.groupAvatarId == null) {
glide.clear(imageView)
glide.load(R.drawable.ic_notification)
glide.load(unknownOpenGroupDrawable)
.centerCrop()
.circleCrop()
.into(imageView)
} else {
glide.clear(imageView)
glide.load(placeholder)
.placeholder(R.drawable.ic_profile_default)
.placeholder(unknownRecipientDrawable)
.centerCrop()
.circleCrop()
.diskCacheStrategy(DiskCacheStrategy.NONE).circleCrop().into(imageView)
}
profilePicturesCache[publicKey] = recipient.profileAvatar
} else {
glide.load(R.drawable.ic_profile_default)
.centerInside()
glide.load(unknownRecipientDrawable)
.centerCrop()
.into(imageView)
}
}

View File

@ -512,14 +512,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (cursor != null) {
val messageTimestamp = messageToScrollTimestamp.getAndSet(-1)
val author = messageToScrollAuthor.getAndSet(null)
val initialUnreadCount: Int
val initialUnreadCount = mmsSmsDb.getUnreadCount(viewModel.threadId)
// Update the unreadCount value to be loaded from the database since we got a new message
if (firstLoad.get() || oldCount != newCount) {
if (firstLoad.get() || oldCount != newCount || initialUnreadCount != unreadCount) {
// Update the unreadCount value to be loaded from the database since we got a new
// message (we need to store it in a local variable as it can get overwritten on
// another thread before the 'firstLoad.getAndSet(false)' case below)
initialUnreadCount = mmsSmsDb.getUnreadCount(viewModel.threadId)
unreadCount = initialUnreadCount
updateUnreadCountIndicator()
}

View File

@ -778,6 +778,7 @@ public class ThreadDatabase extends Database {
if (reader != null)
reader.close();
notifyConversationListListeners();
notifyConversationListeners(threadId);
}
}
@ -794,7 +795,7 @@ public class ThreadDatabase extends Database {
public boolean isPinned(long threadId) {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{DATE}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);
Cursor cursor = db.query(TABLE_NAME, new String[]{IS_PINNED}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
return cursor.getInt(0) == 1;

View File

@ -159,8 +159,9 @@ public class DefaultMessageNotifier implements MessageNotifier {
executor.cancel();
}
private void cancelActiveNotifications(@NonNull Context context) {
private boolean cancelActiveNotifications(@NonNull Context context) {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
boolean hasNotifications = notifications.getActiveNotifications().length > 0;
notifications.cancel(SUMMARY_NOTIFICATION_ID);
try {
@ -174,6 +175,7 @@ public class DefaultMessageNotifier implements MessageNotifier {
Log.w(TAG, e);
notifications.cancelAll();
}
return hasNotifications;
}
private void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) {
@ -246,11 +248,21 @@ public class DefaultMessageNotifier implements MessageNotifier {
return;
}
if (!isVisible && !homeScreenVisible) {
if ((!isVisible && !homeScreenVisible) || hasExistingNotifications(context)) {
updateNotification(context, signal, 0);
}
}
private boolean hasExistingNotifications(Context context) {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
try {
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
return activeNotifications.length > 0;
} catch (Exception e) {
return false;
}
}
@Override
public void updateNotification(@NonNull Context context, boolean signal, int reminderCount)
{
@ -262,8 +274,8 @@ public class DefaultMessageNotifier implements MessageNotifier {
if ((telcoCursor == null || telcoCursor.isAfterLast()) || !TextSecurePreferences.hasSeenWelcomeScreen(context))
{
cancelActiveNotifications(context);
updateBadge(context, 0);
cancelActiveNotifications(context);
clearReminder(context);
return;
}

View File

@ -31,6 +31,7 @@
</RelativeLayout>
<ImageView
android:scaleType="centerCrop"
android:id="@+id/singleModeImageView"
android:layout_width="@dimen/medium_profile_picture_size"
android:layout_height="@dimen/medium_profile_picture_size"
@ -38,6 +39,7 @@
<ImageView
android:id="@+id/largeSingleModeImageView"
android:scaleType="centerCrop"
android:layout_width="@dimen/large_profile_picture_size"
android:layout_height="@dimen/large_profile_picture_size"
android:background="@drawable/profile_picture_view_large_background" />

@ -1 +1 @@
Subproject commit 97084c69f86e67c675095b48efacc86113ccebb0
Subproject commit 7eb87028355bfc89950102c52d5b2927a25b2e22

View File

@ -4,24 +4,28 @@
extern "C" {
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_dirty(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto* configBase = ptrToConfigBase(env, thiz);
return configBase->is_dirty();
}
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_needsPush(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConfigBase(env, thiz);
return config->needs_push();
}
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_needsDump(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConfigBase(env, thiz);
return config->needs_dump();
}
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_push(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConfigBase(env, thiz);
auto push_tuple = config->push();
auto to_push_str = std::get<1>(push_tuple);
@ -51,6 +55,7 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_free(JNIEnv *env, jobjec
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_dump(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConfigBase(env, thiz);
auto dumped = config->dump();
jbyteArray bytes = util::bytes_from_ustring(env, dumped);
@ -68,6 +73,7 @@ JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_confirmPushed(JNIEnv *env, jobject thiz,
jlong seq_no,
jstring new_hash_jstring) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToConfigBase(env, thiz);
auto new_hash = env->GetStringUTFChars(new_hash_jstring, nullptr);
conf->confirm_pushed(seq_no, new_hash);
@ -79,6 +85,7 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_confirmPushed(JNIEnv *en
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_merge___3Lkotlin_Pair_2(JNIEnv *env, jobject thiz,
jobjectArray to_merge) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToConfigBase(env, thiz);
size_t number = env->GetArrayLength(to_merge);
std::vector<std::pair<std::string,session::ustring>> configs = {};
@ -93,6 +100,7 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_merge___3Lkotlin_Pair_2(
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_merge__Lkotlin_Pair_2(JNIEnv *env, jobject thiz,
jobject to_merge) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToConfigBase(env, thiz);
std::vector<std::pair<std::string, session::ustring>> configs = {extractHashAndData(env, to_merge)};
return conf->merge(configs);
@ -132,6 +140,7 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_00024Companion_kindFor(J
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_currentHashes(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToConfigBase(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");

View File

@ -5,6 +5,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_get(JNIEnv *env, jobject thiz,
jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto contacts = ptrToContacts(env, thiz);
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
auto contact = contacts->get(session_id_chars);
@ -18,6 +19,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_getOrConstruct(JNIEnv *env, jobject thiz,
jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto contacts = ptrToContacts(env, thiz);
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
auto contact = contacts->get_or_construct(session_id_chars);
@ -29,6 +31,7 @@ extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_set(JNIEnv *env, jobject thiz,
jobject contact) {
std::lock_guard lock{util::util_mutex_};
auto contacts = ptrToContacts(env, thiz);
auto contact_info = deserialize_contact(env, contact, contacts);
contacts->set(contact_info);
@ -38,6 +41,7 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_erase(JNIEnv *env, jobject thiz,
jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto contacts = ptrToContacts(env, thiz);
auto session_id_chars = env->GetStringUTFChars(session_id, nullptr);
@ -52,6 +56,7 @@ JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B(JNIEnv *env,
jobject thiz,
jbyteArray ed25519_secret_key) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto* contacts = new session::config::Contacts(secret_key, std::nullopt);
@ -65,6 +70,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
@ -80,6 +86,7 @@ Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Contacts_all(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto contacts = ptrToContacts(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");

View File

@ -8,6 +8,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_00024Companion_newInstance___3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto* convo_info_volatile = new session::config::ConvoInfoVolatile(secret_key, std::nullopt);
@ -22,6 +23,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto* convo_info_volatile = new session::config::ConvoInfoVolatile(secret_key, initial);
@ -39,6 +41,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeOneToOnes(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conversations = ptrToConvoInfo(env, thiz);
return conversations->size_1to1();
}
@ -49,6 +52,7 @@ JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseAll(JNIEnv *env,
jobject thiz,
jobject predicate) {
std::lock_guard lock{util::util_mutex_};
auto conversations = ptrToConvoInfo(env, thiz);
jclass predicate_class = env->FindClass("kotlin/jvm/functions/Function1");
@ -58,15 +62,19 @@ Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseAll
jmethodID bool_get = env->GetMethodID(bool_class, "booleanValue", "()Z");
int removed = 0;
auto to_erase = std::vector<session::config::convo::any>();
for (auto it = conversations->begin(); it != conversations->end(); ) {
for (auto it = conversations->begin(); it != conversations->end(); ++it) {
auto result = env->CallObjectMethod(predicate, predicate_call, serialize_any(env, *it));
bool bool_result = env->CallBooleanMethod(result, bool_get);
if (bool_result) {
it = conversations->erase(it);
to_erase.push_back(*it);
}
}
for (auto & entry : to_erase) {
if (conversations->erase(entry)) {
removed++;
} else {
++it;
}
}
@ -77,6 +85,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_size(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConvoInfo(env, thiz);
return (jint)config->size();
}
@ -84,6 +93,7 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_empty(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto config = ptrToConvoInfo(env, thiz);
return config->empty();
}
@ -92,6 +102,7 @@ JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_set(JNIEnv *env,
jobject thiz,
jobject to_store) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
@ -116,6 +127,7 @@ JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOneToOne(JNIEnv *env,
jobject thiz,
jstring pub_key_hex) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto param = env->GetStringUTFChars(pub_key_hex, nullptr);
auto internal = convos->get_1to1(param);
@ -129,6 +141,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructOneToOne(
JNIEnv *env, jobject thiz, jstring pub_key_hex) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto param = env->GetStringUTFChars(pub_key_hex, nullptr);
auto internal = convos->get_or_construct_1to1(param);
@ -140,6 +153,7 @@ JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseOneToOne(JNIEnv *env,
jobject thiz,
jstring pub_key_hex) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto param = env->GetStringUTFChars(pub_key_hex, nullptr);
auto result = convos->erase_1to1(param);
@ -151,6 +165,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getCommunity__Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
@ -165,6 +180,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructCommunity__Ljava_lang_String_2Ljava_lang_String_2_3B(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jbyteArray pub_key) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
@ -177,6 +193,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructCommunity__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
@ -193,6 +210,7 @@ JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseCommunity__Lnetwork_loki_messenger_libsession_1util_util_Conversation_Community_2(JNIEnv *env,
jobject thiz,
jobject open_group) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto deserialized = deserialize_community(env, open_group, convos);
return convos->erase(deserialized);
@ -201,6 +219,7 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseCommunity__Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring base_url, jstring room) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto base_url_chars = env->GetStringUTFChars(base_url, nullptr);
auto room_chars = env->GetStringUTFChars(room, nullptr);
@ -213,6 +232,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getLegacyClosedGroup(
JNIEnv *env, jobject thiz, jstring group_id) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto lgc = convos->get_legacy_group(id_chars);
@ -227,6 +247,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_getOrConstructLegacyGroup(
JNIEnv *env, jobject thiz, jstring group_id) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto lgc = convos->get_or_construct_legacy_group(id_chars);
@ -237,6 +258,7 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_eraseLegacyClosedGroup(
JNIEnv *env, jobject thiz, jstring group_id) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto id_chars = env->GetStringUTFChars(group_id, nullptr);
auto result = convos->erase_legacy_group(id_chars);
@ -248,6 +270,7 @@ JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_erase(JNIEnv *env,
jobject thiz,
jobject conversation) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
auto deserialized = deserialize_any(env, conversation, convos);
if (!deserialized.has_value()) return false;
@ -257,6 +280,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeCommunities(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
return convos->size_communities();
}
@ -264,6 +288,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_sizeLegacyClosedGroups(
JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
return convos->size_legacy_groups();
}
@ -271,6 +296,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_all(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");
@ -286,6 +312,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allOneToOnes(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");
@ -299,6 +326,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allCommunities(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");
@ -312,6 +340,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_ConversationVolatileConfig_allLegacyClosedGroups(
JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto convos = ptrToConvoInfo(env, thiz);
jclass stack = env->FindClass("java/util/Stack");
jmethodID init = env->GetMethodID(stack, "<init>", "()V");

View File

@ -9,6 +9,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_00024Companion_newInstance___3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto* user_groups = new session::config::UserGroups(secret_key, std::nullopt);
@ -24,6 +25,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
@ -41,6 +43,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_util_GroupInfo_00024LegacyGroupInfo_00024Companion_NAME_1MAX_1LENGTH(
JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
return session::config::legacy_group_info::NAME_MAX_LENGTH;
}
@ -50,6 +53,7 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getCommunityInfo(J
jobject thiz,
jstring base_url,
jstring room) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto base_url_bytes = env->GetStringUTFChars(base_url, nullptr);
auto room_bytes = env->GetStringUTFChars(room, nullptr);
@ -71,6 +75,7 @@ JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getLegacyGroupInfo(JNIEnv *env,
jobject thiz,
jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto id_bytes = env->GetStringUTFChars(session_id, nullptr);
auto legacy_group = conf->get_legacy_group(id_bytes);
@ -86,6 +91,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getOrConstructCommunityInfo(
JNIEnv *env, jobject thiz, jstring base_url, jstring room, jstring pub_key_hex) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto base_url_bytes = env->GetStringUTFChars(base_url, nullptr);
auto room_bytes = env->GetStringUTFChars(room, nullptr);
@ -103,6 +109,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_getOrConstructLegacyGroupInfo(
JNIEnv *env, jobject thiz, jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto id_bytes = env->GetStringUTFChars(session_id, nullptr);
auto group = conf->get_or_construct_legacy_group(id_bytes);
@ -114,6 +121,7 @@ extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_set__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_2(
JNIEnv *env, jobject thiz, jobject group_info) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto community_info = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$CommunityGroupInfo");
auto legacy_info = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
@ -132,6 +140,7 @@ extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_erase__Lnetwork_loki_messenger_libsession_1util_util_GroupInfo_2(
JNIEnv *env, jobject thiz, jobject group_info) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto communityInfo = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$CommunityGroupInfo");
auto legacyInfo = env->FindClass("network/loki/messenger/libsession_util/util/GroupInfo$LegacyGroupInfo");
@ -148,6 +157,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_sizeCommunityInfo(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
return conf->size_communities();
}
@ -156,6 +166,7 @@ extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_sizeLegacyGroupInfo(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
return conf->size_legacy_groups();
}
@ -163,6 +174,7 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_sizeLegacyGroupInf
extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_size(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToConvoInfo(env, thiz);
return conf->size();
}
@ -192,6 +204,7 @@ inline jobject iterator_as_java_stack(JNIEnv *env, const session::config::UserGr
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_all(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
jobject all_stack = iterator_as_java_stack(env, conf->begin(), conf->end());
return all_stack;
@ -201,6 +214,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_allCommunityInfo(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
jobject community_stack = iterator_as_java_stack(env, conf->begin_communities(), conf->end());
return community_stack;
@ -210,6 +224,7 @@ extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_allLegacyGroupInfo(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
jobject legacy_stack = iterator_as_java_stack(env, conf->begin_legacy_groups(), conf->end());
return legacy_stack;
@ -220,6 +235,7 @@ JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseCommunity__Lnetwork_loki_messenger_libsession_1util_util_BaseCommunityInfo_2(JNIEnv *env,
jobject thiz,
jobject base_community_info) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto base_community = util::deserialize_base_community(env, base_community_info);
return conf->erase_community(base_community.base_url(),base_community.room());
@ -229,6 +245,7 @@ extern "C"
JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseCommunity__Ljava_lang_String_2Ljava_lang_String_2(
JNIEnv *env, jobject thiz, jstring server, jstring room) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto server_bytes = env->GetStringUTFChars(server, nullptr);
auto room_bytes = env->GetStringUTFChars(room, nullptr);
@ -247,6 +264,7 @@ JNIEXPORT jboolean JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseLegacyGroup(JNIEnv *env,
jobject thiz,
jstring session_id) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
auto session_id_bytes = env->GetStringUTFChars(session_id, nullptr);
bool return_bool = conf->erase_legacy_group(session_id_bytes);

View File

@ -7,6 +7,7 @@ extern "C" {
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B_3B(
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
std::lock_guard lock{util::util_mutex_};
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
auto initial = util::ustring_from_bytes(env, initial_dump);
auto* profile = new session::config::UserProfile(secret_key, std::optional(initial));
@ -23,7 +24,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInsta
JNIEnv* env,
jobject,
jbyteArray secretKey) {
std::lock_guard lock{util::util_mutex_};
auto* profile = new session::config::UserProfile(util::ustring_from_bytes(env, secretKey), std::nullopt);
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
@ -39,6 +40,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setName(
JNIEnv* env,
jobject thiz,
jstring newName) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
auto name_chars = env->GetStringUTFChars(newName, nullptr);
profile->set_name(name_chars);
@ -47,6 +49,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setName(
JNIEXPORT jstring JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
auto name = profile->get_name();
if (name == std::nullopt) return nullptr;
@ -56,6 +59,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jo
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
auto pic = profile->get_profile_pic();
@ -67,6 +71,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, job
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz,
jobject user_pic) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
auto pic = util::deserialize_user_pic(env, user_pic);
auto url = env->GetStringUTFChars(pic.first, nullptr);
@ -80,12 +85,14 @@ extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setNtsPriority(JNIEnv *env, jobject thiz,
jint priority) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
profile->set_nts_priority(priority);
}
extern "C"
JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_getNtsPriority(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto profile = ptrToProfile(env, thiz);
return profile->get_nts_priority();
}

View File

@ -3,6 +3,9 @@
#include <sodium/crypto_sign.h>
namespace util {
std::mutex util_mutex_ = std::mutex();
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str) {
size_t length = from_str.length();
auto jlength = (jsize)length;

View File

@ -10,6 +10,7 @@
#include "session/config/expiring.hpp"
namespace util {
extern std::mutex util_mutex_;
jbyteArray bytes_from_ustring(JNIEnv* env, session::ustring_view from_str);
session::ustring ustring_from_bytes(JNIEnv* env, jbyteArray byteArray);
jobject serialize_user_pic(JNIEnv *env, session::config::profile_pic pic);

View File

@ -26,7 +26,7 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
}
// TODO: time in future to activate (hardcoded to 1st jan 2024 for testing, change before release)
private const val ACTIVATE_TIME = 1704027600
private const val ACTIVATE_TIME = 1690761600000
fun isNewConfigEnabled(forced: Boolean, currentTime: Long) =
forced || currentTime >= ACTIVATE_TIME

View File

@ -219,7 +219,7 @@ class BatchMessageReceiveJob(
if (currentLastSeen > newLastSeen) {
newLastSeen = currentLastSeen
}
if (newLastSeen > 0) {
if (newLastSeen > 0 || currentLastSeen == 0L) {
storage.markConversationAsRead(threadId, newLastSeen, force = true)
}
storage.updateThread(threadId, true)

View File

@ -133,7 +133,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
Log.w(TAG, "No hash returned for the configuration in namespace ${config.configNamespace()}")
return@forEachIndexed
}
Log.d(TAG, "Hash $insertHash returned from store request for new config")
Log.d(TAG, "Hash ${insertHash.take(4)} returned from store request for new config")
// confirm pushed seqno
val thisSeqNo = toPushMessage.seqNo