|
@@ -3,9 +3,16 @@ package io.nexilis.service.core
|
|
|
import android.Manifest
|
|
|
import android.content.Context
|
|
|
import android.content.pm.PackageManager
|
|
|
+import android.graphics.drawable.BitmapDrawable
|
|
|
+import android.net.Uri
|
|
|
import android.util.Log
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
import androidx.core.app.NotificationManagerCompat
|
|
|
+import androidx.core.app.Person
|
|
|
+import androidx.core.graphics.drawable.IconCompat
|
|
|
+import coil.ImageLoader
|
|
|
+import coil.request.ImageRequest
|
|
|
+import coil.transform.CircleCropTransformation
|
|
|
import com.google.android.gms.tasks.OnCompleteListener
|
|
|
import com.google.firebase.messaging.FirebaseMessaging
|
|
|
import io.nexilis.service.Api
|
|
@@ -371,7 +378,7 @@ class Incoming(private val context: Context) {
|
|
|
val messageId = data.bodies["A18"] ?: ""
|
|
|
if (messageId.isEmpty()) return
|
|
|
val me = context.getSharedPreferences().getString("pin", "")
|
|
|
- ApiRoomDatabase.getDatabase(context).messageDao().get(messageId).value?.let {
|
|
|
+ ApiRoomDatabase.getDatabase(context).messageDao().getSync(messageId)?.let {
|
|
|
Service.sendAck(me, data.status)
|
|
|
return
|
|
|
}
|
|
@@ -380,6 +387,12 @@ class Incoming(private val context: Context) {
|
|
|
val opposite = if (me == fPin) lPin else fPin
|
|
|
val scope = data.bodies["A06"] ?: "3"
|
|
|
val chatId = data.bodies["BA"] ?: ""
|
|
|
+ val imageId = data.bodies["A57"]
|
|
|
+ var uri: Uri? = null
|
|
|
+ Log.d(tag, "data.media:${data.media.size}")
|
|
|
+ imageId?.let { fileName ->
|
|
|
+ uri = Network().download(context, "https://digixplatform.com/filepalio/image/$fileName")
|
|
|
+ }
|
|
|
ApiRoomDatabase.getDatabase(context).messageDao().insert(
|
|
|
Message(
|
|
|
messageId,
|
|
@@ -439,7 +452,7 @@ class Incoming(private val context: Context) {
|
|
|
)
|
|
|
if (scope == "4") {
|
|
|
val id = chatId.ifEmpty { lPin }
|
|
|
- ApiRoomDatabase.getDatabase(context).groupMemberDao().get(id).value?.let {
|
|
|
+ ApiRoomDatabase.getDatabase(context).groupMemberDao().getSync(id)?.let {
|
|
|
it.forEach { member ->
|
|
|
ApiRoomDatabase.getDatabase(context).messageStatusDao().insert(
|
|
|
MessageStatus(
|
|
@@ -478,12 +491,27 @@ class Incoming(private val context: Context) {
|
|
|
return@with
|
|
|
}
|
|
|
val buddy = ApiRoomDatabase.getDatabase(context).buddyDao().getBuddySync(opposite)
|
|
|
+ ?: return@with
|
|
|
Log.d(tag, "getBuddy:${buddy}")
|
|
|
+ val request = ImageRequest.Builder(context)
|
|
|
+ .addHeader("User-Agent", "Mozilla/5.0")
|
|
|
+ .addHeader("Cookie", "PHPSESSID=123;MOBILE=123")
|
|
|
+ .data("https://digixplatform.com/filepalio/image/${buddy.image_id}")
|
|
|
+ .transformations(CircleCropTransformation())
|
|
|
+ .build()
|
|
|
+ val drawable = ImageLoader(context).execute(request).drawable as BitmapDrawable
|
|
|
+ val user = Person.Builder()
|
|
|
+ .setIcon(IconCompat.createWithBitmap(drawable.bitmap))
|
|
|
+ .setName("${buddy.first_name} ${buddy.last_name}".trim())
|
|
|
+ .build()
|
|
|
notify(
|
|
|
112346,
|
|
|
ChatNotification(context).getNotification(
|
|
|
- "${buddy.first_name} ${buddy.last_name}".trim(),
|
|
|
- data.bodies["A07"]?.toNormalString() ?: ""
|
|
|
+ user,
|
|
|
+ "",
|
|
|
+ data.bodies["A07"]?.toNormalString() ?: "",
|
|
|
+ data.bodies["A19"]?.toLong() ?: System.currentTimeMillis(),
|
|
|
+ uri
|
|
|
)
|
|
|
)
|
|
|
}
|
|
@@ -496,11 +524,11 @@ class Incoming(private val context: Context) {
|
|
|
try {
|
|
|
val messageId = data.bodies["A18"] ?: ""
|
|
|
if (messageId.isEmpty()) return
|
|
|
- ApiRoomDatabase.getDatabase(context).messageDao().get(messageId).value?.let {
|
|
|
+ ApiRoomDatabase.getDatabase(context).messageDao().getSync(messageId)?.let {
|
|
|
Service.sendAsync(data.responseOk())
|
|
|
return
|
|
|
}
|
|
|
- Service.sendAsync(data.responseNok())
|
|
|
+ Service.sendAsync(data.responseOk())
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(tag, e.message, e)
|
|
|
}
|