The problem is that Flarum doesn't really have a hierarchy with posts. Replying to someone causes only content-wise changes, eg:
@Amal#87279 which is managed by the mentions extension.
You could scan the content for mentions and if only one exists (or the content starts with that) create a relation to the parent post.. Which would be the latter part of the mention 87279. Scanning would probably be done best on the backend, because it always has access to all posts of a discussion using the database, the frontend only knows about the posts it has loaded so far.
This might prove to be a very tough challenge.