mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
member profile & state to types.
This commit is contained in:
parent
58c8104ce6
commit
209971cb8a
@ -9,28 +9,19 @@ import (
|
||||
|
||||
type MemberCreatePayload struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type MemberDataPayload struct {
|
||||
ID string `json:"id"`
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanLogin bool `json:"can_login"`
|
||||
CanConnect bool `json:"can_connect"`
|
||||
CanWatch bool `json:"can_watch"`
|
||||
CanHost bool `json:"can_host"`
|
||||
CanAccessClipboard bool `json:"can_access_clipboard"`
|
||||
*types.MemberProfile
|
||||
}
|
||||
|
||||
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||
data := &MemberDataPayload{
|
||||
IsAdmin: false,
|
||||
CanLogin: true,
|
||||
CanConnect: true,
|
||||
CanWatch: true,
|
||||
CanHost: true,
|
||||
CanAccessClipboard: true,
|
||||
data := &MemberCreatePayload{
|
||||
MemberProfile: &types.MemberProfile{
|
||||
IsAdmin: false,
|
||||
CanLogin: true,
|
||||
CanConnect: true,
|
||||
CanWatch: true,
|
||||
CanHost: true,
|
||||
CanAccessClipboard: true,
|
||||
},
|
||||
}
|
||||
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
@ -60,18 +51,7 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Join structs?
|
||||
session, err := h.sessions.Create(data.ID, types.MemberProfile{
|
||||
Secret: data.Secret,
|
||||
Name: data.Name,
|
||||
IsAdmin: data.IsAdmin,
|
||||
CanLogin: data.CanLogin,
|
||||
CanConnect: data.CanConnect,
|
||||
CanWatch: data.CanWatch,
|
||||
CanHost: data.CanHost,
|
||||
CanAccessClipboard: data.CanAccessClipboard,
|
||||
})
|
||||
|
||||
session, err := h.sessions.Create(data.ID, *data.MemberProfile)
|
||||
if err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
@ -85,8 +65,8 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
|
||||
member := GetMember(r)
|
||||
|
||||
// TODO: Join structs?
|
||||
utils.HttpSuccess(w, MemberDataPayload{
|
||||
// TODO: Get whole profile from session.
|
||||
utils.HttpSuccess(w, types.MemberProfile{
|
||||
Name: member.Name(),
|
||||
IsAdmin: member.IsAdmin(),
|
||||
CanLogin: member.CanLogin(),
|
||||
@ -100,7 +80,8 @@ func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
member := GetMember(r)
|
||||
|
||||
data := &MemberDataPayload{
|
||||
// TODO: Get whole profile from session.
|
||||
profile := types.MemberProfile{
|
||||
Name: member.Name(),
|
||||
IsAdmin: member.IsAdmin(),
|
||||
CanLogin: member.CanLogin(),
|
||||
@ -110,23 +91,11 @@ func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
CanAccessClipboard: member.CanAccessClipboard(),
|
||||
}
|
||||
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
if !utils.HttpJsonRequest(w, r, &profile) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Join structs?
|
||||
err := h.sessions.Update(member.ID(), types.MemberProfile{
|
||||
Secret: data.Secret,
|
||||
Name: data.Name,
|
||||
IsAdmin: data.IsAdmin,
|
||||
CanLogin: data.CanLogin,
|
||||
CanConnect: data.CanConnect,
|
||||
CanWatch: data.CanWatch,
|
||||
CanHost: data.CanHost,
|
||||
CanAccessClipboard: data.CanAccessClipboard,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if err := h.sessions.Update(member.ID(), profile); err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Event string `json:"event"`
|
||||
Payload interface{} `json:"payload"` // TODO: New.
|
||||
@ -55,29 +59,22 @@ type MemberID struct {
|
||||
}
|
||||
|
||||
type MemberProfile struct {
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanLogin bool `json:"can_login"`
|
||||
CanConnect bool `json:"can_connect"`
|
||||
CanWatch bool `json:"can_watch"`
|
||||
CanHost bool `json:"can_host"`
|
||||
CanAccessClipboard bool `json:"can_access_clipboard"`
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id"`
|
||||
*types.MemberProfile
|
||||
}
|
||||
|
||||
type MemberState struct {
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
IsConnected bool `json:"is_connected"`
|
||||
IsWatching bool `json:"is_watching"`
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id"`
|
||||
*types.MemberState
|
||||
}
|
||||
|
||||
type MemberData struct {
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Profile MemberProfile `json:"profile"`
|
||||
State MemberState `json:"state"`
|
||||
Event string `json:"event,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
State types.MemberState `json:"state"`
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
|
@ -3,15 +3,19 @@ package types
|
||||
import "net/http"
|
||||
|
||||
type MemberProfile struct {
|
||||
Secret string
|
||||
Name string
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanLogin bool `json:"can_login"`
|
||||
CanConnect bool `json:"can_connect"`
|
||||
CanWatch bool `json:"can_watch"`
|
||||
CanHost bool `json:"can_host"`
|
||||
CanAccessClipboard bool `json:"can_access_clipboard"`
|
||||
}
|
||||
|
||||
IsAdmin bool
|
||||
CanLogin bool
|
||||
CanConnect bool
|
||||
CanWatch bool
|
||||
CanHost bool
|
||||
CanAccessClipboard bool
|
||||
type MemberState struct {
|
||||
IsConnected bool `json:"is_connected"`
|
||||
IsWatching bool `json:"is_watching"`
|
||||
}
|
||||
|
||||
type MembersDatabase interface {
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
||||
// TODO: Join structs?
|
||||
h.sessions.Broadcast(
|
||||
message.MemberData{
|
||||
Event: event.MEMBER_CREATED,
|
||||
ID: session.ID(),
|
||||
Profile: message.MemberProfile{
|
||||
// TODO: Get whole profile from session.
|
||||
Profile: types.MemberProfile{
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
CanLogin: session.CanLogin(),
|
||||
@ -21,7 +21,8 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
||||
CanHost: session.CanHost(),
|
||||
CanAccessClipboard: session.CanAccessClipboard(),
|
||||
},
|
||||
State: message.MemberState{
|
||||
// TODO: Get whole state from session.
|
||||
State: types.MemberState{
|
||||
IsConnected: session.IsConnected(),
|
||||
IsWatching: session.IsWatching(),
|
||||
},
|
||||
@ -81,31 +82,35 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
||||
// TODO: Join structs?
|
||||
h.sessions.Broadcast(
|
||||
message.MemberProfile{
|
||||
Event: event.MEMBER_PROFILE,
|
||||
ID: session.ID(),
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
CanLogin: session.CanLogin(),
|
||||
CanConnect: session.CanConnect(),
|
||||
CanWatch: session.CanWatch(),
|
||||
CanHost: session.CanHost(),
|
||||
CanAccessClipboard: session.CanAccessClipboard(),
|
||||
Event: event.MEMBER_PROFILE,
|
||||
ID: session.ID(),
|
||||
// TODO: Get whole profile from session.
|
||||
MemberProfile: &types.MemberProfile{
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
CanLogin: session.CanLogin(),
|
||||
CanConnect: session.CanConnect(),
|
||||
CanWatch: session.CanWatch(),
|
||||
CanHost: session.CanHost(),
|
||||
CanAccessClipboard: session.CanAccessClipboard(),
|
||||
},
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
||||
// TODO: Join structs?
|
||||
h.sessions.Broadcast(
|
||||
message.MemberState{
|
||||
Event: event.MEMBER_STATE,
|
||||
ID: session.ID(),
|
||||
IsConnected: session.IsConnected(),
|
||||
IsWatching: session.IsWatching(),
|
||||
// TODO: Get whole state from session.
|
||||
MemberState: &types.MemberState{
|
||||
IsConnected: session.IsConnected(),
|
||||
IsWatching: session.IsWatching(),
|
||||
},
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
|
@ -25,10 +25,10 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
|
||||
members := map[string]message.MemberData{}
|
||||
for _, session := range h.sessions.Members() {
|
||||
// TODO: Join structs?
|
||||
members[session.ID()] = message.MemberData{
|
||||
ID: session.ID(),
|
||||
Profile: message.MemberProfile{
|
||||
// TODO: Get whole profile from session.
|
||||
Profile: types.MemberProfile{
|
||||
Name: session.Name(),
|
||||
IsAdmin: session.IsAdmin(),
|
||||
CanLogin: session.CanLogin(),
|
||||
@ -37,7 +37,8 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
CanHost: session.CanHost(),
|
||||
CanAccessClipboard: session.CanAccessClipboard(),
|
||||
},
|
||||
State: message.MemberState{
|
||||
// TODO: Get whole state from session.
|
||||
State: types.MemberState{
|
||||
IsConnected: session.IsConnected(),
|
||||
IsWatching: session.IsWatching(),
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user