diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 582a88f59d..e06c634635 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -502,7 +502,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc } public void createGroupChatsIfNeeded() { - List defaultChats = LokiPublicChat.Companion.defaultChats(BuildConfig.DEBUG); + List defaultChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG); for (LokiPublicChat chat : defaultChats) { long threadID = GroupManager.getThreadId(chat.getId(), this); String migrationKey = chat.getId() + "_migrated"; @@ -514,7 +514,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc TextSecurePreferences.setBooleanPreference(this, migrationKey, true); } else if (threadID > -1 && !isChatMigrated) { // Migrate the old public chats. - DatabaseFactory.getLokiThreadDatabase(this).setGroupChat(chat, threadID); + DatabaseFactory.getLokiThreadDatabase(this).setPublicChat(chat, threadID); TextSecurePreferences.setBooleanPreference(this, migrationKey, true); } } diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 4cd2f799c2..d2ca8aaa4c 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -273,7 +273,7 @@ public class ConversationListItem extends RelativeLayout private @NonNull CharSequence getTrimmedSnippet(@NonNull CharSequence snippet) { LokiAPIUtilities.INSTANCE.populateUserHexEncodedPublicKeyCacheIfNeeded(threadId, getContext()); // TODO: Terrible place to do this, but okay for now - snippet = MentionUtilities.highlightMentions(snippet, this.recipient.isGroupRecipient(), getContext()); + snippet = MentionUtilities.highlightMentions(snippet, threadId, getContext()); return snippet.length() <= MAX_SNIPPET_LENGTH ? snippet : snippet.subSequence(0, MAX_SNIPPET_LENGTH); } diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index 7febb79499..3680ec4859 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -35,15 +35,12 @@ import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider; import org.thoughtcrime.securesms.components.emoji.EmojiToggle; import org.thoughtcrime.securesms.components.emoji.MediaKeyboard; import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto; -import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.loki.LokiAPIDatabase; -import org.thoughtcrime.securesms.loki.LokiUserDatabase; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.profiles.AvatarHelper; @@ -61,7 +58,6 @@ import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.crypto.ProfileCipher; import org.whispersystems.signalservice.api.util.StreamDetails; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; import org.whispersystems.signalservice.loki.utilities.Analytics; @@ -69,7 +65,6 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.security.SecureRandom; -import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -385,7 +380,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje TextSecurePreferences.setProfileName(context, name); LokiPublicChatAPI chatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI(); if (chatAPI != null) { - Set groupChatServers = DatabaseFactory.getLokiThreadDatabase(context).getAllGroupChatServers(); + Set groupChatServers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers(); for (String server : groupChatServers) { chatAPI.setDisplayName(name, server); } diff --git a/src/org/thoughtcrime/securesms/components/QuoteView.java b/src/org/thoughtcrime/securesms/components/QuoteView.java index a3ce8126d6..f868c56082 100644 --- a/src/org/thoughtcrime/securesms/components/QuoteView.java +++ b/src/org/thoughtcrime/securesms/components/QuoteView.java @@ -21,7 +21,6 @@ import com.annimon.stream.Stream; import com.bumptech.glide.load.engine.DiskCacheStrategy; import org.thoughtcrime.securesms.attachments.Attachment; -import org.thoughtcrime.securesms.database.Database; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; import org.thoughtcrime.securesms.mms.GlideRequests; @@ -29,11 +28,9 @@ import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; -import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.ThemeUtil; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.signalservice.loki.api.LokiPublicChat; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; import java.util.List; @@ -200,7 +197,7 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener // If we're in a group then try and use the display name in the group if (conversationRecipient.isGroupRecipient()) { long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient); - LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(getContext()).getGroupChat(threadId); + LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId); if (chat != null) { String senderDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(chat.getId(), author.getAddress().serialize()); if (senderDisplayName != null) { quoteeDisplayName = senderDisplayName; } diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index b728c58c42..c392596663 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -157,6 +157,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate; import org.thoughtcrime.securesms.loki.LokiAPIUtilities; +import org.thoughtcrime.securesms.loki.LokiThreadDatabase; import org.thoughtcrime.securesms.loki.LokiThreadDatabaseDelegate; import org.thoughtcrime.securesms.loki.LokiUserDatabase; import org.thoughtcrime.securesms.loki.MentionCandidateSelectionView; @@ -2780,9 +2781,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } int lastCharacterIndex = text.length() - 1; char lastCharacter = text.charAt(lastCharacterIndex); + String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(ConversationActivity.this); + LokiThreadDatabase threadDatabase = DatabaseFactory.getLokiThreadDatabase(ConversationActivity.this); LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(ConversationActivity.this); if (lastCharacter == '@') { - List mentionCandidates = LokiAPI.Companion.getMentionCandidates("", threadId, userDatabase); + List mentionCandidates = LokiAPI.Companion.getMentionCandidates("", threadId, userHexEncodedPublicKey, threadDatabase, userDatabase); currentMentionStartIndex = lastCharacterIndex; mentionCandidateSelectionView.show(mentionCandidates, threadId); } else if (Character.isWhitespace(lastCharacter)) { @@ -2791,7 +2794,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } else { if (currentMentionStartIndex != -1) { String query = text.substring(currentMentionStartIndex + 1); // + 1 to get rid of the @ - List mentionCandidates = LokiAPI.Companion.getMentionCandidates(query, threadId, userDatabase); + List mentionCandidates = LokiAPI.Companion.getMentionCandidates(query, threadId, userHexEncodedPublicKey, threadDatabase, userDatabase); mentionCandidateSelectionView.show(mentionCandidates, threadId); } } diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java index a19beb5f0c..0e2835ed2f 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -68,9 +68,7 @@ import org.thoughtcrime.securesms.contactshare.ContactUtil; import org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity; import org.thoughtcrime.securesms.conversation.ConversationAdapter.HeaderViewHolder; import org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener; -import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.database.Address; -import org.thoughtcrime.securesms.database.Database; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.RecipientDatabase; @@ -82,8 +80,6 @@ import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob; import org.thoughtcrime.securesms.linkpreview.LinkPreview; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate; -import org.thoughtcrime.securesms.loki.LokiAPIDatabase; -import org.thoughtcrime.securesms.loki.LokiUserDatabase; import org.thoughtcrime.securesms.longmessage.LongMessageActivity; import org.thoughtcrime.securesms.mediasend.Media; import org.thoughtcrime.securesms.mms.GlideApp; @@ -410,7 +406,7 @@ public class ConversationFragment extends Fragment boolean isGroupChat = recipient.isGroupRecipient(); if (isGroupChat) { - LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getGroupChat(threadId); + LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId); boolean isPublicChat = groupChat != null; int selectedMessageCount = messageRecords.size(); boolean isSentByUser = ((MessageRecord)messageRecords.toArray()[0]).isOutgoing(); @@ -513,7 +509,7 @@ public class ConversationFragment extends Fragment builder.setCancelable(true); // Loki - The delete option is only visible to the user in a group chat - LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getGroupChat(threadId); + LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId); builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { @Override diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index c56b1d6af8..bedeb16cfe 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -71,7 +71,6 @@ import org.thoughtcrime.securesms.components.StickerView; import org.thoughtcrime.securesms.components.emoji.EmojiTextView; import org.thoughtcrime.securesms.contactshare.Contact; import org.thoughtcrime.securesms.database.AttachmentDatabase; -import org.thoughtcrime.securesms.database.Database; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.MmsSmsDatabase; @@ -475,7 +474,7 @@ public class ConversationItem extends LinearLayout if (isCaptionlessMms(messageRecord)) { bodyText.setVisibility(View.GONE); } else { ; - Spannable text = MentionUtilities.highlightMentions(linkifyMessageBody(messageRecord.getDisplayBody(context), batchSelected.isEmpty()), messageRecord.isOutgoing(), isGroupThread, context); + Spannable text = MentionUtilities.highlightMentions(linkifyMessageBody(messageRecord.getDisplayBody(context), batchSelected.isEmpty()), messageRecord.isOutgoing(), messageRecord.getThreadId(), context); text = SearchUtil.getHighlightedSpan(locale, () -> new BackgroundColorSpan(Color.YELLOW), text, searchQuery); text = SearchUtil.getHighlightedSpan(locale, () -> new ForegroundColorSpan(Color.BLACK), text, searchQuery); @@ -791,7 +790,7 @@ public class ConversationItem extends LinearLayout if (current.isMms() && !current.isMmsNotification() && ((MediaMmsMessageRecord)current).getQuote() != null) { Quote quote = ((MediaMmsMessageRecord)current).getQuote(); //noinspection ConstantConditions - String quoteBody = MentionUtilities.highlightMentions(quote.getText(), isGroupThread, context); + String quoteBody = MentionUtilities.highlightMentions(quote.getText(), current.getThreadId(), context); quoteView.setQuote(glideRequests, quote.getId(), Recipient.from(context, quote.getAuthor(), true), quoteBody, quote.isOriginalMissing(), quote.getAttachment(), conversationRecipient); quoteView.setVisibility(View.VISIBLE); quoteView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -941,7 +940,7 @@ public class ConversationItem extends LinearLayout int visibility = View.GONE; // If we have a chat then use that to determine mod status - LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(context).getGroupChat(messageRecord.getThreadId()); + LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(messageRecord.getThreadId()); if (groupChat != null) { boolean isModerator = LokiPublicChatAPI.Companion.isUserModerator(current.getRecipient().getAddress().toString(), groupChat.getChannel(), groupChat.getServer()); visibility = isModerator ? View.VISIBLE : View.GONE; diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 4532e619ca..2f798fe3ee 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -46,7 +46,6 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext; import org.whispersystems.signalservice.loki.api.LokiPublicChat; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; import java.io.IOException; import java.util.ArrayList; @@ -290,7 +289,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { // Loki - All group messages should be directed to their servers long threadID = GroupManager.getThreadIdFromGroupId(groupId, context); - LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(context).getGroupChat(threadID); + LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID); if (chat != null) { // We need to somehow maintain information that will allow the sender to map // a Recipient to the correct public chat thread, and so this might be a bit hacky diff --git a/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionView.kt b/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionView.kt index 878c07cd93..fd01cb778e 100644 --- a/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionView.kt +++ b/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionView.kt @@ -10,7 +10,7 @@ import android.widget.ListView import org.thoughtcrime.securesms.database.DatabaseFactory import org.whispersystems.signalservice.loki.messaging.Mention -class UserSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) { +class MentionCandidateSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) { private var mentionCandidates = listOf() set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.mentionCandidates = newValue } var publicChatServer: String? = null diff --git a/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionViewCell.kt b/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionViewCell.kt index 36f571bb1a..c8bfcc1f81 100644 --- a/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionViewCell.kt +++ b/src/org/thoughtcrime/securesms/loki/MentionCandidateSelectionViewCell.kt @@ -44,7 +44,7 @@ class MentionCandidateSelectionViewCell(context: Context, attrs: AttributeSet?, displayNameTextView.text = mentionCandidate.displayName profilePictureImageView.update(mentionCandidate.hexEncodedPublicKey) if (publicChatServer != null && publicChatChannel != null) { - val isUserModerator = LokiPublicChatAPI.isUserModerator(user.first, publicChatChannel!!, publicChatServer!!) + val isUserModerator = LokiPublicChatAPI.isUserModerator(mentionCandidate.hexEncodedPublicKey, publicChatChannel!!, publicChatServer!!) moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE } else { moderatorIconImageView.visibility = View.GONE