diff --git a/res/layout/conversation_item_received.xml b/res/layout/conversation_item_received.xml index ed289e509b..95b65d1237 100644 --- a/res/layout/conversation_item_received.xml +++ b/res/layout/conversation_item_received.xml @@ -41,141 +41,157 @@ + android:clipChildren="false"> + android:layout_marginEnd="@dimen/message_bubble_edge_margin" + android:layout_marginStart="8dp" + android:layout_toEndOf="@id/contact_photo_container" + android:orientation="vertical" + android:clipToPadding="false" + android:clipChildren="false" + android:background="@color/white" + tools:backgroundTint="@color/conversation_blue"> - + android:layout_marginTop="@dimen/message_bubble_top_padding" + android:layout_marginBottom="2dp" + android:layout_marginStart="@dimen/message_bubble_horizontal_padding" + android:layout_marginEnd="@dimen/message_bubble_horizontal_padding" + android:orientation="horizontal" + android:visibility="gone" + tools:visibility="visible"> - + + + + + + + + + + + + + + + + + + + app:scaleEmojis="true" + app:emoji_maxLength="1000" + tools:text="Mango pickle lorem ipsum"/> + + - - - - - - - - - - - - - - - + android:layout_height="wrap_content" /> diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index e9a5ed6be9..1dc07c664a 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -80,7 +80,6 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.database.model.Quote; -import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob; import org.thoughtcrime.securesms.jobs.MmsDownloadJob; import org.thoughtcrime.securesms.jobs.MmsSendJob; @@ -98,7 +97,6 @@ import org.thoughtcrime.securesms.mms.SlidesClickedListener; import org.thoughtcrime.securesms.mms.TextSlide; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; -import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.LongClickCopySpan; @@ -790,8 +788,7 @@ public class ConversationItem extends LinearLayout } private void setFriendRequestView(@NonNull MessageRecord record) { - OutgoingTextMessage message = OutgoingTextMessage.from((SmsMessageRecord)record); - friendRequestView.update(message, record.id); + friendRequestView.update(record); } private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) { diff --git a/src/org/thoughtcrime/securesms/database/SmsDatabase.java b/src/org/thoughtcrime/securesms/database/SmsDatabase.java index c583963f62..d32cd5a14e 100644 --- a/src/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -178,6 +178,22 @@ public class SmsDatabase extends MessagingDatabase { return 0; } + public long getLastMessageIDForThread(long threadID) { + SQLiteDatabase database = databaseHelper.getReadableDatabase(); + Cursor cursor = null; + try { + cursor = database.query(TABLE_NAME, null, THREAD_ID + " = ?", new String[] { threadID + "" }, null, null, null); + if (cursor != null && cursor.moveToLast()) { + return cursor.getLong(0); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return -1; + } + public void markAsEndSession(long id) { updateTypeBitmask(id, Types.KEY_EXCHANGE_MASK, Types.END_SESSION_BIT); } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index d00eb41504..3b6b09ac65 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -62,6 +62,7 @@ import org.thoughtcrime.securesms.linkpreview.Link; import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.logging.Log; +import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase; import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase; import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase; import org.thoughtcrime.securesms.mms.IncomingMediaMessage; @@ -111,6 +112,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher; +import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage; import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; @@ -135,6 +137,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private long smsMessageId; @Inject SignalServiceMessageSender messageSender; + private Address author; public PushDecryptJob(Context context) { this(context, -1); @@ -276,8 +279,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { else if (isMediaMessage) handleMediaMessage(content, message, smsMessageId); else if (message.getBody().isPresent()) { // Loki - Handle friend request logic - handleFriendRequestIfNeeded(envelope, content, message); handleTextMessage(content, message, smsMessageId); + handleFriendRequestIfNeeded(envelope, content, message); } if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false))) { @@ -321,7 +324,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Log.w(TAG, "Got unrecognized message..."); } - resetRecipientToPush(Recipient.from(context, Address.fromExternal(context, content.getSender()), false)); + resetRecipientToPush(Recipient.from(context, Address.fromSerialized(content.getSender()), false)); if (envelope.isPreKeySignalMessage()) { ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob()); @@ -368,7 +371,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Intent intent = new Intent(context, WebRtcCallService.class); intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL); intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); - intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, content.getSender())); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromSerialized(content.getSender())); intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription()); intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, content.getTimestamp()); @@ -384,7 +387,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Intent intent = new Intent(context, WebRtcCallService.class); intent.setAction(WebRtcCallService.ACTION_RESPONSE_MESSAGE); intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); - intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, content.getSender())); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromSerialized(content.getSender())); intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription()); context.startService(intent); @@ -398,7 +401,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Intent intent = new Intent(context, WebRtcCallService.class); intent.setAction(WebRtcCallService.ACTION_ICE_MESSAGE); intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); - intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, content.getSender())); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromSerialized(content.getSender())); intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP, message.getSdp()); intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid()); intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_LINE_INDEX, message.getSdpMLineIndex()); @@ -418,7 +421,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Intent intent = new Intent(context, WebRtcCallService.class); intent.setAction(WebRtcCallService.ACTION_REMOTE_HANGUP); intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); - intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, content.getSender())); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromSerialized(content.getSender())); context.startService(intent); } @@ -430,7 +433,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Intent intent = new Intent(context, WebRtcCallService.class); intent.setAction(WebRtcCallService.ACTION_REMOTE_BUSY); intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); - intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, content.getSender())); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromSerialized(content.getSender())); context.startService(intent); } @@ -439,7 +442,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { @NonNull Optional smsMessageId) { SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); - IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.fromExternal(context, content.getSender()), + IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.fromSerialized(content.getSender()), content.getSenderDevice(), content.getTimestamp(), "", Optional.absent(), 0, @@ -523,7 +526,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { try { MmsDatabase database = DatabaseFactory.getMmsDatabase(context); Recipient recipient = getMessageDestination(content, message); - IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromExternal(context, content.getSender()), + IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromSerialized(content.getSender()), message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000L, true, content.isNeedsReceipt(), @@ -579,7 +582,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (message.getMessage().getProfileKey().isPresent()) { Recipient recipient = null; - if (message.getDestination().isPresent()) recipient = Recipient.from(context, Address.fromExternal(context, message.getDestination().get()), false); + if (message.getDestination().isPresent()) recipient = Recipient.from(context, Address.fromSerialized(message.getDestination().get()), false); else if (message.getMessage().getGroupInfo().isPresent()) recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false); @@ -636,8 +639,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private void handleSynchronizeReadMessage(@NonNull List readMessages, long envelopeTimestamp) { for (ReadMessage readMessage : readMessages) { - List> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); - List> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); + List> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromSerialized(readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); + List> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromSerialized(readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); for (Pair expiringMessage : expiringText) { ApplicationContext.getInstance(context) @@ -669,7 +672,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Optional quote = getValidatedQuote(message.getQuote()); Optional> sharedContacts = getContacts(message.getSharedContacts()); Optional> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or("")); - IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromExternal(context, content.getSender()), + IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromSerialized(content.getSender()), message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000L, false, content.isNeedsReceipt(), @@ -826,10 +829,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private void handleFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) { Recipient recipient = getMessageDestination(content, message); long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient); - LokiThreadFriendRequestDatabase database = DatabaseFactory.getLokiThreadFriendRequestDatabase(context); - LokiThreadFriendRequestStatus friendRequestStatus = database.getFriendRequestStatus(threadID); + LokiThreadFriendRequestDatabase threadFriendRequestDatabase = DatabaseFactory.getLokiThreadFriendRequestDatabase(context); + LokiThreadFriendRequestStatus threadFriendRequestStatus = threadFriendRequestDatabase.getFriendRequestStatus(threadID); + LokiMessageFriendRequestDatabase messageFriendRequestDatabase = DatabaseFactory.getLokiMessageFriendRequestDatabase(context); + long messageID = DatabaseFactory.getSmsDatabase(context).getLastMessageIDForThread(threadID); if (envelope.isFriendRequest()) { - if (friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT) { + if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT) { // This can happen if Alice sent Bob a friend request, Bob declined, but then Bob changed his // mind and sent a friend request to Alice. In this case we want Alice to auto-accept the request // and send a friend request accepted message back to Bob. We don't check that sending the @@ -840,21 +845,24 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // before updating Alice's thread's friend request status to `FRIENDS`, // we can end up in a deadlock where both users' threads' friend request statuses are // `REQUEST_SENT`. - database.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); + threadFriendRequestDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); + // TODO: Update message friend request status // Accept the friend request sendEmptyMessage(envelope.getSource()); - } else if (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { + } else if (threadFriendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { // Checking that the sender of the message isn't already a friend is necessary because otherwise // the following situation can occur: Alice and Bob are friends. Bob loses his database and his // friend request status is reset to `NONE`. Bob now sends Alice a friend // request. Alice's thread's friend request status is reset to // `REQUEST_RECEIVED`. - database.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.REQUEST_RECEIVED); + threadFriendRequestDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.REQUEST_RECEIVED); + messageFriendRequestDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_PENDING); } - } else if (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { + } else if (threadFriendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { // If the thread's friend request status is not `FRIENDS`, but we're receiving a message, // it must be a friend request accepted message. Declining a friend request doesn't send a message. - database.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); + threadFriendRequestDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); + // TODO: Update message friend request status // TODO: Send p2p details here } } @@ -1040,7 +1048,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { for (long timestamp : message.getTimestamps()) { Log.i(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp)); DatabaseFactory.getMmsSmsDatabase(context) - .incrementDeliveryReceiptCount(new SyncMessageId(Address.fromExternal(context, content.getSender()), timestamp), System.currentTimeMillis()); + .incrementDeliveryReceiptCount(new SyncMessageId(Address.fromSerialized(content.getSender()), timestamp), System.currentTimeMillis()); } } @@ -1053,7 +1061,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Log.i(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp)); DatabaseFactory.getMmsSmsDatabase(context) - .incrementReadReceiptCount(new SyncMessageId(Address.fromExternal(context, content.getSender()), timestamp), content.getTimestamp()); + .incrementReadReceiptCount(new SyncMessageId(Address.fromSerialized(content.getSender()), timestamp), content.getTimestamp()); } } } @@ -1065,12 +1073,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType { return; } - Recipient author = Recipient.from(context, Address.fromExternal(context, content.getSender()), false); + Recipient author = Recipient.from(context, Address.fromSerialized(content.getSender()), false); long threadId; if (typingMessage.getGroupId().isPresent()) { - Address groupAddress = Address.fromExternal(context, GroupUtil.getEncodedId(typingMessage.getGroupId().get(), false)); + Address groupAddress = Address.fromSerialized(GroupUtil.getEncodedId(typingMessage.getGroupId().get(), false)); Recipient groupRecipient = Recipient.from(context, groupAddress, false); threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient); @@ -1105,7 +1113,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { return Optional.absent(); } - Address author = Address.fromExternal(context, quote.get().getAuthor().getNumber()); + Address author = Address.fromSerialized(quote.get().getAuthor().getNumber()); MessageRecord message = DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(quote.get().getId(), author); if (message != null) { @@ -1173,7 +1181,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private Optional insertPlaceholder(@NonNull String sender, int senderDevice, long timestamp) { SmsDatabase database = DatabaseFactory.getSmsDatabase(context); - IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromExternal(context, sender), + IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromSerialized(sender), senderDevice, timestamp, "", Optional.absent(), 0, false); @@ -1183,9 +1191,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private Recipient getSyncMessageDestination(SentTranscriptMessage message) { if (message.getMessage().getGroupInfo().isPresent()) { - return Recipient.from(context, Address.fromExternal(context, GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false); + return Recipient.from(context, Address.fromSerialized(GroupUtil.getEncodedId(message.getMessage().getGroupInfo().get().getGroupId(), false)), false); } else { - return Recipient.from(context, Address.fromExternal(context, message.getDestination().get()), false); + return Recipient.from(context, Address.fromSerialized(message.getDestination().get()), false); } } diff --git a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt index abc716364b..10a07bdf72 100644 --- a/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt +++ b/src/org/thoughtcrime/securesms/loki/FriendRequestView.kt @@ -9,14 +9,12 @@ import android.widget.LinearLayout import android.widget.TextView import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.database.DatabaseFactory -import org.thoughtcrime.securesms.sms.IncomingTextMessage -import org.thoughtcrime.securesms.sms.OutgoingTextMessage +import org.thoughtcrime.securesms.database.model.MessageRecord import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { private var isUISetUp = false - private var message: Any? = null - private var messageID: Long? = null + private var message: MessageRecord? = null var delegate: FriendRequestViewDelegate? = null // region Components @@ -46,9 +44,8 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In // endregion // region Updating - fun update(message: Any, messageID: Long) { + fun update(message: MessageRecord) { this.message = message - this.messageID = messageID setUpUIIfNeeded() updateUI() } @@ -59,7 +56,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In orientation = VERTICAL addView(topSpacer) addView(label) - if (message is IncomingTextMessage) { + if (!message!!.isOutgoing) { fun button(): Button { val result = Button(context) result.setBackgroundColor(resources.getColorWithID(R.color.transparent, context.theme)) @@ -90,9 +87,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In private fun updateUI() { val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) - if (message is IncomingTextMessage) { - val message = this.message as IncomingTextMessage - val friendRequestStatus = database.getFriendRequestStatus(messageID!!) + val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message!!.threadId)!!.address.toString() + if (!message!!.isOutgoing) { + val friendRequestStatus = database.getFriendRequestStatus(message!!.id) buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE val formatID = when (friendRequestStatus) { LokiMessageFriendRequestStatus.NONE, LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED -> throw IllegalStateException() @@ -101,11 +98,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In LokiMessageFriendRequestStatus.REQUEST_REJECTED -> R.string.view_friend_request_incoming_declined_message LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_incoming_expired_message } - val contactID = message.sender.toString() label.text = resources.getString(formatID, contactID) } else { - val message = this.message as OutgoingTextMessage - val friendRequestStatus = database.getFriendRequestStatus(messageID!!) + val friendRequestStatus = database.getFriendRequestStatus(message!!.id) buttonLinearLayout.visibility = View.GONE val formatID = when (friendRequestStatus) { LokiMessageFriendRequestStatus.NONE -> throw IllegalStateException() @@ -116,8 +111,6 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message } if (formatID != null) { - val threadID = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageID!!) - val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)!!.address.toString() label.text = resources.getString(formatID, contactID) } label.visibility = if (formatID != null) View.VISIBLE else View.GONE @@ -128,17 +121,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In // region Interaction private fun accept() { - val message = this.message as IncomingTextMessage val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) - database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED) - delegate?.acceptFriendRequest(message) + database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED) + delegate?.acceptFriendRequest(message!!) } private fun reject() { - val message = this.message as IncomingTextMessage val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) - database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_REJECTED) - delegate?.rejectFriendRequest(message) + database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_REJECTED) + delegate?.rejectFriendRequest(message!!) } // endregion } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/FriendRequestViewDelegate.kt b/src/org/thoughtcrime/securesms/loki/FriendRequestViewDelegate.kt index 1fe8168733..d3bcb475f8 100644 --- a/src/org/thoughtcrime/securesms/loki/FriendRequestViewDelegate.kt +++ b/src/org/thoughtcrime/securesms/loki/FriendRequestViewDelegate.kt @@ -1,16 +1,16 @@ package org.thoughtcrime.securesms.loki -import org.thoughtcrime.securesms.sms.IncomingTextMessage +import org.thoughtcrime.securesms.database.model.MessageRecord interface FriendRequestViewDelegate { /** * Implementations of this method should update the thread's friend request status * and send a friend request accepted message. */ - fun acceptFriendRequest(friendRequest: IncomingTextMessage) + fun acceptFriendRequest(friendRequest: MessageRecord) /** * Implementations of this method should update the thread's friend request status * and remove the pre keys associated with the contact. */ - fun rejectFriendRequest(friendRequest: IncomingTextMessage) + fun rejectFriendRequest(friendRequest: MessageRecord) } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java index 256a93b32a..cfafcb7132 100644 --- a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java +++ b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java @@ -46,7 +46,7 @@ public class IncomingTextMessage implements Parcelable { public IncomingTextMessage(@NonNull Context context, @NonNull SmsMessage message, int subscriptionId) { this.message = message.getDisplayMessageBody(); - this.sender = Address.fromExternal(context, message.getDisplayOriginatingAddress()); + this.sender = Address.fromSerialized(message.getDisplayOriginatingAddress()); this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID; this.protocol = message.getProtocolIdentifier(); this.serviceCenterAddress = message.getServiceCenterAddress();