This repository has been archived on 2023-09-08. You can view files and clone it, but cannot push or open issues or pull requests.
moxplatform/pigeons/api.dart

247 lines
6.0 KiB
Dart
Raw Normal View History

2023-07-27 18:45:09 +00:00
import 'package:pigeon/pigeon.dart';
@ConfigurePigeon(
PigeonOptions(
dartOut: 'packages/moxplatform_platform_interface/lib/src/api.g.dart',
2023-07-27 18:45:09 +00:00
//kotlinOut: 'packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Notifications.g.kt',
//kotlinOptions: KotlinOptions(
// package: 'me.polynom.moxplatform_android',
//),
javaOut: 'packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Api.java',
2023-07-27 18:45:09 +00:00
javaOptions: JavaOptions(
package: 'me.polynom.moxplatform_android',
),
),
)
class NotificationMessageContent {
const NotificationMessageContent(
this.body,
this.mime,
this.path,
);
/// The textual body of the message.
final String? body;
/// The path and mime type of the media to show.
final String? mime;
final String? path;
}
class NotificationMessage {
const NotificationMessage(
this.sender,
this.content,
this.jid,
this.timestamp,
2023-08-30 18:46:38 +00:00
this.avatarPath, {
this.groupId,
});
/// The grouping key for the notification.
final String? groupId;
2023-07-27 18:45:09 +00:00
/// The sender of the message.
final String? sender;
2023-07-27 18:45:09 +00:00
/// The jid of the sender.
final String? jid;
2023-07-27 18:45:09 +00:00
/// The body of the message.
final NotificationMessageContent content;
/// Milliseconds since epoch.
final int timestamp;
/// The path to the avatar to use
final String? avatarPath;
}
class MessagingNotification {
2023-08-30 18:46:38 +00:00
const MessagingNotification(this.title, this.id, this.jid, this.messages, this.channelId, this.isGroupchat, this.extra, {this.groupId});
2023-07-27 18:45:09 +00:00
/// The title of the conversation.
final String title;
/// The id of the notification.
final int id;
/// The id of the notification channel the notification should appear on.
final String channelId;
2023-07-28 10:46:02 +00:00
/// The JID of the chat in which the notifications happen.
final String jid;
2023-07-27 18:45:09 +00:00
/// Messages to show.
final List<NotificationMessage?> messages;
2023-07-30 18:40:59 +00:00
/// Flag indicating whether this notification is from a groupchat or not.
final bool isGroupchat;
2023-08-30 18:46:38 +00:00
/// The id for notification grouping.
final String? groupId;
/// Additional data to include.
final Map<String?, String?>? extra;
2023-07-27 18:45:09 +00:00
}
enum NotificationIcon {
warning,
error,
none,
}
class RegularNotification {
2023-08-30 18:46:38 +00:00
const RegularNotification(this.title, this.body, this.channelId, this.id, this.icon, {this.groupId});
/// The title of the notification.
final String title;
/// The body of the notification.
final String body;
/// The id of the channel to show the notification on.
final String channelId;
2023-08-30 18:46:38 +00:00
/// The id for notification grouping.
final String? groupId;
/// The id of the notification.
final int id;
/// The icon to use.
final NotificationIcon icon;
}
2023-07-28 11:54:57 +00:00
enum NotificationEventType {
markAsRead,
reply,
open,
}
class NotificationEvent {
const NotificationEvent(
this.id,
2023-07-28 11:54:57 +00:00
this.jid,
this.type,
this.payload,
2023-07-30 18:40:59 +00:00
this.extra,
2023-07-28 11:54:57 +00:00
);
/// The notification id.
final int id;
2023-07-28 11:54:57 +00:00
/// The JID the notification was for.
final String jid;
/// The type of event.
final NotificationEventType type;
/// An optional payload.
/// - type == NotificationType.reply: The reply message text.
/// Otherwise: undefined.
final String? payload;
/// Extra data. Only set when type == NotificationType.reply.
final Map<String?, String?>? extra;
2023-07-28 11:54:57 +00:00
}
2023-07-28 15:32:14 +00:00
class NotificationI18nData {
const NotificationI18nData(this.reply, this.markAsRead, this.you);
/// The content of the reply button.
final String reply;
/// The content of the "mark as read" button.
final String markAsRead;
/// The text to show when *you* reply.
final String you;
}
2023-08-03 19:19:11 +00:00
enum CipherAlgorithm {
aes128GcmNoPadding,
aes256GcmNoPadding,
aes256CbcPkcs7;
}
class CryptographyResult {
const CryptographyResult(this.plaintextHash, this.ciphertextHash);
final Uint8List plaintextHash;
final Uint8List ciphertextHash;
}
2023-08-03 19:27:13 +00:00
// The type of icon to use when no avatar path is provided.
enum FallbackIconType {
none,
person,
notes;
}
2023-08-30 18:46:38 +00:00
class NotificationGroup {
const NotificationGroup(this.id, this.description);
final String id;
final String description;
}
enum NotificationChannelImportance {
MIN,
HIGH,
DEFAULT
}
class NotificationChannel {
const NotificationChannel(
this.id,
this.title,
this.description, {
this.importance = NotificationChannelImportance.DEFAULT,
this.showBadge = true,
this.groupId,
this.vibration = true,
this.enableLights = true,
});
final String title;
final String description;
final String id;
final NotificationChannelImportance importance;
final bool showBadge;
final String? groupId;
final bool vibration;
final bool enableLights;
}
2023-07-27 18:45:09 +00:00
@HostApi()
abstract class MoxplatformApi {
2023-08-03 19:19:11 +00:00
/// Notification APIs
2023-08-30 18:46:38 +00:00
void createNotificationGroups(List<NotificationGroup> groups);
void deleteNotificationGroups(List<String> ids);
void createNotificationChannels(List<NotificationChannel> channels);
void deleteNotificationChannels(List<String> ids);
2023-07-27 18:45:09 +00:00
void showMessagingNotification(MessagingNotification notification);
void showNotification(RegularNotification notification);
2023-07-30 18:40:59 +00:00
void dismissNotification(int id);
2023-07-28 19:46:47 +00:00
void setNotificationSelfAvatar(String path);
void setNotificationI18n(NotificationI18nData data);
2023-08-03 19:19:11 +00:00
/// Platform APIs
String getPersistentDataPath();
String getCacheDataPath();
void openBatteryOptimisationSettings();
bool isIgnoringBatteryOptimizations();
2023-08-03 19:19:11 +00:00
2023-08-03 19:27:13 +00:00
/// Contacts APIs
void recordSentMessage(String name, String jid, String? avatarPath, FallbackIconType fallbackIcon);
2023-08-03 19:19:11 +00:00
/// Cryptography APIs
@async CryptographyResult? encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec);
@async CryptographyResult? decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec);
@async Uint8List? hashFile(String sourcePath, String hashSpec);
/// Media APIs
bool generateVideoThumbnail(String src, String dest, int maxWidth);
2023-08-03 19:19:11 +00:00
/// Stubs
2023-07-28 11:54:57 +00:00
void eventStub(NotificationEvent event);
2023-07-27 18:45:09 +00:00
}