2012-10-29 00:04:24 +01:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2012 Moxie Marlinpsike
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base class for message record models that are displayed in
|
|
|
|
* conversations, as opposed to models that are displayed in a thread list.
|
|
|
|
* Encapsulates the shared data between both SMS and MMS messages.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public abstract class MessageRecord extends DisplayRecord {
|
|
|
|
|
2013-01-07 06:38:36 +01:00
|
|
|
public static final int DELIVERY_STATUS_NONE = 0;
|
|
|
|
public static final int DELIVERY_STATUS_RECEIVED = 1;
|
|
|
|
public static final int DELIVERY_STATUS_PENDING = 2;
|
|
|
|
public static final int DELIVERY_STATUS_FAILED = 3;
|
|
|
|
|
2012-10-29 00:04:24 +01:00
|
|
|
private final Recipient individualRecipient;
|
|
|
|
private final long id;
|
2013-01-07 06:38:36 +01:00
|
|
|
private final int deliveryStatus;
|
2012-10-30 00:51:42 +01:00
|
|
|
private final GroupData groupData;
|
2012-10-29 00:04:24 +01:00
|
|
|
|
|
|
|
public MessageRecord(long id, Recipients recipients,
|
|
|
|
Recipient individualRecipient,
|
2013-01-06 22:13:14 +01:00
|
|
|
long dateSent, long dateReceived,
|
2013-01-07 06:38:36 +01:00
|
|
|
long threadId, int deliveryStatus,
|
|
|
|
GroupData groupData)
|
2012-10-29 00:04:24 +01:00
|
|
|
{
|
2013-01-06 22:13:14 +01:00
|
|
|
super(recipients, dateSent, dateReceived, threadId);
|
2012-10-29 00:04:24 +01:00
|
|
|
this.id = id;
|
|
|
|
this.individualRecipient = individualRecipient;
|
2013-01-07 06:38:36 +01:00
|
|
|
this.deliveryStatus = deliveryStatus;
|
2012-10-30 00:51:42 +01:00
|
|
|
this.groupData = groupData;
|
2012-10-29 00:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract boolean isOutgoing();
|
|
|
|
|
|
|
|
public abstract boolean isFailed();
|
|
|
|
|
|
|
|
public abstract boolean isSecure();
|
|
|
|
|
|
|
|
public abstract boolean isPending();
|
|
|
|
|
|
|
|
public abstract boolean isMms();
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2013-01-07 06:38:36 +01:00
|
|
|
public int getDeliveryStatus() {
|
|
|
|
return deliveryStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDelivered() {
|
|
|
|
return getDeliveryStatus() == DELIVERY_STATUS_RECEIVED;
|
|
|
|
}
|
|
|
|
|
2012-10-29 00:04:24 +01:00
|
|
|
public boolean isStaleKeyExchange() {
|
|
|
|
return this.staleKeyExchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isProcessedKeyExchange() {
|
|
|
|
return this.processedKeyExchange;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Recipient getIndividualRecipient() {
|
|
|
|
return individualRecipient;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:51:42 +01:00
|
|
|
public GroupData getGroupData() {
|
|
|
|
return this.groupData;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isGroupDeliveryPending() {
|
|
|
|
if (this.groupData != null) {
|
|
|
|
return groupData.groupSentCount + groupData.groupSendFailedCount < groupData.groupSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class GroupData {
|
|
|
|
public final int groupSize;
|
|
|
|
public final int groupSentCount;
|
|
|
|
public final int groupSendFailedCount;
|
|
|
|
|
|
|
|
public GroupData(int groupSize, int groupSentCount, int groupSendFailedCount) {
|
|
|
|
this.groupSize = groupSize;
|
|
|
|
this.groupSentCount = groupSentCount;
|
|
|
|
this.groupSendFailedCount = groupSendFailedCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-29 00:04:24 +01:00
|
|
|
|
|
|
|
}
|