2023-07-09 11:16:52 +00:00
|
|
|
package libgm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Messages struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2023-07-12 21:44:57 +00:00
|
|
|
func (m *Messages) React(payload *binary.SendReactionPayload) (*binary.SendReactionResponse, error) {
|
2023-07-09 11:16:52 +00:00
|
|
|
actionType := binary.ActionType_SEND_REACTION
|
|
|
|
|
|
|
|
sentRequestId, sendErr := m.client.sessionHandler.completeSendMessage(actionType, true, payload)
|
|
|
|
if sendErr != nil {
|
|
|
|
return nil, sendErr
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err := m.client.sessionHandler.WaitForResponse(sentRequestId, actionType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, ok := response.Data.Decrypted.(*binary.SendReactionResponse)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("failed to assert response into SendReactionResponse")
|
|
|
|
}
|
|
|
|
|
|
|
|
m.client.Logger.Debug().Any("res", res).Msg("sent reaction!")
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messages) Delete(messageId string) (*binary.DeleteMessageResponse, error) {
|
|
|
|
payload := &binary.DeleteMessagePayload{MessageID: messageId}
|
|
|
|
actionType := binary.ActionType_DELETE_MESSAGE
|
|
|
|
|
|
|
|
sentRequestId, sendErr := m.client.sessionHandler.completeSendMessage(actionType, true, payload)
|
|
|
|
if sendErr != nil {
|
|
|
|
return nil, sendErr
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err := m.client.sessionHandler.WaitForResponse(sentRequestId, actionType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, ok := response.Data.Decrypted.(*binary.DeleteMessageResponse)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("failed to assert response into DeleteMessageResponse")
|
|
|
|
}
|
|
|
|
|
|
|
|
m.client.Logger.Debug().Any("res", res).Msg("deleted message!")
|
|
|
|
return res, nil
|
|
|
|
}
|
2023-07-15 11:38:24 +00:00
|
|
|
|
|
|
|
func (m *Messages) MarkRead(conversationID, messageID string) error {
|
|
|
|
payload := &binary.MessageReadPayload{ConversationID: conversationID, MessageID: messageID}
|
|
|
|
actionType := binary.ActionType_MESSAGE_READ
|
|
|
|
|
|
|
|
sentRequestId, sendErr := m.client.sessionHandler.completeSendMessage(actionType, true, payload)
|
|
|
|
if sendErr != nil {
|
|
|
|
return sendErr
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := m.client.sessionHandler.WaitForResponse(sentRequestId, actionType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|