Refresh site icon on reconnect

This commit is contained in:
raucao committed 2026-10-04 18:52:20 +02:00
1 parent 5928406524
commit e0ddce8ed3
5 files changed
+80

No files matched your search

@@ -42,6 +42,7 @@ export default class SettingsIntegrationsManageList extends Component {
if (transport === 'extension') {
await this.sites.reload();
await this.sites.refreshIcon(row.url);
this.integrationResult.show({ success: true, integration });
}
} catch (err) {
+5
View File
@@ -5,6 +5,7 @@ export default class AuthDiscourseCallbackRoute extends Route {
@service authorization;
@service integrationResult;
@service router;
@service sites;
async model() {
try {
@@ -12,6 +13,10 @@ export default class AuthDiscourseCallbackRoute extends Route {
'discourse',
window.location.href
);
// The site list was loaded before the callback activated the record, so
// rebuild it and re-resolve this forum's icon from the network.
await this.sites.reload();
await this.sites.refreshIcon(integration.url);
this.integrationResult.show({ success: true, integration });
} catch (error) {
console.error('Error processing Discourse callback:', error);
+20
View File
@@ -3,6 +3,7 @@ import { tracked } from '@glimmer/tracking';
import { SITE_GROUPS } from '../config/sites';
import { FEEDBIN_ICON_URL } from '../config/integrations';
import { FEEDBIN_DEFAULT_URL } from '../config/feedbin';
import { normalizeOrigin } from './site-icons';
function labelForUrl(url) {
try {
@@ -149,6 +150,25 @@ export default class SitesService extends Service {
await this.load();
}
// Re-resolves a single site's icon, bypassing the icon cache. Used after a
// reconnect so a forum picks up its current icon without waiting for the
// cache to expire.
async refreshIcon(url) {
const icon = await this.siteIcons.refresh(url);
if (!icon) {
return;
}
const origin = normalizeOrigin(url);
const site = this.list.find(
(candidate) => normalizeOrigin(candidate.url) === origin
);
if (site) {
this.updateSite(site.id, { icon });
}
}
async removeSource(id) {
await this.storage.remove('integrations', id);
await this.reload();
@@ -7,6 +7,7 @@ import List from 'dashtab/components/settings/integrations/manage-list';
class FakeSitesService {
@tracked all = [];
removed = [];
refreshed = [];
reloaded = 0;
integrationFor(id) {
@@ -21,6 +22,10 @@ class FakeSitesService {
async reload() {
this.reloaded++;
}
async refreshIcon(url) {
this.refreshed.push(url);
}
}
class FakeNotificationsService {
@@ -305,6 +310,7 @@ module(
{ type: 'discourse', url: 'https://bad.example.com' },
]);
assert.strictEqual(sites.reloaded, 1);
assert.deepEqual(sites.refreshed, ['https://bad.example.com']);
assert.strictEqual(integrationResult.shown.length, 1);
});
+48
View File
@@ -155,6 +155,54 @@ module('Unit | Service | sites', function (hooks) {
assert.strictEqual(service.all[0].id, 'discourse-new');
});
test('refreshIcon replaces the site icon with a freshly resolved record', async function (assert) {
const storage = this.owner.lookup('service:storage');
await storage.set('integrations', 'discourse-abc', {
type: 'discourse',
status: 'active',
url: 'https://forum.example.com',
apiKey: 'key',
});
const fresh = { dataUrl: 'data:image/png;base64,new', maskable: true };
const siteIcons = this.owner.lookup('service:site-icons');
let requested;
siteIcons.refresh = async (url) => {
requested = url;
return fresh;
};
const service = this.owner.lookup('service:sites');
await service.ready;
await service.refreshIcon('https://forum.example.com');
assert.strictEqual(requested, 'https://forum.example.com');
assert.deepEqual(service.all[0].icon, fresh);
});
test('refreshIcon ignores a URL with no matching site', async function (assert) {
const storage = this.owner.lookup('service:storage');
await storage.set('integrations', 'discourse-abc', {
type: 'discourse',
status: 'active',
url: 'https://forum.example.com',
});
const siteIcons = this.owner.lookup('service:site-icons');
siteIcons.refresh = async () => ({
dataUrl: 'data:image/png;base64,new',
maskable: true,
});
const service = this.owner.lookup('service:sites');
await service.ready;
await service.refreshIcon('https://other.example.com');
assert.notOk(service.all[0].icon);
});
test('removeSource deletes the integration and reloads', async function (assert) {
const storage = this.owner.lookup('service:storage');
await storage.set('integrations', 'discourse-abc', {