code: public Observable<Boolean> upsertConversations(List<ChatConversation> conversationsToAdd) {
  
          return asObservable(new Executor<Boolean>() {
              @Override
              void execute(ChatStore store, Emitter<Boolean> emitter) {
  
                  store.beginTransaction();
  
                  boolean isSuccess = true;
  
                  for (ChatConversation conversation : conversationsToAdd) {
                      ChatConversation.Builder toSave = ChatConversation.builder().populate(conversation);
  
                      ChatConversationBase saved = store.getConversation(conversation.getConversationId());
                      if (saved == null) {
                          toSave.setFirstLocalEventId(-1L);
                          toSave.setLastLocalEventId(-1L);
                          if (conversation.getLastRemoteEventId() == null) {
                              toSave.setLastRemoteEventId(-1L);
                          } else {
                              toSave.setLastRemoteEventId(conversation.getLastRemoteEventId());
                          }
                          if (conversation.getUpdatedOn() == null) {
                              toSave.setUpdatedOn(System.currentTimeMillis());
                          } else {
                              toSave.setUpdatedOn(conversation.getUpdatedOn());
                          }
                      } else {
                          toSave.setFirstLocalEventId(saved.getFirstLocalEventId());
                          toSave.setLastLocalEventId(saved.getLastLocalEventId());
                          if (conversation.getLastRemoteEventId() == null) {
                              toSave.setLastRemoteEventId(saved.getLastRemoteEventId());
                          } else {
                              toSave.setLastRemoteEventId(Math.max(saved.getLastRemoteEventId(), conversation.getLastRemoteEventId()));
                          }
                          if (conversation.getUpdatedOn() == null) {
                              toSave.setUpdatedOn(System.currentTimeMillis());
                          } else {
                              toSave.setUpdatedOn(conversation.getUpdatedOn());
                          }
                      }
  
                      isSuccess = isSuccess && store.upsert(toSave.build());
                  }
  
                  store.endTransaction();
  
                  emitter.onNext(isSuccess);
                  emitter.onCompleted();
              }
          });
      }
docs: Insert or update a list of conversations.
  
  @param conversationsToAdd List of conversations to insert or apply an update.
  @return Observable emitting result.