2023-07-09 11:16:52 +00:00
|
|
|
package libgm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
)
|
|
|
|
|
2023-07-15 21:26:22 +00:00
|
|
|
func (c *Client) SendReaction(payload *binary.SendReactionPayload) (*binary.SendReactionResponse, error) {
|
2023-07-09 11:16:52 +00:00
|
|
|
actionType := binary.ActionType_SEND_REACTION
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
res, ok := response.Data.Decrypted.(*binary.SendReactionResponse)
|
|
|
|
if !ok {
|
2023-07-15 21:16:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected response type %T, expected *binary.SendReactionResponse", response.Data.Decrypted)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-07-15 21:26:22 +00:00
|
|
|
func (c *Client) DeleteMessage(messageID string) (*binary.DeleteMessageResponse, error) {
|
|
|
|
payload := &binary.DeleteMessagePayload{MessageID: messageID}
|
2023-07-09 11:16:52 +00:00
|
|
|
actionType := binary.ActionType_DELETE_MESSAGE
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
res, ok := response.Data.Decrypted.(*binary.DeleteMessageResponse)
|
|
|
|
if !ok {
|
2023-07-15 21:16:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected response type %T, expected *binary.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-15 11:38:24 +00:00
|
|
|
payload := &binary.MessageReadPayload{ConversationID: conversationID, MessageID: messageID}
|
|
|
|
actionType := binary.ActionType_MESSAGE_READ
|
|
|
|
|
2023-07-15 22:45:57 +00:00
|
|
|
_, err := c.sessionHandler.sendMessage(actionType, payload)
|
|
|
|
return err
|
2023-07-15 11:38:24 +00:00
|
|
|
}
|