[Pkg-mozext-commits] [wot] 113/226: Implemented local keeper of comments

David Prévot taffit at moszumanska.debian.org
Fri May 1 00:35:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository wot.

commit 9b58cc581e8bb21f4cb97c95b8aec4f5d1007a57
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date:   Thu Aug 22 13:43:08 2013 +0300

    Implemented local keeper of comments
---
 content/api.js                 | 74 ++++++++++++++++++++++++++++++++++++-
 content/ratingwindow.js        | 10 ++++-
 content/rw/keeper.js           | 83 ------------------------------------------
 content/rw/keeper_constants.js | 27 ++++++++++++++
 content/rw/proxies.js          | 10 ++++-
 content/rw/ratingwindow.html   |  2 +-
 6 files changed, 117 insertions(+), 89 deletions(-)

diff --git a/content/api.js b/content/api.js
index b7a8900..5489cd9 100644
--- a/content/api.js
+++ b/content/api.js
@@ -1121,6 +1121,76 @@ var wot_pending =
 	}
 };
 
+var wot_keeper = {
+
+    STATUSES: {
+        LOCAL: 1,       // indicates permanent storing of data locally
+        SUBMITTING: 2   // indicates the saving is temporary until submition is reported succesful
+    },
+
+    /* Comment-specific methods to work with Keeper */
+
+    get_comment: function (target) {
+        // returns comment data stored locally for the specified target. Comment data is {body, timestamp, votes, wcid}
+        var data = wot_keeper.get_by_name(target, "comment");
+        if (data) {
+            return data;
+        } else {
+            return {};
+        }
+    },
+
+    save_comment: function (target, comment_body, wcid, votes, status) {
+//        console.log("keeper.save_comment()");
+
+        var data = {
+            timestamp: Date.now(),
+            target: target,
+            comment: comment_body,
+            wcid: wcid,
+            votes: votes,    // votes as object to be able to restore them to UI
+            status: status || wot_keeper.STATUSES.LOCAL
+        };
+
+        wot_keeper.store_by_name(target, "comment", JSON.stringify(data));
+    },
+
+    remove_comment: function (target) {
+//        console.log("keeper.save_comment()");
+        wot_keeper.remove_by_name(target, "comment");
+    },
+
+    /* Generic methods to work with Keeper */
+
+    get_by_name: function (target, name) {
+        // generic method to get data from local by target and name
+//        console.log("keeper.get_by_name()", target, name);
+
+        try {
+            var json = wot_prefs.getChar(wot_keeper._fullname(target, name)) || null;
+            return json ? JSON.parse(json) : null;
+        } catch (e) {
+            wdump("wot_keeper.get_by_name() Failed with " + e);
+        }
+        return null;
+    },
+
+    store_by_name: function (target, name, data) {
+//        console.log("keeper.store_by_name()", target, name, data);
+        wot_prefs.setChar(wot_keeper._fullname(target, name), data);
+    },
+
+    remove_by_name: function (target, name) {
+        wdump("keeper.remove_by_name()" + target + " " + name);
+        wot_prefs.clear(wot_keeper._fullname(target, name));
+    },
+
+    _fullname: function (target, name) {
+        return "keeper." + name + "." + target;
+    }
+
+};
+
 var wot_api_comments = {
 //    server: "beta.mywot.com",
     server: "dev.mywot.com",
@@ -1474,7 +1544,7 @@ var wot_api_comments = {
 
         switch (error_code) {
             case WOT_COMMENTS.error_codes.SUCCESS:
-//                wot.keeper.remove_by_name(target);  // delete the locally saved comment only on successful submit
+                wot_keeper.remove_comment(target);  // delete the locally saved comment only on successful submit
                 wot_cache.update_comment(target, { status: WOT_QUERY_OK, error_code: error_code });
                 wot_prefs.clear(_this.PENDING_COMMENT_SID + target); // don't try to send again
                 break;
@@ -1508,7 +1578,7 @@ var wot_api_comments = {
         switch (error_code) {
             case WOT_COMMENTS.error_codes.SUCCESS:
                 wot_cache.remove_comment(target);
-//                wot.keeper.remove_comment(target);
+                wot_keeper.remove_comment(target);
                 wot_prefs.clear(_this.PENDING_REMOVAL_SID + target);
                 break;
 
diff --git a/content/ratingwindow.js b/content/ratingwindow.js
index 1562f12..bedf090 100644
--- a/content/ratingwindow.js
+++ b/content/ratingwindow.js
@@ -227,7 +227,7 @@ var wot_rw = {
             cached = wot_rw.get_cached(),
             rw = wot_rw.get_rw_window(),
             rw_wot = wot_rw.get_rw_wot(),
-            local_comment = {}; //TODO: wot.keeper.get_comment(target); // get locally stored comment if exists
+            local_comment = wot_keeper.get_comment(target); // get locally stored comment if exists
 
         rw_wot.ratingwindow.update_comment(cached.cached, local_comment, wot_cache.get_captcha());
     },
@@ -358,6 +358,14 @@ var wot_rw = {
                 case "remove_comment":
                     wot_api_comments.remove(data.target);
                     break;
+
+                case "keeper.remove_comment":
+                    wot_keeper.remove_comment(data.target);
+                    break;
+
+                case "keeper.save_comment":
+                    wot_keeper.save_comment(data.target, data.user_comment, data.user_comment_id, data.votes, data.keeper_status);
+                    break;
             }
 
             return true;
diff --git a/content/rw/keeper.js b/content/rw/keeper.js
deleted file mode 100644
index c90cddb..0000000
--- a/content/rw/keeper.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- comments.js
- Copyright © 2013 -   WOT Services Oy <info at mywot.com>
-
- This file is part of WOT.
-
- WOT is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- WOT is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with WOT. If not, see <http://www.gnu.org/licenses/>.
- */
-
-$.extend(wot, { keeper: {
-
-    STATUSES: {
-        LOCAL: 1,
-        SUBMITTING: 2
-    },
-
-    /* Comment-specific methods to work with Keeper */
-
-    get_comment: function (target) {
-        // returns comment data stored locally for the specified target. Comment data is {body, timestamp, votes, wcid}
-        var data = wot.keeper.get_by_name(target, "comment");
-        if (data) {
-            return data;
-        } else {
-            return {};
-        }
-    },
-
-    save_comment: function (target, comment_body, wcid, votes, status) {
-//        console.log("keeper.save_comment()");
-
-        var data = {
-            timestamp: Date.now(),
-            target: target,
-            comment: comment_body,
-            wcid: wcid,
-            votes: votes,    // votes as object to be able to restore them to UI
-            status: status || wot.keeper.STATUSES.LOCAL
-        };
-
-        this.store_by_name(target, "comment", data);
-    },
-
-    remove_comment: function (target) {
-//        console.log("keeper.save_comment()");
-        this.remove_by_name(target, "comment");
-    },
-
-    /* Generic methods to work with Keeper */
-
-    get_by_name: function (target, name) {
-        // generic method to get data from local by target and name
-//        console.log("keeper.get_by_name()", target, name);
-
-        return wot.prefs.get(wot.keeper._fullname(target, name)) || null;
-    },
-
-    store_by_name: function (target, name, data) {
-//        console.log("keeper.store_by_name()", target, name, data);
-        wot.prefs.set(wot.keeper._fullname(target, name), data);
-    },
-
-    remove_by_name: function (target, name) {
-//        console.log("keeper.remove_by_name()", target, name);
-        wot.prefs.clear(wot.keeper._fullname(target, name));
-    },
-
-    _fullname: function (target, name) {
-        return "keeper:" + name + ":" + target;
-    }
-
-}});
\ No newline at end of file
diff --git a/content/rw/keeper_constants.js b/content/rw/keeper_constants.js
new file mode 100644
index 0000000..d13d77f
--- /dev/null
+++ b/content/rw/keeper_constants.js
@@ -0,0 +1,27 @@
+/*
+ keeper_constants.js
+ Copyright © 2013 -   WOT Services Oy <info at mywot.com>
+
+ This file is part of WOT.
+
+ WOT is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ WOT is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with WOT. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+$.extend(wot, { keeper: {
+
+    STATUSES: {
+        LOCAL: 1,
+        SUBMITTING: 2
+    }
+}});
\ No newline at end of file
diff --git a/content/rw/proxies.js b/content/rw/proxies.js
index 2ffef37..7aca0e4 100644
--- a/content/rw/proxies.js
+++ b/content/rw/proxies.js
@@ -95,11 +95,17 @@ var wot_bg = {    // background page object
 
         keeper: {
             remove_comment: function (target) {
-                // TODO: implement
+                wot_bg.wot.core.moz_send("keeper.remove_comment", { target: target });
             },
 
             save_comment: function (target, user_comment, user_comment_id, votes, keeper_status) {
-
+                wot_bg.wot.core.moz_send("keeper.save_comment", {
+                    target: target,
+                    user_comment: user_comment,
+                    user_comment_id: user_comment_id,
+                    votes: votes,
+                    keeper_status: keeper_status
+                });
             }
         },
 
diff --git a/content/rw/ratingwindow.html b/content/rw/ratingwindow.html
index 5787705..27d72dd 100644
--- a/content/rw/ratingwindow.html
+++ b/content/rw/ratingwindow.html
@@ -27,7 +27,7 @@
     <script type="text/javascript" src="chrome://wot/content/rw/jquery.menu-aim.js"></script>
     <script type="text/javascript" src="chrome://wot/content/rw/proxies.js"></script>
     <script type="text/javascript" src="chrome://wot/content/rw/wot.js"></script>
-    <script type="text/javascript" src="chrome://wot/content/rw/keeper.js"></script>
+    <script type="text/javascript" src="chrome://wot/content/rw/keeper_constants.js"></script>
     <script type="text/javascript" src="chrome://wot/content/injections/ga_configure.js"></script>
     <script type="text/javascript" src="chrome://wot/content/rw/ratingwindow.js"></script>
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/wot.git



More information about the Pkg-mozext-commits mailing list