return;
}
}
PersistenceManager pm = SingletonPersistenceManagerFactory.get().getPersistenceManager();
TwitterWave twitterWave =
TwitterWave.getTwitterWave(pm, wavelet.getWaveId(), wavelet.getWaveletId(), wavelet
.getCreator());
try {
// When user logs in via the popup, finish OAuth by exchanging
// request token for an access token.
for (Event event : robotMessageBundle.getEvents()) {
if (event.getType() == EventType.DOCUMENT_CHANGED) {
// Get all the gadgets in the wave (typically only be one).
TextView document = wavelet.getRootBlip().getDocument();
GadgetView gadgetView = document.getGadgetView();
for (Gadget gadget : gadgetView.getGadgets()) {
if ((gadget != null) && ("true".equals(gadget.getField(GADGET_STATE)))) {
if (twitterService.checkAuthorization(wavelet, loginForm)) {
FetchController controller =
twitterWave.isInSearchMode() ? new SearchController(twitterService, rootBlip,
twitterWave, robotMessageBundle.getEvents()) : new TimelineController(
twitterService, rootBlip, twitterWave, robotMessageBundle.getEvents());
// Fetch and append tweets.
appendTweets(wavelet, controller.fetch());
// Clear the login form and render the search or update form.
controller.renderForm();
}
}
}
}
if (event.getType() == EventType.FORM_BUTTON_CLICKED ||
event.getType() == EventType.BLIP_SUBMITTED) {
// Handle the normal flow after logging in.
FetchController controller =
twitterWave.isInSearchMode() ? new SearchController(twitterService, rootBlip,
twitterWave, robotMessageBundle.getEvents()) : new TimelineController(
twitterService, rootBlip, twitterWave, robotMessageBundle.getEvents());
// Fetch tweets when search or update button is clicked.
if (controller.isButtonClicked()) {