work on chat
This commit is contained in:
parent
ef6bb8c1e9
commit
7514fd5228
@ -21,6 +21,7 @@ import logger, onionrproofs
|
||||
from onionrutils import stringvalidators, epoch
|
||||
from communicator import peeraction, onlinepeers
|
||||
from coredb import blockmetadb
|
||||
from utils import reconstructhash
|
||||
import onionrblacklist
|
||||
blacklist = onionrblacklist.OnionrBlackList()
|
||||
def lookup_blocks_from_communicator(comm_inst):
|
||||
@ -70,6 +71,7 @@ def lookup_blocks_from_communicator(comm_inst):
|
||||
# if request was a success
|
||||
for i in newBlocks.split('\n'):
|
||||
if stringvalidators.validate_hash(i):
|
||||
i = reconstructhash.reconstruct_hash(i)
|
||||
# if newline seperated string is valid hash
|
||||
if not i in existingBlocks:
|
||||
# if block does not exist on disk and is not already in block queue
|
||||
|
@ -21,17 +21,20 @@ from flask import Response, abort
|
||||
import config
|
||||
from onionrutils import bytesconverter, stringvalidators
|
||||
from coredb import blockmetadb
|
||||
|
||||
from utils import reconstructhash
|
||||
def get_public_block_list(clientAPI, publicAPI, request):
|
||||
# Provide a list of our blocks, with a date offset
|
||||
dateAdjust = request.args.get('date')
|
||||
bList = blockmetadb.get_block_list(dateRec=dateAdjust)
|
||||
share_list = ''
|
||||
if clientAPI.config.get('general.hide_created_blocks', True):
|
||||
for b in publicAPI.hideBlocks:
|
||||
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
|
||||
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):
|
||||
'''data is the block hash in hex'''
|
||||
|
@ -21,13 +21,13 @@ import json
|
||||
from flask import Response, request, redirect, Blueprint, send_from_directory
|
||||
import deadsimplekv as simplekv
|
||||
import filepaths
|
||||
flask_blueprint = Blueprint('esoteric_control', __name__)
|
||||
flask_blueprint = Blueprint('chat_control', __name__)
|
||||
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
|
||||
@flask_blueprint.route('/esoteric/ping')
|
||||
@flask_blueprint.route('/chatapi/ping')
|
||||
def ping():
|
||||
return 'pong!'
|
||||
|
||||
@flask_blueprint.route('/esoteric/send/<peer>', methods=['POST'])
|
||||
@flask_blueprint.route('/chatapi/send/<peer>', methods=['POST'])
|
||||
def send_message(peer):
|
||||
data = request.get_json(force=True)
|
||||
key_store.refresh()
|
||||
@ -39,14 +39,14 @@ def send_message(peer):
|
||||
key_store.flush()
|
||||
return Response('success')
|
||||
|
||||
@flask_blueprint.route('/esoteric/gets/<peer>')
|
||||
@flask_blueprint.route('/chatapi/gets/<peer>')
|
||||
def get_sent(peer):
|
||||
sent = key_store.get('s' + peer)
|
||||
if sent is None:
|
||||
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):
|
||||
data = request.get_json(force=True)
|
||||
key_store.refresh()
|
||||
@ -58,7 +58,7 @@ def add_rec(peer):
|
||||
key_store.flush()
|
||||
return Response('success')
|
||||
|
||||
@flask_blueprint.route('/esoteric/getrec/<peer>')
|
||||
@flask_blueprint.route('/chatapi/getrec/<peer>')
|
||||
def get_messages(peer):
|
||||
key_store.refresh()
|
||||
existing = key_store.get('r' + peer)
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name" : "esoteric",
|
||||
"name" : "chat",
|
||||
"version" : "1.0",
|
||||
"author" : "onionr"
|
||||
}
|
@ -25,7 +25,7 @@ import onionrservices, logger, config
|
||||
from onionrservices import bootstrapservice
|
||||
from onionrutils import stringvalidators, epoch, basicrequests
|
||||
|
||||
plugin_name = 'esoteric'
|
||||
plugin_name = 'chat'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import controlapi, peerserver
|
||||
@ -37,7 +37,7 @@ def exit_with_error(text=''):
|
||||
logger.error(text)
|
||||
sys.exit(1)
|
||||
|
||||
class Esoteric:
|
||||
class Chat:
|
||||
def __init__(self, pluginapi):
|
||||
self.peer = None
|
||||
self.transport = None
|
||||
@ -58,7 +58,7 @@ class Esoteric:
|
||||
message += '\n'
|
||||
except EOFError:
|
||||
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 = ''
|
||||
except KeyboardInterrupt:
|
||||
self.shutdown = True
|
||||
@ -89,6 +89,6 @@ def on_init(api, data = None):
|
||||
'''
|
||||
|
||||
pluginapi = api
|
||||
chat = Esoteric(pluginapi)
|
||||
api.commands.register(['esoteric'], chat.create)
|
||||
chat = chat(pluginapi)
|
||||
api.commands.register(['chat'], chat.create)
|
||||
return
|
@ -23,7 +23,7 @@ from onionrutils import localcommand
|
||||
import deadsimplekv as simplekv, filepaths
|
||||
from flask import Response, request, redirect, Blueprint, abort, g
|
||||
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)
|
||||
storage_dir = identifyhome.identify_home()
|
||||
@ -37,11 +37,11 @@ def request_setup():
|
||||
g.host = host
|
||||
g.peer = key_store.get('dc-' + g.host)
|
||||
|
||||
@direct_blueprint.route('/esoteric/ping')
|
||||
@direct_blueprint.route('/chat/ping')
|
||||
def pingdirect():
|
||||
return 'pong!'
|
||||
|
||||
@direct_blueprint.route('/esoteric/sendto', methods=['POST', 'GET'])
|
||||
@direct_blueprint.route('/chat/sendto', methods=['POST', 'GET'])
|
||||
def sendto():
|
||||
try:
|
||||
msg = request.get_json(force=True)
|
||||
@ -49,9 +49,9 @@ def sendto():
|
||||
msg = ''
|
||||
else:
|
||||
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')
|
||||
|
||||
@direct_blueprint.route('/esoteric/poll')
|
||||
@direct_blueprint.route('/chat/poll')
|
||||
def poll_chat():
|
||||
return Response(localcommand.local_command('/esoteric/gets/%s' % (g.peer,)))
|
||||
return Response(localcommand.local_command('/chat/gets/%s' % (g.peer,)))
|
@ -38,6 +38,7 @@
|
||||
<a class="navbar-item idLink" href="/mail/">Mail</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="/chat/">Chat</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -5,6 +5,11 @@
|
||||
|
||||
.convoListContainer{
|
||||
margin-left: 1%;
|
||||
border-radius: 10px solid black;
|
||||
min-height: 100%;
|
||||
border-radius: 5px;
|
||||
border: 1px solid black;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.chatContent{
|
||||
padding-right: 5%;
|
||||
}
|
@ -78,11 +78,11 @@
|
||||
|
||||
<br>
|
||||
|
||||
<div class="columns">
|
||||
<div class="column has-background-dark has-text-light is-one-fifth content convoListContainer">
|
||||
<div class="columns chatContent">
|
||||
<div class="column has-background-dark has-text-light is-one-fifths content convoListContainer">
|
||||
<ul class='conversationList'></ul>
|
||||
</div>
|
||||
<div class="column chatBox"></div>
|
||||
<div class="column chatBox has-text-dark has-background-dark is-four-fifths">yeet</div>
|
||||
</div>
|
||||
|
||||
<script src='/shared/navbar.js'></script>
|
||||
|
@ -25,4 +25,14 @@ fetch('/friends/list', {
|
||||
friendList[keys[i]] = resp[keys[i]]['name']
|
||||
}
|
||||
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)
|
@ -36,6 +36,7 @@
|
||||
<a class="navbar-item idLink" href="/mail/">Mail</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="/chat/">Chat</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -36,6 +36,7 @@
|
||||
<a class="navbar-item idLink" href="/mail/">Mail</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="/chat/">Chat</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -40,6 +40,7 @@
|
||||
<a class="navbar-item idLink" href="/mail/">Mail</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="/chat/">Chat</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -35,5 +35,4 @@ class KeyManagerTest(unittest.TestCase):
|
||||
with open(filepaths.keys_file, 'r') as keyfile:
|
||||
self.assertNotIn(new_key, keyfile.read())
|
||||
|
||||
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user