Edit message: Don't allow send unless message contents changed
This commit is contained in:
		
					parent
					
						
							
								5987350dbe
							
						
					
				
			
			
				commit
				
					
						f53e956810
					
				
			
		
					 5 changed files with 70 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -22,7 +22,12 @@ import type {
 | 
			
		|||
  HydratedBodyRangesType,
 | 
			
		||||
  RangeNode,
 | 
			
		||||
} from '../types/BodyRange';
 | 
			
		||||
import { BodyRange, collapseRangeTree, insertRange } from '../types/BodyRange';
 | 
			
		||||
import {
 | 
			
		||||
  BodyRange,
 | 
			
		||||
  areBodyRangesEqual,
 | 
			
		||||
  collapseRangeTree,
 | 
			
		||||
  insertRange,
 | 
			
		||||
} from '../types/BodyRange';
 | 
			
		||||
import type { LocalizerType, ThemeType } from '../types/Util';
 | 
			
		||||
import type { ConversationType } from '../state/ducks/conversations';
 | 
			
		||||
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
 | 
			
		||||
| 
						 | 
				
			
			@ -359,7 +364,11 @@ export function CompositionInput(props: Props): React.ReactElement {
 | 
			
		|||
      `CompositionInput: Submitting message ${timestamp} with ${bodyRanges.length} ranges`
 | 
			
		||||
    );
 | 
			
		||||
    canSendRef.current = false;
 | 
			
		||||
    onSubmit(text, bodyRanges, timestamp);
 | 
			
		||||
    const didSend = onSubmit(text, bodyRanges, timestamp);
 | 
			
		||||
 | 
			
		||||
    if (!didSend) {
 | 
			
		||||
      canSendRef.current = true;
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  if (inputApi) {
 | 
			
		||||
| 
						 | 
				
			
			@ -579,7 +588,19 @@ export function CompositionInput(props: Props): React.ReactElement {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (propsRef.current.onDirtyChange) {
 | 
			
		||||
      propsRef.current.onDirtyChange(text.length > 0);
 | 
			
		||||
      let isDirty: boolean = false;
 | 
			
		||||
 | 
			
		||||
      if (!draftEditMessage) {
 | 
			
		||||
        isDirty = text.length > 0;
 | 
			
		||||
      } else if (text.trimEnd() !== draftEditMessage.body.trimEnd()) {
 | 
			
		||||
        isDirty = true;
 | 
			
		||||
      } else if (bodyRanges.length !== draftEditMessage.bodyRanges?.length) {
 | 
			
		||||
        isDirty = true;
 | 
			
		||||
      } else if (!areBodyRangesEqual(bodyRanges, draftEditMessage.bodyRanges)) {
 | 
			
		||||
        isDirty = true;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      propsRef.current.onDirtyChange(isDirty);
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue