'Update the syncing users for an external process
Args:
process_id(str): An identifier for the process the users are
syncing against. This allows synapse to process updates
as user start and stop syncing against a given process.
syncing_user_ids(set(str)): The set of user_ids that are
currently syncing on that server.'

@defer.inlineCallbacks
def update_external_syncs(self, process_id, syncing_user_ids):

    prev_syncing_user_ids = self.external_process_to_current_syncs.get(process_id, set())
    prev_states = (yield self.current_state_for_users((syncing_user_ids | prev_syncing_user_ids)))
    updates = []
    time_now_ms = self.clock.time_msec()
    for new_user_id in (syncing_user_ids - prev_syncing_user_ids):
        prev_state = prev_states[new_user_id]
        if (prev_state.state == PresenceState.OFFLINE):
            updates.append(prev_state.copy_and_replace(state=PresenceState.ONLINE, last_active_ts=time_now_ms, last_user_sync_ts=time_now_ms))
        else:
            updates.append(prev_state.copy_and_replace(last_user_sync_ts=time_now_ms))
    for old_user_id in prev_syncing_user_ids:
        prev_state = prev_states[old_user_id]
        updates.append(prev_state.copy_and_replace(last_user_sync_ts=time_now_ms))
    (yield self._update_states(updates))
    self.external_process_last_updated_ms[process_id] = self.clock.time_msec()
    self.external_process_to_current_syncs[process_id] = syncing_user_ids
