The intertwined dynamics of social networks and mental health