diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/storage.go | 3 | ||||
| -rw-r--r-- | server/user.go | 14 |
2 files changed, 14 insertions, 3 deletions
diff --git a/server/storage.go b/server/storage.go index 1cb725f..99402c8 100644 --- a/server/storage.go +++ b/server/storage.go @@ -8,7 +8,8 @@ import ( type Storage interface { AddMessage(msg core.Message) (err error) - GetHistory(channel string, since time.Time, num, offset int) (history []core.Message, err error) + GetHistory(target string, since time.Time, num, offset int) (history []core.Message, err error) + GetHistoryUser(user1, user2 string, since time.Time, num, offset int) (history []core.Message, err error) SetUser(user core.UserData) error DelUser(name string) error diff --git a/server/user.go b/server/user.go index 9a0a71b..69b7ced 100644 --- a/server/user.go +++ b/server/user.go @@ -161,7 +161,7 @@ func (s *Server) handleUsermode(user *User, conn net.Conn, mode core.Usermode) e // TODO: Better errors func (s *Server) handleHistory(user *User, conn net.Conn, hist core.History) error { - _, err := core.ReadAddr(hist.Channel) + addr, err := core.ReadAddr(hist.Channel) if err != nil { fmt.Println("cannot parse address:", err) return user.Send(conn, core.Error{core.ErrorNotFound}) @@ -178,7 +178,17 @@ func (s *Server) handleHistory(user *User, conn net.Conn, hist core.History) err return user.Send(conn, core.Error{core.ErrorNotFound}) } - messages, err := s.Storage.GetHistory(hist.Channel, hist.Since, int(hist.Count), int(hist.Offset)) + var messages []core.Message + count := int(hist.Count) + offset := int(hist.Offset) + + if addr.Type == core.AddrUser { + messages, err = s.Storage.GetHistoryUser(user.Addr, hist.Channel, hist.Since, count, offset) + + } else { + messages, err = s.Storage.GetHistory(hist.Channel, hist.Since, count, offset) + } + if err != nil { fmt.Println("cannot get message history:", err) return user.Send(conn, core.Error{core.ErrorNotFound}) |
