MM-21481: Fixed several issues from user marshalling (#13627)

* MM-21481: Fixed several issues from user marshalling

- Fixed the root cause for panic by properly converting
the map to a User struct.
- Added a check for type conversion for extra safety.
- Fixed a somewhat unrelated issue of a pointer to pointer reference.

* Fix tests
Этот коммит содержится в:
Agniva De Sarker
2020-01-16 13:48:08 +05:30
коммит произвёл Claudio Costa
родитель 87eb7697f9
Коммит 2a28edcd93
5 изменённых файлов: 28 добавлений и 9 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package model
import (
"bytes"
"encoding/json"
"fmt"
"io"
@@ -194,6 +195,15 @@ func WebSocketEventFromJson(data io.Reader) *WebSocketEvent {
return nil
}
ev.Event = o.Event
if u, ok := o.Data["user"]; ok {
// We need to convert to and from JSON again
// because the user is in the form of a map[string]interface{}.
buf, err := json.Marshal(u)
if err != nil {
return nil
}
o.Data["user"] = UserFromJson(bytes.NewReader(buf))
}
ev.Data = o.Data
ev.Broadcast = o.Broadcast
ev.Sequence = o.Sequence