session-android/src/org/thoughtcrime/securesms/database/MmsMessageRecord.java

152 lines
4 KiB
Java
Raw Normal View History

/**
2011-12-20 19:20:44 +01:00
* Copyright (C) 2011 Whisper Systems
*
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;
import android.content.Context;
2011-12-20 19:20:44 +01:00
import org.thoughtcrime.securesms.ConversationItem;
import org.thoughtcrime.securesms.R;
2011-12-20 19:20:44 +01:00
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import java.util.Iterator;
import java.util.List;
2011-12-20 19:20:44 +01:00
public class MmsMessageRecord extends MessageRecord {
private SlideDeck slideDeck;
private byte[] contentLocation;
private long messageSize;
private long expiry;
private boolean isNotification;
private long mailbox;
private int status;
private byte[] transactionId;
public MmsMessageRecord(Context context, MessageRecord record, SlideDeck slideDeck, long mailbox) {
super(record);
2011-12-20 19:20:44 +01:00
this.slideDeck = slideDeck;
this.isNotification = false;
this.mailbox = mailbox;
setBodyIfTextAvailable(context);
2011-12-20 19:20:44 +01:00
}
public MmsMessageRecord(MessageRecord record, byte[] contentLocation, long messageSize, long expiry, int status, byte[] transactionId) {
super(record);
this.contentLocation = contentLocation;
this.messageSize = messageSize;
this.expiry = expiry;
this.isNotification = true;
this.status = status;
this.transactionId = transactionId;
}
2011-12-20 19:20:44 +01:00
public byte[] getTransactionId() {
return transactionId;
}
2011-12-20 19:20:44 +01:00
public int getStatus() {
return this.status;
}
2011-12-20 19:20:44 +01:00
@Override
public boolean isOutgoing() {
2011-12-20 19:20:44 +01:00
return MmsDatabase.Types.isOutgoingMmsBox(mailbox);
}
2011-12-20 19:20:44 +01:00
@Override
public boolean isPending() {
2011-12-20 19:20:44 +01:00
return MmsDatabase.Types.isPendingMmsBox(mailbox);
}
2011-12-20 19:20:44 +01:00
@Override
public boolean isFailed() {
2011-12-20 19:20:44 +01:00
return MmsDatabase.Types.isFailedMmsBox(mailbox);
}
2011-12-20 19:20:44 +01:00
@Override
public boolean isSecure() {
2011-12-20 19:20:44 +01:00
return MmsDatabase.Types.isSecureMmsBox(mailbox);
}
2011-12-20 19:20:44 +01:00
// This is the double-dispatch pattern, don't refactor
// this into the base class.
@Override
2011-12-20 19:20:44 +01:00
public void setOnConversationItem(ConversationItem item) {
item.setMessageRecord(this);
}
2011-12-20 19:20:44 +01:00
public byte[] getContentLocation() {
return contentLocation;
}
2011-12-20 19:20:44 +01:00
public long getMessageSize() {
return (messageSize + 1023) / 1024;
}
2011-12-20 19:20:44 +01:00
public long getExpiration() {
return expiry * 1000;
}
2011-12-20 19:20:44 +01:00
public boolean isNotification() {
return isNotification;
}
public SlideDeck getSlideDeck() {
return slideDeck;
}
2011-12-20 19:20:44 +01:00
private void setBodyFromSlidesIfTextAvailable() {
List<Slide> slides = slideDeck.getSlides();
Iterator<Slide> i = slides.iterator();
2011-12-20 19:20:44 +01:00
while (i.hasNext()) {
Slide slide = i.next();
2011-12-20 19:20:44 +01:00
if (slide.hasText())
setBody(slide.getText());
}
2011-12-20 19:20:44 +01:00
}
private void setBodyIfTextAvailable(Context context) {
2011-12-20 19:20:44 +01:00
switch ((int)mailbox) {
case MmsDatabase.Types.MESSAGE_BOX_DECRYPTING_INBOX:
setBody(context.getString(R.string.MmsMessageRecord_decrypting_mms_please_wait));
2011-12-20 19:20:44 +01:00
setEmphasis(true);
return;
case MmsDatabase.Types.MESSAGE_BOX_DECRYPT_FAILED_INBOX:
setBody(context.getString(R.string.MmsMessageRecord_bad_encrypted_mms_message));
2011-12-20 19:20:44 +01:00
setEmphasis(true);
return;
case MmsDatabase.Types.MESSAGE_BOX_NO_SESSION_INBOX:
setBody(context
.getString(R.string.MmsMessageRecord_mms_message_encrypted_for_non_existing_session));
2011-12-20 19:20:44 +01:00
setEmphasis(true);
return;
}
2011-12-20 19:20:44 +01:00
setBodyFromSlidesIfTextAvailable();
}
2011-12-20 19:20:44 +01:00
@Override
public boolean isMms() {
return true;
}
2011-12-20 19:20:44 +01:00
}