2023-06-30 09:54:08 +00:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
2023-09-04 11:24:45 +00:00
|
|
|
"errors"
|
2023-07-15 12:02:03 +00:00
|
|
|
"fmt"
|
2023-07-03 21:03:36 +00:00
|
|
|
"net/http"
|
|
|
|
|
2023-07-17 13:51:31 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
|
2023-06-30 09:54:08 +00:00
|
|
|
)
|
|
|
|
|
2023-06-30 13:09:29 +00:00
|
|
|
type ClientReady struct {
|
2023-07-15 23:24:39 +00:00
|
|
|
SessionID string
|
2023-07-17 13:51:31 +00:00
|
|
|
Conversations []*gmproto.Conversation
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 12:55:30 +00:00
|
|
|
type AuthTokenRefreshed struct{}
|
2023-07-03 21:03:36 +00:00
|
|
|
|
2024-02-23 18:25:31 +00:00
|
|
|
type GaiaLoggedOut struct{}
|
|
|
|
|
2024-04-05 10:04:39 +00:00
|
|
|
type NoDataReceived struct{}
|
|
|
|
|
2024-06-19 03:44:53 +00:00
|
|
|
type RecentlyDisconnected struct{}
|
|
|
|
|
2023-12-13 23:32:36 +00:00
|
|
|
type AccountChange struct {
|
|
|
|
*gmproto.AccountChangeOrSomethingEvent
|
|
|
|
IsFake bool
|
|
|
|
}
|
|
|
|
|
2023-09-04 11:24:45 +00:00
|
|
|
var ErrRequestedEntityNotFound = RequestError{
|
|
|
|
Data: &gmproto.ErrorResponse{
|
|
|
|
Type: 5,
|
|
|
|
Message: "Requested entity was not found.",
|
|
|
|
Class: []*gmproto.ErrorResponse_ErrorClass{{
|
|
|
|
Class: "type.googleapis.com/google.internal.communications.instantmessaging.v1.TachyonError",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type RequestError struct {
|
|
|
|
Data *gmproto.ErrorResponse
|
|
|
|
HTTP *HTTPError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re RequestError) Unwrap() error {
|
|
|
|
if re.HTTP == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return *re.HTTP
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re RequestError) Error() string {
|
|
|
|
if re.HTTP == nil {
|
|
|
|
return fmt.Sprintf("%d: %s", re.Data.Type, re.Data.Message)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("HTTP %d: %d: %s", re.HTTP.Resp.StatusCode, re.Data.Type, re.Data.Message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (re RequestError) Is(other error) bool {
|
2023-09-04 11:31:59 +00:00
|
|
|
var otherRe RequestError
|
|
|
|
if !errors.As(other, &otherRe) {
|
|
|
|
return re.HTTP != nil && errors.Is(*re.HTTP, other)
|
2023-09-04 11:24:45 +00:00
|
|
|
}
|
|
|
|
return otherRe.Data.GetType() == re.Data.GetType() &&
|
|
|
|
otherRe.Data.GetMessage() == re.Data.GetMessage()
|
|
|
|
// TODO check class?
|
|
|
|
}
|
|
|
|
|
2023-07-15 12:02:03 +00:00
|
|
|
type HTTPError struct {
|
|
|
|
Action string
|
|
|
|
Resp *http.Response
|
2023-09-04 11:24:45 +00:00
|
|
|
Body []byte
|
2023-07-15 12:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (he HTTPError) Error() string {
|
2023-07-19 10:58:53 +00:00
|
|
|
if he.Action == "" {
|
|
|
|
return fmt.Sprintf("unexpected http %d", he.Resp.StatusCode)
|
|
|
|
}
|
2023-07-15 12:02:03 +00:00
|
|
|
return fmt.Sprintf("http %d while %s", he.Resp.StatusCode, he.Action)
|
|
|
|
}
|
|
|
|
|
2023-07-03 21:03:36 +00:00
|
|
|
type ListenFatalError struct {
|
2023-07-15 12:02:03 +00:00
|
|
|
Error error
|
2023-07-03 21:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ListenTemporaryError struct {
|
|
|
|
Error error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ListenRecovered struct{}
|
2023-07-19 21:58:39 +00:00
|
|
|
|
|
|
|
type PhoneNotResponding struct{}
|
|
|
|
|
|
|
|
type PhoneRespondingAgain struct{}
|
2023-09-04 11:24:45 +00:00
|
|
|
|
|
|
|
type PingFailed struct {
|
2023-11-06 14:05:21 +00:00
|
|
|
Error error
|
|
|
|
ErrorCount int
|
2023-09-04 11:24:45 +00:00
|
|
|
}
|
2024-03-13 16:11:18 +00:00
|
|
|
|
|
|
|
type HackySetActiveMayFail struct{}
|