diff options
author | Debanshu Kundu <debanshu.kundu@joshtechnologygroup.com> | 2017-01-20 23:11:13 +0530 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-01-20 14:41:13 -0300 |
commit | 3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4 (patch) | |
tree | b954407a03a6c0ed9836d8b14d910fc52c8dc1dc /webapp/utils | |
parent | fefe4b70d9e69910a8e3acd6890497553b5eff2f (diff) | |
download | chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.tar.gz chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.tar.bz2 chat-3aaf71fdea914af1a7f2b2fb97bb6ae44132fcc4.zip |
#4257 Added functionality to create previews for post links using open graph data from those links. (#4890)
Diffstat (limited to 'webapp/utils')
-rw-r--r-- | webapp/utils/commons.jsx | 36 | ||||
-rw-r--r-- | webapp/utils/constants.jsx | 3 | ||||
-rw-r--r-- | webapp/utils/utils.jsx | 12 |
3 files changed, 51 insertions, 0 deletions
diff --git a/webapp/utils/commons.jsx b/webapp/utils/commons.jsx new file mode 100644 index 000000000..1888869dc --- /dev/null +++ b/webapp/utils/commons.jsx @@ -0,0 +1,36 @@ +export function getDistanceBW2Points(point1, point2, xAttr = 'x', yAttr = 'y') { + return Math.sqrt(Math.pow(point1[xAttr] - point2[xAttr], 2) + Math.pow(point1[yAttr] - point2[yAttr], 2)); +} + +/** + * Funtion to return nearest point of given pivot point. + * It return two points one nearest and other nearest but having both coorditanes smaller than the given point's coordinates. + */ +export function getNearestPoint(pivotPoint, points, xAttr = 'x', yAttr = 'y') { + var nearestPoint = {}; + var nearestPointLte = {}; // Nearest point smaller than or equal to point + for (const point of points) { + if (typeof nearestPoint[xAttr] === 'undefined' || typeof nearestPoint[yAttr] === 'undefined') { + nearestPoint = point; + } else if (getDistanceBW2Points(point, pivotPoint, xAttr, yAttr) < getDistanceBW2Points(nearestPoint, pivotPoint, xAttr, yAttr)) { + // Check for bestImage + nearestPoint = point; + } + + if (typeof nearestPointLte[xAttr] === 'undefined' || typeof nearestPointLte[yAttr] === 'undefined') { + if (point[xAttr] <= pivotPoint[xAttr] && point[yAttr] <= pivotPoint[yAttr]) { + nearestPointLte = point; + } + } else if ( + // Check for bestImageLte + getDistanceBW2Points(point, pivotPoint, xAttr, yAttr) < getDistanceBW2Points(nearestPointLte, pivotPoint, xAttr, yAttr) && + point[xAttr] <= pivotPoint[xAttr] && point[yAttr] <= pivotPoint[yAttr] + ) { + nearestPointLte = point; + } + } + return { + nearestPoint, + nearestPointLte + }; +} diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index 6377f27f2..b1c188d89 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -146,6 +146,9 @@ export const ActionTypes = keyMirror({ RECEIVED_LOCALE: null, + UPDATE_OPEN_GRAPH_METADATA: null, + RECIVED_OPEN_GRAPH_METADATA: null, + SHOW_SEARCH: null, USER_TYPING: null, diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 9654ff605..a0aecbdb3 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -1324,3 +1324,15 @@ export function handleFormattedTextClick(e) { browserHistory.push('/' + TeamStore.getCurrent().name + '/channels/' + channelMentionAttribute.value); } } + +export function isEmptyObject(object) { + if (!object) { + return true; + } + + if (Object.keys(object).length === 0) { + return true; + } + + return false; +} |