| 18 | }; |
| 19 | |
| 20 | function InviteInfo() { |
| 21 | const groupId = window.sessionStorage.getItem('inviteGroupId') || ''; |
| 22 | const action = useAction(); |
| 23 | const [visible, updateVisible] = useState(!!groupId); |
| 24 | const [group, updateGroup] = useState<GroupBasicInfo>(); |
| 25 | const [largerAvatar, toggleLargetAvatar] = useState(false); |
| 26 | const selfId = useSelector((state: State) => state.user?._id); |
| 27 | const hasLinkman = useSelector((state: State) => !!state.linkmans[groupId]); |
| 28 | |
| 29 | useEffect(() => { |
| 30 | if (!groupId) { |
| 31 | return; |
| 32 | } |
| 33 | (async () => { |
| 34 | const [error, groupInfo] = await fetch('getGroupBasicInfo', { |
| 35 | groupId, |
| 36 | }); |
| 37 | if (!error) { |
| 38 | updateGroup((groupInfo as unknown) as GroupBasicInfo); |
| 39 | } |
| 40 | })(); |
| 41 | }, [groupId]); |
| 42 | |
| 43 | function clearInviteId() { |
| 44 | window.sessionStorage.removeItem('inviteGroupId'); |
| 45 | } |
| 46 | |
| 47 | function handleClose() { |
| 48 | updateVisible(false); |
| 49 | } |
| 50 | |
| 51 | async function handleJoinGroup() { |
| 52 | const groupRes = await joinGroup(groupId); |
| 53 | if (groupRes) { |
| 54 | groupRes.type = 'group'; |
| 55 | action.addLinkman(groupRes, true); |
| 56 | |
| 57 | const messages = await getLinkmanHistoryMessages(groupId, 0); |
| 58 | if (messages) { |
| 59 | action.addLinkmanHistoryMessages(groupId, messages); |
| 60 | } |
| 61 | } |
| 62 | clearInviteId(); |
| 63 | handleClose(); |
| 64 | } |
| 65 | |
| 66 | function handleFocusGroup() { |
| 67 | action.setFocus(groupId); |
| 68 | clearInviteId(); |
| 69 | handleClose(); |
| 70 | } |
| 71 | |
| 72 | return ( |
| 73 | <Dialog |
| 74 | className={Style.infoDialog} |
| 75 | visible={visible} |
| 76 | onClose={handleClose} |
| 77 | title="邀请您加入群组" |