Here's how to break it down:
* "Shaken up" implies a sudden and forceful disruption of their emotional state.
* "They had been shaken up" indicates that this emotional distress was a lasting effect of something that happened previously.
The idiom implies that the friends experienced something that left them feeling unsettled, whether it was a personal loss, a frightening experience, or a difficult situation.