change helper_sent.insert methods
This commit is contained in:
parent
0ec15d1d4d
commit
a9e9f25b5d
64
src/api.py
64
src/api.py
|
@ -1116,22 +1116,22 @@ class BMRPCDispatcher(object):
|
|||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
|
||||
t = ('',
|
||||
toAddress,
|
||||
toRipe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this won't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'msgqueued',
|
||||
0,
|
||||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
toRipe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this won't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'msgqueued',
|
||||
0,
|
||||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
|
||||
toLabel = ''
|
||||
queryreturn = sqlQuery(
|
||||
|
@ -1176,22 +1176,22 @@ class BMRPCDispatcher(object):
|
|||
toAddress = str_broadcast_subscribers
|
||||
ripe = ''
|
||||
|
||||
t = ('',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
|
||||
toLabel = str_broadcast_subscribers
|
||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
||||
|
|
|
@ -968,7 +968,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
||||
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
||||
t = (
|
||||
helper_sent.insert(
|
||||
'',
|
||||
addr,
|
||||
ripe,
|
||||
|
@ -985,7 +985,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
2, # encodingType
|
||||
0
|
||||
)
|
||||
helper_sent.insert(t)
|
||||
queues.workerQueue.put(("sendmessage", addr))
|
||||
else: # Broadcast
|
||||
if recv == "":
|
||||
|
@ -996,7 +995,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
||||
recv = BROADCAST_STR
|
||||
ripe = ""
|
||||
t = (
|
||||
helper_sent.insert(
|
||||
'',
|
||||
recv,
|
||||
ripe,
|
||||
|
@ -1013,7 +1012,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
2, # encodingType
|
||||
0
|
||||
)
|
||||
helper_sent.insert(t)
|
||||
queues.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
|
||||
|
|
|
@ -2166,7 +2166,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
t = (
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
|
@ -2183,7 +2183,6 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
encoding, # encodingtype
|
||||
0
|
||||
)
|
||||
helper_sent.insert(t)
|
||||
toLabel = ''
|
||||
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
||||
toAddress)
|
||||
|
@ -2221,23 +2220,23 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
ackdata = genAckPayload(streamNumber, 0)
|
||||
toAddress = str_broadcast_subscribers
|
||||
ripe = ''
|
||||
t = ('', # msgid. We don't know what this will be until the POW is done.
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
'broadcastqueued',
|
||||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encoding type
|
||||
0
|
||||
)
|
||||
helper_sent.insert(t)
|
||||
helper_sent.insert(
|
||||
'', # msgid. We don't know what this will be until the POW is done.
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this will never change)
|
||||
int(time.time()), # lastActionTime
|
||||
0, # sleepTill time. This will get set when the POW gets done.
|
||||
'broadcastqueued',
|
||||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encoding type
|
||||
0
|
||||
)
|
||||
|
||||
toLabel = str_broadcast_subscribers
|
||||
|
||||
|
|
|
@ -755,22 +755,22 @@ class objectProcessor(threading.Thread):
|
|||
# set the TTL for mailing list broadcasts. This is obviously
|
||||
# hard-coded.
|
||||
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
||||
t = ('',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
messageEncodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
subject,
|
||||
message,
|
||||
ackdata,
|
||||
int(time.time()), # sentTime (this doesn't change)
|
||||
int(time.time()), # lastActionTime
|
||||
0,
|
||||
'broadcastqueued',
|
||||
0,
|
||||
'sent',
|
||||
messageEncodingType,
|
||||
TTL)
|
||||
|
||||
queues.UISignalQueue.put((
|
||||
'displayNewSentMessage', (
|
||||
|
|
|
@ -10,38 +10,41 @@ from helper_ackPayload import genAckPayload
|
|||
from helper_sql import sqlExecute
|
||||
|
||||
|
||||
def insert(t, is_testcase=False):
|
||||
# pylint: disable=too-many-arguments
|
||||
def insert(msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
||||
sentTime, lastActionTime, sleeptill=0, status='msgqueued',
|
||||
retryNumber=0, folder='sent', encoding=2, ttl=0, is_testcase=False):
|
||||
"""Perform an insert into the `sent` table"""
|
||||
# pylint: disable=unused-variable
|
||||
# pylint: disable-msg=too-many-locals
|
||||
|
||||
if '' in t or 0 in t:
|
||||
temp = list(t)
|
||||
temp_dict = {
|
||||
0: uuid.uuid4().bytes, # if msgid is empty the put uuid
|
||||
7: int(time.time()), # sentTime
|
||||
8: int(time.time()), # lastActionTime
|
||||
9: 0, # sleeptill
|
||||
10: 'msgqueued',
|
||||
11: 0, # retryNumber
|
||||
12: 'sent', # folder
|
||||
13: 2, # encoding
|
||||
14: BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
}
|
||||
msgid = msgid if msgid else uuid.uuid4().bytes
|
||||
|
||||
if not temp[2] or not temp[6]:
|
||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
|
||||
if not temp[2]:
|
||||
temp_dict[2] = ripe
|
||||
if not ripe or not ackdata:
|
||||
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(toAddress)
|
||||
if not ripe:
|
||||
ripe = new_ripe
|
||||
|
||||
if not temp[6]:
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
temp_dict[6] = ackdata
|
||||
if not ackdata:
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
ackdata = new_ackdata
|
||||
|
||||
sentTime = sentTime if sentTime else int(time.time())
|
||||
lastActionTime = lastActionTime if lastActionTime else int(time.time())
|
||||
|
||||
sleeptill = sleeptill if sleeptill else 0
|
||||
status = status if status else 'msgqueued'
|
||||
retryNumber = retryNumber if retryNumber else 0
|
||||
folder = folder if folder else 'sent'
|
||||
encoding = encoding if encoding else 2
|
||||
|
||||
ttl = ttl if ttl else BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
|
||||
t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
|
||||
sentTime, lastActionTime, sleeptill, status, retryNumber, folder,
|
||||
encoding, ttl)
|
||||
|
||||
for i in dict(enumerate(temp)):
|
||||
if not temp[i]:
|
||||
temp[i] = temp_dict[i]
|
||||
t = tuple(temp)
|
||||
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
return t if is_testcase else None
|
||||
|
|
|
@ -247,7 +247,8 @@ class TestCore(unittest.TestCase):
|
|||
message = 'test message'
|
||||
subject = 'test subject'
|
||||
encoding = 2
|
||||
t = ('', # msgid
|
||||
result = helper_sent.insert(
|
||||
'', # msgid
|
||||
toAddress,
|
||||
'', # ripe
|
||||
fromAddress,
|
||||
|
@ -261,17 +262,18 @@ class TestCore(unittest.TestCase):
|
|||
0,
|
||||
'sent',
|
||||
encoding,
|
||||
0)
|
||||
result = helper_sent.insert(t, True)
|
||||
0,
|
||||
True)
|
||||
self.assertNotEqual(result[0], '')
|
||||
|
||||
def test_defalut_insert_values(self):
|
||||
"""Test missing values in insert method for message sending"""
|
||||
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf'
|
||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP' # autoresponder address
|
||||
message = 'test message'
|
||||
subject = 'test subject'
|
||||
t = ('', # msgid
|
||||
result = helper_sent.insert(
|
||||
'', # msgid
|
||||
toAddress,
|
||||
'', # ripe
|
||||
fromAddress,
|
||||
|
@ -285,8 +287,7 @@ class TestCore(unittest.TestCase):
|
|||
'', # retryNumber
|
||||
'', # folder
|
||||
'', # encoding
|
||||
'') # ttl
|
||||
result = helper_sent.insert(t, True)
|
||||
'', True)
|
||||
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
|
||||
self.assertNotEqual(result[index], '')
|
||||
|
||||
|
|
Reference in New Issue
Block a user