<commit_before>import React from 'react';
import {
  Text,
  Clipboard,
  StyleSheet,
  TouchableWithoutFeedback,
  View,
} from 'react-native';

import MessageText from './MessageText';
import MessageImage from './MessageImage';
import MessageProgress from './MessageProgress';
import DownloadLink from './DownloadLink';
import Time from './Time';
import I18n from './I18nUtil';

import { isSameUser, isSameDay, warnDeprecated } from './utils';

export default class Bubble extends React.Component {
  constructor(props) {
    super(props);
    this.onLongPress = this.onLongPress.bind(this);
  }

  handleBubbleToNext() {
    if (isSameUser(this.props.currentMessage, this.props.nextMessage) && isSameDay(this.props.currentMessage, this.props.nextMessage)) {
      return StyleSheet.flatten([styles[this.props.position].containerToNext, this.props.containerToNextStyle[this.props.position]]);
    }
    return null;
  }

  handleBubbleToPrevious() {
    if (isSameUser(this.props.currentMessage, this.props.previousMessage) && isSameDay(this.props.currentMessage, this.props.previousMessage)) {
      return StyleSheet.flatten([styles[this.props.position].containerToPrevious, this.props.containerToPreviousStyle[this.props.position]]);
    }
    return null;
  }

  renderMessageText() {
	if(this.props.currentMessage.image 
		|| this.props.currentMessage.progress)//don't show text on image/progress message
		return null;
    if (this.props.currentMessage.text) {
      const {containerStyle, wrapperStyle, ...messageTextProps} = this.props;
      if (this.props.renderMessageText) {
        return this.props.renderMessageText(messageTextProps);
      }
      return <MessageText {...messageTextProps}/>;
    }
    return null;
  }

  renderMessageImage() {
	  if (this.props.currentMessage.progress)
	  	return null;
    if (this.props.currentMessage.image) {
      const {containerStyle, wrapperStyle, ...messageImageProps} = this.props;
      if (this.props.renderMessageImage) {
        return this.props.renderMessageImage(messageImageProps);
      }
      return <MessageImage {...messageImageProps}/>;
    }
    return null;
  }

  renderDownloadLink() {
	  if (this.props.currentMessage.filePath) {
		const {containerStyle, wrapperStyle, ...messageProps} = this.props;
		return <DownloadLink {...messageProps}/>;
	  }
	  return null;
  }

  renderMessageProgress() {
	  if (this.props.currentMessage.progress) {
		const {containerStyle, wrapperStyle, ...messageProgressProps} = this.props;
		return <MessageProgress {...messageProgressProps}/>;
	  }
	  return null;
  }

  renderTicks() {
    const {currentMessage} = this.props;
    if (this.props.renderTicks) {
        return this.props.renderTicks(currentMessage);
    }
    if (currentMessage.user._id !== this.props.user._id) {
        return;
    }
    if (currentMessage.sent || currentMessage.received) {
		let readCount = '';
		if (currentMessage.countMessageReadStatus && currentMessage.countMessageReadStatus > 0)
			readCount = currentMessage.countMessageReadStatus;
      return (
        <View style={styles.tickView}>
          {currentMessage.sent && <Text style={[styles.tick, this.props.tickStyle]}>✓</Text>}
          {currentMessage.received && <Text style={[styles.tick, this.props.tickStyle]}>{I18n.get('Received') + readCount}</Text>}
        </View>
      )
    }
  }

  renderTime() {
    if (this.props.currentMessage.createdAt) {
      const {containerStyle, wrapperStyle, ...timeProps} = this.props;
      if (this.props.renderTime) {
        return this.props.renderTime(timeProps);
      }
      return <Time {...timeProps}/>;
    }
    return null;
  }

  renderCustomView() {
    if (this.props.renderCustomView) {
      return this.props.renderCustomView(this.props);
    }
    return null;
  }

  onLongPress() {
    if (this.props.onLongPress) {
      this.props.onLongPress(this.context);
    } else {
      if (this.props.currentMessage.text) {
        const options = [
          'Copy Text',
          'Cancel',
        ];
        const cancelButtonIndex = options.length - 1;
        this.context.actionSheet().showActionSheetWithOptions({
          options,
          cancelButtonIndex,
        },
        (buttonIndex) => {
          switch (buttonIndex) {
            case 0:
              Clipboard.setString(this.props.currentMessage.text);
              break;
          }
        });
      }
    }
  }

  renderResend() {
		if (/*!this.props.currentMessage.notSent ||*/ this.props.position === 'left')
			return null;
		const icon = Platform.select({
			ios: require('./images/refresh-ios10.png'),
			android: require('./images/refresh-android.png')
		});
		return (
			<TouchableOpacity accessibilityTraits="button"
				onPress={ () => {
					this.props.onResend({...this.props.currentMessage})
				}}>
				<View style={{flex: 1, justifyContent: 'center', alignItems: 'center', marginRight: 2,}}>
					<Image style={{width: 18, height: 18}} source={icon} />
					<Text style={{fontSize: 9, color: '#444'}}>
						{'重新傳送'}
					</Text>
				</View>
			</TouchableOpacity>
		);
	}

  render() {
	  let uploadStyle = {};
	  if (this.props.currentMessage.progress) {
		  uploadStyle = { borderWidth: 0, backgroundColor: 'transparent' };<commit_msg>將判斷重送的條件補回 props.currentMessage.notSent<commit_after>import React from 'react';
import {
  Text,
  Clipboard,
  StyleSheet,
  TouchableWithoutFeedback,
  View,
} from 'react-native';

import MessageText from './MessageText';
import MessageImage from './MessageImage';
import MessageProgress from './MessageProgress';
import DownloadLink from './DownloadLink';
import Time from './Time';
import I18n from './I18nUtil';

import { isSameUser, isSameDay, warnDeprecated } from './utils';

export default class Bubble extends React.Component {
  constructor(props) {
    super(props);
    this.onLongPress = this.onLongPress.bind(this);
  }

  handleBubbleToNext() {
    if (isSameUser(this.props.currentMessage, this.props.nextMessage) && isSameDay(this.props.currentMessage, this.props.nextMessage)) {
      return StyleSheet.flatten([styles[this.props.position].containerToNext, this.props.containerToNextStyle[this.props.position]]);
    }
    return null;
  }

  handleBubbleToPrevious() {
    if (isSameUser(this.props.currentMessage, this.props.previousMessage) && isSameDay(this.props.currentMessage, this.props.previousMessage)) {
      return StyleSheet.flatten([styles[this.props.position].containerToPrevious, this.props.containerToPreviousStyle[this.props.position]]);
    }
    return null;
  }

  renderMessageText() {
	if(this.props.currentMessage.image 
		|| this.props.currentMessage.progress)//don't show text on image/progress message
		return null;
    if (this.props.currentMessage.text) {
      const {containerStyle, wrapperStyle, ...messageTextProps} = this.props;
      if (this.props.renderMessageText) {
        return this.props.renderMessageText(messageTextProps);
      }
      return <MessageText {...messageTextProps}/>;
    }
    return null;
  }

  renderMessageImage() {
	  if (this.props.currentMessage.progress)
	  	return null;
    if (this.props.currentMessage.image) {
      const {containerStyle, wrapperStyle, ...messageImageProps} = this.props;
      if (this.props.renderMessageImage) {
        return this.props.renderMessageImage(messageImageProps);
      }
      return <MessageImage {...messageImageProps}/>;
    }
    return null;
  }

  renderDownloadLink() {
	  if (this.props.currentMessage.filePath) {
		const {containerStyle, wrapperStyle, ...messageProps} = this.props;
		return <DownloadLink {...messageProps}/>;
	  }
	  return null;
  }

  renderMessageProgress() {
	  if (this.props.currentMessage.progress) {
		const {containerStyle, wrapperStyle, ...messageProgressProps} = this.props;
		return <MessageProgress {...messageProgressProps}/>;
	  }
	  return null;
  }

  renderTicks() {
    const {currentMessage} = this.props;
    if (this.props.renderTicks) {
        return this.props.renderTicks(currentMessage);
    }
    if (currentMessage.user._id !== this.props.user._id) {
        return;
    }
    if (currentMessage.sent || currentMessage.received) {
		let readCount = '';
		if (currentMessage.countMessageReadStatus && currentMessage.countMessageReadStatus > 0)
			readCount = currentMessage.countMessageReadStatus;
      return (
        <View style={styles.tickView}>
          {currentMessage.sent && <Text style={[styles.tick, this.props.tickStyle]}>✓</Text>}
          {currentMessage.received && <Text style={[styles.tick, this.props.tickStyle]}>{I18n.get('Received') + readCount}</Text>}
        </View>
      )
    }
  }

  renderTime() {
    if (this.props.currentMessage.createdAt) {
      const {containerStyle, wrapperStyle, ...timeProps} = this.props;
      if (this.props.renderTime) {
        return this.props.renderTime(timeProps);
      }
      return <Time {...timeProps}/>;
    }
    return null;
  }

  renderCustomView() {
    if (this.props.renderCustomView) {
      return this.props.renderCustomView(this.props);
    }
    return null;
  }

  onLongPress() {
    if (this.props.onLongPress) {
      this.props.onLongPress(this.context);
    } else {
      if (this.props.currentMessage.text) {
        const options = [
          'Copy Text',
          'Cancel',
        ];
        const cancelButtonIndex = options.length - 1;
        this.context.actionSheet().showActionSheetWithOptions({
          options,
          cancelButtonIndex,
        },
        (buttonIndex) => {
          switch (buttonIndex) {
            case 0:
              Clipboard.setString(this.props.currentMessage.text);
              break;
          }
        });
      }
    }
  }

  renderResend() {
		if (!this.props.currentMessage.notSent || this.props.position === 'left')
			return null;
		const icon = Platform.select({
			ios: require('./images/refresh-ios10.png'),
			android: require('./images/refresh-android.png')
		});
		return (
			<TouchableOpacity accessibilityTraits="button"
				onPress={ () => {
					this.props.onResend({...this.props.currentMessage})
				}}>
				<View style={{flex: 1, justifyContent: 'center', alignItems: 'center', marginRight: 2,}}>
					<Image style={{width: 18, height: 18}} source={icon} />
					<Text style={{fontSize: 9, color: '#444'}}>
						{'重新傳送'}
					</Text>
				</View>
			</TouchableOpacity>
		);
	}

  render() {
	  let uploadStyle = {};
	  if (this.props.currentMessage.progress) {
		  uploadStyle = { borderWidth: 0, backgroundColor: 'transparent' };
{'fraction_non_alphanumeric': 0.13821910005695842, 'fraction_numerical': 0.004176950825897095, 'mean_word_length': 3.112021857923497, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6221832', 'n_tokens_mistral': 3359, 'n_tokens_neox': 3155, 'n_words': 573}