diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/user.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/server/user.go b/server/user.go index 6b0e946..cc8c160 100644 --- a/server/user.go +++ b/server/user.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "log" "net" @@ -154,12 +155,25 @@ func (s *Server) handleUsermode(user *User, conn net.Conn, mode core.Usermode) e return nil } +// TODO: Replace user.Send(error) with conn.Send() +// TODO: Better errors + func (s *Server) handleHistory(user *User, conn net.Conn, hist core.History) error { - // TODO: Add permissions check + addr, err := core.ReadAddr(hist.Channel) + if err != nil { + fmt.Println("cannot parse address:", err) + return user.Send(conn, core.Error{core.ErrorNotFound}) + } + + if _, ok := user.Channels[addr.Channel]; !ok { + fmt.Println("cannot get message history: not authorized") + return user.Send(conn, core.Error{core.ErrorNotFound}) + } messages, err := s.Storage.Read(hist.Channel, hist.Since, int(hist.Count), int(hist.Offset)) if err != nil { - return err + fmt.Println("cannot get message history:", err) + return user.Send(conn, core.Error{core.ErrorNotFound}) } for _, m := range messages { |
