Skip to content

Commit ad8f8ee

Browse files
committed
[WAHA] Fix group.description - attrs id
1 parent a12716b commit ad8f8ee

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

group.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ package whatsmeow
88

99
import (
1010
"context"
11+
"encoding/hex"
1112
"errors"
1213
"fmt"
14+
"math/rand"
1315
"strings"
1416

1517
waBinary "go.mau.fi/whatsmeow/binary"
@@ -978,9 +980,13 @@ func (cli *Client) SetGroupMemberAddMode(jid types.JID, mode types.GroupMemberAd
978980
}
979981

980982
// SetGroupDescription updates the group description.
981-
func (cli *Client) SetGroupDescription(jid types.JID, description string) error {
983+
func (cli *Client) SetGroupDescription(jid types.JID, description string, prevTopicId string) error {
982984
content := waBinary.Node{
983985
Tag: "description",
986+
Attrs: waBinary.Attrs{
987+
"id": generateId(),
988+
"prev": prevTopicId,
989+
},
984990
Content: []waBinary.Node{
985991
{
986992
Tag: "body",
@@ -992,3 +998,15 @@ func (cli *Client) SetGroupDescription(jid types.JID, description string) error
992998
_, err := cli.sendGroupIQ(context.TODO(), iqSet, jid, content)
993999
return err
9941000
}
1001+
1002+
func randomHex(n int) string {
1003+
bytes := make([]byte, n)
1004+
for i := range bytes {
1005+
bytes[i] = byte(rand.Intn(256))
1006+
}
1007+
return hex.EncodeToString(bytes)
1008+
}
1009+
1010+
func generateId() string {
1011+
return strings.ToUpper(randomHex(8))
1012+
}

0 commit comments

Comments
 (0)