attr.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package model
  2. // attribute bit. priority black > following > whisper > no relation.
  3. const (
  4. AttrNoRelation = uint32(0)
  5. AttrWhisper = uint32(1)
  6. AttrFollowing = uint32(1) << 1
  7. AttrFriend = uint32(1) << 2
  8. AttrBlack = uint32(1) << 7
  9. // 128,129,130 变为 0 时候,status = 1
  10. StatusOK = 0
  11. StatusDel = 1
  12. )
  13. // relation act type.
  14. const (
  15. ActAddFollowing = int8(1)
  16. ActDelFollowing = int8(2)
  17. ActAddWhisper = int8(3)
  18. ActDelWhisper = int8(4)
  19. ActAddBlack = int8(5)
  20. ActDelBalck = int8(6)
  21. ActDelFollower = int8(7)
  22. )
  23. // Attr get real attribute by the specified priority.
  24. func Attr(attribute uint32) uint32 {
  25. if attribute&AttrBlack > 0 {
  26. return AttrBlack
  27. }
  28. if attribute&AttrFriend > 0 {
  29. return AttrFriend
  30. }
  31. if attribute&AttrFollowing > 0 {
  32. return AttrFollowing
  33. }
  34. if attribute&AttrWhisper > 0 {
  35. return AttrWhisper
  36. }
  37. return AttrNoRelation
  38. }
  39. // SetAttr set attribute.
  40. func SetAttr(attribute uint32, mask uint32) uint32 {
  41. return attribute | mask
  42. }
  43. // UnsetAttr unset attribute.
  44. func UnsetAttr(attribute uint32, mask uint32) uint32 {
  45. return attribute & ^mask // ^ 按位取反
  46. }