Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add share and open actions #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions app/src/main/java/com/github/gotify/service/WebSocketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,30 @@ private void showNotification(
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setContentIntent(contentIntent);

String actionOpen =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your use-cases for both features, and why do we need another url open, when there is already https://gotify.net/docs/msgextras#clientnotification click.url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be able to open another url for example from the actions buttons under the notification

The current implementation seems too unflexible. You could already have functionality in mark down for opening a URL. Maybe we could parse the links inside a markdown message and automatically create buttons for these. Otherwise, a more generic approach would look like:

{
  "extras": {
    "client::action": {
      "buttons": [
        {
          "label": "Acknowledge",
          "http": {
            "method": "post",
            "url": "https://example.com/ack?id=5",
            "headers": {
              "Authorization": "bearer abcde"
            }
          }
        },
        // another button
      ]
    }
  }
}

But something like this would require more input from other users, so that we know this is fulfills their use cases. Perhaps there is already a standard for defining actions like this, f.ex Microsoft Teams supports such buttons.

Could you give me a concrete use-case for the share feature.

Extras.getNestedValue(String.class, extras, "client::notification", "actions", "open");

if (actionOpen != null) {
Intent actionOpenIntent = new Intent();
actionOpenIntent.setAction(Intent.ACTION_VIEW);
actionOpenIntent.setData(Uri.parse(actionOpen));
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 123, actionOpenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
b.addAction(new NotificationCompat.Action.Builder(null, "open", pendingIntent).build());
}

String actionShare =
Extras.getNestedValue(String.class, extras, "client::notification", "actions", "share");

if (actionShare != null) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, actionShare);
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 124, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
b.addAction(new NotificationCompat.Action.Builder(null, "share", pendingIntent).build());
}

CharSequence formattedMessage = message;
if (Extras.useMarkdown(extras)) {
formattedMessage = markwon.toMarkdown(message);
Expand Down
2 changes: 2 additions & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ ext {
junit_version = "4.13"
threetenbp_version = "1.4.4"
json_fire_version = "1.8.4"
javax_annotation_version = "1.3.2"
}

dependencies {
compile "javax.annotation:javax.annotation-api:$javax_annotation_version"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-scalars:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
Expand Down