@@ -74,6 +74,7 @@ import {
7474 selectDirectById ,
7575 selectDmGroupCurrentId ,
7676 selectDmMetaEntities ,
77+ selectFriendById ,
7778 selectIsInCall ,
7879 selectLastMessageByChannelId ,
7980 selectLastSentMessageStateByChannelId ,
@@ -2447,33 +2448,49 @@ const ChatContextProvider: React.FC<ChatContextProviderProps> = ({ children, isM
24472448
24482449 const onblockfriend = useCallback (
24492450 ( blockFriend : BlockFriend ) => {
2450- if ( ! blockFriend ?. user_id ) {
2451+ if ( ! blockFriend ?. user_id || ! userId ) {
24512452 return ;
24522453 }
2453- dispatch (
2454- friendsActions . applyFriendBlockState ( {
2455- userId : blockFriend . user_id ,
2456- state : EStateFriend . BLOCK ,
2457- sourceId : userId as string
2458- } )
2459- ) ;
2454+ const myId = userId as string ;
2455+ const targetUserId = blockFriend . user_id ;
2456+
2457+ if ( targetUserId === myId ) {
2458+ return ;
2459+ }
2460+
2461+ const existing = selectFriendById ( getStore ( ) . getState ( ) as RootState , targetUserId ) ;
2462+ const iBlockedThem = existing ?. state === EStateFriend . BLOCK && existing . source_id === myId ;
2463+ if ( ! iBlockedThem ) {
2464+ void dispatch ( friendsActions . fetchListFriends ( { noCache : true } ) ) ;
2465+ }
24602466 } ,
24612467 [ dispatch , userId ]
24622468 ) ;
24632469
24642470 const onunblockfriend = useCallback (
24652471 ( unblockFriend : UnblockFriend ) => {
2466- if ( ! unblockFriend ?. user_id ) {
2472+ if ( ! unblockFriend ?. user_id || ! userId ) {
24672473 return ;
24682474 }
2469- dispatch (
2470- friendsActions . applyFriendBlockState ( {
2471- userId : unblockFriend . user_id ,
2472- state : EStateFriend . FRIEND
2473- } )
2474- ) ;
2475+ const myId = userId as string ;
2476+ const targetUserId = unblockFriend . user_id ;
2477+
2478+ if ( targetUserId === myId ) {
2479+ return ;
2480+ }
2481+
2482+ const existing = selectFriendById ( getStore ( ) . getState ( ) as RootState , targetUserId ) ;
2483+ const iBlockedThem = existing ?. state === EStateFriend . BLOCK && existing . source_id === myId ;
2484+ if ( iBlockedThem ) {
2485+ dispatch (
2486+ friendsActions . applyFriendBlockState ( {
2487+ userId : targetUserId ,
2488+ state : EStateFriend . FRIEND
2489+ } )
2490+ ) ;
2491+ }
24752492 } ,
2476- [ dispatch ]
2493+ [ dispatch , userId ]
24772494 ) ;
24782495
24792496 const onMarkAsRead = useCallback ( async ( markAsReadEvent : MarkAsRead ) => {
0 commit comments