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

fixes #103

Merged
merged 4 commits into from
Jan 8, 2024
Merged

fixes #103

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
13 changes: 10 additions & 3 deletions src/main/java/com/zoffcc/applications/trifa/HelperMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,25 @@ public static void take_screen_shot_with_selection(final String selected_friend_
public static MainActivity.Companion.send_message_result tox_friend_send_message_wrapper(final String friend_pubkey, int a_TOX_MESSAGE_TYPE, String message, long timestamp_unixtime_seconds)
{
Log.i(TAG, "tox_friend_send_message_wrapper:" + friend_pubkey);
FriendList f = main_get_friend(friend_pubkey);
if (f == null)
{
return null;
}

long friendnum_to_use = tox_friend_by_public_key(friend_pubkey);
boolean need_call_push_url = false;

final long fcap = tox_friend_get_capabilities(friendnum_to_use);
final long fconnstatus = tox_friend_get_connection_status(friendnum_to_use);

boolean msgv1 = true;
if ((fcap & TOX_CAPABILITY_MSGV2) != 0)
if ((f.capabilities & TOX_CAPABILITY_MSGV2) != 0)
{
msgv1 = false;
}
Log.i(TAG, "tox_friend_send_message_wrapper:msgv1=" + msgv1);

Log.i(TAG, "tox_friend_send_message_wrapper:f conn" + fconnstatus);
Log.i(TAG, "tox_friend_send_message_wrapper:f conn=" + fconnstatus);
if (fconnstatus == TOX_CONNECTION_NONE.value)
{
String relay_pubkey = HelperRelay.get_relay_for_friend(friend_pubkey);
Expand Down Expand Up @@ -526,6 +532,7 @@ public static MainActivity.Companion.send_message_result tox_friend_send_message
result.msg_v2 = false;
result.msg_hash_hex = "";
result.msg_hash_v3_hex = bytebuffer_to_hexstring(hash_bytes, true);
Log.i(TAG, "tox_friend_send_message_wrapper:msg_hash_v3_hex=" + result.msg_hash_v3_hex);
result.raw_message_buf_hex = "";

if (need_call_push_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class TRIFAGlobals
public final static int ABSOLUTE_MINIMUM_GLOBAL_VIDEO_BITRATE = 95;

public final static int NORMAL_GLOBAL_INCOMING_AV_BUFFER_MS = 0;
public final static int HIGH_GLOBAL_INCOMING_AV_BUFFER_MS = 500;
public final static int HIGH_GLOBAL_INCOMING_AV_BUFFER_MS = 60;

final static int HIGHER_GLOBAL_AUDIO_BITRATE = 128;
final static int NORMAL_GLOBAL_AUDIO_BITRATE = 16; // 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,28 +519,33 @@ object HelperGeneric {
}
if (result.msg_v2)
{
Log.i(TAG, "send_message_onclick:2: msg_v2=" + m.msg_version)
m.msg_version = 1
} else
{
Log.i(TAG, "send_message_onclick:2: msg_v2=" + m.msg_version)
m.msg_version = 0
}
if (result.msg_hash_hex != null && !result.msg_hash_hex.equals("", true))
{
// msgV2 message -----------
m.msg_id_hash = result.msg_hash_hex
Log.i(TAG, "send_message_onclick:2: msg_id_hash=" + m.msg_id_hash)
// msgV2 message -----------
}
if (result.msg_hash_v3_hex != null && !result.msg_hash_v3_hex.equals("", true))
{
// msgV3 message -----------
m.msg_idv3_hash = result.msg_hash_v3_hex
Log.i(TAG, "send_message_onclick:2: msg_idv3_hash=" + m.msg_idv3_hash)
// msgV3 message -----------
}
if (result.raw_message_buf_hex != null && !result.raw_message_buf_hex.equals("", true))
{
// save raw message bytes of this v2 msg into the database
// we need it if we want to resend it later
m.raw_msgv2_bytes = result.raw_message_buf_hex
Log.i(TAG, "send_message_onclick:2: raw_msgv2_bytes=" + m.raw_msgv2_bytes)
}
// TODO: typing indicator **// stop_self_typing_indicator_s()
var row_id: Long = -1
Expand Down Expand Up @@ -600,11 +605,13 @@ object HelperGeneric {
{
m.resend_count++
update_message_in_db_resend_count(m)
Log.i(TAG, "tox_friend_resend_msgv3_wrapper:1: msg_idv3_hash=" + m.msg_idv3_hash)
return false
}
if (m.msg_idv3_hash.length < TOX_HASH_LENGTH)
{
m.resend_count++
Log.i(TAG, "tox_friend_resend_msgv3_wrapper:2: msg_idv3_hash=" + m.msg_idv3_hash)
update_message_in_db_resend_count(m)
return false
}
Expand Down
31 changes: 23 additions & 8 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ class MainActivity
@JvmStatic
fun android_tox_callback_friend_read_receipt_cb_method(friend_number: Long, message_id: Long)
{
Log.i(TAG, "friend_read_receipt:friend_number=" + friend_number + " message_id=" + message_id)
try
{
val toxpk = tox_friend_get_public_key(friend_number)!!.uppercase()
Expand All @@ -1577,11 +1578,11 @@ class MainActivity
Log.i(TAG, "friend_read_receipt:m:message_id=" + m.message_id + " text=" + m.text + " friendpubkey=" + m.tox_friendpubkey + " read=" + m.read + " direction=" + m.direction);
if (m != null)
{
m.rcvd_timestamp = System.currentTimeMillis()
m.read = true
Log.i(TAG,
"friend_read_receipt:friend:" + get_friend_name_from_num(friend_number) + " message:" + m.text +
" m=" + m);
m.rcvd_timestamp = System.currentTimeMillis()
m.read = true
update_message_in_db_read_rcvd_timestamp_rawmsgbytes(m)
// TODO: update message in UI
}
Expand Down Expand Up @@ -1628,7 +1629,7 @@ class MainActivity
@JvmStatic
fun android_tox_callback_friend_message_cb_method(friend_number: Long, message_type: Int, friend_message: String?, length: Long, msgV3hash_bin: ByteArray?, message_timestamp: Long)
{
// Log.i(TAG, "android_tox_callback_friend_message_cb_method: fn=" + friend_number + " friend_message=" + friend_message)
// Log.i(TAG, "friend_message_cb_method: fn=" + friend_number + " friend_message=" + friend_message)
val toxpk = tox_friend_get_public_key(friend_number)!!.uppercase()
if ((toxpk == null) || (toxpk.equals("-1", true)))
{
Expand All @@ -1651,6 +1652,7 @@ class MainActivity
// HINT: we already have received a message with this hash
// still send the msgV3 high level ACK, and then ignore
Log.i(TAG, "TOX_MESSAGEv3:ignore double message")
// Log.i(TAG, "send_msgv3_high_level_ack:001")
HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string)
return
}
Expand All @@ -1662,7 +1664,8 @@ class MainActivity
return
}

GlobalScope.launch(Dispatchers.IO) {
//GlobalScope.launch(Dispatchers.IO) {
var new_msgv3_cap = 0
if (msgV3hash_bin != null)
{
val got_messages_mirrored = orma!!.selectFromMessage().
Expand All @@ -1672,21 +1675,32 @@ class MainActivity
// msgV3hash_bin + " " + msgV3hash_hex_string);
if (got_messages_mirrored > 0)
{
Log.i(TAG, "update_friend_msgv3_capability:got_messages_mirrored=" + got_messages_mirrored)
update_friend_msgv3_capability(friend_number, 0)
} else
new_msgv3_cap = 0
}
else
{
update_friend_msgv3_capability(friend_number, 1)
new_msgv3_cap = 1
}
}
else
{
// Log.i(TAG, "update_friend_msgv3_capability:hash0=" + msgV3hash_bin + " " + msgV3hash_hex_string);
update_friend_msgv3_capability(friend_number, 0)
new_msgv3_cap = 0
}

if (msgV3hash_hex_string != null)
{
HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string);
// Log.i(TAG, "send_msgv3_high_level_ack:002")
if (new_msgv3_cap == 1)
{
// send high level ack only if the friend actually understand it
// and it's not a mirrored high level ACK
HelperMessage.send_msgv3_high_level_ack(friend_number, msgV3hash_hex_string);
}
try
{
// ("msgv3:"+friend_message)
Expand All @@ -1703,7 +1717,8 @@ class MainActivity
} catch (_: Exception)
{
}
} else
}
else
{
try
{ // ("msgv1:"+friend_message)
Expand All @@ -1721,7 +1736,7 @@ class MainActivity
{
}
}
}
//}
}

@JvmStatic
Expand Down
15 changes: 14 additions & 1 deletion src/main/kotlin/com/zoffcc/applications/trifa/TrifaToxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import org.briarproject.briar.desktop.contact.GroupPeerItem
import set_tox_running_state
import toxdatastore
import unlock_data_dir_input
import java.io.File
import java.nio.ByteBuffer
import java.util.*

Expand Down Expand Up @@ -427,6 +428,18 @@ class TrifaToxService
// sleep(30)
}

if (MainActivity.AUDIO_PCM_DEBUG_FILES)
{
val f = File("/tmp/toxaudio_play.txt")
try
{
f.appendBytes(buf)
} catch (e: Exception)
{
e.printStackTrace()
}
}

update_audio_bar++
if (update_audio_bar >= 1)
{
Expand Down Expand Up @@ -908,7 +921,7 @@ class TrifaToxService
get_friend_name_from_pubkey(m_resend_v1.tox_friendpubkey))
continue
}
Log.i(TAG, "resend_v3_messages:tox_friend_resend_msgv3_wrapper:" + m_resend_v1.text + " : m=" +
Log.i(TAG, "resend_v3_messages:tox_friend_resend_msgv3_wrapper:msg_idv3_hash=" + m_resend_v1.msg_idv3_hash + " text=" + m_resend_v1.text + " : m=" +
m_resend_v1 + " : " + get_friend_name_from_pubkey(m_resend_v1.tox_friendpubkey));
tox_friend_resend_msgv3_wrapper(m_resend_v1)
cur_resend_count_per_iteration++
Expand Down
Loading