'Generates the presence portion of the sync response. Populates the
`sync_result_builder` with the result.
Args:
sync_result_builder(SyncResultBuilder)
newly_joined_rooms(list): List of rooms that the user has joined
since the last sync (or empty if an initial sync)
newly_joined_users(list): List of users that have joined rooms
since the last sync (or empty if an initial sync)'

@defer.inlineCallbacks
def _generate_sync_entry_for_presence(self, sync_result_builder, newly_joined_rooms, newly_joined_users):

    now_token = sync_result_builder.now_token
    sync_config = sync_result_builder.sync_config
    user = sync_result_builder.sync_config.user
    presence_source = self.event_sources.sources['presence']
    since_token = sync_result_builder.since_token
    if (since_token and (not sync_result_builder.full_state)):
        presence_key = since_token.presence_key
        include_offline = True
    else:
        presence_key = None
        include_offline = False
    (presence, presence_key) = (yield presence_source.get_new_events(user=user, from_key=presence_key, is_guest=sync_config.is_guest, include_offline=include_offline))
    sync_result_builder.now_token = now_token.copy_and_replace('presence_key', presence_key)
    extra_users_ids = set(newly_joined_users)
    for room_id in newly_joined_rooms:
        users = (yield self.state.get_current_user_in_room(room_id))
        extra_users_ids.update(users)
    extra_users_ids.discard(user.to_string())
    if extra_users_ids:
        states = (yield self.presence_handler.get_states(extra_users_ids))
        presence.extend(states)
        presence = {p.user_id: p for p in presence}.values()
    presence = sync_config.filter_collection.filter_presence(presence)
    sync_result_builder.presence = presence
