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
|
||||
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
|
||||
|
@ -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))
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user