|
@@ -6,6 +6,7 @@ import android.app.NotificationChannel
|
|
import android.app.NotificationManager
|
|
import android.app.NotificationManager
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
|
+import android.util.Log
|
|
import androidx.annotation.StringRes
|
|
import androidx.annotation.StringRes
|
|
import androidx.core.app.NotificationCompat
|
|
import androidx.core.app.NotificationCompat
|
|
import androidx.work.CoroutineWorker
|
|
import androidx.work.CoroutineWorker
|
|
@@ -15,24 +16,94 @@ import androidx.work.WorkerParameters
|
|
import androidx.work.workDataOf
|
|
import androidx.work.workDataOf
|
|
import io.nexilis.service.R
|
|
import io.nexilis.service.R
|
|
import io.nexilis.service.Service
|
|
import io.nexilis.service.Service
|
|
|
|
+import io.nexilis.service.data.rooms.ApiRoomDatabase
|
|
|
|
+import io.nexilis.service.tag
|
|
|
|
+import java.io.File
|
|
|
|
|
|
-class Outgoing(context: Context, parameters: WorkerParameters) :
|
|
|
|
|
|
+class Outgoing(private val context: Context, parameters: WorkerParameters) :
|
|
CoroutineWorker(context, parameters) {
|
|
CoroutineWorker(context, parameters) {
|
|
override suspend fun doWork(): Result {
|
|
override suspend fun doWork(): Result {
|
|
try {
|
|
try {
|
|
inputData.getString("data")?.let {
|
|
inputData.getString("data")?.let {
|
|
- Service.sendSync(it)?.let { data ->
|
|
|
|
- return Result.success(
|
|
|
|
- workDataOf(
|
|
|
|
- "message_id" to data.bodies["A18"],
|
|
|
|
- "opposite_pin" to data.bodies["A01"],
|
|
|
|
- "status" to data.bodies["A15"]?.toInt()
|
|
|
|
- )
|
|
|
|
|
|
+ ApiRoomDatabase.getDatabase(context).messageDao().getSync(it)?.let { message ->
|
|
|
|
+ val bodies = mutableMapOf(
|
|
|
|
+ "A18" to message.message_id,
|
|
|
|
+ "A00" to message.f_pin,
|
|
|
|
+ "A01" to message.l_pin,
|
|
|
|
+ "A19" to message.server_date.toString(),
|
|
|
|
+ "lcltm" to message.local_timestamp.toString(),
|
|
|
|
+ "A06" to message.message_scope_id,
|
|
|
|
+ "A15" to message.status,
|
|
|
|
+ "A07" to message.message_text.toStupidString(),
|
|
|
|
+ "A118" to message.credential,
|
|
|
|
+ "A149" to message.attachment_flag.toString(),
|
|
|
|
+ "A52" to message.blog_id,
|
|
|
|
+ "ics" to message.is_consult.toString(),
|
|
|
|
+ "icc" to message.is_call_center.toString(),
|
|
|
|
+ "ccid" to message.call_center_id,
|
|
|
|
+ "iwm" to message.is_work_mode.toString(),
|
|
|
|
+ "Bf" to message.read_receipts.toString()
|
|
|
|
+ )
|
|
|
|
+ if (message.message_scope_id == "5") {
|
|
|
|
+ bodies["BR"] = message.f_display_name
|
|
|
|
+ }
|
|
|
|
+ if (message.contact.isNotEmpty()) {
|
|
|
|
+ bodies["A116"] = message.contact
|
|
|
|
+ }
|
|
|
|
+ if (message.image_id.isNotEmpty()) {
|
|
|
|
+ bodies["A57"] = message.image_id
|
|
|
|
+ }
|
|
|
|
+ if (message.audio_id.isNotEmpty()) {
|
|
|
|
+ bodies["A63"] = message.audio_id
|
|
|
|
+ }
|
|
|
|
+ if (message.video_id.isNotEmpty()) {
|
|
|
|
+ bodies["A47"] = message.video_id
|
|
|
|
+ }
|
|
|
|
+ if (message.file_id.isNotEmpty()) {
|
|
|
|
+ bodies["BN"] = message.file_id
|
|
|
|
+ }
|
|
|
|
+ if (message.thumb_id.isNotEmpty()) {
|
|
|
|
+ bodies["A74"] = message.thumb_id
|
|
|
|
+ }
|
|
|
|
+ if (message.reff_id.isNotEmpty()) {
|
|
|
|
+ bodies["A121"] = message.reff_id
|
|
|
|
+ }
|
|
|
|
+ if (message.chat_id.isNotEmpty()) {
|
|
|
|
+ bodies["BA"] = message.chat_id
|
|
|
|
+ }
|
|
|
|
+ if (message.broadcast_flag > 0) {
|
|
|
|
+ bodies["B4"] = message.broadcast_flag.toString()
|
|
|
|
+ }
|
|
|
|
+ val data = Data(
|
|
|
|
+ code = "S0",
|
|
|
|
+ status = message.message_id,
|
|
|
|
+ f_pin = message.f_pin,
|
|
|
|
+ bodies = bodies
|
|
)
|
|
)
|
|
|
|
+ Log.d(tag, "message.image_id:${message.image_id}")
|
|
|
|
+ if (message.image_id.isNotEmpty()) {
|
|
|
|
+ val upload = Network().upload(
|
|
|
|
+ "https://digixplatform.com/uploader",
|
|
|
|
+ File(context.filesDir, message.image_id)
|
|
|
|
+ )
|
|
|
|
+ if (!upload) {
|
|
|
|
+ Log.d(tag, "Failed to upload image:${message.message_id}")
|
|
|
|
+ return Result.retry()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Service.sendSync(data)?.let { r ->
|
|
|
|
+ return Result.success(
|
|
|
|
+ workDataOf(
|
|
|
|
+ "message_id" to r.bodies["A18"],
|
|
|
|
+ "opposite_pin" to r.bodies["A01"],
|
|
|
|
+ "status" to r.bodies["A15"]?.toInt()
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
- Result.failure()
|
|
|
|
|
|
+ return Result.failure()
|
|
}
|
|
}
|
|
return Result.retry()
|
|
return Result.retry()
|
|
}
|
|
}
|