github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/teams/contact_restrictions.go (about)

     1  package teams
     2  
     3  import (
     4  	"github.com/keybase/client/go/libkb"
     5  	"github.com/keybase/client/go/protocol/keybase1"
     6  )
     7  
     8  type contactRestrictedUsers map[keybase1.UID]bool
     9  
    10  // checkCandidate checks if candidate (AddMemberCandidate from transactions.go)
    11  // is restricted by contact settings. If so, also a keybase1.User struct is
    12  // returned.
    13  func (c contactRestrictedUsers) checkCandidate(candidate AddMemberCandidate) (restricted bool, user keybase1.User) {
    14  	if c == nil {
    15  		return false, user
    16  	}
    17  	if upak := candidate.KeybaseUser; upak != nil {
    18  		if _, ok := c[upak.Uid]; ok {
    19  			// Skip users with contact setting restrictions.
    20  			user = keybase1.User{
    21  				Uid:      upak.Uid,
    22  				Username: libkb.NewNormalizedUsername(upak.Username).String(),
    23  			}
    24  			return true, user
    25  		}
    26  	}
    27  	return false, user
    28  }
    29  
    30  func unpackContactRestrictedUsers(blockError libkb.TeamContactSettingsBlockError) (ret contactRestrictedUsers) {
    31  	uids := blockError.BlockedUIDs()
    32  	ret = make(contactRestrictedUsers, len(uids))
    33  	for _, uid := range uids {
    34  		ret[uid] = true
    35  	}
    36  	return ret
    37  }