2018-02-02 03:29:09 +01:00
|
|
|
/*
|
2012-10-29 00:04:24 +01:00
|
|
|
* Copyright (C) 2012 Moxie Marlinspike
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.database.model;
|
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 21:22:04 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient;
|
2015-11-24 16:06:41 +01:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsColumns;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 21:22:04 +02:00
|
|
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base class for all message record models. Encapsulates basic data
|
|
|
|
* shared between ThreadRecord and MessageRecord.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
public abstract class DisplayRecord {
|
2013-04-30 20:14:01 +02:00
|
|
|
protected final long type;
|
2017-08-01 17:56:00 +02:00
|
|
|
private final Recipient recipient;
|
2014-02-15 00:59:57 +01:00
|
|
|
private final long dateSent;
|
|
|
|
private final long dateReceived;
|
|
|
|
private final long threadId;
|
2018-02-02 03:29:09 +01:00
|
|
|
private final String body;
|
2015-11-24 16:06:41 +01:00
|
|
|
private final int deliveryStatus;
|
2017-09-16 07:38:53 +02:00
|
|
|
private final int deliveryReceiptCount;
|
|
|
|
private final int readReceiptCount;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
2019-03-13 22:28:16 +01:00
|
|
|
DisplayRecord(String body, Recipient recipient, long dateSent,
|
2021-05-31 07:53:25 +02:00
|
|
|
long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount,
|
|
|
|
long type, int readReceiptCount)
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 21:22:04 +02:00
|
|
|
{
|
2014-02-15 00:59:57 +01:00
|
|
|
this.threadId = threadId;
|
2017-08-01 17:56:00 +02:00
|
|
|
this.recipient = recipient;
|
2014-02-15 00:59:57 +01:00
|
|
|
this.dateSent = dateSent;
|
|
|
|
this.dateReceived = dateReceived;
|
|
|
|
this.type = type;
|
|
|
|
this.body = body;
|
2017-09-16 07:38:53 +02:00
|
|
|
this.deliveryReceiptCount = deliveryReceiptCount;
|
|
|
|
this.readReceiptCount = readReceiptCount;
|
2015-11-24 16:06:41 +01:00
|
|
|
this.deliveryStatus = deliveryStatus;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
|
2018-02-02 04:22:48 +01:00
|
|
|
public @NonNull String getBody() {
|
|
|
|
return body == null ? "" : body;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
2019-03-13 22:28:16 +01:00
|
|
|
public abstract SpannableString getDisplayBody(@NonNull Context context);
|
2021-06-22 07:41:14 +02:00
|
|
|
public Recipient getRecipient() { return recipient; }
|
|
|
|
public long getDateSent() { return dateSent; }
|
|
|
|
public long getDateReceived() { return dateReceived; }
|
|
|
|
public long getThreadId() { return threadId; }
|
|
|
|
public int getDeliveryStatus() { return deliveryStatus; }
|
|
|
|
public int getDeliveryReceiptCount() { return deliveryReceiptCount; }
|
|
|
|
public int getReadReceiptCount() { return readReceiptCount; }
|
2021-04-15 06:41:29 +02:00
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isDelivered() {
|
|
|
|
return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE
|
|
|
|
&& deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0;
|
2014-02-15 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 07:41:14 +02:00
|
|
|
public boolean isSent() {
|
|
|
|
return !isFailed() && !isPending();
|
|
|
|
}
|
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isFailed() {
|
|
|
|
return MmsSmsColumns.Types.isFailedMessageType(type)
|
|
|
|
|| MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type)
|
|
|
|
|| deliveryStatus >= SmsDatabase.Status.STATUS_FAILED;
|
2016-08-16 05:23:56 +02:00
|
|
|
}
|
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isPending() {
|
|
|
|
return MmsSmsColumns.Types.isPendingMessageType(type)
|
|
|
|
&& !MmsSmsColumns.Types.isIdentityVerified(type)
|
|
|
|
&& !MmsSmsColumns.Types.isIdentityDefault(type);
|
2021-04-09 08:06:12 +02:00
|
|
|
}
|
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isRead() { return readReceiptCount > 0; }
|
2021-04-09 08:06:12 +02:00
|
|
|
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isOutgoing() {
|
|
|
|
return MmsSmsColumns.Types.isOutgoingMessageType(type);
|
2021-04-09 08:06:12 +02:00
|
|
|
}
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isGroupUpdateMessage() {
|
|
|
|
return SmsDatabase.Types.isGroupUpdateMessage(type);
|
2021-05-12 00:40:10 +02:00
|
|
|
}
|
2021-05-31 07:53:25 +02:00
|
|
|
public boolean isExpirationTimerUpdate() { return SmsDatabase.Types.isExpirationTimerUpdate(type); }
|
|
|
|
public boolean isMediaSavedNotification() { return MmsSmsColumns.Types.isMediaSavedExtraction(type); }
|
|
|
|
public boolean isScreenshotNotification() { return MmsSmsColumns.Types.isScreenshotExtraction(type); }
|
|
|
|
public boolean isDataExtractionNotification() { return isMediaSavedNotification() || isScreenshotNotification(); }
|
|
|
|
public boolean isOpenGroupInvitation() { return MmsSmsColumns.Types.isOpenGroupInvitation(type); }
|
2015-09-21 19:54:23 +02:00
|
|
|
public boolean isCallLog() {
|
|
|
|
return SmsDatabase.Types.isCallLog(type);
|
|
|
|
}
|
|
|
|
public boolean isIncomingCall() {
|
|
|
|
return SmsDatabase.Types.isIncomingCall(type);
|
|
|
|
}
|
|
|
|
public boolean isOutgoingCall() {
|
|
|
|
return SmsDatabase.Types.isOutgoingCall(type);
|
|
|
|
}
|
|
|
|
public boolean isMissedCall() {
|
|
|
|
return SmsDatabase.Types.isMissedCall(type);
|
|
|
|
}
|
2021-08-12 03:43:33 +02:00
|
|
|
public boolean isDeleted() { return MmsSmsColumns.Types.isDeletedMessage(type); }
|
2021-06-01 02:02:20 +02:00
|
|
|
|
|
|
|
public boolean isControlMessage() {
|
|
|
|
return isGroupUpdateMessage() || isExpirationTimerUpdate() || isDataExtractionNotification();
|
|
|
|
}
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|