|
|
|
@ -163,53 +163,6 @@ public class MmsSmsDatabase extends Database {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public @Nullable MessageRecord getSentMessageFor(long timestamp, String serializedAuthor) {
|
|
|
|
|
// Early exit if the author is not us
|
|
|
|
|
boolean isOwnNumber = Util.isOwnNumber(context, serializedAuthor);
|
|
|
|
|
if (!isOwnNumber) {
|
|
|
|
|
Log.i(TAG, "Asked to find sent messages but provided author is not us - returning null.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
|
|
|
|
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
|
|
|
|
|
|
|
|
|
MessageRecord messageRecord;
|
|
|
|
|
while ((messageRecord = reader.getNext()) != null) {
|
|
|
|
|
if (messageRecord.isOutgoing())
|
|
|
|
|
{
|
|
|
|
|
return messageRecord;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "Could not find any message sent from us at provided timestamp - returning null.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageRecord getLastSentMessageRecordFromSender(long threadId, String serializedAuthor) {
|
|
|
|
|
// Early exit if the author is not us
|
|
|
|
|
boolean isOwnNumber = Util.isOwnNumber(context, serializedAuthor);
|
|
|
|
|
if (!isOwnNumber) {
|
|
|
|
|
Log.i(TAG, "Asked to find last sent message but provided author is not us - returning null.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " DESC";
|
|
|
|
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
|
|
|
|
|
|
|
|
|
// Try everything with resources so that they auto-close on end of scope
|
|
|
|
|
try (Cursor cursor = queryTables(PROJECTION, selection, order, null)) {
|
|
|
|
|
try (MmsSmsDatabase.Reader reader = readerFor(cursor)) {
|
|
|
|
|
MessageRecord messageRecord;
|
|
|
|
|
while ((messageRecord = reader.getNext()) != null) {
|
|
|
|
|
if (messageRecord.isOutgoing()) { return messageRecord; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "Could not find last sent message from us in given thread - returning null.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public @Nullable MessageRecord getMessageFor(long timestamp, Address author) {
|
|
|
|
|
return getMessageFor(timestamp, author.serialize());
|
|
|
|
|
}
|
|
|
|
|