Mailspring/internal_packages/open-tracking/lib/open-tracking-icon.jsx
Drew Regitsky 199a62d70e feat(new-plugins): add open tracking and link tracking plugins
Summary:
Adds two (very similar) plugins - Open Tracking and Link Tracking.
Both can be enabled via a button in the composer. Open tracking
inserts a tracking pixel right before send, and link tracking replaces
all links with tracked redirects. Both plugins use the new Metadata
service to store their open/click counts, and have backend servers to
respectively serve the pixel image or handle the redirects. Requests
also trigger a metadata update to increment the open/click counters.

Test Plan: Manual for now

Reviewers: evan, bengotow, drew

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2583
2016-02-19 12:42:56 -08:00

52 lines
1.4 KiB
JavaScript

import {React} from 'nylas-exports'
import {RetinaImg} from 'nylas-component-kit'
import plugin from '../package.json'
export default class OpenTrackingIcon extends React.Component {
static displayName = 'OpenTrackingIcon';
static propTypes = {
thread: React.PropTypes.object.isRequired,
};
constructor(props) {
super(props);
this.state = this._getStateFromThread(props.thread)
}
componentWillReceiveProps(newProps) {
this.setState(this._getStateFromThread(newProps.thread));
}
_getStateFromThread(thread) {
const messages = thread.metadata;
const metadataObjs = messages.map(msg => msg.metadataForPluginId(plugin.appId)).filter(meta => meta);
return {opened: metadataObjs.length ? metadataObjs.every(m => m.open_count > 0) : null};
}
_renderIcon = () => {
if (this.state.opened == null) {
return <span />;
} else if (this.state.opened) {
return (
<RetinaImg
url="nylas://open-tracking/assets/envelope-open-icon@2x.png"
mode={RetinaImg.Mode.ContentIsMask} />
);
}
return (
<RetinaImg
className="unopened"
url="nylas://open-tracking/assets/envelope-closed-icon@2x.png"
mode={RetinaImg.Mode.ContentIsMask} />
);
};
render() {
return (
<div className="open-tracking-icon">
{this._renderIcon()}
</div>
);
}
}