Skip to content

Commit f610532

Browse files
committed
render/send read receipt
1 parent 9431bbb commit f610532

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

pkg/connector/handlegchat.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,18 @@ func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) {
6262
})
6363
case proto.Event_TYPING_STATE_CHANGED:
6464
state := evt.Body.GetTypingStateChanged()
65-
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Message[*proto.Message]{
65+
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Typing{
6666
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventTyping, state.UserId.Id, state.StartTimestampUsec),
6767
})
68+
case proto.Event_READ_RECEIPT_CHANGED:
69+
receipts := evt.Body.GetReadReceiptChanged().ReadReceiptSet.ReadReceipts
70+
for _, receipt := range receipts {
71+
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Receipt{
72+
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventReadReceipt, receipt.User.UserId.Id, receipt.ReadTimeMicros),
73+
ReadUpTo: time.UnixMicro(receipt.ReadTimeMicros),
74+
},
75+
)
76+
}
6877
}
6978

7079
c.setPortalRevision(ctx, evt)

pkg/connector/handlematrix.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
)
1414

1515
var (
16-
_ bridgev2.EditHandlingNetworkAPI = (*GChatClient)(nil)
17-
_ bridgev2.ReactionHandlingNetworkAPI = (*GChatClient)(nil)
18-
_ bridgev2.RedactionHandlingNetworkAPI = (*GChatClient)(nil)
19-
_ bridgev2.TypingHandlingNetworkAPI = (*GChatClient)(nil)
16+
_ bridgev2.EditHandlingNetworkAPI = (*GChatClient)(nil)
17+
_ bridgev2.ReactionHandlingNetworkAPI = (*GChatClient)(nil)
18+
_ bridgev2.ReadReceiptHandlingNetworkAPI = (*GChatClient)(nil)
19+
_ bridgev2.RedactionHandlingNetworkAPI = (*GChatClient)(nil)
20+
_ bridgev2.TypingHandlingNetworkAPI = (*GChatClient)(nil)
2021
)
2122

2223
func portalToGroupId(portal *bridgev2.Portal) *proto.GroupId {
@@ -231,3 +232,11 @@ func (c *GChatClient) HandleMatrixTyping(ctx context.Context, msg *bridgev2.Matr
231232
}
232233
return nil
233234
}
235+
236+
func (c *GChatClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridgev2.MatrixReadReceipt) error {
237+
_, err := c.client.MarkGroupReadstate(ctx, &proto.MarkGroupReadstateRequest{
238+
Id: portalToGroupId(msg.Portal),
239+
LastReadTime: msg.ReadUpTo.UnixMicro(),
240+
})
241+
return err
242+
}

pkg/gchatmeow/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ func (c *Client) SetTypingState(ctx context.Context, request *proto.SetTypingSta
180180
return response, c.gcRequest(ctx, "set_typing_state", request, response)
181181
}
182182

183+
func (c *Client) MarkGroupReadstate(ctx context.Context, request *proto.MarkGroupReadstateRequest) (*proto.MarkGroupReadstateResponse, error) {
184+
request.RequestHeader = c.gcRequestHeader
185+
response := &proto.MarkGroupReadstateResponse{}
186+
return response, c.gcRequest(ctx, "mark_group_readstate", request, response)
187+
}
188+
183189
func (c *Client) UploadFile(ctx context.Context, data []byte, groupId string, fileName string, mimeType string) (*proto.UploadMetadata, error) {
184190
headers := http.Header{
185191
"x-goog-upload-protocol": {"resumable"},

0 commit comments

Comments
 (0)