Debug friend request logic

This commit is contained in:
Niels Andriesse 2019-06-27 16:03:05 +10:00
parent 232faba39f
commit 1a7e0562bb
7 changed files with 202 additions and 174 deletions

View File

@ -40,6 +40,15 @@
</FrameLayout> </FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toStartOf="@+id/indicators_parent"
android:layout_alignWithParentIfMissing="true"
android:clipToPadding="false"
android:clipChildren="false">
<LinearLayout <LinearLayout
android:id="@+id/body_bubble" android:id="@+id/body_bubble"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -179,6 +188,13 @@
</LinearLayout> </LinearLayout>
<org.thoughtcrime.securesms.loki.FriendRequestView
android:id="@+id/friend_request_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<org.thoughtcrime.securesms.components.AlertView <org.thoughtcrime.securesms.components.AlertView
android:id="@+id/indicators_parent" android:id="@+id/indicators_parent"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -80,7 +80,6 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.database.model.Quote; 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.AttachmentDownloadJob;
import org.thoughtcrime.securesms.jobs.MmsDownloadJob; import org.thoughtcrime.securesms.jobs.MmsDownloadJob;
import org.thoughtcrime.securesms.jobs.MmsSendJob; 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.mms.TextSlide;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.LongClickCopySpan; import org.thoughtcrime.securesms.util.LongClickCopySpan;
@ -790,8 +788,7 @@ public class ConversationItem extends LinearLayout
} }
private void setFriendRequestView(@NonNull MessageRecord record) { private void setFriendRequestView(@NonNull MessageRecord record) {
OutgoingTextMessage message = OutgoingTextMessage.from((SmsMessageRecord)record); friendRequestView.update(record);
friendRequestView.update(message, record.id);
} }
private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) { private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) {

View File

@ -178,6 +178,22 @@ public class SmsDatabase extends MessagingDatabase {
return 0; 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) { public void markAsEndSession(long id) {
updateTypeBitmask(id, Types.KEY_EXCHANGE_MASK, Types.END_SESSION_BIT); updateTypeBitmask(id, Types.KEY_EXCHANGE_MASK, Types.END_SESSION_BIT);
} }

View File

@ -62,6 +62,7 @@ import org.thoughtcrime.securesms.linkpreview.Link;
import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil; import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase; import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase; import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
import org.thoughtcrime.securesms.mms.IncomingMediaMessage; 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.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher; 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.LokiServiceMessage;
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
@ -135,6 +137,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private long smsMessageId; private long smsMessageId;
@Inject SignalServiceMessageSender messageSender; @Inject SignalServiceMessageSender messageSender;
private Address author;
public PushDecryptJob(Context context) { public PushDecryptJob(Context context) {
this(context, -1); this(context, -1);
@ -276,8 +279,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
else if (isMediaMessage) handleMediaMessage(content, message, smsMessageId); else if (isMediaMessage) handleMediaMessage(content, message, smsMessageId);
else if (message.getBody().isPresent()) { else if (message.getBody().isPresent()) {
// Loki - Handle friend request logic // Loki - Handle friend request logic
handleFriendRequestIfNeeded(envelope, content, message);
handleTextMessage(content, message, smsMessageId); handleTextMessage(content, message, smsMessageId);
handleFriendRequestIfNeeded(envelope, content, message);
} }
if (message.getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(GroupUtil.getEncodedId(message.getGroupInfo().get().getGroupId(), false))) { 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..."); 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()) { if (envelope.isPreKeySignalMessage()) {
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob()); 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 intent = new Intent(context, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL); intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); 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_REMOTE_DESCRIPTION, message.getDescription());
intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, content.getTimestamp()); 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 intent = new Intent(context, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_RESPONSE_MESSAGE); intent.setAction(WebRtcCallService.ACTION_RESPONSE_MESSAGE);
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); 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_REMOTE_DESCRIPTION, message.getDescription());
context.startService(intent); context.startService(intent);
@ -398,7 +401,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
Intent intent = new Intent(context, WebRtcCallService.class); Intent intent = new Intent(context, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_ICE_MESSAGE); intent.setAction(WebRtcCallService.ACTION_ICE_MESSAGE);
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); 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, message.getSdp());
intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid()); intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_MID, message.getSdpMid());
intent.putExtra(WebRtcCallService.EXTRA_ICE_SDP_LINE_INDEX, message.getSdpMLineIndex()); 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 intent = new Intent(context, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_REMOTE_HANGUP); intent.setAction(WebRtcCallService.ACTION_REMOTE_HANGUP);
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); 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); context.startService(intent);
} }
@ -430,7 +433,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
Intent intent = new Intent(context, WebRtcCallService.class); Intent intent = new Intent(context, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_REMOTE_BUSY); intent.setAction(WebRtcCallService.ACTION_REMOTE_BUSY);
intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId()); 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); context.startService(intent);
} }
@ -439,7 +442,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
@NonNull Optional<Long> smsMessageId) @NonNull Optional<Long> smsMessageId)
{ {
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); 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.getSenderDevice(),
content.getTimestamp(), content.getTimestamp(),
"", Optional.absent(), 0, "", Optional.absent(), 0,
@ -523,7 +526,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
try { try {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context); MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
Recipient recipient = getMessageDestination(content, message); 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.getTimestamp(), -1,
message.getExpiresInSeconds() * 1000L, true, message.getExpiresInSeconds() * 1000L, true,
content.isNeedsReceipt(), content.isNeedsReceipt(),
@ -579,7 +582,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (message.getMessage().getProfileKey().isPresent()) { if (message.getMessage().getProfileKey().isPresent()) {
Recipient recipient = null; 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); 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<ReadMessage> readMessages, long envelopeTimestamp) private void handleSynchronizeReadMessage(@NonNull List<ReadMessage> readMessages, long envelopeTimestamp)
{ {
for (ReadMessage readMessage : readMessages) { for (ReadMessage readMessage : readMessages) {
List<Pair<Long, Long>> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); List<Pair<Long, Long>> expiringText = DatabaseFactory.getSmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromSerialized(readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp);
List<Pair<Long, Long>> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromExternal(context, readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp); List<Pair<Long, Long>> expiringMedia = DatabaseFactory.getMmsDatabase(context).setTimestampRead(new SyncMessageId(Address.fromSerialized(readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp);
for (Pair<Long, Long> expiringMessage : expiringText) { for (Pair<Long, Long> expiringMessage : expiringText) {
ApplicationContext.getInstance(context) ApplicationContext.getInstance(context)
@ -669,7 +672,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
Optional<QuoteModel> quote = getValidatedQuote(message.getQuote()); Optional<QuoteModel> quote = getValidatedQuote(message.getQuote());
Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts()); Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts());
Optional<List<LinkPreview>> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or("")); Optional<List<LinkPreview>> 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.getTimestamp(), -1,
message.getExpiresInSeconds() * 1000L, false, message.getExpiresInSeconds() * 1000L, false,
content.isNeedsReceipt(), 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) { private void handleFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) {
Recipient recipient = getMessageDestination(content, message); Recipient recipient = getMessageDestination(content, message);
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient); long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient);
LokiThreadFriendRequestDatabase database = DatabaseFactory.getLokiThreadFriendRequestDatabase(context); LokiThreadFriendRequestDatabase threadFriendRequestDatabase = DatabaseFactory.getLokiThreadFriendRequestDatabase(context);
LokiThreadFriendRequestStatus friendRequestStatus = database.getFriendRequestStatus(threadID); LokiThreadFriendRequestStatus threadFriendRequestStatus = threadFriendRequestDatabase.getFriendRequestStatus(threadID);
LokiMessageFriendRequestDatabase messageFriendRequestDatabase = DatabaseFactory.getLokiMessageFriendRequestDatabase(context);
long messageID = DatabaseFactory.getSmsDatabase(context).getLastMessageIDForThread(threadID);
if (envelope.isFriendRequest()) { 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 // 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 // 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 // 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`, // 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 // we can end up in a deadlock where both users' threads' friend request statuses are
// `REQUEST_SENT`. // `REQUEST_SENT`.
database.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS); threadFriendRequestDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
// TODO: Update message friend request status
// Accept the friend request // Accept the friend request
sendEmptyMessage(envelope.getSource()); 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 // 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 // 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 // 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. Alice's thread's friend request status is reset to
// `REQUEST_RECEIVED`. // `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, // 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. // 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 // TODO: Send p2p details here
} }
} }
@ -1040,7 +1048,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
for (long timestamp : message.getTimestamps()) { for (long timestamp : message.getTimestamps()) {
Log.i(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp)); Log.i(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp));
DatabaseFactory.getMmsSmsDatabase(context) 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)); Log.i(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp));
DatabaseFactory.getMmsSmsDatabase(context) 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; return;
} }
Recipient author = Recipient.from(context, Address.fromExternal(context, content.getSender()), false); Recipient author = Recipient.from(context, Address.fromSerialized(content.getSender()), false);
long threadId; long threadId;
if (typingMessage.getGroupId().isPresent()) { 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); Recipient groupRecipient = Recipient.from(context, groupAddress, false);
threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient); threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient);
@ -1105,7 +1113,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
return Optional.absent(); 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); MessageRecord message = DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(quote.get().getId(), author);
if (message != null) { if (message != null) {
@ -1173,7 +1181,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private Optional<InsertResult> insertPlaceholder(@NonNull String sender, int senderDevice, long timestamp) { private Optional<InsertResult> insertPlaceholder(@NonNull String sender, int senderDevice, long timestamp) {
SmsDatabase database = DatabaseFactory.getSmsDatabase(context); SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromExternal(context, sender), IncomingTextMessage textMessage = new IncomingTextMessage(Address.fromSerialized(sender),
senderDevice, timestamp, "", senderDevice, timestamp, "",
Optional.absent(), 0, false); Optional.absent(), 0, false);
@ -1183,9 +1191,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private Recipient getSyncMessageDestination(SentTranscriptMessage message) { private Recipient getSyncMessageDestination(SentTranscriptMessage message) {
if (message.getMessage().getGroupInfo().isPresent()) { 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 { } else {
return Recipient.from(context, Address.fromExternal(context, message.getDestination().get()), false); return Recipient.from(context, Address.fromSerialized(message.getDestination().get()), false);
} }
} }

View File

@ -9,14 +9,12 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.sms.IncomingTextMessage import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.sms.OutgoingTextMessage
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
private var isUISetUp = false private var isUISetUp = false
private var message: Any? = null private var message: MessageRecord? = null
private var messageID: Long? = null
var delegate: FriendRequestViewDelegate? = null var delegate: FriendRequestViewDelegate? = null
// region Components // region Components
@ -46,9 +44,8 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
// endregion // endregion
// region Updating // region Updating
fun update(message: Any, messageID: Long) { fun update(message: MessageRecord) {
this.message = message this.message = message
this.messageID = messageID
setUpUIIfNeeded() setUpUIIfNeeded()
updateUI() updateUI()
} }
@ -59,7 +56,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
orientation = VERTICAL orientation = VERTICAL
addView(topSpacer) addView(topSpacer)
addView(label) addView(label)
if (message is IncomingTextMessage) { if (!message!!.isOutgoing) {
fun button(): Button { fun button(): Button {
val result = Button(context) val result = Button(context)
result.setBackgroundColor(resources.getColorWithID(R.color.transparent, context.theme)) result.setBackgroundColor(resources.getColorWithID(R.color.transparent, context.theme))
@ -90,9 +87,9 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private fun updateUI() { private fun updateUI() {
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
if (message is IncomingTextMessage) { val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message!!.threadId)!!.address.toString()
val message = this.message as IncomingTextMessage if (!message!!.isOutgoing) {
val friendRequestStatus = database.getFriendRequestStatus(messageID!!) val friendRequestStatus = database.getFriendRequestStatus(message!!.id)
buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE
val formatID = when (friendRequestStatus) { val formatID = when (friendRequestStatus) {
LokiMessageFriendRequestStatus.NONE, LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED -> throw IllegalStateException() 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_REJECTED -> R.string.view_friend_request_incoming_declined_message
LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_incoming_expired_message LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_incoming_expired_message
} }
val contactID = message.sender.toString()
label.text = resources.getString(formatID, contactID) label.text = resources.getString(formatID, contactID)
} else { } else {
val message = this.message as OutgoingTextMessage val friendRequestStatus = database.getFriendRequestStatus(message!!.id)
val friendRequestStatus = database.getFriendRequestStatus(messageID!!)
buttonLinearLayout.visibility = View.GONE buttonLinearLayout.visibility = View.GONE
val formatID = when (friendRequestStatus) { val formatID = when (friendRequestStatus) {
LokiMessageFriendRequestStatus.NONE -> throw IllegalStateException() 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 LokiMessageFriendRequestStatus.REQUEST_EXPIRED -> R.string.view_friend_request_outgoing_expired_message
} }
if (formatID != null) { 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.text = resources.getString(formatID, contactID)
} }
label.visibility = if (formatID != null) View.VISIBLE else View.GONE label.visibility = if (formatID != null) View.VISIBLE else View.GONE
@ -128,17 +121,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
// region Interaction // region Interaction
private fun accept() { private fun accept() {
val message = this.message as IncomingTextMessage
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED) database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED)
delegate?.acceptFriendRequest(message) delegate?.acceptFriendRequest(message!!)
} }
private fun reject() { private fun reject() {
val message = this.message as IncomingTextMessage
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context) val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
database.setFriendRequestStatus(messageID!!, LokiMessageFriendRequestStatus.REQUEST_REJECTED) database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_REJECTED)
delegate?.rejectFriendRequest(message) delegate?.rejectFriendRequest(message!!)
} }
// endregion // endregion
} }

View File

@ -1,16 +1,16 @@
package org.thoughtcrime.securesms.loki package org.thoughtcrime.securesms.loki
import org.thoughtcrime.securesms.sms.IncomingTextMessage import org.thoughtcrime.securesms.database.model.MessageRecord
interface FriendRequestViewDelegate { interface FriendRequestViewDelegate {
/** /**
* Implementations of this method should update the thread's friend request status * Implementations of this method should update the thread's friend request status
* and send a friend request accepted message. * 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 * Implementations of this method should update the thread's friend request status
* and remove the pre keys associated with the contact. * and remove the pre keys associated with the contact.
*/ */
fun rejectFriendRequest(friendRequest: IncomingTextMessage) fun rejectFriendRequest(friendRequest: MessageRecord)
} }

View File

@ -46,7 +46,7 @@ public class IncomingTextMessage implements Parcelable {
public IncomingTextMessage(@NonNull Context context, @NonNull SmsMessage message, int subscriptionId) { public IncomingTextMessage(@NonNull Context context, @NonNull SmsMessage message, int subscriptionId) {
this.message = message.getDisplayMessageBody(); this.message = message.getDisplayMessageBody();
this.sender = Address.fromExternal(context, message.getDisplayOriginatingAddress()); this.sender = Address.fromSerialized(message.getDisplayOriginatingAddress());
this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID; this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
this.protocol = message.getProtocolIdentifier(); this.protocol = message.getProtocolIdentifier();
this.serviceCenterAddress = message.getServiceCenterAddress(); this.serviceCenterAddress = message.getServiceCenterAddress();