? Editing: Post:21.body Save Delete Cancel
Content changed Sign & Publish new content

BinChan's ZeroNotes

Messy Notes about using ZeroNet and other things
All code published here are under CC-BY-SA licence, if not compatible, then MIT license X)

Follow in NewsfeedFollowing

TOC by date
TOC by tag
View in light theme

Latest comments:

Add new post

Title

21 hours ago · 2 min read ·
3 comments

tag:
Body
Read more

Not found

ZeroMessage: ZeroChat as a Widget for Any Zite!

on Jul 10, 2017 · 3 min read
tag: widget zeronet

I modify ZeroChat from the official tutorial and transform it info a widget that can be added to any (not quite sure though :P) zite.

Bildschirmfoto_2017-07-10_09-05-28.png (24x24)

Check my Jekyll zite for the example and code.

To use it, you need to copy zeromessage folder and dbschema.json to the root folder of your zite, if your zite has one dbschema.json, you need to merge the table inside (need to carefully compare them and add the necessary part).
Respectively, if your zite has no ./data/users/content.json, then you need to follow the official tutorial and create one, also modify ./content.json:


To allow other users to post on our site we have to define the rules of the third-party content.
Create a data/users/content.json file in your site’s directory:

{
  "files": {},
  "ignore": ".*",
  "modified": 0.0,
  "signs": {},
  "user_contents": {
    "cert_signers": {
      "zeroid.bit": [ "1iD5ZQJMNXu43w1qLB8sfdHVKppVMduGz" ]
    },
    "permission_rules": {
      ".*": {
        "files_allowed": "data.json",
        "max_size": 10000
      },
      "bitmsg/.*@zeroid.bit": { "max_size": 15000 }
    },
    "permissions": {
      "bad@zeroid.bit": false,
      "nofish@zeroid.bit": { "max_size": 100000 }
    }
  }
}

After we saved this file we also have to modify our site’s root content.json to ignore everything in this directory on signing and load the file containing the rules:

  ...
    "ignore": "data/.*",
    "includes": {
        "data/users/content.json": {
            "signers": [],
            "signers_required": 1
        }
    },
  ...

Finally, you need to copy this block of code to ./index.html, the proper position is in the bottom, before </body>:

 <script type="text/javascript" src="zeromessage/all.js"> </script>
 <div id="zeromessage" class="zeromessage"></div>

If you perfer a white theme, you can remove ./zeromessage/all.css and rename ./zeromessage/white-all.css to ./zeromessage/all.css.

Don't forget to sign and publish your zite from the config panel (drag the "0" button to left to open it). That's all!

PS0: It's still a little buggy in ZeroBlog, afaik ZeroFrame calling of ZeroMessage is in conflict with ZeroBlog, have no solution yet. If you still want to try it in your blog, you can use the dbschema.json in my ZeroBlog instead.

PS1: for some zite that already has dsschema.json, there's another necessary step (for ZeroUp it is not needed).
Use ZeroBlog as example, you need to find the initial user data table in ./js/all.js or any ./data/users/.../data.json (I can easily find it by searching JSON.parse):

          if (data) {
            data = JSON.parse(data);
          } else {
            data = {
              "next_comment_id": 1,
              "comment": [],
              "comment_vote": {},
              "topic_vote": {}
            };
          }

Then add the table to ./zeromessage/all.js:

            if (data)  // Parse current data file
                data = JSON.parse(data)
            if (data == null)
-              data = {}
+              data = {
+                "next_comment_id": 1,
+                "comment": [],
+                "comment_vote": {},
+                "topic_vote": {}
+              }
            if (data.zm_message == null)  // Not exists yet, add message key
                data.zm_message = []

Hope it works for you ;)

PS2: Thanks to the source code from ZeroNet Dev Center. Now ZeroMessage has follow button. Also I figure that ZeroHello feed-follow feature is by reading "follow" keyword and sqlite command from /path/to/zeronet/data/users.json. So even a zite has no follow function, you can create one for yourself, for example, if you just want to follow username mention in ZeroMessage, you can add something like this under the "follow" keyword (check other zite in users.json for example, also remember to backup users.json file first before directly edit it):

          "Zm-message mention": [
            "SELECT 'mention' AS type, 'ZeroMessage' AS title, '' AS url, date_added, cert_user_id || ': ' || body AS body FROM zm_message LEFT JOIN json USING (json_id) WHERE body LIKE '%@binchan%'", 
            [
              ""
            ]

Need to restart ZeroNet server to take effect.

16 Comments:

user_name1 day ago
Reply
Body
pilothon Oct 05, 2018
Reply

piloth: I followed this exactly i believe and I get nothing. I'm bummed because I was going to use this for a zite I am working on.
I created the /data/users/content.json file and copied it exactly from what you have here. I modified the root content.json file like you have here. And i copied the zeromessage folder and dbschema.json from this blog. I also put the line of code in the index file
I'm at a loss. I see nothing. I used an empty zite for trying to test setting this up, but I am having no luck

Not in any way saying your methods here are at fault. It's most likely me lol

pilothon Oct 03, 2018
Reply

I followed this exactly i believe and I get nothing. I'm bummed because I was going to use this for a zite I am working on.

I created the /data/users/content.json file and copied it exactly from what you have here. I modified the root content.json file like you have here. And i copied the zeromessage folder and dbschema.json from this blog. I also put the line of code in the index file

I'm at a loss. I see nothing. I used an empty zite for trying to test setting this up, but I am having no luck

caryosceluson Apr 03, 2018
Reply

While i was setting this up (on my engine test page), at some point i got everything working, except actual message displaying (posting worked). For some reason they turned on (immediately!) after i clicked on "save site settings" in right panel (even though reload/build db and signing didn't help). Thought this might be useful for somebody.

gitcenteron Nov 13, 2017
Reply

binchan2: I find that if I add follow to dbschema.json, when a user adds the zite, s/he will auto-follow the related post. I think that's what it's for.

Um... maybe. Though I often do both feedListFollow and add follow to dbschema.json.

binchan2on Nov 13, 2017
Reply

gitcenter: Note that follow from dbschema.json is only used when searching.

I find that if I add follow to dbschema.json, when a user adds the zite, s/he will auto-follow the related post. I think that's what it's for.

gitcenteron Nov 12, 2017
Reply

Note that follow from dbschema.json is only used when searching. And when feed is shown, only feedListFollow command shows.

binchan2on Sep 08, 2017
Reply

rollout: Trying to deploy it on my 0blog but...F12 console told me:
Do you know how to deploy it on 0blog easily?

Currectly it's suitable to deploy to a site without ZeroFrame (a static site, a site that is migrated to ZeroNet, etc), the one on this blog is heavily tweaked and buggy, so not recommended.
If you still want to try it, you can use the zeromessage (folder) on this blog instead, also use this block of code for index.html

<div class="zeromessage", id="zeromessage">
  <input id="zm-trigger" class="zm-trigger" type="checkbox" onclick='zmWhenOpen()'></input>
  <div class="trigger">
    <label class="titlebar" for="zm-trigger">
      <span class="zm-title-text">Show Messages</span>
      <span class="zm-title-text2">ZeroMessage</span>
      <span class="buttons"><span id="zm-minimize">×</span></span>
    </label>
    <div class="widget-wrapper">
      <a href="#Select+user" id="zm-select-user" onclick='return page.selectUser()'>Select user</a>
      <div class="input-wrapper">
        <textarea type="text" id="zm-message" onkeypress="if (event.keyCode == 13 && event.ctrlKey) page.sendMessage()"></textarea>
        <input type="button" id="zm-send" value="Send" onclick="return page.sendMessage()"/>
      </div>
      <div class="message-wrapper">
        <ul id="zm-messages">
          <li>Welcome to ZeroMessage!</li>
        </ul>
      </div>
      <script type="text/javascript" src="zeromessage/all.js"> </script>
      <link rel="stylesheet" href="zeromessage/all.css"/>
    </div>
  </div>
</div>
rollouton Sep 08, 2017
Reply

Trying to deploy it on my 0blog but...
F12 console told me:

Uncaught TypeError: Cannot set property 'innerHTML' of null
    at ZeroMessage.onRequest (all.js:124)
    at ZeroMessage.onMessage (all.js:49)
    at window.addEventListener.e (all.js:26)

Uncaught TypeError: Cannot read property 'addres' of undefined
    at Object.<anonymous> (all.js?lang=zh:2740)
    at ZeroBlog.ZeroFrame.onMessage (all.js?lang=zh:2003)
    at all.js?lang=zh:1967

Uncaught TypeError: Cannot read property 'cert_user_id' of undefined
    at ZeroMessage.sendMessage (all.js:139)
    at HTMLInputElement.onclick (?Home&wrapper_nonce=a0415b0…:195)

Do you know how to deploy it on 0blog easily?

binchan2on Sep 08, 2017
Reply

nekox: Thanks a lot

Nice to know that someone is interested in it!

nekoxon Sep 08, 2017
Reply

Thanks a lot

binchan2on Jul 17, 2017
Reply

glightstar: Wow!Good job on this, it looks quite good @binchan2 :)

Thx X)

glightstaron Jul 17, 2017
Reply

Wow!
Good job on this, it looks quite good @binchan2 :)

binchan2on Jul 12, 2017
Reply

sexydance: ZeroMessage is not work?why

Looks like the main class instance page = new ZeroMessage(); in ./zeromessage/all.js is in conflict with ZeroBlog, causing many bugs XD

binchan2on Jul 12, 2017
Reply

sexydance: ZeroMessage is not work?why

I can view your messages in ZeroMessage here ;)

sexydanceon Jul 12, 2017
Reply

sexydance: ZeroMessage is not work?why

but in the BinChan's Gallery - ZeroNet is working.

sexydanceon Jul 12, 2017
Reply

ZeroMessage is not work?why

Select user
  • Welcome to ZeroMessage!
This page is a snapshot of ZeroNet. Start your own ZeroNet for complete experience. Learn More