mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 02:39:55 +01:00
Add LinkPreview support to CFV2.
This commit is contained in:
committed by
Nicholas Tinsley
parent
3bdffed8c9
commit
2fbcc23451
@@ -190,6 +190,7 @@ import org.thoughtcrime.securesms.groups.v2.GroupBlockJoinRequestResult
|
||||
import org.thoughtcrime.securesms.invites.InviteActions
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModelV2
|
||||
import org.thoughtcrime.securesms.longmessage.LongMessageFragment
|
||||
import org.thoughtcrime.securesms.mediaoverview.MediaOverviewActivity
|
||||
import org.thoughtcrime.securesms.mediapreview.MediaIntentFactory
|
||||
@@ -302,6 +303,12 @@ class ConversationFragment :
|
||||
)
|
||||
}
|
||||
|
||||
private val linkPreviewViewModel: LinkPreviewViewModelV2 by viewModel {
|
||||
LinkPreviewViewModelV2(
|
||||
enablePlaceholder = false
|
||||
)
|
||||
}
|
||||
|
||||
private val groupCallViewModel: ConversationGroupCallViewModel by viewModels(
|
||||
factoryProducer = {
|
||||
ConversationGroupCallViewModel.Factory(args.threadId, conversationRecipientRepository)
|
||||
@@ -668,6 +675,7 @@ class ConversationFragment :
|
||||
.addTo(disposables)
|
||||
|
||||
initializeSearch()
|
||||
initializeLinkPreviews()
|
||||
|
||||
inputPanel.setListener(InputPanelListener())
|
||||
}
|
||||
@@ -1031,6 +1039,32 @@ class ConversationFragment :
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeLinkPreviews() {
|
||||
linkPreviewViewModel.linkPreviewState
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeBy { state ->
|
||||
if (state.isLoading) {
|
||||
inputPanel.setLinkPreviewLoading()
|
||||
} else if (state.hasLinks() && !state.linkPreview.isPresent) {
|
||||
inputPanel.setLinkPreviewNoPreview(state.error)
|
||||
} else {
|
||||
inputPanel.setLinkPreview(GlideApp.with(this), state.linkPreview)
|
||||
}
|
||||
|
||||
updateToggleButtonState()
|
||||
}
|
||||
.addTo(disposables)
|
||||
}
|
||||
|
||||
private fun updateLinkPreviewState() {
|
||||
if (/* TODO [cfv2] -- viewModel.isPushAvailable && */ !attachmentManager.isAttachmentPresent && context != null) {
|
||||
linkPreviewViewModel.onEnabled()
|
||||
linkPreviewViewModel.onTextChanged(composeText.textTrimmed.toString(), composeText.selectionStart, composeText.selectionEnd)
|
||||
} else {
|
||||
linkPreviewViewModel.onUserCancel()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateToggleButtonState() {
|
||||
val buttonToggle: AnimatingToggle = binding.conversationInputPanel.buttonToggle
|
||||
val quickAttachment: HidingLinearLayout = binding.conversationInputPanel.quickAttachmentToggle
|
||||
@@ -1065,7 +1099,7 @@ class ConversationFragment :
|
||||
buttonToggle.display(sendButton)
|
||||
quickAttachment.hide()
|
||||
|
||||
if (!attachmentManager.isAttachmentPresent) { // todo [cfv2] && !linkPreviewViewModel.hasLinkPreviewUi()) {
|
||||
if (!attachmentManager.isAttachmentPresent && !linkPreviewViewModel.hasLinkPreviewUi) {
|
||||
inlineAttachment.show()
|
||||
} else {
|
||||
inlineAttachment.hide()
|
||||
@@ -1103,7 +1137,8 @@ class ConversationFragment :
|
||||
mentions = emptyList(),
|
||||
bodyRanges = null,
|
||||
messageToEdit = null,
|
||||
quote = null
|
||||
quote = null,
|
||||
linkPreviews = emptyList()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1116,7 +1151,8 @@ class ConversationFragment :
|
||||
scheduledDate: Long = -1,
|
||||
slideDeck: SlideDeck? = if (attachmentManager.isAttachmentPresent) attachmentManager.buildSlideDeck() else null,
|
||||
contacts: List<Contact> = emptyList(),
|
||||
clearCompose: Boolean = true
|
||||
clearCompose: Boolean = true,
|
||||
linkPreviews: List<LinkPreview> = linkPreviewViewModel.onSend()
|
||||
) {
|
||||
val metricId = viewModel.recipientSnapshot?.let { if (it.isGroup == true) SignalLocalMetrics.GroupMessageSend.start() else SignalLocalMetrics.IndividualMessageSend.start() }
|
||||
|
||||
@@ -1129,7 +1165,8 @@ class ConversationFragment :
|
||||
quote = quote,
|
||||
mentions = mentions,
|
||||
bodyRanges = bodyRanges,
|
||||
contacts = contacts
|
||||
contacts = contacts,
|
||||
linkPreviews = linkPreviews
|
||||
)
|
||||
|
||||
disposables += send
|
||||
@@ -1164,7 +1201,7 @@ class ConversationFragment :
|
||||
scrollToPositionDelegate.resetScrollPosition()
|
||||
attachmentManager.cleanup()
|
||||
|
||||
// todo [cfv2] updateLinkPreviewState();
|
||||
updateLinkPreviewState()
|
||||
|
||||
draftViewModel.onSendComplete()
|
||||
|
||||
@@ -2712,7 +2749,7 @@ class ConversationFragment :
|
||||
}
|
||||
|
||||
override fun onCursorPositionChanged(start: Int, end: Int) {
|
||||
// todo [cfv2] linkPreviewViewModel.onTextChanged(requireContext(), composeText.getTextTrimmed().toString(), start, end);
|
||||
linkPreviewViewModel.onTextChanged(composeText.textTrimmed.toString(), start, end)
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
@@ -2809,7 +2846,7 @@ class ConversationFragment :
|
||||
}
|
||||
|
||||
override fun onLinkPreviewCanceled() {
|
||||
// TODO [cfv2] Not yet implemented
|
||||
linkPreviewViewModel.onUserCancel()
|
||||
}
|
||||
|
||||
override fun onStickerSuggestionSelected(sticker: StickerRecord) {
|
||||
@@ -2845,7 +2882,9 @@ class ConversationFragment :
|
||||
|
||||
private inner class AttachmentManagerListener : AttachmentManager.AttachmentListener {
|
||||
override fun onAttachmentChanged() {
|
||||
// TODO [cfv2] implement
|
||||
// TODO [cfv2] handleSecurityChange(viewModel.getConversationStateSnapshot().getSecurityInfo());
|
||||
updateToggleButtonState()
|
||||
updateLinkPreviewState()
|
||||
}
|
||||
|
||||
override fun onLocationRemoved() {
|
||||
|
||||
@@ -72,6 +72,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob
|
||||
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview
|
||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestState
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMessage
|
||||
@@ -193,7 +194,8 @@ class ConversationRepository(
|
||||
quote: QuoteModel?,
|
||||
mentions: List<Mention>,
|
||||
bodyRanges: BodyRangeList?,
|
||||
contacts: List<Contact>
|
||||
contacts: List<Contact>,
|
||||
linkPreviews: List<LinkPreview>
|
||||
): Completable {
|
||||
val sendCompletable = Completable.create { emitter ->
|
||||
if (body.isEmpty() && slideDeck?.containsMediaSlide() != true) {
|
||||
@@ -218,7 +220,8 @@ class ConversationRepository(
|
||||
outgoingQuote = quote,
|
||||
messageToEdit = messageToEdit?.id ?: 0,
|
||||
mentions = mentions,
|
||||
sharedContacts = contacts
|
||||
sharedContacts = contacts,
|
||||
linkPreviews = linkPreviews
|
||||
)
|
||||
|
||||
MessageSender.send(
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview
|
||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestRepository
|
||||
import org.thoughtcrime.securesms.messagerequests.MessageRequestState
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
@@ -297,7 +298,8 @@ class ConversationViewModel(
|
||||
quote: QuoteModel?,
|
||||
mentions: List<Mention>,
|
||||
bodyRanges: BodyRangeList?,
|
||||
contacts: List<Contact>
|
||||
contacts: List<Contact>,
|
||||
linkPreviews: List<LinkPreview>
|
||||
): Completable {
|
||||
return repository.sendMessage(
|
||||
threadId = threadId,
|
||||
@@ -310,7 +312,8 @@ class ConversationViewModel(
|
||||
quote = quote,
|
||||
mentions = mentions,
|
||||
bodyRanges = bodyRanges,
|
||||
contacts = contacts
|
||||
contacts = contacts,
|
||||
linkPreviews = linkPreviews
|
||||
).observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user