[IMPROVE] Fetch members from API endpoint (#3351)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
5bc74c6c68
commit
4f241b32d0
|
@ -1039,11 +1039,22 @@ const RocketChat = {
|
||||||
}
|
}
|
||||||
return this.post('subscriptions.read', { rid: roomId });
|
return this.post('subscriptions.read', { rid: roomId });
|
||||||
},
|
},
|
||||||
getRoomMembers(rid, allUsers, skip = 0, limit = 10) {
|
getRoomMembers({ rid, allUsers, roomType, type, filter, skip = 0, limit = 10 }) {
|
||||||
|
const serverVersion = reduxStore.getState().server.version;
|
||||||
|
if (compareServerVersion(serverVersion, '3.16.0', methods.greaterThanOrEqualTo)) {
|
||||||
|
const params = {
|
||||||
|
roomId: rid,
|
||||||
|
offset: skip,
|
||||||
|
count: limit,
|
||||||
|
...(type !== 'all' && { 'status[]': type }),
|
||||||
|
...(filter && { filter })
|
||||||
|
};
|
||||||
|
// RC 3.16.0
|
||||||
|
return this.sdk.get(`${this.roomTypeToApiType(roomType)}.members`, params);
|
||||||
|
}
|
||||||
// RC 0.42.0
|
// RC 0.42.0
|
||||||
return this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit });
|
return this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit });
|
||||||
},
|
},
|
||||||
|
|
||||||
methodCallWrapper(method, ...params) {
|
methodCallWrapper(method, ...params) {
|
||||||
const { API_Use_REST_For_DDP_Calls } = reduxStore.getState().settings;
|
const { API_Use_REST_For_DDP_Calls } = reduxStore.getState().settings;
|
||||||
if (API_Use_REST_For_DDP_Calls) {
|
if (API_Use_REST_For_DDP_Calls) {
|
||||||
|
|
|
@ -70,6 +70,7 @@ class RoomMembersView extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.mounted = false;
|
this.mounted = false;
|
||||||
this.MUTE_INDEX = 0;
|
this.MUTE_INDEX = 0;
|
||||||
|
this.permissions = {};
|
||||||
const rid = props.route.params?.rid;
|
const rid = props.route.params?.rid;
|
||||||
const room = props.route.params?.room;
|
const room = props.route.params?.room;
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -96,10 +97,14 @@ class RoomMembersView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
const { room } = this.state;
|
||||||
this.mounted = true;
|
this.mounted = true;
|
||||||
this.fetchMembers();
|
this.fetchMembers();
|
||||||
|
|
||||||
const { room } = this.state;
|
if (RocketChat.isGroupChat(room)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
muteUserPermission,
|
muteUserPermission,
|
||||||
setLeaderPermission,
|
setLeaderPermission,
|
||||||
|
@ -427,15 +432,24 @@ class RoomMembersView extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchMembers = async () => {
|
fetchMembers = async () => {
|
||||||
const { rid, members, isLoading, allUsers, end } = this.state;
|
const { rid, members, isLoading, allUsers, end, room, filtering } = this.state;
|
||||||
|
const { t } = room;
|
||||||
|
let newMembers;
|
||||||
if (isLoading || end) {
|
if (isLoading || end) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
try {
|
try {
|
||||||
const membersResult = await RocketChat.getRoomMembers(rid, allUsers, members.length, PAGE_SIZE);
|
const membersResult = await RocketChat.getRoomMembers({
|
||||||
const newMembers = membersResult.records;
|
rid,
|
||||||
|
roomType: t,
|
||||||
|
type: allUsers ? 'all' : 'online',
|
||||||
|
filter: filtering,
|
||||||
|
skip: members.length,
|
||||||
|
limit: PAGE_SIZE
|
||||||
|
});
|
||||||
|
newMembers = membersResult.members;
|
||||||
this.setState({
|
this.setState({
|
||||||
members: members.concat(newMembers || []),
|
members: members.concat(newMembers || []),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
Loading…
Reference in New Issue