mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-02 14:35:21 +00:00
refactor: re-add thread ID for mentions, fix path resolver call
refactor: re-add thread ID for mentions, fix path resolver call
This commit is contained in:
parent
22905787f6
commit
072ea41b46
@ -1204,7 +1204,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
val sortedMessages = messages.sortedBy { it.dateSent }
|
val sortedMessages = messages.sortedBy { it.dateSent }
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
for (message in sortedMessages) {
|
for (message in sortedMessages) {
|
||||||
val body = MentionUtilities.highlightMentions(message.body, this)
|
val body = MentionUtilities.highlightMentions(message.body, threadID, this)
|
||||||
if (TextUtils.isEmpty(body)) { continue }
|
if (TextUtils.isEmpty(body)) { continue }
|
||||||
val formattedTimestamp = DateUtils.getDisplayFormattedTimeSpanString(this, Locale.getDefault(), message.timestamp)
|
val formattedTimestamp = DateUtils.getDisplayFormattedTimeSpanString(this, Locale.getDefault(), message.timestamp)
|
||||||
builder.append("$formattedTimestamp: $body").append('\n')
|
builder.append("$formattedTimestamp: $body").append('\n')
|
||||||
|
@ -119,7 +119,7 @@ class QuoteView : LinearLayout {
|
|||||||
}
|
}
|
||||||
quoteViewAuthorTextView.isVisible = thread.isGroupRecipient
|
quoteViewAuthorTextView.isVisible = thread.isGroupRecipient
|
||||||
// Body
|
// Body
|
||||||
quoteViewBodyTextView.text = if (isOpenGroupInvitation) resources.getString(R.string.open_group_invitation_view__open_group_invitation) else MentionUtilities.highlightMentions((body ?: "").toSpannable(), context);
|
quoteViewBodyTextView.text = if (isOpenGroupInvitation) resources.getString(R.string.open_group_invitation_view__open_group_invitation) else MentionUtilities.highlightMentions((body ?: "").toSpannable(), threadID, context);
|
||||||
quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage))
|
quoteViewBodyTextView.setTextColor(getTextColor(isOutgoingMessage))
|
||||||
// Accent line / attachment preview
|
// Accent line / attachment preview
|
||||||
val hasAttachments = (attachments != null && attachments.asAttachments().isNotEmpty()) && !isOriginalMissing
|
val hasAttachments = (attachments != null && attachments.asAttachments().isNotEmpty()) && !isOriginalMissing
|
||||||
|
@ -223,7 +223,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
body.setSpan(replacementSpan, start, end, flags)
|
body.setSpan(replacementSpan, start, end, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
body = MentionUtilities.highlightMentions(body, message.isOutgoing, context)
|
body = MentionUtilities.highlightMentions(body, message.isOutgoing, message.threadId, context)
|
||||||
body = SearchUtil.getHighlightedSpan(Locale.getDefault(), StyleFactory { BackgroundColorSpan(Color.WHITE) }, body, searchQuery)
|
body = SearchUtil.getHighlightedSpan(Locale.getDefault(), StyleFactory { BackgroundColorSpan(Color.WHITE) }, body, searchQuery)
|
||||||
body = SearchUtil.getHighlightedSpan(Locale.getDefault(), StyleFactory { ForegroundColorSpan(Color.BLACK) }, body, searchQuery)
|
body = SearchUtil.getHighlightedSpan(Locale.getDefault(), StyleFactory { ForegroundColorSpan(Color.BLACK) }, body, searchQuery)
|
||||||
|
|
||||||
|
@ -19,13 +19,15 @@ import java.util.regex.Pattern
|
|||||||
object MentionUtilities {
|
object MentionUtilities {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun highlightMentions(text: CharSequence, context: Context): String {
|
fun highlightMentions(text: CharSequence, threadID: Long, context: Context): String {
|
||||||
return highlightMentions(text, false, context).toString() // isOutgoingMessage is irrelevant
|
return highlightMentions(text, false, threadID, context).toString() // isOutgoingMessage is irrelevant
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun highlightMentions(text: CharSequence, isOutgoingMessage: Boolean, context: Context): SpannableString {
|
fun highlightMentions(text: CharSequence, isOutgoingMessage: Boolean, threadID: Long, context: Context): SpannableString {
|
||||||
@Suppress("NAME_SHADOWING") var text = text
|
@Suppress("NAME_SHADOWING") var text = text
|
||||||
|
val threadDB = DatabaseFactory.getThreadDatabase(context)
|
||||||
|
val isOpenGroup = threadDB.getRecipientForThreadId(threadID)?.isOpenGroupRecipient ?: false
|
||||||
val pattern = Pattern.compile("@[0-9a-fA-F]*")
|
val pattern = Pattern.compile("@[0-9a-fA-F]*")
|
||||||
var matcher = pattern.matcher(text)
|
var matcher = pattern.matcher(text)
|
||||||
val mentions = mutableListOf<Tuple2<Range<Int>, String>>()
|
val mentions = mutableListOf<Tuple2<Range<Int>, String>>()
|
||||||
@ -38,7 +40,8 @@ object MentionUtilities {
|
|||||||
TextSecurePreferences.getProfileName(context)
|
TextSecurePreferences.getProfileName(context)
|
||||||
} else {
|
} else {
|
||||||
val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey)
|
val contact = DatabaseFactory.getSessionContactDatabase(context).getContactWithSessionID(publicKey)
|
||||||
contact?.displayName(Contact.ContactContext.REGULAR)
|
@Suppress("NAME_SHADOWING") val context = if (isOpenGroup) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR
|
||||||
|
contact?.displayName(context)
|
||||||
}
|
}
|
||||||
if (userDisplayName != null) {
|
if (userDisplayName != null) {
|
||||||
text = text.subSequence(0, matcher.start()).toString() + "@" + userDisplayName + text.subSequence(matcher.end(), text.length)
|
text = text.subSequence(0, matcher.start()).toString() + "@" + userDisplayName + text.subSequence(matcher.end(), text.length)
|
||||||
|
@ -69,7 +69,7 @@ class ConversationView : LinearLayout {
|
|||||||
}
|
}
|
||||||
muteIndicatorImageView.setImageResource(drawableRes)
|
muteIndicatorImageView.setImageResource(drawableRes)
|
||||||
val rawSnippet = thread.getDisplayBody(context)
|
val rawSnippet = thread.getDisplayBody(context)
|
||||||
val snippet = highlightMentions(rawSnippet, context)
|
val snippet = highlightMentions(rawSnippet, thread.threadId, context)
|
||||||
snippetTextView.text = snippet
|
snippetTextView.text = snippet
|
||||||
snippetTextView.typeface = if (unreadCount > 0) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
|
snippetTextView.typeface = if (unreadCount > 0) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
|
||||||
snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE
|
snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE
|
||||||
|
@ -103,6 +103,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
|
|||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
// Set up empty state view
|
// Set up empty state view
|
||||||
createNewPrivateChatButton.setOnClickListener { createNewPrivateChat() }
|
createNewPrivateChatButton.setOnClickListener { createNewPrivateChat() }
|
||||||
|
IP2Country.configureIfNeeded(this@HomeActivity)
|
||||||
// This is a workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update (even though it says it will)
|
// This is a workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update (even though it says it will)
|
||||||
LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
|
|
||||||
@ -154,7 +155,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
|
|||||||
OpenGroupManager.startPolling()
|
OpenGroupManager.startPolling()
|
||||||
JobQueue.shared.resumePendingJobs()
|
JobQueue.shared.resumePendingJobs()
|
||||||
}
|
}
|
||||||
IP2Country.configureIfNeeded(this@HomeActivity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventBus.getDefault().register(this@HomeActivity)
|
EventBus.getDefault().register(this@HomeActivity)
|
||||||
|
@ -83,7 +83,7 @@ public class LongMessageActivity extends PassphraseRequiredActionBarActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String trimmedBody = getTrimmedBody(message.get().getFullBody());
|
String trimmedBody = getTrimmedBody(message.get().getFullBody());
|
||||||
String mentionBody = MentionUtilities.highlightMentions(trimmedBody, this);
|
String mentionBody = MentionUtilities.highlightMentions(trimmedBody, message.get().getMessageRecord().getThreadId(), this);
|
||||||
|
|
||||||
textBody.setText(mentionBody);
|
textBody.setText(mentionBody);
|
||||||
textBody.setMovementMethod(LinkMovementMethod.getInstance());
|
textBody.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
@ -333,7 +333,9 @@ public class DefaultMessageNotifier implements MessageNotifier {
|
|||||||
builder.setMessageCount(notificationState.getMessageCount());
|
builder.setMessageCount(notificationState.getMessageCount());
|
||||||
MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(notifications.get(0).getThreadId(),context);
|
MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(notifications.get(0).getThreadId(),context);
|
||||||
builder.setPrimaryMessageBody(recipient, notifications.get(0).getIndividualRecipient(),
|
builder.setPrimaryMessageBody(recipient, notifications.get(0).getIndividualRecipient(),
|
||||||
MentionUtilities.highlightMentions(notifications.get(0).getText(), context),
|
MentionUtilities.highlightMentions(notifications.get(0).getText(),
|
||||||
|
notifications.get(0).getThreadId(),
|
||||||
|
context),
|
||||||
notifications.get(0).getSlideDeck());
|
notifications.get(0).getSlideDeck());
|
||||||
builder.setContentIntent(notifications.get(0).getPendingIntent(context));
|
builder.setContentIntent(notifications.get(0).getPendingIntent(context));
|
||||||
builder.setDeleteIntent(notificationState.getDeleteIntent(context));
|
builder.setDeleteIntent(notificationState.getDeleteIntent(context));
|
||||||
@ -409,13 +411,13 @@ public class DefaultMessageNotifier implements MessageNotifier {
|
|||||||
while(iterator.hasPrevious()) {
|
while(iterator.hasPrevious()) {
|
||||||
NotificationItem item = iterator.previous();
|
NotificationItem item = iterator.previous();
|
||||||
builder.addMessageBody(item.getIndividualRecipient(), item.getRecipient(),
|
builder.addMessageBody(item.getIndividualRecipient(), item.getRecipient(),
|
||||||
MentionUtilities.highlightMentions(item.getText(), context));
|
MentionUtilities.highlightMentions(item.getText(), item.getThreadId(), context));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
builder.setAlarms(notificationState.getRingtone(context), notificationState.getVibrate());
|
builder.setAlarms(notificationState.getRingtone(context), notificationState.getVibrate());
|
||||||
builder.setTicker(notifications.get(0).getIndividualRecipient(),
|
builder.setTicker(notifications.get(0).getIndividualRecipient(),
|
||||||
MentionUtilities.highlightMentions(notifications.get(0).getText(), context));
|
MentionUtilities.highlightMentions(notifications.get(0).getText(), notifications.get(0).getThreadId(), context));
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification notification = builder.build();
|
Notification notification = builder.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user