Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #83

Merged
merged 12 commits into from
Dec 21, 2023
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: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ buildConfig {
buildConfigField("String", "APP_NAME", "\"${project.name}\"")
buildConfigField("String", "APP_VERSION", provider { "\"${project.version}\"" })
buildConfigField("String", "PROJECT_VERSION", "\"${project.version}\"")
buildConfigField("String", "KOTLIN_VERSION", "\"${kotlin.coreLibrariesVersion}\"")
buildConfigField("String", "COMPOSE_VERSION", "\"${project.findProperty("compose.version")}\"")
try
{
try
Expand Down Expand Up @@ -74,7 +76,7 @@ dependencies {
implementation("com.sksamuel.scrimage:scrimage-core:4.1.1")
implementation("com.sksamuel.scrimage:scrimage-webp:4.1.1")
implementation("com.google.code.gson:gson:2.10.1")
implementation("io.github.alexzhirkevich:qrose:1.0.0-beta02")
implementation("io.github.alexzhirkevich:qrose:1.0.0-beta3")
}

compose.desktop {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true
android.defaults.buildfeatures.buildconfig=true
# Enable kotlin/native experimental memory model
kotlin.native.binary.memoryModel=experimental
compose.version=1.6.0-dev1334
compose.version=1.6.0-dev1340
kotlin.version=1.9.21
multiplatform.version=1.9.21
Binary file modified resources/common/jni-c-toxcore.dll
Binary file not shown.
Binary file modified resources/common/jni-c-toxcore_noise.dll
Binary file not shown.
Binary file modified resources/common/libjni-c-toxcore.jnilib
Binary file not shown.
Binary file modified resources/common/libjni-c-toxcore.so
Binary file not shown.
Binary file modified resources/common/libjni-c-toxcore_noise.jnilib
Binary file not shown.
Binary file modified resources/common/libjni-c-toxcore_noise.so
Binary file not shown.
18 changes: 18 additions & 0 deletions src/main/java/com/zoffcc/applications/sorm/GroupMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,26 @@ public long insert()
Log.i(TAG, "sql=" + insert_pstmt);
}

final long t1 = System.currentTimeMillis();
orma_semaphore_lastrowid_on_insert.acquire();
final long t2 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t2 - t1) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoGroupMessage acquire running long (" + (t2 - t1)+ " ms)");
}
}
final long t3 = System.currentTimeMillis();
insert_pstmt.executeUpdate();
final long t4 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t4 - t3) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoGroupMessage sql running long (" + (t4 - t3)+ " ms)");
}
}
insert_pstmt.close();
ret = get_last_rowid_pstmt();
orma_semaphore_lastrowid_on_insert.release();
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/zoffcc/applications/sorm/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,17 @@ public List<Message> toList()
{
Log.i(TAG, "sql=" + sql);
}
final long t1 = System.currentTimeMillis();
ResultSet rs = statement.executeQuery(sql);
final long t2 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t2 - t1) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "long running (" + (t2 - t1)+ " ms) sql=" + sql);
}
}
final long t3 = System.currentTimeMillis();
while (rs.next())
{
Message out = new Message();
Expand Down Expand Up @@ -249,6 +259,15 @@ public List<Message> toList()

list.add(out);
}
final long t4 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t4 - t3) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "long running (" + (t4 - t3)+ " ms) fetch=" + sql);
}
}


try
{
Expand Down Expand Up @@ -377,10 +396,50 @@ public long insert()
Log.i(TAG, "sql=" + insert_pstmt);
}

final long t1 = System.currentTimeMillis();
orma_semaphore_lastrowid_on_insert.acquire();
final long t2 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t2 - t1) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoMessage acquire running long (" + (t2 - t1)+ " ms)");
}
}

final long t3 = System.currentTimeMillis();
insert_pstmt.executeUpdate();
final long t4 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t4 - t3) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoMessage sql running long (" + (t4 - t3)+ " ms)");
}
}

final long t5 = System.currentTimeMillis();
insert_pstmt.close();
final long t6 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t6 - t5) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoMessage statement close running long (" + (t6 - t5)+ " ms)");
}
}

final long t7 = System.currentTimeMillis();
ret = get_last_rowid_pstmt();
final long t8 = System.currentTimeMillis();
if (ORMA_LONG_RUNNING_TRACE)
{
if ((t8 - t7) > ORMA_LONG_RUNNING_MS)
{
Log.i(TAG, "insertIntoMessage getLastRowId running long (" + (t8 - t7)+ " ms)");
}
}

orma_semaphore_lastrowid_on_insert.release();
}
catch (Exception e)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/zoffcc/applications/sorm/OrmaDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class OrmaDatabase
{
private static final String TAG = "trifa.OrmaDatabase";
final static boolean ORMA_TRACE = false; // set "false" for release builds
final static boolean ORMA_LONG_RUNNING_TRACE = true; // set "false" for release builds
final static long ORMA_LONG_RUNNING_MS = 180;

private static final String CREATE_DB_FILE_SHA256SUM = "LvrHIP4y43BVnVTsd6Y1kAZXqaqKQPnRk3+0HKFP0xA=";
private static final String CREATE_DB_FILE_ON_WINDOWS_SHA256SUM = "5QKQ8Ga1SXdvsiEbf6Ps99KdIJVTNldtI42C3UMI9DM=";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;

import static com.zoffcc.applications.jninotifications.NTFYActivity.jninotifications_notify;
import static com.zoffcc.applications.trifa.MainActivity.getDB_PREF__notifications_active;

public class HelperNotification
{
Expand All @@ -42,8 +43,18 @@ public static void set_resouces_dir(String dir)
resources_dir = dir;
}

public static void displayNotification(String message)
public static void displayNotification(final String message)
{
displayNotification_with_force_option(message, false);
}

public static void displayNotification_with_force_option(final String message, final boolean force)
{
if ((!getDB_PREF__notifications_active()) && (!force))
{
return;
}

try
{
if ((last_message_timestamp + (2 * 1000)) > System.currentTimeMillis())
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/zoffcc/applications/trifa/TRIFAGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class TRIFAGlobals
static boolean bootstrapping = false;
static long global_self_last_went_online_timestamp = -1;
static long global_self_last_went_offline_timestamp = -1;
final static int TOX_BOOTSTRAP_AGAIN_AFTER_OFFLINE_MILLIS =
1000 * 60 * 2; // bootstrap again after 2 minutes offline
// bootstrap again after 30 seconds offline
final static int TOX_BOOTSTRAP_AGAIN_AFTER_OFFLINE_MILLIS = 30 * 1000;

public static final String MY_PACKAGE_NAME = "com.zoffcc.applications.trifa";

Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ val SAVEDATA_PATH_WIDTH = 200.dp
val SAVEDATA_PATH_HEIGHT = 50.dp
val MYTOXID_WIDTH = 200.dp
val MYTOXID_HEIGHT = 50.dp
const val MAX_ONE_ON_ONE_MESSAGES_TO_SHOW = 20000
const val MAX_GROUP_MESSAGES_TO_SHOW = 20000
const val SNACKBAR_TOAST_MS_DURATION: Long = 1000
val ImageloaderDispatcher = Executors.newFixedThreadPool(5).asCoroutineDispatcher()
var global_semaphore_contactlist_ui = CustomSemaphore(1)
Expand Down Expand Up @@ -1025,6 +1027,7 @@ fun App()
ExplainerGroup()
} else
{
Log.i(TAG, "GROUPS -> draw")
load_groupmessages_for_friend(groups.selectedGroupId)
GlobalScope.launch { globalstore.try_clear_unread_group_message_count() }
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
Expand Down Expand Up @@ -1086,9 +1089,9 @@ fun SnackBarToast(message: String, duration_ms: Long = SNACKBAR_TOAST_MS_DURATIO

fun load_messages_for_friend(selectedContactPubkey: String?)
{
Log.i(TAG, "ReceiveMessagesBulkWithClear")
if (selectedContactPubkey != null)
{
Log.i(TAG, "load_messages_for_friend")
try
{
val toxpk = selectedContactPubkey.uppercase()
Expand Down Expand Up @@ -1139,6 +1142,7 @@ fun load_groupmessages_for_friend(selectedGroupId: String?)
{
if (selectedGroupId != null)
{
Log.i(TAG, "load_groupmessages_for_friend")
try
{
val groupid = selectedGroupId.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import com.zoffcc.applications.trifa.TRIFAGlobals.UPDATE_MESSAGE_PROGRESS_SMALL_
import com.zoffcc.applications.trifa.TRIFAGlobals.VFS_FILE_DIR
import com.zoffcc.applications.trifa.TRIFAGlobals.VFS_TMP_FILE_DIR
import com.zoffcc.applications.trifa.TRIFAGlobals.global_last_activity_outgoung_ft_ts
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_connection_status
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_last_went_offline_timestamp
import com.zoffcc.applications.trifa.ToxVars.TOX_CONNECTION
import com.zoffcc.applications.trifa.ToxVars.TOX_FILE_ID_LENGTH
import com.zoffcc.applications.trifa.ToxVars.TOX_HASH_LENGTH
Expand Down Expand Up @@ -137,6 +139,7 @@ class MainActivity
var PREF__ipv6_enabled = 1
var PREF__force_udp_only = 0
@JvmStatic var DB_PREF__open_files_directly = false
@JvmStatic var DB_PREF__notifications_active = true
var incoming_messages_queue: BlockingQueue<String> = LinkedBlockingQueue()
@JvmStatic var video_play_count_frames: Long = 0
@JvmStatic var video_play_last_timestamp: Long = 0
Expand Down Expand Up @@ -1361,16 +1364,20 @@ class MainActivity
@JvmStatic
fun android_tox_callback_self_connection_status_cb_method(a_TOX_CONNECTION: Int)
{
Log.i(TAG, "android_tox_callback_self_connection_status_cb_method: " + a_TOX_CONNECTION)
global_self_connection_status = a_TOX_CONNECTION
// Log.i(TAG, "android_tox_callback_self_connection_status_cb_method: " + a_TOX_CONNECTION)
update_savedata_file_wrapper()
if (a_TOX_CONNECTION == ToxVars.TOX_CONNECTION.TOX_CONNECTION_TCP.value)
{
global_self_last_went_offline_timestamp = -1;
set_tox_online_state("tcp")
} else if (a_TOX_CONNECTION == ToxVars.TOX_CONNECTION.TOX_CONNECTION_UDP.value)
{
global_self_last_went_offline_timestamp = -1;
set_tox_online_state("udp")
} else
{
global_self_last_went_offline_timestamp = System.currentTimeMillis();
set_tox_online_state("offline")
if (avstatestore.state.call_with_friend_pubkey_get() != null)
{
Expand Down
58 changes: 55 additions & 3 deletions src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_peer_get_r
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_iterate
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_iteration_interval
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_kill
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_get_connection_status
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_self_get_friend_list
import com.zoffcc.applications.trifa.MainActivity.Companion.tox_util_friend_resend_message_v2
import com.zoffcc.applications.trifa.TRIFAGlobals.GROUP_ID_LENGTH
import com.zoffcc.applications.trifa.TRIFAGlobals.MAX_TEXTMSG_RESEND_COUNT_OLDMSG_VERSION
import com.zoffcc.applications.trifa.TRIFAGlobals.TOX_BOOTSTRAP_AGAIN_AFTER_OFFLINE_MILLIS
import com.zoffcc.applications.trifa.TRIFAGlobals.USE_MAX_NUMBER_OF_BOOTSTRAP_NODES
import com.zoffcc.applications.trifa.TRIFAGlobals.USE_MAX_NUMBER_OF_BOOTSTRAP_TCP_RELAYS
import com.zoffcc.applications.trifa.TRIFAGlobals.bootstrapping
import com.zoffcc.applications.trifa.TRIFAGlobals.global_last_activity_outgoung_ft_ts
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_connection_status
import com.zoffcc.applications.trifa.TRIFAGlobals.global_self_last_went_offline_timestamp
import contactstore
import globalstore
import grouppeerstore
Expand Down Expand Up @@ -107,12 +112,15 @@ class TrifaToxService
TRIFAGlobals.bootstrapping = true
Log.i(TAG, "bootrapping:set to true")
bootstrap_me()
} // --------------- bootstrap ---------------
}
// --------------- bootstrap ---------------
// --------------- bootstrap ---------------
// --------------- bootstrap ---------------
var tox_iteration_interval_ms = tox_iteration_interval()
Log.i(TAG, "tox_iteration_interval_ms=$tox_iteration_interval_ms")
tox_iterate() // ------- MAIN TOX LOOP ---------------------------------------------------------------
tox_iterate()
global_self_connection_status == tox_self_get_connection_status()
// ------- MAIN TOX LOOP ---------------------------------------------------------------
// ------- MAIN TOX LOOP ---------------------------------------------------------------
// ------- MAIN TOX LOOP ---------------------------------------------------------------
// ------- MAIN TOX LOOP ---------------------------------------------------------------
Expand All @@ -135,7 +143,9 @@ class TrifaToxService
{
e.printStackTrace()
}
tox_iterate() // Log.i(TAG, "=====>>>>> tox_iterate()");
check_if_need_bootstrap_again()
tox_iterate()
// Log.i(TAG, "=====>>>>> tox_iterate()");
tox_iteration_interval_ms = tox_iteration_interval()

// --- send pending 1-on-1 text messages here --------------
Expand Down Expand Up @@ -275,6 +285,47 @@ class TrifaToxService
{
e.printStackTrace()
}

MainActivity.DB_PREF__notifications_active = true
try
{
if (HelperFriend.get_g_opts("DB_PREF__notifications_active") != null)
{
if (HelperFriend.get_g_opts("DB_PREF__notifications_active").equals("false"))
{
MainActivity.DB_PREF__notifications_active = false
}
}
} catch (e: java.lang.Exception)
{
e.printStackTrace()
}
}

private fun check_if_need_bootstrap_again()
{
if (global_self_connection_status == ToxVars.TOX_CONNECTION.TOX_CONNECTION_NONE.value)
{
if (global_self_last_went_offline_timestamp != -1L)
{
if (global_self_last_went_offline_timestamp + TOX_BOOTSTRAP_AGAIN_AFTER_OFFLINE_MILLIS <
System.currentTimeMillis())
{
Log.i(TAG, "offline for too long --> bootstrap again ...")
global_self_last_went_offline_timestamp = System.currentTimeMillis()
bootstrapping = true
Log.i(TAG, "bootrapping:set to true[2]")
try
{
bootstrap_me()
} catch (e: java.lang.Exception)
{
e.printStackTrace()
Log.i(TAG, "bootstrap_me:001:EE:" + e.message)
}
}
}
}
}

companion object
Expand Down Expand Up @@ -389,6 +440,7 @@ class TrifaToxService
// ----- TCP mobile ------
// Log.i(TAG, "add_tcp_relay_single:res=" + MainActivity.add_tcp_relay_single_wrapper("127.0.0.1", 33447, "252E6D7F8168682363BC473C3951357FB2E28BC9A7B7E1F4CB3B302DC331BDAA".substring(0, (TOX_PUBLIC_KEY_SIZE * 2) - 0)));
// ----- TCP mobile ------
bootstrapping = false
}

fun bootstrap_me__obsolete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sealed interface GroupMessageAction

data class GroupMessageState(val groupmessages: SnapshotStateList<UIGroupMessage> = mutableStateListOf())

const val maxGroupMessages = 5000
const val maxGroupMessages = MAX_GROUP_MESSAGES_TO_SHOW
fun groupchatReducer(state: GroupMessageState, action: GroupMessageAction): GroupMessageState = when (action)
{
is GroupMessageAction.ReceiveMessagesBulkWithClear ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sealed interface MessageAction

data class MessageState(var messages: SnapshotStateList<UIMessage> = mutableStateListOf())

const val maxMessages = 5000
const val maxMessages = MAX_ONE_ON_ONE_MESSAGES_TO_SHOW
fun chatReducer(state: MessageState, action: MessageAction): MessageState = when (action)
{
is MessageAction.SendMessagesBulk ->
Expand Down Expand Up @@ -45,7 +45,7 @@ fun chatReducer(state: MessageState, action: MessageAction): MessageState = when
// val m = state.messages
// m.add(action.message)
// m.takeLast(maxMessages)
Log.i(com.zoffcc.applications.trifa.TAG, "MessageAction.ReceiveMessage")
// Log.i(com.zoffcc.applications.trifa.TAG, "MessageAction.ReceiveMessage")
state.copy(messages = (state.messages + action.message).takeLast(maxMessages).toMutableStateList())
}
is MessageAction.Clear ->
Expand Down
Loading
Loading