Community detection in temporal networks via a spreading process