Skip to content

Commit

Permalink
ZeroChat IRC v0.55
Browse files Browse the repository at this point in the history
The commit of version 0.55. All history before this was not kept.
  • Loading branch information
cgm616 committed Mar 6, 2016
1 parent cd03ba9 commit 84914b0
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 55 deletions.
85 changes: 85 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---------------------------------------------
ZEROCHAT "IRC" v0.55
---------------------------------------------

CONTRIBUTORS
- [email protected] (origin)
- [email protected]

SEEKING NEW CONTRIBUTORS

---------------------------------------------

CURRENT FEATURES
- /me actions
- clickable urls/emails
- bolding your messages to stand out
- highlighting messages that mention you
- dark theme (rushjob)
- empty messages prevented
- visitor count

---------------------------------------------

TODO

GITHUB
- call the repo 'ZeroChatIRC'
- commit the original nofish code as a base from 'ZeroChat-nofish-original.tar.gz'
- then commit the forked code, so comparisons are easy to do, especially if the zerochat base changes
- or convince nofish to make a ZeroChat repo along with the others https://github.com/HelloZeroNet?tab=repositories
- turn this file into a README.md

NOTE
there's a hidden div called '#rhs' that is currently set to 'display: none',
it has a list inside that you can put text into, using these functions:
ZeroChat.prototype.resetDebug() and ZeroChat.prototype.debugMsg(msg)

NEW FEATURES TO MAKE
- command '/r' to quickly reply to the last person who mentioned you
- updating the room name and description should update the title/desc in the header immediately
- press tab to autocomplete @mention names
- visitor count should be number of currently connected peers
- proper user list
- proper notifications when people connect/disconnect
- prevent repeated messages to stop spammers/flooders
- help command (like IRC)
- setting a topic (perhaps only the owner and special users)
- moderated users
- IMs?
- embedded images (scale them down to save space, hover over or click to expand)

LAYOUT/UI
- keep header and textbox at the top of the screen, when scrolling through the chat
- have all of your mentions collated in a mini inbox kind of thing (maybe)

IMPROVE DARKTHEME
- adjust colours for darktheme, I rushed it, all darktheme code is inlined in index.html
- adjust inline markup for highlighted messages and links so they aren't horrible to look at
- fix toggling of this rule: li:nth-child(odd) { background-color: #F9FAFD; }

USER PREFERENCES
- use localStorage for user prefs
- option to flip messages so new messages appear at the bottom and scroll up like in slack or IRC
- timestamp options
- textbox size
- layout
- theme

IMPROVE RESPONSIVENESS
- add new msg to '#messages' div immediately and do NOT reload ALL messages
- allow a cap on how many messages to load
- allow site owner to periodically purge messages

---------------------------------------------

BUGS
- Some messages get stuck at the top or get displayed out of order with 'Just now', this is a general ZeroChat bug

IF YOU GET CONTENT SIGNED FAILED: INVALID PRIVATE KEY
This is how I fix it
- I clone siteA to siteB
- I copy siteB's data into siteA
- I republish siteA
That seems to fix it, but the messages get cut off

44 changes: 26 additions & 18 deletions content.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"address": "186dimSoq8cwswwaBNKptSgC8NikcB6YmK",
"address_index": 23086685,
"address": "1CjR14fofbRJ54oj8A7rAfWpzpLawdP5uc",
"address_index": 53380520,
"cloneable": true,
"cloned_from": "1AvF5TpcaamRNtqvN1cnDEWzNmUtD47Npg",
"description": "",
"cloned_from": "1CjR14fofbRJ54oj8A7rAfWpzpLawdP5uc",
"description": "/me support",
"files": {
"README.txt": {
"sha512": "605e1472f53d11e2b697ed8870b3d88b511ab9a5c2d207b424e4b7a16dd028fb",
"size": 2928
},
"ZeroChat-nofish-original.tar.gz": {
"sha512": "7bbc994b9722a6080edde6fc4d1ff9cd250d2fe81ca7a66d69cc1910c1120099",
"size": 7758
},
"data-default/users/content-default.json": {
"sha512": "e1f8d79e306fd6c8c49e0f41f546456ab1952276445d3733909c2883df6f8b0d",
"size": 620
Expand All @@ -14,16 +22,16 @@
"size": 485
},
"index.html": {
"sha512": "fb84d387ed80856cd40bb2acae8562b1a0a8f4691974fb6985ae18ba6a418363",
"size": 998
"sha512": "57d67110acbd069f34f9ae9dad75123981afef41be9dce1f1e03367344233dc2",
"size": 87372
},
"js/ZeroChat.coffee": {
"sha512": "2120b464b303c040316fe7bd7f7c480c2d1447c67299feae669b9f29c75e6c3a",
"size": 4237
"sha512": "75b5d46c7f2bcc3369fd1debbc558a0b4fbca45183dc95b097dc11d9f802e175",
"size": 8123
},
"js/all.js": {
"sha512": "9e7080fc22b1a1ab1a1b715e1a842c3566b8705b950947a4fd74fe79b30558e4",
"size": 10654
"sha512": "0bfa36e0b3a49c064a7d13e2d0095a9fc51436c9409d5c840968e5ee6946f830",
"size": 14212
},
"js/lib/ZeroFrame.coffee": {
"sha512": "96a11e88429e2fa26c47f5d24bf52d030d506f1dfecb2a4e2c5e034cc5d07e31",
Expand All @@ -34,8 +42,8 @@
"size": 248
},
"js/utils/Time.coffee": {
"sha512": "9cf900d99e200d70da56673d643f17f73d524912ecd6c518d4eb1bbc0c372ec0",
"size": 861
"sha512": "9fbb498bb32989018996ac0aaef14885fd8f99f406d197c7b0d8906cef078bc0",
"size": 857
}
},
"ignore": "data/.*",
Expand All @@ -46,16 +54,16 @@
}
},
"inner_path": "content.json",
"modified": 1457284118.282836,
"modified": 1457289646.007745,
"sign": [
108499898069202908412971738329219825445205409778571380321715357580251221529257,
61644468984217288409879143680469733130752579075554880646113916918848958088089
38286886242649303530162726922351568138652059797174958112907154547210874300629,
101199270834046316783965091098571702210002306603468999377279551256578801339919
],
"signers_sign": "G4bSRWTp6R9RBhkBpeoYlx3gDUCv0CFVG5tVkfcMp6hb27G66ew+8UY2xMC0sXVrz1aF/SzLD6Pwk96d3VF77bM=",
"signers_sign": "HJLG8O0mDAYMH4c5SeCvGf7CYBCydDVezM21vnTWZlkn5MWr8jc78rIj6xWcRsoNywK1O2RetGE2YNWbVMPefYA=",
"signs": {
"186dimSoq8cwswwaBNKptSgC8NikcB6YmK": "HOwDkPnqucDXnHNnYn3G7W2UraPrzQHAFJeVHFZYLptN16QgVsEnsFpB93mAfgTI+t4ESkMFzjkiHen2qqo7p5k="
"1CjR14fofbRJ54oj8A7rAfWpzpLawdP5uc": "HCoPn4s6aDEfxGCwuJDVHEBoUJPeudlg7dzOZQm8MptIg3XjxW00rKp29T5uVJtNmUfjn8FqFc2blwY6k1GjmVo="
},
"signs_required": 1,
"title": "myZeroChat tutorial result",
"title": "mymyZeroChatIRC /me forked",
"zeronet_version": "0.3.6"
}
6 changes: 3 additions & 3 deletions data/users/content.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"address": "186dimSoq8cwswwaBNKptSgC8NikcB6YmK",
"address": "1CjR14fofbRJ54oj8A7rAfWpzpLawdP5uc",
"files": {},
"ignore": ".*",
"inner_path": "data/users/content.json",
"modified": 1457284118.244821,
"modified": 1457022297.831354,
"signs": {
"186dimSoq8cwswwaBNKptSgC8NikcB6YmK": "HDi2Kr9N1lIxDbtWtxm7yP4Gxy/SB0gbtqc9ftHRkuRgK/DrYEpwYFKy8g/NiJUqcHUfUfS8YJQeJYHAUAeZSb0="
"1CjR14fofbRJ54oj8A7rAfWpzpLawdP5uc": "HNZNVrNHemyyoQRu3Wtm9nMsJL4sR2LDTe6trPi/l1Y946j+5uYQPPGcKvY4knz/Aj5NvUXs1hZLvrOjWoHszWA="
},
"user_contents": {
"cert_signers": {
Expand Down
Binary file modified data/zerochat.db
Binary file not shown.
84 changes: 76 additions & 8 deletions index.html

Large diffs are not rendered by default.

94 changes: 89 additions & 5 deletions js/ZeroChat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ class ZeroChat extends ZeroFrame
if message.params.event[0] == "file_done"
@loadMessages()

resetDebug: ->
document.getElementById("list").innerHTML = ""

debugMsg: (msg) ->
newElement = document.createElement('li')
newElement.innerHTML = msg
document.getElementById("list").appendChild(newElement)

resetInputField: =>
document.getElementById("message").disabled = false
document.getElementById("message").value = "" # Reset the message input
document.getElementById("message").focus()

sendMessage: =>
if not Page.site_info.cert_user_id # No account selected, display error
Expand All @@ -36,6 +48,12 @@ class ZeroChat extends ZeroFrame
else # Not exits yet, use default data
data = { "message": [] }

# // EMPTY MESSAGES
msg = document.getElementById("message").value
if msg == "" or msg == "/me" or msg == "/me "
@debugMsg('empty message')
@resetInputField()
return false
# Add the message to data
data.message.push({
"body": document.getElementById("message").value,
Expand All @@ -50,9 +68,7 @@ class ZeroChat extends ZeroFrame
if res == "ok"
# Publish the file to other users
@cmd "sitePublish", {"inner_path": inner_path}, (res) =>
document.getElementById("message").disabled = false
document.getElementById("message").value = "" # Reset the message input
document.getElementById("message").focus()
@resetInputField()
@loadMessages()
else
@cmd "wrapperNotification", ["error", "File write error: #{res}"]
Expand All @@ -61,6 +77,36 @@ class ZeroChat extends ZeroFrame
return false


replaceURLs: (body) ->
# // REGEXES
replacePattern0 = /(http:\/\/127.0.0.1:43110\/)/gi
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim
replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim
replacePattern4 = /0net:\/\/([-a-zA-Z0-9+&.,:+_\/=?]*)/g
replacePattern5 = /(([a-zA-Z0-9\-\_\.])+)\/\/0mail/gim;

# // url rewriting 127.0.0.1:43110 to 0net:// so other replacements don't break
replacedText = body.replace(replacePattern0, '0net://')
replacedText = replacedText.replace('@zeroid.bit', '//0mail')

# // URLs starting with http://, https://, or ftp://
replacedText = replacedText.replace(replacePattern1, '<a href="$1" target="_blank" style="color: red; font-weight: bold;">$1</a>');

# // URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank" style="color: red; font-weight: bold;">$2</a>')

# // Change email addresses to mailto:: links.
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1" style="color: red; font-weight: bold;">$1</a>')

# // replace 0net:// URL href back to http://127.0.0.1:43110
replacedText = replacedText.replace(replacePattern4, '<a href="http://127.0.0.1:43110/$1" target="_blank" style="color: green; font-weight: bold;">0net://$1</a>')

# // rewrite link href and replace //0mail with @zeroid.bit
replacedText = replacedText.replace(replacePattern5, '<a href="http://127.0.0.1:43110/Mail.ZeroNetwork.bit/?to=$1" target="_blank" style="color: green; font-weight: bold;">[email protected]</a>')

return replacedText

loadMessages: ->
query = """
SELECT message.*, keyvalue.value AS cert_user_id FROM message
Expand All @@ -74,10 +120,45 @@ class ZeroChat extends ZeroFrame
@cmd "dbQuery", [query], (messages) =>
document.getElementById("messages").innerHTML = "" # Always start with empty messages
message_lines = []

# // remove later
@resetDebug()

for message in messages
body = message.body.replace(/</g, "&lt;").replace(/>/g, "&gt;") # Escape html tags in body
added = new Date(message.date_added)
message_lines.push "<li><small title='#{added}'>#{Time.since(message.date_added/1000)}</small> <b style='color: #{Text.toColor(message.cert_user_id)}'>#{message.cert_user_id.replace('@zeroid.bit', '')}</b>: #{body}</li>"

# // OUR ADDITIONS
time = Time.since(message.date_added / 1000)
userid = message.cert_user_id
useridcolor = Text.toColor(userid)
username = message.cert_user_id.replace('@zeroid.bit', '')
msgseparator = ":"

# // REPLACE URLS
body = @replaceURLs(body)

# // REPLACE IRC
if body.substr(0,3) == "/me"
action = body.replace("/me","")
username = username+' '+action
body = ''
msgseparator = ''

# // STYLE OUR MESSAGES AND MENTIONS
prestyle=""
poststyle=""
# our messages
if userid == Page.site_info.cert_user_id
prestyle = '<span style="color:black; font-weight:bold;">'
poststyle = '</span>'
# our mentions
if Page.site_info.cert_user_id and body.indexOf(Page.site_info.cert_user_id.replace('@zeroid.bit', '')) > -1
prestyle = '<span style="color:blue; font-weight:bold;">'
poststyle = '</span>'
body = prestyle + body + poststyle

message_lines.push "<li><small title='#{added}'>#{time}</small> <b style='color: #{useridcolor}'>#{username}</b>#{msgseparator} #{body}</li>"
message_lines.reverse()
document.getElementById("messages").innerHTML = message_lines.join("\n")

Expand All @@ -90,11 +171,14 @@ class ZeroChat extends ZeroFrame
# Wrapper websocket connection ready
onOpenWebsocket: (e) =>
@cmd "siteInfo", {}, (site_info) =>
document.getElementById("bigTitle").innerHTML = site_info.content.title + ' - ' + site_info.content.description
document.getElementById("peerCount").innerHTML = site_info.peers + ' Visitors'

# Update currently selected username
if site_info.cert_user_id
document.getElementById("select_user").innerHTML = site_info.cert_user_id
@site_info = site_info # Save site info data to allow access it later
@loadMessages()


window.Page = new ZeroChat()
window.Page = new ZeroChat()
Loading

0 comments on commit 84914b0

Please sign in to comment.