|
37 | 37 | import org.thoughtcrime.securesms.database.DatabaseFactory; |
38 | 38 | import org.thoughtcrime.securesms.database.EncryptingSmsDatabase; |
39 | 39 | import org.thoughtcrime.securesms.database.IdentityDatabase; |
| 40 | +import org.thoughtcrime.securesms.database.PushDatabase; |
| 41 | +import org.thoughtcrime.securesms.jobs.PushDecryptJob; |
40 | 42 | import org.thoughtcrime.securesms.jobs.SmsDecryptJob; |
41 | 43 | import org.thoughtcrime.securesms.recipients.Recipient; |
42 | 44 | import org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage; |
|
54 | 56 | import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage; |
55 | 57 | import org.whispersystems.libaxolotl.state.IdentityKeyStore; |
56 | 58 | import org.whispersystems.libaxolotl.util.guava.Optional; |
| 59 | +import org.whispersystems.textsecure.api.messages.TextSecureEnvelope; |
57 | 60 | import org.whispersystems.textsecure.api.messages.TextSecureGroup; |
58 | 61 |
|
59 | 62 | import java.io.IOException; |
@@ -211,18 +214,39 @@ protected void onPreExecute() { |
211 | 214 |
|
212 | 215 | @Override |
213 | 216 | protected Void doInBackground(Void... params) { |
214 | | - IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(ReceiveKeyActivity.this); |
215 | | - EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this); |
216 | 217 | Context context = ReceiveKeyActivity.this; |
| 218 | + IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context); |
| 219 | + EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context); |
| 220 | + PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(context); |
217 | 221 |
|
218 | 222 | identityDatabase.saveIdentity(masterSecret, recipient.getRecipientId(), identityKey); |
219 | 223 |
|
220 | 224 | if (message.isIdentityUpdate()) { |
221 | 225 | smsDatabase.markAsProcessedKeyExchange(messageId); |
222 | 226 | } else { |
223 | | - ApplicationContext.getInstance(context) |
224 | | - .getJobManager() |
225 | | - .add(new SmsDecryptJob(context, messageId)); |
| 227 | + if (getIntent().getBooleanExtra("is_push", false)) { |
| 228 | + try { |
| 229 | + byte[] body = Base64.decode(message.getMessageBody()); |
| 230 | + TextSecureEnvelope envelope = new TextSecureEnvelope(3, message.getSender(), |
| 231 | + message.getSenderDeviceId(), "", |
| 232 | + message.getSentTimestampMillis(), |
| 233 | + body); |
| 234 | + |
| 235 | + long pushId = pushDatabase.insert(envelope); |
| 236 | + |
| 237 | + ApplicationContext.getInstance(context) |
| 238 | + .getJobManager() |
| 239 | + .add(new PushDecryptJob(context, pushId)); |
| 240 | + |
| 241 | + smsDatabase.deleteMessage(messageId); |
| 242 | + } catch (IOException e) { |
| 243 | + throw new AssertionError(e); |
| 244 | + } |
| 245 | + } else { |
| 246 | + ApplicationContext.getInstance(context) |
| 247 | + .getJobManager() |
| 248 | + .add(new SmsDecryptJob(context, messageId)); |
| 249 | + } |
226 | 250 | } |
227 | 251 |
|
228 | 252 | return null; |
|
0 commit comments