refactor accept_invite function into a class so it can be shared more easily