sync: 0.7.2 from main (6164dced8d3ab8f9bcce9bf333fb4e8663760ff1)
This commit is contained in:
1 parent
0f9ef308d2
commit
9337afc47e
74 files changed
+11173
-4687
No files matched your search
@@ -215,6 +215,21 @@ func ParseJID(arg string) (whatsmeow_types.JID, bool) {
|
||||
return recipient, true
|
||||
}
|
||||
|
||||
// CanonicalJID returns a JID safe for RAW protocol nodes (chatstate / typing,
|
||||
// read receipts, presence subscribe, reactions, etc.).
|
||||
//
|
||||
// CreateJID intentionally prefixes phone numbers with "+" (e.g.
|
||||
// "[email protected]") to match the IsOnWhatsApp/display convention.
|
||||
// Message sending tolerates this because whatsmeow normalizes the JID during
|
||||
// usync/device resolution. RAW nodes are sent WITHOUT usync, so a malformed
|
||||
// "+JID" reaches the server and the node is silently dropped (e.g. the "typing"
|
||||
// indicator never reaches the recipient). WhatsApp user JIDs are digits-only, so
|
||||
// strip the leading "+" to get the canonical form.
|
||||
func CanonicalJID(jid whatsmeow_types.JID) whatsmeow_types.JID {
|
||||
jid.User = strings.TrimPrefix(jid.User, "+")
|
||||
return jid
|
||||
}
|
||||
|
||||
func CreateHTTPProxy(httpHost, httpPort, user, password string) (func(*http.Request) (*url.URL, error), error) {
|
||||
address := fmt.Sprintf("http://%s:%s@%s:%s", user, password, httpHost, httpPort)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -325,3 +326,61 @@ func TestParseJID(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCanonicalJID locks in the fix for the silent typing-indicator / receipt
|
||||
// drop: ParseJID (via CreateJID) prefixes phone numbers with "+", which is
|
||||
// tolerated by message sending (usync normalizes it) but breaks RAW nodes
|
||||
// (chatstate, read receipts, reactions). CanonicalJID must strip that "+" while
|
||||
// leaving already-canonical JIDs (LID, group, digits-only) untouched.
|
||||
func TestCanonicalJID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expectedJID string // canonical JID expected after ParseJID -> CanonicalJID
|
||||
}{
|
||||
{
|
||||
name: "BR phone strips the leading +",
|
||||
input: "554187083284",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "US phone strips the leading +",
|
||||
input: "15551234567",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "Already-canonical JID is unchanged",
|
||||
input: "[email protected]",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
{
|
||||
name: "LID JID is left untouched",
|
||||
input: "15883309207561@lid",
|
||||
expectedJID: "15883309207561@lid",
|
||||
},
|
||||
{
|
||||
name: "Group JID is left untouched",
|
||||
input: "[email protected]",
|
||||
expectedJID: "[email protected]",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
jid, ok := ParseJID(tt.input)
|
||||
if !ok {
|
||||
t.Fatalf("ParseJID(%q) failed", tt.input)
|
||||
}
|
||||
|
||||
canonical := CanonicalJID(jid)
|
||||
|
||||
if got := canonical.String(); got != tt.expectedJID {
|
||||
t.Errorf("CanonicalJID for input %q = %q, want %q", tt.input, got, tt.expectedJID)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(canonical.User, "+") {
|
||||
t.Errorf("CanonicalJID for input %q still has '+' in User: %q", tt.input, canonical.User)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user