Skip to content

Commit

Permalink
add FetchFBID to messagix
Browse files Browse the repository at this point in the history
  • Loading branch information
JJTech0130 committed Jul 2, 2024
1 parent 44621fd commit fb6a9cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions messagix/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,11 @@ func (c *Client) WaitUntilCanSendMessages(timeout time.Duration) error {
}
return nil
}

func (c *Client) FetchFBID() (int64, error) {
if c.platform.IsMessenger() {
return c.Facebook.FetchFBID()
} else {
return c.Instagram.FetchFBID()
}
}
8 changes: 8 additions & 0 deletions messagix/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,11 @@ type pushNotificationsResponse struct {
type payload struct {
Success bool `json:"success"`
}

func (fb *FacebookMethods) FetchFBID() (int64, error) {
userInfo, _, err := fb.client.LoadMessagesPage()
if err != nil {
return 0, fmt.Errorf("failed to fetch FBID: %w", err)
}
return userInfo.GetFBID(), nil
}
27 changes: 27 additions & 0 deletions messagix/instagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,30 @@ func (ig *InstagramMethods) RegisterPushNotifications(endpoint string) error {

return nil
}

func (ig *InstagramMethods) FetchFBID() (int64, error) {
currentUser, tbl, err := ig.client.LoadMessagesPage()
if err != nil {
return 0, fmt.Errorf("failed to fetch FBID: %w", err)
}

var newFBID int64

for _, row := range tbl.LSVerifyContactRowExists {
if row.IsSelf && row.ContactId != newFBID {
if newFBID != 0 {
// Hopefully this won't happen
ig.client.Logger.Warn().Int64("prev_fbid", newFBID).Int64("new_fbid", row.ContactId).Msg("Got multiple fbids for self")
} else {
ig.client.Logger.Debug().Int64("fbid", row.ContactId).Msg("Found own fbid")
}
newFBID = row.ContactId
}
}
if newFBID == 0 {
newFBID = currentUser.GetFBID()
ig.client.Logger.Warn().Int64("fbid", newFBID).Msg("Own contact entry not found, falling back to fbid in current user object")
}

return newFBID, nil
}

0 comments on commit fb6a9cb

Please sign in to comment.