Solution for NodeBB/NodeBB#2440

I think these two comments should be a solution for NodeBB/NodeBB#2440

The code might have simple errors (I haven't been able to test it), but the theory behind the code should be good.