Refactor getAttachmentGroups which was copied from haku-app