diff --git a/pkg/connector/handlegchat.go b/pkg/connector/handlegchat.go index 3335148..e4f68a9 100644 --- a/pkg/connector/handlegchat.go +++ b/pkg/connector/handlegchat.go @@ -62,9 +62,18 @@ func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) { }) case proto.Event_TYPING_STATE_CHANGED: state := evt.Body.GetTypingStateChanged() - c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Message[*proto.Message]{ + c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Typing{ EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventTyping, state.UserId.Id, state.StartTimestampUsec), }) + case proto.Event_READ_RECEIPT_CHANGED: + receipts := evt.Body.GetReadReceiptChanged().ReadReceiptSet.ReadReceipts + for _, receipt := range receipts { + c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Receipt{ + EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventReadReceipt, receipt.User.UserId.Id, receipt.ReadTimeMicros), + ReadUpTo: time.UnixMicro(receipt.ReadTimeMicros), + }, + ) + } } c.setPortalRevision(ctx, evt) diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index bf3e13c..b5a212e 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -13,10 +13,11 @@ import ( ) var ( - _ bridgev2.EditHandlingNetworkAPI = (*GChatClient)(nil) - _ bridgev2.ReactionHandlingNetworkAPI = (*GChatClient)(nil) - _ bridgev2.RedactionHandlingNetworkAPI = (*GChatClient)(nil) - _ bridgev2.TypingHandlingNetworkAPI = (*GChatClient)(nil) + _ bridgev2.EditHandlingNetworkAPI = (*GChatClient)(nil) + _ bridgev2.ReactionHandlingNetworkAPI = (*GChatClient)(nil) + _ bridgev2.ReadReceiptHandlingNetworkAPI = (*GChatClient)(nil) + _ bridgev2.RedactionHandlingNetworkAPI = (*GChatClient)(nil) + _ bridgev2.TypingHandlingNetworkAPI = (*GChatClient)(nil) ) func portalToGroupId(portal *bridgev2.Portal) *proto.GroupId { @@ -231,3 +232,11 @@ func (c *GChatClient) HandleMatrixTyping(ctx context.Context, msg *bridgev2.Matr } return nil } + +func (c *GChatClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridgev2.MatrixReadReceipt) error { + _, err := c.client.MarkGroupReadstate(ctx, &proto.MarkGroupReadstateRequest{ + Id: portalToGroupId(msg.Portal), + LastReadTime: msg.ReadUpTo.UnixMicro(), + }) + return err +} diff --git a/pkg/gchatmeow/api.go b/pkg/gchatmeow/api.go index 8bba57f..648f751 100644 --- a/pkg/gchatmeow/api.go +++ b/pkg/gchatmeow/api.go @@ -180,6 +180,12 @@ func (c *Client) SetTypingState(ctx context.Context, request *proto.SetTypingSta return response, c.gcRequest(ctx, "set_typing_state", request, response) } +func (c *Client) MarkGroupReadstate(ctx context.Context, request *proto.MarkGroupReadstateRequest) (*proto.MarkGroupReadstateResponse, error) { + request.RequestHeader = c.gcRequestHeader + response := &proto.MarkGroupReadstateResponse{} + return response, c.gcRequest(ctx, "mark_group_readstate", request, response) +} + func (c *Client) UploadFile(ctx context.Context, data []byte, groupId string, fileName string, mimeType string) (*proto.UploadMetadata, error) { headers := http.Header{ "x-goog-upload-protocol": {"resumable"},