gmessages/libgm/conversations.go

88 lines
3.5 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 13:51:31 +00:00
func (c *Client) ListConversations(count int64, folder gmproto.ListConversationsPayload_Folder) (*gmproto.Conversations, error) {
payload := &gmproto.ListConversationsPayload{Count: count, Folder: folder}
//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:11:43 +00:00
return typedResponse[*gmproto.Conversations](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) {
payload := &gmproto.ListContactsPayload{
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) {
payload := &gmproto.ListTopContactsPayload{
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 13:51:31 +00:00
func (c *Client) GetOrCreateConversation(req *gmproto.GetOrCreateConversationPayload) (*gmproto.GetOrCreateConversationResponse, error) {
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) {
payload := &gmproto.ConversationTypePayload{ConversationID: conversationID}
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 13:51:31 +00:00
func (c *Client) FetchMessages(conversationID string, count int64, cursor *gmproto.Cursor) (*gmproto.FetchMessagesResponse, error) {
payload := &gmproto.FetchConversationMessagesPayload{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 13:51:31 +00:00
func (c *Client) SendMessage(payload *gmproto.SendMessagePayload) (*gmproto.SendMessageResponse, error) {
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 13:51:31 +00:00
func (c *Client) GetParticipantThumbnail(convID string) (*gmproto.ParticipantThumbnail, error) {
payload := &gmproto.GetParticipantThumbnailPayload{ConversationID: convID}
actionType := gmproto.ActionType_GET_PARTICIPANTS_THUMBNAIL
2023-07-17 23:11:43 +00:00
return typedResponse[*gmproto.ParticipantThumbnail](c.sessionHandler.sendMessage(actionType, payload))
}
2023-07-17 13:51:31 +00:00
func (c *Client) UpdateConversation(convBuilder *ConversationBuilder) (*gmproto.UpdateConversationResponse, error) {
data := &gmproto.UpdateConversationPayload{}
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 13:51:31 +00:00
payload := &gmproto.TypingUpdatePayload{Data: &gmproto.SetTypingIn{ConversationID: convID, Typing: true}}
actionType := gmproto.ActionType_TYPING_UPDATES
2023-07-15 22:45:57 +00:00
_, err := c.sessionHandler.sendMessage(actionType, payload)
return err
}