session-android/src/org/thoughtcrime/securesms/sms/OutgoingTextMessage.java

88 lines
2.4 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.sms;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
public class OutgoingTextMessage {
private final Recipient recipient;
private final String message;
private final int subscriptionId;
private final long expiresIn;
2019-09-18 07:33:34 +00:00
public boolean isFriendRequest = false;
public OutgoingTextMessage(Recipient recipient, String message, int subscriptionId) {
this(recipient, message, 0, subscriptionId);
}
public OutgoingTextMessage(Recipient recipient, String message, long expiresIn, int subscriptionId) {
this.recipient = recipient;
this.message = message;
this.expiresIn = expiresIn;
this.subscriptionId = subscriptionId;
}
protected OutgoingTextMessage(OutgoingTextMessage base, String body) {
this.recipient = base.getRecipient();
this.subscriptionId = base.getSubscriptionId();
this.expiresIn = base.getExpiresIn();
this.message = body;
}
public long getExpiresIn() {
return expiresIn;
}
public int getSubscriptionId() {
return subscriptionId;
}
public String getMessageBody() {
return message;
}
public Recipient getRecipient() {
return recipient;
}
public boolean isKeyExchange() {
return false;
}
public boolean isSecureMessage() {
return false;
}
public boolean isEndSession() {
return false;
}
public boolean isPreKeyBundle() {
return false;
}
public boolean isIdentityVerified() {
return false;
}
public boolean isIdentityDefault() {
return false;
}
public static OutgoingTextMessage from(SmsMessageRecord record) {
if (record.isSecure()) {
2018-02-02 02:29:09 +00:00
return new OutgoingEncryptedMessage(record.getRecipient(), record.getBody(), record.getExpiresIn());
} else if (record.isKeyExchange()) {
2018-02-02 02:29:09 +00:00
return new OutgoingKeyExchangeMessage(record.getRecipient(), record.getBody());
} else if (record.isEndSession()) {
2018-02-02 02:29:09 +00:00
return new OutgoingEndSessionMessage(new OutgoingTextMessage(record.getRecipient(), record.getBody(), 0, -1));
} else {
2018-02-02 02:29:09 +00:00
return new OutgoingTextMessage(record.getRecipient(), record.getBody(), record.getExpiresIn(), record.getSubscriptionId());
}
}
public OutgoingTextMessage withBody(String body) {
return new OutgoingTextMessage(this, body);
}
}