Skip to content

Commit

Permalink
Don't request viewer_metadata when getting info by link
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 22, 2023
1 parent 7c1b618 commit bde5a87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions newsletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ type respGetNewsletterInfo struct {
Newsletter *types.NewsletterMetadata `json:"xwa2_newsletter"`
}

func (cli *Client) getNewsletterInfo(input map[string]any) (*types.NewsletterMetadata, error) {
func (cli *Client) getNewsletterInfo(input map[string]any, fetchViewerMeta bool) (*types.NewsletterMetadata, error) {
data, err := cli.sendMexIQ(context.TODO(), queryFetchNewsletter, map[string]any{
"fetch_creation_time": true,
"fetch_full_image": true,
"fetch_viewer_metadata": true,
"fetch_viewer_metadata": fetchViewerMeta,
"input": input,
})
if err != nil {
Expand All @@ -182,17 +182,19 @@ func (cli *Client) GetNewsletterInfo(jid types.JID) (*types.NewsletterMetadata,
return cli.getNewsletterInfo(map[string]any{
"key": jid.String(),
"type": types.NewsletterKeyTypeJID,
})
}, true)
}

// GetNewsletterInfoWithInvite gets the info of a newsletter with an invite link.
//
// You can either pass the full link (https://whatsapp.com/channel/...) or just the `...` part.
//
// Note that the ViewerMeta field of the returned NewsletterMetadata will be nil.
func (cli *Client) GetNewsletterInfoWithInvite(key string) (*types.NewsletterMetadata, error) {
return cli.getNewsletterInfo(map[string]any{
"key": strings.TrimPrefix(key, NewsletterLinkPrefix),
"type": types.NewsletterKeyTypeInvite,
})
}, false)
}

type CreateNewsletterParams struct {
Expand Down
8 changes: 4 additions & 4 deletions types/newsletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ const (
)

type NewsletterMetadata struct {
ID JID `json:"id"`
State WrappedNewsletterState `json:"state"`
ThreadMeta NewsletterThreadMetadata `json:"thread_metadata"`
ViewerMeta NewsletterViewerMetadata `json:"viewer_metadata"`
ID JID `json:"id"`
State WrappedNewsletterState `json:"state"`
ThreadMeta NewsletterThreadMetadata `json:"thread_metadata"`
ViewerMeta *NewsletterViewerMetadata `json:"viewer_metadata"`
}

type NewsletterViewerMetadata struct {
Expand Down

0 comments on commit bde5a87

Please sign in to comment.