mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-14 01:17:36 +00:00
Make delivery receipts work correctly for groups.
This commit is contained in:
@@ -31,6 +31,7 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
|||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||||
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||||
import org.whispersystems.textsecure.crypto.MasterCipher;
|
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.PduPart;
|
||||||
import ws.com.google.android.mms.pdu.SendReq;
|
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:
|
// XXXX Clean up MMS efficiency:
|
||||||
// 1) We need to be careful about how much memory we're using for parts. SoftRefereences.
|
// 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
|
// 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;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
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()) {
|
while (cursor.moveToNext()) {
|
||||||
List<String> addresses = addressDatabase.getAddressesForId(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)))) {
|
||||||
|
List<String> addresses = addressDatabase.getAddressesForId(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
|
||||||
|
|
||||||
for (String storedAddress : addresses) {
|
for (String storedAddress : addresses) {
|
||||||
try {
|
try {
|
||||||
String ourAddress = org.thoughtcrime.securesms.util.Util.canonicalizeNumber(context, address);
|
String ourAddress = canonicalizeNumber(context, address);
|
||||||
String theirAddress = org.thoughtcrime.securesms.util.Util.canonicalizeNumber(context, storedAddress);
|
String theirAddress = canonicalizeNumberOrGroup(context, storedAddress);
|
||||||
|
|
||||||
if (ourAddress.equals(theirAddress)) {
|
if (ourAddress.equals(theirAddress) || GroupUtil.isEncodedGroup(theirAddress)) {
|
||||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
|
||||||
|
|
||||||
database.execSQL("UPDATE " + TABLE_NAME + " SET " +
|
database.execSQL("UPDATE " + TABLE_NAME + " SET " +
|
||||||
RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?",
|
RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " + ID + " = ?",
|
||||||
new String[] {String.valueOf(id)});
|
new String[] {String.valueOf(id)});
|
||||||
|
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
|
}
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
Log.w("MmsDatabase", e);
|
||||||
}
|
}
|
||||||
} catch (InvalidNumberException e) {
|
|
||||||
Log.w("MmsDatabase", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,9 +36,7 @@ import org.thoughtcrime.securesms.sms.IncomingGroupMessage;
|
|||||||
import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
|
import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
|
||||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
||||||
import org.thoughtcrime.securesms.util.Trimmer;
|
import org.thoughtcrime.securesms.util.Trimmer;
|
||||||
import org.whispersystems.textsecure.util.Base64;
|
|
||||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||||
import org.whispersystems.textsecure.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
@@ -252,25 +250,27 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, ADDRESS},
|
cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, ADDRESS, TYPE},
|
||||||
DATE_SENT + " = ?", new String[] {String.valueOf(timestamp)},
|
DATE_SENT + " = ?", new String[] {String.valueOf(timestamp)},
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
try {
|
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(TYPE)))) {
|
||||||
String theirAddress = canonicalizeNumber(context, address);
|
try {
|
||||||
String ourAddress = canonicalizeNumber(context, cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS)));
|
String theirAddress = canonicalizeNumber(context, address);
|
||||||
|
String ourAddress = canonicalizeNumber(context, cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS)));
|
||||||
|
|
||||||
if (ourAddress.equals(theirAddress)) {
|
if (ourAddress.equals(theirAddress)) {
|
||||||
database.execSQL("UPDATE " + TABLE_NAME +
|
database.execSQL("UPDATE " + TABLE_NAME +
|
||||||
" SET " + RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " +
|
" SET " + RECEIPT_COUNT + " = " + RECEIPT_COUNT + " + 1 WHERE " +
|
||||||
ID + " = ?",
|
ID + " = ?",
|
||||||
new String[] {String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ID)))});
|
new String[] {String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ID)))});
|
||||||
|
|
||||||
notifyConversationListeners(cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID)));
|
notifyConversationListeners(cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID)));
|
||||||
|
}
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
Log.w("SmsDatabase", e);
|
||||||
}
|
}
|
||||||
} catch (InvalidNumberException e) {
|
|
||||||
Log.w("SmsDatabase", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@@ -134,6 +134,13 @@ public class Util {
|
|||||||
return PhoneNumberFormatter.formatNumber(number, localNumber);
|
return PhoneNumberFormatter.formatNumber(number, localNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String canonicalizeNumberOrGroup(Context context, String number)
|
||||||
|
throws InvalidNumberException
|
||||||
|
{
|
||||||
|
if (GroupUtil.isEncodedGroup(number)) return number;
|
||||||
|
else return canonicalizeNumber(context, number);
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] readFully(InputStream in) throws IOException {
|
public static byte[] readFully(InputStream in) throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
byte[] buffer = new byte[4069];
|
byte[] buffer = new byte[4069];
|
||||||
|
Reference in New Issue
Block a user