Skip to content

Commit

Permalink
send reply
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Dec 15, 2024
1 parent 571c027 commit 7aa90e6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
19 changes: 18 additions & 1 deletion pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package connector
import (
"context"
"fmt"
"strings"
"time"

"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/networkid"
"maunium.net/go/mautrix/bridgev2/simplevent"

"go.mau.fi/util/ptr"

"go.mau.fi/mautrix-googlechat/pkg/gchatmeow"
"go.mau.fi/mautrix-googlechat/pkg/gchatmeow/proto"
)
Expand Down Expand Up @@ -40,8 +43,22 @@ func (c *GChatClient) Connect(ctx context.Context) error {
func (c *GChatClient) Disconnect() {
}

var dmCaps = &bridgev2.NetworkRoomCapabilities{
Replies: true,
}

var spaceCaps *bridgev2.NetworkRoomCapabilities

func init() {
spaceCaps = ptr.Clone(dmCaps)
spaceCaps.Threads = true
}

func (c *GChatClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities {
return &bridgev2.NetworkRoomCapabilities{}
if strings.Contains(string(portal.ID), "space") {
return spaceCaps
}
return dmCaps
}

func (c *GChatClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/connector/handlegchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package connector
import (
"context"
"fmt"
"time"

"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/networkid"
"maunium.net/go/mautrix/bridgev2/simplevent"
bridgeEvt "maunium.net/go/mautrix/event"

"go.mau.fi/mautrix-googlechat/pkg/gchatmeow/proto"
"go.mau.fi/util/ptr"

"go.mau.fi/mautrix-googlechat/pkg/gchatmeow/proto"
)

func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) {
Expand All @@ -36,7 +38,7 @@ func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) {
SenderLogin: networkid.UserLoginID(senderId),
Sender: networkid.UserID(senderId),
},
// Timestamp: evtData.CreatedAt,
Timestamp: time.UnixMicro(*msg.CreateTime),
},
ID: networkid.MessageID(*msg.LocalId),
Data: msg,
Expand Down
27 changes: 25 additions & 2 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ func (c *GChatClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.Mat
return nil, err
}

plainGroupId := groupId.GetDmId().DmId
if plainGroupId == nil {
var plainGroupId *string
if groupId.GetDmId() != nil {
plainGroupId = groupId.GetDmId().DmId
} else {
plainGroupId = groupId.GetSpaceId().SpaceId
}

Expand Down Expand Up @@ -59,6 +61,27 @@ func (c *GChatClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.Mat
}
}

if msg.ReplyTo != nil {
replyToId := ptr.Ptr(string(msg.ReplyTo.ID))
req.MessageInfo = &proto.MessageInfo{
AcceptFormatAnnotations: ptr.Ptr(true),
ReplyTo: &proto.SendReplyTarget{
Id: &proto.MessageId{
ParentId: &proto.MessageParentId{
Parent: &proto.MessageParentId_TopicId{
TopicId: &proto.TopicId{
GroupId: groupId,
TopicId: replyToId,
},
},
},
MessageId: replyToId,
},
CreateTime: ptr.Ptr(msg.ReplyTo.Timestamp.UnixMicro()),
},
}
}

res, err := c.client.CreateTopic(ctx, req)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/gchatmeow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *Client) UploadFile(ctx context.Context, data []byte, groupId string, fi
headers := http.Header{
"x-goog-upload-protocol": {"resumable"},
"x-goog-upload-command": {"start"},
"x-goog-upload-content-length": {string(len(data))},
"x-goog-upload-content-length": {strconv.Itoa(len(data))},
"x-goog-upload-content-type": {mimeType},
"x-goog-upload-file-name": {fileName},
}
Expand Down

0 comments on commit 7aa90e6

Please sign in to comment.