mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Update OutputTypingEvent format
This commit is contained in:
parent
0bd298ad85
commit
7ae50fffd4
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue