diff --git a/src/org/thoughtcrime/securesms/ConversationFragment.java b/src/org/thoughtcrime/securesms/ConversationFragment.java index 4bed8af509..187f727a83 100644 --- a/src/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationFragment.java @@ -136,10 +136,15 @@ public class ConversationFragment extends SherlockListFragment private void handleDisplayDetails(MessageRecord message) { String sender = message.getIndividualRecipient().getNumber(); - String transport = message.isMms() ? "mms" : "sms"; long dateReceived = message.getDateReceived(); long dateSent = message.getDateSent(); + String transport; + + if (message.isPush()) transport = "push"; + else if (message.isMms()) transport = "mms"; + else transport = "sms"; + SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE MMM d, yyyy 'at' hh:mm:ss a zzz"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index 2278f9989f..9c74e89dfb 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -175,7 +175,7 @@ public class ConversationItem extends LinearLayout { private void setBodyText(MessageRecord messageRecord) { // TODO jake is going to fix this up - if (messageRecord.isPushSent()) { + if (messageRecord.isPush() && messageRecord.isOutgoing()) { bodyText.setText("PUSH " + messageRecord.getDisplayBody()); return; } diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index a48e79712e..bfb6b2d6a2 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -308,6 +308,10 @@ public class MmsDatabase extends Database implements MmsSmsColumns { updateMailboxBitmask(messageId, 0, Types.SECURE_MESSAGE_BIT); } + public void markAsPush(long messageId) { + updateMailboxBitmask(messageId, 0, Types.PUSH_MESSAGE_BIT); + } + public void markAsDecryptFailed(long messageId, long threadId) { updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT); notifyConversationListeners(threadId); @@ -448,7 +452,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns { throws MmsException { return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId, - Types.BASE_INBOX_TYPE | Types.ENCRYPTION_SYMMETRIC_BIT); + Types.BASE_INBOX_TYPE | Types.ENCRYPTION_SYMMETRIC_BIT | + (retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0)); } public Pair insertSecureMessageInbox(MasterSecret masterSecret, @@ -457,7 +462,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns { throws MmsException { return insertMessageInbox(masterSecret, retrieved, contentLocation, threadId, - Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_REMOTE_BIT); + Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | + Types.ENCRYPTION_REMOTE_BIT); } public Pair insertSecureDecryptedMessageInbox(MasterSecret masterSecret, @@ -466,7 +472,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns { throws MmsException { return insertMessageInbox(masterSecret, retrieved, "", threadId, - Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_SYMMETRIC_BIT); + Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | + Types.ENCRYPTION_SYMMETRIC_BIT | + (retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0)); } public Pair insertMessageInbox(NotificationInd notification) { @@ -870,7 +878,6 @@ public class MmsDatabase extends Database implements MmsSmsColumns { long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID)); String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS)); int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID)); - int status = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.STATUS)); DisplayRecord.Body body = getBody(cursor); int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT)); Recipients recipients = getRecipientsFor(address); @@ -879,7 +886,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns { return new MediaMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(), addressDeviceId, dateSent, dateReceived, threadId, body, - slideDeck, partCount, status, box); + slideDeck, partCount, box); } private Recipients getRecipientsFor(String address) { diff --git a/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java b/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java index 3eeff0709b..4e5511479a 100644 --- a/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java +++ b/src/org/thoughtcrime/securesms/database/MmsSmsColumns.java @@ -38,6 +38,7 @@ public interface MmsSmsColumns { // Secure Message Information protected static final long SECURE_MESSAGE_BIT = 0x800000; protected static final long END_SESSION_BIT = 0x400000; + protected static final long PUSH_MESSAGE_BIT = 0x200000; // Group Message Information protected static final long GROUP_ADD_MEMBERS_BIT = 0x10000; @@ -79,6 +80,10 @@ public interface MmsSmsColumns { return (type & SECURE_MESSAGE_BIT) != 0; } + public static boolean isPushType(long type) { + return (type & PUSH_MESSAGE_BIT) != 0; + } + public static boolean isEndSessionType(long type) { return (type & END_SESSION_BIT) != 0; } diff --git a/src/org/thoughtcrime/securesms/database/SmsDatabase.java b/src/org/thoughtcrime/securesms/database/SmsDatabase.java index 7a9cc27868..f749cae90c 100644 --- a/src/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -174,6 +174,10 @@ public class SmsDatabase extends Database implements MmsSmsColumns { updateTypeBitmask(id, 0, Types.SECURE_MESSAGE_BIT); } + public void markAsPush(long id) { + updateTypeBitmask(id, 0, Types.PUSH_MESSAGE_BIT); + } + public void markAsDecryptFailed(long id) { updateTypeBitmask(id, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_FAILED_BIT); } @@ -267,6 +271,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns { type |= Types.ENCRYPTION_REMOTE_BIT; } + if (message.isPush()) type |= Types.PUSH_MESSAGE_BIT; + Recipients recipients; try { @@ -470,7 +476,6 @@ public class SmsDatabase extends Database implements MmsSmsColumns { public static final int STATUS_COMPLETE = 0; public static final int STATUS_PENDING = 0x20; public static final int STATUS_FAILED = 0x40; - public static final int STATUS_SENT_PUSH = 0x8000; } public Reader readerFor(Cursor cursor) { diff --git a/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java index 9c58344826..f600d2ae89 100644 --- a/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java @@ -45,10 +45,10 @@ public class MediaMmsMessageRecord extends MessageRecord { Recipient individualRecipient, int recipientDeviceId, long dateSent, long dateReceived, long threadId, Body body, ListenableFutureTask slideDeck, - int partCount, int deliveryStatus, long mailbox) + int partCount, long mailbox) { super(context, id, body, recipients, individualRecipient, recipientDeviceId, - dateSent, dateReceived, threadId, getGenericDeliveryStatus(deliveryStatus), mailbox); + dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox); this.context = context.getApplicationContext(); this.partCount = partCount; @@ -82,8 +82,4 @@ public class MediaMmsMessageRecord extends MessageRecord { return super.getDisplayBody(); } - - private static int getGenericDeliveryStatus(int status) { - return status == SmsDatabase.Status.STATUS_SENT_PUSH ? DELVIERY_STATUS_PUSH : DELIVERY_STATUS_NONE; - } } diff --git a/src/org/thoughtcrime/securesms/database/model/MessageRecord.java b/src/org/thoughtcrime/securesms/database/model/MessageRecord.java index 81c213b73a..41ac7a1a2b 100644 --- a/src/org/thoughtcrime/securesms/database/model/MessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/MessageRecord.java @@ -44,7 +44,6 @@ public abstract class MessageRecord extends DisplayRecord { public static final int DELIVERY_STATUS_RECEIVED = 1; public static final int DELIVERY_STATUS_PENDING = 2; public static final int DELIVERY_STATUS_FAILED = 3; - public static final int DELVIERY_STATUS_PUSH = 4; private final Recipient individualRecipient; private final int recipientDeviceId; @@ -108,8 +107,8 @@ public abstract class MessageRecord extends DisplayRecord { return getDeliveryStatus() == DELIVERY_STATUS_RECEIVED; } - public boolean isPushSent() { - return getDeliveryStatus() == DELVIERY_STATUS_PUSH; + public boolean isPush() { + return SmsDatabase.Types.isPushType(type); } public boolean isStaleKeyExchange() { diff --git a/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java index 7deff424c2..b598000f32 100644 --- a/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java @@ -97,8 +97,6 @@ public class SmsMessageRecord extends MessageRecord { private static int getGenericDeliveryStatus(int status) { if (status == SmsDatabase.Status.STATUS_NONE) { return MessageRecord.DELIVERY_STATUS_NONE; - } else if (status >= SmsDatabase.Status.STATUS_SENT_PUSH) { - return MessageRecord.DELVIERY_STATUS_PUSH; } else if (status >= SmsDatabase.Status.STATUS_FAILED) { return MessageRecord.DELIVERY_STATUS_FAILED; } else if (status >= SmsDatabase.Status.STATUS_PENDING) { diff --git a/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java b/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java index 1d01cdec2b..18a856cfe2 100644 --- a/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java +++ b/src/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java @@ -20,11 +20,13 @@ public class IncomingMediaMessage { private final PduHeaders headers; private final PduBody body; private final String groupId; + private final boolean push; public IncomingMediaMessage(RetrieveConf retreived) { this.headers = retreived.getPduHeaders(); this.body = retreived.getBody(); this.groupId = null; + this.push = false; } public IncomingMediaMessage(MasterSecret masterSecret, String localNumber, @@ -33,6 +35,7 @@ public class IncomingMediaMessage { { this.headers = new PduHeaders(); this.body = new PduBody(); + this.push = true; if (messageContent.hasGroup()) { this.groupId = GroupUtil.getEncodedId(messageContent.getGroup().getId().toByteArray()); @@ -84,6 +87,10 @@ public class IncomingMediaMessage { return groupId; } + public boolean isPushMessage() { + return push; + } + public boolean isGroupMessage() { return groupId != null || !Util.isEmpty(headers.getEncodedStringValues(PduHeaders.CC)) || diff --git a/src/org/thoughtcrime/securesms/service/MmsSender.java b/src/org/thoughtcrime/securesms/service/MmsSender.java index 3a756edae6..65dd948690 100644 --- a/src/org/thoughtcrime/securesms/service/MmsSender.java +++ b/src/org/thoughtcrime/securesms/service/MmsSender.java @@ -79,8 +79,7 @@ public class MmsSender { MmsSendResult result = transport.deliver(message, threadId); if (result.isUpgradedSecure()) database.markAsSecure(message.getDatabaseMessageId()); - if (result.isPush()) database.markDeliveryStatus(message.getDatabaseMessageId(), - Status.STATUS_SENT_PUSH); + if (result.isPush()) database.markAsPush(message.getDatabaseMessageId()); database.markAsSent(message.getDatabaseMessageId(), result.getMessageId(), result.getResponseStatus()); diff --git a/src/org/thoughtcrime/securesms/service/SmsSender.java b/src/org/thoughtcrime/securesms/service/SmsSender.java index 61275a7c0d..e0c2624157 100644 --- a/src/org/thoughtcrime/securesms/service/SmsSender.java +++ b/src/org/thoughtcrime/securesms/service/SmsSender.java @@ -121,7 +121,7 @@ public class SmsSender { database.markAsSent(messageId); if (upgraded) database.markAsSecure(messageId); - if (push) database.markStatus(messageId, SmsDatabase.Status.STATUS_SENT_PUSH); + if (push) database.markAsPush(messageId); SmsMessageRecord record = reader.getNext(); diff --git a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java index 86f87b9323..662e98c2e1 100644 --- a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java +++ b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java @@ -4,15 +4,12 @@ import android.os.Parcel; import android.os.Parcelable; import android.telephony.SmsMessage; -import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.util.GroupUtil; import org.whispersystems.textsecure.push.IncomingPushMessage; import org.whispersystems.textsecure.storage.RecipientDevice; import java.util.List; -import ws.com.google.android.mms.pdu.SendReq; - import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext; public class IncomingTextMessage implements Parcelable { @@ -38,6 +35,7 @@ public class IncomingTextMessage implements Parcelable { private final String pseudoSubject; private final long sentTimestampMillis; private final String groupId; + private final boolean push; public IncomingTextMessage(SmsMessage message) { this.message = message.getDisplayMessageBody(); @@ -49,6 +47,7 @@ public class IncomingTextMessage implements Parcelable { this.pseudoSubject = message.getPseudoSubject(); this.sentTimestampMillis = message.getTimestampMillis(); this.groupId = null; + this.push = false; } public IncomingTextMessage(IncomingPushMessage message, String encodedBody, GroupContext group) { @@ -60,6 +59,7 @@ public class IncomingTextMessage implements Parcelable { this.replyPathPresent = true; this.pseudoSubject = ""; this.sentTimestampMillis = message.getTimestampMillis(); + this.push = true; if (group != null && group.hasId()) { this.groupId = GroupUtil.getEncodedId(group.getId().toByteArray()); @@ -78,6 +78,7 @@ public class IncomingTextMessage implements Parcelable { this.pseudoSubject = in.readString(); this.sentTimestampMillis = in.readLong(); this.groupId = in.readString(); + this.push = (in.readInt() == 1); } public IncomingTextMessage(IncomingTextMessage base, String newBody) { @@ -90,6 +91,7 @@ public class IncomingTextMessage implements Parcelable { this.pseudoSubject = base.getPseudoSubject(); this.sentTimestampMillis = base.getSentTimestampMillis(); this.groupId = base.getGroupId(); + this.push = base.isPush(); } public IncomingTextMessage(List fragments) { @@ -108,30 +110,7 @@ public class IncomingTextMessage implements Parcelable { this.pseudoSubject = fragments.get(0).getPseudoSubject(); this.sentTimestampMillis = fragments.get(0).getSentTimestampMillis(); this.groupId = fragments.get(0).getGroupId(); - } - - public IncomingTextMessage(SendReq record) { - this.message = ""; - this.sender = record.getTo()[0].getString(); - this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID; - this.protocol = 31338; - this.serviceCenterAddress = "Outgoing"; - this.replyPathPresent = true; - this.pseudoSubject = ""; - this.sentTimestampMillis = System.currentTimeMillis(); - this.groupId = null; - } - - public IncomingTextMessage(SmsMessageRecord record) { - this.message = record.getBody().getBody(); - this.sender = record.getIndividualRecipient().getNumber(); - this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID; - this.protocol = 31338; - this.serviceCenterAddress = "Outgoing"; - this.replyPathPresent = true; - this.pseudoSubject = ""; - this.sentTimestampMillis = System.currentTimeMillis(); - this.groupId = null; + this.push = fragments.get(0).isPush(); } protected IncomingTextMessage(String sender, String groupId) @@ -145,6 +124,7 @@ public class IncomingTextMessage implements Parcelable { this.pseudoSubject = ""; this.sentTimestampMillis = System.currentTimeMillis(); this.groupId = groupId; + this.push = true; } public long getSentTimestampMillis() { @@ -203,6 +183,10 @@ public class IncomingTextMessage implements Parcelable { return false; } + public boolean isPush() { + return push; + } + public String getGroupId() { return groupId; } @@ -227,5 +211,6 @@ public class IncomingTextMessage implements Parcelable { out.writeString(pseudoSubject); out.writeLong(sentTimestampMillis); out.writeString(groupId); + out.writeInt(push ? 1 : 0); } }