mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-02 21:27:47 +00:00
Display both sent and received time in message details.
1) We record time sent in SMS database (date_sent). 2) We record time received in MMS database (date_received). 3) We union this information correctly in MmsSmsDatabase.
This commit is contained in:
parent
ead97953e8
commit
83f90ddd4e
@ -87,6 +87,7 @@
|
||||
<!-- ConversationFragment -->
|
||||
<string name="ConversationFragment_message_details">Message details</string>
|
||||
<string name="ConversationFragment_sender_s_transport_s_sent_received_s">Sender: %1$s\nTransport: %2$s\nSent/Received:%3$s</string>
|
||||
<string name="ConversationFragment_sender_s_transport_s_sent_s_received_s">Sender: %1$s\nTransport: %2$s\nSent: %3$s\nReceived:%4$s</string>
|
||||
<string name="ConversationFragment_confirm_message_delete">Confirm Message Delete</string>
|
||||
<string name="ConversationFragment_are_you_sure_you_want_to_permanently_delete_this_message">Are you sure that you want to permanently delete this message?</string>
|
||||
|
||||
|
@ -143,7 +143,8 @@ public class ConversationAdapter extends CursorAdapter {
|
||||
|
||||
private MediaMmsMessageRecord getMediaMmsMessageRecord(long messageId, Cursor cursor) {
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.ID));
|
||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.DATE));
|
||||
long dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_SENT));
|
||||
long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_RECEIVED));
|
||||
long box = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_BOX));
|
||||
Recipient recipient = getIndividualRecipientFor(null);
|
||||
GroupData groupData = null;
|
||||
@ -175,13 +176,15 @@ public class ConversationAdapter extends CursorAdapter {
|
||||
}
|
||||
|
||||
return new MediaMmsMessageRecord(context, id, recipients, recipient,
|
||||
date, threadId, slideDeck, box, groupData);
|
||||
dateSent, dateReceived, threadId,
|
||||
slideDeck, box, groupData);
|
||||
}
|
||||
|
||||
private NotificationMmsMessageRecord getNotificationMmsMessageRecord(long messageId, Cursor cursor) {
|
||||
Recipient recipient = getIndividualRecipientFor(null);
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.ID));
|
||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.DATE));
|
||||
long dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_SENT));
|
||||
long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_RECEIVED));
|
||||
|
||||
NotificationInd notification;
|
||||
|
||||
@ -192,7 +195,8 @@ public class ConversationAdapter extends CursorAdapter {
|
||||
notification = new NotificationInd(new PduHeaders());
|
||||
}
|
||||
|
||||
return new NotificationMmsMessageRecord(id, recipients, recipient, date, threadId,
|
||||
return new NotificationMmsMessageRecord(id, recipients, recipient,
|
||||
dateSent, dateReceived, threadId,
|
||||
notification.getContentLocation(),
|
||||
notification.getMessageSize(),
|
||||
notification.getExpiry(),
|
||||
@ -201,7 +205,8 @@ public class ConversationAdapter extends CursorAdapter {
|
||||
}
|
||||
|
||||
private SmsMessageRecord getSmsMessageRecord(long messageId, Cursor cursor) {
|
||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE));
|
||||
long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_RECEIVED));
|
||||
long dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_SENT));
|
||||
long type = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.TYPE));
|
||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
|
||||
String address = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
|
||||
@ -220,8 +225,8 @@ public class ConversationAdapter extends CursorAdapter {
|
||||
}
|
||||
|
||||
SmsMessageRecord messageRecord = new SmsMessageRecord(context, messageId, recipients,
|
||||
recipient, date, type, threadId,
|
||||
groupData);
|
||||
recipient, dateSent, dateReceived,
|
||||
type, threadId, groupData);
|
||||
|
||||
if (body == null) {
|
||||
body = "";
|
||||
|
@ -123,19 +123,30 @@ public class ConversationFragment extends SherlockListFragment
|
||||
}
|
||||
|
||||
private void handleDisplayDetails(MessageRecord message) {
|
||||
String sender = message.getRecipients().getPrimaryRecipient().getNumber();
|
||||
String transport = message.isMms() ? "mms" : "sms";
|
||||
long date = message.getDate();
|
||||
String sender = message.getRecipients().getPrimaryRecipient().getNumber();
|
||||
String transport = message.isMms() ? "mms" : "sms";
|
||||
long dateReceived = message.getDateReceived();
|
||||
long dateSent = message.getDateSent();
|
||||
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE MMM d, yyyy 'at' hh:mm:ss a zzz");
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.ConversationFragment_message_details);
|
||||
builder.setIcon(android.R.drawable.ic_dialog_info);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage(String.format(getSherlockActivity()
|
||||
.getString(R.string.ConversationFragment_sender_s_transport_s_sent_received_s),
|
||||
sender, transport.toUpperCase(),
|
||||
dateFormatter.format(new Date(date))));
|
||||
|
||||
if (dateReceived == dateSent || message.isOutgoing()) {
|
||||
builder.setMessage(String.format(getSherlockActivity()
|
||||
.getString(R.string.ConversationFragment_sender_s_transport_s_sent_received_s),
|
||||
sender, transport.toUpperCase(),
|
||||
dateFormatter.format(new Date(dateSent))));
|
||||
} else {
|
||||
builder.setMessage(String.format(getSherlockActivity()
|
||||
.getString(R.string.ConversationFragment_sender_s_transport_s_sent_s_received_s),
|
||||
sender, transport.toUpperCase(),
|
||||
dateFormatter.format(new Date(dateSent)),
|
||||
dateFormatter.format(new Date(dateReceived))));
|
||||
}
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.show();
|
||||
}
|
||||
|
@ -190,7 +190,9 @@ public class ConversationItem extends LinearLayout {
|
||||
if (messageRecord.isFailed()) dateText.setText(R.string.ConversationItem_error_sending_message);
|
||||
else if (messageRecord.isPending()) dateText.setText(R.string.ConversationItem_sending);
|
||||
else dateText.setText(DateUtils.getRelativeTimeSpanString(getContext(),
|
||||
messageRecord.getDate(),
|
||||
(messageRecord.isOutgoing() ?
|
||||
messageRecord.getDateSent() :
|
||||
messageRecord.getDateReceived()),
|
||||
false));
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,8 @@ public class DatabaseFactory {
|
||||
|
||||
private static final int INTRODUCED_IDENTITIES_VERSION = 2;
|
||||
private static final int INTRODUCED_INDEXES_VERSION = 3;
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
private static final int INTRODUCED_DATE_SENT_VERSION = 4;
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
|
||||
private static final String DATABASE_NAME = "messages.db";
|
||||
private static final Object lock = new Object();
|
||||
@ -171,6 +172,21 @@ public class DatabaseFactory {
|
||||
executeStatements(db, ThreadDatabase.CREATE_INDEXS);
|
||||
executeStatements(db, MmsAddressDatabase.CREATE_INDEXS);
|
||||
}
|
||||
|
||||
if (oldVersion < INTRODUCED_DATE_SENT_VERSION) {
|
||||
db.beginTransaction();
|
||||
db.execSQL("ALTER TABLE " + SmsDatabase.TABLE_NAME +
|
||||
" ADD COLUMN " + SmsDatabase.DATE_SENT + " INTEGER;");
|
||||
db.execSQL("UPDATE " + SmsDatabase.TABLE_NAME +
|
||||
" SET " + SmsDatabase.DATE_SENT + " = " + SmsDatabase.DATE_RECEIVED + ";");
|
||||
|
||||
db.execSQL("ALTER TABLE " + MmsDatabase.TABLE_NAME +
|
||||
" ADD COLUMN " + MmsDatabase.DATE_RECEIVED + " INTEGER;");
|
||||
db.execSQL("UPDATE " + MmsDatabase.TABLE_NAME +
|
||||
" SET " + MmsDatabase.DATE_RECEIVED + " = " + MmsDatabase.DATE_SENT + ";");
|
||||
db.setTransactionSuccessful();
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
private void executeStatements(SQLiteDatabase db, String[] statements) {
|
||||
|
@ -49,7 +49,8 @@ public class MmsDatabase extends Database {
|
||||
public static final String TABLE_NAME = "mms";
|
||||
public static final String ID = "_id";
|
||||
private static final String THREAD_ID = "thread_id";
|
||||
public static final String DATE = "date";
|
||||
public static final String DATE_SENT = "date";
|
||||
public static final String DATE_RECEIVED = "date_received";
|
||||
public static final String MESSAGE_BOX = "msg_box";
|
||||
private static final String READ = "read";
|
||||
private static final String MESSAGE_ID = "m_id";
|
||||
@ -78,7 +79,7 @@ public class MmsDatabase extends Database {
|
||||
private static final String DELIVERY_REPORT = "d_rpt";
|
||||
|
||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
|
||||
THREAD_ID + " INTEGER, " + DATE + " INTEGER, " + MESSAGE_BOX + " INTEGER, " +
|
||||
THREAD_ID + " INTEGER, " + DATE_SENT + " INTEGER, " + DATE_RECEIVED + "INTEGER, " + MESSAGE_BOX + " INTEGER, " +
|
||||
READ + " INTEGER DEFAULT 0, " + MESSAGE_ID + " TEXT, " + SUBJECT + " TEXT, " +
|
||||
SUBJECT_CHARSET + " INTEGER, " + CONTENT_TYPE + " TEXT, " + CONTENT_LOCATION + " TEXT, " +
|
||||
EXPIRY + " INTEGER, " + MESSAGE_CLASS + " TEXT, " + MESSAGE_TYPE + " INTEGER, " +
|
||||
@ -297,6 +298,10 @@ public class MmsDatabase extends Database {
|
||||
contentValues.put(THREAD_ID, threadId);
|
||||
contentValues.put(CONTENT_LOCATION, contentLocation);
|
||||
contentValues.put(STATUS, Types.DOWNLOAD_INITIALIZED);
|
||||
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
||||
|
||||
if (!contentValues.containsKey(DATE_SENT))
|
||||
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
||||
|
||||
long messageId = insertMediaMessage(retrieved, contentValues);
|
||||
return messageId;
|
||||
@ -327,8 +332,10 @@ public class MmsDatabase extends Database {
|
||||
contentValues.put(MESSAGE_BOX, Types.MESSAGE_BOX_INBOX);
|
||||
contentValues.put(THREAD_ID, threadId);
|
||||
contentValues.put(STATUS, Types.DOWNLOAD_INITIALIZED);
|
||||
if (!contentValues.containsKey(DATE))
|
||||
contentValues.put(DATE, System.currentTimeMillis() / 1000);
|
||||
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
||||
|
||||
if (!contentValues.containsKey(DATE_SENT))
|
||||
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
||||
|
||||
long messageId = db.insert(TABLE_NAME, null, contentValues);
|
||||
addressDatabase.insertAddressesForId(messageId, headers);
|
||||
@ -353,6 +360,7 @@ public class MmsDatabase extends Database {
|
||||
|
||||
contentValues.put(THREAD_ID, threadId);
|
||||
contentValues.put(READ, 1);
|
||||
contentValues.put(DATE_RECEIVED, contentValues.getAsLong(DATE_SENT));
|
||||
|
||||
long messageId = insertMediaMessage(sendRequest, contentValues);
|
||||
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
||||
@ -480,7 +488,7 @@ public class MmsDatabase extends Database {
|
||||
phb.addOctet(REPORT_ALLOWED, PduHeaders.REPORT_ALLOWED);
|
||||
phb.addOctet(RETRIEVE_STATUS, PduHeaders.RETRIEVE_STATUS);
|
||||
phb.addOctet(STATUS, PduHeaders.STATUS);
|
||||
phb.addLong(DATE, PduHeaders.DATE);
|
||||
phb.addLong(DATE_SENT, PduHeaders.DATE);
|
||||
phb.addLong(DELIVERY_TIME, PduHeaders.DELIVERY_TIME);
|
||||
phb.addLong(EXPIRY, PduHeaders.EXPIRY);
|
||||
phb.addLong(MESSAGE_SIZE, PduHeaders.MESSAGE_SIZE);
|
||||
@ -510,7 +518,7 @@ public class MmsDatabase extends Database {
|
||||
cvb.add(REPORT_ALLOWED, headers.getOctet(PduHeaders.REPORT_ALLOWED));
|
||||
cvb.add(RETRIEVE_STATUS, headers.getOctet(PduHeaders.RETRIEVE_STATUS));
|
||||
cvb.add(STATUS, headers.getOctet(PduHeaders.STATUS));
|
||||
cvb.add(DATE, headers.getLongInteger(PduHeaders.DATE));
|
||||
cvb.add(DATE_SENT, headers.getLongInteger(PduHeaders.DATE));
|
||||
cvb.add(DELIVERY_TIME, headers.getLongInteger(PduHeaders.DELIVERY_TIME));
|
||||
cvb.add(EXPIRY, headers.getLongInteger(PduHeaders.EXPIRY));
|
||||
cvb.add(MESSAGE_SIZE, headers.getLongInteger(PduHeaders.MESSAGE_SIZE));
|
||||
|
@ -35,6 +35,9 @@ public class MmsSmsDatabase extends Database {
|
||||
public static final String MMS_GROUP_SENT_COUNT = "mms_group_sent_count";
|
||||
public static final String MMS_GROUP_SEND_FAILED_COUNT = "mms_group_sent_failed_count";
|
||||
|
||||
public static final String DATE_SENT = "date_sent";
|
||||
public static final String DATE_RECEIVED = "date_received";
|
||||
|
||||
public MmsSmsDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||
super(context, databaseHelper);
|
||||
}
|
||||
@ -75,10 +78,10 @@ public class MmsSmsDatabase extends Database {
|
||||
"WHEN " + SmsDatabase.Types.FAILED_TYPE + " THEN 1 " +
|
||||
"ELSE 0 END)";
|
||||
|
||||
String[] projection = {"_id", "body", "type", "address", "subject", "normalized_date AS date", "m_type", "msg_box", "transport_type", "COUNT(_id) AS group_size", mmsGroupSentCount + " AS mms_group_sent_count", mmsGroupSentFailedCount + " AS mms_group_sent_failed_count", smsGroupSentCount + " AS sms_group_sent_count", smsGroupSentFailedCount + " AS sms_group_sent_failed_count", smsCaseSecurity + " AS sms_collate", mmsCaseSecurity + " AS mms_collate"};
|
||||
String order = "normalized_date ASC";
|
||||
String[] projection = {"_id", "body", "type", "address", "subject", "normalized_date_sent AS date_sent", "normalized_date_received AS date_received", "m_type", "msg_box", "transport_type", "COUNT(_id) AS group_size", mmsGroupSentCount + " AS mms_group_sent_count", mmsGroupSentFailedCount + " AS mms_group_sent_failed_count", smsGroupSentCount + " AS sms_group_sent_count", smsGroupSentFailedCount + " AS sms_group_sent_failed_count", smsCaseSecurity + " AS sms_collate", mmsCaseSecurity + " AS mms_collate"};
|
||||
String order = "normalized_date_received ASC";
|
||||
String selection = "thread_id = " + threadId;
|
||||
String groupBy = "normalized_date / 1000, sms_collate, mms_collate";
|
||||
String groupBy = "normalized_date_sent / 1000, sms_collate, mms_collate";
|
||||
|
||||
Cursor cursor = queryTables(projection, selection, order, groupBy, null);
|
||||
setNotifyConverationListeners(cursor, threadId);
|
||||
@ -87,8 +90,11 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
|
||||
public Cursor getConversation(long threadId) {
|
||||
String[] projection = {"_id", "body", "type", "address", "subject", "normalized_date AS date", "m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date ASC";
|
||||
String[] projection = {"_id", "body", "type", "address", "subject",
|
||||
"normalized_date_sent AS date_sent",
|
||||
"normalized_date_received AS date_received",
|
||||
"m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date_received ASC";
|
||||
String selection = "thread_id = " + threadId;
|
||||
|
||||
Cursor cursor = queryTables(projection, selection, order, null, null);
|
||||
@ -98,8 +104,11 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
|
||||
public Cursor getConversationSnippet(long threadId) {
|
||||
String[] projection = {"_id", "body", "type", "address", "subject", "normalized_date AS date", "m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date DESC";
|
||||
String[] projection = {"_id", "body", "type", "address", "subject",
|
||||
"normalized_date_sent AS date_sent",
|
||||
"normalized_date_received AS date_received",
|
||||
"m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date_received DESC";
|
||||
String selection = "thread_id = " + threadId;
|
||||
|
||||
Cursor cursor = queryTables(projection, selection, order, null, "1");
|
||||
@ -107,8 +116,11 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
|
||||
public Cursor getUnread() {
|
||||
String[] projection = {"_id", "body", "read", "type", "address", "subject", "thread_id", "normalized_date AS date", "m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date ASC";
|
||||
String[] projection = {"_id", "body", "read", "type", "address", "subject", "thread_id",
|
||||
"normalized_date_sent AS date_sent",
|
||||
"normalized_date_received AS date_received",
|
||||
"m_type", "msg_box", "transport_type"};
|
||||
String order = "normalized_date_received ASC";
|
||||
String selection = "read = 0";
|
||||
|
||||
Cursor cursor = queryTables(projection, selection, order, null, null);
|
||||
@ -123,8 +135,8 @@ public class MmsSmsDatabase extends Database {
|
||||
}
|
||||
|
||||
private Cursor queryTables(String[] projection, String selection, String order, String groupBy, String limit) {
|
||||
String[] mmsProjection = {"date * 1000 AS normalized_date", "_id", "body", "read", "thread_id", "type", "address", "subject", "date", "m_type", "msg_box", "transport_type"};
|
||||
String[] smsProjection = {"date * 1 AS normalized_date", "_id", "body", "read", "thread_id", "type", "address", "subject", "date", "m_type", "msg_box", "transport_type"};
|
||||
String[] mmsProjection = {"date * 1000 AS normalized_date_sent", "date_received * 1000 AS normalized_date_received", "_id", "body", "read", "thread_id", "type", "address", "subject", "date", "m_type", "msg_box", "transport_type"};
|
||||
String[] smsProjection = {"date_sent * 1 AS normalized_date_sent", "date * 1 AS normalized_date_received", "_id", "body", "read", "thread_id", "type", "address", "subject", "date", "m_type", "msg_box", "transport_type"};
|
||||
|
||||
SQLiteQueryBuilder mmsQueryBuilder = new SQLiteQueryBuilder();
|
||||
SQLiteQueryBuilder smsQueryBuilder = new SQLiteQueryBuilder();
|
||||
@ -140,6 +152,7 @@ public class MmsSmsDatabase extends Database {
|
||||
mmsColumnsPresent.add("m_type");
|
||||
mmsColumnsPresent.add("msg_box");
|
||||
mmsColumnsPresent.add("date");
|
||||
mmsColumnsPresent.add("date_received");
|
||||
mmsColumnsPresent.add("read");
|
||||
mmsColumnsPresent.add("thread_id");
|
||||
|
||||
@ -149,12 +162,13 @@ public class MmsSmsDatabase extends Database {
|
||||
smsColumnsPresent.add("type");
|
||||
smsColumnsPresent.add("address");
|
||||
smsColumnsPresent.add("subject");
|
||||
smsColumnsPresent.add("date_sent");
|
||||
smsColumnsPresent.add("date");
|
||||
smsColumnsPresent.add("read");
|
||||
smsColumnsPresent.add("thread_id");
|
||||
|
||||
String mmsSubQuery = mmsQueryBuilder.buildUnionSubQuery("transport_type", mmsProjection, mmsColumnsPresent, 0, "mms", selection, null, null, null);
|
||||
String smsSubQuery = smsQueryBuilder.buildUnionSubQuery("transport_type", smsProjection, smsColumnsPresent, 0, "sms", selection, null, null, null);
|
||||
String mmsSubQuery = mmsQueryBuilder.buildUnionSubQuery("transport_type", mmsProjection, mmsColumnsPresent, 2, "mms", selection, null, null, null);
|
||||
String smsSubQuery = smsQueryBuilder.buildUnionSubQuery("transport_type", smsProjection, smsColumnsPresent, 2, "sms", selection, null, null, null);
|
||||
|
||||
SQLiteQueryBuilder unionQueryBuilder = new SQLiteQueryBuilder();
|
||||
String unionQuery = unionQueryBuilder.buildUnionQuery(new String[] {smsSubQuery, mmsSubQuery}, order, null);
|
||||
|
@ -45,7 +45,8 @@ public class SmsDatabase extends Database {
|
||||
public static final String THREAD_ID = "thread_id";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String PERSON = "person";
|
||||
public static final String DATE = "date";
|
||||
public static final String DATE_RECEIVED = "date";
|
||||
public static final String DATE_SENT = "date_sent";
|
||||
public static final String PROTOCOL = "protocol";
|
||||
public static final String READ = "read";
|
||||
public static final String STATUS = "status";
|
||||
@ -56,10 +57,10 @@ public class SmsDatabase extends Database {
|
||||
public static final String SERVICE_CENTER = "service_center";
|
||||
|
||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " integer PRIMARY KEY, " +
|
||||
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + PERSON + " INTEGER, " + DATE + " INTEGER, " +
|
||||
PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " + STATUS + " INTEGER DEFAULT -1," +
|
||||
TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " + SUBJECT + " TEXT, " + BODY + " TEXT, " +
|
||||
SERVICE_CENTER + " TEXT);";
|
||||
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + PERSON + " INTEGER, " + DATE_RECEIVED + " INTEGER, " +
|
||||
DATE_SENT + " INTEGER, " + PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " +
|
||||
STATUS + " INTEGER DEFAULT -1," + TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " +
|
||||
SUBJECT + " TEXT, " + BODY + " TEXT, " + SERVICE_CENTER + " TEXT);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
|
||||
@ -82,7 +83,7 @@ public class SmsDatabase extends Database {
|
||||
notifyConversationListeners(getThreadIdForMessage(id));
|
||||
}
|
||||
|
||||
private long insertMessageReceived(SmsMessage message, String body, long type) {
|
||||
private long insertMessageReceived(SmsMessage message, String body, long type, long timeSent) {
|
||||
List<Recipient> recipientList = new ArrayList<Recipient>(1);
|
||||
recipientList.add(new Recipient(null, message.getDisplayOriginatingAddress(), null, null));
|
||||
Recipients recipients = new Recipients(recipientList);
|
||||
@ -91,7 +92,8 @@ public class SmsDatabase extends Database {
|
||||
|
||||
ContentValues values = new ContentValues(6);
|
||||
values.put(ADDRESS, message.getDisplayOriginatingAddress());
|
||||
values.put(DATE, Long.valueOf(System.currentTimeMillis()));
|
||||
values.put(DATE_RECEIVED, Long.valueOf(System.currentTimeMillis()));
|
||||
values.put(DATE_SENT, timeSent);
|
||||
values.put(PROTOCOL, message.getProtocolIdentifier());
|
||||
values.put(READ, Integer.valueOf(0));
|
||||
|
||||
@ -198,11 +200,12 @@ public class SmsDatabase extends Database {
|
||||
}
|
||||
|
||||
public long insertSecureMessageReceived(SmsMessage message, String body) {
|
||||
return insertMessageReceived(message, body, Types.DECRYPT_IN_PROGRESS_TYPE);
|
||||
return insertMessageReceived(message, body, Types.DECRYPT_IN_PROGRESS_TYPE,
|
||||
message.getTimestampMillis());
|
||||
}
|
||||
|
||||
public long insertMessageReceived(SmsMessage message, String body) {
|
||||
return insertMessageReceived(message, body, Types.INBOX_TYPE);
|
||||
return insertMessageReceived(message, body, Types.INBOX_TYPE, message.getTimestampMillis());
|
||||
}
|
||||
|
||||
public long insertMessageSent(String address, long threadId, String body, long date, long type) {
|
||||
@ -211,7 +214,8 @@ public class SmsDatabase extends Database {
|
||||
contentValues.put(ADDRESS, address);
|
||||
contentValues.put(THREAD_ID, threadId);
|
||||
contentValues.put(BODY, body);
|
||||
contentValues.put(DATE, date);
|
||||
contentValues.put(DATE_RECEIVED, date);
|
||||
contentValues.put(DATE_SENT, date);
|
||||
contentValues.put(READ, 1);
|
||||
contentValues.put(TYPE, type);
|
||||
|
||||
@ -297,8 +301,20 @@ public class SmsDatabase extends Database {
|
||||
}
|
||||
|
||||
/*package*/ SQLiteStatement createInsertStatement(SQLiteDatabase database) {
|
||||
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " + PERSON + ", " + DATE + ", " + PROTOCOL + ", " + READ + ", " + STATUS + ", " + TYPE + ", " + REPLY_PATH_PRESENT + ", " + SUBJECT + ", " + BODY + ", " + SERVICE_CENTER + ", THREAD_ID) " +
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " +
|
||||
PERSON + ", " +
|
||||
DATE_SENT + ", " +
|
||||
DATE_RECEIVED + ", " +
|
||||
PROTOCOL + ", " +
|
||||
READ + ", " +
|
||||
STATUS + ", " +
|
||||
TYPE + ", " +
|
||||
REPLY_PATH_PRESENT + ", " +
|
||||
SUBJECT + ", " +
|
||||
BODY + ", " +
|
||||
SERVICE_CENTER +
|
||||
", THREAD_ID) " +
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
}
|
||||
|
||||
public static class Types {
|
||||
|
@ -77,17 +77,18 @@ public class SmsMigrator {
|
||||
{
|
||||
addStringToStatement(statement, cursor, 1, SmsDatabase.ADDRESS);
|
||||
addIntToStatement(statement, cursor, 2, SmsDatabase.PERSON);
|
||||
addIntToStatement(statement, cursor, 3, SmsDatabase.DATE);
|
||||
addIntToStatement(statement, cursor, 4, SmsDatabase.PROTOCOL);
|
||||
addIntToStatement(statement, cursor, 5, SmsDatabase.READ);
|
||||
addIntToStatement(statement, cursor, 6, SmsDatabase.STATUS);
|
||||
addIntToStatement(statement, cursor, 7, SmsDatabase.TYPE);
|
||||
addIntToStatement(statement, cursor, 8, SmsDatabase.REPLY_PATH_PRESENT);
|
||||
addStringToStatement(statement, cursor, 9, SmsDatabase.SUBJECT);
|
||||
addEncryptedStringToStatement(context, statement, cursor, masterSecret, 10, SmsDatabase.BODY);
|
||||
addStringToStatement(statement, cursor, 11, SmsDatabase.SERVICE_CENTER);
|
||||
addIntToStatement(statement, cursor, 3, SmsDatabase.DATE_SENT);
|
||||
addIntToStatement(statement, cursor, 4, SmsDatabase.DATE_RECEIVED);
|
||||
addIntToStatement(statement, cursor, 5, SmsDatabase.PROTOCOL);
|
||||
addIntToStatement(statement, cursor, 6, SmsDatabase.READ);
|
||||
addIntToStatement(statement, cursor, 7, SmsDatabase.STATUS);
|
||||
addIntToStatement(statement, cursor, 8, SmsDatabase.TYPE);
|
||||
addIntToStatement(statement, cursor, 9, SmsDatabase.REPLY_PATH_PRESENT);
|
||||
addStringToStatement(statement, cursor, 10, SmsDatabase.SUBJECT);
|
||||
addEncryptedStringToStatement(context, statement, cursor, masterSecret, 11, SmsDatabase.BODY);
|
||||
addStringToStatement(statement, cursor, 12, SmsDatabase.SERVICE_CENTER);
|
||||
|
||||
statement.bindLong(12, threadId);
|
||||
statement.bindLong(13, threadId);
|
||||
}
|
||||
|
||||
private static String getTheirCanonicalAddress(Context context, String theirRecipientId) {
|
||||
|
@ -279,7 +279,7 @@ public class ThreadDatabase extends Database {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
updateThread(threadId, count,
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)),
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE)));
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsDatabase.DATE_RECEIVED)));
|
||||
} else {
|
||||
deleteThread(threadId);
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
public abstract class DisplayRecord {
|
||||
|
||||
private final Recipients recipients;
|
||||
private final long date;
|
||||
private final long dateSent;
|
||||
private final long dateReceived;
|
||||
private final long threadId;
|
||||
|
||||
private String body;
|
||||
@ -39,11 +40,12 @@ public abstract class DisplayRecord {
|
||||
protected boolean processedKeyExchange;
|
||||
protected boolean staleKeyExchange;
|
||||
|
||||
public DisplayRecord(Recipients recipients, long date, long threadId) {
|
||||
this.threadId = threadId;
|
||||
this.recipients = recipients;
|
||||
this.date = date;
|
||||
this.emphasis = false;
|
||||
public DisplayRecord(Recipients recipients, long dateSent, long dateReceived, long threadId) {
|
||||
this.threadId = threadId;
|
||||
this.recipients = recipients;
|
||||
this.dateSent = dateSent;
|
||||
this.dateReceived = dateReceived;
|
||||
this.emphasis = false;
|
||||
}
|
||||
|
||||
public void setEmphasis(boolean emphasis) {
|
||||
@ -81,8 +83,12 @@ public abstract class DisplayRecord {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return date;
|
||||
public long getDateSent() {
|
||||
return dateSent;
|
||||
}
|
||||
|
||||
public long getDateReceived() {
|
||||
return dateReceived;
|
||||
}
|
||||
|
||||
public long getThreadId() {
|
||||
|
@ -42,10 +42,11 @@ public class MediaMmsMessageRecord extends MessageRecord {
|
||||
private final long mailbox;
|
||||
|
||||
public MediaMmsMessageRecord(Context context, long id, Recipients recipients,
|
||||
Recipient individualRecipient, long date, long threadId,
|
||||
SlideDeck slideDeck, long mailbox, GroupData groupData)
|
||||
Recipient individualRecipient, long dateSent, long dateReceived,
|
||||
long threadId, SlideDeck slideDeck, long mailbox,
|
||||
GroupData groupData)
|
||||
{
|
||||
super(id, recipients, individualRecipient, date, threadId, groupData);
|
||||
super(id, recipients, individualRecipient, dateSent, dateReceived, threadId, groupData);
|
||||
this.slideDeck = slideDeck;
|
||||
this.mailbox = mailbox;
|
||||
|
||||
|
@ -35,10 +35,10 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
|
||||
public MessageRecord(long id, Recipients recipients,
|
||||
Recipient individualRecipient,
|
||||
long date, long threadId,
|
||||
GroupData groupData)
|
||||
long dateSent, long dateReceived,
|
||||
long threadId, GroupData groupData)
|
||||
{
|
||||
super(recipients, date, threadId);
|
||||
super(recipients, dateSent, dateReceived, threadId);
|
||||
this.id = id;
|
||||
this.individualRecipient = individualRecipient;
|
||||
this.groupData = groupData;
|
||||
|
@ -37,11 +37,11 @@ public class NotificationMmsMessageRecord extends MessageRecord {
|
||||
private final byte[] transactionId;
|
||||
|
||||
public NotificationMmsMessageRecord(long id, Recipients recipients, Recipient individualRecipient,
|
||||
long date, long threadId, byte[] contentLocation,
|
||||
long messageSize, long expiry,
|
||||
long dateSent, long dateReceived, long threadId,
|
||||
byte[] contentLocation, long messageSize, long expiry,
|
||||
int status, byte[] transactionId)
|
||||
{
|
||||
super(id, recipients, individualRecipient, date, threadId, null);
|
||||
super(id, recipients, individualRecipient, dateSent, dateReceived, threadId, null);
|
||||
this.contentLocation = contentLocation;
|
||||
this.messageSize = messageSize;
|
||||
this.expiry = expiry;
|
||||
@ -60,7 +60,6 @@ public class NotificationMmsMessageRecord extends MessageRecord {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getContentLocation() {
|
||||
return contentLocation;
|
||||
}
|
||||
|
@ -36,16 +36,19 @@ public class SmsMessageRecord extends MessageRecord {
|
||||
|
||||
private final Context context;
|
||||
private final long type;
|
||||
private final long dateSent;
|
||||
|
||||
public SmsMessageRecord(Context context, long id,
|
||||
Recipients recipients,
|
||||
Recipient individualRecipient,
|
||||
long date, long type, long threadId,
|
||||
long dateSent, long dateReceived,
|
||||
long type, long threadId,
|
||||
GroupData groupData)
|
||||
{
|
||||
super(id, recipients, individualRecipient, date, threadId, groupData);
|
||||
this.context = context.getApplicationContext();
|
||||
this.type = type;
|
||||
super(id, recipients, individualRecipient, dateSent, dateReceived, threadId, groupData);
|
||||
this.context = context.getApplicationContext();
|
||||
this.type = type;
|
||||
this.dateSent = dateSent;
|
||||
}
|
||||
|
||||
public long getType() {
|
||||
|
@ -38,7 +38,7 @@ public class ThreadRecord extends DisplayRecord {
|
||||
long date, long count,
|
||||
boolean read, long threadId)
|
||||
{
|
||||
super(recipients, date, threadId);
|
||||
super(recipients, date, date, threadId);
|
||||
this.context = context.getApplicationContext();
|
||||
this.count = count;
|
||||
this.read = read;
|
||||
@ -68,4 +68,8 @@ public class ThreadRecord extends DisplayRecord {
|
||||
return read;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return getDateReceived();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user