@@ -47,7 +47,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
47
47
highlightMessage,
48
48
} = props ;
49
49
const [ replyingId , setReplyingId ] = useState < string > ( '' ) ;
50
- const counters = S . Chat . getState ( subId ) ;
50
+ const [ preloading , setPreloading ] = useState ( new Map < string , string > ( ) ) ;
51
51
const nodeRef = useRef ( null ) ;
52
52
const dummyRef = useRef ( null ) ;
53
53
const editableRef = useRef ( null ) ;
@@ -62,6 +62,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
62
62
const marks = useRef < I . Mark [ ] > ( [ ] ) ;
63
63
const editingId = useRef < string > ( '' ) ;
64
64
const speedLimit = useRef ( { last : 0 , counter : 0 } ) ;
65
+ const counters = S . Chat . getState ( subId ) ;
65
66
const mentionCounter = counters . mentionCounter ;
66
67
const messageCounter = S . Chat . counterString ( counters . messageCounter ) ;
67
68
const history = useRef ( { position : - 1 , states : [ ] } ) ;
@@ -672,10 +673,33 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
672
673
return ;
673
674
} ;
674
675
675
- setAttachments ( [ ...list , ...attachments ] ) ;
676
+ list . forEach ( item => {
677
+ if ( item . isTmp && U . Object . isFileLayout ( item . layout ) && item . path ) {
678
+ preloadFile ( item ) ;
679
+ } ;
680
+ } ) ;
681
+
682
+ saveState ( [ ...list , ...attachments ] ) ;
676
683
historySaveState ( ) ;
677
684
} ;
678
685
686
+ const preloadFile = ( item : any ) => {
687
+ if ( preloading . has ( item . id ) ) {
688
+ return ;
689
+ } ;
690
+
691
+ C . FileUpload ( S . Common . space , '' , item . path , I . FileType . None , { } , true , '' , ( message : any ) => {
692
+ if ( message . error . code ) {
693
+ return ;
694
+ } ;
695
+
696
+ if ( message . preloadFileId ) {
697
+ preloading . set ( item . id , message . preloadFileId ) ;
698
+ setPreloading ( preloading ) ;
699
+ } ;
700
+ } ) ;
701
+ } ;
702
+
679
703
const addBookmark = ( url : string , fromText ?: boolean ) => {
680
704
const add = ( param : any ) => {
681
705
const { title, description, url } = param ;
@@ -744,7 +768,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
744
768
} ) ;
745
769
746
770
if ( attachments . length != filtered . length ) {
747
- setAttachments ( filtered ) ;
771
+ saveState ( filtered ) ;
748
772
} ;
749
773
} ;
750
774
@@ -826,7 +850,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
826
850
827
851
let n = 0 ;
828
852
for ( const item of files ) {
829
- C . FileUpload ( S . Common . space , '' , item . path , I . FileType . None , { } , ( message : any ) => {
853
+ C . FileUpload ( S . Common . space , '' , item . path , I . FileType . None , { } , false , preloading . get ( item . id ) , ( message : any ) => {
830
854
n ++ ;
831
855
832
856
if ( message . objectId ) {
@@ -909,8 +933,9 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
909
933
updateMarkup ( '' , { from : 0 , to : 0 } ) ;
910
934
clearCounter ( ) ;
911
935
checkSendButton ( ) ;
936
+ saveState ( [ ] ) ;
937
+ setPreloading ( new Map ( ) ) ;
912
938
checkTextMenu ( ) ;
913
- setAttachments ( [ ] ) ;
914
939
} ;
915
940
916
941
const onReply = ( message : I . ChatMessage ) => {
@@ -1054,10 +1079,15 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
1054
1079
const value = getTextValue ( ) ;
1055
1080
const list = ( attachments || [ ] ) . filter ( it => it . id != id ) ;
1056
1081
1082
+ if ( preloading . has ( id ) ) {
1083
+ C . FileDiscardPreload ( preloading . get ( id ) ) ;
1084
+ preloading . delete ( id ) ;
1085
+ } ;
1086
+
1057
1087
if ( editingId . current && ! value && ! attachments . length ) {
1058
1088
onDelete ( editingId . current ) ;
1059
1089
} else {
1060
- setAttachments ( list ) ;
1090
+ saveState ( list ) ;
1061
1091
analytics . event ( 'DetachItemChat' ) ;
1062
1092
} ;
1063
1093
} ;
@@ -1138,8 +1168,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
1138
1168
object . isTmp = true ;
1139
1169
object . timestamp = U . Date . now ( ) ;
1140
1170
1141
- attachments . unshift ( object ) ;
1142
- setAttachments ( attachments ) ;
1171
+ saveState ( [ object ] ) ;
1143
1172
} ) ;
1144
1173
break ;
1145
1174
} ;
@@ -1261,7 +1290,6 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
1261
1290
} ;
1262
1291
} ) ;
1263
1292
1264
- setAttachments ( list ) ;
1265
1293
saveState ( list ) ;
1266
1294
} ) ;
1267
1295
} ;
@@ -1422,6 +1450,7 @@ const ChatForm = observer(forwardRef<RefProps, Props>((props, ref) => {
1422
1450
} ;
1423
1451
1424
1452
const saveState = ( attachments ?: any [ ] ) => {
1453
+ setAttachments ( attachments ) ;
1425
1454
Storage . setChat ( rootId , {
1426
1455
text : getTextValue ( ) ,
1427
1456
marks : marks . current ,
0 commit comments