github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/team_member.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 "net/http" 10 "strings" 11 ) 12 13 type TeamMember struct { 14 TeamId string `json:"team_id"` 15 UserId string `json:"user_id"` 16 Roles string `json:"roles"` 17 DeleteAt int64 `json:"delete_at"` 18 } 19 20 type TeamUnread struct { 21 TeamId string `json:"team_id"` 22 MsgCount int64 `json:"msg_count"` 23 MentionCount int64 `json:"mention_count"` 24 } 25 26 func (o *TeamMember) ToJson() string { 27 b, _ := json.Marshal(o) 28 return string(b) 29 } 30 31 func (o *TeamUnread) ToJson() string { 32 b, _ := json.Marshal(o) 33 return string(b) 34 } 35 36 func TeamMemberFromJson(data io.Reader) *TeamMember { 37 var o *TeamMember 38 json.NewDecoder(data).Decode(&o) 39 return o 40 } 41 42 func TeamUnreadFromJson(data io.Reader) *TeamUnread { 43 var o *TeamUnread 44 json.NewDecoder(data).Decode(&o) 45 return o 46 } 47 48 func TeamMembersToJson(o []*TeamMember) string { 49 if b, err := json.Marshal(o); err != nil { 50 return "[]" 51 } else { 52 return string(b) 53 } 54 } 55 56 func TeamMembersFromJson(data io.Reader) []*TeamMember { 57 var o []*TeamMember 58 json.NewDecoder(data).Decode(&o) 59 return o 60 } 61 62 func TeamsUnreadToJson(o []*TeamUnread) string { 63 if b, err := json.Marshal(o); err != nil { 64 return "[]" 65 } else { 66 return string(b) 67 } 68 } 69 70 func TeamsUnreadFromJson(data io.Reader) []*TeamUnread { 71 var o []*TeamUnread 72 json.NewDecoder(data).Decode(&o) 73 return o 74 } 75 76 func (o *TeamMember) IsValid() *AppError { 77 78 if len(o.TeamId) != 26 { 79 return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.team_id.app_error", nil, "", http.StatusBadRequest) 80 } 81 82 if len(o.UserId) != 26 { 83 return NewAppError("TeamMember.IsValid", "model.team_member.is_valid.user_id.app_error", nil, "", http.StatusBadRequest) 84 } 85 86 return nil 87 } 88 89 func (o *TeamMember) PreUpdate() { 90 } 91 92 func (o *TeamMember) GetRoles() []string { 93 return strings.Fields(o.Roles) 94 }