session-android/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java

121 lines
4.4 KiB
Java
Raw Normal View History

/**
* Copyright (C) 2012 Moxie Marlinspike
*
2011-12-20 19:20:44 +01:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2011-12-20 19:20:44 +01:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.database.model;
2011-12-20 19:20:44 +01:00
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.SpannableString;
2011-12-20 19:20:44 +01:00
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.MmsDatabase;
import org.thoughtcrime.securesms.database.SmsDatabase.Status;
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
import org.thoughtcrime.securesms.mms.Slide;
2011-12-20 19:20:44 +01:00
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients;
2011-12-20 19:20:44 +01:00
import java.util.List;
2014-08-12 21:11:23 +02:00
/**
* Represents the message record model for MMS messages that contain
* media (ie: they've been downloaded).
*
* @author Moxie Marlinspike
*
*/
public class MediaMmsMessageRecord extends MessageRecord {
2014-08-12 21:11:23 +02:00
private final static String TAG = MediaMmsMessageRecord.class.getSimpleName();
2011-12-20 19:20:44 +01:00
private final Context context;
private final int partCount;
private final @NonNull SlideDeck slideDeck;
public MediaMmsMessageRecord(Context context, long id, Recipients recipients,
Recipient individualRecipient, int recipientDeviceId,
long dateSent, long dateReceived, int receiptCount,
long threadId, Body body,
@NonNull SlideDeck slideDeck,
int partCount, long mailbox,
List<IdentityKeyMismatch> mismatches,
List<NetworkFailure> failures, int subscriptionId,
long expiresIn, long expireStarted)
{
super(context, id, body, recipients, individualRecipient, recipientDeviceId, dateSent,
dateReceived, threadId, Status.STATUS_NONE, receiptCount, mailbox, mismatches, failures,
subscriptionId, expiresIn, expireStarted);
this.context = context.getApplicationContext();
this.partCount = partCount;
this.slideDeck = slideDeck;
2014-08-12 21:11:23 +02:00
}
public @NonNull SlideDeck getSlideDeck() {
return slideDeck;
2011-12-20 19:20:44 +01:00
}
2014-08-12 21:11:23 +02:00
public boolean containsMediaSlide() {
return slideDeck.containsMediaSlide();
}
2014-08-12 21:11:23 +02:00
public int getPartCount() {
return partCount;
}
@Override
public boolean isMms() {
return true;
2011-12-20 19:20:44 +01:00
}
@Override
public boolean isMmsNotification() {
return false;
}
@Override
public boolean isMediaPending() {
for (Slide slide : getSlideDeck().getSlides()) {
if (slide.isInProgress() || slide.isPendingDownload()) {
return true;
}
}
return false;
}
@Override
public SpannableString getDisplayBody() {
if (MmsDatabase.Types.isDecryptInProgressType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_decrypting_mms_please_wait));
} else if (MmsDatabase.Types.isFailedDecryptType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_bad_encrypted_mms_message));
2014-03-19 20:37:46 +01:00
} else if (MmsDatabase.Types.isDuplicateMessageType(type)) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));
} else if (MmsDatabase.Types.isNoRemoteSessionType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_mms_message_encrypted_for_non_existing_session));
} else if (isLegacyMessage()) {
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else if (!getBody().isPlaintext()) {
2015-07-18 02:46:02 +02:00
return emphasisAdded(context.getString(R.string.MessageNotifier_locked_message));
2011-12-20 19:20:44 +01:00
}
return super.getDisplayBody();
2011-12-20 19:20:44 +01:00
}
}