-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2848 from BlueBubblesApp/development
v1.15.0
- Loading branch information
Showing
47 changed files
with
1,340 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
android/app/src/main/kotlin/com/bluebubbles/messaging/UnifiedPushReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.bluebubbles.messaging | ||
|
||
import com.bluebubbles.messaging.services.backend_ui_interop.DartWorkManager | ||
import com.bluebubbles.messaging.utils.Utils | ||
import com.google.gson.Gson | ||
import com.google.gson.JsonElement | ||
import com.google.gson.reflect.TypeToken | ||
|
||
import org.unifiedpush.android.connector.MessagingReceiver | ||
import io.flutter.embedding.engine.dart.DartExecutor | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.core.os.bundleOf | ||
|
||
class UnifiedPushReceiver : MessagingReceiver() { | ||
companion object { | ||
const val tag: String = "UnifiedPushReceiver" | ||
} | ||
|
||
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { | ||
Log.d(tag, "New endpoint: $endpoint") | ||
|
||
val data = HashMap<String, Any?>(); | ||
data["endpoint"] = endpoint; | ||
DartWorkManager.createWorker(context, "unifiedpush-settings", data) {} | ||
} | ||
|
||
override fun onRegistrationFailed(context: Context, instance: String) { | ||
Log.d(tag, "Registration Failed") | ||
val data = HashMap<String, Any?>(); | ||
data["endpoint"] = ""; | ||
DartWorkManager.createWorker(context, "unifiedpush-settings", data) {} | ||
} | ||
|
||
override fun onUnregistered(context: Context, instance: String) { | ||
Log.d(tag, "Unregistered endpoint") | ||
val data = HashMap<String, Any?>(); | ||
data["endpoint"] = ""; | ||
DartWorkManager.createWorker(context, "unifiedpush-settings", data) {} | ||
} | ||
|
||
inline fun <reified T> Gson.fromJson(json: String) = fromJson<T>(json, object: TypeToken<T>() {}.type) | ||
|
||
override fun onMessage(context: Context, payload: ByteArray, instance: String) { | ||
val applicationContext = context.getApplicationContext() | ||
val msg = payload.toString(Charsets.UTF_8) | ||
val gson: Gson = Gson() | ||
val json: Map<String, JsonElement> = gson.fromJson(msg) | ||
val type: String | ||
try { | ||
type = json.get("type")?.getAsString() ?: return | ||
} catch (e: UnsupportedOperationException) { | ||
Log.d(tag, "Invalid message type") | ||
return | ||
} | ||
|
||
Log.i(tag, "Received new message of type $type from UnifiedPush...") | ||
DartWorkManager.createWorker(applicationContext, type, HashMap(json)) {} | ||
|
||
// check if the user configured "Send Events to Tasker" | ||
val prefs = applicationContext.getSharedPreferences("FlutterSharedPreferences", 0) | ||
if (prefs.getBoolean("flutter.sendEventsToTasker", false)) { | ||
Utils.getServerUrl(applicationContext, object : MethodChannel.Result { | ||
override fun success(result: Any?) { | ||
Log.w(tag, "Got URL: $result - sending to Tasker...") | ||
val intent = Intent() | ||
intent.setAction("net.dinglisch.android.taserm.BB_EVENT") | ||
intent.putExtra("url", result.toString()) | ||
intent.putExtra("event", type) | ||
intent.putExtras(bundleOf(*json.toList().toTypedArray())) | ||
applicationContext.sendBroadcast(intent) | ||
} | ||
|
||
override fun error(errorCode: String, errorMesage: String?, errorDetails: Any?) {} | ||
override fun notImplemented() {} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...src/main/kotlin/com/bluebubbles/messaging/services/firebase/FirebaseDeleteTokenHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.bluebubbles.messaging.services.firebase | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import com.bluebubbles.messaging.Constants | ||
import com.bluebubbles.messaging.models.MethodCallHandlerImpl | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class FirebaseDeleteTokenHandler: MethodCallHandlerImpl() { | ||
companion object { | ||
const val tag: String = "firebase-delete-token" | ||
} | ||
|
||
override fun handleMethodCall( | ||
call: MethodCall, | ||
result: MethodChannel.Result, | ||
context: Context | ||
) { | ||
FirebaseCloudMessagingTokenHandler().deleteToken(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...pp/src/main/kotlin/com/bluebubbles/messaging/services/notifications/UnifiedPushHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.bluebubbles.messaging.services.notifications | ||
|
||
import android.content.Context | ||
import com.bluebubbles.messaging.models.MethodCallHandlerImpl | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import org.unifiedpush.android.connector.UnifiedPush | ||
|
||
class UnifiedPushHandler: MethodCallHandlerImpl() { | ||
companion object { | ||
const val tag = "UnifiedPushHandler" | ||
} | ||
public fun registerUnifiedPush(context: Context) { | ||
UnifiedPush.registerAppWithDialog(context) | ||
} | ||
|
||
public fun unregisterUnifiedPush(context: Context) { | ||
UnifiedPush.unregisterApp(context) | ||
} | ||
|
||
override fun handleMethodCall( | ||
call: MethodCall, | ||
result: MethodChannel.Result, | ||
context: Context | ||
) { | ||
val operation: String? = call.argument("operation") | ||
when(operation) { | ||
"register" -> this.registerUnifiedPush(context) | ||
"unregister" -> this.unregisterUnifiedPush(context) | ||
else -> { | ||
result.error("500", "invalid operation argument '$operation'", null) | ||
return | ||
} | ||
} | ||
result.success(null) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.