work on UI friends manager

master
Kevin Froman 2019-02-21 19:55:13 -06:00
parent 4f39c5792a
commit 30a2ae8d06
7 changed files with 43 additions and 21 deletions

View File

@ -467,14 +467,6 @@ class Core:
except TypeError: except TypeError:
pass pass
if getPow:
try:
peerList.append(self._crypto.pubKey + '-' + self._crypto.pubKeyPowToken)
except TypeError:
pass
else:
peerList.append(self._crypto.pubKey)
conn.close() conn.close()
return peerList return peerList

View File

@ -17,12 +17,20 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
import core import core, json
from onionrusers import contactmanager from onionrusers import contactmanager
from flask import Blueprint, Response, request, abort from flask import Blueprint, Response, request, abort
friends = Blueprint('friends', __name__) friends = Blueprint('friends', __name__)
@friends.route('/friends/list')
def list_friends():
pubkey_list = {}
friend_list = contactmanager.ContactManager.list_friends(core.Core())
for friend in friend_list:
pubkey_list[friend.publicKey] = {'name': friend.get_info('name')}
return json.dumps(pubkey_list)
@friends.route('/friends/add/<pubkey>', methods=['POST']) @friends.route('/friends/add/<pubkey>', methods=['POST'])
def add_friend(pubkey): def add_friend(pubkey):
contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1) contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1)

View File

@ -370,11 +370,8 @@ class Onionr:
action = action.lower() action = action.lower()
if action == 'list': if action == 'list':
# List out peers marked as our friend # List out peers marked as our friend
for friend in self.onionrCore.listPeers(randomOrder=False, trust=1): for friend in onionrusers.OnionrUser.list_friends(self.onionrCore):
if friend == self.onionrCore._crypto.pubKey: # do not list our key logger.info(friend.publicKey + ' - ' + friend.getName())
continue
friendProfile = onionrusers.OnionrUser(self.onionrCore, friend)
logger.info(friend + ' - ' + friendProfile.getName())
elif action in ('add', 'remove'): elif action in ('add', 'remove'):
try: try:
friend = sys.argv[3] friend = sys.argv[3]

View File

@ -201,3 +201,10 @@ class OnionrUser:
conn.commit() conn.commit()
conn.close() conn.close()
return True return True
@classmethod
def list_friends(cls, coreInst):
friendList = []
for x in coreInst.listPeers(trust=1):
friendList.append(cls(coreInst, x))
return list(friendList)

View File

@ -34,6 +34,6 @@ def on_init(api, data = None):
# Doing this makes it so that the other functions can access the api object # Doing this makes it so that the other functions can access the api object
# by simply referencing the variable `pluginapi`. # by simply referencing the variable `pluginapi`.
pluginapi = api pluginapi = api
ui = OnionrCLIUI(api) ui = OnionrContactManager(api)
#api.commands.register('interactive', ui.start) #api.commands.register('interactive', ui.start)
return return

View File

@ -19,3 +19,25 @@
friendListDisplay = document.getElementById('friendList') friendListDisplay = document.getElementById('friendList')
fetch('/friends/list', {
headers: {
"token": webpass
}})
.then((resp) => resp.json()) // Transform the data into json
.then(function(resp) {
var keys = [];
for(var k in resp) keys.push(k);
console.log(keys)
for (var i = 0; i < keys.length; i++){
friendListDisplay.innerText = ''
var peer = keys[i]
var name = resp[keys[i]]['name']
if (name === null || name === ''){
name = 'Anonymous'
}
var entry = document.createElement('div')
entry.style.paddingTop = '8px'
entry.innerText = name + ' - ' + peer
friendListDisplay.appendChild(entry)
}
})

View File

@ -10,11 +10,6 @@
<link rel='stylesheet' href='/friends/style.css'> <link rel='stylesheet' href='/friends/style.css'>
</head> </head>
<body> <body>
<div id="shutdownNotice" class='overlay'>
<div>
<p>Your node will shutdown. Thank you for using Onionr.</p>
</div>
</div>
<div class='content'> <div class='content'>
<img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'> <img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'>
<span class='logoText'>Onionr Web Control Panel</span> <span class='logoText'>Onionr Web Control Panel</span>
@ -24,7 +19,8 @@
<label>Set Alias: <input type='text' name='addAlias' placeholder='what to call them' required></label> <label>Set Alias: <input type='text' name='addAlias' placeholder='what to call them' required></label>
<input type='submit' value='Add Friend'> <input type='submit' value='Add Friend'>
</form> </form>
<div id='friendList'></div> <h2>Friend List:</h2>
<div id='friendList'>None Yet :(</div>
</div> </div>
<script src='/shared/misc.js'></script> <script src='/shared/misc.js'></script>
<script src='/friends/friends.js'></script> <script src='/friends/friends.js'></script>