mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Debug friend request logic
This commit is contained in:
parent
232faba39f
commit
1a7e0562bb
@ -41,141 +41,157 @@
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/body_bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/message_bubble_edge_margin"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toEndOf="@id/contact_photo_container"
|
||||
android:orientation="vertical"
|
||||
android:layout_toStartOf="@+id/indicators_parent"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false"
|
||||
android:background="@color/white"
|
||||
tools:backgroundTint="@color/conversation_blue">
|
||||
android:clipChildren="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/group_sender_holder"
|
||||
android:id="@+id/body_bubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
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">
|
||||
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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/group_message_sender"
|
||||
<LinearLayout
|
||||
android:id="@+id/group_sender_holder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4sp"
|
||||
style="@style/Signal.Text.Preview"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="?conversation_item_received_text_primary_color"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
tools:visibility="visible"
|
||||
tools:text="+14152222222"/>
|
||||
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">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/group_message_sender_profile"
|
||||
<TextView
|
||||
android:id="@+id/group_message_sender"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4sp"
|
||||
style="@style/Signal.Text.Preview"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textColor="?conversation_item_received_text_primary_color"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
tools:visibility="visible"
|
||||
tools:text="+14152222222"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/group_message_sender_profile"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="4sp"
|
||||
android:paddingEnd="4sp"
|
||||
style="@style/Signal.Text.Preview"
|
||||
android:fontFamily="sans-serif-regular"
|
||||
android:textColor="?conversation_item_received_text_primary_color"
|
||||
android:textStyle="italic"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
tools:text="~Clement Duval"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.QuoteView
|
||||
android:id="@+id/quote_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="4sp"
|
||||
android:paddingEnd="4sp"
|
||||
style="@style/Signal.Text.Preview"
|
||||
android:fontFamily="sans-serif-regular"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:visibility="gone"
|
||||
app:message_type="incoming"
|
||||
app:quote_colorPrimary="?attr/conversation_item_quote_text_color"
|
||||
app:quote_colorSecondary="?attr/conversation_item_quote_text_color"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/shared_contact_view_stub"
|
||||
android:layout="@layout/conversation_item_received_shared_contact"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/image_view_stub"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout="@layout/conversation_item_received_thumbnail" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/link_preview_stub"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout="@layout/conversation_item_received_link_preview" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/audio_view_stub"
|
||||
android:layout="@layout/conversation_item_received_audio"
|
||||
android:layout_width="210dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/document_view_stub"
|
||||
android:layout="@layout/conversation_item_received_document"
|
||||
android:layout_width="210dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/conversation_item_body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:textColor="?conversation_item_received_text_primary_color"
|
||||
android:textStyle="italic"
|
||||
android:maxLines="1"
|
||||
android:textColorLink="?conversation_item_received_text_primary_color"
|
||||
android:ellipsize="end"
|
||||
tools:text="~Clement Duval"/>
|
||||
app:scaleEmojis="true"
|
||||
app:emoji_maxLength="1000"
|
||||
tools:text="Mango pickle lorem ipsum"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/conversation_item_footer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="-4dp"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_bottom_padding"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:alpha="0.7"
|
||||
app:footer_text_color="?conversation_item_received_text_secondary_color"
|
||||
app:footer_icon_color="?conversation_item_received_text_secondary_color"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.QuoteView
|
||||
android:id="@+id/quote_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:visibility="gone"
|
||||
app:message_type="incoming"
|
||||
app:quote_colorPrimary="?attr/conversation_item_quote_text_color"
|
||||
app:quote_colorSecondary="?attr/conversation_item_quote_text_color"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/shared_contact_view_stub"
|
||||
android:layout="@layout/conversation_item_received_shared_contact"
|
||||
android:layout_width="@dimen/media_bubble_default_dimens"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/image_view_stub"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout="@layout/conversation_item_received_thumbnail" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/link_preview_stub"
|
||||
<org.thoughtcrime.securesms.loki.FriendRequestView
|
||||
android:id="@+id/friend_request_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout="@layout/conversation_item_received_link_preview" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/audio_view_stub"
|
||||
android:layout="@layout/conversation_item_received_audio"
|
||||
android:layout_width="210dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/document_view_stub"
|
||||
android:layout="@layout/conversation_item_received_document"
|
||||
android:layout_width="210dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/conversation_item_body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/message_bubble_top_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_collapsed_footer_padding"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:textColor="?conversation_item_received_text_primary_color"
|
||||
android:textColorLink="?conversation_item_received_text_primary_color"
|
||||
android:ellipsize="end"
|
||||
app:scaleEmojis="true"
|
||||
app:emoji_maxLength="1000"
|
||||
tools:text="Mango pickle lorem ipsum"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/conversation_item_footer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="-4dp"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_bottom_padding"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:alpha="0.7"
|
||||
app:footer_text_color="?conversation_item_received_text_secondary_color"
|
||||
app:footer_icon_color="?conversation_item_received_text_secondary_color"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Long> 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<ReadMessage> readMessages, long envelopeTimestamp)
|
||||
{
|
||||
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>> expiringMedia = DatabaseFactory.getMmsDatabase(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.fromSerialized(readMessage.getSender()), readMessage.getTimestamp()), envelopeTimestamp);
|
||||
|
||||
for (Pair<Long, Long> expiringMessage : expiringText) {
|
||||
ApplicationContext.getInstance(context)
|
||||
@ -669,7 +672,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Optional<QuoteModel> quote = getValidatedQuote(message.getQuote());
|
||||
Optional<List<Contact>> sharedContacts = getContacts(message.getSharedContacts());
|
||||
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.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<InsertResult> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
@ -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)
|
||||
}
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user