|
|
|
@ -31,6 +31,7 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
import org.whispersystems.libaxolotl.InvalidMessageException;
|
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterCipher;
|
|
|
|
@ -74,6 +75,9 @@ import ws.com.google.android.mms.pdu.PduHeaders;
|
|
|
|
|
import ws.com.google.android.mms.pdu.PduPart;
|
|
|
|
|
import ws.com.google.android.mms.pdu.SendReq;
|
|
|
|
|
|
|
|
|
|
import static org.thoughtcrime.securesms.util.Util.canonicalizeNumber;
|
|
|
|
|
import static org.thoughtcrime.securesms.util.Util.canonicalizeNumberOrGroup;
|
|
|
|
|
|
|
|
|
|
// XXXX Clean up MMS efficiency:
|
|
|
|
|
// 1) We need to be careful about how much memory we're using for parts. SoftRefereences.
|
|
|
|
|
// 2) How many queries do we make? calling getMediaMessageForId() from within an existing query
|
|
|
|
@ -175,28 +179,30 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID}, DATE_SENT + " = ?", new String[] {String.valueOf(timestamp / 1000)}, null, null, null, null);
|
|
|
|
|
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, MESSAGE_BOX}, DATE_SENT + " = ?", new String[] {String.valueOf(timestamp / 1000)}, null, null, null, null);
|
|
|
|
|
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
List<String> addresses = addressDatabase.getAddressesForId(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
|
|
|
|
|
|
|
|
|
for (String storedAddress : addresses) {
|
|
|
|
|
try {
|
|
|
|
|
String ourAddress = org.thoughtcrime.securesms.util.Util.canonicalizeNumber(context, address);
|
|
|
|
|
String theirAddress = org.thoughtcrime.securesms.util.Util.canonicalizeNumber(context, storedAddress);
|
|
|
|
|
|
|
|
|
|
if (ourAddress.equals(theirAddress)) {
|
|
|
|
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
|
|
|
|
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
|
|
|
|
|
|
|
|
|
database.execSQL("UPDATE " + TABLE_NAME + " SET " +
|
|
|
|
|
RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?",
|
|
|
|
|
new String[] {String.valueOf(id)});
|
|
|
|
|
|
|
|
|
|
notifyConversationListeners(threadId);
|
|
|
|
|
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)))) {
|
|
|
|
|
List<String> addresses = addressDatabase.getAddressesForId(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
|
|
|
|
|
|
|
|
|
for (String storedAddress : addresses) {
|
|
|
|
|
try {
|
|
|
|
|
String ourAddress = canonicalizeNumber(context, address);
|
|
|
|
|
String theirAddress = canonicalizeNumberOrGroup(context, storedAddress);
|
|
|
|
|
|
|
|
|
|
if (ourAddress.equals(theirAddress) || GroupUtil.isEncodedGroup(theirAddress)) {
|
|
|
|
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
|
|
|
|
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
|
|
|
|
|
|
|
|
|
database.execSQL("UPDATE " + TABLE_NAME + " SET " +
|
|
|
|
|
RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?",
|
|
|
|
|
new String[] {String.valueOf(id)});
|
|
|
|
|
|
|
|
|
|
notifyConversationListeners(threadId);
|
|
|
|
|
}
|
|
|
|
|
} catch (InvalidNumberException e) {
|
|
|
|
|
Log.w("MmsDatabase", e);
|
|
|
|
|
}
|
|
|
|
|
} catch (InvalidNumberException e) {
|
|
|
|
|
Log.w("MmsDatabase", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|