Browse Source

Fix compatibility issues

master
1lann 5 years ago
parent
commit
d531425c8c
No known key found for this signature in database
GPG Key ID: E4EAE9E36D9BDEFA
  1. 8
      connect.go
  2. 6
      consts.go
  3. 2
      meta.go
  4. 6
      parse.go
  5. 1
      profile.go
  6. 59
      send.go
  7. 10
      session.go
  8. 4
      typing.go

8
connect.go

@ -79,10 +79,10 @@ func (s *Session) ConnectToChat() error {
return err
}
err = s.connectToStage3()
if err != nil {
return err
}
// err = s.connectToStage3()
// if err != nil {
// return err
// }
return nil
}

6
consts.go

@ -16,12 +16,12 @@ const (
threadSyncURL = "https://www.facebook.com/ajax/mercury/thread_sync.php"
reconnectURL = "https://www.facebook.com/ajax/presence/reconnect.php?reason=6"
readStatusURL = "https://www.facebook.com/ajax/mercury/change_read_status.php"
sendMessageURL = "https://www.facebook.com/messaging/send/"
sendMessageURL = "https://www.facebook.com/messaging/send/?dpr=2"
typingURL = "https://www.facebook.com/ajax/messaging/typ.php"
syncURL = "https://www.facebook.com/notifications/sync/?"
profileURL = "https://www.facebook.com/chat/user_info/"
profileURL = "https://www.facebook.com/chat/user_info/?dpr=2"
allProfileURL = "https://www.facebook.com/chat/user_info_all"
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
formURLEncoded = "application/x-www-form-urlencoded"
loggedOutError = 1357001
)

2
meta.go

@ -81,6 +81,8 @@ func (s *Session) addFormMeta(form url.Values) url.Values {
s.meta.req++
form.Set("__rev", s.meta.revision)
form.Set("__a", "1")
form.Set("__af", "h0")
form.Set("__be", "-1")
form.Set("fb_dtsg", s.meta.dtsg)
form.Set("ttstamp", s.meta.ttstamp)
return form

6
parse.go

@ -33,7 +33,11 @@ func unmarshalPullData(rd io.Reader, to interface{}) error {
}
if os.Getenv("MDEBUG") == "true" {
log.Println("debug response: " + string(data))
if len(data) > 10000 {
log.Println("debug response size:", len(data))
} else {
log.Println("debug response: " + string(data))
}
}
startPos := bytes.IndexByte(data, '{')

1
profile.go

@ -31,6 +31,7 @@ func (s *Session) UserProfileInfo(userID string) (UserProfile, error) {
req, _ := http.NewRequest(http.MethodPost, profileURL,
strings.NewReader(form.Encode()))
req.Header = defaultHeader()
req.Header.Set("Content-Type", formURLEncoded)
resp, err := s.doRequest(req)
if err != nil {

59
send.go

@ -49,35 +49,35 @@ func (s *Session) SendMessage(msg *Message) (string, error) {
}
form := url.Values{
"client": []string{"mercury"},
"action_type": []string{"ma-type:user-generated-message"},
"author": []string{"fbid:" + s.userID},
"timestamp": []string{strconv.FormatInt(time.Now().UnixNano()/1e6, 10)},
"timestamp_absolute": []string{"Today"},
"timestamp_relative": []string{time.Now().Format("15:04")},
"timestamp_time_passed": []string{"0"},
"is_unread": []string{"false"},
"is_cleared": []string{"false"},
"is_forward": []string{"false"},
"is_filtered_content": []string{"false"},
"is_filtered_content_bh": []string{"false"},
"is_filtered_content_account": []string{"false"},
"is_filtered_content_quasar": []string{"false"},
"is_filtered_content_invalid_app": []string{"false"},
"is_spoof_warning": []string{"false"},
"source": []string{"source:chat:web"},
"source_tags[0]": []string{"source:chat"},
"body": []string{msg.Body},
"html_body": []string{"false"},
"ui_push_phase": []string{"V3"},
"status": []string{"0"},
"offline_threading_id": []string{msg.offlineThreadID},
"message_id": []string{msg.offlineThreadID},
"threading_id": []string{s.generateThreadID()},
"ephemeral_ttl_mode:": []string{"0"},
"manual_retry_cnt": []string{"0"},
"has_attachment": []string{hasAttachment},
"signatureID": []string{generateSignatureID()},
"client": []string{"mercury"},
"action_type": []string{"ma-type:user-generated-message"},
// "author": []string{"fbid:" + s.userID},
"timestamp": []string{strconv.FormatInt(time.Now().UnixNano()/1e6, 10)},
// "timestamp_absolute": []string{"Today"},
// "timestamp_relative": []string{time.Now().Format("15:04")},
// "timestamp_time_passed": []string{"0"},
// "is_unread": []string{"false"},
// "is_cleared": []string{"false"},
// "is_forward": []string{"false"},
// "is_filtered_content": []string{"false"},
// "is_filtered_content_bh": []string{"false"},
// "is_filtered_content_account": []string{"false"},
// "is_filtered_content_quasar": []string{"false"},
// "is_filtered_content_invalid_app": []string{"false"},
// "is_spoof_warning": []string{"false"},
"source": []string{"source:messenger:web"},
"tags[0]": []string{"web:trigger:function (){return i(m)}"},
"body": []string{msg.Body},
"html_body": []string{"false"},
"ui_push_phase": []string{"C3"},
"status": []string{"0"},
"offline_threading_id": []string{msg.offlineThreadID},
"message_id": []string{msg.offlineThreadID},
"threading_id": []string{s.generateThreadID()},
"ephemeral_ttl_mode:": []string{"0"},
"manual_retry_cnt": []string{"0"},
"has_attachment": []string{hasAttachment},
"signature_id": []string{generateSignatureID()},
}
if msg.Thread.IsGroup {
@ -94,6 +94,7 @@ func (s *Session) SendMessage(msg *Message) (string, error) {
req, _ := http.NewRequest(http.MethodPost, sendMessageURL,
strings.NewReader(form.Encode()))
req.Header = defaultHeader()
req.Header.Set("Content-Type", formURLEncoded)
resp, err := s.doRequest(req)
if err != nil {

10
session.go

@ -1,8 +1,10 @@
package messenger
import (
"log"
"net/http"
"net/http/cookiejar"
"os"
"sync"
"time"
)
@ -39,7 +41,15 @@ func NewSession() *Session {
func (s *Session) doRequest(req *http.Request) (resp *http.Response, err error) {
s.requestMutex.RLock()
if os.Getenv("MDEBUG") == "true" {
log.Println("performing " + req.Method + " request to " + req.URL.String())
}
resp, err = s.client.Do(req)
if os.Getenv("MDEBUG") == "true" {
log.Println("response code:", resp.Status)
}
s.requestMutex.RUnlock()
return
}

4
typing.go

@ -9,6 +9,10 @@ import (
// SetTypingIndicator sets the typing indicator seen by members of the
// thread.
func (s *Session) SetTypingIndicator(thread Thread, typing bool) error {
if true {
return nil
}
form := make(url.Values)
form.Set("source", "mercury-chat")

Loading…
Cancel
Save