Skip to content

Commit

Permalink
Fixed message sizes. Allowed sending pictures without description.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Jan 25, 2023
1 parent aced92d commit 7baf16a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk 21
targetSdk 31
versionCode 16
versionName "1.9.0"
versionName "1.9.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ChatActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, StorageLis
val sendButton = findViewById<AppCompatImageButton>(R.id.send_button)
sendButton.setOnClickListener {
val text: String = editText.text.toString().trim()
if (text.isNotEmpty()) {
if (text.isNotEmpty() || attachmentJson != null) {
editText.text?.clear()
sendMessage(contact.pubkey, text, replyTo)
replyPanel.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ fun readClientHello(dis: DataInputStream, read_address: Boolean): ClientHello? {
count += read
}
size = dis.readInt()
if (size != 32) {
return null
}
val receiver = ByteArray(size)
count = 0
while (count < size) {
Expand All @@ -72,6 +75,9 @@ fun readClientHello(dis: DataInputStream, read_address: Boolean): ClientHello? {
val clientId = dis.readInt()
val address = if (read_address) {
val size = dis.readInt()
if (size != 16) {
return null
}
val buf = ByteArray(size)
dis.read(buf)
InetAddress.getByAddress(buf)
Expand Down Expand Up @@ -213,6 +219,7 @@ fun writeMessage(dos: DataOutputStream, message: Message, filePath: String, stre
val data: ByteArray
var jsonSize = -1
if (message.data.isNotEmpty()) {
var add = 0
when (message.type) {
1 -> {
val meta = JSONObject(String(message.data))
Expand All @@ -221,12 +228,13 @@ fun writeMessage(dos: DataOutputStream, message: Message, filePath: String, stre
val picture = getFileContents(file.absolutePath)
//TODO optimize memory
data = message.data.plus(picture)
add = 4
}
else -> {
data = message.data
}
}
json.put("payloadSize", data.size + 4)
json.put("payloadSize", data.size + add)
} else {
data = message.data
}
Expand Down

0 comments on commit 7baf16a

Please sign in to comment.