Mailspring/internal_packages/open-tracking/lib/open-tracking-message-status.jsx
Evan Morikawa 6144f83834 fix(tracking): fix link tracking and read receipt plugins
Fix broken links in link tracking and read receipts

Fix bug in email frame where it wouldn't adjust the height even when
content changed

MessageItem bodies automatically clear the MessageBodyProcessor cache when
the message contents (including metadata) change.

Remove unused Account stuff from nylas-observables

Plugins appIds properly read if there's an environment set
2016-02-24 12:30:12 -08:00

50 lines
1.3 KiB
JavaScript

import {React} from 'nylas-exports'
import {RetinaImg} from 'nylas-component-kit'
import {PLUGIN_ID} from './open-tracking-constants'
export default class OpenTrackingMessageStatus extends React.Component {
static displayName = "OpenTrackingMessageStatus";
static propTypes = {
message: React.PropTypes.object.isRequired,
};
constructor(props) {
super(props);
this.state = this._getStateFromMessage(props.message)
}
_getStateFromMessage(message) {
const metadata = message.metadataForPluginId(PLUGIN_ID);
if (!metadata) {
return {hasMetadata: false, opened: false}
}
return {
hasMetadata: true,
opened: metadata.open_count > 0,
};
}
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} />
);
}
render() {
if (!this.state.hasMetadata) { return false }
const txt = this.state.opened ? "Read" : "Unread";
const title = this.state.opened ? "This message has been read at least once" : "This message has not been read";
return (
<span title={title} className={`read-receipt-message-status ${txt}`}>{this.renderImage()}&nbsp;&nbsp;{txt}</span>
)
}
}