gmessages/libgm/events/ready.go

95 lines
1.8 KiB
Go
Raw Normal View History

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{}
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 {
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{}
type PhoneNotResponding struct{}
type PhoneRespondingAgain struct{}
2023-09-04 11:24:45 +00:00
type PingFailed struct {
Error error
ErrorCount int
2023-09-04 11:24:45 +00:00
}