private long getThreadIdFor(IncomingMediaMessage retrieved) throws RecipientFormattingException, MmsException { if (retrieved.getGroupId() != null) { Recipients groupRecipients = RecipientFactory.getRecipientsFromString(context, retrieved.getGroupId(), true); return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients); } String localNumber; Set<String> group = new HashSet<>(); if (retrieved.getAddresses().getFrom() == null) { throw new MmsException("FROM value in PduHeaders did not exist."); } group.add(retrieved.getAddresses().getFrom()); if (TextSecurePreferences.isPushRegistered(context)) { localNumber = TextSecurePreferences.getLocalNumber(context); } else { localNumber = ServiceUtil.getTelephonyManager(context).getLine1Number(); } for (String cc : retrieved.getAddresses().getCc()) { PhoneNumberUtil.MatchType match; if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, cc); if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) { group.add(cc); } } if (retrieved.getAddresses().getTo().size() > 1) { for (String to : retrieved.getAddresses().getTo()) { PhoneNumberUtil.MatchType match; if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, to); if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) { group.add(to); } } } String recipientsList = Util.join(group, ","); Recipients recipients = RecipientFactory.getRecipientsFromString(context, recipientsList, false); return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); }
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) { this.context = context.getApplicationContext(); this.groupContext = groupContext; if (groupContext == null || groupContext.getMembersList().isEmpty()) { this.members = null; } else { this.members = RecipientFactory.getRecipientsFromString( context, Util.join(groupContext.getMembersList(), ", "), true); } }
private Cursor rawQuery(@NonNull String where, @Nullable String[] arguments) { SQLiteDatabase database = databaseHelper.getReadableDatabase(); return database.rawQuery( "SELECT " + Util.join(MMS_PROJECTION, ",") + " FROM " + MmsDatabase.TABLE_NAME + " LEFT OUTER JOIN " + AttachmentDatabase.TABLE_NAME + " ON (" + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " = " + AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.MMS_ID + ")" + " WHERE " + where, arguments); }