MCPcopy
hub / github.com/tinode/chat / changeUserState

Function changeUserState

server/user.go:556–583  ·  view source on GitHub ↗

Change user state: suspended/normal (ok). 1. Not needed -- Disable/enable logins (state checked after login). 2. If suspending, evict user's sessions. Skip this step if resuming. 3. Suspend/activate p2p with the user. 4. Suspend/activate grp topics where the user is the owner. 5. Update user's DB re

(s *Session, uid types.Uid, user *types.User, msg *ClientComMessage)

Source from the content-addressed store, hash-verified

554// 4. Suspend/activate grp topics where the user is the owner.
555// 5. Update user's DB record.
556func changeUserState(s *Session, uid types.Uid, user *types.User, msg *ClientComMessage) (bool, error) {
557 state, err := types.NewObjState(msg.Acc.State)
558 if err != nil || state == types.StateUndefined {
559 logs.Warn.Println("replyUpdateUser: invalid account state", s.sid)
560 return false, types.ErrMalformed
561 }
562
563 // State unchanged.
564 if user.State == state {
565 return false, nil
566 }
567
568 if state != types.StateOK {
569 // Terminate all sessions.
570 globals.sessionStore.EvictUser(uid, "")
571 }
572
573 err = store.Users.UpdateState(uid, state)
574 if err != nil {
575 return false, err
576 }
577
578 // Update state of all loaded in memory user's p2p & grp-owner topics.
579 globals.hub.userStatus <- &userStatusReq{forUser: uid, state: state}
580 user.State = state
581
582 return true, err
583}
584
585// Request to delete a user:
586// 1. Disable user's login

Callers 1

replyUpdateUserFunction · 0.85

Calls 4

NewObjStateFunction · 0.92
PrintlnMethod · 0.80
EvictUserMethod · 0.80
UpdateStateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…