Skip to content

Commit

Permalink
render/send read receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Dec 26, 2024
1 parent 9431bbb commit f610532
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
11 changes: 10 additions & 1 deletion pkg/connector/handlegchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pkg/gchatmeow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit f610532

Please sign in to comment.