Fix Notifications for ConversationInfor

This commit is contained in:
Sarah Jamie Lewis 2024-02-23 15:05:59 -08:00
parent 5627f6a438
commit 11e7e58109
Signed by: sarah
GPG Key ID: F27FD21A270837EF
1 changed files with 22 additions and 3 deletions

View File

@ -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)