|  |  | @ -22,6 +22,7 @@ import android.database.Cursor; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.database.sqlite.SQLiteDatabase; |  |  |  | import android.database.sqlite.SQLiteDatabase; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.database.sqlite.SQLiteOpenHelper; |  |  |  | import android.database.sqlite.SQLiteOpenHelper; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.net.Uri; |  |  |  | import android.net.Uri; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.support.annotation.NonNull; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.telephony.TelephonyManager; |  |  |  | import android.telephony.TelephonyManager; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.text.TextUtils; |  |  |  | import android.text.TextUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.util.Log; |  |  |  | import android.util.Log; | 
			
		
	
	
		
		
			
				
					|  |  | @ -339,15 +340,13 @@ public class MmsDatabase extends MessagingDatabase { | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   private long getThreadIdFor(NotificationInd notification) throws RecipientFormattingException { |  |  |  |   private long getThreadIdFor(@NonNull NotificationInd notification) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     try { |  |  |  |     String fromString = notification.getFrom() != null && notification.getFrom().getTextString() != null | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       EncodedStringValue encodedString = notification.getFrom(); |  |  |  |                       ? Util.toIsoString(notification.getFrom().getTextString()) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       String fromString                = new String(encodedString.getTextString(), CharacterSets.MIMENAME_ISO_8859_1); |  |  |  |                       : ""; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       Recipients recipients            = RecipientFactory.getRecipientsFromString(context, fromString, false); |  |  |  |     Recipients recipients = RecipientFactory.getRecipientsFromString(context, fromString, false); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); |  |  |  |     if (recipients.isEmpty()) recipients = new Recipients(Recipient.getUnknownRecipient(context)); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } catch (UnsupportedEncodingException e) { |  |  |  |     return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       throw new AssertionError(e); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   public Cursor getMessage(long messageId) { |  |  |  |   public Cursor getMessage(long messageId) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -646,38 +645,28 @@ public class MmsDatabase extends MessagingDatabase { | 
			
		
	
		
		
			
				
					
					|  |  |  |                               (retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0)); |  |  |  |                               (retrieved.isPushMessage() ? Types.PUSH_MESSAGE_BIT : 0)); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   public Pair<Long, Long> insertMessageInbox(NotificationInd notification) { |  |  |  |   public Pair<Long, Long> insertMessageInbox(@NonNull NotificationInd notification) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     try { |  |  |  |     SQLiteDatabase     db              = databaseHelper.getWritableDatabase(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       SQLiteDatabase     db              = databaseHelper.getWritableDatabase(); |  |  |  |     MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       MmsAddressDatabase addressDatabase = DatabaseFactory.getMmsAddressDatabase(context); |  |  |  |     long               threadId        = getThreadIdFor(notification); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       long               threadId        = getThreadIdFor(notification); |  |  |  |     PduHeaders         headers         = notification.getPduHeaders(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       PduHeaders         headers         = notification.getPduHeaders(); |  |  |  |     ContentValues      contentValues   = getContentValuesFromHeader(headers); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       ContentValues      contentValues   = getContentValuesFromHeader(headers); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     Log.w(TAG, "Message received type: " + headers.getOctet(PduHeaders.MESSAGE_TYPE)); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       Log.w("MmsDatabse", "Message received type: " + headers.getOctet(PduHeaders.MESSAGE_TYPE)); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE); |  |  |  |     contentValues.put(THREAD_ID, threadId); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       contentValues.put(THREAD_ID, threadId); |  |  |  |     contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); |  |  |  |     contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000); |  |  |  |     contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       contentValues.put(READ, org.thoughtcrime.securesms.util.Util.isDefaultSmsProvider(context) ? 0 : 1); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     if (!contentValues.containsKey(DATE_SENT)) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       if (!contentValues.containsKey(DATE_SENT)) |  |  |  |       contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED)); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED)); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     long messageId = db.insert(TABLE_NAME, null, contentValues); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       long messageId = db.insert(TABLE_NAME, null, contentValues); |  |  |  |     addressDatabase.insertAddressesForId(messageId, headers); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       addressDatabase.insertAddressesForId(messageId, headers); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     return new Pair<>(messageId, threadId); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | //      notifyConversationListeners(threadId);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | //      DatabaseFactory.getThreadDatabase(context).update(threadId);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | //      DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | //      Trimmer.trimThread(context, threadId);
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       return new Pair<Long, Long>(messageId, threadId); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } catch (RecipientFormattingException rfe) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       Log.w("MmsDatabase", rfe); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       return new Pair<Long, Long>(-1L, -1L); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   public void markIncomingNotificationReceived(long threadId) { |  |  |  |   public void markIncomingNotificationReceived(long threadId) { | 
			
		
	
	
		
		
			
				
					|  |  | 
 |