// Fetch new tweets from Twitter.
List<Tweet> newTweets = controller.fetch();
appendTweets(wavelet, newTweets);
// Update the latest tweet id, and purge the cache.
WaveSubmittedTweetsCache cache = new WaveSubmittedTweetsCache();
if (!newTweets.isEmpty()) {
twitterWave.setLatestTweetId(newTweets.get(0).getId());
cache.purge(twitterWave.getWaveId(), twitterWave.getLatestTweetId());
} else {
String lastTweetSubmitted = cache.last(twitterWave.getWaveId());
if (!Util.isEmpty(lastTweetSubmitted) &&
lastTweetSubmitted.compareTo(twitterWave.getLatestTweetId()) > 0) {
twitterWave.setLatestTweetId(lastTweetSubmitted);
cache.purge(twitterWave.getWaveId(), lastTweetSubmitted);
}
}
} catch (IOException e) {
LOG.warning("There is a problem connecting to Twitter. Cause:" + e.getMessage());
} catch (JSONException e) {