mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-13 01:43:09 -06:00
Send one event per API call
This commit is contained in:
parent
9a710455c6
commit
edf90f7823
|
|
@ -37,18 +37,17 @@ func (p *TypingServerProducer) Send(
|
||||||
ctx context.Context, userID, roomID string,
|
ctx context.Context, userID, roomID string,
|
||||||
typing bool, timeout int64,
|
typing bool, timeout int64,
|
||||||
) error {
|
) error {
|
||||||
data := api.InputTypingEvent{
|
requestData := api.InputTypingEvent{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
Typing: typing,
|
Typing: typing,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
|
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
|
||||||
}
|
}
|
||||||
request := []api.InputTypingEvent{data}
|
|
||||||
|
|
||||||
var response api.InputTypingEventsResponse
|
var response api.InputTypingEventResponse
|
||||||
err := p.InputAPI.InputTypingEvents(
|
err := p.InputAPI.InputTypingEvent(
|
||||||
ctx, &api.InputTypingEventsRequest{InputTypingEvents: request}, &response,
|
ctx, &api.InputTypingEventRequest{InputTypingEvent: requestData}, &response,
|
||||||
)
|
)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -36,25 +36,25 @@ type InputTypingEvent struct {
|
||||||
OriginServerTS gomatrixserverlib.Timestamp `json:"origin_server_ts"`
|
OriginServerTS gomatrixserverlib.Timestamp `json:"origin_server_ts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputTypingEventsRequest is a request to TypingServerInputAPI
|
// InputTypingEventRequest is a request to TypingServerInputAPI
|
||||||
type InputTypingEventsRequest struct {
|
type InputTypingEventRequest struct {
|
||||||
InputTypingEvents []InputTypingEvent `json:"input_typing_events"`
|
InputTypingEvent InputTypingEvent `json:"input_typing_event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputTypingEventsResponse is a response to InputTypingEvents
|
// InputTypingEventResponse is a response to InputTypingEvents
|
||||||
type InputTypingEventsResponse struct{}
|
type InputTypingEventResponse struct{}
|
||||||
|
|
||||||
// TypingServerInputAPI is used to write events to the typing server.
|
// TypingServerInputAPI is used to write events to the typing server.
|
||||||
type TypingServerInputAPI interface {
|
type TypingServerInputAPI interface {
|
||||||
InputTypingEvents(
|
InputTypingEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *InputTypingEventsRequest,
|
request *InputTypingEventRequest,
|
||||||
response *InputTypingEventsResponse,
|
response *InputTypingEventResponse,
|
||||||
) error
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypingServerInputTypingEventsPath is the HTTP path for the InputTypingEvents API.
|
// TypingServerInputTypingEventPath is the HTTP path for the InputTypingEvent API.
|
||||||
const TypingServerInputTypingEventsPath = "/api/typingserver/input"
|
const TypingServerInputTypingEventPath = "/api/typingserver/input"
|
||||||
|
|
||||||
// NewTypingServerInputAPIHTTP creates a TypingServerInputAPI implemented by talking to a HTTP POST API.
|
// NewTypingServerInputAPIHTTP creates a TypingServerInputAPI implemented by talking to a HTTP POST API.
|
||||||
func NewTypingServerInputAPIHTTP(typingServerURL string, httpClient *http.Client) TypingServerInputAPI {
|
func NewTypingServerInputAPIHTTP(typingServerURL string, httpClient *http.Client) TypingServerInputAPI {
|
||||||
|
|
@ -70,14 +70,14 @@ type httpTypingServerInputAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputRoomEvents implements TypingServerInputAPI
|
// InputRoomEvents implements TypingServerInputAPI
|
||||||
func (h *httpTypingServerInputAPI) InputTypingEvents(
|
func (h *httpTypingServerInputAPI) InputTypingEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *InputTypingEventsRequest,
|
request *InputTypingEventRequest,
|
||||||
response *InputTypingEventsResponse,
|
response *InputTypingEventResponse,
|
||||||
) error {
|
) error {
|
||||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvents")
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvent")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
apiURL := h.typingServerURL + TypingServerInputTypingEventsPath
|
apiURL := h.typingServerURL + TypingServerInputTypingEventPath
|
||||||
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue