'Get receipts for a single room for sending to clients.
Args:
room_ids (str): The room id.
to_key (int): Max stream id to fetch receipts upto.
from_key (int): Min stream id to fetch receipts from. None fetches
from the start.
Returns:
list: A list of receipts.'

@cachedInlineCallbacks(num_args=3, tree=True)
def get_linearized_receipts_for_room(self, room_id, to_key, from_key=None):

    def f(txn):
        if from_key:
            sql = 'SELECT    *    FROM    receipts_linearized    WHERE    room_id    =    ?    AND    stream_id    >    ?    AND    stream_id    <=    ?'
            txn.execute(sql, (room_id, from_key, to_key))
        else:
            sql = 'SELECT    *    FROM    receipts_linearized    WHERE    room_id    =    ?    AND    stream_id    <=    ?'
            txn.execute(sql, (room_id, to_key))
        rows = self.cursor_to_dict(txn)
        return rows
    rows = (yield self.runInteraction('get_linearized_receipts_for_room', f))
    if (not rows):
        defer.returnValue([])
    content = {}
    for row in rows:
        content.setdefault(row['event_id'], {}).setdefault(row['receipt_type'], {})[row['user_id']] = json.loads(row['data'])
    defer.returnValue([{'type': 'm.receipt', 'room_id': room_id, 'content': content}])
