Skip to content

Commit

Permalink
fix(classes): keep user changes to public talks during backup
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Sep 25, 2023
1 parent 1393e5e commit b2d8080
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/classes/Congregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,32 @@ Congregation.prototype.mergeVisitingSpeakersFromBackup = function (congregations
return finalCongs;
};

Congregation.prototype.mergePublicTalksFromBackup = function (cong_publicTalks) {
// new record
if (this.cong_publicTalks.length === 0) {
this.cong_publicTalks = cong_publicTalks;
return;
}

// update record
for (const incomingTalk of cong_publicTalks) {
const currentTalk = this.cong_publicTalks.find((talk) => talk.talk_number === incomingTalk.talk_number);

for (const talkLanguage of Object.entries(incomingTalk.talk_title)) {
const incomingModified = talkLanguage.modified;
const currentModified = incomingTalk.talk_title[talkLanguage]?.modified;

if (!currentModified) {
currentTalk.talk_title[talkLanguage] = incomingTalk.talk_title[talkLanguage];
}

if (currentModified && incomingModified > currentModified) {
currentTalk.talk_title[talkLanguage] = incomingTalk.talk_title[talkLanguage];
}
}
}
};

Congregation.prototype.saveBackup = async function (payload) {
const cong_persons = payload.cong_persons;
const cong_deleted = payload.cong_deleted;
Expand Down Expand Up @@ -1087,6 +1113,11 @@ Congregation.prototype.saveBackup = async function (payload) {
finalFieldServiceGroup = this.mergeFieldServiceGroupFromBackup(cong_fieldServiceGroup, cong_deleted);
}

// update cong_publicTalks data
if (cong_publicTalks) {
this.mergePublicTalksFromBackup(cong_publicTalks);
}

const userInfo = users.findUserByAuthUid(uid);

// remove user settings from settings
Expand Down

0 comments on commit b2d8080

Please sign in to comment.