2023-07-09 11:16:52 +00:00
|
|
|
package libgm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-07-17 13:51:31 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
|
2023-07-09 11:16:52 +00:00
|
|
|
)
|
|
|
|
|
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-09 11:16:52 +00:00
|
|
|
|
2023-07-15 22:45:57 +00:00
|
|
|
response, err := c.sessionHandler.sendMessage(actionType, payload)
|
2023-07-09 11:16:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-17 13:51:31 +00:00
|
|
|
res, ok := response.Data.Decrypted.(*gmproto.SendReactionResponse)
|
2023-07-09 11:16:52 +00:00
|
|
|
if !ok {
|
2023-07-17 13:51:31 +00:00
|
|
|
return nil, fmt.Errorf("unexpected response type %T, expected *gmproto.SendReactionResponse", response.Data.Decrypted)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-09 11:16:52 +00:00
|
|
|
|
2023-07-15 22:45:57 +00:00
|
|
|
response, err := c.sessionHandler.sendMessage(actionType, payload)
|
2023-07-09 11:16:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-17 13:51:31 +00:00
|
|
|
res, ok := response.Data.Decrypted.(*gmproto.DeleteMessageResponse)
|
2023-07-09 11:16:52 +00:00
|
|
|
if !ok {
|
2023-07-17 13:51:31 +00:00
|
|
|
return nil, fmt.Errorf("unexpected response type %T, expected *gmproto.DeleteMessagesResponse", response.Data.Decrypted)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
2023-07-15 11:38:24 +00:00
|
|
|
|
2023-07-15 21:26:22 +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
|
|
|
}
|