OnProfileChanged add new & old profile.

This commit is contained in:
Miroslav Šedivý 2024-06-09 18:02:01 +02:00
parent 59b2faec66
commit fc3b6f2e21
5 changed files with 15 additions and 12 deletions

View File

@ -31,7 +31,7 @@ func New(
}
// generate fallback image for private mode when needed
sessions.OnSettingsChanged(func(session types.Session, new types.Settings, old types.Settings) {
sessions.OnSettingsChanged(func(session types.Session, new, old types.Settings) {
if old.PrivateMode && !new.PrivateMode {
log.Debug().Msg("clearing private mode fallback image")
h.privateModeImage = nil

View File

@ -122,10 +122,11 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile)
return types.ErrSessionNotFound
}
old := session.profile
session.profile = profile
manager.sessionsMu.Unlock()
manager.emmiter.Emit("profile_changed", session)
manager.emmiter.Emit("profile_changed", session, profile, old)
manager.save()
session.profileChanged()
@ -361,9 +362,9 @@ func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Ses
})
}
func (manager *SessionManagerCtx) OnProfileChanged(listener func(session types.Session)) {
func (manager *SessionManagerCtx) OnProfileChanged(listener func(session types.Session, new, old types.MemberProfile)) {
manager.emmiter.On("profile_changed", func(payload ...any) {
listener(payload[0].(*SessionCtx))
listener(payload[0].(*SessionCtx), payload[1].(types.MemberProfile), payload[2].(types.MemberProfile))
})
}
@ -383,7 +384,7 @@ func (manager *SessionManagerCtx) OnHostChanged(listener func(session, host type
})
}
func (manager *SessionManagerCtx) OnSettingsChanged(listener func(session types.Session, new types.Settings, old types.Settings)) {
func (manager *SessionManagerCtx) OnSettingsChanged(listener func(session types.Session, new, old types.Settings)) {
manager.emmiter.On("settings_changed", func(payload ...any) {
listener(payload[0].(types.Session), payload[1].(types.Settings), payload[2].(types.Settings))
})

View File

@ -83,12 +83,12 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
return h.SessionStateChanged(session)
}
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session, new, old types.MemberProfile) error {
h.sessions.Broadcast(
event.SESSION_PROFILE,
message.MemberProfile{
ID: session.ID(),
MemberProfile: session.Profile(),
MemberProfile: new,
})
return nil

View File

@ -96,10 +96,12 @@ func (manager *WebSocketManagerCtx) Start() {
Msg("session disconnected")
})
manager.sessions.OnProfileChanged(func(session types.Session) {
err := manager.handler.SessionProfileChanged(session)
manager.sessions.OnProfileChanged(func(session types.Session, new, old types.MemberProfile) {
err := manager.handler.SessionProfileChanged(session, new, old)
manager.logger.Err(err).
Str("session_id", session.ID()).
Interface("new", new).
Interface("old", old).
Msg("session profile changed")
})
@ -129,7 +131,7 @@ func (manager *WebSocketManagerCtx) Start() {
Msg("session host changed")
})
manager.sessions.OnSettingsChanged(func(session types.Session, new types.Settings, old types.Settings) {
manager.sessions.OnSettingsChanged(func(session types.Session, new, old types.Settings) {
// start inactive cursors
if new.InactiveCursors && !old.InactiveCursors {
manager.startInactiveCursors()

View File

@ -100,10 +100,10 @@ type SessionManager interface {
OnDeleted(listener func(session Session))
OnConnected(listener func(session Session))
OnDisconnected(listener func(session Session))
OnProfileChanged(listener func(session Session))
OnProfileChanged(listener func(session Session, new, old MemberProfile))
OnStateChanged(listener func(session Session))
OnHostChanged(listener func(session, host Session))
OnSettingsChanged(listener func(session Session, new Settings, old Settings))
OnSettingsChanged(listener func(session Session, new, old Settings))
UpdateSettingsFunc(session Session, f func(settings *Settings) bool)
Settings() Settings