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;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-10-16 22:59:40 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
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.Spannable;
|
|
|
|
import android.text.SpannableString;
|
2014-11-12 20:15:05 +01:00
|
|
|
import android.text.TextUtils;
|
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.style.StyleSpan;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2014-04-11 00:20:43 +02: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;
|
2015-11-24 16:06:41 +01:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
2012-10-29 00:04:24 +01:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2016-08-16 05:23:56 +02:00
|
|
|
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
2014-02-17 20:42:51 +01:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The message record model which represents thread heading messages.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ThreadRecord extends DisplayRecord {
|
|
|
|
|
2015-10-16 22:59:40 +02:00
|
|
|
private @NonNull final Context context;
|
|
|
|
private @Nullable final Uri snippetUri;
|
|
|
|
private final long count;
|
|
|
|
private final boolean read;
|
|
|
|
private final int distributionType;
|
2015-11-24 00:07:41 +01:00
|
|
|
private final boolean archived;
|
2016-08-16 05:23:56 +02:00
|
|
|
private final long expiresIn;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
2015-10-16 22:59:40 +02:00
|
|
|
public ThreadRecord(@NonNull Context context, @NonNull Body body, @Nullable Uri snippetUri,
|
|
|
|
@NonNull Recipients recipients, long date, long count, boolean read,
|
2015-11-24 16:06:41 +01:00
|
|
|
long threadId, int receiptCount, int status, long snippetType,
|
2016-08-16 05:23:56 +02:00
|
|
|
int distributionType, boolean archived, long expiresIn)
|
2012-10-29 00:04:24 +01:00
|
|
|
{
|
2015-11-24 16:06:41 +01:00
|
|
|
super(context, body, recipients, date, date, threadId, status, receiptCount, snippetType);
|
2013-04-26 03:59:49 +02:00
|
|
|
this.context = context.getApplicationContext();
|
2015-10-16 22:59:40 +02:00
|
|
|
this.snippetUri = snippetUri;
|
2013-04-26 03:59:49 +02:00
|
|
|
this.count = count;
|
|
|
|
this.read = read;
|
|
|
|
this.distributionType = distributionType;
|
2015-11-24 00:07:41 +01:00
|
|
|
this.archived = archived;
|
2016-08-16 05:23:56 +02:00
|
|
|
this.expiresIn = expiresIn;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-10-16 22:59:40 +02:00
|
|
|
public @Nullable Uri getSnippetUri() {
|
|
|
|
return snippetUri;
|
|
|
|
}
|
|
|
|
|
2012-10-29 00:04:24 +01:00
|
|
|
@Override
|
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
|
|
|
public SpannableString getDisplayBody() {
|
|
|
|
if (SmsDatabase.Types.isDecryptInProgressType(type)) {
|
|
|
|
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
|
2014-02-22 02:51:25 +01:00
|
|
|
} else if (isGroupUpdate()) {
|
2015-09-17 02:31:24 +02:00
|
|
|
return emphasisAdded(GroupUtil.getDescription(context, getBody().getBody()).toString());
|
2014-02-20 06:06:54 +01:00
|
|
|
} else if (isGroupQuit()) {
|
2014-02-22 20:10:30 +01:00
|
|
|
return emphasisAdded(context.getString(R.string.ThreadRecord_left_the_group));
|
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
|
|
|
} else if (isKeyExchange()) {
|
|
|
|
return emphasisAdded(context.getString(R.string.ConversationListItem_key_exchange_message));
|
|
|
|
} else if (SmsDatabase.Types.isFailedDecryptType(type)) {
|
|
|
|
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_bad_encrypted_message));
|
|
|
|
} else if (SmsDatabase.Types.isNoRemoteSessionType(type)) {
|
|
|
|
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
|
2013-04-30 20:14:01 +02:00
|
|
|
} else if (!getBody().isPlaintext()) {
|
2015-07-18 02:46:02 +02:00
|
|
|
return emphasisAdded(context.getString(R.string.MessageNotifier_locked_message));
|
2014-02-19 22:46:49 +01:00
|
|
|
} else if (SmsDatabase.Types.isEndSessionType(type)) {
|
2015-10-04 05:13:34 +02:00
|
|
|
return emphasisAdded(context.getString(R.string.ThreadRecord_secure_session_reset));
|
2014-04-11 00:20:43 +02:00
|
|
|
} else if (MmsSmsColumns.Types.isLegacyType(type)) {
|
|
|
|
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
|
2014-12-12 02:13:01 +01:00
|
|
|
} else if (MmsSmsColumns.Types.isDraftMessageType(type)) {
|
|
|
|
String draftText = context.getString(R.string.ThreadRecord_draft);
|
|
|
|
return emphasisAdded(draftText + " " + getBody().getBody(), 0, draftText.length());
|
2015-10-02 01:48:57 +02:00
|
|
|
} else if (SmsDatabase.Types.isOutgoingCall(type)) {
|
2015-10-02 02:54:05 +02:00
|
|
|
return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_called));
|
2015-10-02 01:48:57 +02:00
|
|
|
} else if (SmsDatabase.Types.isIncomingCall(type)) {
|
2015-10-02 02:54:05 +02:00
|
|
|
return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_called_you));
|
2015-10-02 01:48:57 +02:00
|
|
|
} else if (SmsDatabase.Types.isMissedCall(type)) {
|
2015-10-02 02:54:05 +02:00
|
|
|
return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_missed_call));
|
2015-10-27 20:18:02 +01:00
|
|
|
} else if (SmsDatabase.Types.isJoinedType(type)) {
|
|
|
|
return emphasisAdded(context.getString(R.string.ThreadRecord_s_is_on_signal_say_hey, getRecipients().getPrimaryRecipient().toShortString()));
|
2016-08-16 05:23:56 +02:00
|
|
|
} else if (SmsDatabase.Types.isExpirationTimerUpdate(type)) {
|
|
|
|
String time = ExpirationUtil.getExpirationDisplayValue(context, (int)(getExpiresIn() / 1000));
|
|
|
|
return emphasisAdded(context.getString(R.string.ThreadRecord_disappearing_message_time_updated_to_s, time));
|
2012-10-29 00:04:24 +01:00
|
|
|
} else {
|
2014-11-12 20:15:05 +01:00
|
|
|
if (TextUtils.isEmpty(getBody().getBody())) {
|
2015-10-16 22:59:40 +02:00
|
|
|
return new SpannableString(emphasisAdded(context.getString(R.string.ThreadRecord_media_message)));
|
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
|
|
|
} else {
|
2013-04-30 20:14:01 +02:00
|
|
|
return new SpannableString(getBody().getBody());
|
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
|
|
|
}
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
private SpannableString emphasisAdded(String sequence) {
|
2014-12-12 02:13:01 +01:00
|
|
|
return emphasisAdded(sequence, 0, sequence.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
private SpannableString emphasisAdded(String sequence, int start, int end) {
|
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
|
|
|
SpannableString spannable = new SpannableString(sequence);
|
2014-12-12 02:13:01 +01:00
|
|
|
spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),
|
|
|
|
start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
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 spannable;
|
|
|
|
}
|
|
|
|
|
2012-10-29 00:04:24 +01:00
|
|
|
public long getCount() {
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRead() {
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
2013-01-06 22:13:14 +01:00
|
|
|
public long getDate() {
|
|
|
|
return getDateReceived();
|
|
|
|
}
|
|
|
|
|
2015-11-24 00:07:41 +01:00
|
|
|
public boolean isArchived() {
|
|
|
|
return archived;
|
|
|
|
}
|
|
|
|
|
2013-04-26 03:59:49 +02:00
|
|
|
public int getDistributionType() {
|
|
|
|
return distributionType;
|
|
|
|
}
|
2016-08-16 05:23:56 +02:00
|
|
|
|
|
|
|
public long getExpiresIn() {
|
|
|
|
return expiresIn;
|
|
|
|
}
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|