浏览代码

更新Usync

Joey 3 周之前
父节点
当前提交
3635a2bca2
共有 2 个文件被更改,包括 43 次插入3 次删除
  1. 6 3
      types/user.go
  2. 37 0
      user.go

+ 6 - 3
types/user.go

@@ -84,9 +84,12 @@ type LocalChatSettings struct {
 
 // IsOnWhatsAppResponse contains information received in response to checking if a phone number is on WhatsApp.
 type IsOnWhatsAppResponse struct {
-	Query string // The query string used
-	JID   JID    // The canonical user ID
-	IsIn  bool   // Whether the phone is registered or not.
+	Query     string // The query string used
+	JID       JID    // The canonical user ID
+	IsIn      bool   // Whether the phone is registered or not.
+	Status    string
+	Devices   []JID
+	PictureID string
 
 	VerifiedName *VerifiedName // If the phone is a business, the verified business details.
 }

+ 37 - 0
user.go

@@ -162,6 +162,43 @@ func (cli *Client) SetStatusMessage(ctx context.Context, msg string) error {
 	})
 	return err
 }
+func (cli *Client) Usync(ctx context.Context, phones []string) ([]types.IsOnWhatsAppResponse, error) {
+	jids := make([]types.JID, len(phones))
+	for i := range jids {
+		jids[i] = types.NewJID(phones[i], types.LegacyUserServer)
+	}
+	list, err := cli.usync(ctx, jids, "delta", "interactive", []waBinary.Node{
+		//{Tag: "business", Content: []waBinary.Node{{Tag: "verified_name"}}},
+		{Tag: "lid"},
+		{Tag: "status"},
+		{Tag: "contact"},
+	})
+	if err != nil {
+		return nil, err
+	}
+	output := make([]types.IsOnWhatsAppResponse, 0, len(jids))
+	querySuffix := "@" + types.LegacyUserServer
+	for _, child := range list.GetChildren() {
+		jid, jidOK := child.Attrs["jid"].(types.JID)
+		if child.Tag != "user" || !jidOK {
+			continue
+		}
+		var info types.IsOnWhatsAppResponse
+		info.JID = jid
+		info.VerifiedName, err = parseVerifiedName(child.GetChildByTag("business"))
+		if err != nil {
+			cli.Log.Warnf("Failed to parse %s's verified name details: %v", jid, err)
+		}
+		status, _ := child.GetChildByTag("status").Content.([]byte)
+		info.Status = string(status)
+		contactNode := child.GetChildByTag("contact")
+		info.IsIn = contactNode.AttrGetter().String("type") == "in"
+		contactQuery, _ := contactNode.Content.([]byte)
+		info.Query = strings.TrimSuffix(string(contactQuery), querySuffix)
+		output = append(output, info)
+	}
+	return output, nil
+}
 
 // IsOnWhatsApp checks if the given phone numbers are registered on WhatsApp.
 // The phone numbers should be in international format, including the `+` prefix.