feat: adding call messages for incoming/outgoing/missed

This commit is contained in:
jubb
2021-11-23 17:59:02 +11:00
parent c863df2a60
commit f05487f925
15 changed files with 176 additions and 69 deletions

View File

@@ -2,6 +2,7 @@ package org.session.libsession.database
import android.content.Context
import android.net.Uri
import org.session.libsession.messaging.calls.CallMessageType
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.jobs.AttachmentUploadJob
import org.session.libsession.messaging.jobs.Job
@@ -153,4 +154,5 @@ interface StorageProtocol {
*/
fun persist(message: VisibleMessage, quotes: QuoteModel?, linkPreview: List<LinkPreview?>, groupPublicKey: String?, openGroupID: String?, attachments: List<Attachment>): Long?
fun insertDataExtractionNotificationMessage(senderPublicKey: String, message: DataExtractionNotificationInfoMessage, sentTimestamp: Long)
fun insertCallMessage(senderPublicKey: String, callMessageType: CallMessageType, sentTimestamp: Long)
}

View File

@@ -0,0 +1,7 @@
package org.session.libsession.messaging.calls
enum class CallMessageType {
CALL_MISSED,
CALL_INCOMING,
CALL_OUTGOING
}

View File

@@ -5,6 +5,7 @@ import android.os.Parcelable;
import androidx.annotation.Nullable;
import org.session.libsession.messaging.calls.CallMessageType;
import org.session.libsession.messaging.messages.visible.OpenGroupInvitation;
import org.session.libsession.messaging.messages.visible.VisibleMessage;
import org.session.libsession.utilities.Address;
@@ -41,12 +42,19 @@ public class IncomingTextMessage implements Parcelable {
private final int subscriptionId;
private final long expiresInMillis;
private final boolean unidentified;
private final int callType;
private boolean isOpenGroupInvitation = false;
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
String encodedBody, Optional<SignalServiceGroup> group,
long expiresInMillis, boolean unidentified) {
this(sender, senderDeviceId, sentTimestampMillis, encodedBody, group, expiresInMillis, unidentified, -1);
}
public IncomingTextMessage(Address sender, int senderDeviceId, long sentTimestampMillis,
String encodedBody, Optional<SignalServiceGroup> group,
long expiresInMillis, boolean unidentified)
long expiresInMillis, boolean unidentified, int callType)
{
this.message = encodedBody;
this.sender = sender;
@@ -60,6 +68,7 @@ public class IncomingTextMessage implements Parcelable {
this.subscriptionId = -1;
this.expiresInMillis = expiresInMillis;
this.unidentified = unidentified;
this.callType = callType;
if (group.isPresent()) {
this.groupId = Address.fromSerialized(GroupUtil.getEncodedId(group.get()));
@@ -69,36 +78,39 @@ public class IncomingTextMessage implements Parcelable {
}
public IncomingTextMessage(Parcel in) {
this.message = in.readString();
this.sender = in.readParcelable(IncomingTextMessage.class.getClassLoader());
this.senderDeviceId = in.readInt();
this.protocol = in.readInt();
this.serviceCenterAddress = in.readString();
this.replyPathPresent = (in.readInt() == 1);
this.pseudoSubject = in.readString();
this.sentTimestampMillis = in.readLong();
this.groupId = in.readParcelable(IncomingTextMessage.class.getClassLoader());
this.push = (in.readInt() == 1);
this.subscriptionId = in.readInt();
this.expiresInMillis = in.readLong();
this.unidentified = in.readInt() == 1;
this.message = in.readString();
this.sender = in.readParcelable(IncomingTextMessage.class.getClassLoader());
this.senderDeviceId = in.readInt();
this.protocol = in.readInt();
this.serviceCenterAddress = in.readString();
this.replyPathPresent = (in.readInt() == 1);
this.pseudoSubject = in.readString();
this.sentTimestampMillis = in.readLong();
this.groupId = in.readParcelable(IncomingTextMessage.class.getClassLoader());
this.push = (in.readInt() == 1);
this.subscriptionId = in.readInt();
this.expiresInMillis = in.readLong();
this.unidentified = in.readInt() == 1;
this.isOpenGroupInvitation = in.readInt() == 1;
this.callType = in.readInt();
}
public IncomingTextMessage(IncomingTextMessage base, String newBody) {
this.message = newBody;
this.sender = base.getSender();
this.senderDeviceId = base.getSenderDeviceId();
this.protocol = base.getProtocol();
this.serviceCenterAddress = base.getServiceCenterAddress();
this.replyPathPresent = base.isReplyPathPresent();
this.pseudoSubject = base.getPseudoSubject();
this.sentTimestampMillis = base.getSentTimestampMillis();
this.groupId = base.getGroupId();
this.push = base.isPush();
this.subscriptionId = base.getSubscriptionId();
this.expiresInMillis = base.getExpiresIn();
this.unidentified = base.isUnidentified();
this.isOpenGroupInvitation= base.isOpenGroupInvitation();
this.message = newBody;
this.sender = base.getSender();
this.senderDeviceId = base.getSenderDeviceId();
this.protocol = base.getProtocol();
this.serviceCenterAddress = base.getServiceCenterAddress();
this.replyPathPresent = base.isReplyPathPresent();
this.pseudoSubject = base.getPseudoSubject();
this.sentTimestampMillis = base.getSentTimestampMillis();
this.groupId = base.getGroupId();
this.push = base.isPush();
this.subscriptionId = base.getSubscriptionId();
this.expiresInMillis = base.getExpiresIn();
this.unidentified = base.isUnidentified();
this.isOpenGroupInvitation = base.isOpenGroupInvitation();
this.callType = base.callType;
}
public static IncomingTextMessage from(VisibleMessage message,
@@ -121,6 +133,13 @@ public class IncomingTextMessage implements Parcelable {
return incomingTextMessage;
}
public static IncomingTextMessage fromCallInfo(CallMessageType callMessageType,
Address sender,
Optional<SignalServiceGroup> group,
long sentTimestamp) {
return new IncomingTextMessage(sender, 1, sentTimestamp, null, group, 0, false, callMessageType.ordinal());
}
public int getSubscriptionId() {
return subscriptionId;
}
@@ -183,6 +202,18 @@ public class IncomingTextMessage implements Parcelable {
public boolean isOpenGroupInvitation() { return isOpenGroupInvitation; }
public boolean isCallInfo() {
int callMessageTypeLength = CallMessageType.values().length;
return callType >= 0 && callType < callMessageTypeLength;
}
@Nullable
public CallMessageType getCallType() {
int callTypeLength = CallMessageType.values().length;
if (callType < 0 || callType >= callTypeLength) return null;
return CallMessageType.values()[callType];
}
@Override
public int describeContents() {
return 0;
@@ -202,5 +233,7 @@ public class IncomingTextMessage implements Parcelable {
out.writeInt(push ? 1 : 0);
out.writeInt(subscriptionId);
out.writeInt(unidentified ? 1 : 0);
out.writeInt(isOpenGroupInvitation ? 1 : 0);
out.writeInt(callType);
}
}

View File

@@ -3,6 +3,7 @@ package org.session.libsession.messaging.utilities
import android.content.Context
import org.session.libsession.R
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.calls.CallMessageType
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage
import org.session.libsession.utilities.ExpirationUtil
@@ -102,4 +103,17 @@ object UpdateMessageBuilder {
context.getString(R.string.MessageRecord_media_saved_by_s, senderName)
}
}
fun buildCallMessage(context: Context, type: CallMessageType, sender: String): String {
val storage = MessagingModuleConfiguration.shared.storage
val senderName = storage.getContactWithSessionID(sender)?.displayName(Contact.ContactContext.REGULAR) ?: sender
return when (type) {
CallMessageType.CALL_MISSED ->
context.getString(R.string.MessageRecord_missed_call_from, senderName)
CallMessageType.CALL_INCOMING ->
context.getString(R.string.MessageRecord_called_s, senderName)
CallMessageType.CALL_OUTGOING ->
context.getString(R.string.MessageRecord_s_called_you, senderName)
}
}
}