user.go 757 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package chat
  2. import (
  3. "time"
  4. "git.ali33.ru/fcg-xvii/go-tools/json"
  5. "git.ali33.ru/fcg-xvii/rest"
  6. )
  7. type User struct {
  8. ID int64 `rest:"default"`
  9. Name string `rest:"default"`
  10. Password string `rest:"ignore"`
  11. Streams []rest.IStream
  12. }
  13. func (s *User) SendMessage(sender *User, message string, file rest.IReadCloserLen) {
  14. var files map[string]rest.IReadCloserLen
  15. if file != nil {
  16. files = make(map[string]rest.IReadCloserLen)
  17. }
  18. req := rest.NewRequestStream(
  19. time.Now().Add(time.Second*5),
  20. &rest.Request{
  21. Type: rest.RequestTypeEvent,
  22. Command: "/users/message",
  23. Data: json.Map{
  24. "sender": sender,
  25. "message": message,
  26. },
  27. Files: files,
  28. },
  29. )
  30. for _, stream := range s.Streams {
  31. stream.SendMessage(req)
  32. }
  33. }