Fix error around combined user activity (#7637)
This commit is contained in:
parent
7de8a1ef6e
commit
b9024f5183
2 changed files with 39 additions and 26 deletions
|
|
@ -25,7 +25,7 @@ type Props = {
|
|||
currentUserId?: string;
|
||||
currentUsername?: string;
|
||||
location: string;
|
||||
post: Post;
|
||||
post: Post | null;
|
||||
showJoinLeave: boolean;
|
||||
testID?: string;
|
||||
theme: Theme;
|
||||
|
|
@ -65,23 +65,11 @@ const CombinedUserActivity = ({
|
|||
const intl = useIntl();
|
||||
const isTablet = useIsTablet();
|
||||
const serverUrl = useServerUrl();
|
||||
const itemTestID = `${testID}.${post.id}`;
|
||||
const textStyles = getMarkdownTextStyles(theme);
|
||||
const {allUserIds, allUsernames, messageData} = post.props.user_activity;
|
||||
const styles = getStyleSheet(theme);
|
||||
const content = [];
|
||||
const removedUserIds: string[] = [];
|
||||
|
||||
const loadUserProfiles = () => {
|
||||
if (allUserIds.length) {
|
||||
fetchMissingProfilesByIds(serverUrl, allUserIds);
|
||||
}
|
||||
|
||||
if (allUsernames.length) {
|
||||
fetchMissingProfilesByUsernames(serverUrl, allUsernames);
|
||||
}
|
||||
};
|
||||
|
||||
const getUsernames = (userIds: string[]) => {
|
||||
const someone = intl.formatMessage({id: 'channel_loader.someone', defaultMessage: 'Someone'});
|
||||
const you = intl.formatMessage({id: 'combined_system_message.you', defaultMessage: 'You'});
|
||||
|
|
@ -120,6 +108,9 @@ const CombinedUserActivity = ({
|
|||
}, [post, canDelete, isTablet, intl, location]);
|
||||
|
||||
const renderMessage = (postType: string, userIds: string[], actorId: string) => {
|
||||
if (!post) {
|
||||
return null;
|
||||
}
|
||||
let actor = '';
|
||||
if (usernamesById[actorId]) {
|
||||
actor = `@${usernamesById[actorId]}`;
|
||||
|
|
@ -177,9 +168,26 @@ const CombinedUserActivity = ({
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadUserProfiles();
|
||||
}, [allUserIds, allUsernames]);
|
||||
if (!post) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {allUserIds, allUsernames} = post.props.user_activity;
|
||||
if (allUserIds.length) {
|
||||
fetchMissingProfilesByIds(serverUrl, allUserIds);
|
||||
}
|
||||
|
||||
if (allUsernames.length) {
|
||||
fetchMissingProfilesByUsernames(serverUrl, allUsernames);
|
||||
}
|
||||
}, [post?.props.user_activity.allUserIds, post?.props.user_activity.allUsernames]);
|
||||
|
||||
if (!post) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const itemTestID = `${testID}.${post.id}`;
|
||||
const {messageData} = post.props.user_activity;
|
||||
for (const message of messageData) {
|
||||
const {postType, actorId} = message;
|
||||
const userIds = new Set<string>(message.userIds);
|
||||
|
|
|
|||
|
|
@ -28,24 +28,29 @@ const withCombinedPosts = withObservables(['postId'], ({database, postId}: WithD
|
|||
|
||||
// Columns observed: `props` is used by `usernamesById`. `message` is used by generateCombinedPost.
|
||||
const posts = queryPostsById(database, postIds).observeWithColumns(['props', 'message']);
|
||||
const post = posts.pipe(map((ps) => generateCombinedPost(postId, ps)));
|
||||
const post = posts.pipe(map((ps) => (ps.length ? generateCombinedPost(postId, ps) : null)));
|
||||
const canDelete = combineLatest([posts, currentUser]).pipe(
|
||||
switchMap(([ps, u]) => (ps.length ? observePermissionForPost(database, ps[0], u, Permissions.DELETE_OTHERS_POSTS, false) : of$(false))),
|
||||
);
|
||||
|
||||
const usernamesById = post.pipe(
|
||||
switchMap(
|
||||
(p) => queryUsersByIdsOrUsernames(database, p.props.user_activity.allUserIds, p.props.user_activity.allUsernames).observeWithColumns(['username']).
|
||||
pipe(
|
||||
// eslint-disable-next-line max-nested-callbacks
|
||||
switchMap((users) => {
|
||||
(p) => {
|
||||
if (!p) {
|
||||
return of$<Record<string, string>>({});
|
||||
}
|
||||
return queryUsersByIdsOrUsernames(database, p.props.user_activity.allUserIds, p.props.user_activity.allUsernames).observeWithColumns(['username']).
|
||||
pipe(
|
||||
// eslint-disable-next-line max-nested-callbacks
|
||||
return of$(users.reduce((acc: Record<string, string>, user) => {
|
||||
acc[user.id] = user.username;
|
||||
return acc;
|
||||
}, {}));
|
||||
}),
|
||||
),
|
||||
switchMap((users) => {
|
||||
// eslint-disable-next-line max-nested-callbacks
|
||||
return of$(users.reduce((acc: Record<string, string>, user) => {
|
||||
acc[user.id] = user.username;
|
||||
return acc;
|
||||
}, {}));
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue