call,group,user: add tctokens to more requests
This commit is contained in:
@@ -109,13 +109,22 @@ func (cli *Client) RejectCall(ctx context.Context, callFrom types.JID, callID st
|
||||
return ErrNotLoggedIn
|
||||
}
|
||||
ownID, callFrom = ownID.ToNonAD(), callFrom.ToNonAD()
|
||||
rejectNode := waBinary.Node{
|
||||
Tag: "reject",
|
||||
Attrs: waBinary.Attrs{"call-id": callID, "call-creator": callFrom, "count": "0"},
|
||||
Content: nil,
|
||||
}
|
||||
if token, err := cli.ensureTCToken(ctx, callFrom); err != nil {
|
||||
cli.Log.Warnf("Failed to get privacy token for call reject to %s: %v", callFrom, err)
|
||||
} else if len(token) > 0 {
|
||||
rejectNode.Content = []waBinary.Node{{
|
||||
Tag: "tctoken",
|
||||
Content: token,
|
||||
}}
|
||||
}
|
||||
return cli.sendNode(ctx, waBinary.Node{
|
||||
Tag: "call",
|
||||
Attrs: waBinary.Attrs{"id": cli.GenerateMessageID(), "from": ownID, "to": callFrom},
|
||||
Content: []waBinary.Node{{
|
||||
Tag: "reject",
|
||||
Attrs: waBinary.Attrs{"call-id": callID, "call-creator": callFrom, "count": "0"},
|
||||
Content: nil,
|
||||
}},
|
||||
Tag: "call",
|
||||
Attrs: waBinary.Attrs{"id": cli.GenerateMessageID(), "from": ownID, "to": callFrom},
|
||||
Content: []waBinary.Node{rejectNode},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ func (cli *Client) CreateGroup(ctx context.Context, req ReqCreateGroup) (*types.
|
||||
Tag: "participant",
|
||||
Attrs: waBinary.Attrs{"jid": participant},
|
||||
}
|
||||
pt, err := cli.Store.PrivacyTokens.GetPrivacyToken(ctx, participant)
|
||||
token, err := cli.ensureTCToken(ctx, participant)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get privacy token for participant %s: %v", participant, err)
|
||||
} else if pt != nil {
|
||||
} else if len(token) > 0 {
|
||||
participantNodes[i].Content = []waBinary.Node{{
|
||||
Tag: "privacy",
|
||||
Content: pt.Token,
|
||||
Content: token,
|
||||
}}
|
||||
}
|
||||
}
|
||||
@@ -201,6 +201,17 @@ func (cli *Client) UpdateGroupParticipants(ctx context.Context, jid types.JID, p
|
||||
content[i].Attrs["phone_number"] = pn
|
||||
}
|
||||
}
|
||||
if action == ParticipantChangeAdd {
|
||||
token, err := cli.ensureTCToken(ctx, participantJID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get privacy token for participant %s: %v", participantJID, err)
|
||||
} else if len(token) > 0 {
|
||||
content[i].Content = []waBinary.Node{{
|
||||
Tag: "privacy",
|
||||
Content: token,
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
resp, err := cli.sendGroupIQ(ctx, iqSet, jid, waBinary.Node{
|
||||
Tag: string(action),
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ func (cli *Client) SubscribePresence(ctx context.Context, jid types.JID) error {
|
||||
if cli == nil {
|
||||
return ErrClientIsNil
|
||||
}
|
||||
privacyToken, err := cli.Store.PrivacyTokens.GetPrivacyToken(ctx, jid)
|
||||
privacyToken, err := cli.ensureTCToken(ctx, jid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get privacy token: %w", err)
|
||||
} else if privacyToken == nil {
|
||||
@@ -118,7 +118,7 @@ func (cli *Client) SubscribePresence(ctx context.Context, jid types.JID) error {
|
||||
if privacyToken != nil {
|
||||
req.Content = []waBinary.Node{{
|
||||
Tag: "tctoken",
|
||||
Content: privacyToken.Token,
|
||||
Content: privacyToken,
|
||||
}}
|
||||
}
|
||||
return cli.sendNode(ctx, req)
|
||||
|
||||
@@ -218,6 +218,8 @@ func (cli *Client) GetUserInfo(ctx context.Context, jids []types.JID) (map[types
|
||||
{Tag: "picture"},
|
||||
{Tag: "devices", Attrs: waBinary.Attrs{"version": "2"}},
|
||||
{Tag: "lid"},
|
||||
}, UsyncQueryExtras{
|
||||
IncludePrivacyToken: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -577,10 +579,10 @@ func (cli *Client) GetProfilePictureInfo(ctx context.Context, jid types.JID, par
|
||||
}
|
||||
|
||||
var pictureContent []waBinary.Node
|
||||
if token, _ := cli.Store.PrivacyTokens.GetPrivacyToken(ctx, jid); token != nil {
|
||||
if token, _ := cli.ensureTCToken(ctx, jid); token != nil {
|
||||
pictureContent = []waBinary.Node{{
|
||||
Tag: "tctoken",
|
||||
Content: token.Token,
|
||||
Content: token,
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -841,7 +843,8 @@ func (cli *Client) getFBIDDevices(ctx context.Context, jids []types.JID) ([]type
|
||||
}
|
||||
|
||||
type UsyncQueryExtras struct {
|
||||
BotListInfo []types.BotListInfo
|
||||
BotListInfo []types.BotListInfo
|
||||
IncludePrivacyToken bool
|
||||
}
|
||||
|
||||
func (cli *Client) usync(ctx context.Context, jids []types.JID, mode, context string, query []waBinary.Node, extra ...UsyncQueryExtras) (*waBinary.Node, error) {
|
||||
@@ -884,6 +887,16 @@ func (cli *Client) usync(ctx context.Context, jids []types.JID, mode, context st
|
||||
Attrs: waBinary.Attrs{"persona_id": personaID},
|
||||
}},
|
||||
}}
|
||||
} else if extras.IncludePrivacyToken {
|
||||
token, err := cli.ensureTCToken(ctx, jid)
|
||||
if err != nil {
|
||||
cli.Log.Warnf("Failed to get privacy token for usync status query to %s: %v", jid, err)
|
||||
} else if len(token) > 0 {
|
||||
userList[i].Content = []waBinary.Node{{
|
||||
Tag: "tctoken",
|
||||
Content: token,
|
||||
}}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown user server '%s'", jid.Server)
|
||||
|
||||
Reference in New Issue
Block a user