From 393156c55c23815376dd015f295d0844860e2a73 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Tue, 23 Feb 2016 18:51:05 -0800 Subject: [PATCH] fix(link-tracking): fixes in link-tracking --- .../lib/link-tracking-composer-extension.es6 | 2 +- .../link-tracking/lib/link-tracking-icon.jsx | 4 ++-- .../lib/link-tracking-message-extension.es6 | 9 ++++----- .../link-tracking/lib/link-tracking-panel.jsx | 4 ++-- internal_packages/link-tracking/lib/main.es6 | 6 +++--- internal_packages/link-tracking/package.json | 2 +- .../assets/icon-tracking-read@2x.png | Bin 0 -> 975 bytes internal_packages/open-tracking/lib/main.es6 | 2 +- .../open-tracking/lib/open-tracking-icon.jsx | 19 +++++++----------- .../lib/open-tracking-message-status.jsx | 5 +++-- .../open-tracking/stylesheets/main.less | 5 +++-- 11 files changed, 27 insertions(+), 31 deletions(-) create mode 100644 internal_packages/open-tracking/assets/icon-tracking-read@2x.png diff --git a/internal_packages/link-tracking/lib/link-tracking-composer-extension.es6 b/internal_packages/link-tracking/lib/link-tracking-composer-extension.es6 index fa60ae2bd..216641172 100644 --- a/internal_packages/link-tracking/lib/link-tracking-composer-extension.es6 +++ b/internal_packages/link-tracking/lib/link-tracking-composer-extension.es6 @@ -32,7 +32,7 @@ export default class LinkTrackingComposerExtension extends ComposerExtension { draftBody.unquoted = draftBody.unquoted.replace(RegExpUtils.linkTagRegex(), (match, prefix, url, suffix, content, closingTag) => { const encoded = encodeURIComponent(url); const redirectUrl = `http://${PLUGIN_URL}/${draft.accountId}/${messageUid}/${links.length}?redirect=${encoded}`; - links.push({originalUrl: url, clickCount: 0, clickData: [], redirectUrl: redirectUrl}); + links.push({url: url, click_count: 0, click_data: [], redirect_url: redirectUrl}); return prefix + redirectUrl + suffix + content + closingTag; }); diff --git a/internal_packages/link-tracking/lib/link-tracking-icon.jsx b/internal_packages/link-tracking/lib/link-tracking-icon.jsx index 63b896061..834d1da6d 100644 --- a/internal_packages/link-tracking/lib/link-tracking-icon.jsx +++ b/internal_packages/link-tracking/lib/link-tracking-icon.jsx @@ -29,7 +29,7 @@ export default class LinkTrackingIcon extends React.Component { // If there's metadata, return the total number of link clicks in the most recent metadata const mostRecentMetadata = metadataObjs.pop(); return { - clicks: sum(mostRecentMetadata.links || [], link => link.clickCount || 0), + clicks: sum(mostRecentMetadata.links || [], link => link.click_count || 0), }; } return {clicks: null}; @@ -44,7 +44,7 @@ export default class LinkTrackingIcon extends React.Component { return ( 0 ? "clicked" : ""} - url="nylas://link-tracking/assets/linktracking-icon@2x.png" + name="icon-composer-linktracking.png" mode={RetinaImg.Mode.ContentIsMask} /> {clicks > 0 ? clicks : ""} ) diff --git a/internal_packages/link-tracking/lib/link-tracking-message-extension.es6 b/internal_packages/link-tracking/lib/link-tracking-message-extension.es6 index 887b5e3ae..04d343295 100644 --- a/internal_packages/link-tracking/lib/link-tracking-message-extension.es6 +++ b/internal_packages/link-tracking/lib/link-tracking-message-extension.es6 @@ -7,10 +7,9 @@ export default class LinkTrackingMessageExtension extends MessageViewExtension { if ((metadata.links || []).length === 0) { return } const links = {} for (const link of metadata.links) { - links[link.redirectUrl] = link + links[link.redirect_url] = link } - message.body = message.body.replace(RegExpUtils.linkTagRegex(), (match, openTagPrefix, aTagHref, openTagSuffix, content, closingTag) => { if (links[aTagHref]) { const openTag = openTagPrefix + aTagHref + openTagSuffix @@ -22,12 +21,12 @@ export default class LinkTrackingMessageExtension extends MessageViewExtension { if (!content) { return match; } if (content.search("link-tracking-dot") >= 0) { return match; } - const originalUrl = links[aTagHref].originalUrl; + const originalUrl = links[aTagHref].url; const dotImgSrcPrefix = "nylas://link-tracking/assets/"; const dotStyles = "margin-left: 1px; vertical-align: super; margin-right: 2px; zoom: 0.55;" - if (links[aTagHref].clickCount > 0) { - title = ` title="Number of clicks: ${links[aTagHref].clickCount} | ${originalUrl}" `; + if (links[aTagHref].click_count > 0) { + title = ` title="Number of clicks: ${links[aTagHref].click_count} | ${originalUrl}" `; dotSrc = dotImgSrcPrefix + "ic-tracking-visited@2x.png" } else { title = ` title="Never been clicked | ${originalUrl}" ` diff --git a/internal_packages/link-tracking/lib/link-tracking-panel.jsx b/internal_packages/link-tracking/lib/link-tracking-panel.jsx index 655a3f34e..26861b54b 100644 --- a/internal_packages/link-tracking/lib/link-tracking-panel.jsx +++ b/internal_packages/link-tracking/lib/link-tracking-panel.jsx @@ -25,8 +25,8 @@ export default class LinkTrackingPanel extends React.Component { _renderContents() { return this.state.links.map(link => { return ( - {link.originalUrl} - {link.clickCount + " clicks"} + {link.url} + {link.click_count + " clicks"} ) }) } diff --git a/internal_packages/link-tracking/lib/main.es6 b/internal_packages/link-tracking/lib/main.es6 index c0dd3995b..18d215d8d 100644 --- a/internal_packages/link-tracking/lib/main.es6 +++ b/internal_packages/link-tracking/lib/main.es6 @@ -1,6 +1,6 @@ import {ComponentRegistry, DatabaseStore, Message, ExtensionRegistry, Actions} from 'nylas-exports'; import LinkTrackingButton from './link-tracking-button'; -import LinkTrackingIcon from './link-tracking-icon'; +// import LinkTrackingIcon from './link-tracking-icon'; import LinkTrackingComposerExtension from './link-tracking-composer-extension'; import LinkTrackingMessageExtension from './link-tracking-message-extension'; // import LinkTrackingPanel from './link-tracking-panel'; @@ -45,7 +45,7 @@ function afterDraftSend({draftClientId}) { export function activate() { ComponentRegistry.register(LinkTrackingButton, {role: 'Composer:ActionButton'}); - ComponentRegistry.register(LinkTrackingIcon, {role: 'ThreadListIcon'}); + // ComponentRegistry.register(LinkTrackingIcon, {role: 'ThreadListIcon'}); // ComponentRegistry.register(LinkTrackingPanel, {role: 'message:BodyHeader'}); ExtensionRegistry.Composer.register(LinkTrackingComposerExtension); ExtensionRegistry.MessageView.register(LinkTrackingMessageExtension); @@ -56,7 +56,7 @@ export function serialize() {} export function deactivate() { ComponentRegistry.unregister(LinkTrackingButton); - ComponentRegistry.unregister(LinkTrackingIcon); + // ComponentRegistry.unregister(LinkTrackingIcon); // ComponentRegistry.unregister(LinkTrackingPanel); ExtensionRegistry.Composer.unregister(LinkTrackingComposerExtension); ExtensionRegistry.MessageView.unregister(LinkTrackingMessageExtension); diff --git a/internal_packages/link-tracking/package.json b/internal_packages/link-tracking/package.json index 9e57dbda6..c7f4466be 100644 --- a/internal_packages/link-tracking/package.json +++ b/internal_packages/link-tracking/package.json @@ -22,4 +22,4 @@ }, "dependencies": {}, "license": "GPL-3.0" -} \ No newline at end of file +} diff --git a/internal_packages/open-tracking/assets/icon-tracking-read@2x.png b/internal_packages/open-tracking/assets/icon-tracking-read@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..4408e13b7d72e9a584944355ea09a65733283583 GIT binary patch literal 975 zcmV;=12FuFP)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006 zVoOIv00000008+zyMF)x010qNS#tmY3labT3lag+-G2N400T2gL_t(Y$DNf+h+IV! zhQIr$={w!`wmtYjB_J9>-8c(H1s^D=BgsPDxH70HqJn1;kU&;Z2+l$g&L$fL7eNu+ zDA9<9;8GV7H5d|-g~A{a(SFUC?prnYy6Bp=pC&W4DXQw6|F2W$uX6&nIaD`+?hlWWsC>_yITpd@3RrcTB9Ri@=A)rWx(fLqcu#TWxXS(bD<9g3nDvybDLG))PDVALiD z-U8khk>aw%s(Ju8Y>bK0G#&1DyIq`fmw+R{N5B~%1eSs4fftN1@s^Ksj&8RL@GbC+ zi2OO1SXJKz_Gei}9LJNSYrtL+`FYMOJpg=OsZ^G#)#`A+*=z!w10EHTwJBmB>1w0V z7|UTovDO|Hk$tLqHSl8)1iR|>`Y@ls1z=f3{!!JhlO%a;adB}B$4CAd z@U)1Op{gdphsKyGQUGf$z!!e`60ob$Xb^@WQ54~$yA^oW+Z^xpdQ&*w?n&T9yf{{X zn@5E-WBl&t-Lo#|Q?uJI|Ck3-tJMHjRka=hUjk>n0_TnE{d~qbH+5K+CBQF!dEGpa zjg1X}<08@tMZ^O8oO5}e=TpW$!aaWZK5)L-Y+|j&TDz6IQw)j*z}_TDrf|F#eg$5K zaaF$p9GUz|Ueyk`TSR_R)oXx5K1G}U#SV!`M^zsIPEM-Yf5$chRi7Rs_T&eF!?jwC zg@uJl$KQYz5ji*O8CCTj;FvMy+EKl<+ii-X_=`ae_8pm-Z%d$y;b>KbV zW8kd!zY};4cy-jrzZBl?smTk^tJQZgsMX8WYL!Z*0>I|x=2or%ocE8yFr;3uPuA)J zP~hOKw)ubEDQ56D4*<6V!|oJC(U`5ZmVUpFS9}f}1y)7m{5<^2_G5pE`}nUP-vQh( xa@=E3xxNFw0Zxd>-&caWqoJyqsxIu*|6fNfVWQwMvP=K~002ovPDHLkV1hsEui^jz literal 0 HcmV?d00001 diff --git a/internal_packages/open-tracking/lib/main.es6 b/internal_packages/open-tracking/lib/main.es6 index 970280e82..acb579e51 100644 --- a/internal_packages/open-tracking/lib/main.es6 +++ b/internal_packages/open-tracking/lib/main.es6 @@ -25,7 +25,7 @@ function afterDraftSend({draftClientId}) { const uid = metadata.uid; // set metadata against the message - Actions.setMetadata(message, PLUGIN_ID, {openCount: 0, openData: []}); + Actions.setMetadata(message, PLUGIN_ID, {open_count: 0, open_data: []}); // post the uid and message id pair to the plugin server const data = {uid: uid, message_id: message.id, thread_id: 1}; diff --git a/internal_packages/open-tracking/lib/open-tracking-icon.jsx b/internal_packages/open-tracking/lib/open-tracking-icon.jsx index b96b3a9d4..ae6ab8969 100644 --- a/internal_packages/open-tracking/lib/open-tracking-icon.jsx +++ b/internal_packages/open-tracking/lib/open-tracking-icon.jsx @@ -24,30 +24,25 @@ export default class OpenTrackingIcon extends React.Component { const metadataObjs = messages.map(msg => msg.metadataForPluginId(plugin.appId)).filter(meta => meta); return { hasMetadata: metadataObjs.length > 0, - opened: metadataObjs.every(m => m.openCount > 0), + opened: metadataObjs.length > 0 && metadataObjs.every(m => m.open_count > 0), }; } - _renderIcon = () => { - if (!this.state.hasMetadata) { - return ; - } - return this.renderImage() - }; - - renderImage() { + _renderImage() { return ( ); } render() { + if (!this.state.hasMetadata) { return false } + const title = this.state.opened ? "This message has been read at least once" : "This message has not been read"; return ( -
- {this._renderIcon()} +
+ {this._renderImage()}
); } diff --git a/internal_packages/open-tracking/lib/open-tracking-message-status.jsx b/internal_packages/open-tracking/lib/open-tracking-message-status.jsx index b257244c6..4ac755ca3 100644 --- a/internal_packages/open-tracking/lib/open-tracking-message-status.jsx +++ b/internal_packages/open-tracking/lib/open-tracking-message-status.jsx @@ -21,7 +21,7 @@ export default class OpenTrackingMessageStatus extends React.Component { } return { hasMetadata: true, - opened: metadata.openCount > 0, + opened: metadata.open_count > 0, }; } @@ -41,8 +41,9 @@ export default class OpenTrackingMessageStatus extends React.Component { 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 ( - {this.renderImage()}  {txt} + {this.renderImage()}  {txt} ) } } diff --git a/internal_packages/open-tracking/stylesheets/main.less b/internal_packages/open-tracking/stylesheets/main.less index 8c11d67c3..051bea281 100644 --- a/internal_packages/open-tracking/stylesheets/main.less +++ b/internal_packages/open-tracking/stylesheets/main.less @@ -19,13 +19,14 @@ font-weight: bold; } .open-tracking-icon { - width: 16px; - margin-right: 4px; + height: 10px; + margin: -9px 0 0 4px; } .read-receipt-message-status { color: @text-color-very-subtle; margin-left: 10px; + cursor: default; &.Unread { img.content-mask { background-color: @text-color-very-subtle;