unbreak notifications on android ([Pp]ictures) + asset dup; fix sync progres resume logic
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
1d0cb785c1
commit
7cfa9432c8
|
@ -32,7 +32,15 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
private var notificationSimple: String? = null
|
private var notificationSimple: String? = null
|
||||||
private var notificationConversationInfo: String? = null
|
private var notificationConversationInfo: String? = null
|
||||||
|
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
|
// Hack to uncomment and deploy if your device has zombie workers you need to kill
|
||||||
|
// We need a proper solution but this will clear those out for now
|
||||||
|
/*if (notificationSimple == null) {
|
||||||
|
Log.e("FlwtchWorker", "doWork found notificationSimple is null, app has not started, this is a stale thread, terminating")
|
||||||
|
return Result.failure()
|
||||||
|
}*/
|
||||||
|
|
||||||
val method = inputData.getString(KEY_METHOD)
|
val method = inputData.getString(KEY_METHOD)
|
||||||
?: return Result.failure()
|
?: return Result.failure()
|
||||||
val args = inputData.getString(KEY_ARGS)
|
val args = inputData.getString(KEY_ARGS)
|
||||||
|
@ -52,7 +60,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleCwtch(method: String, args: String): Result {
|
private fun handleCwtch(method: String, args: String): Result {
|
||||||
try {
|
|
||||||
val a = JSONObject(args)
|
val a = JSONObject(args)
|
||||||
when (method) {
|
when (method) {
|
||||||
"Start" -> {
|
"Start" -> {
|
||||||
|
@ -66,11 +74,14 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
Log.i("FlwtchWorker.kt", "startCwtch success, starting coroutine AppbusEvent loop...")
|
Log.i("FlwtchWorker.kt", "startCwtch success, starting coroutine AppbusEvent loop...")
|
||||||
val downloadIDs = mutableMapOf<String, Int>()
|
val downloadIDs = mutableMapOf<String, Int>()
|
||||||
while (true) {
|
while (true) {
|
||||||
|
try {
|
||||||
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
||||||
// TODO replace this notification block with the NixNotification manager in dart as it has access to contact names and also needs less working around
|
// TODO replace this notification block with the NixNotification manager in dart as it has access to contact names and also needs less working around
|
||||||
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
||||||
val data = JSONObject(evt.Data)
|
val data = JSONObject(evt.Data)
|
||||||
val handle = data.getString("RemotePeer");
|
val handle = data.getString("RemotePeer");
|
||||||
|
val conversationId = data.getInt("ConversationID").toString();
|
||||||
|
val notificationChannel = if (evt.EventType == "NewMessageFromPeer") handle else conversationId
|
||||||
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
if (data["RemotePeer"] != data["ProfileOnion"]) {
|
||||||
val notification = data["notification"]
|
val notification = data["notification"]
|
||||||
|
|
||||||
|
@ -101,14 +112,16 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
} else if (notification == "ContactInfo") {
|
} else if (notification == "ContactInfo") {
|
||||||
val channelId =
|
val channelId =
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
createMessageNotificationChannel(handle, handle)
|
createMessageNotificationChannel(notificationChannel, notificationChannel)
|
||||||
} else {
|
} else {
|
||||||
// If earlier version channel ID is not used
|
// If earlier version channel ID is not used
|
||||||
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
val loader = FlutterInjector.instance().flutterLoader()
|
val loader = FlutterInjector.instance().flutterLoader()
|
||||||
val key = loader.getLookupKeyForAsset("assets/" + data.getString("Picture"))//"assets/profiles/001-centaur.png")
|
Log.i("FlwtchWorker.kt", "notification for " + evt.EventType + " " + handle + " " + conversationId + " " + channelId)
|
||||||
|
Log.i("FlwtchWorker.kt", data.toString());
|
||||||
|
val key = loader.getLookupKeyForAsset(data.getString("picture"))//"assets/profiles/001-centaur.png")
|
||||||
val fh = applicationContext.assets.open(key)
|
val fh = applicationContext.assets.open(key)
|
||||||
|
|
||||||
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
val clickIntent = Intent(applicationContext, MainActivity::class.java).also { intent ->
|
||||||
|
@ -128,7 +141,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), channelId), newNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -200,8 +213,12 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
intent.putExtra("EventID", evt.EventID)
|
intent.putExtra("EventID", evt.EventID)
|
||||||
LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(intent)
|
LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(intent)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("FlwtchWorker", "Error in handleCwtch: " + e.toString() + " :: " + e.getStackTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"ReconnectCwtchForeground" -> {
|
"ReconnectCwtchForeground" -> {
|
||||||
Cwtch.reconnectCwtchForeground()
|
Cwtch.reconnectCwtchForeground()
|
||||||
}
|
}
|
||||||
|
@ -408,11 +425,8 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.success()
|
return Result.success()
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("FlwtchWorker", "Error in handleCwtch: " + e.toString() + " :: " + e.getStackTrace())
|
|
||||||
return Result.failure()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates an instance of ForegroundInfo which can be used to update the
|
// Creates an instance of ForegroundInfo which can be used to update the
|
||||||
|
|
|
@ -153,6 +153,7 @@ class CwtchNotifier {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "NewMessageFromPeer":
|
case "NewMessageFromPeer":
|
||||||
|
|
||||||
var identifier = int.parse(data["ConversationID"]);
|
var identifier = int.parse(data["ConversationID"]);
|
||||||
var messageID = int.parse(data["Index"]);
|
var messageID = int.parse(data["Index"]);
|
||||||
var timestamp = DateTime.tryParse(data['TimestampReceived'])!;
|
var timestamp = DateTime.tryParse(data['TimestampReceived'])!;
|
||||||
|
|
|
@ -63,9 +63,9 @@ class FlwtchState extends State<Flwtch> with WindowListener {
|
||||||
|
|
||||||
final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
Future<dynamic> shutdownDirect(MethodCall call) {
|
Future<dynamic> shutdownDirect(MethodCall call) async {
|
||||||
print(call);
|
print(call);
|
||||||
cwtch.Shutdown();
|
await cwtch.Shutdown();
|
||||||
return Future.value({});
|
return Future.value({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +247,8 @@ class FlwtchState extends State<Flwtch> with WindowListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() async {
|
||||||
cwtch.Shutdown();
|
await cwtch.Shutdown();
|
||||||
windowManager.removeListener(this);
|
windowManager.removeListener(this);
|
||||||
cwtch.dispose();
|
cwtch.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
|
@ -50,8 +50,8 @@ class RemoteServerInfoState extends ChangeNotifier {
|
||||||
// updateSyncProgressFor point takes a message's time, and updates the server sync progress,
|
// updateSyncProgressFor point takes a message's time, and updates the server sync progress,
|
||||||
// based on that point in time between the precalculated lastPreSyncMessagTime and Now
|
// based on that point in time between the precalculated lastPreSyncMessagTime and Now
|
||||||
void updateSyncProgressFor(DateTime point) {
|
void updateSyncProgressFor(DateTime point) {
|
||||||
var range = lastPreSyncMessagTime.difference(DateTime.now());
|
var range = lastPreSyncMessagTime.toUtc().difference(DateTime.now().toUtc());
|
||||||
var pointFromStart = lastPreSyncMessagTime.difference(point);
|
var pointFromStart = lastPreSyncMessagTime.toUtc().difference(point.toUtc());
|
||||||
syncProgress = pointFromStart.inSeconds / range.inSeconds;
|
syncProgress = pointFromStart.inSeconds / range.inSeconds;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue