server: send user details
This commit is contained in:
parent
c7e40ab6c1
commit
7ceed88dfa
27
main.go
27
main.go
@ -81,6 +81,29 @@ func (this *App) HubWorker(Nick, Pass string, so socketio.Socket, done chan stru
|
|||||||
|
|
||||||
// Loop hub connection
|
// Loop hub connection
|
||||||
|
|
||||||
|
serveUserInfo := func(nick string) {
|
||||||
|
props := ""
|
||||||
|
hub.Users(func(users *map[string]libnmdc.UserInfo) error {
|
||||||
|
uinfo, ok := (*users)[nick]
|
||||||
|
if !ok {
|
||||||
|
return nil // just skip
|
||||||
|
}
|
||||||
|
|
||||||
|
bProps, err := json.Marshal(uinfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil // just skip
|
||||||
|
}
|
||||||
|
|
||||||
|
props = string(bProps)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
// 'Message' is a json-encoded param with user properties
|
||||||
|
if len(props) > 0 {
|
||||||
|
so.Emit("info", UserMessageStruct{User: nick, Message: props})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
@ -100,8 +123,12 @@ func (this *App) HubWorker(Nick, Pass string, so socketio.Socket, done chan stru
|
|||||||
case libnmdc.EVENT_PRIVATE:
|
case libnmdc.EVENT_PRIVATE:
|
||||||
so.Emit("priv", UserMessageStruct{User: hev.Nick, Message: hev.Message})
|
so.Emit("priv", UserMessageStruct{User: hev.Nick, Message: hev.Message})
|
||||||
|
|
||||||
|
case libnmdc.EVENT_USER_UPDATED_INFO:
|
||||||
|
serveUserInfo(hev.Nick)
|
||||||
|
|
||||||
case libnmdc.EVENT_USER_JOINED:
|
case libnmdc.EVENT_USER_JOINED:
|
||||||
so.Emit("join", UserMessageStruct{User: hev.Nick})
|
so.Emit("join", UserMessageStruct{User: hev.Nick})
|
||||||
|
serveUserInfo(hev.Nick)
|
||||||
|
|
||||||
case libnmdc.EVENT_USER_PART:
|
case libnmdc.EVENT_USER_PART:
|
||||||
so.Emit("part", UserMessageStruct{User: hev.Nick})
|
so.Emit("part", UserMessageStruct{User: hev.Nick})
|
||||||
|
Loading…
Reference in New Issue
Block a user