'Works out the differnce in state between the start of the timeline
and the previous sync.
Args:
room_id(str):
batch(synapse.handlers.sync.TimelineBatch): The timeline batch for
the room that will be sent to the user.
sync_config(synapse.handlers.sync.SyncConfig):
since_token(str|None): Token of the end of the previous batch. May
be None.
now_token(str): Token of the end of the current batch.
full_state(bool): Whether to force returning the full state.
Returns:
A deferred new event dictionary'

@defer.inlineCallbacks
def compute_state_delta(self, room_id, batch, sync_config, since_token, now_token, full_state):

    with Measure(self.clock, 'compute_state_delta'):
        if full_state:
            if batch:
                current_state_ids = (yield self.store.get_state_ids_for_event(batch.events[(-1)].event_id))
                state_ids = (yield self.store.get_state_ids_for_event(batch.events[0].event_id))
            else:
                current_state_ids = (yield self.get_state_at(room_id, stream_position=now_token))
                state_ids = current_state_ids
            timeline_state = {(event.type, event.state_key): event.event_id for event in batch.events if event.is_state()}
            state_ids = _calculate_state(timeline_contains=timeline_state, timeline_start=state_ids, previous={}, current=current_state_ids)
        elif batch.limited:
            state_at_previous_sync = (yield self.get_state_at(room_id, stream_position=since_token))
            current_state_ids = (yield self.store.get_state_ids_for_event(batch.events[(-1)].event_id))
            state_at_timeline_start = (yield self.store.get_state_ids_for_event(batch.events[0].event_id))
            timeline_state = {(event.type, event.state_key): event.event_id for event in batch.events if event.is_state()}
            state_ids = _calculate_state(timeline_contains=timeline_state, timeline_start=state_at_timeline_start, previous=state_at_previous_sync, current=current_state_ids)
        else:
            state_ids = {}
    state = {}
    if state_ids:
        state = (yield self.store.get_events(state_ids.values()))
    defer.returnValue({(e.type, e.state_key): e for e in sync_config.filter_collection.filter_room_state(state.values())})
