Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: group change event mode membership approval mode #546

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -640,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.IsJoinApprovalRequired = true
default:
cli.Log.Debugf("Unknown element in group node %s: %s", group.JID.String(), child.XMLString())
}
Expand Down Expand Up @@ -810,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{
IsJoinApprovalRequired: true,
}
default:
evt.UnknownChanges = append(evt.UnknownChanges, &child)
}
Expand Down
2 changes: 2 additions & 0 deletions types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions types/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type GroupInfo struct {
GroupParent
GroupLinkedParent
GroupIsDefaultSub
GroupMembershipApprovalMode

GroupCreated time.Time

Expand All @@ -40,6 +41,10 @@ type GroupInfo struct {
MemberAddMode GroupMemberAddMode
}

type GroupMembershipApprovalMode struct {
IsJoinApprovalRequired bool
}

type GroupParent struct {
IsParent bool
DefaultMembershipApprovalMode string // request_required
Expand Down
Loading