From 7ca845638305825699dadd30f44709447b37d36e Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Thu, 14 Jan 2021 10:28:07 +1100 Subject: [PATCH] WIP clean --- .../MmsNotificationAttachment.java | 1 + .../securesms/audio/AudioSlidePlayer.java | 2 +- .../securesms/backup/FullBackupExporter.kt | 2 +- .../securesms/backup/FullBackupImporter.kt | 2 +- .../components/ConversationItemThumbnail.java | 2 +- .../securesms/components/QuoteView.java | 2 +- .../components/TransferControlView.java | 2 +- .../securesms/contactshare/Contact.java | 6 +- .../contactshare/ContactModelMapper.java | 2 +- .../conversation/ConversationFragment.java | 2 +- .../securesms/database/EarlyReceiptCache.java | 3 +- .../securesms/database/MmsDatabase.java | 59 +- .../securesms/database/SmsDatabase.java | 18 +- .../database/loaders/PagingMediaLoader.java | 2 +- .../database/model/MediaMmsMessageRecord.java | 4 +- .../securesms/database/model/Sticker.java | 2 +- .../securesms/events/PartProgressEvent.java | 2 +- .../securesms/groups/GroupManager.java | 2 +- .../securesms/jobs/AttachmentDownloadJob.java | 4 +- .../securesms/jobs/AttachmentUploadJob.java | 4 +- .../securesms/jobs/MmsDownloadJob.java | 2 +- .../securesms/jobs/MmsSendJob.java | 2 +- .../securesms/jobs/PushDecryptJob.java | 2 +- .../securesms/jobs/PushGroupSendJob.java | 2 +- .../securesms/jobs/PushMediaSendJob.java | 2 +- .../securesms/jobs/PushSendJob.java | 2 +- .../thoughtcrime/securesms/jobs/SendJob.java | 2 +- .../securesms/linkpreview/LinkPreview.java | 4 +- .../linkpreview/LinkPreviewRepository.java | 2 +- .../api/PrepareAttachmentAudioExtrasJob.kt | 4 +- .../securesms/mms/AttachmentManager.java | 2 +- .../securesms/mms/AudioSlide.java | 2 +- .../securesms/mms/DocumentSlide.java | 2 +- .../thoughtcrime/securesms/mms/GifSlide.java | 2 +- .../securesms/mms/ImageSlide.java | 2 +- .../securesms/mms/IncomingMediaMessage.java | 12 +- .../securesms/mms/MediaConstraints.java | 2 +- .../thoughtcrime/securesms/mms/MmsSlide.java | 2 +- .../mms/OutgoingExpirationUpdateMessage.java | 2 +- .../mms/OutgoingGroupMediaMessage.java | 10 +- .../securesms/mms/OutgoingMediaMessage.java | 7 +- .../mms/OutgoingSecureMediaMessage.java | 7 +- .../securesms/mms/QuoteModel.java | 2 +- .../org/thoughtcrime/securesms/mms/Slide.java | 2 +- .../thoughtcrime/securesms/mms/SlideDeck.java | 2 +- .../securesms/mms/StickerSlide.java | 2 +- .../thoughtcrime/securesms/mms/TextSlide.java | 2 +- .../securesms/mms/VideoSlide.java | 2 +- .../securesms/recipients/Recipient.java | 732 ------------------ .../recipients/RecipientExporter.java | 46 -- .../RecipientFormattingException.java | 35 - .../recipients/RecipientModifiedListener.java | 6 - .../recipients/RecipientProvider.java | 241 ------ .../recipients/RecipientsFormatter.java | 76 -- .../securesms/sms/MessageSender.java | 2 +- .../securesms/util/AttachmentUtil.java | 2 +- .../securesms/util/MediaUtil.java | 2 +- .../securesms/video/VideoPlayer.java | 2 +- .../securesms/video/exo/PartDataSource.java | 2 +- .../session/libsession/utilities/GroupUtil.kt | 10 + .../org/session/libsession/utilities/Util.kt | 39 + 61 files changed, 164 insertions(+), 1242 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientExporter.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientFormattingException.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientModifiedListener.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientProvider.java delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientsFormatter.java diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/MmsNotificationAttachment.java b/app/src/main/java/org/thoughtcrime/securesms/attachments/MmsNotificationAttachment.java index 9eac9138a9..aa7e797214 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/MmsNotificationAttachment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/MmsNotificationAttachment.java @@ -6,6 +6,7 @@ import androidx.annotation.Nullable; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.MmsDatabase; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; public class MmsNotificationAttachment extends Attachment { diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java index 7e87f649f5..3d9b1946b9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java @@ -33,7 +33,7 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import org.jetbrains.annotations.NotNull; -import org.thoughtcrime.securesms.attachments.AttachmentServer; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentServer; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.util.ServiceUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt index d9e1c1a958..b647e70fc9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupExporter.kt @@ -10,7 +10,7 @@ import com.annimon.stream.function.Predicate import com.google.protobuf.ByteString import net.sqlcipher.database.SQLiteDatabase import org.greenrobot.eventbus.EventBus -import org.thoughtcrime.securesms.attachments.AttachmentId +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId import org.thoughtcrime.securesms.backup.BackupProtos.* import org.thoughtcrime.securesms.crypto.AttachmentSecret import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt index 18187a6b0b..3ccf94f2a8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/FullBackupImporter.kt @@ -7,7 +7,7 @@ import android.net.Uri import androidx.annotation.WorkerThread import net.sqlcipher.database.SQLiteDatabase import org.greenrobot.eventbus.EventBus -import org.thoughtcrime.securesms.attachments.AttachmentId +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId import org.thoughtcrime.securesms.backup.BackupProtos.* import org.thoughtcrime.securesms.crypto.AttachmentSecret import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ConversationItemThumbnail.java b/app/src/main/java/org/thoughtcrime/securesms/components/ConversationItemThumbnail.java index ba86eb8993..ac84030b1e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ConversationItemThumbnail.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ConversationItemThumbnail.java @@ -12,7 +12,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideClickListener; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/QuoteView.java b/app/src/main/java/org/thoughtcrime/securesms/components/QuoteView.java index 9b5222612a..834224068f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/QuoteView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/QuoteView.java @@ -21,7 +21,7 @@ import androidx.annotation.RequiresApi; import com.annimon.stream.Stream; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java b/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java index 843ebc9ee7..ffdd17a43a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/TransferControlView.java @@ -16,7 +16,7 @@ import com.pnikosis.materialishprogress.ProgressWheel; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.events.PartProgressEvent; import org.thoughtcrime.securesms.mms.Slide; diff --git a/app/src/main/java/org/thoughtcrime/securesms/contactshare/Contact.java b/app/src/main/java/org/thoughtcrime/securesms/contactshare/Contact.java index aad4ade1ce..b3bebdab5a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contactshare/Contact.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contactshare/Contact.java @@ -11,9 +11,9 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.AttachmentId; -import org.thoughtcrime.securesms.attachments.UriAttachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.util.JsonUtils; import org.thoughtcrime.securesms.util.MediaUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/contactshare/ContactModelMapper.java b/app/src/main/java/org/thoughtcrime/securesms/contactshare/ContactModelMapper.java index b1b00bd8ac..7db10dcfdf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contactshare/ContactModelMapper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contactshare/ContactModelMapper.java @@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.contactshare; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.PointerAttachment; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.messages.shared.SharedContact; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 8c99955377..ba85cce4dc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -61,7 +61,7 @@ import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.MessageDetailsActivity; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.ShareActivity; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.components.ConversationTypingView; import org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager; import org.thoughtcrime.securesms.conversation.ConversationAdapter.HeaderViewHolder; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/EarlyReceiptCache.java b/app/src/main/java/org/thoughtcrime/securesms/database/EarlyReceiptCache.java index d29eee9ec4..595cdf51a1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/EarlyReceiptCache.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/EarlyReceiptCache.java @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.database; -import org.thoughtcrime.securesms.logging.Log; +import org.session.libsignal.libsignal.logging.Log; +import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.util.LRUCache; import java.util.HashMap; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java index 1c2657bc39..683c515002 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -37,11 +37,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.AttachmentId; -import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.attachments.MmsNotificationAttachment; -import org.thoughtcrime.securesms.contactshare.Contact; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList; import org.thoughtcrime.securesms.database.documents.NetworkFailure; @@ -52,21 +48,28 @@ import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord; import org.thoughtcrime.securesms.database.model.Quote; import org.thoughtcrime.securesms.jobs.TrimThreadJob; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; -import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.IncomingMediaMessage; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage; import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage; import org.thoughtcrime.securesms.mms.OutgoingMediaMessage; import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage; -import org.thoughtcrime.securesms.mms.QuoteModel; import org.thoughtcrime.securesms.mms.SlideDeck; + +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel; +import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.RecipientFormattingException; -import org.thoughtcrime.securesms.util.JsonUtils; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; +import org.session.libsession.utilities.JsonUtils; +import org.session.libsession.utilities.TextSecurePreferences; +import org.session.libsession.utilities.Util; + +import org.session.libsignal.libsignal.logging.Log; import org.session.libsignal.libsignal.util.guava.Optional; import java.io.Closeable; @@ -267,7 +270,7 @@ public class MmsDatabase extends MessagingDatabase { while (cursor.moveToNext()) { if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)))) { - Address theirAddress = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); + Address theirAddress = Address.Companion.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); Address ourAddress = messageId.getAddress(); String columnName = deliveryReceipt ? DELIVERY_RECEIPT_COUNT : READ_RECEIPT_COUNT; @@ -332,7 +335,7 @@ public class MmsDatabase extends MessagingDatabase { String fromString = notification.getFrom() != null && notification.getFrom().getTextString() != null ? Util.toIsoString(notification.getFrom().getTextString()) : ""; - Recipient recipient = Recipient.from(context, Address.fromExternal(context, fromString), false); + Recipient recipient = Recipient.from(context, Address.Companion.fromExternal(context, fromString), false); return DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(recipient); } @@ -499,7 +502,7 @@ public class MmsDatabase extends MessagingDatabase { while(cursor != null && cursor.moveToNext()) { if (Types.isSecureType(cursor.getLong(3))) { - SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), cursor.getLong(2)); + SyncMessageId syncMessageId = new SyncMessageId(Address.Companion.fromSerialized(cursor.getString(1)), cursor.getLong(2)); ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), cursor.getLong(4), cursor.getLong(5), true); result.add(new MarkedMessageInfo(syncMessageId, expirationInfo)); @@ -528,7 +531,7 @@ public class MmsDatabase extends MessagingDatabase { cursor = database.query(TABLE_NAME, new String[] {ID, THREAD_ID, MESSAGE_BOX, EXPIRES_IN, EXPIRE_STARTED, ADDRESS}, DATE_SENT + " = ?", new String[] {String.valueOf(messageId.getTimetamp())}, null, null, null, null); while (cursor.moveToNext()) { - Address theirAddress = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); + Address theirAddress = Address.Companion.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); Address ourAddress = messageId.getAddress(); if (ourAddress.equals(theirAddress) || theirAddress.isGroup()) { @@ -641,13 +644,13 @@ public class MmsDatabase extends MessagingDatabase { .filterNot(previewAttachments::contains) .map(a -> (Attachment)a).toList(); - Recipient recipient = Recipient.from(context, Address.fromSerialized(address), false); + Recipient recipient = Recipient.from(context, Address.Companion.fromSerialized(address), false); List networkFailures = new LinkedList<>(); List mismatches = new LinkedList<>(); QuoteModel quote = null; if (quoteId > 0 && (!TextUtils.isEmpty(quoteText) || !quoteAttachments.isEmpty())) { - quote = new QuoteModel(quoteId, Address.fromSerialized(quoteAuthor), quoteText, quoteMissing, quoteAttachments); + quote = new QuoteModel(quoteId, Address.Companion.fromSerialized(quoteAuthor), quoteText, quoteMissing, quoteAttachments); } if (!TextUtils.isEmpty(mismatchDocument)) { @@ -711,9 +714,9 @@ public class MmsDatabase extends MessagingDatabase { if (contact.getAvatar() != null && contact.getAvatar().getAttachmentId() != null) { DatabaseAttachment attachment = attachmentIdMap.get(contact.getAvatar().getAttachmentId()); - Avatar updatedAvatar = new Avatar(contact.getAvatar().getAttachmentId(), - attachment, - contact.getAvatar().isProfile()); + Contact.Avatar updatedAvatar = new Contact.Avatar(contact.getAvatar().getAttachmentId(), + attachment, + contact.getAvatar().isProfile()); contacts.add(new Contact(contact, updatedAvatar)); } else { contacts.add(contact); @@ -940,7 +943,7 @@ public class MmsDatabase extends MessagingDatabase { contentBuilder.add(MESSAGE_TYPE, notification.getMessageType()); if (notification.getFrom() != null) { - contentValues.put(ADDRESS, Address.fromExternal(context, Util.toIsoString(notification.getFrom().getTextString())).serialize()); + contentValues.put(ADDRESS, Address.Companion.fromExternal(context, Util.toIsoString(notification.getFrom().getTextString())).serialize()); } contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE); @@ -1022,7 +1025,7 @@ public class MmsDatabase extends MessagingDatabase { contentValues.put(QUOTE_ID, message.getOutgoingQuote().getId()); contentValues.put(QUOTE_AUTHOR, message.getOutgoingQuote().getAuthor().serialize()); contentValues.put(QUOTE_BODY, message.getOutgoingQuote().getText()); - contentValues.put(QUOTE_MISSING, message.getOutgoingQuote().isOriginalMissing() ? 1 : 0); + contentValues.put(QUOTE_MISSING, message.getOutgoingQuote().getMissing() ? 1 : 0); quoteAttachments.addAll(message.getOutgoingQuote().getAttachments()); } @@ -1152,9 +1155,7 @@ public class MmsDatabase extends MessagingDatabase { attachmentId = insertedAttachmentIds.get(contact.getAvatarAttachment()); } - Avatar updatedAvatar = new Avatar(attachmentId, - contact.getAvatarAttachment(), - contact.getAvatar() != null && contact.getAvatar().isProfile()); + Contact.Avatar updatedAvatar = new Contact.Avatar(attachmentId, contact.getAvatarAttachment(), contact.getAvatar() != null && contact.getAvatar().isProfile()); Contact updatedContact = new Contact(contact, updatedAvatar); sharedContactJson.put(new JSONObject(updatedContact.serialize())); @@ -1321,7 +1322,7 @@ public class MmsDatabase extends MessagingDatabase { private final int subscriptionId; MmsNotificationInfo(@Nullable String from, String contentLocation, String transactionId, int subscriptionId) { - this.from = from == null ? null : Address.fromSerialized(from); + this.from = from == null ? null : Address.Companion.fromSerialized(from); this.contentLocation = contentLocation; this.transactionId = transactionId; this.subscriptionId = subscriptionId; @@ -1373,7 +1374,7 @@ public class MmsDatabase extends MessagingDatabase { new Quote(message.getOutgoingQuote().getId(), message.getOutgoingQuote().getAuthor(), message.getOutgoingQuote().getText(), - message.getOutgoingQuote().isOriginalMissing(), + message.getOutgoingQuote().getMissing(), new SlideDeck(context, message.getOutgoingQuote().getAttachments())) : null, message.getSharedContacts(), message.getLinkPreviews(), false); @@ -1492,9 +1493,9 @@ public class MmsDatabase extends MessagingDatabase { Address address; if (TextUtils.isEmpty(serialized) || "insert-address-token".equals(serialized)) { - address = Address.UNKNOWN; + address = Address.Companion.getUNKNOWN(); } else { - address = Address.fromSerialized(serialized); + address = Address.Companion.fromSerialized(serialized); } return Recipient.from(context, address, true); @@ -1541,7 +1542,7 @@ public class MmsDatabase extends MessagingDatabase { SlideDeck quoteDeck = new SlideDeck(context, quoteAttachments); if (quoteId > 0 && !TextUtils.isEmpty(quoteAuthor)) { - return new Quote(quoteId, Address.fromExternal(context, quoteAuthor), quoteText, quoteMissing, quoteDeck); + return new Quote(quoteId, Address.Companion.fromExternal(context, quoteAuthor), quoteText, quoteMissing, quoteDeck); } else { return null; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java index 0ea70e5a41..77f957f47d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -30,6 +30,7 @@ import com.annimon.stream.Stream; import net.sqlcipher.database.SQLiteDatabase; import net.sqlcipher.database.SQLiteStatement; +import org.session.libsignal.libsignal.logging.Log; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchList; @@ -37,13 +38,14 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.jobs.TrimThreadJob; -import org.thoughtcrime.securesms.logging.Log; -import org.session.libsession.messaging.threads.recipients.Recipient; import org.thoughtcrime.securesms.sms.IncomingGroupMessage; import org.thoughtcrime.securesms.sms.IncomingTextMessage; import org.thoughtcrime.securesms.sms.OutgoingTextMessage; -import org.thoughtcrime.securesms.util.JsonUtils; -import org.thoughtcrime.securesms.util.TextSecurePreferences; + +import org.session.libsession.messaging.threads.Address; +import org.session.libsession.messaging.threads.recipients.Recipient; +import org.session.libsession.utilities.JsonUtils; +import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsignal.libsignal.util.guava.Optional; import java.io.IOException; @@ -374,7 +376,7 @@ public class SmsDatabase extends MessagingDatabase { while (cursor.moveToNext()) { if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(TYPE)))) { Address theirAddress = messageId.getAddress(); - Address ourAddress = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); + Address ourAddress = Address.Companion.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); String columnName = deliveryReceipt ? DELIVERY_RECEIPT_COUNT : READ_RECEIPT_COUNT; if (ourAddress.equals(theirAddress)) { @@ -415,7 +417,7 @@ public class SmsDatabase extends MessagingDatabase { while (cursor.moveToNext()) { Address theirAddress = messageId.getAddress(); - Address ourAddress = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); + Address ourAddress = Address.Companion.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS))); if (ourAddress.equals(theirAddress)) { long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID)); @@ -466,7 +468,7 @@ public class SmsDatabase extends MessagingDatabase { while (cursor != null && cursor.moveToNext()) { if (Types.isSecureType(cursor.getLong(3))) { - SyncMessageId syncMessageId = new SyncMessageId(Address.fromSerialized(cursor.getString(1)), cursor.getLong(2)); + SyncMessageId syncMessageId = new SyncMessageId(Address.Companion.fromSerialized(cursor.getString(1)), cursor.getLong(2)); ExpirationInfo expirationInfo = new ExpirationInfo(cursor.getLong(0), cursor.getLong(4), cursor.getLong(5), false); results.add(new MarkedMessageInfo(syncMessageId, expirationInfo)); @@ -923,7 +925,7 @@ public class SmsDatabase extends MessagingDatabase { public SmsMessageRecord getCurrent() { long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.ID)); - Address address = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS))); + Address address = Address.Companion.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS))); int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.ADDRESS_DEVICE_ID)); long type = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.TYPE)); long dateReceived = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.NORMALIZED_DATE_RECEIVED)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/loaders/PagingMediaLoader.java b/app/src/main/java/org/thoughtcrime/securesms/database/loaders/PagingMediaLoader.java index 4798ccf31d..f8e3fe882e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/loaders/PagingMediaLoader.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/loaders/PagingMediaLoader.java @@ -8,7 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.util.Pair; -import org.thoughtcrime.securesms.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.mms.PartAuthority; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java index 157e2eb1fd..6579da6a0d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java @@ -22,12 +22,12 @@ import androidx.annotation.Nullable; import android.text.SpannableString; import network.loki.messenger.R; -import org.thoughtcrime.securesms.contactshare.Contact; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase.Status; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.NetworkFailure; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.mms.SlideDeck; import org.session.libsession.messaging.threads.recipients.Recipient; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/Sticker.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/Sticker.java index 9ee97c131a..935d7e25c7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/Sticker.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/Sticker.java @@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.database.model; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; public class Sticker { diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/PartProgressEvent.java b/app/src/main/java/org/thoughtcrime/securesms/events/PartProgressEvent.java index b824ec16cf..1be748f54b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/PartProgressEvent.java +++ b/app/src/main/java/org/thoughtcrime/securesms/events/PartProgressEvent.java @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.events; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; public class PartProgressEvent { diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java index 20b9fdac2c..1febce5fd4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java @@ -9,7 +9,7 @@ import androidx.annotation.Nullable; import com.google.protobuf.ByteString; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.AttachmentDatabase; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java index 63eecd7796..a2c8a884ce 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java @@ -14,8 +14,8 @@ import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCo import org.session.libsignal.service.api.push.exceptions.PushNetworkException; import org.session.libsignal.service.loki.utilities.DownloadUtilities; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java index 8138f840ad..4a0d46fe4d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java @@ -3,8 +3,8 @@ package org.thoughtcrime.securesms.jobs; import androidx.annotation.NonNull; import org.greenrobot.eventbus.EventBus; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.attachments.PointerAttachment; import org.session.libsession.messaging.threads.Address; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java index 2a45ec75f1..1532b9bbf3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsDownloadJob.java @@ -11,7 +11,7 @@ import com.google.android.mms.pdu_alt.PduPart; import com.google.android.mms.pdu_alt.RetrieveConf; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.AttachmentDatabase; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java index ce0d7d688a..d33f3dd222 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java @@ -20,7 +20,7 @@ import com.google.android.mms.smil.SmilHelper; import com.klinker.android.send_message.Utils; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsDatabase; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 128957b37e..7a93709098 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -27,7 +27,7 @@ import org.session.libsignal.metadata.ProtocolUntrustedIdentityException; import org.session.libsignal.metadata.SelfSendException; import org.session.libsignal.service.loki.api.crypto.SessionProtocol; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.attachments.PointerAttachment; import org.thoughtcrime.securesms.attachments.UriAttachment; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 5d2a0557a3..b1873a5bb1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -9,7 +9,7 @@ import com.annimon.stream.Collectors; import com.annimon.stream.Stream; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.session.libsession.messaging.threads.Address; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 8bc8088d4d..2290093e55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -7,7 +7,7 @@ import androidx.annotation.WorkerThread; import com.annimon.stream.Stream; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; import org.session.libsession.messaging.threads.Address; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java index f0bab80454..d60959a24f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -11,7 +11,7 @@ import com.annimon.stream.Stream; import org.greenrobot.eventbus.EventBus; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.TextSecureExpiredException; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.contactshare.Contact; import org.thoughtcrime.securesms.contactshare.ContactModelMapper; import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/SendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/SendJob.java index c755e2443c..31363c0234 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/SendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/SendJob.java @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.jobs; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.jobmanager.Job; diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreview.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreview.java index dc5bc8f3b6..bce458f70a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreview.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreview.java @@ -6,8 +6,8 @@ import androidx.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.util.JsonUtils; import org.session.libsignal.libsignal.util.guava.Optional; diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index 79d893833d..e13ede3155 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -13,7 +13,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.google.android.gms.common.util.IOUtils; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.dependencies.InjectableType; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PrepareAttachmentAudioExtrasJob.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PrepareAttachmentAudioExtrasJob.kt index bc7e6e0502..c3695e093a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PrepareAttachmentAudioExtrasJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PrepareAttachmentAudioExtrasJob.kt @@ -5,8 +5,8 @@ import android.os.Build import org.thoughtcrime.securesms.logging.Log import androidx.annotation.RequiresApi import org.greenrobot.eventbus.EventBus -import org.thoughtcrime.securesms.attachments.Attachment -import org.thoughtcrime.securesms.attachments.AttachmentId +import org.session.libsession.messaging.sending_receiving.attachments.Attachment +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId import org.thoughtcrime.securesms.attachments.DatabaseAttachmentAudioExtras import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobmanager.Data diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java index eb1a990b80..e52eefd4c4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -39,7 +39,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import org.thoughtcrime.securesms.MediaPreviewActivity; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.loki.views.MessageAudioView; import org.thoughtcrime.securesms.components.DocumentView; import org.thoughtcrime.securesms.components.RemovableEditableMediaView; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java index 546d3cae0b..42b9cb6f0c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java @@ -24,7 +24,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import network.loki.messenger.R; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.util.MediaUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/DocumentSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/DocumentSlide.java index 968e8dd441..50b3834d0b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/DocumentSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/DocumentSlide.java @@ -6,7 +6,7 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.ExternalStorageUtil; public class DocumentSlide extends Slide { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java index a0f1caaaee..9ee38cca0b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java @@ -4,7 +4,7 @@ import android.content.Context; import android.net.Uri; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.MediaUtil; public class GifSlide extends ImageSlide { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java index 0502171c21..1e8755ff11 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java @@ -24,7 +24,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import network.loki.messenger.R; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.MediaUtil; public class ImageSlide extends Slide { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java b/app/src/main/java/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java index e101c7c63a..49d6899d15 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/IncomingMediaMessage.java @@ -1,11 +1,11 @@ package org.thoughtcrime.securesms.mms; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.attachments.PointerAttachment; -import org.thoughtcrime.securesms.contactshare.Contact; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.PointerAttachment; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; import org.session.libsession.messaging.threads.Address; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; -import org.thoughtcrime.securesms.util.GroupUtil; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.utilities.GroupUtil; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.messages.SignalServiceAttachment; import org.session.libsignal.service.api.messages.SignalServiceGroup; @@ -79,7 +79,7 @@ public class IncomingMediaMessage { this.quote = quote.orNull(); this.unidentified = unidentified; - if (group.isPresent()) this.groupId = Address.fromSerialized(GroupUtil.getEncodedId(group.get())); + if (group.isPresent()) this.groupId = Address.Companion.fromSerialized(GroupUtil.INSTANCE.getEncodedId(group.get())); else this.groupId = null; this.attachments.addAll(PointerAttachment.forPointers(attachments)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java b/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java index 37ffb87e83..f65c51c844 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java @@ -7,7 +7,7 @@ import androidx.annotation.Nullable; import org.thoughtcrime.securesms.logging.Log; import android.util.Pair; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; import org.thoughtcrime.securesms.util.BitmapDecodingException; import org.thoughtcrime.securesms.util.BitmapUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/MmsSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/MmsSlide.java index 08593a206f..967d49c09b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/MmsSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/MmsSlide.java @@ -4,7 +4,7 @@ package org.thoughtcrime.securesms.mms; import android.content.Context; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; public class MmsSlide extends ImageSlide { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingExpirationUpdateMessage.java b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingExpirationUpdateMessage.java index c48f751bbf..91fcab901d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingExpirationUpdateMessage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingExpirationUpdateMessage.java @@ -1,6 +1,6 @@ package org.thoughtcrime.securesms.mms; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.session.libsession.messaging.threads.recipients.Recipient; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingGroupMediaMessage.java b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingGroupMediaMessage.java index 442a207a39..05e1ebd1c3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingGroupMediaMessage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingGroupMediaMessage.java @@ -3,12 +3,14 @@ package org.thoughtcrime.securesms.mms; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.contactshare.Contact; import org.thoughtcrime.securesms.database.ThreadDatabase; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel; import org.session.libsession.messaging.threads.recipients.Recipient; -import org.thoughtcrime.securesms.util.Base64; +import org.session.libsession.utilities.Base64; + import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext; import java.io.IOException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java index 42275f8aaf..a5cc2608fd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingMediaMessage.java @@ -4,11 +4,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.text.TextUtils; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.contactshare.Contact; import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch; import org.thoughtcrime.securesms.database.documents.NetworkFailure; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel; import org.session.libsession.messaging.threads.recipients.Recipient; import java.util.LinkedList; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingSecureMediaMessage.java b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingSecureMediaMessage.java index a67a7e5968..599e4878be 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingSecureMediaMessage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/OutgoingSecureMediaMessage.java @@ -3,9 +3,10 @@ package org.thoughtcrime.securesms.mms; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.contactshare.Contact; -import org.thoughtcrime.securesms.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.contacts.Contact; +import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview; +import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel; import org.session.libsession.messaging.threads.recipients.Recipient; import java.util.Collections; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/QuoteModel.java b/app/src/main/java/org/thoughtcrime/securesms/mms/QuoteModel.java index d2ffb8bb80..1e02fc17ac 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/QuoteModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/QuoteModel.java @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.mms; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.threads.Address; import java.util.List; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.java index 62c23985af..c0e7803932 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/Slide.java @@ -22,7 +22,7 @@ import android.net.Uri; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.attachments.UriAttachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.stickers.StickerLocator; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/SlideDeck.java b/app/src/main/java/org/thoughtcrime/securesms/mms/SlideDeck.java index e4eb474dca..0b41342001 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/SlideDeck.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/SlideDeck.java @@ -22,7 +22,7 @@ import androidx.annotation.Nullable; import com.annimon.stream.Stream; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.util.guava.Optional; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java index 75baee0f35..34819bd1ad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java @@ -7,7 +7,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.stickers.StickerLocator; import org.thoughtcrime.securesms.util.MediaUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java index d3612143e9..38a3374a17 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java @@ -6,7 +6,7 @@ import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.MediaUtil; public class TextSlide extends Slide { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java index 3ab2375f7c..4b9c72abb3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java @@ -24,7 +24,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import network.loki.messenger.R; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.ResUtil; diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java deleted file mode 100644 index f6fdc531ad..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java +++ /dev/null @@ -1,732 +0,0 @@ -/* - * Copyright (C) 2011 Whisper Systems - * Copyright (C) 2013 - 2017 Open Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.recipients; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.Uri; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.annimon.stream.function.Consumer; - -import org.greenrobot.eventbus.EventBus; -import org.thoughtcrime.securesms.color.MaterialColor; -import org.thoughtcrime.securesms.contacts.avatars.ContactColors; -import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.GroupRecordContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.SystemContactPhoto; -import org.thoughtcrime.securesms.contacts.avatars.TransparentContactPhoto; -import org.session.libsession.messaging.threads.Address; -import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.database.GroupDatabase; -import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings; -import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState; -import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode; -import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState; -import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.utilities.ProfilePictureModifiedEvent; -import org.thoughtcrime.securesms.notifications.NotificationChannels; -import org.session.libsession.messaging.threads.recipients.RecipientProvider.RecipientDetails; -import org.thoughtcrime.securesms.util.FutureTaskListener; -import org.thoughtcrime.securesms.util.ListenableFutureTask; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; -import org.session.libsignal.libsignal.util.guava.Optional; -import org.session.libsignal.service.loki.protocol.shelved.multidevice.MultiDeviceProtocol; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.WeakHashMap; -import java.util.concurrent.ExecutionException; - -import network.loki.messenger.R; - -public class Recipient implements RecipientModifiedListener { - - private static final String TAG = Recipient.class.getSimpleName(); - private static final RecipientProvider provider = new RecipientProvider(); - - private final Set listeners = Collections.newSetFromMap(new WeakHashMap()); - - private final @NonNull Address address; - private final @NonNull List participants = new LinkedList<>(); - - private Context context; - private @Nullable String name; - private @Nullable String customLabel; - private boolean resolving; - private boolean isLocalNumber; - - private @Nullable Uri systemContactPhoto; - private @Nullable Long groupAvatarId; - private Uri contactUri; - private @Nullable Uri messageRingtone = null; - private @Nullable Uri callRingtone = null; - public long mutedUntil = 0; - private boolean blocked = false; - private VibrateState messageVibrate = VibrateState.DEFAULT; - private VibrateState callVibrate = VibrateState.DEFAULT; - private int expireMessages = 0; - private Optional defaultSubscriptionId = Optional.absent(); - private @NonNull RegisteredState registered = RegisteredState.UNKNOWN; - - private @Nullable MaterialColor color; - private @Nullable byte[] profileKey; - private @Nullable String profileName; - private @Nullable String profileAvatar; - private boolean profileSharing; - private String notificationChannel; - private boolean forceSmsSelection; - - private @NonNull UnidentifiedAccessMode unidentifiedAccessMode = UnidentifiedAccessMode.ENABLED; - - @SuppressWarnings("ConstantConditions") - public static @NonNull Recipient from(@NonNull Context context, @NonNull Address address, boolean asynchronous) { - if (address == null) throw new AssertionError(address); - return provider.getRecipient(context, address, Optional.absent(), Optional.absent(), asynchronous); - } - - @SuppressWarnings("ConstantConditions") - public static @NonNull Recipient from(@NonNull Context context, @NonNull Address address, @NonNull Optional settings, @NonNull Optional groupRecord, boolean asynchronous) { - if (address == null) throw new AssertionError(address); - return provider.getRecipient(context, address, settings, groupRecord, asynchronous); - } - - public static void applyCached(@NonNull Address address, Consumer consumer) { - Optional recipient = provider.getCached(address); - if (recipient.isPresent()) consumer.accept(recipient.get()); - } - - public static boolean removeCached(@NonNull Address address) { - return provider.removeCached(address); - } - - Recipient(@NonNull Context context, - @NonNull Address address, - @Nullable Recipient stale, - @NonNull Optional details, - @NonNull ListenableFutureTask future) - { - this.context = context; - this.address = address; - this.color = null; - this.resolving = true; - - if (stale != null) { - this.name = stale.name; - this.contactUri = stale.contactUri; - this.systemContactPhoto = stale.systemContactPhoto; - this.groupAvatarId = stale.groupAvatarId; - this.isLocalNumber = stale.isLocalNumber; - this.color = stale.color; - this.customLabel = stale.customLabel; - this.messageRingtone = stale.messageRingtone; - this.callRingtone = stale.callRingtone; - this.mutedUntil = stale.mutedUntil; - this.blocked = stale.blocked; - this.messageVibrate = stale.messageVibrate; - this.callVibrate = stale.callVibrate; - this.expireMessages = stale.expireMessages; - this.defaultSubscriptionId = stale.defaultSubscriptionId; - this.registered = stale.registered; - this.notificationChannel = stale.notificationChannel; - this.profileKey = stale.profileKey; - this.profileName = stale.profileName; - this.profileAvatar = stale.profileAvatar; - this.profileSharing = stale.profileSharing; - this.unidentifiedAccessMode = stale.unidentifiedAccessMode; - this.forceSmsSelection = stale.forceSmsSelection; - - this.participants.clear(); - this.participants.addAll(stale.participants); - } - - if (details.isPresent()) { - this.name = details.get().name; - this.systemContactPhoto = details.get().systemContactPhoto; - this.groupAvatarId = details.get().groupAvatarId; - this.isLocalNumber = details.get().isLocalNumber; - this.color = details.get().color; - this.messageRingtone = details.get().messageRingtone; - this.callRingtone = details.get().callRingtone; - this.mutedUntil = details.get().mutedUntil; - this.blocked = details.get().blocked; - this.messageVibrate = details.get().messageVibrateState; - this.callVibrate = details.get().callVibrateState; - this.expireMessages = details.get().expireMessages; - this.defaultSubscriptionId = details.get().defaultSubscriptionId; - this.registered = details.get().registered; - this.notificationChannel = details.get().notificationChannel; - this.profileKey = details.get().profileKey; - this.profileName = details.get().profileName; - this.profileAvatar = details.get().profileAvatar; - this.profileSharing = details.get().profileSharing; - this.unidentifiedAccessMode = details.get().unidentifiedAccessMode; - this.forceSmsSelection = details.get().forceSmsSelection; - - this.participants.clear(); - this.participants.addAll(details.get().participants); - } - - future.addListener(new FutureTaskListener() { - @Override - public void onSuccess(RecipientDetails result) { - if (result != null) { - synchronized (Recipient.this) { - Recipient.this.name = result.name; - Recipient.this.contactUri = result.contactUri; - Recipient.this.systemContactPhoto = result.systemContactPhoto; - Recipient.this.groupAvatarId = result.groupAvatarId; - Recipient.this.isLocalNumber = result.isLocalNumber; - Recipient.this.color = result.color; - Recipient.this.customLabel = result.customLabel; - Recipient.this.messageRingtone = result.messageRingtone; - Recipient.this.callRingtone = result.callRingtone; - Recipient.this.mutedUntil = result.mutedUntil; - Recipient.this.blocked = result.blocked; - Recipient.this.messageVibrate = result.messageVibrateState; - Recipient.this.callVibrate = result.callVibrateState; - Recipient.this.expireMessages = result.expireMessages; - Recipient.this.defaultSubscriptionId = result.defaultSubscriptionId; - Recipient.this.registered = result.registered; - Recipient.this.notificationChannel = result.notificationChannel; - Recipient.this.profileKey = result.profileKey; - Recipient.this.profileName = result.profileName; - Recipient.this.profileAvatar = result.profileAvatar; - Recipient.this.profileSharing = result.profileSharing; - Recipient.this.unidentifiedAccessMode = result.unidentifiedAccessMode; - Recipient.this.forceSmsSelection = result.forceSmsSelection; - - Recipient.this.participants.clear(); - Recipient.this.participants.addAll(result.participants); - Recipient.this.resolving = false; - - if (!listeners.isEmpty()) { - for (Recipient recipient : participants) recipient.addListener(Recipient.this); - } - - Recipient.this.notifyAll(); - } - - notifyListeners(); - } - } - - @Override - public void onFailure(ExecutionException error) { - Log.w(TAG, error); - } - }); - } - - Recipient(@NonNull Context context, @NonNull Address address, @NonNull RecipientDetails details) { - this.context = context; - this.address = address; - this.contactUri = details.contactUri; - this.name = details.name; - this.systemContactPhoto = details.systemContactPhoto; - this.groupAvatarId = details.groupAvatarId; - this.isLocalNumber = details.isLocalNumber; - this.color = details.color; - this.customLabel = details.customLabel; - this.messageRingtone = details.messageRingtone; - this.callRingtone = details.callRingtone; - this.mutedUntil = details.mutedUntil; - this.blocked = details.blocked; - this.messageVibrate = details.messageVibrateState; - this.callVibrate = details.callVibrateState; - this.expireMessages = details.expireMessages; - this.defaultSubscriptionId = details.defaultSubscriptionId; - this.registered = details.registered; - this.notificationChannel = details.notificationChannel; - this.profileKey = details.profileKey; - this.profileName = details.profileName; - this.profileAvatar = details.profileAvatar; - this.profileSharing = details.profileSharing; - this.unidentifiedAccessMode = details.unidentifiedAccessMode; - this.forceSmsSelection = details.forceSmsSelection; - - this.participants.addAll(details.participants); - this.resolving = false; - } - - public boolean isLocalNumber() { - return isLocalNumber; - } - - public boolean isUserMasterDevice() { - String userMasterDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - return userMasterDevice != null && userMasterDevice.equals(getAddress().serialize()); - } - - public synchronized @Nullable Uri getContactUri() { - return this.contactUri; - } - - public void setContactUri(@Nullable Uri contactUri) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(contactUri, this.contactUri)) { - this.contactUri = contactUri; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public synchronized @Nullable String getName() { - String displayName = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(this.address.toString()); - if (displayName != null) { return displayName; } - - if (this.name == null && isMmsGroupRecipient()) { - List names = new LinkedList<>(); - - for (Recipient recipient : participants) { - names.add(recipient.toShortString()); - } - - return Util.join(names, ", "); - } - - return this.name; - } - - public void setName(@Nullable String name) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(this.name, name)) { - this.name = name; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public synchronized @NonNull MaterialColor getColor() { - if (isGroupRecipient()) return MaterialColor.GROUP; - else if (color != null) return color; - else if (name != null) return ContactColors.generateFor(name); - else return ContactColors.UNKNOWN_COLOR; - } - - public void setColor(@NonNull MaterialColor color) { - synchronized (this) { - this.color = color; - } - - notifyListeners(); - } - - public @NonNull Address getAddress() { - return address; - } - - public synchronized @Nullable String getCustomLabel() { - return customLabel; - } - - public void setCustomLabel(@Nullable String customLabel) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(customLabel, this.customLabel)) { - this.customLabel = customLabel; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public synchronized Optional getDefaultSubscriptionId() { - return defaultSubscriptionId; - } - - public void setDefaultSubscriptionId(Optional defaultSubscriptionId) { - synchronized (this) { - this.defaultSubscriptionId = defaultSubscriptionId; - } - - notifyListeners(); - } - - public synchronized @Nullable String getProfileName() { - return profileName; - } - - public void setProfileName(@Nullable String profileName) { - synchronized (this) { - this.profileName = profileName; - } - - notifyListeners(); - } - - public synchronized @Nullable String getProfileAvatar() { - return profileAvatar; - } - - public void setProfileAvatar(@Nullable String profileAvatar) { - synchronized (this) { - this.profileAvatar = profileAvatar; - } - - notifyListeners(); - EventBus.getDefault().post(new ProfilePictureModifiedEvent(this)); - } - - public synchronized boolean isProfileSharing() { - return profileSharing; - } - - public void setProfileSharing(boolean value) { - synchronized (this) { - this.profileSharing = value; - } - - notifyListeners(); - } - - public boolean isGroupRecipient() { - return address.isGroup(); - } - - public boolean isOpenGroupRecipient() { - return address.isOpenGroup(); - } - - public boolean isMmsGroupRecipient() { - return address.isMmsGroup(); - } - - public boolean isPushGroupRecipient() { - return address.isGroup() && !address.isMmsGroup(); - } - - public @NonNull synchronized List getParticipants() { - return new LinkedList<>(participants); - } - - public void setParticipants(@NonNull List participants) { - synchronized (this) { - this.participants.clear(); - this.participants.addAll(participants); - } - - notifyListeners(); - } - - public synchronized void addListener(RecipientModifiedListener listener) { - if (listeners.isEmpty()) { - for (Recipient recipient : participants) recipient.addListener(this); - } - listeners.add(listener); - } - - public synchronized void removeListener(RecipientModifiedListener listener) { - listeners.remove(listener); - - if (listeners.isEmpty()) { - for (Recipient recipient : participants) recipient.removeListener(this); - } - } - - public synchronized String toShortString() { - String name = getName(); - return (name != null ? name : address.serialize()); - } - - public synchronized @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) { - return getFallbackContactPhoto().asDrawable(context, getColor().toAvatarColor(context), inverted); - } - - public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() { - // TODO: I believe this is now completely unused - if (isResolving()) return new TransparentContactPhoto(); - else if (isGroupRecipient()) return new GeneratedContactPhoto(name, R.drawable.ic_profile_default); - else { return new TransparentContactPhoto(); } - } - - public synchronized @Nullable ContactPhoto getContactPhoto() { - if (isLocalNumber) return new ProfileContactPhoto(address, String.valueOf(TextSecurePreferences.getProfileAvatarId(context))); - else if (isGroupRecipient() && groupAvatarId != null) return new GroupRecordContactPhoto(address, groupAvatarId); - else if (systemContactPhoto != null) return new SystemContactPhoto(address, systemContactPhoto, 0); - else if (profileAvatar != null) return new ProfileContactPhoto(address, profileAvatar); - else return null; - } - - public void setSystemContactPhoto(@Nullable Uri systemContactPhoto) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(systemContactPhoto, this.systemContactPhoto)) { - this.systemContactPhoto = systemContactPhoto; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public void setGroupAvatarId(@Nullable Long groupAvatarId) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(this.groupAvatarId, groupAvatarId)) { - this.groupAvatarId = groupAvatarId; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - @Nullable - public synchronized Long getGroupAvatarId() { - return groupAvatarId; - } - - public synchronized @Nullable Uri getMessageRingtone() { - if (messageRingtone != null && messageRingtone.getScheme() != null && messageRingtone.getScheme().startsWith("file")) { - return null; - } - - return messageRingtone; - } - - public void setMessageRingtone(@Nullable Uri ringtone) { - synchronized (this) { - this.messageRingtone = ringtone; - } - - notifyListeners(); - } - - public synchronized @Nullable Uri getCallRingtone() { - if (callRingtone != null && callRingtone.getScheme() != null && callRingtone.getScheme().startsWith("file")) { - return null; - } - - return callRingtone; - } - - public void setCallRingtone(@Nullable Uri ringtone) { - synchronized (this) { - this.callRingtone = ringtone; - } - - notifyListeners(); - } - - public synchronized boolean isMuted() { - return System.currentTimeMillis() <= mutedUntil; - } - - public void setMuted(long mutedUntil) { - synchronized (this) { - this.mutedUntil = mutedUntil; - } - - notifyListeners(); - } - - public synchronized boolean isBlocked() { - String masterPublicKey = MultiDeviceProtocol.shared.getMasterDevice(this.address.serialize()); - if (masterPublicKey != null) { - return Recipient.from(context, Address.fromSerialized(masterPublicKey), false).blocked; - } else { - return blocked; - } - } - - public void setBlocked(boolean blocked) { - synchronized (this) { - this.blocked = blocked; - } - - notifyListeners(); - } - - public synchronized VibrateState getMessageVibrate() { - return messageVibrate; - } - - public void setMessageVibrate(VibrateState vibrate) { - synchronized (this) { - this.messageVibrate = vibrate; - } - - notifyListeners(); - } - - public synchronized VibrateState getCallVibrate() { - return callVibrate; - } - - public void setCallVibrate(VibrateState vibrate) { - synchronized (this) { - this.callVibrate = vibrate; - } - - notifyListeners(); - } - - public synchronized int getExpireMessages() { - return expireMessages; - } - - public void setExpireMessages(int expireMessages) { - synchronized (this) { - this.expireMessages = expireMessages; - } - - notifyListeners(); - } - - public synchronized RegisteredState getRegistered() { - if (isPushGroupRecipient()) return RegisteredState.REGISTERED; - else if (isMmsGroupRecipient()) return RegisteredState.NOT_REGISTERED; - - return registered; - } - - public void setRegistered(@NonNull RegisteredState value) { - boolean notify = false; - - synchronized (this) { - if (this.registered != value) { - this.registered = value; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public synchronized @Nullable String getNotificationChannel() { - return !NotificationChannels.supported() ? null : notificationChannel; - } - - public void setNotificationChannel(@Nullable String value) { - boolean notify = false; - - synchronized (this) { - if (!Util.equals(this.notificationChannel, value)) { - this.notificationChannel = value; - notify = true; - } - } - - if (notify) notifyListeners(); - } - - public boolean isForceSmsSelection() { - return forceSmsSelection; - } - - public void setForceSmsSelection(boolean value) { - synchronized (this) { - this.forceSmsSelection = value; - } - - notifyListeners(); - } - - public synchronized @Nullable byte[] getProfileKey() { - return profileKey; - } - - public void setProfileKey(@Nullable byte[] profileKey) { - synchronized (this) { - this.profileKey = profileKey; - } - - notifyListeners(); - } - - public @NonNull synchronized UnidentifiedAccessMode getUnidentifiedAccessMode() { - return unidentifiedAccessMode; - } - - public void setUnidentifiedAccessMode(@NonNull UnidentifiedAccessMode unidentifiedAccessMode) { - synchronized (this) { - this.unidentifiedAccessMode = unidentifiedAccessMode; - } - - notifyListeners(); - } - - public synchronized boolean isSystemContact() { - return contactUri != null; - } - - public synchronized Recipient resolve() { - while (resolving) Util.wait(this, 0); - return this; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof Recipient)) return false; - - Recipient that = (Recipient) o; - - return this.address.equals(that.address); - } - - @Override - public int hashCode() { - return this.address.hashCode(); - } - - public void notifyListeners() { - Set localListeners; - - synchronized (this) { - localListeners = new HashSet<>(listeners); - } - - for (RecipientModifiedListener listener : localListeners) - listener.onModified(this); - } - - @Override - public void onModified(Recipient recipient) { - notifyListeners(); - } - - public synchronized boolean isResolving() { - return resolving; - } - - -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientExporter.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientExporter.java deleted file mode 100644 index e968fa427c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientExporter.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.thoughtcrime.securesms.recipients; - -import android.content.Intent; -import android.provider.ContactsContract; -import android.text.TextUtils; - -import org.session.libsession.messaging.threads.Address; - -import static android.content.Intent.ACTION_INSERT_OR_EDIT; - -public final class RecipientExporter { - - public static RecipientExporter export(Recipient recipient) { - return new RecipientExporter(recipient); - } - - private final Recipient recipient; - - private RecipientExporter(Recipient recipient) { - this.recipient = recipient; - } - - public Intent asAddContactIntent() { - Intent intent = new Intent(ACTION_INSERT_OR_EDIT); - intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); - addNameToIntent(intent, recipient.getProfileName()); - addAddressToIntent(intent, recipient.getAddress()); - return intent; - } - - private static void addNameToIntent(Intent intent, String profileName) { - if (!TextUtils.isEmpty(profileName)) { - intent.putExtra(ContactsContract.Intents.Insert.NAME, profileName); - } - } - - private static void addAddressToIntent(Intent intent, Address address) { - if (address.isPhone()) { - intent.putExtra(ContactsContract.Intents.Insert.PHONE, address.toPhoneString()); - } else if (address.isEmail()) { - intent.putExtra(ContactsContract.Intents.Insert.EMAIL, address.toEmailString()); - } else { - throw new RuntimeException("Cannot export Recipient with neither phone nor email"); - } - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientFormattingException.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientFormattingException.java deleted file mode 100644 index 9b2731e16b..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientFormattingException.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.recipients; - -public class RecipientFormattingException extends Exception { - public RecipientFormattingException() { - super(); - } - - public RecipientFormattingException(String message) { - super(message); - } - - public RecipientFormattingException(String message, Throwable nested) { - super(message, nested); - } - - public RecipientFormattingException(Throwable nested) { - super(nested); - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientModifiedListener.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientModifiedListener.java deleted file mode 100644 index d6e0955c3f..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientModifiedListener.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.thoughtcrime.securesms.recipients; - - -public interface RecipientModifiedListener { - public void onModified(Recipient recipient); -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientProvider.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientProvider.java deleted file mode 100644 index fac15b935d..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientProvider.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.recipients; - -import android.content.Context; -import android.net.Uri; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import android.text.TextUtils; - -import network.loki.messenger.R; -import org.thoughtcrime.securesms.color.MaterialColor; -import org.session.libsession.messaging.threads.Address; -import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord; -import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings; -import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState; -import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode; -import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState; -import org.thoughtcrime.securesms.util.ListenableFutureTask; -import org.thoughtcrime.securesms.util.SoftHashMap; -import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.thoughtcrime.securesms.util.Util; -import org.session.libsignal.libsignal.util.guava.Optional; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; - -class RecipientProvider { - - @SuppressWarnings("unused") - private static final String TAG = RecipientProvider.class.getSimpleName(); - - private static final RecipientCache recipientCache = new RecipientCache(); - private static final ExecutorService asyncRecipientResolver = Util.newSingleThreadedLifoExecutor(); - - private static final Map STATIC_DETAILS = new HashMap() {{ - put("262966", new RecipientDetails("Amazon", null, false, false, null, null)); - }}; - - @NonNull Recipient getRecipient(@NonNull Context context, @NonNull Address address, @NonNull Optional settings, @NonNull Optional groupRecord, boolean asynchronous) { - Recipient cachedRecipient = recipientCache.get(address); - - if (cachedRecipient != null && (asynchronous || !cachedRecipient.isResolving()) && ((!groupRecord.isPresent() && !settings.isPresent()) || !cachedRecipient.isResolving() || cachedRecipient.getName() != null)) { - return cachedRecipient; - } - - Optional prefetchedRecipientDetails = createPrefetchedRecipientDetails(context, address, settings, groupRecord); - - if (asynchronous) { - cachedRecipient = new Recipient(context, address, cachedRecipient, prefetchedRecipientDetails, getRecipientDetailsAsync(context, address, settings, groupRecord)); - } else { - cachedRecipient = new Recipient(context, address, getRecipientDetailsSync(context, address, settings, groupRecord, false)); - } - - recipientCache.set(address, cachedRecipient); - return cachedRecipient; - } - - @NonNull Optional getCached(@NonNull Address address) { - return Optional.fromNullable(recipientCache.get(address)); - } - - boolean removeCached(@NonNull Address address) { - return recipientCache.remove(address); - } - - private @NonNull Optional createPrefetchedRecipientDetails(@NonNull Context context, @NonNull Address address, - @NonNull Optional settings, - @NonNull Optional groupRecord) - { - if (address.isGroup() && settings.isPresent() && groupRecord.isPresent()) { - return Optional.of(getGroupRecipientDetails(context, address, groupRecord, settings, true)); - } else if (!address.isGroup() && settings.isPresent()) { - boolean isLocalNumber = address.serialize().equals(TextSecurePreferences.getLocalNumber(context)); - return Optional.of(new RecipientDetails(null, null, !TextUtils.isEmpty(settings.get().getSystemDisplayName()), isLocalNumber, settings.get(), null)); - } - - return Optional.absent(); - } - - private @NonNull ListenableFutureTask getRecipientDetailsAsync(final Context context, final @NonNull Address address, final @NonNull Optional settings, final @NonNull Optional groupRecord) - { - Callable task = () -> getRecipientDetailsSync(context, address, settings, groupRecord, true); - - ListenableFutureTask future = new ListenableFutureTask<>(task); - asyncRecipientResolver.submit(future); - return future; - } - - private @NonNull RecipientDetails getRecipientDetailsSync(Context context, @NonNull Address address, Optional settings, Optional groupRecord, boolean nestedAsynchronous) { - if (address.isGroup()) return getGroupRecipientDetails(context, address, groupRecord, settings, nestedAsynchronous); - else return getIndividualRecipientDetails(context, address, settings); - } - - private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, @NonNull Address address, Optional settings) { - if (!settings.isPresent()) { - settings = DatabaseFactory.getRecipientDatabase(context).getRecipientSettings(address); - } - - if (!settings.isPresent() && STATIC_DETAILS.containsKey(address.serialize())) { - return STATIC_DETAILS.get(address.serialize()); - } else { - boolean systemContact = settings.isPresent() && !TextUtils.isEmpty(settings.get().getSystemDisplayName()); - boolean isLocalNumber = address.serialize().equals(TextSecurePreferences.getLocalNumber(context)); - return new RecipientDetails(null, null, systemContact, isLocalNumber, settings.orNull(), null); - } - } - - private @NonNull RecipientDetails getGroupRecipientDetails(Context context, Address groupId, Optional groupRecord, Optional settings, boolean asynchronous) { - - if (!groupRecord.isPresent()) { - groupRecord = DatabaseFactory.getGroupDatabase(context).getGroup(groupId.toGroupString()); - } - - if (!settings.isPresent()) { - settings = DatabaseFactory.getRecipientDatabase(context).getRecipientSettings(groupId); - } - - if (groupRecord.isPresent()) { - String title = groupRecord.get().getTitle(); - List
memberAddresses = groupRecord.get().getMembers(); - List members = new LinkedList<>(); - Long avatarId = null; - - for (Address memberAddress : memberAddresses) { - members.add(getRecipient(context, memberAddress, Optional.absent(), Optional.absent(), asynchronous)); - } - - if (!groupId.isMmsGroup() && title == null) { - title = context.getString(R.string.RecipientProvider_unnamed_group); - } - - if (groupRecord.get().getAvatar() != null && groupRecord.get().getAvatar().length > 0) { - avatarId = groupRecord.get().getAvatarId(); - } - - return new RecipientDetails(title, avatarId, false, false, settings.orNull(), members); - } - - return new RecipientDetails(context.getString(R.string.RecipientProvider_unnamed_group), null, false, false, settings.orNull(), null); - } - - static class RecipientDetails { - @Nullable final String name; - @Nullable final String customLabel; - @Nullable final Uri systemContactPhoto; - @Nullable final Uri contactUri; - @Nullable final Long groupAvatarId; - @Nullable final MaterialColor color; - @Nullable final Uri messageRingtone; - @Nullable final Uri callRingtone; - final long mutedUntil; - @Nullable final VibrateState messageVibrateState; - @Nullable final VibrateState callVibrateState; - final boolean blocked; - final int expireMessages; - @NonNull final List participants; - @Nullable final String profileName; - final Optional defaultSubscriptionId; - @NonNull final RegisteredState registered; - @Nullable final byte[] profileKey; - @Nullable final String profileAvatar; - final boolean profileSharing; - final boolean systemContact; - final boolean isLocalNumber; - @Nullable final String notificationChannel; - @NonNull final UnidentifiedAccessMode unidentifiedAccessMode; - final boolean forceSmsSelection; - - RecipientDetails(@Nullable String name, @Nullable Long groupAvatarId, - boolean systemContact, boolean isLocalNumber, @Nullable RecipientSettings settings, - @Nullable List participants) - { - this.groupAvatarId = groupAvatarId; - this.systemContactPhoto = settings != null ? Util.uri(settings.getSystemContactPhotoUri()) : null; - this.customLabel = settings != null ? settings.getSystemPhoneLabel() : null; - this.contactUri = settings != null ? Util.uri(settings.getSystemContactUri()) : null; - this.color = settings != null ? settings.getColor() : null; - this.messageRingtone = settings != null ? settings.getMessageRingtone() : null; - this.callRingtone = settings != null ? settings.getCallRingtone() : null; - this.mutedUntil = settings != null ? settings.getMuteUntil() : 0; - this.messageVibrateState = settings != null ? settings.getMessageVibrateState() : null; - this.callVibrateState = settings != null ? settings.getCallVibrateState() : null; - this.blocked = settings != null && settings.isBlocked(); - this.expireMessages = settings != null ? settings.getExpireMessages() : 0; - this.participants = participants == null ? new LinkedList<>() : participants; - this.profileName = settings != null ? settings.getProfileName() : null; - this.defaultSubscriptionId = settings != null ? settings.getDefaultSubscriptionId() : Optional.absent(); - this.registered = settings != null ? settings.getRegistered() : RegisteredState.UNKNOWN; - this.profileKey = settings != null ? settings.getProfileKey() : null; - this.profileAvatar = settings != null ? settings.getProfileAvatar() : null; - this.profileSharing = settings != null && settings.isProfileSharing(); - this.systemContact = systemContact; - this.isLocalNumber = isLocalNumber; - this.notificationChannel = settings != null ? settings.getNotificationChannel() : null; - this.unidentifiedAccessMode = settings != null ? settings.getUnidentifiedAccessMode() : UnidentifiedAccessMode.DISABLED; - this.forceSmsSelection = settings != null && settings.isForceSmsSelection(); - - if (name == null && settings != null) this.name = settings.getSystemDisplayName(); - else this.name = name; - } - } - - private static class RecipientCache { - - private final Map cache = new SoftHashMap<>(1000); - - public synchronized Recipient get(Address address) { - return cache.get(address); - } - - public synchronized void set(Address address, Recipient recipient) { - cache.put(address, recipient); - } - - public synchronized boolean remove(Address address) { - return cache.remove(address) != null; - } - - } - -} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientsFormatter.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientsFormatter.java deleted file mode 100644 index 041299c4bf..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/RecipientsFormatter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2011 Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.thoughtcrime.securesms.recipients; - -import android.telephony.PhoneNumberUtils; -import android.text.TextUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -public class RecipientsFormatter { - - private static String parseBracketedNumber(String recipient) throws RecipientFormattingException { - int begin = recipient.indexOf('<'); - int end = recipient.indexOf('>'); - String value = recipient.substring(begin + 1, end); - - if (PhoneNumberUtils.isWellFormedSmsAddress(value)) - return value; - else - throw new RecipientFormattingException("Bracketed value: " + value + " is not valid."); - } - - private static String parseRecipient(String recipient) throws RecipientFormattingException { - recipient = recipient.trim(); - - if ((recipient.indexOf('<') != -1) && (recipient.indexOf('>') != -1)) - return parseBracketedNumber(recipient); - - if (PhoneNumberUtils.isWellFormedSmsAddress(recipient)) - return recipient; - - throw new RecipientFormattingException("Recipient: " + recipient + " is badly formatted."); - } - - public static List getRecipients(String rawText) throws RecipientFormattingException { - ArrayList results = new ArrayList(); - StringTokenizer tokenizer = new StringTokenizer(rawText, ","); - - while (tokenizer.hasMoreTokens()) { - results.add(parseRecipient(tokenizer.nextToken())); - } - - return results; - } - - public static String formatNameAndNumber(String name, String number) { - // Format like this: Mike Cleron <(650) 555-1234> - // Erick Tseng <(650) 555-1212> - // Tutankhamun - // (408) 555-1289 - String formattedNumber = PhoneNumberUtils.formatNumber(number); - if (!TextUtils.isEmpty(name) && !name.equals(number)) { - return name + " <" + formattedNumber + ">"; - } else { - return formattedNumber; - } - } - - -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/sms/MessageSender.java b/app/src/main/java/org/thoughtcrime/securesms/sms/MessageSender.java index 515271f8ec..c43d08768a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/app/src/main/java/org/thoughtcrime/securesms/sms/MessageSender.java @@ -20,7 +20,7 @@ import android.content.Context; import androidx.annotation.NonNull; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java index b98b930aa0..8aa15bf874 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java @@ -10,7 +10,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; -import org.thoughtcrime.securesms.attachments.AttachmentId; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId; import org.thoughtcrime.securesms.attachments.DatabaseAttachment; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.logging.Log; diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java index 6278073fd0..1dcdc54a90 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java @@ -15,7 +15,7 @@ import android.webkit.MimeTypeMap; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.gif.GifDrawable; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java index dff96b4fab..5a49b71dbb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/video/VideoPlayer.java @@ -48,7 +48,7 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; -import org.thoughtcrime.securesms.attachments.AttachmentServer; +import org.session.libsession.messaging.sending_receiving.attachments.AttachmentServer; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.PartAuthority; import org.thoughtcrime.securesms.mms.VideoSlide; diff --git a/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java b/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java index e504eff71a..6f5be91e9d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java +++ b/app/src/main/java/org/thoughtcrime/securesms/video/exo/PartDataSource.java @@ -10,7 +10,7 @@ import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.TransferListener; -import org.thoughtcrime.securesms.attachments.Attachment; +import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.mms.PartUriParser; diff --git a/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt b/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt index 777e53dac5..b65b9af488 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/GroupUtil.kt @@ -1,5 +1,7 @@ package org.session.libsession.utilities +import org.session.libsignal.service.api.messages.SignalServiceGroup + object GroupUtil { const val CLOSED_GROUP_PREFIX = "__textsecure_group__!" const val MMS_GROUP_PREFIX = "__signal_mms_group__!" @@ -29,6 +31,14 @@ object GroupUtil { return (MMS_GROUP_PREFIX + groupID).toByteArray() } + fun getEncodedId(group: SignalServiceGroup): String? { + val groupId = group.groupId + if (group.groupType == SignalServiceGroup.GroupType.PUBLIC_CHAT) { + return getEncodedOpenGroupID(groupId.toString()) + } + return getEncodedGroupID(groupId) + } + fun getEncodedGroupID(groupID: ByteArray): String { return groupID.toString() } diff --git a/libsession/src/main/java/org/session/libsession/utilities/Util.kt b/libsession/src/main/java/org/session/libsession/utilities/Util.kt index 94da8a8f80..eb7e098752 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Util.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Util.kt @@ -1,15 +1,18 @@ package org.session.libsession.utilities +import android.annotation.SuppressLint import android.content.Context import android.net.Uri import android.os.Handler import android.os.Looper +import android.provider.Telephony import org.session.libsession.messaging.threads.Address import org.session.libsignal.libsignal.logging.Log import java.io.Closeable import java.io.IOException import java.io.InputStream import java.io.OutputStream +import java.nio.charset.StandardCharsets import java.util.* import java.util.concurrent.ExecutorService import java.util.concurrent.ThreadPoolExecutor @@ -88,6 +91,11 @@ object Util { return executor } + @JvmStatic + fun join(list: Array, delimiter: String?): String { + return join(Arrays.asList(*list), delimiter) + } + @JvmStatic fun join(list: Collection, delimiter: String?): String { val result = StringBuilder() @@ -99,6 +107,16 @@ object Util { return result.toString() } + @JvmStatic + fun join(list: LongArray, delimeter: String?): String { + val sb = java.lang.StringBuilder() + for (j in list.indices) { + if (j != 0) sb.append(delimeter) + sb.append(list[j]) + } + return sb.toString() + } + @JvmStatic fun equals(a: Any?, b: Any?): Boolean { return a === b || a != null && a == b @@ -160,4 +178,25 @@ object Util { return results } + @JvmStatic + fun toIsoString(bytes: ByteArray?): String { + return String(bytes!!, StandardCharsets.ISO_8859_1) + } + + @JvmStatic + fun toIsoBytes(isoString: String): ByteArray { + return isoString.toByteArray(StandardCharsets.ISO_8859_1) + } + + @JvmStatic + fun toUtf8Bytes(utf8String: String): ByteArray { + return utf8String.toByteArray(StandardCharsets.UTF_8) + } + + @JvmStatic + @SuppressLint("NewApi") + fun isDefaultSmsProvider(context: Context): Boolean { + return context.packageName == Telephony.Sms.getDefaultSmsPackage(context) + } + } \ No newline at end of file