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'
|
|
|
|
import plugin from '../package.json'
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
_getStateFromMessage(message) {
|
|
|
|
const metadata = message.metadataForPluginId(plugin.appId);
|
|
|
|
if (!metadata) {
|
|
|
|
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"}
|
|
|
|
url="nylas://open-tracking/assets/icon-composer-eye@2x.png"
|
|
|
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|