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;
|
2020-08-19 02:06:26 +02:00
|
|
|
import androidx.annotation.NonNull;
|
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.text.SpannableString;
|
|
|
|
|
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;
|
2021-01-13 07:11:30 +01:00
|
|
|
import org.session.libsession.messaging.threads.recipients.Recipient;
|
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,
|
2018-02-02 03:29:09 +01: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
|
|
|
}
|
|
|
|
|
2015-11-24 16:06:41 +01:00
|
|
|
public boolean isFailed() {
|
|
|
|
return
|
|
|
|
MmsSmsColumns.Types.isFailedMessageType(type) ||
|
|
|
|
MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type) ||
|
|
|
|
deliveryStatus >= SmsDatabase.Status.STATUS_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPending() {
|
2017-06-07 03:03:09 +02:00
|
|
|
return MmsSmsColumns.Types.isPendingMessageType(type) &&
|
|
|
|
!MmsSmsColumns.Types.isIdentityVerified(type) &&
|
|
|
|
!MmsSmsColumns.Types.isIdentityDefault(type);
|
2015-11-24 16:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isOutgoing() {
|
|
|
|
return MmsSmsColumns.Types.isOutgoingMessageType(type);
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:28:16 +01:00
|
|
|
public abstract SpannableString getDisplayBody(@NonNull Context context);
|
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
|
|
|
|
2017-08-01 17:56:00 +02:00
|
|
|
public Recipient getRecipient() {
|
|
|
|
return recipient;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
|
2013-01-06 22:13:14 +01:00
|
|
|
public long getDateSent() {
|
|
|
|
return dateSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getDateReceived() {
|
|
|
|
return dateReceived;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isKeyExchange() {
|
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
|
|
|
return SmsDatabase.Types.isKeyExchangeType(type);
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
2013-04-30 20:14:01 +02:00
|
|
|
|
2019-12-06 03:00:08 +01:00
|
|
|
public boolean isEndSession() { return SmsDatabase.Types.isEndSessionType(type); }
|
2019-12-05 03:56:12 +01:00
|
|
|
|
|
|
|
public boolean isLokiSessionRestoreSent() { return SmsDatabase.Types.isLokiSessionRestoreSentType(type); }
|
|
|
|
|
2020-08-24 03:41:39 +02:00
|
|
|
public boolean isLokiSessionRestoreDone() { return SmsDatabase.Types.isLokiSessionRestoreDoneType(type); }
|
|
|
|
|
2014-02-22 02:51:25 +01:00
|
|
|
public boolean isGroupUpdate() {
|
|
|
|
return SmsDatabase.Types.isGroupUpdate(type);
|
2014-02-20 06:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGroupQuit() {
|
|
|
|
return SmsDatabase.Types.isGroupQuit(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGroupAction() {
|
2014-02-22 02:51:25 +01:00
|
|
|
return isGroupUpdate() || isGroupQuit();
|
2014-02-15 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
2016-08-16 05:23:56 +02:00
|
|
|
public boolean isExpirationTimerUpdate() {
|
|
|
|
return SmsDatabase.Types.isExpirationTimerUpdate(type);
|
|
|
|
}
|
|
|
|
|
2015-09-21 19:54:23 +02:00
|
|
|
public boolean isCallLog() {
|
|
|
|
return SmsDatabase.Types.isCallLog(type);
|
|
|
|
}
|
|
|
|
|
2015-10-27 20:18:02 +01:00
|
|
|
public boolean isJoined() {
|
|
|
|
return SmsDatabase.Types.isJoinedType(type);
|
|
|
|
}
|
|
|
|
|
2015-09-21 19:54:23 +02:00
|
|
|
public boolean isIncomingCall() {
|
|
|
|
return SmsDatabase.Types.isIncomingCall(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isOutgoingCall() {
|
|
|
|
return SmsDatabase.Types.isOutgoingCall(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMissedCall() {
|
|
|
|
return SmsDatabase.Types.isMissedCall(type);
|
|
|
|
}
|
|
|
|
|
2017-10-04 20:50:12 +02:00
|
|
|
public boolean isVerificationStatusChange() {
|
|
|
|
return SmsDatabase.Types.isIdentityDefault(type) || SmsDatabase.Types.isIdentityVerified(type);
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:06:41 +01:00
|
|
|
public int getDeliveryStatus() {
|
|
|
|
return deliveryStatus;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:38:53 +02:00
|
|
|
public int getDeliveryReceiptCount() {
|
|
|
|
return deliveryReceiptCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getReadReceiptCount() {
|
|
|
|
return readReceiptCount;
|
2015-11-24 16:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDelivered() {
|
|
|
|
return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE &&
|
2017-09-16 07:38:53 +02:00
|
|
|
deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRemoteRead() {
|
|
|
|
return readReceiptCount > 0;
|
2015-11-24 16:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPendingInsecureSmsFallback() {
|
|
|
|
return SmsDatabase.Types.isPendingInsecureSmsFallbackType(type);
|
|
|
|
}
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|