Skip to content

Commit e99b393

Browse files
committed
Modernize code for mailing pending Bible updates
#1071
1 parent adb74e9 commit e99b393

1 file changed

Lines changed: 59 additions & 59 deletions

File tree

bb/logic.cpp

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -642,65 +642,65 @@ void bible_logic::client_receive_merge_mail (const std::string& bible, int book,
642642
// This emails pending Bible updates to the user.
643643
void bible_logic::client_mail_pending_bible_updates (const std::string& user)
644644
{
645-
// Iterate over all the actions stored for all Bible data ready for sending to the Cloud.
646-
const std::vector <std::string> bibles = database::bible_actions::get_bibles ();
647-
for (const auto& bible : bibles) {
648-
// Skip the Sample Bible, for less clutter.
649-
if (bible == demo_sample_bible_name ()) continue;
650-
const std::vector <int> books = database::bible_actions::get_books (bible);
651-
for (const int book : books) {
652-
const std::vector <int> chapters = database::bible_actions::get_chapters (bible, book);
653-
for (const int chapter : chapters) {
654-
655-
// Get old and new USFM for this chapter.
656-
const std::string oldusfm = database::bible_actions::get_usfm (bible, book, chapter);
657-
const std::string newusfm = database::bibles::get_chapter (bible, book, chapter);
658-
// If old USFM and new USFM are the same, or the new USFM is empty, skip it.
659-
if (newusfm == oldusfm) continue;
660-
if (newusfm.empty ()) continue;
661-
662-
// Add the passage to the subject.
663-
std::string subject = "Discarded text update";
664-
subject.append (" | " + filter_passage_display (book, chapter, std::string()));
665-
666-
// Create the body of the email.
667-
pugi::xml_document document {};
668-
pugi::xml_node node {};
669-
node = document.append_child ("h3");
670-
node.text ().set (subject.c_str());
671-
672-
// Add some information for the user.
673-
node = document.append_child ("p");
674-
std::string information {};
675-
information.append (translate ("You have now connected to Bibledit Cloud."));
676-
information.append (" ");
677-
information.append (translate ("While you were disconnected from Bibledit Cloud, you made some changes in the Bible text on your device."));
678-
information.append (" ");
679-
information.append (translate ("These changes will not be saved to Bibledit Cloud."));
680-
information.append (" ");
681-
information.append (translate ("The unsaved text is below."));
682-
node.text ().set (information.c_str());
683-
684-
// Add the passage.
685-
node = document.append_child ("p");
686-
std::string location = bible + " " + filter_passage_display (book, chapter, "") + ".";
687-
node.text ().set (location.c_str ());
688-
689-
// Add the text.
690-
document.append_child ("br");
691-
node = document.append_child ("pre");
692-
node.text ().set (newusfm.c_str ());
693-
694-
// Convert the document to a string with indent, to avoid line-too-long errors.
695-
std::stringstream output {};
696-
document.print (output, " ", pugi::format_indent);
697-
const std::string html = output.str ();
698-
699-
// Schedule the mail for sending to the user.
700-
email::schedule (user, subject, html);
701-
}
702-
}
703-
}
645+
// Iterate over all the actions stored for all Bible data ready for sending to the Cloud.
646+
std::ranges::for_each(database::bible_actions::get_bibles(), [&](const std::string& bible)
647+
{
648+
// Skip the Sample Bible, for less clutter.
649+
if (bible == demo_sample_bible_name()) return;
650+
std::ranges::for_each(database::bible_actions::get_books(bible), [&](const int book)
651+
{
652+
std::ranges::for_each(database::bible_actions::get_chapters(bible, book), [&](const int chapter)
653+
{
654+
// Get old and new USFM for this chapter.
655+
const std::string old_usfm = database::bible_actions::get_usfm(bible, book, chapter);
656+
const std::string new_usfm = database::bibles::get_chapter(bible, book, chapter);
657+
// If the old and the new USFM are the same, or the new USFM is empty, skip it.
658+
if (new_usfm == old_usfm) return;
659+
if (new_usfm.empty()) return;
660+
661+
// Add the passage to the subject.
662+
std::string subject = "Discarded text update";
663+
subject.append(" | " + filter_passage_display(book, chapter, {}));
664+
665+
// Create the body of the email.
666+
pugi::xml_document document{};
667+
pugi::xml_node node{};
668+
node = document.append_child("h3");
669+
node.text().set(subject.c_str());
670+
671+
// Add some information for the user.
672+
node = document.append_child("p");
673+
std::string information{};
674+
information.append(translate("You have now connected to Bibledit Cloud."));
675+
information.append(" ");
676+
information.append(translate(
677+
"While you were disconnected from Bibledit Cloud, you made some changes in the Bible text on your device."));
678+
information.append(" ");
679+
information.append(translate("These changes will not be saved to Bibledit Cloud."));
680+
information.append(" ");
681+
information.append(translate("The unsaved text is below."));
682+
node.text().set(information.c_str());
683+
684+
// Add the passage.
685+
node = document.append_child("p");
686+
const std::string location = bible + " " + filter_passage_display(book, chapter, "") + ".";
687+
node.text().set(location.c_str());
688+
689+
// Add the text.
690+
document.append_child("br");
691+
node = document.append_child("pre");
692+
node.text().set(new_usfm.c_str());
693+
694+
// Convert the document to a string with indentation: This avoids line-too-long errors.
695+
std::stringstream output{};
696+
document.print(output, " ", pugi::format_indent);
697+
const std::string html = std::move(output).str();
698+
699+
// Schedule the mail for sending to the user.
700+
email::schedule(user, subject, html);
701+
});
702+
});
703+
});
704704
}
705705

706706

0 commit comments

Comments
 (0)