|
@@ -1,32 +1,20 @@
|
|
|
package io.nexilis.service.core
|
|
|
|
|
|
+import android.content.Context
|
|
|
import android.util.Log
|
|
|
+import io.newuniverse.SDK.nuSDKService
|
|
|
import io.nexilis.service.Service
|
|
|
import io.nexilis.service.apiScope
|
|
|
-import io.nexilis.service.context
|
|
|
import io.nexilis.service.data.entities.Buddy
|
|
|
import io.nexilis.service.data.entities.Message
|
|
|
import io.nexilis.service.data.rooms.ApiRoomDatabase
|
|
|
+import io.nexilis.service.pass
|
|
|
import io.nexilis.service.tag
|
|
|
import kotlinx.coroutines.launch
|
|
|
import org.json.JSONArray
|
|
|
import java.util.zip.ZipInputStream
|
|
|
|
|
|
-class Incoming private constructor() {
|
|
|
-
|
|
|
- companion object {
|
|
|
-
|
|
|
- @Volatile
|
|
|
- private var INSTANCE: Incoming? = null
|
|
|
-
|
|
|
- fun getInstance(): Incoming {
|
|
|
- return INSTANCE ?: synchronized(this) {
|
|
|
- val instance = Incoming()
|
|
|
- INSTANCE = instance
|
|
|
- instance
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+class Incoming(private val context: Context = nuSDKService.getInstance(pass) as Context) {
|
|
|
|
|
|
fun process(data: Data) {
|
|
|
Log.d(tag, "process(${data.code}):$data")
|
|
@@ -40,18 +28,29 @@ class Incoming private constructor() {
|
|
|
"LF" -> {
|
|
|
loginFile(data)
|
|
|
}
|
|
|
+
|
|
|
"A037", "A037A" -> {
|
|
|
pushMySelf(data)
|
|
|
}
|
|
|
+
|
|
|
"A0052", "IBB", "A004" -> {
|
|
|
pushBuddies(data)
|
|
|
}
|
|
|
+
|
|
|
"S0" -> {
|
|
|
pushMessage(data)
|
|
|
}
|
|
|
+
|
|
|
"INQ" -> {
|
|
|
inquiryMessage(data)
|
|
|
}
|
|
|
+
|
|
|
+ "A002" -> {
|
|
|
+ context.getSharedPreferences().getString("pin", "").let {
|
|
|
+ Service.sendAck(it, data.status)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
else -> {
|
|
|
Log.d(tag, "unprocessed:$data")
|
|
|
}
|
|
@@ -260,15 +259,15 @@ class Incoming private constructor() {
|
|
|
try {
|
|
|
val messageId = data.bodies["A18"] ?: ""
|
|
|
if (messageId.isEmpty()) return
|
|
|
+ val me = context.getSharedPreferences().getString("pin", "")
|
|
|
ApiRoomDatabase.getDatabase(context).messageDao().get(messageId).value?.let {
|
|
|
if (it.isNotEmpty()) {
|
|
|
- Service.sendAck(messageId)
|
|
|
+ Service.sendAck(me, data.status)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
val fPin = data.bodies["A00"] ?: ""
|
|
|
val lPin = data.bodies["A01"] ?: ""
|
|
|
- val me = context.getSharedPreferences().getString("pin", "")
|
|
|
val opposite = if (me == fPin) lPin else fPin
|
|
|
ApiRoomDatabase.getDatabase(context).messageDao().insert(
|
|
|
Message(
|
|
@@ -327,7 +326,7 @@ class Incoming private constructor() {
|
|
|
data.bodies["ccid"] ?: ""
|
|
|
)
|
|
|
)
|
|
|
- Service.sendAck(messageId)
|
|
|
+ Service.sendAck(me, data.status)
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(tag, e.message, e)
|
|
|
}
|