From 5605edeca44de8bf0b29f407a78f8618d3a88215 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Wed, 14 Feb 2024 02:47:52 -0300 Subject: [PATCH 1/4] fix: resolved to return group jid if approval membership mode is enabled --- group.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/group.go b/group.go index 199493c8..d55fc80e 100644 --- a/group.go +++ b/group.go @@ -439,6 +439,10 @@ func (cli *Client) JoinGroupWithLink(code string) (types.JID, error) { } else if err != nil { return types.EmptyJID, err } + membershipApprovalModeNode, ok := resp.GetOptionalChildByTag("membership_approval_request") + if ok { + return membershipApprovalModeNode.AttrGetter().JID("jid"), nil + } groupNode, ok := resp.GetOptionalChildByTag("group") if !ok { return types.EmptyJID, &ElementMissingError{Tag: "group", In: "response to group link join query"} From 2ebde8a99be89f5ad1cefc0067a260fde68e34d8 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Wed, 14 Feb 2024 02:49:45 -0300 Subject: [PATCH 2/4] feat: add on parse group node membership approval mode info is enabled --- group.go | 3 ++- types/group.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/group.go b/group.go index d55fc80e..e63c1b7e 100644 --- a/group.go +++ b/group.go @@ -644,7 +644,8 @@ func (cli *Client) parseGroupNode(groupNode *waBinary.Node) (*types.GroupInfo, e group.DefaultMembershipApprovalMode = childAG.OptionalString("default_membership_approval_mode") case "incognito": group.IsIncognito = true - // TODO: membership_approval_mode + case "membership_approval_mode": + group.IsApprovalRequired = true default: cli.Log.Debugf("Unknown element in group node %s: %s", group.JID.String(), child.XMLString()) } diff --git a/types/group.go b/types/group.go index 9fd97675..5fad0997 100644 --- a/types/group.go +++ b/types/group.go @@ -31,6 +31,7 @@ type GroupInfo struct { GroupParent GroupLinkedParent GroupIsDefaultSub + GroupMembershipApprovalMode GroupCreated time.Time @@ -40,6 +41,10 @@ type GroupInfo struct { MemberAddMode GroupMemberAddMode } +type GroupMembershipApprovalMode struct { + IsApprovalRequired bool +} + type GroupParent struct { IsParent bool DefaultMembershipApprovalMode string // request_required From f27f488ea02225dc452b6da2a29605c3fef40b8e Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Wed, 14 Feb 2024 03:00:54 -0300 Subject: [PATCH 3/4] feat: add to group change event mode membership approval mode --- group.go | 4 ++++ types/events/events.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/group.go b/group.go index e63c1b7e..133da997 100644 --- a/group.go +++ b/group.go @@ -815,6 +815,10 @@ func (cli *Client) parseGroupChange(node *waBinary.Node) (*events.GroupInfo, err if err != nil { return nil, fmt.Errorf("failed to parse group unlink node in group change: %w", err) } + case "membership_approval_mode": + evt.MembershipApprovalMode = &types.GroupMembershipApprovalMode{ + IsApprovalRequired: true, + } default: evt.UnknownChanges = append(evt.UnknownChanges, &child) } diff --git a/types/events/events.go b/types/events/events.go index 05645260..fcc4e3e2 100644 --- a/types/events/events.go +++ b/types/events/events.go @@ -400,6 +400,8 @@ type GroupInfo struct { Announce *types.GroupAnnounce // Group announce status change (can only admins send messages?) Ephemeral *types.GroupEphemeral // Disappearing messages change + MembershipApprovalMode *types.GroupMembershipApprovalMode // Membership approval mode change + Delete *types.GroupDelete Link *types.GroupLinkChange From 0c687dde7f9972b3659bd7d98b8045145613cb10 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 24 Sep 2024 15:34:09 +0300 Subject: [PATCH 4/4] Rename field --- group.go | 4 ++-- types/group.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/group.go b/group.go index 133da997..3c93ec00 100644 --- a/group.go +++ b/group.go @@ -645,7 +645,7 @@ func (cli *Client) parseGroupNode(groupNode *waBinary.Node) (*types.GroupInfo, e case "incognito": group.IsIncognito = true case "membership_approval_mode": - group.IsApprovalRequired = true + group.IsJoinApprovalRequired = true default: cli.Log.Debugf("Unknown element in group node %s: %s", group.JID.String(), child.XMLString()) } @@ -817,7 +817,7 @@ func (cli *Client) parseGroupChange(node *waBinary.Node) (*events.GroupInfo, err } case "membership_approval_mode": evt.MembershipApprovalMode = &types.GroupMembershipApprovalMode{ - IsApprovalRequired: true, + IsJoinApprovalRequired: true, } default: evt.UnknownChanges = append(evt.UnknownChanges, &child) diff --git a/types/group.go b/types/group.go index 5fad0997..94ae025d 100644 --- a/types/group.go +++ b/types/group.go @@ -42,7 +42,7 @@ type GroupInfo struct { } type GroupMembershipApprovalMode struct { - IsApprovalRequired bool + IsJoinApprovalRequired bool } type GroupParent struct {