Be more rigorous about discerning media message thread.

Fixes #4312
// FREEBIE
pull/1/head
Moxie Marlinspike 9 years ago
parent 79313c8093
commit 4271732b10

@ -59,6 +59,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.GroupUtil;
import org.thoughtcrime.securesms.util.JsonUtils; import org.thoughtcrime.securesms.util.JsonUtils;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.jobqueue.JobManager; import org.whispersystems.jobqueue.JobManager;
@ -252,34 +253,36 @@ public class MmsDatabase extends MessagingDatabase {
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients); return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients);
} }
Set<String> group = new HashSet<>(); String localNumber;
Set<String> group = new HashSet<>();
if (retrieved.getAddresses().getFrom() == null) { if (retrieved.getAddresses().getFrom() == null) {
throw new MmsException("FROM value in PduHeaders did not exist."); throw new MmsException("FROM value in PduHeaders did not exist.");
} }
group.add(retrieved.getAddresses().getFrom());
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); group.add(retrieved.getAddresses().getFrom());
String localNumber = telephonyManager.getLine1Number();
if (localNumber == null) { if (TextSecurePreferences.isPushRegistered(context)) {
localNumber = TextSecurePreferences.getLocalNumber(context); localNumber = TextSecurePreferences.getLocalNumber(context);
} } else {
localNumber = ServiceUtil.getTelephonyManager(context).getLine1Number();
}
for (String cc : retrieved.getAddresses().getCc()) { for (String cc : retrieved.getAddresses().getCc()) {
PhoneNumberUtil.MatchType match; PhoneNumberUtil.MatchType match;
if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH;
else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, cc); else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, cc);
if (match == PhoneNumberUtil.MatchType.NO_MATCH || if (match == PhoneNumberUtil.MatchType.NO_MATCH ||
match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) match == PhoneNumberUtil.MatchType.NOT_A_NUMBER)
{ {
group.add(cc); group.add(cc);
}
} }
}
if (retrieved.getAddresses().getTo().size() > 1) {
for (String to : retrieved.getAddresses().getTo()) { for (String to : retrieved.getAddresses().getTo()) {
PhoneNumberUtil.MatchType match; PhoneNumberUtil.MatchType match;
@ -291,11 +294,14 @@ public class MmsDatabase extends MessagingDatabase {
{ {
group.add(to); group.add(to);
} }
} }
}
String recipientsList = Util.join(group, ","); String recipientsList = Util.join(group, ",");
Recipients recipients = RecipientFactory.getRecipientsFromString(context, recipientsList, false); Recipients recipients = RecipientFactory.getRecipientsFromString(context, recipientsList, false);
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
} }
private long getThreadIdFor(@NonNull NotificationInd notification) { private long getThreadIdFor(@NonNull NotificationInd notification) {

@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.telephony.TelephonyManager;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -23,4 +24,8 @@ public class ServiceUtil {
public static NotificationManager getNotificationManager(Context context) { public static NotificationManager getNotificationManager(Context context) {
return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
} }
public static TelephonyManager getTelephonyManager(Context context) {
return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}
} }

Loading…
Cancel
Save