gmessages/libgm/messages.go

49 lines
1.4 KiB
Go
Raw Normal View History

package libgm
import (
"fmt"
2023-07-17 13:51:31 +00:00
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
)
2023-07-17 13:51:31 +00:00
func (c *Client) SendReaction(payload *gmproto.SendReactionPayload) (*gmproto.SendReactionResponse, error) {
actionType := gmproto.ActionType_SEND_REACTION
2023-07-15 22:45:57 +00:00
response, err := c.sessionHandler.sendMessage(actionType, payload)
if err != nil {
return nil, err
}
2023-07-17 13:51:31 +00:00
res, ok := response.Data.Decrypted.(*gmproto.SendReactionResponse)
if !ok {
2023-07-17 13:51:31 +00:00
return nil, fmt.Errorf("unexpected response type %T, expected *gmproto.SendReactionResponse", response.Data.Decrypted)
}
return res, nil
}
2023-07-17 13:51:31 +00:00
func (c *Client) DeleteMessage(messageID string) (*gmproto.DeleteMessageResponse, error) {
payload := &gmproto.DeleteMessagePayload{MessageID: messageID}
actionType := gmproto.ActionType_DELETE_MESSAGE
2023-07-15 22:45:57 +00:00
response, err := c.sessionHandler.sendMessage(actionType, payload)
if err != nil {
return nil, err
}
2023-07-17 13:51:31 +00:00
res, ok := response.Data.Decrypted.(*gmproto.DeleteMessageResponse)
if !ok {
2023-07-17 13:51:31 +00:00
return nil, fmt.Errorf("unexpected response type %T, expected *gmproto.DeleteMessagesResponse", response.Data.Decrypted)
}
return res, nil
}
2023-07-15 11:38:24 +00:00
func (c *Client) MarkRead(conversationID, messageID string) error {
2023-07-17 13:51:31 +00:00
payload := &gmproto.MessageReadPayload{ConversationID: conversationID, MessageID: messageID}
actionType := gmproto.ActionType_MESSAGE_READ
2023-07-15 11:38:24 +00:00
2023-07-15 22:45:57 +00:00
_, err := c.sessionHandler.sendMessage(actionType, payload)
return err
2023-07-15 11:38:24 +00:00
}