gmessages/libgm/conversations.go

100 lines
4 KiB
Go
Raw Normal View History

2023-06-30 11:05:33 +00:00
package libgm
2023-06-30 09:54:08 +00:00
import (
2023-07-17 13:51:31 +00:00
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
2023-06-30 09:54:08 +00:00
)
2023-07-17 23:57:20 +00:00
func (c *Client) ListConversations(count int64, folder gmproto.ListConversationsRequest_Folder) (*gmproto.ListConversationsResponse, error) {
payload := &gmproto.ListConversationsRequest{Count: count, Folder: folder}
2023-07-17 13:51:31 +00:00
//var actionType gmproto.ActionType
//if !c.synced {
2023-07-17 13:51:31 +00:00
// actionType = gmproto.ActionType_LIST_CONVERSATIONS_SYNC
// c.synced = true
//} else {
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_LIST_CONVERSATIONS
2023-07-17 23:57:20 +00:00
return typedResponse[*gmproto.ListConversationsResponse](c.sessionHandler.sendMessage(actionType, payload))
2023-06-30 09:54:08 +00:00
}
2023-07-17 13:51:31 +00:00
func (c *Client) ListContacts() (*gmproto.ListContactsResponse, error) {
2023-07-17 23:57:20 +00:00
payload := &gmproto.ListContactsRequest{
I1: 1,
I2: 350,
I3: 50,
}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_LIST_CONTACTS
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.ListContactsResponse](c.sessionHandler.sendMessage(actionType, payload))
}
2023-07-17 13:51:31 +00:00
func (c *Client) ListTopContacts() (*gmproto.ListTopContactsResponse, error) {
2023-07-17 23:57:20 +00:00
payload := &gmproto.ListTopContactsRequest{
Count: 8,
}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_LIST_TOP_CONTACTS
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.ListTopContactsResponse](c.sessionHandler.sendMessage(actionType, payload))
}
2023-07-17 23:57:20 +00:00
func (c *Client) GetOrCreateConversation(req *gmproto.GetOrCreateConversationRequest) (*gmproto.GetOrCreateConversationResponse, error) {
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_GET_OR_CREATE_CONVERSATION
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.GetOrCreateConversationResponse](c.sessionHandler.sendMessage(actionType, req))
}
2023-07-17 13:51:31 +00:00
func (c *Client) GetConversationType(conversationID string) (*gmproto.GetConversationTypeResponse, error) {
2023-07-17 23:57:20 +00:00
payload := &gmproto.ConversationTypeRequest{ConversationID: conversationID}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_GET_CONVERSATION_TYPE
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.GetConversationTypeResponse](c.sessionHandler.sendMessage(actionType, payload))
2023-06-30 09:54:08 +00:00
}
2023-07-17 23:19:25 +00:00
func (c *Client) GetConversation(conversationID string) (*gmproto.Conversation, error) {
2023-07-17 23:57:20 +00:00
payload := &gmproto.GetConversationRequest{ConversationID: conversationID}
2023-07-17 23:19:25 +00:00
actionType := gmproto.ActionType_GET_CONVERSATION
resp, err := typedResponse[*gmproto.GetConversationResponse](c.sessionHandler.sendMessage(actionType, payload))
if err != nil {
return nil, err
}
return resp.GetConversation(), nil
}
2023-07-17 13:51:31 +00:00
func (c *Client) FetchMessages(conversationID string, count int64, cursor *gmproto.Cursor) (*gmproto.FetchMessagesResponse, error) {
2023-07-17 23:57:20 +00:00
payload := &gmproto.FetchMessagesRequest{ConversationID: conversationID, Count: count}
if cursor != nil {
payload.Cursor = cursor
2023-06-30 09:54:08 +00:00
}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_LIST_MESSAGES
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.FetchMessagesResponse](c.sessionHandler.sendMessage(actionType, payload))
}
2023-06-30 09:54:08 +00:00
2023-07-17 23:57:20 +00:00
func (c *Client) SendMessage(payload *gmproto.SendMessageRequest) (*gmproto.SendMessageResponse, error) {
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_SEND_MESSAGE
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.SendMessageResponse](c.sessionHandler.sendMessage(actionType, payload))
2023-06-30 09:54:08 +00:00
}
2023-07-17 23:57:20 +00:00
func (c *Client) GetParticipantThumbnail(convID string) (*gmproto.GetParticipantThumbnailResponse, error) {
payload := &gmproto.GetParticipantThumbnailRequest{ConversationID: convID}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_GET_PARTICIPANTS_THUMBNAIL
2023-07-17 23:57:20 +00:00
return typedResponse[*gmproto.GetParticipantThumbnailResponse](c.sessionHandler.sendMessage(actionType, payload))
}
2023-07-17 13:51:31 +00:00
func (c *Client) UpdateConversation(convBuilder *ConversationBuilder) (*gmproto.UpdateConversationResponse, error) {
2023-07-17 23:57:20 +00:00
data := &gmproto.UpdateConversationRequest{}
payload, buildErr := convBuilder.Build(data)
if buildErr != nil {
panic(buildErr)
}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_UPDATE_CONVERSATION
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.UpdateConversationResponse](c.sessionHandler.sendMessage(actionType, payload))
}
func (c *Client) SetTyping(convID string) error {
2023-07-17 23:57:20 +00:00
payload := &gmproto.TypingUpdateRequest{
Data: &gmproto.TypingUpdateRequest_Data{ConversationID: convID, Typing: true},
}
2023-07-17 13:51:31 +00:00
actionType := gmproto.ActionType_TYPING_UPDATES
2023-07-15 22:45:57 +00:00
_, err := c.sessionHandler.sendMessage(actionType, payload)
return err
}