use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MmsReceiveJob method onRun.
@Override
public void onRun() {
if (data == null) {
Log.w(TAG, "Received NULL pdu, ignoring...");
return;
}
PduParser parser = new PduParser(data);
GenericPdu pdu = null;
try {
pdu = parser.parse();
} catch (RuntimeException e) {
Log.w(TAG, e);
}
if (isNotification(pdu) && !isBlocked(pdu)) {
MessageDatabase database = SignalDatabase.mms();
Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
Log.i(TAG, "Inserted received MMS notification...");
ApplicationDependencies.getJobManager().add(new MmsDownloadJob(messageAndThreadId.first(), messageAndThreadId.second(), true));
} else if (isNotification(pdu)) {
Log.w(TAG, "*** Received blocked MMS, ignoring...");
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MmsDownloadJob method onFailure.
@Override
public void onFailure() {
MessageDatabase database = SignalDatabase.mms();
database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE);
if (automatic) {
database.markIncomingNotificationReceived(threadId);
ApplicationDependencies.getMessageNotifier().updateNotification(context, threadId);
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MmsDownloadJob method handleDownloadError.
private void handleDownloadError(long messageId, long threadId, int downloadStatus, boolean automatic) {
MessageDatabase db = SignalDatabase.mms();
db.markDownloadState(messageId, downloadStatus);
if (automatic) {
db.markIncomingNotificationReceived(threadId);
ApplicationDependencies.getMessageNotifier().updateNotification(context, threadId);
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MmsDownloadJob method storeRetrievedMms.
private void storeRetrievedMms(String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId, @Nullable RecipientId notificationFrom) throws MmsException {
MessageDatabase database = SignalDatabase.mms();
Optional<GroupId> group = Optional.absent();
Set<RecipientId> members = new HashSet<>();
String body = null;
List<Attachment> attachments = new LinkedList<>();
List<Contact> sharedContacts = new LinkedList<>();
RecipientId from = null;
if (retrieved.getFrom() != null) {
from = Recipient.external(context, Util.toIsoString(retrieved.getFrom().getTextString())).getId();
} else if (notificationFrom != null) {
from = notificationFrom;
}
if (retrieved.getTo() != null) {
for (EncodedStringValue toValue : retrieved.getTo()) {
members.add(Recipient.external(context, Util.toIsoString(toValue.getTextString())).getId());
}
}
if (retrieved.getCc() != null) {
for (EncodedStringValue ccValue : retrieved.getCc()) {
members.add(Recipient.external(context, Util.toIsoString(ccValue.getTextString())).getId());
}
}
if (from != null) {
members.add(from);
}
members.add(Recipient.self().getId());
if (retrieved.getBody() != null) {
body = PartParser.getMessageText(retrieved.getBody());
PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
for (int i = 0; i < media.getPartsNum(); i++) {
PduPart part = media.getPart(i);
if (part.getData() != null) {
if (Util.toIsoString(part.getContentType()).toLowerCase().equals(MediaUtil.VCARD)) {
sharedContacts.addAll(VCardUtil.parseContacts(new String(part.getData())));
} else {
Uri uri = BlobProvider.getInstance().forData(part.getData()).createForSingleUseInMemory();
String name = null;
if (part.getName() != null)
name = Util.toIsoString(part.getName());
attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length, name, false, false, false, false, null, null, null, null, null));
}
}
}
}
if (members.size() > 2) {
List<RecipientId> recipients = new ArrayList<>(members);
group = Optional.of(SignalDatabase.groups().getOrCreateMmsGroupForMembers(recipients));
}
IncomingMediaMessage message = new IncomingMediaMessage(from, group, body, TimeUnit.SECONDS.toMillis(retrieved.getDate()), -1, System.currentTimeMillis(), attachments, subscriptionId, 0, false, false, false, Optional.of(sharedContacts));
Optional<InsertResult> insertResult = database.insertMessageInbox(message, contentLocation, threadId);
if (insertResult.isPresent()) {
database.deleteMessage(messageId);
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
}
Aggregations