Send one event per API call

This commit is contained in:
Anant Prakash 2018-07-24 11:56:16 +05:30
parent 9a710455c6
commit edf90f7823
No known key found for this signature in database
GPG key ID: C5D399F626523045
2 changed files with 19 additions and 20 deletions

View file

@ -37,18 +37,17 @@ func (p *TypingServerProducer) Send(
ctx context.Context, userID, roomID string,
typing bool, timeout int64,
) error {
data := api.InputTypingEvent{
requestData := api.InputTypingEvent{
UserID: userID,
RoomID: roomID,
Typing: typing,
Timeout: timeout,
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
}
request := []api.InputTypingEvent{data}
var response api.InputTypingEventsResponse
err := p.InputAPI.InputTypingEvents(
ctx, &api.InputTypingEventsRequest{InputTypingEvents: request}, &response,
var response api.InputTypingEventResponse
err := p.InputAPI.InputTypingEvent(
ctx, &api.InputTypingEventRequest{InputTypingEvent: requestData}, &response,
)
return err

View file

@ -36,25 +36,25 @@ type InputTypingEvent struct {
OriginServerTS gomatrixserverlib.Timestamp `json:"origin_server_ts"`
}
// InputTypingEventsRequest is a request to TypingServerInputAPI
type InputTypingEventsRequest struct {
InputTypingEvents []InputTypingEvent `json:"input_typing_events"`
// InputTypingEventRequest is a request to TypingServerInputAPI
type InputTypingEventRequest struct {
InputTypingEvent InputTypingEvent `json:"input_typing_event"`
}
// InputTypingEventsResponse is a response to InputTypingEvents
type InputTypingEventsResponse struct{}
// InputTypingEventResponse is a response to InputTypingEvents
type InputTypingEventResponse struct{}
// TypingServerInputAPI is used to write events to the typing server.
type TypingServerInputAPI interface {
InputTypingEvents(
InputTypingEvent(
ctx context.Context,
request *InputTypingEventsRequest,
response *InputTypingEventsResponse,
request *InputTypingEventRequest,
response *InputTypingEventResponse,
) error
}
// TypingServerInputTypingEventsPath is the HTTP path for the InputTypingEvents API.
const TypingServerInputTypingEventsPath = "/api/typingserver/input"
// TypingServerInputTypingEventPath is the HTTP path for the InputTypingEvent API.
const TypingServerInputTypingEventPath = "/api/typingserver/input"
// NewTypingServerInputAPIHTTP creates a TypingServerInputAPI implemented by talking to a HTTP POST API.
func NewTypingServerInputAPIHTTP(typingServerURL string, httpClient *http.Client) TypingServerInputAPI {
@ -70,14 +70,14 @@ type httpTypingServerInputAPI struct {
}
// InputRoomEvents implements TypingServerInputAPI
func (h *httpTypingServerInputAPI) InputTypingEvents(
func (h *httpTypingServerInputAPI) InputTypingEvent(
ctx context.Context,
request *InputTypingEventsRequest,
response *InputTypingEventsResponse,
request *InputTypingEventRequest,
response *InputTypingEventResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvents")
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvent")
defer span.Finish()
apiURL := h.typingServerURL + TypingServerInputTypingEventsPath
apiURL := h.typingServerURL + TypingServerInputTypingEventPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}