Page MenuHomePhorge

D4958.1764994819.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D4958.1764994819.diff

diff --git a/lib/shared/user-utils.js b/lib/shared/user-utils.js
--- a/lib/shared/user-utils.js
+++ b/lib/shared/user-utils.js
@@ -2,8 +2,18 @@
import bots from '../facts/bots';
import staff from '../facts/staff';
-import type { RelativeMemberInfo } from '../types/thread-types';
-import type { RelativeUserInfo } from '../types/user-types';
+import type {
+ ServerThreadInfo,
+ RawThreadInfo,
+ RelativeMemberInfo,
+ ThreadInfo,
+} from '../types/thread-types';
+import type {
+ RelativeUserInfo,
+ UserInfo,
+ UserInfos,
+} from '../types/user-types';
+import { memberHasAdminPowers } from './thread-utils';
function stringForUser(user: RelativeUserInfo | RelativeMemberInfo): string {
if (user.isViewer) {
@@ -28,4 +38,15 @@
return false;
}
-export { stringForUser, isStaff };
+function getKeyserverAdmin(
+ community: ThreadInfo | RawThreadInfo | ServerThreadInfo,
+ userInfos: UserInfos,
+): ?UserInfo {
+ // This hack only works as long as there is only one admin
+ // Linear task to revert this:
+ // https://linear.app/comm/issue/ENG-1707/revert-fix-getting-the-keyserver-admin-info
+ const admin = community.members.find(memberHasAdminPowers);
+ return admin ? userInfos[admin.id] : undefined;
+}
+
+export { stringForUser, isStaff, getKeyserverAdmin };
diff --git a/native/components/community-pill.react.js b/native/components/community-pill.react.js
--- a/native/components/community-pill.react.js
+++ b/native/components/community-pill.react.js
@@ -3,8 +3,8 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
-import { memberHasAdminPowers } from 'lib/shared/thread-utils';
-import type { ThreadInfo, RelativeMemberInfo } from 'lib/types/thread-types';
+import { getKeyserverAdmin } from 'lib/shared/user-utils';
+import type { ThreadInfo } from 'lib/types/thread-types';
import { useSelector } from '../redux/redux-utils';
import { useColors } from '../themes/colors';
@@ -19,13 +19,10 @@
const { community } = props;
const userInfos = useSelector(state => state.userStore.userInfos);
- const keyserverOperatorUsername: ?string = React.useMemo(() => {
- for (const member: RelativeMemberInfo of community.members) {
- if (memberHasAdminPowers(member)) {
- return userInfos[member.id].username;
- }
- }
- }, [community, userInfos]);
+ const keyserverOperatorUsername: ?string = React.useMemo(
+ () => getKeyserverAdmin(community, userInfos)?.username,
+ [community, userInfos],
+ );
const colors = useColors();
const keyserverOperatorLabel: ?React.Node = React.useMemo(() => {
diff --git a/web/chat/chat-thread-ancestors.react.js b/web/chat/chat-thread-ancestors.react.js
--- a/web/chat/chat-thread-ancestors.react.js
+++ b/web/chat/chat-thread-ancestors.react.js
@@ -4,7 +4,8 @@
import * as React from 'react';
import { useAncestorThreads } from 'lib/shared/ancestor-threads';
-import { memberHasAdminPowers, colorIsDark } from 'lib/shared/thread-utils';
+import { colorIsDark } from 'lib/shared/thread-utils';
+import { getKeyserverAdmin } from 'lib/shared/user-utils';
import type { ThreadInfo } from 'lib/types/thread-types';
import CommIcon from '../CommIcon.react';
@@ -39,14 +40,10 @@
const userInfos = useSelector(state => state.userStore.userInfos);
const community = ancestorThreads[0] ?? threadInfo;
- const keyserverOwnerUsername: ?string = React.useMemo(() => {
- for (const member of community.members) {
- if (memberHasAdminPowers(member)) {
- return userInfos[member.id].username;
- }
- }
- return undefined;
- }, [community.members, userInfos]);
+ const keyserverOwnerUsername: ?string = React.useMemo(
+ () => getKeyserverAdmin(community, userInfos)?.username,
+ [community, userInfos],
+ );
const keyserverInfo = React.useMemo(
() => (

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 6, 4:20 AM (8 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5832108
Default Alt Text
D4958.1764994819.diff (3 KB)

Event Timeline