Improve the method used to determine associated group when rewriting activity action

This is a more generalized version of r-a-y/buddypress-docs@8ec8f03d1b816af601c2f0949c45d224880a4c02

See #353