Skip to content

Commit

Permalink
feat: NoteクラスのgetOriginUrlを使用するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jan 6, 2024
1 parent e3f5836 commit 7dc246c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ class NoteDetailFragment : Fragment(R.layout.fragment_note_detail) {

binding.showInBrowser.setOnClickListener {
viewLifecycleOwner.lifecycleScope.launch {
val url = noteDetailViewModel.getUrl()
showShareLink(url)
noteDetailViewModel.getUrl().onSuccess { url ->
showShareLink(url)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import net.pantasystem.milktea.common.Logger
import net.pantasystem.milktea.model.account.Account
import net.pantasystem.milktea.common.runCancellableCatching
import net.pantasystem.milktea.model.account.AccountRepository
import net.pantasystem.milktea.model.account.CurrentAccountWatcher
import net.pantasystem.milktea.model.account.page.Pageable
Expand Down Expand Up @@ -126,12 +126,11 @@ class NoteDetailViewModel @Inject constructor(

}

suspend fun getUrl(): String {
suspend fun getUrl(): Result<String> = runCancellableCatching {
val account = currentAccountWatcher.getAccount()
return when(account.instanceType) {
Account.InstanceType.MISSKEY, Account.InstanceType.FIREFISH -> "${account.normalizedInstanceUri}/notes/${pageable.noteId}"
Account.InstanceType.PLEROMA, Account.InstanceType.MASTODON -> "${account.normalizedInstanceUri}/web/statuses/${pageable.noteId}"
}
val note = noteRepository.find(Note.Id(account.accountId, pageable.noteId))
.getOrThrow()
note.getOriginUrl(account)
}


Expand Down

0 comments on commit 7dc246c

Please sign in to comment.