diff --git a/onionr/core.py b/onionr/core.py index b135c4f2..396ebca4 100755 --- a/onionr/core.py +++ b/onionr/core.py @@ -467,14 +467,6 @@ class Core: except TypeError: pass - if getPow: - try: - peerList.append(self._crypto.pubKey + '-' + self._crypto.pubKeyPowToken) - except TypeError: - pass - else: - peerList.append(self._crypto.pubKey) - conn.close() return peerList diff --git a/onionr/httpapi/friendsapi/__init__.py b/onionr/httpapi/friendsapi/__init__.py index bca0ad92..80ade1f4 100644 --- a/onionr/httpapi/friendsapi/__init__.py +++ b/onionr/httpapi/friendsapi/__init__.py @@ -17,12 +17,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import core +import core, json from onionrusers import contactmanager from flask import Blueprint, Response, request, abort 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/', methods=['POST']) def add_friend(pubkey): contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1) diff --git a/onionr/onionr.py b/onionr/onionr.py index 13e6e47b..7742f632 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -370,11 +370,8 @@ class Onionr: action = action.lower() if action == 'list': # List out peers marked as our friend - for friend in self.onionrCore.listPeers(randomOrder=False, trust=1): - if friend == self.onionrCore._crypto.pubKey: # do not list our key - continue - friendProfile = onionrusers.OnionrUser(self.onionrCore, friend) - logger.info(friend + ' - ' + friendProfile.getName()) + for friend in onionrusers.OnionrUser.list_friends(self.onionrCore): + logger.info(friend.publicKey + ' - ' + friend.getName()) elif action in ('add', 'remove'): try: friend = sys.argv[3] diff --git a/onionr/onionrusers/onionrusers.py b/onionr/onionrusers/onionrusers.py index 83c0e277..b680acd7 100755 --- a/onionr/onionrusers/onionrusers.py +++ b/onionr/onionrusers/onionrusers.py @@ -201,3 +201,10 @@ class OnionrUser: conn.commit() conn.close() return True + + @classmethod + def list_friends(cls, coreInst): + friendList = [] + for x in coreInst.listPeers(trust=1): + friendList.append(cls(coreInst, x)) + return list(friendList) \ No newline at end of file diff --git a/onionr/static-data/default-plugins/contactmanager/main.py b/onionr/static-data/default-plugins/contactmanager/main.py index 2aaa423a..bdf6ac5b 100644 --- a/onionr/static-data/default-plugins/contactmanager/main.py +++ b/onionr/static-data/default-plugins/contactmanager/main.py @@ -34,6 +34,6 @@ def on_init(api, data = None): # Doing this makes it so that the other functions can access the api object # by simply referencing the variable `pluginapi`. pluginapi = api - ui = OnionrCLIUI(api) + ui = OnionrContactManager(api) #api.commands.register('interactive', ui.start) return diff --git a/onionr/static-data/www/friends/friends.js b/onionr/static-data/www/friends/friends.js index b8c673f3..313e1bb8 100644 --- a/onionr/static-data/www/friends/friends.js +++ b/onionr/static-data/www/friends/friends.js @@ -19,3 +19,25 @@ 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) + } + }) \ No newline at end of file diff --git a/onionr/static-data/www/friends/index.html b/onionr/static-data/www/friends/index.html index 265eb9ed..e45bf6ce 100644 --- a/onionr/static-data/www/friends/index.html +++ b/onionr/static-data/www/friends/index.html @@ -10,11 +10,6 @@ -
-
-

Your node will shutdown. Thank you for using Onionr.

-
-
Onionr Web Control Panel @@ -24,7 +19,8 @@ -
+

Friend List:

+
None Yet :(