use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class PlaintextBackupExporter method exportPlaintext.
private static void exportPlaintext(Context context, MasterSecret masterSecret) throws IOException {
int count = DatabaseFactory.getSmsDatabase(context).getMessageCount();
XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportFile().getAbsolutePath(), count);
SmsMessageRecord record;
EncryptingSmsDatabase.Reader reader = null;
int skip = 0;
int ROW_LIMIT = 500;
do {
if (reader != null)
reader.close();
reader = DatabaseFactory.getEncryptingSmsDatabase(context).getMessages(masterSecret, skip, ROW_LIMIT);
while ((record = reader.getNext()) != null) {
XmlBackup.XmlBackupItem item = new XmlBackup.XmlBackupItem(0, record.getIndividualRecipient().getNumber(), record.getDateReceived(), MmsSmsColumns.Types.translateToSystemBaseType(record.getType()), null, record.getDisplayBody().toString(), null, 1, record.getDeliveryStatus());
writer.writeItem(item);
}
skip += ROW_LIMIT;
} while (reader.getCount() > 0);
writer.close();
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class SmsDatabase method copyMessageInbox.
public Pair<Long, Long> copyMessageInbox(long messageId) {
Reader reader = readerFor(getMessage(messageId));
SmsMessageRecord record = reader.getNext();
ContentValues contentValues = new ContentValues();
contentValues.put(TYPE, (record.getType() & ~Types.BASE_TYPE_MASK) | Types.BASE_INBOX_TYPE);
contentValues.put(ADDRESS, record.getIndividualRecipient().getNumber());
contentValues.put(ADDRESS_DEVICE_ID, record.getRecipientDeviceId());
contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
contentValues.put(DATE_SENT, record.getDateSent());
contentValues.put(PROTOCOL, 31337);
contentValues.put(READ, 0);
contentValues.put(BODY, record.getBody().getBody());
contentValues.put(THREAD_ID, record.getThreadId());
contentValues.put(EXPIRES_IN, record.getExpiresIn());
SQLiteDatabase db = databaseHelper.getWritableDatabase();
long newMessageId = db.insert(TABLE_NAME, null, contentValues);
DatabaseFactory.getThreadDatabase(context).update(record.getThreadId(), true);
notifyConversationListeners(record.getThreadId());
jobManager.add(new TrimThreadJob(context, record.getThreadId()));
reader.close();
return new Pair<>(newMessageId, record.getThreadId());
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class PushTextSendJob method onPushSend.
@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsMessageRecord record = database.getMessage(masterSecret, messageId);
try {
Log.w(TAG, "Sending message: " + messageId);
deliver(record);
database.markAsSent(messageId, true);
if (record.getExpiresIn() > 0) {
database.markExpireStarted(messageId);
expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
}
} catch (InsecureFallbackApprovalException e) {
Log.w(TAG, e);
database.markAsPendingInsecureSmsFallback(record.getId());
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
} catch (UntrustedIdentityException e) {
Log.w(TAG, e);
Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
database.markAsSentFailed(record.getId());
database.markAsPush(record.getId());
}
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.
the class SmsSendJob method onSend.
@Override
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsMessageRecord record = database.getMessage(masterSecret, messageId);
try {
Log.w(TAG, "Sending message: " + messageId);
deliver(record);
} catch (UndeliverableMessageException ude) {
Log.w(TAG, ude);
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId());
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
}
}
use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.
the class SmsSendJob method onSend.
@Override
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException {
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
SmsMessageRecord record = database.getMessage(messageId);
try {
Log.w(TAG, "Sending message: " + messageId);
deliver(record);
} catch (UndeliverableMessageException ude) {
Log.w(TAG, ude);
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId());
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
}
}
Aggregations