private MetaList<Tweet> getSavedSearchFromTwitter(int searchId, boolean fromDbOnly) { MetaList<Tweet> messages; Paging paging = new Paging(); paging.setCount(20); messages = th.getSavedSearchesTweets(searchId, fromDbOnly, paging); tweets = messages.getList(); return messages; }
/** * Retrieve a list of statuses. Depending on listId, this is taken from different sources: * * <ul> * <li>0 : home timeline * <li>-1 : mentions * <li>>0 : User list * </ul> * * This method may trigger a network call if fromDbOnly is false. The filter if not null is a * regular expression, that if matches filters the tweet. * * @param fromDbOnly If true only statuses already in the DB are returned * @param listId Id of the list / timeline to fetch (see above) * @param updateStatusList Should the currently displayed list be updated? * @return List of status items along with some counts */ private MetaList<Status> getTimlinesFromTwitter( boolean fromDbOnly, int listId, boolean updateStatusList) { Paging paging = new Paging(); MetaList<Status> myStatuses; long last = tdb.getLastRead(account.getId(), listId); if (last > 0) // && !Debug.isDebuggerConnected()) paging.sinceId(last).setCount(200); else paging.setCount(50); // 50 Tweets if we don't have the timeline yet switch (listId) { case 0: // Home time line myStatuses = th.getTimeline(paging, listId, fromDbOnly); break; case -1: myStatuses = th.getTimeline(paging, listId, fromDbOnly); break; case -2: // see below at getDirectsFromTwitter myStatuses = new MetaList<Status>(); break; case -3: myStatuses = th.getTimeline(paging, listId, fromDbOnly); break; case -4: myStatuses = th.getTimeline(paging, listId, fromDbOnly); break; default: myStatuses = th.getUserList(paging, listId, fromDbOnly, unreadCount); if (unreadCount > -1) { List<Status> list = myStatuses.getList(); if (list.size() <= unreadCount) unreadCount = list.size() - 1; if (unreadCount > -1) last = list.get(unreadCount).getId(); } break; } long newLast = -1; // Update the 'since' id in the database if (myStatuses.getList().size() > 0) { newLast = myStatuses .getList() .get(0) .getId(); // assumption is that twitter sends the newest (=highest id) first tdb.updateOrInsertLastRead(account.getId(), listId, newLast); } // Sync with TweetMarker long newLast2 = -1; if (listId >= 0 && !account.isStatusNet() && !fromDbOnly) { if (listId == 0) newLast2 = TweetMarkerSync.syncFromTweetMarker("timeline", account.getName()); else newLast2 = TweetMarkerSync.syncFromTweetMarker("lists." + listId, account.getName()); if (newLast2 > newLast) { tdb.updateOrInsertLastRead(account.getId(), listId, newLast2); } else { if (listId == 0) TweetMarkerSync.syncToTweetMarker("timeline", newLast, account.getName(), th.getOAuth()); else TweetMarkerSync.syncToTweetMarker( "lists." + listId, newLast, account.getName(), th.getOAuth()); } } MetaList<Status> metaList; if (updateStatusList) { statuses = new ArrayList<Status>(); List<Status> data = new ArrayList<Status>(myStatuses.getList().size()); if (filterPattern == null) { setupFilter(); // TODO report errors? } for (Status status : myStatuses.getList()) { boolean shouldFilter = matchesFilter(status); if (shouldFilter) { Log.i( "TweetListActivity::filter, filtered ", status.getUser().getScreenName() + " - " + status.getText()); } else { data.add(status); statuses.add(status); } } metaList = new MetaList<Status>(data, myStatuses.getNumOriginal(), myStatuses.getNumAdded()); } else { metaList = new MetaList<Status>(new ArrayList<Status>(), 0, 0); } if (newLast2 > last) { metaList.oldLast = newLast2; // the read status from remote is newer than the last read locally, so lets mark those in // between as read for (Status s : statuses) { long id = s.getId(); if (id > last) { th.markStatusAsOld(id); } } } else { metaList.oldLast = last; } for (Status status : metaList.getList()) { AccountHolder accountHolder = AccountHolder.getInstance(); accountHolder.addUserName(status.getUser().getScreenName()); if (status.getHashtagEntities() != null) { for (HashtagEntity hte : status.getHashtagEntities()) { accountHolder.addHashTag(hte.getText()); } } } return metaList; }