/**
   * This method will be called when a list of options is posted to the EventBus.
   *
   * @param event The bus event containing a list of ballot options objects.
   */
  public void onEventMainThread(BusEventOptions event) {
    // Unregister this instance. For new push messages the new instance will be registered in
    // onCreate().
    EventBus.getDefault().unregister(this);
    Log.d(TAG, event.toString());
    List<Option> options = event.getOptions();

    boolean newOptions =
        GroupController.storeOptions(getApplicationContext(), options, pushMessage.getId2());
    boolean newVotes = GroupController.storeVoters(getApplicationContext(), options);

    if (newVotes || newOptions) {
      NotificationSettings notificationSettings =
          settingsDBM.getGroupNotificationSettings(pushMessage.getId1());
      if (notificationSettings == NotificationSettings.GENERAL) {
        notificationSettings = settingsDBM.getSettings().getNotificationSettings();
      }
      if (notificationSettings.equals(NotificationSettings.ALL)) {
        sendOptionNotification(pushMessage.getId1(), pushMessage.getId2());
      }
      new GroupDatabaseManager(getApplicationContext())
          .setGroupNewEvents(pushMessage.getId1(), true);
    }
  }
 /**
  * This method will be called when conversation messages are posted to the EventBus.
  *
  * @param event The bus event containing conversation message objects.
  */
 public void onEvent(BusEventConversationMessages event) {
   // Unregister this instance. For new push messages the new instance will be registered in
   // onCreate().
   EventBus.getDefault().unregister(this);
   Log.d(TAG, event.toString());
   List<ConversationMessage> conversationMessages = event.getConversationMessages();
   // Store new conversation messages in database.
   GroupDatabaseManager groupDBM = new GroupDatabaseManager(getApplicationContext());
   for (ConversationMessage cm : conversationMessages) {
     groupDBM.storeConversationMessage(cm);
   }
   if (!conversationMessages.isEmpty()) {
     groupDBM.setGroupNewEvents(pushMessage.getId1(), true);
     NotificationSettings notificationSettings =
         settingsDBM.getGroupNotificationSettings(pushMessage.getId1());
     if (notificationSettings == NotificationSettings.GENERAL) {
       notificationSettings = settingsDBM.getSettings().getNotificationSettings();
     }
     if (!notificationSettings.equals(NotificationSettings.NONE)) {
       sendNewConversationMessageNotification(pushMessage.getId1(), pushMessage.getId2());
     }
   }
 }
 /** Load data described by push message. */
 private void handlePushMessage() {
   int messageNumber;
   NotificationSettings notificationSettings;
   switch (pushMessage.getPushType()) {
     case ANNOUNCEMENT_NEW:
       // Load new announcements from server.
       messageNumber =
           new ChannelDatabaseManager(getApplicationContext())
               .getMaxMessageNumberAnnouncement(pushMessage.getId1());
       ChannelAPI.getInstance(getApplicationContext())
           .getAnnouncements(pushMessage.getId1(), messageNumber);
       break;
     case CHANNEL_DELETED:
       // Mark local channel as deleted.
       int channelId = pushMessage.getId1();
       ChannelController.deleteChannel(getApplicationContext(), channelId);
       // Notify user as if this push message had the priority HIGH.
       notificationSettings = settingsDBM.getChannelNotificationSettings(channelId);
       if (notificationSettings == NotificationSettings.GENERAL) {
         notificationSettings = settingsDBM.getSettings().getNotificationSettings();
       }
       if (!notificationSettings.equals(NotificationSettings.NONE)) {
         sendChannelDeletedNotification(channelId);
       }
       break;
     case CHANNEL_CHANGED:
       // Load updated channel data from server.
       ChannelAPI.getInstance(getApplicationContext()).getChannel(pushMessage.getId1());
       break;
     case MODERATOR_ADDED:
     case MODERATOR_CHANGED:
     case MODERATOR_REMOVED:
       // Refresh responsible moderator data.
       ChannelAPI.getInstance(this).getResponsibleModerators(pushMessage.getId1());
       break;
     case CONVERSATION_CHANGED:
     case CONVERSATION_CLOSED:
       GroupAPI.getInstance(getApplicationContext())
           .getConversation(pushMessage.getId1(), pushMessage.getId2());
       break;
     case CONVERSATION_CHANGED_ALL:
     case CONVERSATION_NEW:
       GroupAPI.getInstance(getApplicationContext()).getConversations(pushMessage.getId1());
       break;
     case CONVERSATION_MESSAGE_NEW:
       // Get conversation message data. Request new messages only.
       messageNumber =
           new GroupDatabaseManager(getApplicationContext())
               .getMaxMessageNumberConversationMessage(pushMessage.getId2());
       GroupAPI.getInstance(this)
           .getConversationMessages(pushMessage.getId1(), pushMessage.getId2(), messageNumber);
       break;
     case CONVERSATION_DELETED:
       notificationSettings = settingsDBM.getGroupNotificationSettings(pushMessage.getId1());
       if (notificationSettings == NotificationSettings.GENERAL) {
         notificationSettings = settingsDBM.getSettings().getNotificationSettings();
       }
       if (!notificationSettings.equals(NotificationSettings.NONE)) {
         sendConversationNotification(pushMessage.getId1());
       }
       new GroupDatabaseManager(getApplicationContext()).deleteConversation(pushMessage.getId2());
       new GroupDatabaseManager(getApplicationContext())
           .setGroupNewEvents(pushMessage.getId1(), true);
       break;
     case PARTICIPANT_NEW:
     case PARTICIPANT_CHANGED:
     case PARTICIPANT_LEFT:
     case PARTICIPANT_REMOVED:
       GroupAPI.getInstance(this).getGroupMembers(pushMessage.getId1());
       break;
     case BALLOT_NEW:
     case BALLOT_CHANGED:
     case BALLOT_CHANGED_ALL:
       GroupAPI.getInstance(this).getBallots(pushMessage.getId1());
       break;
     case BALLOT_OPTION_DELETED:
     case BALLOT_OPTION_ALL:
       GroupAPI.getInstance(this).getOptions(pushMessage.getId1(), pushMessage.getId2(), true);
       break;
     case BALLOT_OPTION_VOTE:
     case BALLOT_OPTION_VOTE_ALL:
       // Do nothing. Load new votes when user enters ballot screen.
       break;
     case GROUP_CHANGED:
       GroupAPI.getInstance(this).getGroup(pushMessage.getId1());
       break;
   }
 }