Replaced appropriate queries in api
This commit is contained in:
parent
7dd75eec21
commit
9367948387
49
src/api.py
49
src/api.py
|
@ -73,8 +73,8 @@ from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
|
import helper_db
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_sent
|
|
||||||
import network.stats
|
import network.stats
|
||||||
import proofofwork
|
import proofofwork
|
||||||
import queues
|
import queues
|
||||||
|
@ -587,14 +587,9 @@ class BMRPCDispatcher(object):
|
||||||
label = self._decode(label, "base64")
|
label = self._decode(label, "base64")
|
||||||
address = addBMIfNotPresent(address)
|
address = addBMIfNotPresent(address)
|
||||||
self._verifyAddress(address)
|
self._verifyAddress(address)
|
||||||
# TODO: add unique together constraint in the table
|
if not helper_db.put_addressbook(label, address):
|
||||||
queryreturn = sqlQuery(
|
|
||||||
"SELECT address FROM addressbook WHERE address=?", address)
|
|
||||||
if queryreturn != []:
|
|
||||||
raise APIError(
|
raise APIError(
|
||||||
16, 'You already have this address in your address book.')
|
16, 'You already have this address in your address book.')
|
||||||
|
|
||||||
sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address)
|
|
||||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||||
queues.UISignalQueue.put(('rerenderMessagelistToLabels', ''))
|
queues.UISignalQueue.put(('rerenderMessagelistToLabels', ''))
|
||||||
queues.UISignalQueue.put(('rerenderAddressBook', ''))
|
queues.UISignalQueue.put(('rerenderAddressBook', ''))
|
||||||
|
@ -1110,18 +1105,15 @@ class BMRPCDispatcher(object):
|
||||||
if not fromAddressEnabled:
|
if not fromAddressEnabled:
|
||||||
raise APIError(14, 'Your fromAddress is disabled. Cannot send.')
|
raise APIError(14, 'Your fromAddress is disabled. Cannot send.')
|
||||||
|
|
||||||
ackdata = helper_sent.insert(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
toAddress=toAddress, fromAddress=fromAddress,
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
subject=subject, message=message, encoding=encodingType, ttl=TTL)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
|
|
||||||
toLabel = ''
|
helper_db.put_sent(
|
||||||
queryreturn = sqlQuery(
|
toAddress, fromAddress, subject, message, ackdata,
|
||||||
"SELECT label FROM addressbook WHERE address=?", toAddress)
|
'msgqueued', encodingType, ttl=TTL)
|
||||||
try:
|
|
||||||
toLabel, = queryreturn[0][0]
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
toLabel = helper_db.get_label(toAddress) or ''
|
||||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||||
queues.workerQueue.put(('sendmessage', toAddress))
|
queues.workerQueue.put(('sendmessage', toAddress))
|
||||||
|
@ -1151,15 +1143,15 @@ class BMRPCDispatcher(object):
|
||||||
self.config.getboolean(fromAddress, 'enabled')
|
self.config.getboolean(fromAddress, 'enabled')
|
||||||
except BaseException:
|
except BaseException:
|
||||||
raise APIError(
|
raise APIError(
|
||||||
13, 'Could not find your fromAddress in the keys.dat file.')
|
13, 'could not find your fromAddress in the keys.dat file.')
|
||||||
toAddress = str_broadcast_subscribers
|
streamNumber = decodeAddress(fromAddress)[2]
|
||||||
|
ackdata = genAckPayload(streamNumber, 0)
|
||||||
|
toAddress = toLabel = str_broadcast_subscribers
|
||||||
|
|
||||||
ackdata = helper_sent.insert(
|
helper_db.put_sent(
|
||||||
fromAddress=fromAddress, subject=subject,
|
toAddress, fromAddress, subject, message, ackdata,
|
||||||
message=message, status='broadcastqueued',
|
'broadcastqueued', encodingType, ttl=TTL)
|
||||||
encoding=encodingType)
|
|
||||||
|
|
||||||
toLabel = str_broadcast_subscribers
|
|
||||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||||
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
toAddress, toLabel, fromAddress, subject, message, ackdata)))
|
||||||
queues.workerQueue.put(('sendbroadcast', ''))
|
queues.workerQueue.put(('sendbroadcast', ''))
|
||||||
|
@ -1197,15 +1189,8 @@ class BMRPCDispatcher(object):
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
raise APIError(17, 'Label is not valid UTF-8 data.')
|
raise APIError(17, 'Label is not valid UTF-8 data.')
|
||||||
self._verifyAddress(address)
|
self._verifyAddress(address)
|
||||||
address = addBMIfNotPresent(address)
|
if not helper_db.put_subscriptions(label, address):
|
||||||
# First we must check to see if the address is already in the
|
|
||||||
# subscriptions list.
|
|
||||||
queryreturn = sqlQuery(
|
|
||||||
"SELECT * FROM subscriptions WHERE address=?", address)
|
|
||||||
if queryreturn:
|
|
||||||
raise APIError(16, 'You are already subscribed to that address.')
|
raise APIError(16, 'You are already subscribed to that address.')
|
||||||
sqlExecute(
|
|
||||||
"INSERT INTO subscriptions VALUES (?,?,?)", label, address, True)
|
|
||||||
shared.reloadBroadcastSendersForWhichImWatching()
|
shared.reloadBroadcastSendersForWhichImWatching()
|
||||||
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
|
||||||
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
queues.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user