Refactor the chat controller method to update messages