@@ -12,7 +12,9 @@ import (
1212 "errors"
1313 "fmt"
1414 "slices"
15+ "strconv"
1516 "strings"
17+ "time"
1618
1719 "google.golang.org/protobuf/proto"
1820
@@ -942,16 +944,52 @@ func (cli *Client) GetBlocklist(ctx context.Context) (*types.Blocklist, error) {
942944
943945// UpdateBlocklist updates the user's block list and returns the updated list.
944946func (cli * Client ) UpdateBlocklist (ctx context.Context , jid types.JID , action events.BlocklistChangeAction ) (* types.Blocklist , error ) {
947+ var lidJID , pnJID types.JID
948+
949+ if jid .Server == types .DefaultUserServer {
950+ pnJID = jid
951+ lid , err := cli .Store .LIDs .GetLIDForPN (ctx , jid )
952+ if err != nil {
953+ return nil , fmt .Errorf ("failed to get LID for PN %s: %w" , jid , err )
954+ }
955+ if lid .IsEmpty () {
956+ info , err := cli .GetUserInfo (ctx , []types.JID {jid })
957+ if err != nil {
958+ return nil , fmt .Errorf ("failed to get user info for %s to fill LID cache: %w" , jid , err )
959+ }
960+ lid = info [jid ].LID
961+ if lid .IsEmpty () {
962+ return nil , fmt .Errorf ("no LID found for %s from server" , jid )
963+ }
964+ }
965+ lidJID = lid
966+ } else if jid .Server == types .HiddenUserServer {
967+ lidJID = jid
968+ if action == events .BlocklistChangeActionBlock {
969+ pn , err := cli .Store .LIDs .GetPNForLID (ctx , jid )
970+ if err != nil {
971+ return nil , fmt .Errorf ("failed to resolve PN for %s: %w" , jid , err )
972+ }
973+ pnJID = pn
974+ }
975+ }
976+
977+ itemAttrs := waBinary.Attrs {
978+ "jid" : lidJID ,
979+ "action" : string (action ),
980+ "dhash" : strconv .FormatInt (time .Now ().UnixMilli (), 10 ),
981+ }
982+ if action == events .BlocklistChangeActionBlock && ! pnJID .IsEmpty () {
983+ itemAttrs ["pn_jid" ] = pnJID
984+ }
985+
945986 resp , err := cli .sendIQ (ctx , infoQuery {
946987 Namespace : "blocklist" ,
947988 Type : iqSet ,
948989 To : types .ServerJID ,
949990 Content : []waBinary.Node {{
950- Tag : "item" ,
951- Attrs : waBinary.Attrs {
952- "jid" : jid ,
953- "action" : string (action ),
954- },
991+ Tag : "item" ,
992+ Attrs : itemAttrs ,
955993 }},
956994 })
957995 if err != nil {
0 commit comments