Remove unnecessary body model

This commit is contained in:
Moxie Marlinspike 2018-02-01 18:29:09 -08:00
parent 23aee53c7d
commit e6a069af6d
18 changed files with 46 additions and 84 deletions

View File

@ -1077,8 +1077,8 @@
<string name="preferences__choose_your_contact_entry_from_the_contacts_list">Choose your contact entry from the contacts list.</string> <string name="preferences__choose_your_contact_entry_from_the_contacts_list">Choose your contact entry from the contacts list.</string>
<string name="preferences__change_passphrase">Change passphrase</string> <string name="preferences__change_passphrase">Change passphrase</string>
<string name="preferences__change_your_passphrase">Change your passphrase</string> <string name="preferences__change_your_passphrase">Change your passphrase</string>
<string name="preferences__enable_passphrase">Enable passphrase</string> <string name="preferences__enable_passphrase">Enable passphrase screen lock</string>
<string name="preferences__lock_signal_and_message_notifications_with_a_passphrase">Lock Signal and message notifications with a passphrase</string> <string name="preferences__lock_signal_and_message_notifications_with_a_passphrase">Lock screen and notifications with a passphrase</string>
<string name="preferences__screen_security">Screen security</string> <string name="preferences__screen_security">Screen security</string>
<string name="preferences__disable_screen_security_to_allow_screen_shots">Block screenshots in the recents list and inside the app</string> <string name="preferences__disable_screen_security_to_allow_screen_shots">Block screenshots in the recents list and inside the app</string>
<string name="preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity">Auto-lock Signal after a specified time interval of inactivity</string> <string name="preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity">Auto-lock Signal after a specified time interval of inactivity</string>

View File

@ -169,8 +169,8 @@ public class ConfirmIdentityDialog extends AlertDialog {
messageRecord.getIndividualRecipient().getAddress().toPhoneString(), messageRecord.getIndividualRecipient().getAddress().toPhoneString(),
messageRecord.getRecipientDeviceId(), "", messageRecord.getRecipientDeviceId(), "",
messageRecord.getDateSent(), messageRecord.getDateSent(),
legacy ? Base64.decode(messageRecord.getBody().getBody()) : null, legacy ? Base64.decode(messageRecord.getBody()) : null,
!legacy ? Base64.decode(messageRecord.getBody().getBody()) : null); !legacy ? Base64.decode(messageRecord.getBody()) : null);
long pushId = pushDatabase.insert(envelope); long pushId = pushDatabase.insert(envelope);

View File

@ -146,7 +146,7 @@ public class ConversationUpdateItem extends LinearLayout
icon.setImageResource(R.drawable.ic_group_grey600_24dp); icon.setImageResource(R.drawable.ic_group_grey600_24dp);
icon.clearColorFilter(); icon.clearColorFilter();
GroupUtil.getDescription(getContext(), messageRecord.getBody().getBody()).addListener(this); GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this);
body.setText(messageRecord.getDisplayBody()); body.setText(messageRecord.getDisplayBody());
date.setVisibility(View.GONE); date.setVisibility(View.GONE);

View File

@ -41,7 +41,6 @@ import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList;
import org.thoughtcrime.securesms.database.documents.NetworkFailure; import org.thoughtcrime.securesms.database.documents.NetworkFailure;
import org.thoughtcrime.securesms.database.documents.NetworkFailureList; import org.thoughtcrime.securesms.database.documents.NetworkFailureList;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.database.model.DisplayRecord;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord; import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
@ -1011,7 +1010,7 @@ public class MmsDatabase extends MessagingDatabase {
return new MediaMmsMessageRecord(context, id, message.getRecipient(), message.getRecipient(), return new MediaMmsMessageRecord(context, id, message.getRecipient(), message.getRecipient(),
1, System.currentTimeMillis(), System.currentTimeMillis(), 1, System.currentTimeMillis(), System.currentTimeMillis(),
0, threadId, new DisplayRecord.Body(message.getBody(), true), 0, threadId, message.getBody(),
slideDeck, slideDeck.getSlides().size(), slideDeck, slideDeck.getSlides().size(),
message.isSecure() ? MmsSmsColumns.Types.getOutgoingEncryptedMessageType() : MmsSmsColumns.Types.getOutgoingSmsMessageType(), message.isSecure() ? MmsSmsColumns.Types.getOutgoingEncryptedMessageType() : MmsSmsColumns.Types.getOutgoingSmsMessageType(),
new LinkedList<IdentityKeyMismatch>(), new LinkedList<IdentityKeyMismatch>(),
@ -1099,7 +1098,7 @@ public class MmsDatabase extends MessagingDatabase {
int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID)); int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID));
int deliveryReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.DELIVERY_RECEIPT_COUNT)); int deliveryReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.DELIVERY_RECEIPT_COUNT));
int readReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.READ_RECEIPT_COUNT)); int readReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.READ_RECEIPT_COUNT));
DisplayRecord.Body body = getBody(cursor); String body = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.BODY));
int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT)); int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT));
String mismatchDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.MISMATCHED_IDENTITIES)); String mismatchDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.MISMATCHED_IDENTITIES));
String networkDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.NETWORK_FAILURE)); String networkDocument = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.NETWORK_FAILURE));
@ -1159,11 +1158,6 @@ public class MmsDatabase extends MessagingDatabase {
return new LinkedList<>(); return new LinkedList<>();
} }
private DisplayRecord.Body getBody(Cursor cursor) {
String body = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.BODY));
return new DisplayRecord.Body(body == null ? "" : body, true);
}
private SlideDeck getSlideDeck(@NonNull Cursor cursor) { private SlideDeck getSlideDeck(@NonNull Cursor cursor) {
Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(cursor); Attachment attachment = DatabaseFactory.getAttachmentDatabase(context).getAttachment(cursor);
return new SlideDeck(context, attachment); return new SlideDeck(context, attachment);

View File

@ -34,7 +34,6 @@ import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.database.model.DisplayRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.jobs.TrimThreadJob; import org.thoughtcrime.securesms.jobs.TrimThreadJob;
@ -449,7 +448,7 @@ public class SmsDatabase extends MessagingDatabase {
contentValues.put(DATE_SENT, record.getDateSent()); contentValues.put(DATE_SENT, record.getDateSent());
contentValues.put(PROTOCOL, 31337); contentValues.put(PROTOCOL, 31337);
contentValues.put(READ, 0); contentValues.put(READ, 0);
contentValues.put(BODY, record.getBody().getBody()); contentValues.put(BODY, record.getBody());
contentValues.put(THREAD_ID, record.getThreadId()); contentValues.put(THREAD_ID, record.getThreadId());
contentValues.put(EXPIRES_IN, record.getExpiresIn()); contentValues.put(EXPIRES_IN, record.getExpiresIn());
@ -806,7 +805,7 @@ public class SmsDatabase extends MessagingDatabase {
} }
public MessageRecord getCurrent() { public MessageRecord getCurrent() {
return new SmsMessageRecord(context, id, new DisplayRecord.Body(message.getMessageBody(), true), return new SmsMessageRecord(context, id, message.getMessageBody(),
message.getRecipient(), message.getRecipient(), message.getRecipient(), message.getRecipient(),
1, System.currentTimeMillis(), System.currentTimeMillis(), 1, System.currentTimeMillis(), System.currentTimeMillis(),
0, message.isSecureMessage() ? MmsSmsColumns.Types.getOutgoingEncryptedMessageType() : MmsSmsColumns.Types.getOutgoingSmsMessageType(), 0, message.isSecureMessage() ? MmsSmsColumns.Types.getOutgoingEncryptedMessageType() : MmsSmsColumns.Types.getOutgoingSmsMessageType(),
@ -851,6 +850,7 @@ public class SmsDatabase extends MessagingDatabase {
int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.SUBSCRIPTION_ID)); int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.SUBSCRIPTION_ID));
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRES_IN)); long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRES_IN));
long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED)); long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED));
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) { if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
readReceiptCount = 0; readReceiptCount = 0;
@ -858,7 +858,6 @@ public class SmsDatabase extends MessagingDatabase {
List<IdentityKeyMismatch> mismatches = getMismatches(mismatchDocument); List<IdentityKeyMismatch> mismatches = getMismatches(mismatchDocument);
Recipient recipient = Recipient.from(context, address, true); Recipient recipient = Recipient.from(context, address, true);
DisplayRecord.Body body = getBody(cursor);
return new SmsMessageRecord(context, messageId, body, recipient, return new SmsMessageRecord(context, messageId, body, recipient,
recipient, recipient,
@ -880,10 +879,6 @@ public class SmsDatabase extends MessagingDatabase {
return new LinkedList<>(); return new LinkedList<>();
} }
protected DisplayRecord.Body getBody(Cursor cursor) {
return new DisplayRecord.Body(cursor.getString(cursor.getColumnIndexOrThrow(BODY)), true);
}
public void close() { public void close() {
cursor.close(); cursor.close();
} }

View File

@ -34,7 +34,6 @@ import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings; import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.database.model.DisplayRecord;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.database.model.ThreadRecord;
@ -567,7 +566,7 @@ public class ThreadDatabase extends Database {
MessageRecord record; MessageRecord record;
if (reader != null && (record = reader.getNext()) != null) { if (reader != null && (record = reader.getNext()) != null) {
updateThread(threadId, count, record.getBody().getBody(), getAttachmentUriFor(record), updateThread(threadId, count, record.getBody(), getAttachmentUriFor(record),
record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(), record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(),
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount()); record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
notifyConversationListListeners(); notifyConversationListListeners();
@ -658,7 +657,7 @@ public class ThreadDatabase extends Database {
} }
Recipient recipient = Recipient.from(context, address, settings, groupRecord, true); Recipient recipient = Recipient.from(context, address, settings, groupRecord, true);
DisplayRecord.Body body = getPlaintextBody(cursor); String body = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET));
long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE)); long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE));
long count = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT)); long count = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT));
int unreadCount = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.UNREAD_COUNT)); int unreadCount = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.UNREAD_COUNT));
@ -680,10 +679,6 @@ public class ThreadDatabase extends Database {
distributionType, archived, expiresIn, lastSeen, readReceiptCount); distributionType, archived, expiresIn, lastSeen, readReceiptCount);
} }
private DisplayRecord.Body getPlaintextBody(Cursor cursor) {
return new DisplayRecord.Body(cursor.getString(cursor.getColumnIndexOrThrow(SNIPPET)), true);
}
private @Nullable Uri getSnippetUri(Cursor cursor) { private @Nullable Uri getSnippetUri(Cursor cursor) {
if (cursor.isNull(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI))) { if (cursor.isNull(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI))) {
return null; return null;

View File

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2012 Moxie Marlinspike * Copyright (C) 2012 Moxie Marlinspike
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -40,12 +40,12 @@ public abstract class DisplayRecord {
private final long dateSent; private final long dateSent;
private final long dateReceived; private final long dateReceived;
private final long threadId; private final long threadId;
private final Body body; private final String body;
private final int deliveryStatus; private final int deliveryStatus;
private final int deliveryReceiptCount; private final int deliveryReceiptCount;
private final int readReceiptCount; private final int readReceiptCount;
public DisplayRecord(Context context, Body body, Recipient recipient, long dateSent, DisplayRecord(Context context, String body, Recipient recipient, long dateSent,
long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount,
long type, int readReceiptCount) long type, int readReceiptCount)
{ {
@ -61,7 +61,7 @@ public abstract class DisplayRecord {
this.deliveryStatus = deliveryStatus; this.deliveryStatus = deliveryStatus;
} }
public Body getBody() { public String getBody() {
return body; return body;
} }
@ -172,22 +172,4 @@ public abstract class DisplayRecord {
public boolean isPendingInsecureSmsFallback() { public boolean isPendingInsecureSmsFallback() {
return SmsDatabase.Types.isPendingInsecureSmsFallbackType(type); return SmsDatabase.Types.isPendingInsecureSmsFallbackType(type);
} }
public static class Body {
private final String body;
private final boolean plaintext;
public Body(String body, boolean plaintext) {
this.body = body;
this.plaintext = plaintext;
}
public boolean isPlaintext() {
return plaintext;
}
public String getBody() {
return body == null ? "" : body;
}
}
} }

View File

@ -47,7 +47,7 @@ public class MediaMmsMessageRecord extends MmsMessageRecord {
public MediaMmsMessageRecord(Context context, long id, Recipient conversationRecipient, public MediaMmsMessageRecord(Context context, long id, Recipient conversationRecipient,
Recipient individualRecipient, int recipientDeviceId, Recipient individualRecipient, int recipientDeviceId,
long dateSent, long dateReceived, int deliveryReceiptCount, long dateSent, long dateReceived, int deliveryReceiptCount,
long threadId, Body body, long threadId, String body,
@NonNull SlideDeck slideDeck, @NonNull SlideDeck slideDeck,
int partCount, long mailbox, int partCount, long mailbox,
List<IdentityKeyMismatch> mismatches, List<IdentityKeyMismatch> mismatches,
@ -81,8 +81,6 @@ public class MediaMmsMessageRecord extends MmsMessageRecord {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_mms_message_encrypted_for_non_existing_session)); return emphasisAdded(context.getString(R.string.MmsMessageRecord_mms_message_encrypted_for_non_existing_session));
} else if (isLegacyMessage()) { } else if (isLegacyMessage()) {
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported)); return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else if (!getBody().isPlaintext()) {
return emphasisAdded(context.getString(R.string.MessageNotifier_locked_message));
} }
return super.getDisplayBody(); return super.getDisplayBody();

View File

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2012 Moxie Marlinpsike * Copyright (C) 2012 Moxie Marlinpsike
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -54,7 +54,7 @@ public abstract class MessageRecord extends DisplayRecord {
private final long expiresIn; private final long expiresIn;
private final long expireStarted; private final long expireStarted;
MessageRecord(Context context, long id, Body body, Recipient conversationRecipient, MessageRecord(Context context, long id, String body, Recipient conversationRecipient,
Recipient individualRecipient, int recipientDeviceId, Recipient individualRecipient, int recipientDeviceId,
long dateSent, long dateReceived, long threadId, long dateSent, long dateReceived, long threadId,
int deliveryStatus, int deliveryReceiptCount, long type, int deliveryStatus, int deliveryReceiptCount, long type,
@ -91,7 +91,7 @@ public abstract class MessageRecord extends DisplayRecord {
if (isGroupUpdate() && isOutgoing()) { if (isGroupUpdate() && isOutgoing()) {
return emphasisAdded(context.getString(R.string.MessageRecord_you_updated_group)); return emphasisAdded(context.getString(R.string.MessageRecord_you_updated_group));
} else if (isGroupUpdate()) { } else if (isGroupUpdate()) {
return emphasisAdded(GroupUtil.getDescription(context, getBody().getBody()).toString(getIndividualRecipient())); return emphasisAdded(GroupUtil.getDescription(context, getBody()).toString(getIndividualRecipient()));
} else if (isGroupQuit() && isOutgoing()) { } else if (isGroupQuit() && isOutgoing()) {
return emphasisAdded(context.getString(R.string.MessageRecord_left_group)); return emphasisAdded(context.getString(R.string.MessageRecord_left_group));
} else if (isGroupQuit()) { } else if (isGroupQuit()) {
@ -116,11 +116,11 @@ public abstract class MessageRecord extends DisplayRecord {
} else if (isIdentityDefault()) { } else if (isIdentityDefault()) {
if (isOutgoing()) return emphasisAdded(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified, getIndividualRecipient().toShortString())); if (isOutgoing()) return emphasisAdded(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified, getIndividualRecipient().toShortString()));
else return emphasisAdded(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified_from_another_device, getIndividualRecipient().toShortString())); else return emphasisAdded(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified_from_another_device, getIndividualRecipient().toShortString()));
} else if (getBody().getBody().length() > MAX_DISPLAY_LENGTH) { } else if (getBody().length() > MAX_DISPLAY_LENGTH) {
return new SpannableString(getBody().getBody().substring(0, MAX_DISPLAY_LENGTH)); return new SpannableString(getBody().substring(0, MAX_DISPLAY_LENGTH));
} }
return new SpannableString(getBody().getBody()); return new SpannableString(getBody());
} }
public long getId() { public long getId() {

View File

@ -16,7 +16,7 @@ public abstract class MmsMessageRecord extends MessageRecord {
private final @NonNull SlideDeck slideDeck; private final @NonNull SlideDeck slideDeck;
MmsMessageRecord(Context context, long id, Body body, Recipient conversationRecipient, MmsMessageRecord(Context context, long id, String body, Recipient conversationRecipient,
Recipient individualRecipient, int recipientDeviceId, long dateSent, Recipient individualRecipient, int recipientDeviceId, long dateSent,
long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount,
long type, List<IdentityKeyMismatch> mismatches, long type, List<IdentityKeyMismatch> mismatches,

View File

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2012 Moxie Marlinspike * Copyright (C) 2012 Moxie Marlinspike
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -52,7 +52,7 @@ public class NotificationMmsMessageRecord extends MmsMessageRecord {
long expiry, int status, byte[] transactionId, long mailbox, long expiry, int status, byte[] transactionId, long mailbox,
int subscriptionId, SlideDeck slideDeck, int readReceiptCount) int subscriptionId, SlideDeck slideDeck, int readReceiptCount)
{ {
super(context, id, new Body("", true), conversationRecipient, individualRecipient, recipientDeviceId, super(context, id, "", conversationRecipient, individualRecipient, recipientDeviceId,
dateSent, dateReceived, threadId, Status.STATUS_NONE, deliveryReceiptCount, mailbox, dateSent, dateReceived, threadId, Status.STATUS_NONE, deliveryReceiptCount, mailbox,
new LinkedList<IdentityKeyMismatch>(), new LinkedList<NetworkFailure>(), subscriptionId, new LinkedList<IdentityKeyMismatch>(), new LinkedList<NetworkFailure>(), subscriptionId,
0, 0, slideDeck, readReceiptCount); 0, 0, slideDeck, readReceiptCount);

View File

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2012 Moxie Marlinspike * Copyright (C) 2012 Moxie Marlinspike
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -24,7 +24,6 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.MmsSmsColumns; import org.thoughtcrime.securesms.database.MmsSmsColumns;
import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import java.util.LinkedList; import java.util.LinkedList;
@ -40,7 +39,7 @@ import java.util.List;
public class SmsMessageRecord extends MessageRecord { public class SmsMessageRecord extends MessageRecord {
public SmsMessageRecord(Context context, long id, public SmsMessageRecord(Context context, long id,
Body body, Recipient recipient, String body, Recipient recipient,
Recipient individualRecipient, Recipient individualRecipient,
int recipientDeviceId, int recipientDeviceId,
long dateSent, long dateReceived, long dateSent, long dateReceived,
@ -52,7 +51,7 @@ public class SmsMessageRecord extends MessageRecord {
{ {
super(context, id, body, recipient, individualRecipient, recipientDeviceId, super(context, id, body, recipient, individualRecipient, recipientDeviceId,
dateSent, dateReceived, threadId, status, deliveryReceiptCount, type, dateSent, dateReceived, threadId, status, deliveryReceiptCount, type,
mismatches, new LinkedList<NetworkFailure>(), subscriptionId, mismatches, new LinkedList<>(), subscriptionId,
expiresIn, expireStarted, readReceiptCount); expiresIn, expireStarted, readReceiptCount);
} }
@ -80,8 +79,6 @@ public class SmsMessageRecord extends MessageRecord {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message)); return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));
} else if (SmsDatabase.Types.isNoRemoteSessionType(type)) { } else if (SmsDatabase.Types.isNoRemoteSessionType(type)) {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session)); return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
} else if (!getBody().isPlaintext()) {
return emphasisAdded(context.getString(R.string.MessageNotifier_locked_message));
} else if (isEndSession() && isOutgoing()) { } else if (isEndSession() && isOutgoing()) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset)); return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset));
} else if (isEndSession()) { } else if (isEndSession()) {

View File

@ -49,7 +49,7 @@ public class ThreadRecord extends DisplayRecord {
private final long expiresIn; private final long expiresIn;
private final long lastSeen; private final long lastSeen;
public ThreadRecord(@NonNull Context context, @NonNull Body body, @Nullable Uri snippetUri, public ThreadRecord(@NonNull Context context, @NonNull String body, @Nullable Uri snippetUri,
@NonNull Recipient recipient, long date, long count, int unreadCount, @NonNull Recipient recipient, long date, long count, int unreadCount,
long threadId, int deliveryReceiptCount, int status, long snippetType, long threadId, int deliveryReceiptCount, int status, long snippetType,
int distributionType, boolean archived, long expiresIn, long lastSeen, int distributionType, boolean archived, long expiresIn, long lastSeen,
@ -82,15 +82,13 @@ public class ThreadRecord extends DisplayRecord {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_bad_encrypted_message)); return emphasisAdded(context.getString(R.string.MessageDisplayHelper_bad_encrypted_message));
} else if (SmsDatabase.Types.isNoRemoteSessionType(type)) { } else if (SmsDatabase.Types.isNoRemoteSessionType(type)) {
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session)); return emphasisAdded(context.getString(R.string.MessageDisplayHelper_message_encrypted_for_non_existing_session));
} else if (!getBody().isPlaintext()) {
return emphasisAdded(context.getString(R.string.MessageNotifier_locked_message));
} else if (SmsDatabase.Types.isEndSessionType(type)) { } else if (SmsDatabase.Types.isEndSessionType(type)) {
return emphasisAdded(context.getString(R.string.ThreadRecord_secure_session_reset)); return emphasisAdded(context.getString(R.string.ThreadRecord_secure_session_reset));
} else if (MmsSmsColumns.Types.isLegacyType(type)) { } 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)); return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else if (MmsSmsColumns.Types.isDraftMessageType(type)) { } else if (MmsSmsColumns.Types.isDraftMessageType(type)) {
String draftText = context.getString(R.string.ThreadRecord_draft); String draftText = context.getString(R.string.ThreadRecord_draft);
return emphasisAdded(draftText + " " + getBody().getBody(), 0, draftText.length()); return emphasisAdded(draftText + " " + getBody(), 0, draftText.length());
} else if (SmsDatabase.Types.isOutgoingCall(type)) { } else if (SmsDatabase.Types.isOutgoingCall(type)) {
return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_called)); return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_called));
} else if (SmsDatabase.Types.isIncomingCall(type)) { } else if (SmsDatabase.Types.isIncomingCall(type)) {
@ -110,10 +108,10 @@ public class ThreadRecord extends DisplayRecord {
} else if (SmsDatabase.Types.isIdentityDefault(type)) { } else if (SmsDatabase.Types.isIdentityDefault(type)) {
return emphasisAdded(context.getString(R.string.ThreadRecord_you_marked_unverified)); return emphasisAdded(context.getString(R.string.ThreadRecord_you_marked_unverified));
} else { } else {
if (TextUtils.isEmpty(getBody().getBody())) { if (TextUtils.isEmpty(getBody())) {
return new SpannableString(emphasisAdded(context.getString(R.string.ThreadRecord_media_message))); return new SpannableString(emphasisAdded(context.getString(R.string.ThreadRecord_media_message)));
} else { } else {
return new SpannableString(getBody().getBody()); return new SpannableString(getBody());
} }
} }
} }

View File

@ -102,7 +102,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient()); Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient());
SignalServiceDataMessage textSecureMessage = SignalServiceDataMessage.newBuilder() SignalServiceDataMessage textSecureMessage = SignalServiceDataMessage.newBuilder()
.withTimestamp(message.getDateSent()) .withTimestamp(message.getDateSent())
.withBody(message.getBody().getBody()) .withBody(message.getBody())
.withExpiration((int)(message.getExpiresIn() / 1000)) .withExpiration((int)(message.getExpiresIn() / 1000))
.withProfileKey(profileKey.orNull()) .withProfileKey(profileKey.orNull())
.asEndSessionMessage(message.isEndSession()) .asEndSessionMessage(message.isEndSession())

View File

@ -93,7 +93,7 @@ public class SmsSendJob extends SendJob {
throw new UndeliverableMessageException("Not a valid SMS destination! " + recipient); throw new UndeliverableMessageException("Not a valid SMS destination! " + recipient);
} }
ArrayList<String> messages = SmsManager.getDefault().divideMessage(message.getBody().getBody()); ArrayList<String> messages = SmsManager.getDefault().divideMessage(message.getBody());
ArrayList<PendingIntent> sentIntents = constructSentIntents(message.getId(), message.getType(), messages, false); ArrayList<PendingIntent> sentIntents = constructSentIntents(message.getId(), message.getType(), messages, false);
ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages); ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages);

View File

@ -42,7 +42,6 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo; import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.MmsSmsDatabase;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord;
@ -427,7 +426,7 @@ public class MessageNotifier {
threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId); threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId);
} }
if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) { if (KeyCachingService.isLocked(context)) {
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message)); body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
} else if (record.isMms() && TextUtils.isEmpty(body)) { } else if (record.isMms() && TextUtils.isEmpty(body)) {
body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message)); body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));

View File

@ -78,6 +78,10 @@ public class KeyCachingService extends Service {
public KeyCachingService() {} public KeyCachingService() {}
public static synchronized boolean isLocked(Context context) {
return getMasterSecret(context) == null;
}
public static synchronized @Nullable MasterSecret getMasterSecret(Context context) { public static synchronized @Nullable MasterSecret getMasterSecret(Context context) {
if (masterSecret == null && TextSecurePreferences.isPasswordDisabled(context)) { if (masterSecret == null && TextSecurePreferences.isPasswordDisabled(context)) {
try { try {

View File

@ -70,13 +70,13 @@ public class OutgoingTextMessage {
public static OutgoingTextMessage from(SmsMessageRecord record) { public static OutgoingTextMessage from(SmsMessageRecord record) {
if (record.isSecure()) { if (record.isSecure()) {
return new OutgoingEncryptedMessage(record.getRecipient(), record.getBody().getBody(), record.getExpiresIn()); return new OutgoingEncryptedMessage(record.getRecipient(), record.getBody(), record.getExpiresIn());
} else if (record.isKeyExchange()) { } else if (record.isKeyExchange()) {
return new OutgoingKeyExchangeMessage(record.getRecipient(), record.getBody().getBody()); return new OutgoingKeyExchangeMessage(record.getRecipient(), record.getBody());
} else if (record.isEndSession()) { } else if (record.isEndSession()) {
return new OutgoingEndSessionMessage(new OutgoingTextMessage(record.getRecipient(), record.getBody().getBody(), 0, -1)); return new OutgoingEndSessionMessage(new OutgoingTextMessage(record.getRecipient(), record.getBody(), 0, -1));
} else { } else {
return new OutgoingTextMessage(record.getRecipient(), record.getBody().getBody(), record.getExpiresIn(), record.getSubscriptionId()); return new OutgoingTextMessage(record.getRecipient(), record.getBody(), record.getExpiresIn(), record.getSubscriptionId());
} }
} }