MCPcopy
hub / github.com/yinxin630/fiora / UserInfo

Function UserInfo

packages/web/src/modules/UserInfo.tsx:34–216  ·  view source on GitHub ↗
(props: UserInfoProps)

Source from the content-addressed store, hash-verified

32}
33
34function UserInfo(props: UserInfoProps) {
35 const { visible, onClose, user } = props;
36
37 const action = useAction();
38
39 const selfId =
40 useSelector((state: State) => state.user && state.user._id) || '';
41 // 获取好友id
42 if (user && user._id.length === selfId.length) {
43 user._id = getFriendId(selfId, user._id);
44 }
45 /** 获取原始用户id */
46 const originUserId = user && user._id.replace(selfId, '');
47
48 // @ts-ignore
49 const linkman = useSelector((state: State) => state.linkmans[user?._id]);
50 const isFriend = linkman && linkman.type === 'friend';
51 const isAdmin = useSelector(
52 (state: State) => state.user && state.user.isAdmin,
53 );
54 const [largerAvatar, toggleLargetAvatar] = useState(false);
55
56 const [userIps, setUserIps] = useState([]);
57
58 useEffect(() => {
59 if (isAdmin && user && user._id) {
60 (async () => {
61 const ips = await getUserIps(user._id.replace(selfId, ''));
62 setUserIps(ips);
63 })();
64 }
65 }, [isAdmin, selfId, user]);
66
67 if (!user) {
68 return null;
69 }
70
71 function handleFocusUser() {
72 onClose();
73 // @ts-ignore
74 action.setFocus(user._id);
75 }
76
77 async function handleAddFriend() {
78 // @ts-ignore
79 const friend = await addFriend(originUserId);
80 if (friend) {
81 onClose();
82 // @ts-ignore
83 const { _id } = user;
84 let existCount = 0;
85 if (linkman) {
86 existCount = Object.keys(linkman.messages).length;
87 action.setLinkmanProperty(_id, 'type', 'friend');
88 } else {
89 const newLinkman = {
90 _id,
91 from: selfId,

Callers

nothing calls this directly

Calls 5

getUserIpsFunction · 0.90
getOSSFileUrlFunction · 0.90
useActionFunction · 0.85
searchIpFunction · 0.85
getFriendIdFunction · 0.50

Tested by

no test coverage detected