feat: Allow the sender's data being null

This commit is contained in:
PapaTutuWawa 2023-07-30 22:05:45 +02:00
parent 2490a8ee9f
commit 2f5a39416b
4 changed files with 63 additions and 31 deletions

View File

@ -171,30 +171,24 @@ public class Api {
/** Generated class from Pigeon that represents data sent in messages. */
public static final class NotificationMessage {
/** The sender of the message. */
private @NonNull String sender;
private @Nullable String sender;
public @NonNull String getSender() {
public @Nullable String getSender() {
return sender;
}
public void setSender(@NonNull String setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"sender\" is null.");
}
public void setSender(@Nullable String setterArg) {
this.sender = setterArg;
}
/** The jid of the sender. */
private @NonNull String jid;
private @Nullable String jid;
public @NonNull String getJid() {
public @Nullable String getJid() {
return jid;
}
public void setJid(@NonNull String setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"jid\" is null.");
}
public void setJid(@Nullable String setterArg) {
this.jid = setterArg;
}
@ -244,14 +238,14 @@ public class Api {
private @Nullable String sender;
public @NonNull Builder setSender(@NonNull String setterArg) {
public @NonNull Builder setSender(@Nullable String setterArg) {
this.sender = setterArg;
return this;
}
private @Nullable String jid;
public @NonNull Builder setJid(@NonNull String setterArg) {
public @NonNull Builder setJid(@Nullable String setterArg) {
this.jid = setterArg;
return this;
}
@ -664,6 +658,20 @@ public class Api {
/** Generated class from Pigeon that represents data sent in messages. */
public static final class NotificationEvent {
/** The notification id. */
private @NonNull Long id;
public @NonNull Long getId() {
return id;
}
public void setId(@NonNull Long setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"id\" is null.");
}
this.id = setterArg;
}
/** The JID the notification was for. */
private @NonNull String jid;
@ -723,6 +731,13 @@ public class Api {
public static final class Builder {
private @Nullable Long id;
public @NonNull Builder setId(@NonNull Long setterArg) {
this.id = setterArg;
return this;
}
private @Nullable String jid;
public @NonNull Builder setJid(@NonNull String setterArg) {
@ -753,6 +768,7 @@ public class Api {
public @NonNull NotificationEvent build() {
NotificationEvent pigeonReturn = new NotificationEvent();
pigeonReturn.setId(id);
pigeonReturn.setJid(jid);
pigeonReturn.setType(type);
pigeonReturn.setPayload(payload);
@ -763,7 +779,8 @@ public class Api {
@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(4);
ArrayList<Object> toListResult = new ArrayList<Object>(5);
toListResult.add(id);
toListResult.add(jid);
toListResult.add(type == null ? null : type.index);
toListResult.add(payload);
@ -773,13 +790,15 @@ public class Api {
static @NonNull NotificationEvent fromList(@NonNull ArrayList<Object> list) {
NotificationEvent pigeonResult = new NotificationEvent();
Object jid = list.get(0);
Object id = list.get(0);
pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer) id : (Long) id));
Object jid = list.get(1);
pigeonResult.setJid((String) jid);
Object type = list.get(1);
Object type = list.get(2);
pigeonResult.setType(type == null ? null : NotificationEventType.values()[(int) type]);
Object payload = list.get(2);
Object payload = list.get(3);
pigeonResult.setPayload((String) payload);
Object extra = list.get(3);
Object extra = list.get(4);
pigeonResult.setExtra((Map<String, String>) extra);
return pigeonResult;
}

View File

@ -58,6 +58,7 @@ class NotificationReceiver : BroadcastReceiver() {
private fun handleMarkAsRead(context: Context, intent: Intent) {
MoxplatformAndroidPlugin.notificationSink?.success(
NotificationEvent().apply {
id = intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1)
jid = intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!
type = Api.NotificationEventType.MARK_AS_READ
payload = null
@ -74,6 +75,7 @@ class NotificationReceiver : BroadcastReceiver() {
val replyPayload = remoteInput.getCharSequence(REPLY_TEXT_KEY)
MoxplatformAndroidPlugin.notificationSink?.success(
NotificationEvent().apply {
id = intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1)
jid = intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!
type = Api.NotificationEventType.REPLY
payload = replyPayload.toString()
@ -165,6 +167,7 @@ class NotificationReceiver : BroadcastReceiver() {
private fun handleTap(context: Context, intent: Intent) {
MoxplatformAndroidPlugin.notificationSink?.success(
NotificationEvent().apply {
id = intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1)
jid = intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!
type = Api.NotificationEventType.OPEN
payload = null

View File

@ -55,18 +55,18 @@ class NotificationMessageContent {
class NotificationMessage {
NotificationMessage({
required this.sender,
required this.jid,
this.sender,
this.jid,
required this.content,
required this.timestamp,
this.avatarPath,
});
/// The sender of the message.
String sender;
String? sender;
/// The jid of the sender.
String jid;
String? jid;
/// The body of the message.
NotificationMessageContent content;
@ -90,8 +90,8 @@ class NotificationMessage {
static NotificationMessage decode(Object result) {
result as List<Object?>;
return NotificationMessage(
sender: result[0]! as String,
jid: result[1]! as String,
sender: result[0] as String?,
jid: result[1] as String?,
content: NotificationMessageContent.decode(result[2]! as List<Object?>),
timestamp: result[3]! as int,
avatarPath: result[4] as String?,
@ -205,12 +205,16 @@ class RegularNotification {
class NotificationEvent {
NotificationEvent({
required this.id,
required this.jid,
required this.type,
this.payload,
this.extra,
});
/// The notification id.
int id;
/// The JID the notification was for.
String jid;
@ -227,6 +231,7 @@ class NotificationEvent {
Object encode() {
return <Object?>[
id,
jid,
type.index,
payload,
@ -237,10 +242,11 @@ class NotificationEvent {
static NotificationEvent decode(Object result) {
result as List<Object?>;
return NotificationEvent(
jid: result[0]! as String,
type: NotificationEventType.values[result[1]! as int],
payload: result[2] as String?,
extra: (result[3] as Map<Object?, Object?>?)?.cast<String?, String?>(),
id: result[0]! as int,
jid: result[1]! as String,
type: NotificationEventType.values[result[2]! as int],
payload: result[3] as String?,
extra: (result[4] as Map<Object?, Object?>?)?.cast<String?, String?>(),
);
}
}

View File

@ -38,10 +38,10 @@ class NotificationMessage {
);
/// The sender of the message.
final String sender;
final String? sender;
/// The jid of the sender.
final String jid;
final String? jid;
/// The body of the message.
final NotificationMessageContent content;
@ -111,12 +111,16 @@ enum NotificationEventType {
class NotificationEvent {
const NotificationEvent(
this.id,
this.jid,
this.type,
this.payload,
this.extra,
);
/// The notification id.
final int id;
/// The JID the notification was for.
final String jid;