2023-07-09 11:16:52 +00:00
|
|
|
package libgm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/pblite"
|
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Client) handleUpdatesEvent(res *pblite.Response) {
|
|
|
|
switch res.Data.Action {
|
|
|
|
case binary.ActionType_GET_UPDATES:
|
|
|
|
data, ok := res.Data.Decrypted.(*binary.UpdateEvents)
|
|
|
|
if !ok {
|
|
|
|
c.Logger.Error().Any("res", res).Msg("failed to assert ActionType_GET_UPDATES event into UpdateEvents")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch evt := data.Event.(type) {
|
|
|
|
case *binary.UpdateEvents_UserAlertEvent:
|
2023-07-15 13:17:02 +00:00
|
|
|
c.rpc.logContent(res)
|
2023-07-09 11:16:52 +00:00
|
|
|
c.handleUserAlertEvent(res, evt.UserAlertEvent)
|
|
|
|
|
|
|
|
case *binary.UpdateEvents_SettingsEvent:
|
2023-07-15 13:17:02 +00:00
|
|
|
c.rpc.logContent(res)
|
2023-07-09 11:16:52 +00:00
|
|
|
c.handleSettingsEvent(res, evt.SettingsEvent)
|
|
|
|
|
|
|
|
case *binary.UpdateEvents_ConversationEvent:
|
2023-07-10 22:20:50 +00:00
|
|
|
if c.rpc.deduplicateUpdate(res) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.triggerEvent(evt.ConversationEvent.GetData())
|
2023-07-09 11:16:52 +00:00
|
|
|
|
|
|
|
case *binary.UpdateEvents_MessageEvent:
|
2023-07-10 22:20:50 +00:00
|
|
|
if c.rpc.deduplicateUpdate(res) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.triggerEvent(evt.MessageEvent.GetData())
|
2023-07-09 11:16:52 +00:00
|
|
|
|
|
|
|
case *binary.UpdateEvents_TypingEvent:
|
2023-07-15 13:17:02 +00:00
|
|
|
c.rpc.logContent(res)
|
2023-07-09 11:16:52 +00:00
|
|
|
c.handleTypingEvent(res, evt.TypingEvent.GetData())
|
|
|
|
default:
|
|
|
|
c.Logger.Debug().Any("evt", evt).Any("res", res).Msg("Got unknown event type")
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
c.Logger.Error().Any("response", res).Msg("ignoring response.")
|
|
|
|
}
|
|
|
|
}
|