Skip to content

Commit

Permalink
Fixed trying to sync removed accounts
Browse files Browse the repository at this point in the history
Fix #5
  • Loading branch information
kam193 committed Jan 11, 2023
1 parent fba4c92 commit 22d7384
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
36 changes: 24 additions & 12 deletions signature-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ function refreshAccessTokenWithErrorCatching(refreshToken) {
},
});
return new Promise((resolve, reject) => {
fetch(refreshRequest).then((response) => {
if (response.status != 200) {
reject("Cannot refresh access token");
}
response.json().then((json) => {
resolve(json.access_token);
});
}).catch((error) => reject(error));
fetch(refreshRequest)
.then((response) => {
if (response.status != 200) {
reject("Cannot refresh access token");
}
response.json().then((json) => {
resolve(json.access_token);
});
})
.catch((error) => reject(error));
});
}

Expand All @@ -58,7 +60,7 @@ async function getUserSendAs(syncable) {
try {
let token = await refreshAccessTokenWithErrorCatching(syncable.refreshToken);
let settings = await makeRequest(token, dataUrl);

let sendAs = [];
settings.sendAs.forEach((alias) => {
sendAs.push({
Expand Down Expand Up @@ -111,6 +113,12 @@ async function syncAccounts() {
continue;
}
try {
let account = await browser.accounts.get(account_id, false);
if (account === null) {
console.warn(`The account ${account_id} doesn't exist anymore. Skipping sync...`);
continue;
}

let gmailSendAs = await getUserSendAs(syncable);
let aliasesByEmail = {};
gmailSendAs.forEach((alias) => {
Expand All @@ -119,8 +127,12 @@ async function syncAccounts() {

await ensureDefaultIdentitySyncable(syncable);
let identities = syncable.identitiesSyncable || {};
Object.values(identities).forEach((identity) => {
if (identity.gmailSendAsEmail != NONE_EMAIL) {

for (const identity of Object.values(identities)) {
let thunderbirdIdentity = await browser.identities.get(identity.identityId);
if (thunderbirdIdentity === null) {
console.warn(`The identity ${account_id} doesn't exist anymore. Skipping sync...`);
} else if (identity.gmailSendAsEmail != NONE_EMAIL) {
let alias = aliasesByEmail[identity.gmailSendAsEmail];
if (alias) {
console.log(
Expand All @@ -133,7 +145,7 @@ async function syncAccounts() {
console.error(error);
}
}
});
}

// After trying sync all identities, throw last error if any
if (error) throw error;
Expand Down
7 changes: 7 additions & 0 deletions signature-extension/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ <h1>Welcome in the new version of Signature sync for Gmail!</h1>
only on first use and major changes, but you can always access it in add-on's preferences.
</p>

<h2>Version 3.1.0</h2>
<ul>
<li>
Fixing trying to sync already removed from Thunderbird accounts or identities.
</li>
</ul>

<h2>Version 3.0.0</h2>
<ul>
<li>
Expand Down
2 changes: 1 addition & 1 deletion signature-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Signature sync for Gmail",
"version": "3.0.0",
"version": "3.1.0",
"author": "Kamil Mańkowski",
"description": "Sync your signatures with Gmail accounts",
"homepage_url": "https://thbrd-signature.kam193.eu/",
Expand Down

0 comments on commit 22d7384

Please sign in to comment.