work on UI friends manager
parent
4f39c5792a
commit
30a2ae8d06
|
@ -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
|
||||
|
|
|
@ -17,12 +17,20 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
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/<pubkey>', methods=['POST'])
|
||||
def add_friend(pubkey):
|
||||
contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
|
@ -10,11 +10,6 @@
|
|||
<link rel='stylesheet' href='/friends/style.css'>
|
||||
</head>
|
||||
<body>
|
||||
<div id="shutdownNotice" class='overlay'>
|
||||
<div>
|
||||
<p>Your node will shutdown. Thank you for using Onionr.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class='content'>
|
||||
<img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'>
|
||||
<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>
|
||||
<input type='submit' value='Add Friend'>
|
||||
</form>
|
||||
<div id='friendList'></div>
|
||||
<h2>Friend List:</h2>
|
||||
<div id='friendList'>None Yet :(</div>
|
||||
</div>
|
||||
<script src='/shared/misc.js'></script>
|
||||
<script src='/friends/friends.js'></script>
|
||||
|
|
Loading…
Reference in New Issue