Fix use after free of groupchat invites

Fixes #728, fixes #706, fixes #394