change helper_sent.insert methods
This commit is contained in:
parent
0ec15d1d4d
commit
a9e9f25b5d
|
@ -1116,7 +1116,8 @@ class BMRPCDispatcher(object):
|
|||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
|
||||
t = ('',
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
toRipe,
|
||||
fromAddress,
|
||||
|
@ -1131,7 +1132,6 @@ class BMRPCDispatcher(object):
|
|||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
toLabel = ''
|
||||
queryreturn = sqlQuery(
|
||||
|
@ -1176,7 +1176,8 @@ class BMRPCDispatcher(object):
|
|||
toAddress = str_broadcast_subscribers
|
||||
ripe = ''
|
||||
|
||||
t = ('',
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
|
@ -1191,7 +1192,6 @@ class BMRPCDispatcher(object):
|
|||
'sent',
|
||||
encodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
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,7 +2220,8 @@ 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.
|
||||
helper_sent.insert(
|
||||
'', # msgid. We don't know what this will be until the POW is done.
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
|
@ -2237,7 +2237,6 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
encoding, # encoding type
|
||||
0
|
||||
)
|
||||
helper_sent.insert(t)
|
||||
|
||||
toLabel = str_broadcast_subscribers
|
||||
|
||||
|
|
|
@ -755,7 +755,8 @@ 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 = ('',
|
||||
helper_sent.insert(
|
||||
'',
|
||||
toAddress,
|
||||
ripe,
|
||||
fromAddress,
|
||||
|
@ -770,7 +771,6 @@ class objectProcessor(threading.Thread):
|
|||
'sent',
|
||||
messageEncodingType,
|
||||
TTL)
|
||||
helper_sent.insert(t)
|
||||
|
||||
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]:
|
||||
if not ackdata:
|
||||
stealthLevel = BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'ackstealthlevel')
|
||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||
temp_dict[6] = ackdata
|
||||
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], '')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user