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 {
|
type MemberCreatePayload struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
*types.MemberProfile
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
data := &MemberDataPayload{
|
data := &MemberCreatePayload{
|
||||||
|
MemberProfile: &types.MemberProfile{
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
CanLogin: true,
|
CanLogin: true,
|
||||||
CanConnect: true,
|
CanConnect: true,
|
||||||
CanWatch: true,
|
CanWatch: true,
|
||||||
CanHost: true,
|
CanHost: true,
|
||||||
CanAccessClipboard: true,
|
CanAccessClipboard: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if !utils.HttpJsonRequest(w, r, data) {
|
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, *data.MemberProfile)
|
||||||
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,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.HttpInternalServerError(w, err)
|
utils.HttpInternalServerError(w, err)
|
||||||
return
|
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) {
|
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
|
||||||
member := GetMember(r)
|
member := GetMember(r)
|
||||||
|
|
||||||
// TODO: Join structs?
|
// TODO: Get whole profile from session.
|
||||||
utils.HttpSuccess(w, MemberDataPayload{
|
utils.HttpSuccess(w, types.MemberProfile{
|
||||||
Name: member.Name(),
|
Name: member.Name(),
|
||||||
IsAdmin: member.IsAdmin(),
|
IsAdmin: member.IsAdmin(),
|
||||||
CanLogin: member.CanLogin(),
|
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) {
|
func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
member := GetMember(r)
|
member := GetMember(r)
|
||||||
|
|
||||||
data := &MemberDataPayload{
|
// TODO: Get whole profile from session.
|
||||||
|
profile := types.MemberProfile{
|
||||||
Name: member.Name(),
|
Name: member.Name(),
|
||||||
IsAdmin: member.IsAdmin(),
|
IsAdmin: member.IsAdmin(),
|
||||||
CanLogin: member.CanLogin(),
|
CanLogin: member.CanLogin(),
|
||||||
@ -110,23 +91,11 @@ func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
|
|||||||
CanAccessClipboard: member.CanAccessClipboard(),
|
CanAccessClipboard: member.CanAccessClipboard(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !utils.HttpJsonRequest(w, r, data) {
|
if !utils.HttpJsonRequest(w, r, &profile) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Join structs?
|
if err := h.sessions.Update(member.ID(), profile); err != nil {
|
||||||
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 {
|
|
||||||
utils.HttpInternalServerError(w, err)
|
utils.HttpInternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package message
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"demodesk/neko/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
Payload interface{} `json:"payload"` // TODO: New.
|
Payload interface{} `json:"payload"` // TODO: New.
|
||||||
@ -56,28 +60,21 @@ type MemberID struct {
|
|||||||
|
|
||||||
type MemberProfile struct {
|
type MemberProfile struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
*types.MemberProfile
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberState struct {
|
type MemberState struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id"`
|
||||||
IsConnected bool `json:"is_connected"`
|
*types.MemberState
|
||||||
IsWatching bool `json:"is_watching"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberData struct {
|
type MemberData struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Profile MemberProfile `json:"profile"`
|
Profile types.MemberProfile `json:"profile"`
|
||||||
State MemberState `json:"state"`
|
State types.MemberState `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -3,15 +3,19 @@ package types
|
|||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
type MemberProfile struct {
|
type MemberProfile struct {
|
||||||
Secret string
|
Secret string `json:"secret,omitempty"`
|
||||||
Name string
|
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
|
type MemberState struct {
|
||||||
CanLogin bool
|
IsConnected bool `json:"is_connected"`
|
||||||
CanConnect bool
|
IsWatching bool `json:"is_watching"`
|
||||||
CanWatch bool
|
|
||||||
CanHost bool
|
|
||||||
CanAccessClipboard bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MembersDatabase interface {
|
type MembersDatabase interface {
|
||||||
|
@ -7,12 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
||||||
// TODO: Join structs?
|
|
||||||
h.sessions.Broadcast(
|
h.sessions.Broadcast(
|
||||||
message.MemberData{
|
message.MemberData{
|
||||||
Event: event.MEMBER_CREATED,
|
Event: event.MEMBER_CREATED,
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
Profile: message.MemberProfile{
|
// TODO: Get whole profile from session.
|
||||||
|
Profile: types.MemberProfile{
|
||||||
Name: session.Name(),
|
Name: session.Name(),
|
||||||
IsAdmin: session.IsAdmin(),
|
IsAdmin: session.IsAdmin(),
|
||||||
CanLogin: session.CanLogin(),
|
CanLogin: session.CanLogin(),
|
||||||
@ -21,7 +21,8 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
|||||||
CanHost: session.CanHost(),
|
CanHost: session.CanHost(),
|
||||||
CanAccessClipboard: session.CanAccessClipboard(),
|
CanAccessClipboard: session.CanAccessClipboard(),
|
||||||
},
|
},
|
||||||
State: message.MemberState{
|
// TODO: Get whole state from session.
|
||||||
|
State: types.MemberState{
|
||||||
IsConnected: session.IsConnected(),
|
IsConnected: session.IsConnected(),
|
||||||
IsWatching: session.IsWatching(),
|
IsWatching: session.IsWatching(),
|
||||||
},
|
},
|
||||||
@ -81,11 +82,12 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
||||||
// TODO: Join structs?
|
|
||||||
h.sessions.Broadcast(
|
h.sessions.Broadcast(
|
||||||
message.MemberProfile{
|
message.MemberProfile{
|
||||||
Event: event.MEMBER_PROFILE,
|
Event: event.MEMBER_PROFILE,
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
|
// TODO: Get whole profile from session.
|
||||||
|
MemberProfile: &types.MemberProfile{
|
||||||
Name: session.Name(),
|
Name: session.Name(),
|
||||||
IsAdmin: session.IsAdmin(),
|
IsAdmin: session.IsAdmin(),
|
||||||
CanLogin: session.CanLogin(),
|
CanLogin: session.CanLogin(),
|
||||||
@ -93,19 +95,22 @@ func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
|||||||
CanWatch: session.CanWatch(),
|
CanWatch: session.CanWatch(),
|
||||||
CanHost: session.CanHost(),
|
CanHost: session.CanHost(),
|
||||||
CanAccessClipboard: session.CanAccessClipboard(),
|
CanAccessClipboard: session.CanAccessClipboard(),
|
||||||
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
||||||
// TODO: Join structs?
|
|
||||||
h.sessions.Broadcast(
|
h.sessions.Broadcast(
|
||||||
message.MemberState{
|
message.MemberState{
|
||||||
Event: event.MEMBER_STATE,
|
Event: event.MEMBER_STATE,
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
|
// TODO: Get whole state from session.
|
||||||
|
MemberState: &types.MemberState{
|
||||||
IsConnected: session.IsConnected(),
|
IsConnected: session.IsConnected(),
|
||||||
IsWatching: session.IsWatching(),
|
IsWatching: session.IsWatching(),
|
||||||
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -25,10 +25,10 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
|||||||
|
|
||||||
members := map[string]message.MemberData{}
|
members := map[string]message.MemberData{}
|
||||||
for _, session := range h.sessions.Members() {
|
for _, session := range h.sessions.Members() {
|
||||||
// TODO: Join structs?
|
|
||||||
members[session.ID()] = message.MemberData{
|
members[session.ID()] = message.MemberData{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
Profile: message.MemberProfile{
|
// TODO: Get whole profile from session.
|
||||||
|
Profile: types.MemberProfile{
|
||||||
Name: session.Name(),
|
Name: session.Name(),
|
||||||
IsAdmin: session.IsAdmin(),
|
IsAdmin: session.IsAdmin(),
|
||||||
CanLogin: session.CanLogin(),
|
CanLogin: session.CanLogin(),
|
||||||
@ -37,7 +37,8 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
|||||||
CanHost: session.CanHost(),
|
CanHost: session.CanHost(),
|
||||||
CanAccessClipboard: session.CanAccessClipboard(),
|
CanAccessClipboard: session.CanAccessClipboard(),
|
||||||
},
|
},
|
||||||
State: message.MemberState{
|
// TODO: Get whole state from session.
|
||||||
|
State: types.MemberState{
|
||||||
IsConnected: session.IsConnected(),
|
IsConnected: session.IsConnected(),
|
||||||
IsWatching: session.IsWatching(),
|
IsWatching: session.IsWatching(),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user