From 7ae50fffd46f544b860aa1614d7d8c1ed7080282 Mon Sep 17 00:00:00 2001 From: Anant Prakash Date: Tue, 7 Aug 2018 22:33:18 +0530 Subject: [PATCH] Update OutputTypingEvent format --- .../dendrite/typingserver/api/output.go | 14 +++++------ .../dendrite/typingserver/input/input.go | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/typingserver/api/output.go b/src/github.com/matrix-org/dendrite/typingserver/api/output.go index 08f834993..39b4b7d1e 100644 --- a/src/github.com/matrix-org/dendrite/typingserver/api/output.go +++ b/src/github.com/matrix-org/dendrite/typingserver/api/output.go @@ -16,16 +16,14 @@ package api type OutputTypingEvent struct { // The Event for the typing edu event. Event TypingEvent `json:"event"` + // Users typing in the room at the event. + TypingUsers []string `json:"typing_users"` } // TypingEvent represents a matrix edu event of type 'm.typing'. type TypingEvent struct { - Type string `json:"type"` - RoomID string `json:"room_id"` - Content TypingEventContent `json:"content"` -} - -// TypingEventContent for TypingEvent -type TypingEventContent struct { - UserIDs []string `json:"user_ids"` + Type string `json:"type"` + RoomID string `json:"room_id"` + UserID string `json:"user_id"` + Typing bool `json:"typing"` } diff --git a/src/github.com/matrix-org/dendrite/typingserver/input/input.go b/src/github.com/matrix-org/dendrite/typingserver/input/input.go index 735c4da65..b9968ce4c 100644 --- a/src/github.com/matrix-org/dendrite/typingserver/input/input.go +++ b/src/github.com/matrix-org/dendrite/typingserver/input/input.go @@ -53,24 +53,29 @@ func (t *TypingServerInputAPI) InputTypingEvent( t.Cache.RemoveUser(ite.UserID, ite.RoomID) } - return t.sendUpdateForRoom(ite.RoomID) + return t.sendEvent(ite) } -func (t *TypingServerInputAPI) sendUpdateForRoom(roomID string) error { - userIDs := t.Cache.GetTypingUsers(roomID) - event := &api.TypingEvent{ - Type: gomatrixserverlib.MTyping, - RoomID: roomID, - Content: api.TypingEventContent{UserIDs: userIDs}, +func (t *TypingServerInputAPI) sendEvent(ite *api.InputTypingEvent) error { + userIDs := t.Cache.GetTypingUsers(ite.RoomID) + ev := &api.TypingEvent{ + Type: gomatrixserverlib.MTyping, + RoomID: ite.RoomID, + UserID: ite.UserID, } - eventJSON, err := json.Marshal(api.OutputTypingEvent{Event: *event}) + ote := &api.OutputTypingEvent{ + Event: *ev, + TypingUsers: userIDs, + } + + eventJSON, err := json.Marshal(ote) if err != nil { return err } m := &sarama.ProducerMessage{ Topic: string(t.OutputTypingEventTopic), - Key: sarama.StringEncoder(roomID), + Key: sarama.StringEncoder(ite.RoomID), Value: sarama.ByteEncoder(eventJSON), }