Skip to content

Commit

Permalink
Add SUPPRESS_NOTIFICATIONS flag for message (#2393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysterious-Dev authored Feb 12, 2023
1 parent b9161cf commit 8852b5e
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,15 @@ default MessageCreateAction replyFiles(@Nonnull Collection<? extends FileUpload>
*/
boolean isEphemeral();

/**
* Whether this message is silent.
* <br>The message being silent means it will not trigger push and desktop notifications
* <br>This is a shortcut method for checking if {@link #getFlags()} contains {@link MessageFlag#NOTIFICATIONS_SUPPRESSED}
*
* @return Whether the message is silent
*/
boolean isSuppressedNotifications();

/**
* Returns a possibly {@code null} {@link ThreadChannel ThreadChannel} that was started from this message.
* This can be {@code null} due to no ThreadChannel being started from it or the ThreadChannel later being deleted.
Expand Down Expand Up @@ -2129,7 +2138,12 @@ enum MessageFlag
/**
* Indicates, that this Message is an interaction response and the bot is "thinking"
*/
LOADING(7);
LOADING(7),
/**
* Indicates, that this message will not trigger push and desktop notifications
* @see Message#isSuppressedNotifications
*/
NOTIFICATIONS_SUPPRESSED(12);

private final int value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public R clear()
this.components.clear();
this.content.setLength(0);
this.mentions.clear();
this.messageFlags = 0;
return (R) this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ public MessageCreateBuilder setTTS(boolean tts)
return this;
}

@Nonnull
@Override
public MessageCreateBuilder setSuppressedNotifications(boolean suppressed)
{
if(suppressed)
messageFlags |= Message.MessageFlag.NOTIFICATIONS_SUPPRESSED.getValue();
else
messageFlags &= ~Message.MessageFlag.NOTIFICATIONS_SUPPRESSED.getValue();
return this;
}

@Override
public boolean isEmpty()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ public boolean isTTS()
return tts;
}

/**
* Whether this message is silent.
*
* @return True, if the message will not trigger push and desktop notifications
*/
public boolean isSuppressedNotifications()
{
return (flags & Message.MessageFlag.NOTIFICATIONS_SUPPRESSED.getValue()) != 0;
}

/**
* The IDs for users which are allowed to be mentioned, or an empty list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ default R addFiles(@Nonnull FileUpload... files)
@Nonnull
R setTTS(boolean tts);

/**
* Set whether this message should trigger push/desktop notifications to other users.
* <br>When a message is suppressed, it will not trigger push/desktop notifications.
*
* @param suppressed
* True, if this message should not trigger push/desktop notifications
*
* @return The same reply action, for chaining convenience
*/
@Nonnull
R setSuppressedNotifications(boolean suppressed);

/**
* Applies the provided {@link MessageCreateData} to this request.
*
Expand All @@ -336,6 +348,7 @@ default R applyData(@Nonnull MessageCreateData data)
.mentionRepliedUser(data.isMentionRepliedUser())
.setEmbeds(data.getEmbeds())
.setTTS(data.isTTS())
.setSuppressedNotifications(data.isSuppressedNotifications())
.setComponents(layoutComponents)
.setFiles(data.getFiles());
}
Expand All @@ -352,6 +365,7 @@ default R applyMessage(@Nonnull Message message)
return setContent(message.getContentRaw())
.setEmbeds(embeds)
.setTTS(message.isTTS())
.setSuppressedNotifications(message.isSuppressedNotifications())
.setComponents(message.getActionRows());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ public boolean isEphemeral()
return false;
}

@Override
public boolean isSuppressedNotifications()
{
unsupported();
return false;
}

@Nullable
@Override
public ThreadChannel getStartedThread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ public boolean isEphemeral()
return (this.flags & MessageFlag.EPHEMERAL.getValue()) != 0;
}

@Override
public boolean isSuppressedNotifications()
{
return (this.flags & MessageFlag.NOTIFICATIONS_SUPPRESSED.getValue()) != 0;
}

@Nullable
@Override
public ThreadChannel getStartedThread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ default List<FileUpload> getAttachments()
{
return getBuilder().getAttachments();
}

@Nonnull
@Override
default R setSuppressedNotifications(boolean suppressed)
{
getBuilder().setSuppressedNotifications(suppressed);
return (R) this;
}
}

0 comments on commit 8852b5e

Please sign in to comment.