mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-19 11:39:52 +01:00
reduced rate limit when add/remove users from lists #694
This commit is contained in:
parent
20ac36c07b
commit
702832cbe4
@ -83,9 +83,11 @@ import org.mariotaku.chameleon.Chameleon
|
||||
import org.mariotaku.chameleon.ChameleonUtils
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.ktextension.*
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.FriendshipUpdate
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.UserList
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.AccountSelectorActivity
|
||||
@ -915,21 +917,38 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
ProgressDialogFragment.show(fragmentManager, "get_list_progress")
|
||||
}
|
||||
}.then {
|
||||
fun MicroBlog.getUserListOwnerMemberships(id: String): ArrayList<UserList> {
|
||||
val result = ArrayList<UserList>()
|
||||
var nextCursor: Long
|
||||
val paging = Paging()
|
||||
paging.count(100)
|
||||
do {
|
||||
val resp = getUserListMemberships(user.key.id, paging, true)
|
||||
result.addAll(resp)
|
||||
nextCursor = resp.nextCursor
|
||||
paging.cursor(nextCursor)
|
||||
} while (nextCursor > 0)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
val microBlog = MicroBlogAPIFactory.getInstance(context, user.account_key)
|
||||
val ownedLists = ArrayList<ParcelableUserList>()
|
||||
val listMemberships = microBlog.getUserListOwnerMemberships(user.key.id)
|
||||
val paging = Paging()
|
||||
val ownedLists = microBlog.getUserListOwnerships(paging)
|
||||
var nextCursor = ownedLists.nextCursor
|
||||
while (nextCursor != 0L) {
|
||||
val list = microBlog.getUserListOwnerships(paging)
|
||||
ownedLists.addAll(list)
|
||||
nextCursor = list.nextCursor
|
||||
}
|
||||
val userListMemberships = microBlog.getUserListMemberships(user.key.id, null, true)
|
||||
return@then Array<ParcelableUserList>(ownedLists.size) { idx ->
|
||||
val list = ParcelableUserListUtils.from(ownedLists[idx], user.account_key)
|
||||
list.is_user_inside = userListMemberships.firstOrNull { it.id == ownedLists[idx].id } != null
|
||||
return@Array list
|
||||
}
|
||||
paging.count(100)
|
||||
var nextCursor: Long
|
||||
do {
|
||||
val resp = microBlog.getUserListOwnerships(paging)
|
||||
resp.mapTo(ownedLists) { item ->
|
||||
val userList = ParcelableUserListUtils.from(item, user.account_key)
|
||||
userList.is_user_inside = listMemberships.any { it.id == item.id }
|
||||
return@mapTo userList
|
||||
}
|
||||
nextCursor = resp.nextCursor
|
||||
paging.cursor(nextCursor)
|
||||
} while (nextCursor > 0)
|
||||
return@then ownedLists.toTypedArray()
|
||||
}.alwaysUi {
|
||||
executeAfterFragmentResumed {
|
||||
val df = fragmentManager.findFragmentByTag("get_list_progress") as? DialogFragment
|
||||
|
Loading…
Reference in New Issue
Block a user