Updates single conversation state.

@return Result of synchronisation with services.
764905
Observable<ChatResult> synchroniseConversation(String conversationId) {

        return checkState().flatMap(client -> client.service().messaging()
                .queryMessages(conversationId, null, 1)
                .map(result -> {
                    if (result.isSuccessful() && result.getResult() != null) {
                        return (long) result.getResult().getLatestEventId();
                    }
                    return -1L;
                })
                .flatMap(result -> persistenceController.getConversation(conversationId).map(loaded -> compare(result, loaded)))
                .flatMap(this::updateLocalConversationList)
                .flatMap(result -> lookForMissingEvents(client, result))
                .map(result -> new ChatResult(result.isSuccessful, null)));
    }
766472
@Override
	public void update () {
		// Execute the global state (if any)
		if (globalState != null) globalState.update(owner);

		// Execute the current state (if any)
		if (currentState != null) currentState.update(owner);
	}
748929
public function touchCurrentConversation()
    {
        if (! is_null($this->currentConversationData)) {
            $touched = $this->currentConversationData;
            $touched['time'] = microtime();

            $this->cache->put($this->message->getConversationIdentifier(), $touched, $this->config['config']['conversation_cache_time'] ?? 30);
        }
    }
92797
public Observable<ChatResult> handleParticipantsAdded(final String conversationId) {
        return persistenceController.getConversation(conversationId).flatMap(conversation -> {
            if (conversation == null) {
                return handleNoLocalConversation(conversationId);
            } else {
                return Observable.fromCallable(() -> new ChatResult(true, null));
            }
        });
    }
908468
@SuppressLint("UseSparseArrays")
    public void addStatusUpdate(ChatMessageStatus status) {
        int unique = (status.getMessageId() + status.getProfileId() + status.getMessageStatus().name()).hashCode();
        if (statusUpdates == null) {
            statusUpdates = new HashMap<>();
        }
        statusUpdates.put(unique, status);
    }
306523
Observable<ChatResult> handleNoLocalConversation(String conversationId) {

        return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
                .flatMap(result -> {
                    if (result.isSuccessful() && result.getResult() != null) {
                        return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build())
                                .map(success -> new ChatResult(success, success ? null : new ChatResult.Error(0, "External store reported failure.", "Error when inserting conversation "+conversationId)));
                    } else {
                        return Observable.fromCallable(() -> adapter.adaptResult(result));
                    }
                }));
    }
306177
private void updateState(final TaskStatus.State state) {
    statusUpdater.setState(state);
    // Commit and push a new status
    try {
      statusUpdater.update();
    } catch (InterruptedException e) {
      // TODO: propagate interrupt instead?
      Thread.currentThread().interrupt();
    }
  }
938948
private <T> Observable<PollingState<T>> updateStateFromLocationHeaderOnPutAsync(final PollingState<T> pollingState) {
        return pollAsync(pollingState.locationHeaderLink(), pollingState.loggingContext())
                .flatMap(new Func1<Response<ResponseBody>, Observable<PollingState<T>>>() {
                    @Override
                    public Observable<PollingState<T>> call(Response<ResponseBody> response) {
                        int statusCode = response.code();
                        if (statusCode == 202) {
                            pollingState.withResponse(response);
                            pollingState.withStatus(AzureAsyncOperation.IN_PROGRESS_STATUS, statusCode);
                        } else if (statusCode == 200 || statusCode == 201) {
                            try {
                                pollingState.updateFromResponseOnPutPatch(response);
                            } catch (CloudException | IOException e) {
                                return Observable.error(e);
                            }
                        }
                        return Observable.just(pollingState);
                    }
                });
    }
130933
Observable<ChatResult> handleConversationCreated(ComapiResult<ConversationDetails> result) {
        if (result.isSuccessful()) {
            return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build()).map(success -> adapter.adaptResult(result, success));
        } else {
            return Observable.fromCallable(() -> adapter.adaptResult(result));
        }
    }
910564
public Observable<ComapiResult<Void>> updateMessageStatus(@NonNull final String conversationId, @NonNull final List<MessageStatusUpdate> msgStatusList) {

        final String token = getToken();

        if (sessionController.isCreatingSession()) {
            return getTaskQueue().queueUpdateMessageStatus(conversationId, msgStatusList);
        } else if (TextUtils.isEmpty(token)) {
            return Observable.error(getSessionStateErrorDescription());
        } else {
            return doUpdateMessageStatus(token, conversationId, msgStatusList);
        }
    }
515385
private synchronized void refresh() {

        try {
            long now = System.currentTimeMillis();
            if ((now - m_lastUpdate) > UPDATE_INTERVAL) {
                setup();
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
646969
public List<ChatMessageStatus> adaptStatuses(String conversationId, String messageId, Map<String, MessageReceived.Status> statuses) {
        List<ChatMessageStatus> adapted = new ArrayList<>();
        for (String key : statuses.keySet()) {
            MessageReceived.Status status = statuses.get(key);
            adapted.add(ChatMessageStatus.builder().populate(conversationId, messageId, key, status.getStatus().compareTo(MessageStatus.delivered) == 0 ? LocalMessageStatus.delivered : LocalMessageStatus.read, DateHelper.getUTCMilliseconds(status.getTimestamp()), null).build());
        }
        return adapted;
    }
1291046
public synchronized void update() {
    SYSTEM_POWER_STATUS status = new SYSTEM_POWER_STATUS();
    Kernel32.INSTANCE.GetSystemPowerStatus(status);

    switch (status.ACLineStatus) {
    case 0: // battery
      allow(!requireAC
          && (status.BatteryLifePercent < 0 || status.BatteryLifePercent >= minBatteryLifePercent));
      break;

    case 1:  // A/C
    default:
      allow((status.BatteryFlag & 0x8) == 0 // not charging
          || (status.BatteryLifePercent < 0 || status.BatteryLifePercent >= minBatteryLifePercentWhileCharging));
      break;

    }
  }
728692
private void handleConversationStateChange(Conversation conversation) {
		ApptentiveLog.d(CONVERSATION, "Conversation state changed: %s", conversation);
		checkConversationQueue();

		assertTrue(conversation != null && !conversation.hasState(UNDEFINED));

		if (conversation != null && !conversation.hasState(UNDEFINED)) {

			ApptentiveNotificationCenter.defaultCenter()
				.postNotification(NOTIFICATION_CONVERSATION_STATE_DID_CHANGE,
					NOTIFICATION_KEY_CONVERSATION, conversation);

			if (conversation.hasActiveState()) {
				if (appIsInForeground) {
					// ConversationManager listens to the foreground event to fetch interactions when it comes to foreground
					conversation.fetchInteractions(getContext());
					// Message Manager listens to foreground/background events itself
					conversation.getMessageManager().attemptToStartMessagePolling();
				}

				// Fetch app configuration
				fetchAppConfiguration(conversation);

				// Update conversation with push configuration changes that happened while it wasn't active.
				SharedPreferences prefs = ApptentiveInternal.getInstance().getGlobalSharedPrefs();
				int pushProvider = prefs.getInt(Constants.PREF_KEY_PUSH_PROVIDER, -1);
				String pushToken = prefs.getString(Constants.PREF_KEY_PUSH_TOKEN, null);
				if (pushProvider != -1 && pushToken != null) {
					conversation.setPushIntegration(pushProvider, pushToken);
				}
			}

			updateMetadataItems(conversation);
			if (ApptentiveLog.canLog(VERBOSE)) {
				printMetadata(conversationMetadata, "Updated Metadata");
			}
		}
	}
769469
Observable<ChatResult> handleConversationDeleted(String conversationId, ComapiResult<Void> result) {
        if (result.getCode() != ETAG_NOT_VALID) {
            return persistenceController.deleteConversation(conversationId).map(success -> adapter.adaptResult(result, success));
        } else {
            return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
                    .flatMap(newResult -> {
                        if (newResult.isSuccessful()) {
                            return persistenceController.upsertConversation(ChatConversation.builder().populate(newResult.getResult(), newResult.getETag()).build())
                                    .flatMap(success -> Observable.fromCallable(() -> new ChatResult(false, success ? new ChatResult.Error(ETAG_NOT_VALID, "Conversation updated, try delete again.", "Conversation "+conversationId+" updated in response to  wrong eTag error when deleting.") : new ChatResult.Error(0, "Error updating custom store.", null))));
                        } else {
                            return Observable.fromCallable(() -> adapter.adaptResult(newResult));
                        }
                    }));
        }
    }
555174
private void update()
    {
        boolean hasEvents = false;
        // set the newly received key and motion events.
        synchronized (eventLock)
        {
            hasEvents = (keyEvent.size() > 0) || (motionEvent.size() > 0);
            processedKeyEvent.addAll(keyEvent);
            keyEvent.clear();
            processedMotionEvent.addAll(motionEvent);
            motionEvent.clear();
        }
        previousActive = active;
        if ((scene != null) && (mPicker != null))
        {
            updatePicker(getMotionEvent(), active);
        }
        context.getEventManager().sendEvent(this, IControllerEvent.class, "onEvent", this, active);

        // reset the set key and motion events.
        synchronized (eventLock)
        {
            processedKeyEvent.clear();
            processedMotionEvent.clear();
        }
    }
415330
private Future<M> sync() {
        logger.debug("Synchronization of Remote[" + this + "] triggered...");
        try {
            validateInitialization();
            try {
                SyncTaskCallable syncCallable = new SyncTaskCallable();

                final Future<M> currentSyncTask = GlobalCachedExecutorService.submit(syncCallable);
                syncCallable.setRelatedFuture(currentSyncTask);
                return currentSyncTask;
            } catch (java.util.concurrent.RejectedExecutionException | NullPointerException ex) {
                throw new CouldNotPerformException("Could not request the current status.", ex);
            }
        } catch (CouldNotPerformException ex) {
            return FutureProcessor.canceledFuture(ex);
        }
    }