Skip to content
Closed
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
36 changes: 34 additions & 2 deletions app/src/main/java/com/github/gotify/service/WebSocketService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.gotify.service;
Copy link
Member

Choose a reason for hiding this comment

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

What's the use-case, I don't think this is needed as you can already open urls, no need to do this separately in background.


import static com.github.gotify.api.Callback.call;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
Expand All @@ -12,11 +14,15 @@
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;

import com.github.gotify.MarkwonFactory;
import com.github.gotify.MissedMessageUtil;
import com.github.gotify.NotificationSupport;
Expand All @@ -32,12 +38,15 @@
import com.github.gotify.messages.Extras;
import com.github.gotify.messages.MessagesActivity;
import com.github.gotify.picasso.PicassoHandler;
import io.noties.markwon.Markwon;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;

import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import static com.github.gotify.api.Callback.call;
import cz.msebera.android.httpclient.Header;
import io.noties.markwon.Markwon;

public class WebSocketService extends Service {

Expand Down Expand Up @@ -323,6 +332,29 @@ private void showNotification(
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setContentIntent(contentIntent);

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

if (callbackUrl != null) {
Handler callbackHandler = new Handler(Looper.getMainLooper());
Runnable callbackRunnable = () -> {
AsyncHttpClient client = new AsyncHttpClient();
client.post(callbackUrl, null, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println("Callback successfully send to: " +callbackUrl);
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
System.out.println("Can't send callback to: "+callbackUrl);
}
});
};
callbackHandler.post(callbackRunnable);
}

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

dependencies {
compile "javax.annotation:javax.annotation-api:$javax_annotation_version"
compile "com.loopj.android:android-async-http:$android_async_http"
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