From 11e7e58109939ddbccfed346c519b05b2a6ea332 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 23 Feb 2024 15:05:59 -0800 Subject: [PATCH] Fix Notifications for ConversationInfor --- .../kotlin/im/cwtch/flwtch/FlwtchWorker.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt index f9e05bec..66f429ff 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt @@ -23,6 +23,13 @@ import io.flutter.FlutterInjector import org.json.JSONObject import java.nio.file.Files import java.nio.file.Paths +import java.io.FileInputStream + + +import java.io.File + + + class FlwtchWorker(context: Context, parameters: WorkerParameters) : CoroutineWorker(context, parameters) { @@ -138,7 +145,19 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) : Log.i(TAG, "notification for " + evt.EventType + " " + handle + " " + conversationId + " " + channelId) Log.i(TAG, data.toString()); val key = loader.getLookupKeyForAsset(data.getString("picture"))//"assets/profiles/001-centaur.png") - val fh = applicationContext.assets.open(key) + var fh : java.io.InputStream? = null; + try { + fh = applicationContext.assets.open(key) + } catch (e: Exception) { + Log.d("FlwtchWorker->ContactInfo", e.toString() + " :: " + e.getStackTrace()); + } + + try { + val file = File(data.getString("picture")) + fh = FileInputStream(file) + } catch (e: Exception) { + Log.d("FlwtchWorker->ContactInfo", e.toString() + " :: " + e.getStackTrace()); + } val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent -> intent.action = Intent.ACTION_RUN @@ -146,12 +165,12 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) : intent.putExtra("ProfileOnion", data.getString("ProfileOnion")) intent.putExtra("Handle", handle) } - + val image : android.graphics.Bitmap? = if (fh != null) BitmapFactory.decodeStream(fh ) else null; val newNotification = NotificationCompat.Builder(applicationContext, channelId) .setContentTitle(data.getString("Nick")) .setContentText((notificationConversationInfo ?: "New Message From %1").replace("%1", data.getString("Nick"))) - .setLargeIcon(BitmapFactory.decodeStream(fh)) + .setLargeIcon(image) .setSmallIcon(R.mipmap.knott_transparent) .setContentIntent(PendingIntent.getActivity(applicationContext, 1, clickIntent, flags)) .setAutoCancel(true)