Skip to content

Commit

Permalink
support sending text msg
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Dec 8, 2024
1 parent 3473f5a commit 3981662
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *GChatClient) Disconnect() {
}

func (c *GChatClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities {
return nil
return &bridgev2.NetworkRoomCapabilities{}
}

func (c *GChatClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error) {
Expand All @@ -46,7 +46,7 @@ func (c *GChatClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*
}

func (c *GChatClient) IsLoggedIn() bool {
return false
return true
}

func (c *GChatClient) IsThisUser(ctx context.Context, userID networkid.UserID) bool {
Expand Down
35 changes: 34 additions & 1 deletion pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@ package connector
import (
"context"

"go.mau.fi/mautrix-googlechat/pkg/gchatmeow/proto"
"google.golang.org/protobuf/encoding/prototext"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
)

func portalToGroupId(portal *bridgev2.Portal) (*proto.GroupId, error) {
groupId := &proto.GroupId{}
err := prototext.Unmarshal([]byte(portal.ID), groupId)
if err != nil {
return nil, err
}

return groupId, nil
}

func (c *GChatClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage) (message *bridgev2.MatrixMessageResponse, err error) {
return nil, nil
groupId, err := portalToGroupId(msg.Portal)
if err != nil {
return nil, err
}

res, err := c.Client.CreateTopic(ctx, &proto.CreateTopicRequest{
GroupId: groupId,
TextBody: &msg.Content.Body,
})
if err != nil {
return nil, err
}
msgID := *res.Topic.Id.TopicId
msg.AddPendingToIgnore(networkid.TransactionID(msgID))
return &bridgev2.MatrixMessageResponse{
DB: &database.Message{
ID: networkid.MessageID(msgID),
},
RemovePending: networkid.TransactionID(msgID),
}, nil
}
7 changes: 7 additions & 0 deletions pkg/gchatmeow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ func (c *Client) paginatedWorld(ctx context.Context) (*proto.PaginatedWorldRespo
err := c.gcRequest(ctx, "paginated_world", request, response)
return response, err
}

func (c *Client) CreateTopic(ctx context.Context, request *proto.CreateTopicRequest) (*proto.CreateTopicResponse, error) {
request.RequestHeader = c.gcRequestHeader
response := &proto.CreateTopicResponse{}
err := c.gcRequest(ctx, "create_topic", request, response)
return response, err
}

0 comments on commit 3981662

Please sign in to comment.