improved conversation loader

This commit is contained in:
Mariotaku Lee 2016-02-12 01:04:18 +08:00
parent 0c91cace96
commit d8ce5acac1
1 changed files with 7 additions and 10 deletions

View File

@ -28,7 +28,6 @@ import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.api.twitter.model.SearchQuery;
import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.StatusUtils;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
import org.mariotaku.twidere.util.Nullables;
@ -64,10 +63,10 @@ public class ConversationLoader extends TwitterAPIStatusesLoader {
}
final List<Status> statuses = new ArrayList<>();
final long maxId = getMaxId(), sinceId = getSinceId();
boolean getConversations = maxId < status.id || (maxId <= 0 && sinceId <= 0);
boolean getReplies = sinceId > status.id || (maxId <= 0 && sinceId <= 0);
if (getConversations) {
long inReplyToId = status.in_reply_to_status_id;
final boolean noSinceMaxId = maxId <= 0 && sinceId <= 0;
// Load conversations
if ((maxId > 0 && maxId < status.id) || noSinceMaxId) {
long inReplyToId = maxId > 0 ? maxId : status.in_reply_to_status_id;
int count = 0;
while (inReplyToId > 0 && count < 10) {
final Status item = twitter.showStatus(inReplyToId);
@ -76,17 +75,15 @@ public class ConversationLoader extends TwitterAPIStatusesLoader {
count++;
}
}
if ((sinceId <= 0 && maxId <= 0) || (sinceId > 0 && sinceId < status.id) || (maxId > 0 && maxId >= status.id)) {
// statuses.add(StatusUtils.fromParcelableStatus(status));
}
if (getReplies) {
// Load replies
if ((sinceId > 0 && sinceId > status.id) || noSinceMaxId) {
SearchQuery query = new SearchQuery();
if (mTwitterOptimizedSearches) {
query.query("to:" + status.user_screen_name);
} else {
query.query("@" + status.user_screen_name);
}
query.sinceId(status.id);
query.sinceId(sinceId > 0 ? sinceId : status.id);
try {
for (Status item : twitter.search(query)) {
if (item.getInReplyToStatusId() == status.id) {