2016-02-24 07:22:55 +08:00
|
|
|
import {React} from 'nylas-exports'
|
2016-02-24 10:20:26 +08:00
|
|
|
import {RetinaImg} from 'nylas-component-kit'
|
2016-02-25 04:24:19 +08:00
|
|
|
import {PLUGIN_ID} from './open-tracking-constants'
|
2016-02-24 07:22:55 +08:00
|
|
|
|
2016-02-24 10:20:26 +08:00
|
|
|
export default class OpenTrackingMessageStatus extends React.Component {
|
2016-02-24 07:22:55 +08:00
|
|
|
static displayName = "OpenTrackingMessageStatus";
|
|
|
|
|
2016-02-24 10:20:26 +08:00
|
|
|
static propTypes = {
|
|
|
|
message: React.PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = this._getStateFromMessage(props.message)
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:25:11 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
this.setState(this._getStateFromMessage(nextProps.message))
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:20:26 +08:00
|
|
|
_getStateFromMessage(message) {
|
2016-02-25 04:24:19 +08:00
|
|
|
const metadata = message.metadataForPluginId(PLUGIN_ID);
|
2016-03-08 12:54:43 +08:00
|
|
|
if (!metadata || metadata.open_count == null) {
|
2016-02-24 10:20:26 +08:00
|
|
|
return {hasMetadata: false, opened: false}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
hasMetadata: true,
|
2016-02-24 10:51:05 +08:00
|
|
|
opened: metadata.open_count > 0,
|
2016-02-24 10:20:26 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static containerStyles = {
|
|
|
|
paddingTop: 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
renderImage() {
|
|
|
|
return (
|
|
|
|
<RetinaImg
|
|
|
|
className={this.state.opened ? "opened" : "unopened"}
|
2016-02-26 03:54:46 +08:00
|
|
|
style={{position: 'relative', top: -1}}
|
|
|
|
url="nylas://open-tracking/assets/InMessage-Read@2x.png"
|
2016-02-24 10:20:26 +08:00
|
|
|
mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-24 07:22:55 +08:00
|
|
|
render() {
|
2016-02-24 10:20:26 +08:00
|
|
|
if (!this.state.hasMetadata) { return false }
|
|
|
|
const txt = this.state.opened ? "Read" : "Unread";
|
2016-02-24 10:51:05 +08:00
|
|
|
const title = this.state.opened ? "This message has been read at least once" : "This message has not been read";
|
2016-02-24 07:22:55 +08:00
|
|
|
return (
|
2016-02-24 10:51:05 +08:00
|
|
|
<span title={title} className={`read-receipt-message-status ${txt}`}>{this.renderImage()} {txt}</span>
|
2016-02-24 07:22:55 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 02:01:40 +08:00
|
|
|
|