mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
* Update build tools
* Update appcompat version
* Update dependencies
* feat: add paging into conversation recycler and queries to fetch data off-thread
* refactor: wip for updating paged results and bucketing messages / fetching enough to display
* fix: currently works for scrolling and possibly refreshing? need scroll to message and auto scroll down on insert (at bottom)
* fix: search and scrolling to X message works now
* build: increase version code and name
* fix: re-add refresh, remove the outdated comment
* refactor: lets see if 25 size pages increases performance 👀
* feat: add in some equals overrides for mms records to refresh if media has finished DLing
* feat: add scroll to bottom for new messages if we are at the end of the chat
* build: update build numbers
* fix: update AGP and fix compile errors for sdk version 31
* feat: add log for loki-avatar and loki-fs on upload types and responses
* feat: increase build number to match latest installed version
* feat: changing props and permission checks for call service
* fix: possible service exception when no call ID remote foreground service not terminated
* revert: google services version
* fix: re-add paging dependency
* feat: adding new last seen function and figuring out the last seen for recycler adapter
* build: update version names and codes for deploy
* refactor: undo the new adapter and query changes to use previous cursor logic. revert this commit to enable new paged adapter
* fix: use author's address in typist equality and hashcode for set inclusion
* refactor: refactor the select contacts activity
* refactor: refactor the select contacts activity
* build: update version code
* fix: hide all other bound views if deleted
* refactor: change voice message tint, upgrade build number
* fix: message detail showing up properly
* revert: realise copy public key is actually not allowed if open group participant
* fix: copy session ID, message detail activity support re-enabled
* build: update build version code
* build: remove version name
* build: update build code
* feat: google services version minimum compatible
* fix: selection for re-created objects not properly highlighting
* fix: foreground CENTER_INSIDE instead of just CENTER for scaletype
* build: update version code
* fix: don't show error if no error
* build: update version code
* fix: clear error messages if any on successful send
Co-authored-by: charles <charles@oxen.io>
230 lines
8 KiB
Java
230 lines
8 KiB
Java
package org.thoughtcrime.securesms.notifications;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient;
|
|
import org.session.libsession.utilities.recipients.Recipient.VibrateState;
|
|
import org.session.libsignal.utilities.Log;
|
|
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2;
|
|
|
|
import java.util.LinkedHashSet;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
public class NotificationState {
|
|
|
|
private static final String TAG = NotificationState.class.getSimpleName();
|
|
|
|
private final LinkedList<NotificationItem> notifications = new LinkedList<>();
|
|
private final LinkedHashSet<Long> threads = new LinkedHashSet<>();
|
|
|
|
private int notificationCount = 0;
|
|
|
|
public NotificationState() {}
|
|
|
|
public NotificationState(@NonNull List<NotificationItem> items) {
|
|
for (NotificationItem item : items) {
|
|
addNotification(item);
|
|
}
|
|
}
|
|
|
|
public void addNotification(NotificationItem item) {
|
|
notifications.addFirst(item);
|
|
|
|
if (threads.contains(item.getThreadId())) {
|
|
threads.remove(item.getThreadId());
|
|
}
|
|
|
|
threads.add(item.getThreadId());
|
|
notificationCount++;
|
|
}
|
|
|
|
public @Nullable Uri getRingtone(@NonNull Context context) {
|
|
if (!notifications.isEmpty()) {
|
|
Recipient recipient = notifications.getFirst().getRecipient();
|
|
|
|
if (recipient != null) {
|
|
return NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context, recipient)
|
|
: recipient.resolve().getMessageRingtone();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public VibrateState getVibrate() {
|
|
if (!notifications.isEmpty()) {
|
|
Recipient recipient = notifications.getFirst().getRecipient();
|
|
|
|
if (recipient != null) {
|
|
return recipient.resolve().getMessageVibrate();
|
|
}
|
|
}
|
|
|
|
return VibrateState.DEFAULT;
|
|
}
|
|
|
|
public boolean hasMultipleThreads() {
|
|
return threads.size() > 1;
|
|
}
|
|
|
|
public LinkedHashSet<Long> getThreads() {
|
|
return threads;
|
|
}
|
|
|
|
public int getThreadCount() {
|
|
return threads.size();
|
|
}
|
|
|
|
public int getMessageCount() {
|
|
return notificationCount;
|
|
}
|
|
|
|
public List<NotificationItem> getNotifications() {
|
|
return notifications;
|
|
}
|
|
|
|
public List<NotificationItem> getNotificationsForThread(long threadId) {
|
|
LinkedList<NotificationItem> list = new LinkedList<>();
|
|
|
|
for (NotificationItem item : notifications) {
|
|
if (item.getThreadId() == threadId) list.addFirst(item);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public PendingIntent getMarkAsReadIntent(Context context, int notificationId) {
|
|
long[] threadArray = new long[threads.size()];
|
|
int index = 0;
|
|
|
|
for (long thread : threads) {
|
|
Log.i(TAG, "Added thread: " + thread);
|
|
threadArray[index++] = thread;
|
|
}
|
|
|
|
Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION);
|
|
intent.setClass(context, MarkReadReceiver.class);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
intent.putExtra(MarkReadReceiver.THREAD_IDS_EXTRA, threadArray);
|
|
intent.putExtra(MarkReadReceiver.NOTIFICATION_ID_EXTRA, notificationId);
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
public PendingIntent getRemoteReplyIntent(Context context, Recipient recipient, ReplyMethod replyMethod) {
|
|
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
|
|
|
|
Intent intent = new Intent(RemoteReplyReceiver.REPLY_ACTION);
|
|
intent.setClass(context, RemoteReplyReceiver.class);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
intent.putExtra(RemoteReplyReceiver.ADDRESS_EXTRA, recipient.getAddress());
|
|
intent.putExtra(RemoteReplyReceiver.REPLY_METHOD, replyMethod);
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
public PendingIntent getAndroidAutoReplyIntent(Context context, Recipient recipient) {
|
|
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
|
|
|
|
Intent intent = new Intent(AndroidAutoReplyReceiver.REPLY_ACTION);
|
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
intent.setClass(context, AndroidAutoReplyReceiver.class);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
intent.putExtra(AndroidAutoReplyReceiver.ADDRESS_EXTRA, recipient.getAddress());
|
|
intent.putExtra(AndroidAutoReplyReceiver.THREAD_ID_EXTRA, (long)threads.toArray()[0]);
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
public PendingIntent getAndroidAutoHeardIntent(Context context, int notificationId) {
|
|
long[] threadArray = new long[threads.size()];
|
|
int index = 0;
|
|
for (long thread : threads) {
|
|
Log.i(TAG, "getAndroidAutoHeardIntent Added thread: " + thread);
|
|
threadArray[index++] = thread;
|
|
}
|
|
|
|
Intent intent = new Intent(AndroidAutoHeardReceiver.HEARD_ACTION);
|
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
intent.setClass(context, AndroidAutoHeardReceiver.class);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
intent.putExtra(AndroidAutoHeardReceiver.THREAD_IDS_EXTRA, threadArray);
|
|
intent.putExtra(AndroidAutoHeardReceiver.NOTIFICATION_ID_EXTRA, notificationId);
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
public PendingIntent getQuickReplyIntent(Context context, Recipient recipient) {
|
|
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications! " + threads.size());
|
|
|
|
Intent intent = new Intent(context, ConversationActivityV2.class);
|
|
intent.putExtra(ConversationActivityV2.ADDRESS, recipient.getAddress());
|
|
intent.putExtra(ConversationActivityV2.THREAD_ID, (long)threads.toArray()[0]);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getActivity(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
public PendingIntent getDeleteIntent(Context context) {
|
|
int index = 0;
|
|
long[] ids = new long[notifications.size()];
|
|
boolean[] mms = new boolean[ids.length];
|
|
|
|
for (NotificationItem notificationItem : notifications) {
|
|
ids[index] = notificationItem.getId();
|
|
mms[index++] = notificationItem.isMms();
|
|
}
|
|
|
|
Intent intent = new Intent(context, DeleteNotificationReceiver.class);
|
|
intent.setAction(DeleteNotificationReceiver.DELETE_NOTIFICATION_ACTION);
|
|
intent.putExtra(DeleteNotificationReceiver.EXTRA_IDS, ids);
|
|
intent.putExtra(DeleteNotificationReceiver.EXTRA_MMS, mms);
|
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
|
|
int intentFlags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
intentFlags |= PendingIntent.FLAG_MUTABLE;
|
|
}
|
|
|
|
return PendingIntent.getBroadcast(context, 0, intent, intentFlags);
|
|
}
|
|
|
|
|
|
}
|