gmessages/libgm/useralert_handler.go

41 lines
1.2 KiB
Go
Raw Normal View History

package libgm
import (
"go.mau.fi/mautrix-gmessages/libgm/pblite"
"go.mau.fi/mautrix-gmessages/libgm/binary"
"go.mau.fi/mautrix-gmessages/libgm/events"
)
func (c *Client) handleClientReady(newSessionId string) {
c.Logger.Info().Any("sessionId", newSessionId).Msg("Client is ready!")
2023-07-15 21:55:55 +00:00
conversations, convErr := c.ListConversations(25, binary.ListConversationsPayload_INBOX)
if convErr != nil {
panic(convErr)
}
c.Logger.Debug().Any("conversations", conversations).Msg("got conversations")
notifyErr := c.NotifyDittoActivity()
if notifyErr != nil {
panic(notifyErr)
}
readyEvt := events.NewClientReady(newSessionId, conversations)
c.triggerEvent(readyEvt)
}
func (c *Client) handleUserAlertEvent(res *pblite.Response, data *binary.UserAlertEvent) {
alertType := data.AlertType
switch alertType {
case binary.AlertType_BROWSER_ACTIVE:
2023-07-15 22:45:57 +00:00
newSessionId := res.Data.RequestID
c.Logger.Info().Any("sessionId", newSessionId).Msg("[NEW_BROWSER_ACTIVE] Opened new browser connection")
2023-07-15 22:45:57 +00:00
if newSessionId != c.sessionHandler.sessionID {
evt := events.NewBrowserActive(newSessionId)
c.triggerEvent(evt)
} else {
go c.handleClientReady(newSessionId)
}
default:
2023-07-15 12:02:03 +00:00
c.triggerEvent(data)
}
}