Skip to content

Commit

Permalink
WIP got files and voices to work, need to get geolocation to work, ne…
Browse files Browse the repository at this point in the history
…ed to fix bug when uri isn't available

Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Jan 25, 2024
1 parent 5594ebe commit c21c863
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4178,37 +4178,47 @@ class ChatActivity :
fun shareToNotes(message: ChatMessage, roomToken: String) {
val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
val type = message.getCalculateMessageType()
val filename = message.selectedIndividualHashMap!!["name"]
path = applicationContext.cacheDir.absolutePath + "/" + filename
val shareUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID,
File(path)
)
Log.d("Julius", "uploadFile called with $roomToken")
var shareUri: Uri? = null
if(message.hasFileAttachment()) {
val filename = message.selectedIndividualHashMap!!["name"]
path = applicationContext.cacheDir.absolutePath + "/" + filename

// TODO implementation somewhat works, figure another way
// perhaps since all file messages are already uploaded, it could be a matter of using
// the copy function or the share function, instead of the upload function
shareUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID,
File(path)
)

this.grantUriPermission(
applicationContext.packageName,
shareUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
)

Log.d("Julius", "shareUri: $shareUri")
}

// Note: this implementation might result in duplicated files being uploaded, which could lead to complications
// but I want to see if this works
// TODO check if URI exists, if not, then file isn't downloaded to cache yet
Log.d("Julius", "uploadFile called with $roomToken")
when (type) {
ChatMessage.MessageType.VOICE_MESSAGE ->
uploadFile(shareUri.toString(), true, token = roomToken)
ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE ->
uploadFile(shareUri.toString(), false, token = roomToken)
ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE -> { /* TODO implement this */ }
ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE -> {
val caption = if(message.message != "{file}") message.message else ""
uploadFile(shareUri.toString(), false, caption!!, roomToken)
}
ChatMessage.MessageType.SINGLE_NC_GEOLOCATION_MESSAGE -> { /* TODO implement this api func in MVVM */ }
ChatMessage.MessageType.REGULAR_TEXT_MESSAGE -> {
chatViewModel.shareToNotes(
credentials!!,
ApiUtils.getUrlForChat(apiVersion, conversationUser!!.baseUrl, roomToken),
message.message!!,
conversationUser!!.displayName!!
)
}
else -> {}
}

// chatViewModel.shareToNotes(
// credentials!!,
// ApiUtils.getUrlForChat(apiVersion, conversationUser!!.baseUrl, roomToken),
// message.message!!,
// conversationUser!!.displayName!!
// )
}

fun openInFilesApp(message: ChatMessage) {
Expand Down

0 comments on commit c21c863

Please sign in to comment.