Merge pull request #1410 from hmhealey/plt906
PLT-906 Added ChannelExtra.MemberCount field
Этот коммит содержится в:
@@ -707,6 +707,7 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
|
||||
ecm := Srv.Store.Channel().GetExtraMembers(id, 20)
|
||||
ccm := Srv.Store.Channel().GetMemberCount(id)
|
||||
|
||||
if cmresult := <-scm; cmresult.Err != nil {
|
||||
c.Err = cmresult.Err
|
||||
@@ -714,9 +715,13 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else if ecmresult := <-ecm; ecmresult.Err != nil {
|
||||
c.Err = ecmresult.Err
|
||||
return
|
||||
} else if ccmresult := <-ccm; ccmresult.Err != nil {
|
||||
c.Err = ccmresult.Err
|
||||
return
|
||||
} else {
|
||||
member := cmresult.Data.(model.ChannelMember)
|
||||
extraMembers := ecmresult.Data.([]model.ExtraMember)
|
||||
memberCount := ccmresult.Data.(int64)
|
||||
|
||||
if !c.HasPermissionsToTeam(channel.TeamId, "getChannelExtraInfo") {
|
||||
return
|
||||
@@ -732,7 +737,7 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
data := model.ChannelExtra{Id: channel.Id, Members: extraMembers}
|
||||
data := model.ChannelExtra{Id: channel.Id, Members: extraMembers, MemberCount: memberCount}
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, extraEtag)
|
||||
w.Header().Set("Expires", "-1")
|
||||
w.Write([]byte(data.ToJson()))
|
||||
|
||||
@@ -677,6 +677,10 @@ func TestGetChannelExtraInfo(t *testing.T) {
|
||||
data := rget.Data.(*model.ChannelExtra)
|
||||
if data.Id != channel1.Id {
|
||||
t.Fatal("couldnt't get extra info")
|
||||
} else if len(data.Members) != 1 {
|
||||
t.Fatal("got incorrect members")
|
||||
} else if data.MemberCount != 1 {
|
||||
t.Fatal("got incorrect member count")
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -23,8 +23,9 @@ func (o *ExtraMember) Sanitize(options map[string]bool) {
|
||||
}
|
||||
|
||||
type ChannelExtra struct {
|
||||
Id string `json:"id"`
|
||||
Members []ExtraMember `json:"members"`
|
||||
Id string `json:"id"`
|
||||
Members []ExtraMember `json:"members"`
|
||||
MemberCount int64 `json:"member_count"`
|
||||
}
|
||||
|
||||
func (o *ChannelExtra) ToJson() string {
|
||||
|
||||
@@ -542,6 +542,26 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
count, err := s.GetReplica().SelectInt("SELECT count(*) FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId})
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetMemberCount", "We couldn't get the channel member count", "channel_id="+channelId+", "+err.Error())
|
||||
} else {
|
||||
result.Data = count
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetExtraMembers(channelId string, limit int) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
|
||||
@@ -339,15 +339,15 @@ func TestChannelMemberStore(t *testing.T) {
|
||||
t.Fatal("Member update time incorrect")
|
||||
}
|
||||
|
||||
members := (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
|
||||
if len(members) != 2 {
|
||||
count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
|
||||
if count != 2 {
|
||||
t.Fatal("should have saved 2 members")
|
||||
}
|
||||
|
||||
Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId))
|
||||
|
||||
members = (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember)
|
||||
if len(members) != 1 {
|
||||
count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
|
||||
if count != 1 {
|
||||
t.Fatal("should have removed 1 member")
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ type ChannelStore interface {
|
||||
UpdateMember(member *model.ChannelMember) StoreChannel
|
||||
GetMembers(channelId string) StoreChannel
|
||||
GetMember(channelId string, userId string) StoreChannel
|
||||
GetMemberCount(channelId string) StoreChannel
|
||||
RemoveMember(channelId string, userId string) StoreChannel
|
||||
GetExtraMembers(channelId string, limit int) StoreChannel
|
||||
CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel
|
||||
|
||||
@@ -39,11 +39,14 @@ export default class ChannelHeader extends React.Component {
|
||||
this.state = state;
|
||||
}
|
||||
getStateFromStores() {
|
||||
const extraInfo = ChannelStore.getCurrentExtraInfo();
|
||||
|
||||
return {
|
||||
channel: ChannelStore.getCurrent(),
|
||||
memberChannel: ChannelStore.getCurrentMember(),
|
||||
memberTeam: UserStore.getCurrentUser(),
|
||||
users: ChannelStore.getCurrentExtraInfo().members,
|
||||
users: extraInfo.members,
|
||||
userCount: extraInfo.member_count,
|
||||
searchVisible: SearchStore.getSearchResults() !== null
|
||||
};
|
||||
}
|
||||
@@ -373,6 +376,7 @@ export default class ChannelHeader extends React.Component {
|
||||
<th>
|
||||
<PopoverListMembers
|
||||
members={this.state.users}
|
||||
memberCount={this.state.userCount}
|
||||
channelId={channel.id}
|
||||
/>
|
||||
</th>
|
||||
|
||||
@@ -69,7 +69,6 @@ export default class PopoverListMembers extends React.Component {
|
||||
|
||||
render() {
|
||||
let popoverHtml = [];
|
||||
let count = 0;
|
||||
let countText = '-';
|
||||
const members = this.props.members;
|
||||
const teamMembers = UserStore.getProfilesUsernameMap();
|
||||
@@ -147,10 +146,10 @@ export default class PopoverListMembers extends React.Component {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
||||
const count = this.props.memberCount;
|
||||
if (count > 20) {
|
||||
countText = '20+';
|
||||
} else if (count > 0) {
|
||||
@@ -195,5 +194,6 @@ export default class PopoverListMembers extends React.Component {
|
||||
|
||||
PopoverListMembers.propTypes = {
|
||||
members: React.PropTypes.array.isRequired,
|
||||
memberCount: React.PropTypes.number.isRequired,
|
||||
channelId: React.PropTypes.string.isRequired
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user