From bc77c8f8f5902afcabdf1112c993ba00afc8357c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 25 Nov 2020 19:44:50 +0100 Subject: [PATCH] add MemberProfile to session. --- internal/session/manager.go | 12 +++++++----- internal/session/session.go | 23 ++++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/internal/session/manager.go b/internal/session/manager.go index 46460a67..ac2e6e7d 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -42,9 +42,11 @@ func (manager *SessionManagerCtx) New(id string, admin bool) types.Session { session := &SessionCtx{ id: id, - admin: admin, manager: manager, logger: manager.logger.With().Str("id", id).Logger(), + profile: MemberProfile{ + is_admin: admin, + }, connected: false, } @@ -116,7 +118,7 @@ func (manager *SessionManagerCtx) Admins() []types.Session { var sessions []types.Session for _, session := range manager.members { - if !session.connected || !session.admin { + if !session.Connected() || !session.Admin() { continue } @@ -132,7 +134,7 @@ func (manager *SessionManagerCtx) Members() []types.Session { var sessions []types.Session for _, session := range manager.members { - if !session.connected { + if !session.Connected() { continue } @@ -147,7 +149,7 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) defer manager.membersMu.Unlock() for id, session := range manager.members { - if !session.connected { + if !session.Connected() { continue } @@ -168,7 +170,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac defer manager.membersMu.Unlock() for id, session := range manager.members { - if !session.connected || !session.Admin() { + if !session.Connected() || !session.Admin() { continue } diff --git a/internal/session/session.go b/internal/session/session.go index 95c3c95a..189aadea 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -8,15 +8,24 @@ import ( "demodesk/neko/internal/types/message" ) +type MemberProfile struct { + token string + name string + is_admin bool + enabled bool + can_control bool + can_watch bool + clipboard_access bool +} + type SessionCtx struct { - logger zerolog.Logger id string - name string - admin bool - connected bool + logger zerolog.Logger manager *SessionManagerCtx + profile MemberProfile websocket_peer types.WebSocketPeer webrtc_peer types.WebRTCPeer + connected bool } func (session *SessionCtx) ID() string { @@ -24,11 +33,11 @@ func (session *SessionCtx) ID() string { } func (session *SessionCtx) Name() string { - return session.name + return session.profile.name } func (session *SessionCtx) Admin() bool { - return session.admin + return session.profile.is_admin } func (session *SessionCtx) IsHost() bool { @@ -40,7 +49,7 @@ func (session *SessionCtx) Connected() bool { } func (session *SessionCtx) SetName(name string) { - session.name = name + session.profile.name = name } func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) {