diff --git a/app/src/main/java/com/polar/nextcloudservices/Notification/NotificationController.java b/app/src/main/java/com/polar/nextcloudservices/Notification/NotificationController.java index db055dc..3b6602d 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Notification/NotificationController.java +++ b/app/src/main/java/com/polar/nextcloudservices/Notification/NotificationController.java @@ -9,6 +9,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Build; +import android.service.notification.StatusBarNotification; import android.util.Log; import android.widget.Toast; @@ -26,6 +27,7 @@ import org.json.JSONObject; import java.util.HashSet; +import java.util.NoSuchElementException; public class NotificationController implements NotificationEventReceiver, StatusCheckable { private final HashSet active_notifications = new HashSet<>(); @@ -159,6 +161,19 @@ public void tellActionRequestFailed(){ Toast.makeText(mContext, R.string.quick_action_failed, Toast.LENGTH_LONG).show(); } + public Notification getNotificationById(int id) throws NoSuchElementException { + for(StatusBarNotification notification: mNotificationManager.getActiveNotifications()){ + if(notification.getId() == id){ + return notification.getNotification(); + } + } + throw new NoSuchElementException("Can not find notification with specified id: " + id); + } + + public void postNotification(int id, Notification notification){ + mNotificationManager.notify(id, notification); + } + public INextcloudAbstractAPI getAPI(){ return mServiceSettings.getAPIFromSettings(); } diff --git a/app/src/main/java/com/polar/nextcloudservices/Notification/Processors/spreed/NextcloudTalkProcessor.java b/app/src/main/java/com/polar/nextcloudservices/Notification/Processors/spreed/NextcloudTalkProcessor.java index 6fc68bf..f0b2221 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Notification/Processors/spreed/NextcloudTalkProcessor.java +++ b/app/src/main/java/com/polar/nextcloudservices/Notification/Processors/spreed/NextcloudTalkProcessor.java @@ -4,6 +4,7 @@ import static com.polar.nextcloudservices.Notification.NotificationEvent.NOTIFICATION_EVENT_FASTREPLY; import android.annotation.SuppressLint; +import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; @@ -276,6 +277,7 @@ public void onNotificationEvent(NotificationEvent event, Intent intent, Thread thread = new Thread(() -> { try { api.sendTalkReply(chatroom, reply); + appendQuickReply(controller, notification_id, reply); } catch (Exception e) { Log.e(TAG, e.toString()); controller.tellActionRequestFailed(); @@ -311,6 +313,18 @@ public void onNotificationEvent(NotificationEvent event, Intent intent, } } + private void appendQuickReply(NotificationController controller, + int notification_id, String text){ + Notification notification = controller.getNotificationById(notification_id); + Context context = controller.getContext(); + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, notification); + NotificationCompat.MessagingStyle style = NotificationCompat + .MessagingStyle.extractMessagingStyleFromNotification(notification); + style.addMessage(text, CommonUtil.getTimestamp(), "You"); + notification = builder.setStyle(style).build(); + controller.postNotification(notification_id, notification); + } + @Override public int getPriority() { return priority; diff --git a/app/src/main/java/com/polar/nextcloudservices/Utils/CommonUtil.java b/app/src/main/java/com/polar/nextcloudservices/Utils/CommonUtil.java index 48e427d..d2e9159 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Utils/CommonUtil.java +++ b/app/src/main/java/com/polar/nextcloudservices/Utils/CommonUtil.java @@ -70,4 +70,8 @@ public static void safeSleep(long millis){ Log.e(TAG, "Interrupted while sleeping " + millis + "ms"); } } + + public static long getTimestamp(){ + return System.currentTimeMillis(); + } }