Skip to content

Commit

Permalink
render/send typing
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Dec 26, 2024
1 parent af40085 commit 9431bbb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/connector/handlegchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (c *GChatClient) onStreamEvent(ctx context.Context, raw any) {
EventMeta: eventMeta,
TargetMessage: networkid.MessageID(msg.MessageId.MessageId),
})
case proto.Event_TYPING_STATE_CHANGED:
state := evt.Body.GetTypingStateChanged()
c.userLogin.Bridge.QueueRemoteEvent(c.userLogin, &simplevent.Message[*proto.Message]{
EventMeta: c.makeEventMeta(evt, bridgev2.RemoteEventTyping, state.UserId.Id, state.StartTimestampUsec),
})
}

c.setPortalRevision(ctx, evt)
Expand Down
35 changes: 24 additions & 11 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ var (
_ bridgev2.EditHandlingNetworkAPI = (*GChatClient)(nil)
_ bridgev2.ReactionHandlingNetworkAPI = (*GChatClient)(nil)
_ bridgev2.RedactionHandlingNetworkAPI = (*GChatClient)(nil)
_ bridgev2.TypingHandlingNetworkAPI = (*GChatClient)(nil)
)

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

return groupId, nil
prototext.Unmarshal([]byte(portal.ID), groupId)
return groupId
}

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

var plainGroupId string
if groupId.GetDmId() != nil {
Expand Down Expand Up @@ -218,3 +212,22 @@ func (c *GChatClient) doHandleMatrixReaction(ctx context.Context, portal *bridge
})
return err
}

func (c *GChatClient) HandleMatrixTyping(ctx context.Context, msg *bridgev2.MatrixTyping) error {
if msg.Type == bridgev2.TypingTypeText {
state := proto.TypingState_STOPPED
if msg.IsTyping {
state = proto.TypingState_TYPING
}
_, err := c.client.SetTypingState(ctx, &proto.SetTypingStateRequest{
Context: &proto.TypingContext{
Context: &proto.TypingContext_GroupId{
GroupId: portalToGroupId(msg.Portal),
},
},
State: state,
})
return err
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/gchatmeow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func (c *Client) UpdateReaction(ctx context.Context, request *proto.UpdateReacti
return response, c.gcRequest(ctx, "update_reaction", request, response)
}

func (c *Client) SetTypingState(ctx context.Context, request *proto.SetTypingStateRequest) (*proto.SetTypingStateResponse, error) {
request.RequestHeader = c.gcRequestHeader
response := &proto.SetTypingStateResponse{}
return response, c.gcRequest(ctx, "set_typing_state", 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 9431bbb

Please sign in to comment.