[chronojump] socialNetwork poll is only asked one time, stored locally and resent in the future if network proble



commit bbbb23c705c18d696326bcd989113d50820df399
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jun 8 18:00:15 2021 +0200

    socialNetwork poll is only asked one time, stored locally and resent in the future if network problems

 src/gui/app1/chronojump.cs | 16 +++++++++++++++-
 src/gui/sendLogAndPoll.cs  | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 8036ce87f..1727ea79a 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -587,7 +587,7 @@ public partial class ChronoJumpWindow
                        hbox_message_permissions_at_boot.Visible = true;
                }
 
-               bool showSocialNetworkPoll = true;
+               bool showSocialNetworkPoll = (preferences.socialNetworkDatetime == "");
                //show send log if needed or other messages
                if (showSendLog)
                {
@@ -7110,7 +7110,21 @@ LogB.Debug("mc finished 5");
        {
                jsPing = new Json();
                if(pingDo())
+               {
                        getNewsDatetime();
+
+                       //also manage pending poll
+                       if(preferences.socialNetworkDatetime == "-1")
+                       {
+                               Json js = new Json();
+                               bool success = js.SocialNetworkPoll(preferences.machineID, 
preferences.socialNetwork);
+                               if(success) {
+                                       SqlitePreferences.Update(SqlitePreferences.SocialNetwork, 
preferences.socialNetwork, false);
+                                       SqlitePreferences.Update(SqlitePreferences.SocialNetworkDatetime,
+                                                       UtilDate.ToFile(DateTime.Now), false);
+                               }
+                       }
+               }
        }
 
        private bool pingDo()
diff --git a/src/gui/sendLogAndPoll.cs b/src/gui/sendLogAndPoll.cs
index bae935458..f594ddad4 100644
--- a/src/gui/sendLogAndPoll.cs
+++ b/src/gui/sendLogAndPoll.cs
@@ -62,7 +62,9 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_social_network_poll_message;
 
 
+       //-----------------
        //--- send log ----
+       //-----------------
 
        string emailStored;
        private void show_send_log(string sendLogMessage, string logLanguage)
@@ -158,7 +160,10 @@ public partial class ChronoJumpWindow
                textview_send_log_message.Buffer = tb;
        }
 
+
+       //-----------------
        //--- send poll ----
+       //-----------------
 
        private void socialNetworkPollInit ()
        {
@@ -213,20 +218,50 @@ public partial class ChronoJumpWindow
                button_social_network_poll_send.Sensitive = false;
                vbox_social_network_poll_answers.Sensitive = false;
 
-               if(success) {
+               preferences.socialNetwork = socialNetwork; //to manage if it has to be sent after ping
+               SqlitePreferences.Update(SqlitePreferences.SocialNetwork, socialNetwork, false);
+
+               if(success)
+               {
+                       image_social_network_poll_send_yes.Show();
+                       image_social_network_poll_send_no.Hide();
+                       LogB.Information(js.ResultMessage);
+
+                       preferences.socialNetworkDatetime = UtilDate.ToFile(DateTime.Now);
+                       SqlitePreferences.Update(SqlitePreferences.SocialNetworkDatetime,
+                                       UtilDate.ToFile(DateTime.Now), false);
+               }
+               /*
+                  if not success (no network) but user clicked on nsnc and send,
+                  then show green button and do not bother user again,
+                  but try to send on next ping that value
+                  */
+               else if(radio_social_network_poll_nsnc.Active)
+               {
                        image_social_network_poll_send_yes.Show();
                        image_social_network_poll_send_no.Hide();
                        LogB.Information(js.ResultMessage);
+
+                       preferences.socialNetworkDatetime = "-1";
+                       SqlitePreferences.Update(SqlitePreferences.SocialNetworkDatetime,
+                                       "-1", false);
                } else {
                        image_social_network_poll_send_yes.Hide();
                        image_social_network_poll_send_no.Show();
                        LogB.Error(js.ResultMessage);
+
+                       preferences.socialNetworkDatetime = "-1";
+                       SqlitePreferences.Update(SqlitePreferences.SocialNetworkDatetime,
+                                       "-1", false);
                }
 
                label_social_network_poll_message.Text = js.ResultMessage;
        }
 
+
+       //------------------------------
        //--- send log and send poll----
+       //------------------------------
 
        private void on_button_open_chronojump_clicked(object o, EventArgs args)
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]