2013-02-08 20:57:54 +01:00
|
|
|
package org.thoughtcrime.securesms.notifications;
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2020-03-27 17:08:22 +01:00
|
|
|
|
2019-06-05 21:47:14 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.app.TaskStackBuilder;
|
2013-02-08 20:57:54 +01:00
|
|
|
|
2019-02-01 04:28:40 +01:00
|
|
|
import org.thoughtcrime.securesms.conversation.ConversationActivity;
|
2020-03-27 17:08:22 +01:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2015-08-01 01:46:17 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
2013-04-26 03:59:49 +02:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2013-02-08 20:57:54 +01:00
|
|
|
|
|
|
|
public class NotificationItem {
|
|
|
|
|
2020-03-27 17:08:22 +01:00
|
|
|
private final long id;
|
|
|
|
private final boolean mms;
|
|
|
|
@NonNull private final Recipient conversationRecipient;
|
|
|
|
@NonNull private final Recipient individualRecipient;
|
|
|
|
@Nullable private final Recipient threadRecipient;
|
|
|
|
private final long threadId;
|
|
|
|
@Nullable private final CharSequence text;
|
|
|
|
private final long notificationTimestamp;
|
|
|
|
private final long messageReceivedTimestamp;
|
|
|
|
@Nullable private final SlideDeck slideDeck;
|
|
|
|
private final boolean jumpToMessage;
|
|
|
|
|
|
|
|
public NotificationItem(long id,
|
|
|
|
boolean mms,
|
|
|
|
@NonNull Recipient individualRecipient,
|
|
|
|
@NonNull Recipient conversationRecipient,
|
|
|
|
@Nullable Recipient threadRecipient,
|
|
|
|
long threadId,
|
|
|
|
@Nullable CharSequence text,
|
|
|
|
long notificationTimestamp,
|
|
|
|
long messageReceivedTimestamp,
|
|
|
|
@Nullable SlideDeck slideDeck,
|
|
|
|
boolean jumpToMessage)
|
2013-04-26 03:59:49 +02:00
|
|
|
{
|
2020-03-27 17:08:22 +01:00
|
|
|
this.id = id;
|
|
|
|
this.mms = mms;
|
|
|
|
this.individualRecipient = individualRecipient;
|
|
|
|
this.conversationRecipient = conversationRecipient;
|
|
|
|
this.threadRecipient = threadRecipient;
|
|
|
|
this.text = text;
|
|
|
|
this.threadId = threadId;
|
|
|
|
this.notificationTimestamp = notificationTimestamp;
|
|
|
|
this.messageReceivedTimestamp = messageReceivedTimestamp;
|
|
|
|
this.slideDeck = slideDeck;
|
|
|
|
this.jumpToMessage = jumpToMessage;
|
2013-02-08 20:57:54 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 17:56:00 +02:00
|
|
|
public @NonNull Recipient getRecipient() {
|
|
|
|
return threadRecipient == null ? conversationRecipient : threadRecipient;
|
2015-06-09 16:37:20 +02:00
|
|
|
}
|
|
|
|
|
2015-12-05 00:00:13 +01:00
|
|
|
public @NonNull Recipient getIndividualRecipient() {
|
2013-04-26 03:59:49 +02:00
|
|
|
return individualRecipient;
|
2013-02-08 20:57:54 +01:00
|
|
|
}
|
|
|
|
|
2019-05-22 18:51:56 +02:00
|
|
|
public @Nullable CharSequence getText() {
|
2013-02-08 20:57:54 +01:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2015-03-09 22:27:50 +01:00
|
|
|
public long getTimestamp() {
|
2020-03-27 17:08:22 +01:00
|
|
|
return notificationTimestamp;
|
2015-03-09 22:27:50 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 20:57:54 +01:00
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:32:19 +02:00
|
|
|
public @Nullable SlideDeck getSlideDeck() {
|
2015-08-01 01:46:17 +02:00
|
|
|
return slideDeck;
|
|
|
|
}
|
|
|
|
|
2013-02-08 20:57:54 +01:00
|
|
|
public PendingIntent getPendingIntent(Context context) {
|
2020-03-27 17:08:22 +01:00
|
|
|
Recipient recipient = threadRecipient != null ? threadRecipient : conversationRecipient;
|
|
|
|
int startingPosition = jumpToMessage ? getStartingPosition(context, threadId, messageReceivedTimestamp) : -1;
|
|
|
|
Intent intent = ConversationActivity.buildIntent(context, recipient.getId(), threadId, 0, -1, startingPosition);
|
2013-02-08 20:57:54 +01:00
|
|
|
|
2015-12-15 15:04:47 +01:00
|
|
|
return TaskStackBuilder.create(context)
|
|
|
|
.addNextIntentWithParentStack(intent)
|
|
|
|
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
2013-02-08 20:57:54 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 02:38:55 +01:00
|
|
|
public long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
2015-06-22 17:46:43 +02:00
|
|
|
|
2017-03-09 02:38:55 +01:00
|
|
|
public boolean isMms() {
|
|
|
|
return mms;
|
|
|
|
}
|
2020-03-27 17:08:22 +01:00
|
|
|
|
|
|
|
private static int getStartingPosition(@NonNull Context context, long threadId, long receivedTimestampMs) {
|
|
|
|
return DatabaseFactory.getMmsSmsDatabase(context).getMessagePositionInConversation(threadId, receivedTimestampMs);
|
|
|
|
}
|
2013-02-08 20:57:54 +01:00
|
|
|
}
|