mirror of https://github.com/vector-im/riot-web
Merge remote-tracking branch 'origin/develop' into develop
commit
29cf079561
|
@ -292,22 +292,32 @@ function inviteUser(event, roomId, userId) {
|
||||||
* arrives) or rejects after a timeout
|
* arrives) or rejects after a timeout
|
||||||
*
|
*
|
||||||
* @param {string} widgetId The ID of the widget to wait for
|
* @param {string} widgetId The ID of the widget to wait for
|
||||||
|
* @param {boolean} add True to wait for the widget to be added,
|
||||||
|
* false to wait for it to be deleted.
|
||||||
* @returns {Promise} that resolves when the widget is available
|
* @returns {Promise} that resolves when the widget is available
|
||||||
*/
|
*/
|
||||||
function waitForUserWidget(widgetId) {
|
function waitForUserWidget(widgetId, add) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const currentAccountDataEvent = MatrixClientPeg.get().getAccountData('m.widgets');
|
const currentAccountDataEvent = MatrixClientPeg.get().getAccountData('m.widgets');
|
||||||
if (
|
|
||||||
currentAccountDataEvent &&
|
// Tests an account data event, returning true if it's in the state
|
||||||
currentAccountDataEvent.getContent() &&
|
// we're waiting for it to be in
|
||||||
currentAccountDataEvent.getContent()[widgetId] !== undefined
|
function eventInIntendedState(ev) {
|
||||||
) {
|
if (!ev || !currentAccountDataEvent.getContent()) return false;
|
||||||
|
if (add) {
|
||||||
|
return ev.getContent()[widgetId] !== undefined;
|
||||||
|
} else {
|
||||||
|
return ev.getContent()[widgetId] === undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventInIntendedState(currentAccountDataEvent)) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAccountData(ev) {
|
function onAccountData(ev) {
|
||||||
if (ev.getType() === 'm.widgets' && ev.getContent() && ev.getContent()[widgetId] !== undefined) {
|
if (eventInIntendedState(currentAccountDataEvent)) {
|
||||||
MatrixClientPeg.get().removeListener('accountData', onAccountData);
|
MatrixClientPeg.get().removeListener('accountData', onAccountData);
|
||||||
clearTimeout(timerId);
|
clearTimeout(timerId);
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -395,7 +405,7 @@ function setWidget(event, roomId) {
|
||||||
// wait for this, the action will complete but if the user is fast enough,
|
// wait for this, the action will complete but if the user is fast enough,
|
||||||
// the widget still won't actually be there.
|
// the widget still won't actually be there.
|
||||||
client.setAccountData('m.widgets', userWidgets).then(() => {
|
client.setAccountData('m.widgets', userWidgets).then(() => {
|
||||||
return waitForUserWidget(widgetId);
|
return waitForUserWidget(widgetId, widgetUrl !== null);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
sendResponse(event, {
|
sendResponse(event, {
|
||||||
success: true,
|
success: true,
|
||||||
|
|
Loading…
Reference in New Issue