2023-06-30 11:05:33 +00:00
|
|
|
package libgm
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
)
|
2023-06-30 09:54:08 +00:00
|
|
|
|
|
|
|
type Session struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
// start receiving updates from mobile on this session
|
|
|
|
func (s *Session) SetActiveSession() error {
|
|
|
|
s.client.sessionHandler.ResetSessionId()
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
actionType := binary.ActionType_GET_UPDATES
|
|
|
|
_, sendErr := s.client.sessionHandler.completeSendMessage(actionType, false, nil)
|
|
|
|
if sendErr != nil {
|
|
|
|
return sendErr
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2023-07-09 11:16:52 +00:00
|
|
|
return nil
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
func (s *Session) IsBugleDefault() (*binary.IsBugleDefaultResponse, error) {
|
|
|
|
s.client.sessionHandler.ResetSessionId()
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
actionType := binary.ActionType_IS_BUGLE_DEFAULT
|
|
|
|
sentRequestId, sendErr := s.client.sessionHandler.completeSendMessage(actionType, true, nil)
|
|
|
|
if sendErr != nil {
|
|
|
|
return nil, sendErr
|
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
response, err := s.client.sessionHandler.WaitForResponse(sentRequestId, actionType)
|
2023-06-30 09:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
res, ok := response.Data.Decrypted.(*binary.IsBugleDefaultResponse)
|
|
|
|
if !ok {
|
2023-07-15 21:16:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected response type %T, expected *binary.IsBugleDefaultResponse", response.Data.Decrypted)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
return res, nil
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
func (s *Session) NotifyDittoActivity() error {
|
|
|
|
payload := &binary.NotifyDittoActivityPayload{Success: true}
|
|
|
|
actionType := binary.ActionType_NOTIFY_DITTO_ACTIVITY
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
sentRequestId, sendErr := s.client.sessionHandler.completeSendMessage(actionType, true, payload)
|
|
|
|
if sendErr != nil {
|
|
|
|
return sendErr
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
_, err := s.client.sessionHandler.WaitForResponse(sentRequestId, actionType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
return nil
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|