See https://discourse.phabricator-community.org/t/error-when-sending-a-message-chat-room/2548.
Conpherence calls setAfterID() and setBeforeID() directly on a subquery, but these methods no longer exist.
Use a pager instead. This code probably shouldn't exist (we should use some other approach to fetch this data in most cases) but that's a larger change.