'Get messages in a room.
Args:
requester (Requester): The user requesting messages.
room_id (str): The room they want messages from.
pagin_config (synapse.api.streams.PaginationConfig): The pagination
config rules to apply, if any.
as_client_event (bool): True to get events in client-server format.
event_filter (Filter): Filter to apply to results or None
Returns:
dict: Pagination API results'

@defer.inlineCallbacks
def get_messages(self, requester, room_id=None, pagin_config=None, as_client_event=True, event_filter=None):

    user_id = requester.user.to_string()
    if pagin_config.from_token:
        room_token = pagin_config.from_token.room_key
    else:
        pagin_config.from_token = (yield self.hs.get_event_sources().get_current_token_for_room(room_id=room_id))
        room_token = pagin_config.from_token.room_key
    room_token = RoomStreamToken.parse(room_token)
    pagin_config.from_token = pagin_config.from_token.copy_and_replace('room_key', str(room_token))
    source_config = pagin_config.get_source_config('room')
    with (yield self.pagination_lock.read(room_id)):
        (membership, member_event_id) = (yield self._check_in_room_or_world_readable(room_id, user_id))
        if (source_config.direction == 'b'):
            if room_token.topological:
                max_topo = room_token.topological
            else:
                max_topo = (yield self.store.get_max_topological_token(room_id, room_token.stream))
            if (membership == Membership.LEAVE):
                leave_token = (yield self.store.get_topological_token_for_event(member_event_id))
                leave_token = RoomStreamToken.parse(leave_token)
                if (leave_token.topological < max_topo):
                    source_config.from_key = str(leave_token)
            (yield self.hs.get_handlers().federation_handler.maybe_backfill(room_id, max_topo))
        (events, next_key) = (yield self.store.paginate_room_events(room_id=room_id, from_key=source_config.from_key, to_key=source_config.to_key, direction=source_config.direction, limit=source_config.limit, event_filter=event_filter))
        next_token = pagin_config.from_token.copy_and_replace('room_key', next_key)
    if (not events):
        defer.returnValue({'chunk': [], 'start': pagin_config.from_token.to_string(), 'end': next_token.to_string()})
    if event_filter:
        events = event_filter.filter(events)
    events = (yield filter_events_for_client(self.store, user_id, events, is_peeking=(member_event_id is None)))
    time_now = self.clock.time_msec()
    chunk = {'chunk': [serialize_event(e, time_now, as_client_event) for e in events], 'start': pagin_config.from_token.to_string(), 'end': next_token.to_string()}
    defer.returnValue(chunk)
