[IMPROVE] Fetch members from API endpoint (#3351)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gerzon Z 2021-09-16 12:26:05 -04:00 committed by GitHub
parent 5bc74c6c68
commit 4f241b32d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -1039,11 +1039,22 @@ const RocketChat = {
}
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
return this.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit });
},
methodCallWrapper(method, ...params) {
const { API_Use_REST_For_DDP_Calls } = reduxStore.getState().settings;
if (API_Use_REST_For_DDP_Calls) {

View File

@ -70,6 +70,7 @@ class RoomMembersView extends React.Component {
super(props);
this.mounted = false;
this.MUTE_INDEX = 0;
this.permissions = {};
const rid = props.route.params?.rid;
const room = props.route.params?.room;
this.state = {
@ -96,10 +97,14 @@ class RoomMembersView extends React.Component {
}
async componentDidMount() {
const { room } = this.state;
this.mounted = true;
this.fetchMembers();
const { room } = this.state;
if (RocketChat.isGroupChat(room)) {
return;
}
const {
muteUserPermission,
setLeaderPermission,
@ -427,15 +432,24 @@ class RoomMembersView extends React.Component {
};
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) {
return;
}
this.setState({ isLoading: true });
try {
const membersResult = await RocketChat.getRoomMembers(rid, allUsers, members.length, PAGE_SIZE);
const newMembers = membersResult.records;
const membersResult = await RocketChat.getRoomMembers({
rid,
roomType: t,
type: allUsers ? 'all' : 'online',
filter: filtering,
skip: members.length,
limit: PAGE_SIZE
});
newMembers = membersResult.members;
this.setState({
members: members.concat(newMembers || []),
isLoading: false,