From d5d5397959b8027fa7fa77d03ddc4030e34dac39 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 5 Dec 2017 21:41:44 +0000 Subject: [PATCH 1/8] Set custom widget title. --- src/ScalarAuthClient.js | 30 ++++++++++++++++++++++++ src/components/views/elements/AppTile.js | 19 +++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index c9d056f88e..f50128c454 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -76,6 +76,36 @@ class ScalarAuthClient { return defer.promise; } + getScalarPageTitle(url) { + const defer = Promise.defer(); + + let scalarPageLookupUrl = SdkConfig.get().integrations_rest_url + '/api/widgets/title_lookup'; + scalarPageLookupUrl = this.getStarterLink(scalarPageLookupUrl); + scalarPageLookupUrl += '&curl=' + encodeURIComponent(url); + request({ + method: 'GET', + uri: scalarPageLookupUrl, + json: true, + }, (err, response, body) => { + if (err) { + defer.reject(err); + } else if (response.statusCode / 100 !== 2) { + defer.reject({statusCode: response.statusCode}); + } else if (!body) { + defer.reject(new Error("Missing scalar_token in response")); + } else { + console.warn("page title body", body); + let title = ""; + if (body.page_title_cache_item && body.page_title_cache_item.cached_title) { + title = body.page_title_cache_item.cached_title; + } + defer.resolve(title); + } + }); + + return defer.promise; + } + getScalarInterfaceUrlForRoom(roomId, screen, id) { let url = SdkConfig.get().integrations_ui_url; url += "?scalar_token=" + encodeURIComponent(this.scalarToken); diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 1dbb7af586..ba0691a1de 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -196,6 +196,8 @@ export default React.createClass({ widgetUrl: u.format(), initialising: false, }); + + this._updateWidgetTitle(params.url); }, (err) => { console.error("Failed to get scalar_token", err); this.setState({ @@ -299,12 +301,19 @@ export default React.createClass({ /** * Set remote content title on AppTile - * @param {string} title Title string to set on the AppTile + * @param {string} url Url to check for title */ - _updateWidgetTitle(title) { - if (title) { - this.setState({widgetPageTitle: null}); - } + _updateWidgetTitle(url) { + this._scalarClient.getScalarPageTitle(url).then((widgetPageTitle) => { + if (widgetPageTitle) { + console.log("Got page title", widgetPageTitle); + this.setState({widgetPageTitle: widgetPageTitle}); + } else { + console.error("No page title"); + } + }, (err) =>{ + console.error("Failed to get page title", err); + }); }, // Widget labels to render, depending upon user permissions From 7f86ed35a33bd1bb4807d016b20f4755044dbc48 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 5 Dec 2017 21:49:11 +0000 Subject: [PATCH 2/8] Only show custom title if different from app name. --- src/components/views/elements/AppTile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 9c9f9d6ec5..6762d4fec1 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -453,7 +453,7 @@ export default React.createClass({ height="10" /> { this.formatAppTileName() } - { this.state.widgetPageTitle && ( + { this.state.widgetPageTitle && this.state.widgetPageTitle != this.formatAppTileName() && (  - { this.state.widgetPageTitle } ) } From fc3287c49f2bbd2ec9f213a33754242760e8f77e Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 5 Dec 2017 21:56:35 +0000 Subject: [PATCH 3/8] Fix error message. --- src/ScalarAuthClient.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index f50128c454..41266bdced 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -92,9 +92,8 @@ class ScalarAuthClient { } else if (response.statusCode / 100 !== 2) { defer.reject({statusCode: response.statusCode}); } else if (!body) { - defer.reject(new Error("Missing scalar_token in response")); + defer.reject(new Error("Missing page_title in response")); } else { - console.warn("page title body", body); let title = ""; if (body.page_title_cache_item && body.page_title_cache_item.cached_title) { title = body.page_title_cache_item.cached_title; From d62520482a9114bd2762ccede1b014c0a510d32b Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 5 Dec 2017 21:57:28 +0000 Subject: [PATCH 4/8] fix typo. --- src/ScalarAuthClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index 41266bdced..a796c92ab3 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -92,7 +92,7 @@ class ScalarAuthClient { } else if (response.statusCode / 100 !== 2) { defer.reject({statusCode: response.statusCode}); } else if (!body) { - defer.reject(new Error("Missing page_title in response")); + defer.reject(new Error("Missing page title in response")); } else { let title = ""; if (body.page_title_cache_item && body.page_title_cache_item.cached_title) { From 3206527d73a7b6145e92817d9bc9d7c9f945c6e9 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 5 Dec 2017 21:59:44 +0000 Subject: [PATCH 5/8] Remove logging. --- src/components/views/elements/AppTile.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 6762d4fec1..1a5032cf94 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -306,10 +306,7 @@ export default React.createClass({ _updateWidgetTitle(url) { this._scalarClient.getScalarPageTitle(url).then((widgetPageTitle) => { if (widgetPageTitle) { - console.log("Got page title", widgetPageTitle); this.setState({widgetPageTitle: widgetPageTitle}); - } else { - console.error("No page title"); } }, (err) =>{ console.error("Failed to get page title", err); From 20917e1a07f04c1901fba045bacf16367a82ff97 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 8 Dec 2017 15:12:48 +0000 Subject: [PATCH 6/8] Set page title from widget data, if available. --- src/components/views/elements/AppTile.js | 9 ++++++--- src/components/views/rooms/AppsDrawer.js | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 1a5032cf94..9c327d55fe 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -79,7 +79,7 @@ export default React.createClass({ hasPermissionToLoad: hasPermissionToLoad === 'true' || newProps.userId === newProps.creatorUserId, error: null, deleting: false, - widgetPageTitle: null, + widgetPageTitle: newProps.widgetPageTitle, }; }, @@ -197,7 +197,10 @@ export default React.createClass({ initialising: false, }); - this._updateWidgetTitle(params.url); + // Fetch page title from remote content if not already set + if (!this.state.widgetPageTitle) { + this._fetchWidgetTitle(params.url); + } }, (err) => { console.error("Failed to get scalar_token", err); this.setState({ @@ -303,7 +306,7 @@ export default React.createClass({ * Set remote content title on AppTile * @param {string} url Url to check for title */ - _updateWidgetTitle(url) { + _fetchWidgetTitle(url) { this._scalarClient.getScalarPageTitle(url).then((widgetPageTitle) => { if (widgetPageTitle) { this.setState({widgetPageTitle: widgetPageTitle}); diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 423f345b1d..4e4fc5f06c 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -224,6 +224,7 @@ module.exports = React.createClass({ userId={this.props.userId} show={this.props.showApps} creatorUserId={app.creatorUserId} + widgetPageTitle={(app.data && app.data.widgetPageTitle) ? app.data.widgetPageTitle : ''} />); }); From a9ae4be74ce7f45f1de5aa101a41581f5504cd59 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 8 Dec 2017 15:27:14 +0000 Subject: [PATCH 7/8] Fix page title variable name. --- src/components/views/rooms/AppsDrawer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 4e4fc5f06c..2282f0717f 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -224,7 +224,7 @@ module.exports = React.createClass({ userId={this.props.userId} show={this.props.showApps} creatorUserId={app.creatorUserId} - widgetPageTitle={(app.data && app.data.widgetPageTitle) ? app.data.widgetPageTitle : ''} + widgetPageTitle={(app.data && app.data.title) ? app.data.title : ''} />); }); From 24db57bfb6c1b480281ad35df74dd578f5537050 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Fri, 8 Dec 2017 18:47:00 +0000 Subject: [PATCH 8/8] Fix api prefix. --- src/ScalarAuthClient.js | 2 +- src/components/views/elements/AppTile.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index a796c92ab3..3e775a94ab 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -79,7 +79,7 @@ class ScalarAuthClient { getScalarPageTitle(url) { const defer = Promise.defer(); - let scalarPageLookupUrl = SdkConfig.get().integrations_rest_url + '/api/widgets/title_lookup'; + let scalarPageLookupUrl = SdkConfig.get().integrations_rest_url + '/widgets/title_lookup'; scalarPageLookupUrl = this.getStarterLink(scalarPageLookupUrl); scalarPageLookupUrl += '&curl=' + encodeURIComponent(url); request({ diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 9c327d55fe..3ed67eb69d 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -198,7 +198,7 @@ export default React.createClass({ }); // Fetch page title from remote content if not already set - if (!this.state.widgetPageTitle) { + if (!this.state.widgetPageTitle && params.url) { this._fetchWidgetTitle(params.url); } }, (err) => {