Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions android/app/src/main/kotlin/com/zulip/flutter/AndroidIntents.g.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v27.3.2), do not edit directly.
// Autogenerated from Pigeon (v30.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -258,12 +258,12 @@ private open class AndroidIntentsPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
129.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
IntentSharedFile.fromList(it)
}
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
AndroidIntentSendEvent.fromList(it)
}
}
Expand Down Expand Up @@ -305,9 +305,9 @@ private class AndroidIntentsPigeonStreamHandler<T>(
}

interface AndroidIntentsPigeonEventChannelWrapper<T> {
open fun onListen(p0: Any?, sink: PigeonEventSink<T>) {}
fun onListen(p0: Any?, sink: PigeonEventSink<T>) {}

open fun onCancel(p0: Any?) {}
fun onCancel(p0: Any?) {}
}

class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
Expand All @@ -324,20 +324,48 @@ class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
}
}

/** A typed channel for communicating with the Flutter application using asynchronous event streams. */
class AndroidIntentEventsEventChannel(messenger: BinaryMessenger, instanceName: String = "") {
private val channel: EventChannel

init {
var channelName = "dev.flutter.pigeon.zulip.AndroidIntentsEventChannelApi.androidIntentEvents"
if (instanceName.isNotEmpty()) {
channelName += ".$instanceName"
}
channel = EventChannel(messenger, channelName, AndroidIntentsPigeonMethodCodec)
}

/**
* Sets the stream handler for this channel, replacing any previous handler.
*
* Pass `null` to remove the event channel registration.
*/
fun setStreamHandler(streamHandler: AndroidIntentEventsStreamHandler?) {
val internalHandler = streamHandler?.let { AndroidIntentsPigeonStreamHandler<AndroidIntentEvent>(it) }
channel.setStreamHandler(internalHandler)
}
}

abstract class AndroidIntentEventsStreamHandler : AndroidIntentsPigeonEventChannelWrapper<AndroidIntentEvent> {
companion object {
fun register(messenger: BinaryMessenger, streamHandler: AndroidIntentEventsStreamHandler, instanceName: String = "") {
var channelName: String = "dev.flutter.pigeon.zulip.AndroidIntentsEventChannelApi.androidIntentEvents"
if (instanceName.isNotEmpty()) {
channelName += ".$instanceName"
}
val internalStreamHandler = AndroidIntentsPigeonStreamHandler<AndroidIntentEvent>(streamHandler)
EventChannel(messenger, channelName, AndroidIntentsPigeonMethodCodec).setStreamHandler(internalStreamHandler)
/**
* Creates and returns a new event channel that calls the provided stream handler.
*
* The returned channel can be stored to allow changing or removing the stream handler.
* If the handler will not be changed for the lifetime of the engine associated with the messenger,
* the return value can be ignored.
*/
fun register(messenger: BinaryMessenger, streamHandler: AndroidIntentEventsStreamHandler, instanceName: String = ""): AndroidIntentEventsEventChannel {
val channel = AndroidIntentEventsEventChannel(messenger, instanceName)
channel.setStreamHandler(streamHandler)
return channel
}
}
// Implement methods from AndroidIntentsPigeonEventChannelWrapper
override fun onListen(p0: Any?, sink: PigeonEventSink<AndroidIntentEvent>) {}

override fun onCancel(p0: Any?) {}
// Implement methods from AndroidIntentsPigeonEventChannelWrapper
override fun onListen(p0: Any?, sink: PigeonEventSink<AndroidIntentEvent>) {}

override fun onCancel(p0: Any?) {}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v27.3.2), do not edit directly.
// Autogenerated from Pigeon (v30.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -761,52 +761,52 @@ private open class AndroidNotificationsPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
129.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
NotificationChannel.fromList(it)
}
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
AndroidIntent.fromList(it)
}
}
131.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
PendingIntent.fromList(it)
}
}
132.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
InboxStyle.fromList(it)
}
}
133.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
Person.fromList(it)
}
}
134.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
MessagingStyleMessage.fromList(it)
}
}
135.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
MessagingStyle.fromList(it)
}
}
136.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
Notification.fromList(it)
}
}
137.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
StatusBarNotification.fromList(it)
}
}
138.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
StoredNotificationSound.fromList(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v27.3.2), do not edit directly.
// Autogenerated from Pigeon (v30.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -280,12 +280,12 @@ private open class NotificationsPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
129.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
IosNotificationTapEvent.fromList(it)
}
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
(readValue(buffer) as? List<Any?>)?.let {
AndroidNotificationTapEvent.fromList(it)
}
}
Expand Down Expand Up @@ -327,9 +327,9 @@ private class NotificationsPigeonStreamHandler<T>(
}

interface NotificationsPigeonEventChannelWrapper<T> {
open fun onListen(p0: Any?, sink: PigeonEventSink<T>) {}
fun onListen(p0: Any?, sink: PigeonEventSink<T>) {}

open fun onCancel(p0: Any?) {}
fun onCancel(p0: Any?) {}
}

class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
Expand Down Expand Up @@ -362,20 +362,48 @@ class PigeonEventSink<T>(private val sink: EventChannel.EventSink) {
* data URL has the "zulip" scheme, and "notification" authority. The
* emitted event will carry the intent data URL.
*/
/** A typed channel for communicating with the Flutter application using asynchronous event streams. */
class NotificationTapEventsEventChannel(messenger: BinaryMessenger, instanceName: String = "") {
private val channel: EventChannel

init {
var channelName = "dev.flutter.pigeon.zulip.NotificationEventChannelApi.notificationTapEvents"
if (instanceName.isNotEmpty()) {
channelName += ".$instanceName"
}
channel = EventChannel(messenger, channelName, NotificationsPigeonMethodCodec)
}

/**
* Sets the stream handler for this channel, replacing any previous handler.
*
* Pass `null` to remove the event channel registration.
*/
fun setStreamHandler(streamHandler: NotificationTapEventsStreamHandler?) {
val internalHandler = streamHandler?.let { NotificationsPigeonStreamHandler<NotificationTapEvent>(it) }
channel.setStreamHandler(internalHandler)
}
}

abstract class NotificationTapEventsStreamHandler : NotificationsPigeonEventChannelWrapper<NotificationTapEvent> {
companion object {
fun register(messenger: BinaryMessenger, streamHandler: NotificationTapEventsStreamHandler, instanceName: String = "") {
var channelName: String = "dev.flutter.pigeon.zulip.NotificationEventChannelApi.notificationTapEvents"
if (instanceName.isNotEmpty()) {
channelName += ".$instanceName"
}
val internalStreamHandler = NotificationsPigeonStreamHandler<NotificationTapEvent>(streamHandler)
EventChannel(messenger, channelName, NotificationsPigeonMethodCodec).setStreamHandler(internalStreamHandler)
/**
* Creates and returns a new event channel that calls the provided stream handler.
*
* The returned channel can be stored to allow changing or removing the stream handler.
* If the handler will not be changed for the lifetime of the engine associated with the messenger,
* the return value can be ignored.
*/
fun register(messenger: BinaryMessenger, streamHandler: NotificationTapEventsStreamHandler, instanceName: String = ""): NotificationTapEventsEventChannel {
val channel = NotificationTapEventsEventChannel(messenger, instanceName)
channel.setStreamHandler(streamHandler)
return channel
}
}
// Implement methods from NotificationsPigeonEventChannelWrapper
override fun onListen(p0: Any?, sink: PigeonEventSink<NotificationTapEvent>) {}

override fun onCancel(p0: Any?) {}
// Implement methods from NotificationsPigeonEventChannelWrapper
override fun onListen(p0: Any?, sink: PigeonEventSink<NotificationTapEvent>) {}

override fun onCancel(p0: Any?) {}
}

52 changes: 27 additions & 25 deletions ios/NotificationService/IosNotifications.g.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v27.3.2), do not edit directly.
// Autogenerated from Pigeon (v30.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand All @@ -25,7 +25,7 @@ final class PigeonError: Error {

var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>"))"
}
}

Expand Down Expand Up @@ -74,19 +74,19 @@ enum IosNotificationsPigeonInternal {
case is (Void, Void):
return true

case (let lhsArray, let rhsArray) as ([Any?], [Any?]):
case (let lhsArray, let rhsArray) as ([Double], [Double]):
guard lhsArray.count == rhsArray.count else { return false }
for (index, element) in lhsArray.enumerated() {
if !deepEquals(element, rhsArray[index]) {
if !doubleEquals(element, rhsArray[index]) {
return false
}
}
return true

case (let lhsArray, let rhsArray) as ([Double], [Double]):
case (let lhsArray, let rhsArray) as ([Any?], [Any?]):
guard lhsArray.count == rhsArray.count else { return false }
for (index, element) in lhsArray.enumerated() {
if !doubleEquals(element, rhsArray[index]) {
if !deepEquals(element, rhsArray[index]) {
return false
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ protocol IosNotifFlutterApiProtocol {
/// will be displayed to the user.
///
/// See docs: https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension/didreceive(_:withcontenthandler:)
func didReceivePushNotification(content contentArg: NotificationContent, completion: @escaping (Result<ImprovedNotificationContent, PigeonError>) -> Void)
@MainActor func didReceivePushNotification(content contentArg: NotificationContent) async throws -> ImprovedNotificationContent
}
class IosNotifFlutterApi: IosNotifFlutterApiProtocol {
private let binaryMessenger: FlutterBinaryMessenger
Expand All @@ -374,24 +374,26 @@ class IosNotifFlutterApi: IosNotifFlutterApiProtocol {
/// will be displayed to the user.
///
/// See docs: https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension/didreceive(_:withcontenthandler:)
func didReceivePushNotification(content contentArg: NotificationContent, completion: @escaping (Result<ImprovedNotificationContent, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.zulip.IosNotifFlutterApi.didReceivePushNotification\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([contentArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")))
} else {
let result = listResponse[0] as! ImprovedNotificationContent
completion(.success(result))
@MainActor func didReceivePushNotification(content contentArg: NotificationContent) async throws -> ImprovedNotificationContent {
return try await withCheckedThrowingContinuation { continuation in
let channelName: String = "dev.flutter.pigeon.zulip.IosNotifFlutterApi.didReceivePushNotification\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([contentArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
continuation.resume(throwing: createConnectionError(withChannelName: channelName))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
continuation.resume(throwing: PigeonError(code: code, message: message, details: details))
} else if IosNotificationsPigeonInternal.isNullish(listResponse[0]) {
continuation.resume(throwing: PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))
} else {
let result = listResponse[0] as! ImprovedNotificationContent
continuation.resume(returning: result)
}
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions ios/NotificationService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,14 @@ enum DartNotificationService {
let iosNotifFlutterApi = IosNotifFlutterApi(
binaryMessenger: headlessEngine.binaryMessenger
)
let result = await withCheckedContinuation { continuation in
iosNotifFlutterApi.didReceivePushNotification(content: content) { result in
continuation.resume(returning: result)
}
}

switch result {
case .success(let improvedNotificationContent):
return improvedNotificationContent

case .failure(let error): // TODO(log)
do {
return try await iosNotifFlutterApi.didReceivePushNotification(content: content)
} catch let error as PigeonError { // TODO(log)
logger.debug(
"IosNotifFlutterApi.didReceivePushNotification failed: \(error.localizedDescription)")
return nil
} catch {
return nil // TODO(log)
}
}
}
Loading
Loading