mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Merge pull request #1650 from matrix-org/rxl881/customTitle
Display custom widget content titles
This commit is contained in:
commit
c1d9df0e1f
3 changed files with 46 additions and 7 deletions
|
@ -76,6 +76,35 @@ class ScalarAuthClient {
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getScalarPageTitle(url) {
|
||||||
|
const defer = Promise.defer();
|
||||||
|
|
||||||
|
let scalarPageLookupUrl = SdkConfig.get().integrations_rest_url + '/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 page title in response"));
|
||||||
|
} else {
|
||||||
|
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) {
|
getScalarInterfaceUrlForRoom(roomId, screen, id) {
|
||||||
let url = SdkConfig.get().integrations_ui_url;
|
let url = SdkConfig.get().integrations_ui_url;
|
||||||
url += "?scalar_token=" + encodeURIComponent(this.scalarToken);
|
url += "?scalar_token=" + encodeURIComponent(this.scalarToken);
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default React.createClass({
|
||||||
hasPermissionToLoad: hasPermissionToLoad === 'true' || newProps.userId === newProps.creatorUserId,
|
hasPermissionToLoad: hasPermissionToLoad === 'true' || newProps.userId === newProps.creatorUserId,
|
||||||
error: null,
|
error: null,
|
||||||
deleting: false,
|
deleting: false,
|
||||||
widgetPageTitle: null,
|
widgetPageTitle: newProps.widgetPageTitle,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -196,6 +196,11 @@ export default React.createClass({
|
||||||
widgetUrl: u.format(),
|
widgetUrl: u.format(),
|
||||||
initialising: false,
|
initialising: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fetch page title from remote content if not already set
|
||||||
|
if (!this.state.widgetPageTitle && params.url) {
|
||||||
|
this._fetchWidgetTitle(params.url);
|
||||||
|
}
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.error("Failed to get scalar_token", err);
|
console.error("Failed to get scalar_token", err);
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -299,12 +304,16 @@ export default React.createClass({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set remote content title on AppTile
|
* 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) {
|
_fetchWidgetTitle(url) {
|
||||||
if (title) {
|
this._scalarClient.getScalarPageTitle(url).then((widgetPageTitle) => {
|
||||||
this.setState({widgetPageTitle: null});
|
if (widgetPageTitle) {
|
||||||
}
|
this.setState({widgetPageTitle: widgetPageTitle});
|
||||||
|
}
|
||||||
|
}, (err) =>{
|
||||||
|
console.error("Failed to get page title", err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Widget labels to render, depending upon user permissions
|
// Widget labels to render, depending upon user permissions
|
||||||
|
@ -444,7 +453,7 @@ export default React.createClass({
|
||||||
height="10"
|
height="10"
|
||||||
/>
|
/>
|
||||||
<b>{ this.formatAppTileName() }</b>
|
<b>{ this.formatAppTileName() }</b>
|
||||||
{ this.state.widgetPageTitle && (
|
{ this.state.widgetPageTitle && this.state.widgetPageTitle != this.formatAppTileName() && (
|
||||||
<span> - { this.state.widgetPageTitle }</span>
|
<span> - { this.state.widgetPageTitle }</span>
|
||||||
) }
|
) }
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -224,6 +224,7 @@ module.exports = React.createClass({
|
||||||
userId={this.props.userId}
|
userId={this.props.userId}
|
||||||
show={this.props.showApps}
|
show={this.props.showApps}
|
||||||
creatorUserId={app.creatorUserId}
|
creatorUserId={app.creatorUserId}
|
||||||
|
widgetPageTitle={(app.data && app.data.title) ? app.data.title : ''}
|
||||||
/>);
|
/>);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue