Update OutputTypingEvent format

This commit is contained in:
Anant Prakash 2018-08-07 22:33:18 +05:30
parent 0bd298ad85
commit 7ae50fffd4
No known key found for this signature in database
GPG key ID: C5D399F626523045
2 changed files with 20 additions and 17 deletions

View file

@ -16,16 +16,14 @@ package api
type OutputTypingEvent struct { type OutputTypingEvent struct {
// The Event for the typing edu event. // The Event for the typing edu event.
Event TypingEvent `json:"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'. // TypingEvent represents a matrix edu event of type 'm.typing'.
type TypingEvent struct { type TypingEvent struct {
Type string `json:"type"` Type string `json:"type"`
RoomID string `json:"room_id"` RoomID string `json:"room_id"`
Content TypingEventContent `json:"content"` UserID string `json:"user_id"`
} Typing bool `json:"typing"`
// TypingEventContent for TypingEvent
type TypingEventContent struct {
UserIDs []string `json:"user_ids"`
} }

View file

@ -53,24 +53,29 @@ func (t *TypingServerInputAPI) InputTypingEvent(
t.Cache.RemoveUser(ite.UserID, ite.RoomID) t.Cache.RemoveUser(ite.UserID, ite.RoomID)
} }
return t.sendUpdateForRoom(ite.RoomID) return t.sendEvent(ite)
} }
func (t *TypingServerInputAPI) sendUpdateForRoom(roomID string) error { func (t *TypingServerInputAPI) sendEvent(ite *api.InputTypingEvent) error {
userIDs := t.Cache.GetTypingUsers(roomID) userIDs := t.Cache.GetTypingUsers(ite.RoomID)
event := &api.TypingEvent{ ev := &api.TypingEvent{
Type: gomatrixserverlib.MTyping, Type: gomatrixserverlib.MTyping,
RoomID: roomID, RoomID: ite.RoomID,
Content: api.TypingEventContent{UserIDs: userIDs}, 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 { if err != nil {
return err return err
} }
m := &sarama.ProducerMessage{ m := &sarama.ProducerMessage{
Topic: string(t.OutputTypingEventTopic), Topic: string(t.OutputTypingEventTopic),
Key: sarama.StringEncoder(roomID), Key: sarama.StringEncoder(ite.RoomID),
Value: sarama.ByteEncoder(eventJSON), Value: sarama.ByteEncoder(eventJSON),
} }