'Get the ephemeral events for each room the user is in
Args:
sync_config (SyncConfig): The flags, filters and user for the sync.
now_token (StreamToken): Where the server is currently up to.
since_token (StreamToken): Where the server was when the client
last synced.
Returns:
A tuple of the now StreamToken, updated to reflect the which typing
events are included, and a dict mapping from room_id to a list of
typing events for that room.'

@defer.inlineCallbacks
def ephemeral_by_room(self, sync_config, now_token, since_token=None):

    with Measure(self.clock, 'ephemeral_by_room'):
        typing_key = (since_token.typing_key if since_token else '0')
        room_ids = (yield self.store.get_rooms_for_user(sync_config.user.to_string()))
        typing_source = self.event_sources.sources['typing']
        (typing, typing_key) = (yield typing_source.get_new_events(user=sync_config.user, from_key=typing_key, limit=sync_config.filter_collection.ephemeral_limit(), room_ids=room_ids, is_guest=sync_config.is_guest))
        now_token = now_token.copy_and_replace('typing_key', typing_key)
        ephemeral_by_room = {}
        for event in typing:
            room_id = event['room_id']
            event_copy = {k: v for (k, v) in event.iteritems() if (k != 'room_id')}
            ephemeral_by_room.setdefault(room_id, []).append(event_copy)
        receipt_key = (since_token.receipt_key if since_token else '0')
        receipt_source = self.event_sources.sources['receipt']
        (receipts, receipt_key) = (yield receipt_source.get_new_events(user=sync_config.user, from_key=receipt_key, limit=sync_config.filter_collection.ephemeral_limit(), room_ids=room_ids, is_guest=sync_config.is_guest))
        now_token = now_token.copy_and_replace('receipt_key', receipt_key)
        for event in receipts:
            room_id = event['room_id']
            event_copy = {k: v for (k, v) in event.iteritems() if (k != 'room_id')}
            ephemeral_by_room.setdefault(room_id, []).append(event_copy)
    defer.returnValue((now_token, ephemeral_by_room))
