Add early search prototype on the client, add leave button
This commit is contained in:
parent
deba58dbff
commit
7aae7685c5
19 changed files with 297 additions and 60 deletions
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,8 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/khlieng/name_pending/storage"
|
||||
)
|
||||
|
||||
type WSRequest struct {
|
||||
|
@ -111,6 +113,18 @@ type Away struct {
|
|||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
Server string `json:"server"`
|
||||
Channel string `json:"channel"`
|
||||
Phrase string `json:"phrase"`
|
||||
}
|
||||
|
||||
type SearchResult struct {
|
||||
Server string `json:"server"`
|
||||
Channel string `json:"channel"`
|
||||
Results []storage.Message `json:"results"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Server string `json:"server"`
|
||||
Message string `json:"message"`
|
||||
|
|
|
@ -202,6 +202,25 @@ func handleWS(ws *websocket.Conn) {
|
|||
if irc, ok := session.getIRC(data.Server); ok {
|
||||
irc.Away(data.Message)
|
||||
}
|
||||
|
||||
case "search":
|
||||
go func() {
|
||||
var data SearchRequest
|
||||
|
||||
json.Unmarshal(req.Request, &data)
|
||||
|
||||
results, err := session.user.SearchMessages(data.Server, data.Channel, data.Phrase)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
session.sendJSON("search", SearchResult{
|
||||
Server: data.Server,
|
||||
Channel: data.Channel,
|
||||
Results: results,
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue