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

Add the method to modify group add member mode #541

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ func (cli *Client) SetGroupAnnounce(jid types.JID, announce bool) error {
return err
}

// SetGroupAddMemberMode changes who can add member to this group
func (cli *Client) SetGroupAddMemberMode(jid types.JID, isMemberCouldAdd bool) error {
tag := "member_add_mode"
var addMemberMode types.GroupMemberAddMode
if isMemberCouldAdd {
addMemberMode = types.GroupMemberAddModeAllMember
} else {
addMemberMode = types.GroupMemberAddModeAdmin
}

_, err := cli.sendGroupIQ(context.TODO(), iqSet, jid, waBinary.Node{
Tag: tag,
Content: []byte(addMemberMode),
})
return err
}

// GetGroupInviteLink requests the invite link to the group from the WhatsApp servers.
//
// If reset is true, then the old invite link will be revoked and a new one generated.
Expand Down
35 changes: 35 additions & 0 deletions mdtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,41 @@ func handleCmd(cmd string, args []string) {
log.Infof("%+v", group)
}
}
case "setgrouppermissions":
if len(args) < 3 {
log.Errorf("Usage: setgrouppermissions <jid> <action> <status>")
return
}
jid, ok := parseJID(args[0])
if !ok {
return
}
action := args[1]

status, err := strconv.ParseBool(args[2])
if err != nil {
log.Errorf("Valid status: ture, false")
return
}

switch action {
case "edit":
err = cli.SetGroupLocked(jid, status)
case "send":
err = cli.SetGroupAnnounce(jid, status)
case "add":
err = cli.SetGroupAddMemberMode(jid, status)
default:
log.Errorf("Valid actions: edit, send, add")
return
}

if err != nil {
log.Errorf("Failed to Setgrouppermissions, action: %v, status:%v, err:%v", action, args[2], err)
} else {
log.Infof("Setgrouppermissions action: %s to status:%s", action, args[2])
}

case "getinvitelink":
if len(args) < 1 {
log.Errorf("Usage: getinvitelink <jid> [--reset]")
Expand Down
3 changes: 2 additions & 1 deletion types/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
type GroupMemberAddMode string

const (
GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
GroupMemberAddModeAllMember GroupMemberAddMode = "all_member_add"
)

// GroupInfo contains basic information about a group chat on WhatsApp.
Expand Down
Loading