Skip to content

Commit

Permalink
[IMPROVE] Deprecate fixCordova helper (#13598)
Browse files Browse the repository at this point in the history
* Deprecate fixCordova helper

* Remove redundant check
  • Loading branch information
tassoevan authored and rodrigok committed Mar 2, 2019
1 parent 54b8dbd commit 2e9b0ff
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 35 deletions.
19 changes: 2 additions & 17 deletions packages/rocketchat-lazy-load/client/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import _ from 'underscore';
import './lazyloadImage';

export const fixCordova = function(url) {
if (url && url.indexOf('data:image') === 0) {
return url;
}

if (Meteor.settings.public.sandstorm || url.match(/^(https?:)?\/\//i)) {
return url;
} else if (navigator.userAgent.indexOf('Electron') > -1) {
return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url;
} else {
return Meteor.absoluteUrl().replace(/\/$/, '') + url;
}
};

const getEl = (el, instance) => (instance && instance.firstNode) || el;

const loadImage = (el, instance) => {
const element = getEl(el, instance);
const img = new Image();
const src = element.getAttribute('data-src');
img.onload = function() {
img.onload = () => {
if (instance) {
instance.loaded.set(true);
} else {
Expand All @@ -32,7 +17,7 @@ const loadImage = (el, instance) => {
}
element.removeAttribute('data-src');
};
img.src = fixCordova(src);
img.src = src;
};

const isVisible = (el, instance) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-lazy-load/client/lazyloadImage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import './lazyloadImage.html';
import { addImage, fixCordova } from './';
import { addImage } from './';

const emptyImageEncoded =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8+/u3PQAJJAM0dIyWdgAAAABJRU5ErkJggg==';
Expand All @@ -13,14 +13,14 @@ Template.lazyloadImage.helpers({
},

srcUrl() {
return this.src && fixCordova(this.src);
return this.src;
},

lazySrcUrl() {
const { preview, placeholder, src } = this;

if (Template.instance().loaded.get() || (!preview && !placeholder)) {
return fixCordova(src);
return src;
}

return `data:image/png;base64,${ preview || emptyImageEncoded }`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
{{#if author_link}}
<div class="attachment-author">
{{#if author_icon}}
<img src="{{fixCordova author_icon}}">
<img src="{{author_icon}}">
{{/if}}
<a href="{{fixCordova author_link}}" target="_blank" rel="noopener noreferrer">{{author_name}}</a>
<a href="{{author_link}}" target="_blank" rel="noopener noreferrer">{{author_name}}</a>
{{#if ts}}
{{#if message_link}}
<span class="time-link">
Expand All @@ -32,7 +32,7 @@
{{else}}
<div class="attachment-author">
{{#if author_icon}}
<img src="{{fixCordova author_icon}}">
<img src="{{author_icon}}">
{{/if}}
{{author_name}}
{{#if ts}}
Expand All @@ -54,9 +54,9 @@
{{#if title}}
<div class="attachment-title">
{{#if title_link}}
<a href="{{fixCordova title_link}}" target="_blank" rel="noopener noreferrer">{{#if isFile}} {{_ "Attachment_File_Uploaded"}}: {{/if}}{{title}}</a>
<a href="{{title_link}}" target="_blank" rel="noopener noreferrer">{{#if isFile}} {{_ "Attachment_File_Uploaded"}}: {{/if}}{{title}}</a>
{{#if title_link_download}}
<a class="attachment-download-icon" href="{{fixCordova title_link}}" target="_blank" download="" rel="noopener noreferrer">{{> icon icon="download"}}</a>
<a class="attachment-download-icon" href="{{title_link}}" target="_blank" download="" rel="noopener noreferrer">{{> icon icon="download"}}</a>
{{/if}}
{{else}}
{{title}}
Expand All @@ -73,7 +73,7 @@
<div class="attachment-flex">
{{#if thumb_url}}
<div class="attachment-thumb">
<img src="{{fixCordova thumb_url}}">
<img src="{{thumb_url}}">
</div>
{{/if}}

Expand Down Expand Up @@ -116,7 +116,7 @@
{{#unless mediaCollapsed}}
<div class="attachment-audio">
<audio controls>
<source src="{{fixCordova audio_url}}" type="{{audio_type}}" data-description="{{description}}">
<source src="{{audio_url}}" type="{{audio_type}}" data-description="{{description}}">
Your browser does not support the audio element.
</audio>
</div>
Expand All @@ -127,7 +127,7 @@
{{#unless mediaCollapsed}}
<div class="attachment-video">
<video controls class="inline-video">
<source src="{{fixCordova video_url}}" type="{{video_type}}" data-description="{{description}}">
<source src="{{video_url}}" type="{{video_type}}" data-description="{{description}}">
Your browser does not support the video element.
</video>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { DateFormat } from 'meteor/rocketchat:lib';
import { fixCordova } from 'meteor/rocketchat:lazy-load';
import { Template } from 'meteor/templating';
import { getUserPreference } from 'meteor/rocketchat:utils';
import { Users } from 'meteor/rocketchat:models';
Expand All @@ -13,7 +12,6 @@ const colors = {
};

Template.messageAttachment.helpers({
fixCordova,
parsedText() {
return renderMessageBody({
msg: this.text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ul class="attachments">
{{#each files}}
<li class="attachments__item">
<a href="{{fixCordova url}}" title="{{name}}" data-description="{{description}}"
<a href="{{url}}" title="{{name}}" data-description="{{description}}"
class="attachments__item-link {{fileTypeClass}}"
download rel="noopener noreferrer" target="_blank">
{{#with thumb}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Mongo } from 'meteor/mongo';
import { fixCordova } from 'meteor/rocketchat:lazy-load';
import { ReactiveVar } from 'meteor/reactive-var';
import { DateFormat } from 'meteor/rocketchat:lib';
import { t } from 'meteor/rocketchat:utils';
Expand Down Expand Up @@ -29,8 +28,6 @@ Template.uploadedFilesList.helpers({
return roomFiles.find({ rid: this.rid }, { sort: { uploadedAt: -1 } });
},

fixCordova,

url() {
return `/file-upload/${ this._id }/${ this.name }`;
},
Expand All @@ -44,7 +41,7 @@ Template.uploadedFilesList.helpers({

thumb() {
if (/image/.test(this.type)) {
return fixCordova(this.url);
return this.url;
}
},
format(timestamp) {
Expand Down

0 comments on commit 2e9b0ff

Please sign in to comment.