Remove remnants of token and credential passing
This commit is contained in:
parent
dfb452113d
commit
e41e5b4f19
@ -57,8 +57,6 @@ data class PhotoData(
|
||||
|
||||
class PostCreationActivity : BaseActivity() {
|
||||
|
||||
private lateinit var accessToken: String
|
||||
|
||||
private var user: UserDatabaseEntity? = null
|
||||
private lateinit var instance: InstanceDatabaseEntity
|
||||
|
||||
@ -84,8 +82,6 @@ class PostCreationActivity : BaseActivity() {
|
||||
// get image URIs
|
||||
intent.clipData?.let { addPossibleImages(it) }
|
||||
|
||||
accessToken = user?.accessToken.orEmpty()
|
||||
|
||||
val carousel: ImageCarousel = binding.carousel
|
||||
carousel.addData(photoData.map { CarouselItem(it.imageUri) })
|
||||
carousel.layoutCarouselCallback = {
|
||||
|
@ -54,7 +54,6 @@ fun parseHTMLText(
|
||||
mentions: List<Mention>?,
|
||||
api : PixelfedAPI,
|
||||
context: Context,
|
||||
credential: String,
|
||||
lifecycleScope: LifecycleCoroutineScope
|
||||
) : Spanned {
|
||||
//Convert text to spannable
|
||||
@ -108,7 +107,7 @@ fun parseHTMLText(
|
||||
Log.e("MENTION", "CLICKED")
|
||||
//Retrieve the account for the given profile
|
||||
lifecycleScope.launchWhenCreated {
|
||||
openAccountFromId(accountId, api, context, credential)
|
||||
openAccountFromId(accountId, api, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import java.io.IOException
|
||||
|
||||
class PostActivity : BaseActivity() {
|
||||
lateinit var domain : String
|
||||
private lateinit var accessToken : String
|
||||
|
||||
private lateinit var binding: ActivityPostBinding
|
||||
|
||||
@ -45,7 +44,6 @@ class PostActivity : BaseActivity() {
|
||||
val user = db.userDao().getActiveUser()
|
||||
|
||||
domain = user?.instance_uri.orEmpty()
|
||||
accessToken = user?.accessToken.orEmpty()
|
||||
|
||||
|
||||
supportActionBar?.title = getString(R.string.post_title).format(status.account?.getDisplayName())
|
||||
@ -54,8 +52,7 @@ class PostActivity : BaseActivity() {
|
||||
|
||||
holder.bind(status, apiHolder.api!!, db, lifecycleScope, displayDimensionsInPx(), isActivity = true)
|
||||
|
||||
val credential = "Bearer $accessToken"
|
||||
activateCommenter(credential)
|
||||
activateCommenter()
|
||||
|
||||
if(viewComments || postComment){
|
||||
//Scroll already down as much as possible (since comments are not loaded yet)
|
||||
@ -68,10 +65,10 @@ class PostActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
// also retrieve comments if we're not posting the comment
|
||||
if(!postComment) retrieveComments(apiHolder.api!!, credential)
|
||||
if(!postComment) retrieveComments(apiHolder.api!!)
|
||||
}
|
||||
binding.postFragmentSingle.viewComments.setOnClickListener {
|
||||
retrieveComments(apiHolder.api!!, credential)
|
||||
retrieveComments(apiHolder.api!!)
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +77,7 @@ class PostActivity : BaseActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun activateCommenter(credential: String) {
|
||||
private fun activateCommenter() {
|
||||
//Activate commenter
|
||||
binding.submitComment.setOnClickListener {
|
||||
val textIn = binding.editComment.text
|
||||
@ -94,15 +91,14 @@ class PostActivity : BaseActivity() {
|
||||
} else {
|
||||
//Post the comment
|
||||
lifecycleScope.launchWhenCreated {
|
||||
apiHolder.api?.let { it1 -> postComment(it1, credential) }
|
||||
apiHolder.api?.let { it1 -> postComment(it1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addComment(context: Context, commentContainer: LinearLayout,
|
||||
commentUsername: String, commentContent: String, mentions: List<Mention>,
|
||||
credential: String) {
|
||||
commentUsername: String, commentContent: String, mentions: List<Mention>) {
|
||||
|
||||
|
||||
val itemBinding = CommentBinding.inflate(
|
||||
@ -115,12 +111,11 @@ class PostActivity : BaseActivity() {
|
||||
mentions,
|
||||
apiHolder.api!!,
|
||||
context,
|
||||
credential,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
|
||||
private fun retrieveComments(api: PixelfedAPI, credential: String) {
|
||||
private fun retrieveComments(api: PixelfedAPI) {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
status.id.let {
|
||||
try {
|
||||
@ -130,8 +125,12 @@ class PostActivity : BaseActivity() {
|
||||
|
||||
//Create the new views for each comment
|
||||
for (status in statuses) {
|
||||
addComment(binding.root.context, binding.commentContainer, status.account!!.username!!,
|
||||
status.content!!, status.mentions.orEmpty(), credential
|
||||
addComment(
|
||||
binding.root.context,
|
||||
binding.commentContainer,
|
||||
status.account!!.username!!,
|
||||
status.content!!,
|
||||
status.mentions.orEmpty()
|
||||
)
|
||||
}
|
||||
binding.commentContainer.visibility = View.VISIBLE
|
||||
@ -149,7 +148,6 @@ class PostActivity : BaseActivity() {
|
||||
|
||||
private suspend fun postComment(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
) {
|
||||
val textIn = binding.editComment.text
|
||||
val nonNullText = textIn.toString()
|
||||
@ -161,7 +159,7 @@ class PostActivity : BaseActivity() {
|
||||
//Add the comment to the comment section
|
||||
addComment(
|
||||
binding.root.context, binding.commentContainer, response.account!!.username!!,
|
||||
response.content!!, response.mentions.orEmpty(), credential
|
||||
response.content!!, response.mentions.orEmpty()
|
||||
)
|
||||
|
||||
Toast.makeText(
|
||||
|
@ -24,10 +24,6 @@ class ReportActivity : BaseActivity() {
|
||||
|
||||
val status = intent.getSerializableExtra(Status.POST_TAG) as Status?
|
||||
|
||||
//get the currently active user
|
||||
val user = db.userDao().getActiveUser()
|
||||
|
||||
|
||||
binding.reportTargetTextview.text = getString(R.string.report_target).format(status?.account?.acct)
|
||||
|
||||
|
||||
@ -37,7 +33,6 @@ class ReportActivity : BaseActivity() {
|
||||
|
||||
binding.textInputLayout.editText?.isEnabled = false
|
||||
|
||||
val accessToken = user?.accessToken.orEmpty()
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
|
@ -178,7 +178,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
|
||||
private fun setDescription(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
lifecycleScope: LifecycleCoroutineScope
|
||||
) {
|
||||
binding.description.apply {
|
||||
@ -190,7 +189,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
status?.mentions,
|
||||
api,
|
||||
binding.root.context,
|
||||
credential,
|
||||
lifecycleScope
|
||||
)
|
||||
movementMethod = LinkMovementMethod.getInstance()
|
||||
@ -204,20 +202,15 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
lifecycleScope: LifecycleCoroutineScope,
|
||||
isActivity: Boolean
|
||||
){
|
||||
val user = db.userDao().getActiveUser()!!
|
||||
|
||||
val credential = "Bearer ${user.accessToken}"
|
||||
//Set the special HTML text
|
||||
setDescription(api, credential, lifecycleScope)
|
||||
setDescription(api, lifecycleScope)
|
||||
|
||||
//Activate onclickListeners
|
||||
activateLiker(
|
||||
api, credential, status?.favourited ?: false,
|
||||
lifecycleScope
|
||||
api, status?.favourited ?: false, lifecycleScope
|
||||
)
|
||||
activateReblogger(
|
||||
api, credential, status?.reblogged ?: false,
|
||||
lifecycleScope
|
||||
api, status?.reblogged ?: false, lifecycleScope
|
||||
)
|
||||
|
||||
if(isActivity){
|
||||
@ -242,7 +235,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
|
||||
private fun activateReblogger(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
isReblogged: Boolean,
|
||||
lifecycleScope: LifecycleCoroutineScope
|
||||
) {
|
||||
@ -255,10 +247,10 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
lifecycleScope.launchWhenCreated {
|
||||
if (buttonState) {
|
||||
// Button is active
|
||||
undoReblogPost(api, credential)
|
||||
undoReblogPost(api)
|
||||
} else {
|
||||
// Button is inactive
|
||||
reblogPost(api, credential)
|
||||
reblogPost(api)
|
||||
}
|
||||
}
|
||||
//show animation or not?
|
||||
@ -267,10 +259,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun reblogPost(
|
||||
api: PixelfedAPI,
|
||||
credential: String
|
||||
) {
|
||||
private suspend fun reblogPost(api: PixelfedAPI) {
|
||||
//Call the api function
|
||||
status?.id?.let {
|
||||
|
||||
@ -290,14 +279,11 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun undoReblogPost(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
) {
|
||||
private suspend fun undoReblogPost(api: PixelfedAPI) {
|
||||
//Call the api function
|
||||
status?.id?.let {
|
||||
try {
|
||||
val resp = api.undoReblogStatus(credential)
|
||||
val resp = api.undoReblogStatus(it)
|
||||
|
||||
//Update shown share count
|
||||
binding.nshares.text = resp.getNShares(binding.root.context)
|
||||
@ -440,7 +426,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
|
||||
private fun activateLiker(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
isLiked: Boolean,
|
||||
lifecycleScope: LifecycleCoroutineScope
|
||||
) {
|
||||
@ -454,10 +439,10 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
lifecycleScope.launchWhenCreated {
|
||||
if (buttonState) {
|
||||
// Button is active, unlike
|
||||
unLikePostCall(api, credential)
|
||||
unLikePostCall(api)
|
||||
} else {
|
||||
// Button is inactive, like
|
||||
likePostCall(api, credential)
|
||||
likePostCall(api)
|
||||
}
|
||||
}
|
||||
//show animation or not?
|
||||
@ -476,12 +461,12 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
if (binding.liker.isChecked) {
|
||||
// Button is active, unlike
|
||||
binding.liker.isChecked = false
|
||||
unLikePostCall(api, credential)
|
||||
unLikePostCall(api)
|
||||
} else {
|
||||
// Button is inactive, like
|
||||
binding.liker.playAnimation()
|
||||
binding.liker.isChecked = true
|
||||
likePostCall(api, credential)
|
||||
likePostCall(api)
|
||||
}
|
||||
} else {
|
||||
clicked = true
|
||||
@ -495,10 +480,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun likePostCall(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
) {
|
||||
private suspend fun likePostCall(api: PixelfedAPI) {
|
||||
//Call the api function
|
||||
status?.id?.let {
|
||||
|
||||
@ -518,10 +500,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun unLikePostCall(
|
||||
api: PixelfedAPI,
|
||||
credential: String,
|
||||
) {
|
||||
private suspend fun unLikePostCall(api: PixelfedAPI) {
|
||||
//Call the api function
|
||||
status?.id?.let {
|
||||
|
||||
|
@ -166,7 +166,6 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
|
||||
fun bind(
|
||||
notification: Notification?,
|
||||
api: PixelfedAPI,
|
||||
accessToken: String,
|
||||
lifecycleScope: LifecycleCoroutineScope
|
||||
) {
|
||||
|
||||
@ -208,7 +207,6 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
|
||||
notification?.status?.mentions,
|
||||
api,
|
||||
itemView.context,
|
||||
"Bearer $accessToken",
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
@ -258,7 +256,6 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
|
||||
(holder as NotificationViewHolder).bind(
|
||||
it,
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
lifecycleScope
|
||||
)
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ class NotificationsRemoteMediator @Inject constructor(
|
||||
val user = db.userDao().getActiveUser()
|
||||
?: return MediatorResult.Error(NullPointerException("No active user exists"))
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
val accessToken = user.accessToken
|
||||
|
||||
val apiResponse = api.notifications(
|
||||
max_id = max_id,
|
||||
|
@ -44,7 +44,6 @@ class HomeFeedRemoteMediator @Inject constructor(
|
||||
val user = db.userDao().getActiveUser()
|
||||
?: return MediatorResult.Error(NullPointerException("No active user exists"))
|
||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
val accessToken = user.accessToken
|
||||
|
||||
val apiResponse = api.timelineHome(
|
||||
max_id= max_id,
|
||||
|
@ -55,7 +55,6 @@ class AccountListFragment : UncachedFeedFragment<Account>() {
|
||||
viewModel = ViewModelProvider(this, ViewModelFactory(
|
||||
FollowersContentRepository(
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
id,
|
||||
following
|
||||
)
|
||||
|
@ -14,7 +14,6 @@ import javax.inject.Inject
|
||||
class FollowersContentRepository @ExperimentalPagingApi
|
||||
@Inject constructor(
|
||||
private val api: PixelfedAPI,
|
||||
private val accessToken: String,
|
||||
private val accountId: String,
|
||||
private val following: Boolean,
|
||||
): UncachedContentRepository<Account> {
|
||||
@ -25,7 +24,7 @@ class FollowersContentRepository @ExperimentalPagingApi
|
||||
pageSize = NETWORK_PAGE_SIZE,
|
||||
enablePlaceholders = false),
|
||||
pagingSourceFactory = {
|
||||
FollowersPagingSource(api, accessToken, accountId, following)
|
||||
FollowersPagingSource(api, accountId, following)
|
||||
}
|
||||
).flow
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import java.io.IOException
|
||||
|
||||
class FollowersPagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
private val accessToken: String,
|
||||
private val accountId: String,
|
||||
private val following: Boolean
|
||||
) : PagingSource<String, Account>() {
|
||||
|
@ -13,7 +13,6 @@ import javax.inject.Inject
|
||||
class ProfileContentRepository @ExperimentalPagingApi
|
||||
@Inject constructor(
|
||||
private val api: PixelfedAPI,
|
||||
private val accessToken: String,
|
||||
private val accountId: String
|
||||
) : UncachedContentRepository<Status> {
|
||||
override fun getStream(): Flow<PagingData<Status>> {
|
||||
@ -23,7 +22,7 @@ class ProfileContentRepository @ExperimentalPagingApi
|
||||
pageSize = NETWORK_PAGE_SIZE,
|
||||
enablePlaceholders = false),
|
||||
pagingSourceFactory = {
|
||||
ProfilePagingSource(api, accessToken, accountId)
|
||||
ProfilePagingSource(api, accountId)
|
||||
}
|
||||
).flow
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import java.io.IOException
|
||||
|
||||
class ProfilePagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
private val accessToken: String,
|
||||
private val accountId: String
|
||||
) : PagingSource<String, Status>() {
|
||||
override suspend fun load(params: LoadParams<String>): LoadResult<String, Status> {
|
||||
|
@ -41,7 +41,6 @@ class SearchAccountFragment : UncachedFeedFragment<Account>() {
|
||||
SearchContentRepository<Account>(
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
Results.SearchType.accounts,
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
query
|
||||
)
|
||||
)
|
||||
|
@ -22,7 +22,6 @@ class SearchContentRepository<T: FeedContent> @ExperimentalPagingApi
|
||||
@Inject constructor(
|
||||
private val api: PixelfedAPI,
|
||||
private val type: Results.SearchType,
|
||||
private val accessToken: String,
|
||||
private val query: String,
|
||||
): UncachedContentRepository<T> {
|
||||
override fun getStream(): Flow<PagingData<T>> {
|
||||
@ -32,7 +31,7 @@ class SearchContentRepository<T: FeedContent> @ExperimentalPagingApi
|
||||
pageSize = NETWORK_PAGE_SIZE,
|
||||
enablePlaceholders = false),
|
||||
pagingSourceFactory = {
|
||||
SearchPagingSource<T>(api, query, type, accessToken)
|
||||
SearchPagingSource<T>(api, query, type)
|
||||
}
|
||||
).flow
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ class SearchHashtagFragment : UncachedFeedFragment<Tag>() {
|
||||
SearchContentRepository<Tag>(
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
Results.SearchType.hashtags,
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
query
|
||||
)
|
||||
)
|
||||
|
@ -15,7 +15,6 @@ class SearchPagingSource<T: FeedContent>(
|
||||
private val api: PixelfedAPI,
|
||||
private val query: String,
|
||||
private val type: Results.SearchType,
|
||||
private val accessToken: String,
|
||||
) : PagingSource<Int, T>() {
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, T> {
|
||||
val position = params.key
|
||||
|
@ -45,7 +45,6 @@ class SearchPostsFragment : UncachedFeedFragment<Status>() {
|
||||
SearchContentRepository<Status>(
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
Results.SearchType.statuses,
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
query
|
||||
)
|
||||
)
|
||||
|
@ -45,7 +45,6 @@ import java.io.IOException
|
||||
class ProfileActivity : BaseActivity() {
|
||||
|
||||
private lateinit var pixelfedAPI : PixelfedAPI
|
||||
private lateinit var accessToken : String
|
||||
private lateinit var domain : String
|
||||
private lateinit var accountId : String
|
||||
private lateinit var binding: ActivityProfileBinding
|
||||
@ -67,7 +66,6 @@ class ProfileActivity : BaseActivity() {
|
||||
|
||||
domain = user?.instance_uri.orEmpty()
|
||||
pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
accessToken = user?.accessToken.orEmpty()
|
||||
|
||||
// Set profile according to given account
|
||||
val account = intent.getSerializableExtra(Account.ACCOUNT_TAG) as Account?
|
||||
@ -77,9 +75,8 @@ class ProfileActivity : BaseActivity() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
viewModel = ViewModelProvider(this, ProfileViewModelFactory(
|
||||
ProfileContentRepository(
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
db.userDao().getActiveUser()!!.accessToken,
|
||||
accountId
|
||||
apiHolder.setDomainToCurrentUser(db),
|
||||
accountId
|
||||
)
|
||||
)
|
||||
).get(FeedViewModel::class.java) as FeedViewModel<Status>
|
||||
@ -163,7 +160,7 @@ class ProfileActivity : BaseActivity() {
|
||||
|
||||
binding.descriptionTextView.text = parseHTMLText(
|
||||
account.note ?: "", emptyList(), pixelfedAPI,
|
||||
applicationContext, "Bearer $accessToken",
|
||||
applicationContext,
|
||||
lifecycleScope
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,6 @@ class SearchDiscoverFragment : BaseFragment() {
|
||||
private lateinit var api: PixelfedAPI
|
||||
private lateinit var recycler : RecyclerView
|
||||
private lateinit var adapter : DiscoverRecyclerViewAdapter
|
||||
private lateinit var accessToken: String
|
||||
|
||||
var binding: FragmentSearchBinding by bindingLifecycleAware()
|
||||
|
||||
@ -62,8 +61,6 @@ class SearchDiscoverFragment : BaseFragment() {
|
||||
|
||||
api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||
|
||||
accessToken = db.userDao().getActiveUser()?.accessToken.orEmpty()
|
||||
|
||||
getDiscover()
|
||||
|
||||
binding.discoverRefreshLayout.setOnRefreshListener {
|
||||
|
@ -51,7 +51,7 @@ data class Account(
|
||||
/**
|
||||
* @brief Opens an activity of the profile with the given id
|
||||
*/
|
||||
suspend fun openAccountFromId(id: String, api : PixelfedAPI, context: Context, credential: String) {
|
||||
suspend fun openAccountFromId(id: String, api : PixelfedAPI, context: Context) {
|
||||
val account = try {
|
||||
api.getAccount(id)
|
||||
} catch (exception: IOException) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user