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

make chat message boxes behave nicer #40

Merged
merged 2 commits into from
Nov 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class GroupMessage
private static final String TAG = "DB.GroupMessage";

@PrimaryKey(autoincrement = true, auto = true)
long id; // uniqe message id!!
public long id; // uniqe message id!!

@Column(indexed = true, helpers = Column.Helpers.ALL, defaultExpr = "")
@Nullable
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/HelperGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static String bytebuffer_to_hexstring(ByteBuffer in, boolean upper_case)

public static class incoming_group_file_meta_data
{
long rowid;
String message_text;
String path_name;
String file_name;
Expand Down Expand Up @@ -274,6 +275,7 @@ static incoming_group_file_meta_data handle_incoming_group_file(long group_numbe
ret.message_text = m.text;
ret.path_name = m.path_name;
ret.file_name = m.file_name;
ret.rowid = row_id;

return ret; // return metadata
}
Expand Down
40 changes: 23 additions & 17 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fun App()
VerticalDivider()
Column(Modifier.fillMaxSize()) {
Row(modifier = Modifier.fillMaxWidth().height(main_top_tab_height)) {
Column() {
Column{
Row(Modifier.wrapContentHeight(), Arrangement.spacedBy(5.dp)) {
Button(modifier = Modifier.width(140.dp), onClick = { // start/stop tox button
if (tox_running_state == "running")
Expand Down Expand Up @@ -320,10 +320,12 @@ fun App()
}
)
val current_vplayfps_state by avstatestorevplayfpsstate.stateFlow.collectAsState()
/*
Text(if (current_vplayfps_state.videoplayfps_state == 0) "" else (" fps: " + current_vplayfps_state.videoplayfps_state),
fontSize = 13.sp,
modifier = Modifier.height(20.dp),
maxLines = 1)
*/
Text(" " + current_vplayfps_state.incomingResolution,
fontSize = 13.sp,
maxLines = 1)
Expand Down Expand Up @@ -394,9 +396,11 @@ fun App()
update = {Log.i(TAG, "update2: " + video_out_box_small) }
)
val current_vicfps_state by avstatestorevcapfpsstate.stateFlow.collectAsState()
/*
Text(if (current_vicfps_state.videocapfps_state == 0) "" else ("fps: " + current_vicfps_state.videocapfps_state),
fontSize = 13.sp,
maxLines = 1)
*/
Text("" + current_vicfps_state.sourceResolution,
fontSize = 13.sp,
maxLines = 1)
Expand Down Expand Up @@ -695,19 +699,17 @@ fun App()
UiMode.CONTACTS ->
{
val focusRequester = remember { FocusRequester() }
val contacts by contactstore.stateFlow.collectAsState()
Row(modifier = Modifier.fillMaxWidth()) {
val contacts by contactstore.stateFlow.collectAsState()
ContactList(contactList = contacts)
VerticalDivider()
if (contacts.selectedContactPubkey == null)
{
ExplainerChat()
} else
{
messagestore.send(MessageAction.Clear(0))
// GlobalScope.launch {
load_messages_for_friend(contacts.selectedContactPubkey)
//}
Log.i(TAG, "CONTACTS -> draw")
load_messages_for_friend(contacts.selectedContactPubkey)
ChatAppWithScaffold(focusRequester = focusRequester, contactList = contacts, ui_scale = ui_scale)
LaunchedEffect(contacts.selectedContactPubkey) {
focusRequester.requestFocus()
Expand Down Expand Up @@ -735,10 +737,7 @@ fun App()
ExplainerGroup()
} else
{
groupmessagestore.send(GroupMessageAction.ClearGroup(0))
// GlobalScope.launch {
load_groupmessages_for_friend(groups.selectedGroupId)
//}
load_groupmessages_for_friend(groups.selectedGroupId)
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
LaunchedEffect(groups.selectedGroupId) {
groupfocusRequester.requestFocus()
Expand All @@ -764,13 +763,14 @@ fun App()

fun load_messages_for_friend(selectedContactPubkey: String?)
{
Log.i(TAG, "ReceiveMessagesBulkWithClear")
if (selectedContactPubkey != null)
{
try
{
val toxk = selectedContactPubkey.uppercase()
val toxpk = selectedContactPubkey.uppercase()
val uimessages = ArrayList<UIMessage>()
val messages = orma!!.selectFromMessage().tox_friendpubkeyEq(toxk).orderBySent_timestampAsc().toList()
val messages = orma!!.selectFromMessage().tox_friendpubkeyEq(toxpk).orderBySent_timestampAsc().toList()
messages.forEach() { // 0 -> msg received, 1 -> msg sent
when (it.direction)
{
Expand All @@ -791,8 +791,7 @@ fun load_messages_for_friend(selectedContactPubkey: String?)
}
}
// Thread.sleep(4000)
// Log.i(TAG, "LLLLLLLLLLLLLL")
messagestore.send(MessageAction.ReceiveMessagesBulkWithClear(uimessages, toxk))
messagestore.send(MessageAction.ReceiveMessagesBulkWithClear(uimessages, toxpk))
} catch (e: Exception)
{
e.printStackTrace()
Expand All @@ -806,6 +805,8 @@ fun load_groupmessages_for_friend(selectedGroupId: String?)
{
try
{
val groupid = selectedGroupId.lowercase()
val uigroupmessages = ArrayList<UIGroupMessage>()
val messages = orma!!.selectFromGroupMessage().group_identifierEq(selectedGroupId).orderBySent_timestampAsc().toList()
messages.forEach() { // 0 -> msg received, 1 -> msg sent
when (it.direction)
Expand All @@ -815,19 +816,24 @@ fun load_groupmessages_for_friend(selectedGroupId: String?)
val friend_user = User(it.tox_group_peername + " / " + PubkeyShort(it.tox_group_peer_pubkey), picture = "friend_avatar.png", toxpk = it.tox_group_peer_pubkey.uppercase(), color = ColorProvider.getColor(true, it.tox_group_peer_pubkey.uppercase()))
when (it.TRIFA_MESSAGE_TYPE)
{
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value -> groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(groupmessage = UIGroupMessage(user = friend_user, timeMs = it.rcvd_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath)))
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value -> groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(groupmessage = UIGroupMessage(user = friend_user, timeMs = it.rcvd_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath)))
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value ->
uigroupmessages.add(UIGroupMessage(message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.rcvd_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))
TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value ->
uigroupmessages.add(UIGroupMessage(message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = friend_user, timeMs = it.rcvd_timestamp, text = it.text, toxpk = it.tox_group_peer_pubkey.uppercase(), groupId = it.group_identifier.lowercase(), trifaMsgType = it.TRIFA_MESSAGE_TYPE, filename_fullpath = it.filename_fullpath))

}
}
1 ->
{
groupmessagestore.send(GroupMessageAction.SendGroupMessage(UIGroupMessage(myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = myUser.toxpk, groupId = it.group_identifier.lowercase(), trifaMsgType = TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value, filename_fullpath = null)))
uigroupmessages.add(UIGroupMessage(message_id_tox = it.message_id_tox, msgDatabaseId = it.id, user = myUser, timeMs = it.sent_timestamp, text = it.text, toxpk = myUser.toxpk, groupId = it.group_identifier.lowercase(), trifaMsgType = TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value, filename_fullpath = null))
}
else ->
{
}
}
}
// Thread.sleep(4000)
groupmessagestore.send(GroupMessageAction.ReceiveMessagesBulkWithClear(uigroupmessages, groupid))
} catch (e: Exception)
{
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ data class AVState(val a: Int)
{
override fun onSuccess(width: Long, height: Long, source_width: Long, source_height: Long, pts: Long, fps: Int, source_format: Int)
{
Log.i(TAG, "ffmpeg open video capture onSuccess: $width $height $pts FPS: $fps Source Format: "
+ AVActivity.ffmpegav_video_source_format_name.value_str(source_format))
// Log.i(TAG, "ffmpeg open video capture onSuccess: $width $height $pts FPS: $fps Source Format: "
// + AVActivity.ffmpegav_video_source_format_name.value_str(source_format))
if (current_video_in_fps_get() != fps) {
current_video_in_fps_set(fps)
avstatestorevcapfpsstate.update(fps)
Expand Down Expand Up @@ -617,7 +617,7 @@ fun CoroutineScope.createAVStateStoreVideoCaptureFpsState(): AVStateStoreVideoCa
override fun update(fps: Int)
{
launch {
mutableStateFlow.value = state.copy(videocapfps_state = fps)
// mutableStateFlow.value = state.copy(videocapfps_state = fps)
}
}
override fun updateSourceResolution(sourceResolution: String)
Expand Down Expand Up @@ -653,7 +653,7 @@ fun CoroutineScope.createAVStateStoreVideoPlayFpsState(): AVStateStoreVideoPlayF
override fun update(fps: Int)
{
launch {
mutableStateFlow.value = state.copy(videoplayfps_state = fps)
//mutableStateFlow.value = state.copy(videoplayfps_state = fps)
}
}
override fun updateIncomingResolution(incomingResolution: String)
Expand Down
20 changes: 17 additions & 3 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1783,12 +1783,18 @@ class MainActivity

val group_id = tox_group_by_groupnum__wrapper(group_number).lowercase()
val tox_peerpk = tox_group_peer_get_public_key(group_number, peer_id)!!.uppercase()
val message_id_hex = fourbytes_of_long_to_hex(message_id)
val message_timestamp = System.currentTimeMillis()
received_groupmessage_to_db(tox_peerpk = tox_peerpk!!, groupid = group_id, message_timestamp = message_timestamp, group_message = message_orig, message_id = message_id)
val msg_dbid = received_groupmessage_to_db(tox_peerpk = tox_peerpk!!, groupid = group_id, message_timestamp = message_timestamp, group_message = message_orig, message_id = message_id)
val peernum = tox_group_peer_by_public_key(group_number, tox_peerpk)
val fname = tox_group_peer_get_name(group_number, peernum)
val peer_user = User(fname + " / " + PubkeyShort(tox_peerpk), picture = "friend_avatar.png", toxpk = tox_peerpk.uppercase(), color = ColorProvider.getColor(true, tox_peerpk.uppercase()))
groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(UIGroupMessage(peer_user, timeMs = message_timestamp, message_orig!!, toxpk = tox_peerpk, groupId = group_id!!.lowercase(), trifaMsgType = TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value, filename_fullpath = null)))
groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(
UIGroupMessage(
message_id_tox = message_id_hex, msgDatabaseId = msg_dbid,
user = peer_user, timeMs = message_timestamp, text = message_orig!!,
toxpk = tox_peerpk, groupId = group_id!!.lowercase(),
trifaMsgType = TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value, filename_fullpath = null)))
}

@JvmStatic
Expand Down Expand Up @@ -2022,7 +2028,15 @@ class MainActivity
if (incoming_group_file_meta_data != null)
{
val peer_user = User(fname + " / " + PubkeyShort(tox_peerpk), picture = "friend_avatar.png", toxpk = tox_peerpk.uppercase(), color = ColorProvider.getColor(true, tox_peerpk.uppercase()))
groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(UIGroupMessage(peer_user, timeMs = msg_timestamp, incoming_group_file_meta_data.message_text, toxpk = tox_peerpk, groupId = group_id!!.lowercase(), trifaMsgType = TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value, filename_fullpath = incoming_group_file_meta_data.path_name + incoming_group_file_meta_data.file_name)))
groupmessagestore.send(GroupMessageAction.ReceiveGroupMessage(
UIGroupMessage(
message_id_tox = "", msgDatabaseId = incoming_group_file_meta_data.rowid,
user = peer_user, timeMs = msg_timestamp,
text = incoming_group_file_meta_data.message_text,
toxpk = tox_peerpk, groupId = group_id!!.lowercase(),
trifaMsgType = TRIFA_MSG_TYPE.TRIFA_MSG_FILE.value,
filename_fullpath = incoming_group_file_meta_data.path_name +
incoming_group_file_meta_data.file_name)))
}
} else
{ // Log.i(TAG, "group_custom_packet_cb:wrong signature 2");
Expand Down
20 changes: 13 additions & 7 deletions src/main/kotlin/com/zoffcc/applications/trifa2/ChatApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.zoffcc.applications.trifa.AVState
import com.zoffcc.applications.trifa.HelperGroup
import com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper
import com.zoffcc.applications.trifa.Log
import com.zoffcc.applications.trifa.MainActivity
Expand Down Expand Up @@ -159,14 +160,13 @@ fun GroupAppWithScaffold(focusRequester: FocusRequester, displayTextField: Boole
@Composable
fun ChatApp(focusRequester: FocusRequester, displayTextField: Boolean = true, selectedContactPubkey: String?, ui_scale: Float)
{
val state by messagestore.stateFlow.collectAsState()
Theme {
Surface {
Box(modifier = Modifier.fillMaxSize()) {
Image(painterResource("background.jpg"), modifier = Modifier.fillMaxSize(), contentDescription = null, contentScale = ContentScale.Crop)
Column(modifier = Modifier.fillMaxSize()) {
Box(Modifier.weight(1f)) {
Messages(state.messages, ui_scale)
Messages(ui_scale, selectedContactPubkey)
}
Row(modifier = Modifier.fillMaxWidth().height(MESAGE_INPUT_LINE_HEIGHT)) {
if (displayTextField)
Expand Down Expand Up @@ -213,14 +213,13 @@ fun ChatApp(focusRequester: FocusRequester, displayTextField: Boolean = true, se
@Composable
fun GroupApp(focusRequester: FocusRequester, displayTextField: Boolean = true, selectedGroupId: String?, ui_scale: Float)
{
val state by groupmessagestore.stateFlow.collectAsState()
Theme {
Surface {
Box(modifier = Modifier.fillMaxSize()) {
Image(painterResource("background.jpg"), modifier = Modifier.fillMaxSize(), contentDescription = null, contentScale = ContentScale.Crop)
Column(modifier = Modifier.fillMaxSize()) {
Box(Modifier.weight(1f)) {
GroupMessages(state.groupmessages, ui_scale = ui_scale)
GroupMessages(ui_scale = ui_scale, selectedGroupId)
}
if (displayTextField)
{
Expand All @@ -230,9 +229,16 @@ fun GroupApp(focusRequester: FocusRequester, displayTextField: Boolean = true, s
val message_id: Long = tox_group_send_message(groupnum, ToxVars.TOX_MESSAGE_TYPE.TOX_MESSAGE_TYPE_NORMAL.value, text)
if (message_id >= 0)
{
MainActivity.sent_groupmessage_to_db(groupid = selectedGroupId, message_timestamp = timestamp, group_message = text, message_id = message_id )
groupmessagestore.send(GroupMessageAction.SendGroupMessage(UIGroupMessage(myUser, timeMs = timestamp, text, toxpk = myUser.toxpk, groupId = selectedGroupId!!.lowercase(),
trifaMsgType = TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value, filename_fullpath = null)))
val message_id_hex = HelperGroup.fourbytes_of_long_to_hex(message_id)
val db_msgid = MainActivity.sent_groupmessage_to_db(groupid = selectedGroupId, message_timestamp = timestamp, group_message = text, message_id = message_id )
groupmessagestore.send(GroupMessageAction.SendGroupMessage(
UIGroupMessage(
message_id_tox = message_id_hex, msgDatabaseId = db_msgid,
user = myUser, timeMs = timestamp, text = text,
toxpk = myUser.toxpk,
groupId = selectedGroupId!!.lowercase(),
trifaMsgType = TRIFAGlobals.TRIFA_MSG_TYPE.TRIFA_MSG_TYPE_TEXT.value,
filename_fullpath = null)))
}
}
}
Expand Down
Loading
Loading