mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
OnProfileChanged add new & old profile.
This commit is contained in:
parent
59b2faec66
commit
fc3b6f2e21
@ -31,7 +31,7 @@ func New(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generate fallback image for private mode when needed
|
// 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 {
|
if old.PrivateMode && !new.PrivateMode {
|
||||||
log.Debug().Msg("clearing private mode fallback image")
|
log.Debug().Msg("clearing private mode fallback image")
|
||||||
h.privateModeImage = nil
|
h.privateModeImage = nil
|
||||||
|
@ -122,10 +122,11 @@ func (manager *SessionManagerCtx) Update(id string, profile types.MemberProfile)
|
|||||||
return types.ErrSessionNotFound
|
return types.ErrSessionNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
old := session.profile
|
||||||
session.profile = profile
|
session.profile = profile
|
||||||
manager.sessionsMu.Unlock()
|
manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
manager.emmiter.Emit("profile_changed", session)
|
manager.emmiter.Emit("profile_changed", session, profile, old)
|
||||||
manager.save()
|
manager.save()
|
||||||
|
|
||||||
session.profileChanged()
|
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) {
|
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) {
|
manager.emmiter.On("settings_changed", func(payload ...any) {
|
||||||
listener(payload[0].(types.Session), payload[1].(types.Settings), payload[2].(types.Settings))
|
listener(payload[0].(types.Session), payload[1].(types.Settings), payload[2].(types.Settings))
|
||||||
})
|
})
|
||||||
|
@ -83,12 +83,12 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
|||||||
return h.SessionStateChanged(session)
|
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(
|
h.sessions.Broadcast(
|
||||||
event.SESSION_PROFILE,
|
event.SESSION_PROFILE,
|
||||||
message.MemberProfile{
|
message.MemberProfile{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
MemberProfile: session.Profile(),
|
MemberProfile: new,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -96,10 +96,12 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
Msg("session disconnected")
|
Msg("session disconnected")
|
||||||
})
|
})
|
||||||
|
|
||||||
manager.sessions.OnProfileChanged(func(session types.Session) {
|
manager.sessions.OnProfileChanged(func(session types.Session, new, old types.MemberProfile) {
|
||||||
err := manager.handler.SessionProfileChanged(session)
|
err := manager.handler.SessionProfileChanged(session, new, old)
|
||||||
manager.logger.Err(err).
|
manager.logger.Err(err).
|
||||||
Str("session_id", session.ID()).
|
Str("session_id", session.ID()).
|
||||||
|
Interface("new", new).
|
||||||
|
Interface("old", old).
|
||||||
Msg("session profile changed")
|
Msg("session profile changed")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -129,7 +131,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
Msg("session host changed")
|
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
|
// start inactive cursors
|
||||||
if new.InactiveCursors && !old.InactiveCursors {
|
if new.InactiveCursors && !old.InactiveCursors {
|
||||||
manager.startInactiveCursors()
|
manager.startInactiveCursors()
|
||||||
|
@ -100,10 +100,10 @@ type SessionManager interface {
|
|||||||
OnDeleted(listener func(session Session))
|
OnDeleted(listener func(session Session))
|
||||||
OnConnected(listener func(session Session))
|
OnConnected(listener func(session Session))
|
||||||
OnDisconnected(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))
|
OnStateChanged(listener func(session Session))
|
||||||
OnHostChanged(listener func(session, host 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)
|
UpdateSettingsFunc(session Session, f func(settings *Settings) bool)
|
||||||
Settings() Settings
|
Settings() Settings
|
||||||
|
Loading…
Reference in New Issue
Block a user