Those links use a slightly different serializer - because not all the group data is needed there.
Still, you can store a filtered list of the current user’s groups on the initial page view and use those as a reference to check for membership. This information is already available in the initial payload, so there’s no overhead in terms of extra requests or anything like that. Something like this
<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
if (!user) {
return;
}
const userGroups = user.groups.map(group => group.name);
api.reopenWidget("pm-map-user-group", {
transform(attrs) {
const group = attrs.group;
const isGroupUser = Object.values(userGroups).includes(group.name);
// {href: "/g/foo"};
let groupURL = this._super(...arguments);
if (isGroupUser && group.has_messages) {
groupURL.href = `${groupURL.href}/messages/`;
}
return groupURL;
}
});
</script>
Keep this snippet in its own script tags and add it to the header along with the other snippets. You keep it separate because it does a quick bail if the user is not logged in.