work on chat

master
Kevin Froman 2019-07-27 16:56:06 -05:00
parent ef6bb8c1e9
commit 7514fd5228
14 changed files with 50 additions and 27 deletions

View File

@ -21,6 +21,7 @@ import logger, onionrproofs
from onionrutils import stringvalidators, epoch from onionrutils import stringvalidators, epoch
from communicator import peeraction, onlinepeers from communicator import peeraction, onlinepeers
from coredb import blockmetadb from coredb import blockmetadb
from utils import reconstructhash
import onionrblacklist import onionrblacklist
blacklist = onionrblacklist.OnionrBlackList() blacklist = onionrblacklist.OnionrBlackList()
def lookup_blocks_from_communicator(comm_inst): def lookup_blocks_from_communicator(comm_inst):
@ -70,6 +71,7 @@ def lookup_blocks_from_communicator(comm_inst):
# if request was a success # if request was a success
for i in newBlocks.split('\n'): for i in newBlocks.split('\n'):
if stringvalidators.validate_hash(i): if stringvalidators.validate_hash(i):
i = reconstructhash.reconstruct_hash(i)
# if newline seperated string is valid hash # if newline seperated string is valid hash
if not i in existingBlocks: if not i in existingBlocks:
# if block does not exist on disk and is not already in block queue # if block does not exist on disk and is not already in block queue

View File

@ -21,17 +21,20 @@ from flask import Response, abort
import config import config
from onionrutils import bytesconverter, stringvalidators from onionrutils import bytesconverter, stringvalidators
from coredb import blockmetadb from coredb import blockmetadb
from utils import reconstructhash
def get_public_block_list(clientAPI, publicAPI, request): def get_public_block_list(clientAPI, publicAPI, request):
# Provide a list of our blocks, with a date offset # Provide a list of our blocks, with a date offset
dateAdjust = request.args.get('date') dateAdjust = request.args.get('date')
bList = blockmetadb.get_block_list(dateRec=dateAdjust) bList = blockmetadb.get_block_list(dateRec=dateAdjust)
share_list = ''
if clientAPI.config.get('general.hide_created_blocks', True): if clientAPI.config.get('general.hide_created_blocks', True):
for b in publicAPI.hideBlocks: for b in publicAPI.hideBlocks:
if b in bList: if b in bList:
# Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block
bList.remove(b) bList.remove(b)
return Response('\n'.join(bList)) for b in bList:
share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),)
return Response(share_list)
def get_block_data(clientAPI, publicAPI, data): def get_block_data(clientAPI, publicAPI, data):
'''data is the block hash in hex''' '''data is the block hash in hex'''

View File

@ -21,13 +21,13 @@ import json
from flask import Response, request, redirect, Blueprint, send_from_directory from flask import Response, request, redirect, Blueprint, send_from_directory
import deadsimplekv as simplekv import deadsimplekv as simplekv
import filepaths import filepaths
flask_blueprint = Blueprint('esoteric_control', __name__) flask_blueprint = Blueprint('chat_control', __name__)
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5) key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
@flask_blueprint.route('/esoteric/ping') @flask_blueprint.route('/chatapi/ping')
def ping(): def ping():
return 'pong!' return 'pong!'
@flask_blueprint.route('/esoteric/send/<peer>', methods=['POST']) @flask_blueprint.route('/chatapi/send/<peer>', methods=['POST'])
def send_message(peer): def send_message(peer):
data = request.get_json(force=True) data = request.get_json(force=True)
key_store.refresh() key_store.refresh()
@ -39,14 +39,14 @@ def send_message(peer):
key_store.flush() key_store.flush()
return Response('success') return Response('success')
@flask_blueprint.route('/esoteric/gets/<peer>') @flask_blueprint.route('/chatapi/gets/<peer>')
def get_sent(peer): def get_sent(peer):
sent = key_store.get('s' + peer) sent = key_store.get('s' + peer)
if sent is None: if sent is None:
sent = [] sent = []
return Response(json.dumps(sent)) return Response(json.dumps(sent))
@flask_blueprint.route('/esoteric/addrec/<peer>', methods=['POST']) @flask_blueprint.route('/chatapi/addrec/<peer>', methods=['POST'])
def add_rec(peer): def add_rec(peer):
data = request.get_json(force=True) data = request.get_json(force=True)
key_store.refresh() key_store.refresh()
@ -58,7 +58,7 @@ def add_rec(peer):
key_store.flush() key_store.flush()
return Response('success') return Response('success')
@flask_blueprint.route('/esoteric/getrec/<peer>') @flask_blueprint.route('/chatapi/getrec/<peer>')
def get_messages(peer): def get_messages(peer):
key_store.refresh() key_store.refresh()
existing = key_store.get('r' + peer) existing = key_store.get('r' + peer)

View File

@ -1,5 +1,5 @@
{ {
"name" : "esoteric", "name" : "chat",
"version" : "1.0", "version" : "1.0",
"author" : "onionr" "author" : "onionr"
} }

View File

@ -25,7 +25,7 @@ import onionrservices, logger, config
from onionrservices import bootstrapservice from onionrservices import bootstrapservice
from onionrutils import stringvalidators, epoch, basicrequests from onionrutils import stringvalidators, epoch, basicrequests
plugin_name = 'esoteric' plugin_name = 'chat'
PLUGIN_VERSION = '0.0.0' PLUGIN_VERSION = '0.0.0'
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import controlapi, peerserver import controlapi, peerserver
@ -37,7 +37,7 @@ def exit_with_error(text=''):
logger.error(text) logger.error(text)
sys.exit(1) sys.exit(1)
class Esoteric: class Chat:
def __init__(self, pluginapi): def __init__(self, pluginapi):
self.peer = None self.peer = None
self.transport = None self.transport = None
@ -58,7 +58,7 @@ class Esoteric:
message += '\n' message += '\n'
except EOFError: except EOFError:
message = json.dumps({'m': message, 't': epoch.get_epoch()}) message = json.dumps({'m': message, 't': epoch.get_epoch()})
print(basicrequests.do_post_request('http://%s/esoteric/sendto' % (self.transport,), port=self.socks, data=message)) print(basicrequests.do_post_request('http://%s/chat/sendto' % (self.transport,), port=self.socks, data=message))
message = '' message = ''
except KeyboardInterrupt: except KeyboardInterrupt:
self.shutdown = True self.shutdown = True
@ -89,6 +89,6 @@ def on_init(api, data = None):
''' '''
pluginapi = api pluginapi = api
chat = Esoteric(pluginapi) chat = chat(pluginapi)
api.commands.register(['esoteric'], chat.create) api.commands.register(['chat'], chat.create)
return return

View File

@ -23,7 +23,7 @@ from onionrutils import localcommand
import deadsimplekv as simplekv, filepaths import deadsimplekv as simplekv, filepaths
from flask import Response, request, redirect, Blueprint, abort, g from flask import Response, request, redirect, Blueprint, abort, g
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
direct_blueprint = Blueprint('esoteric', __name__) direct_blueprint = Blueprint('chat', __name__)
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5) key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
storage_dir = identifyhome.identify_home() storage_dir = identifyhome.identify_home()
@ -37,11 +37,11 @@ def request_setup():
g.host = host g.host = host
g.peer = key_store.get('dc-' + g.host) g.peer = key_store.get('dc-' + g.host)
@direct_blueprint.route('/esoteric/ping') @direct_blueprint.route('/chat/ping')
def pingdirect(): def pingdirect():
return 'pong!' return 'pong!'
@direct_blueprint.route('/esoteric/sendto', methods=['POST', 'GET']) @direct_blueprint.route('/chat/sendto', methods=['POST', 'GET'])
def sendto(): def sendto():
try: try:
msg = request.get_json(force=True) msg = request.get_json(force=True)
@ -49,9 +49,9 @@ def sendto():
msg = '' msg = ''
else: else:
msg = json.dumps(msg) msg = json.dumps(msg)
localcommand.local_command('/esoteric/addrec/%s' % (g.peer,), post=True, postData=msg) localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg)
return Response('success') return Response('success')
@direct_blueprint.route('/esoteric/poll') @direct_blueprint.route('/chat/poll')
def poll_chat(): def poll_chat():
return Response(localcommand.local_command('/esoteric/gets/%s' % (g.peer,))) return Response(localcommand.local_command('/chat/gets/%s' % (g.peer,)))

View File

@ -38,6 +38,7 @@
<a class="navbar-item idLink" href="/mail/">Mail</a> <a class="navbar-item idLink" href="/mail/">Mail</a>
<a class="navbar-item idLink" href="/friends/">Friends</a> <a class="navbar-item idLink" href="/friends/">Friends</a>
<a class="navbar-item idLink" href="/board/">Circles</a> <a class="navbar-item idLink" href="/board/">Circles</a>
<a class="navbar-item idLink" href="/chat/">Chat</a>
</div> </div>
</div> </div>
</nav> </nav>

View File

@ -5,6 +5,11 @@
.convoListContainer{ .convoListContainer{
margin-left: 1%; margin-left: 1%;
border-radius: 10px solid black; border-radius: 5px;
min-height: 100%; border: 1px solid black;
overflow-y: scroll;
}
.chatContent{
padding-right: 5%;
} }

View File

@ -78,11 +78,11 @@
<br> <br>
<div class="columns"> <div class="columns chatContent">
<div class="column has-background-dark has-text-light is-one-fifth content convoListContainer"> <div class="column has-background-dark has-text-light is-one-fifths content convoListContainer">
<ul class='conversationList'></ul> <ul class='conversationList'></ul>
</div> </div>
<div class="column chatBox"></div> <div class="column chatBox has-text-dark has-background-dark is-four-fifths">yeet</div>
</div> </div>
<script src='/shared/navbar.js'></script> <script src='/shared/navbar.js'></script>

View File

@ -26,3 +26,13 @@ fetch('/friends/list', {
} }
createConvoList() createConvoList()
}) })
// Correct conversation list height
function correctConvoList(){
margin = 50
els = document.getElementsByClassName('convoListContainer')
for (x = 0; x < els.length; x++){
els[x].style.height = window.innerHeight - (2 * margin) + 'px'
}
}
setInterval(function(){correctConvoList()}, 30)

View File

@ -36,6 +36,7 @@
<a class="navbar-item idLink" href="/mail/">Mail</a> <a class="navbar-item idLink" href="/mail/">Mail</a>
<a class="navbar-item idLink" href="/friends/">Friends</a> <a class="navbar-item idLink" href="/friends/">Friends</a>
<a class="navbar-item idLink" href="/board/">Circles</a> <a class="navbar-item idLink" href="/board/">Circles</a>
<a class="navbar-item idLink" href="/chat/">Chat</a>
</div> </div>
</div> </div>
</nav> </nav>

View File

@ -36,6 +36,7 @@
<a class="navbar-item idLink" href="/mail/">Mail</a> <a class="navbar-item idLink" href="/mail/">Mail</a>
<a class="navbar-item idLink" href="/friends/">Friends</a> <a class="navbar-item idLink" href="/friends/">Friends</a>
<a class="navbar-item idLink" href="/board/">Circles</a> <a class="navbar-item idLink" href="/board/">Circles</a>
<a class="navbar-item idLink" href="/chat/">Chat</a>
</div> </div>
</div> </div>
</nav> </nav>

View File

@ -40,6 +40,7 @@
<a class="navbar-item idLink" href="/mail/">Mail</a> <a class="navbar-item idLink" href="/mail/">Mail</a>
<a class="navbar-item idLink" href="/friends/">Friends</a> <a class="navbar-item idLink" href="/friends/">Friends</a>
<a class="navbar-item idLink" href="/board/">Circles</a> <a class="navbar-item idLink" href="/board/">Circles</a>
<a class="navbar-item idLink" href="/chat/">Chat</a>
</div> </div>
</div> </div>
</nav> </nav>

View File

@ -35,5 +35,4 @@ class KeyManagerTest(unittest.TestCase):
with open(filepaths.keys_file, 'r') as keyfile: with open(filepaths.keys_file, 'r') as keyfile:
self.assertNotIn(new_key, keyfile.read()) self.assertNotIn(new_key, keyfile.read())
unittest.main() unittest.main()