change helper_sent.insert methods
This commit is contained in:
parent
0ec15d1d4d
commit
a9e9f25b5d
|
@ -1116,7 +1116,8 @@ class BMRPCDispatcher(object):
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
|
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
|
'',
|
||||||
toAddress,
|
toAddress,
|
||||||
toRipe,
|
toRipe,
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -1131,7 +1132,6 @@ class BMRPCDispatcher(object):
|
||||||
'sent',
|
'sent',
|
||||||
encodingType,
|
encodingType,
|
||||||
TTL)
|
TTL)
|
||||||
helper_sent.insert(t)
|
|
||||||
|
|
||||||
toLabel = ''
|
toLabel = ''
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
|
@ -1176,7 +1176,8 @@ class BMRPCDispatcher(object):
|
||||||
toAddress = str_broadcast_subscribers
|
toAddress = str_broadcast_subscribers
|
||||||
ripe = ''
|
ripe = ''
|
||||||
|
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
|
'',
|
||||||
toAddress,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -1191,7 +1192,6 @@ class BMRPCDispatcher(object):
|
||||||
'sent',
|
'sent',
|
||||||
encodingType,
|
encodingType,
|
||||||
TTL)
|
TTL)
|
||||||
helper_sent.insert(t)
|
|
||||||
|
|
||||||
toLabel = str_broadcast_subscribers
|
toLabel = str_broadcast_subscribers
|
||||||
queues.UISignalQueue.put(('displayNewSentMessage', (
|
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, "))
|
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
||||||
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
addr,
|
addr,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -985,7 +985,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
2, # encodingType
|
2, # encodingType
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
queues.workerQueue.put(("sendmessage", addr))
|
queues.workerQueue.put(("sendmessage", addr))
|
||||||
else: # Broadcast
|
else: # Broadcast
|
||||||
if recv == "":
|
if recv == "":
|
||||||
|
@ -996,7 +995,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
||||||
recv = BROADCAST_STR
|
recv = BROADCAST_STR
|
||||||
ripe = ""
|
ripe = ""
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
recv,
|
recv,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -1013,7 +1012,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
||||||
2, # encodingType
|
2, # encodingType
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
queues.workerQueue.put(('sendbroadcast', ''))
|
queues.workerQueue.put(('sendbroadcast', ''))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2166,7 +2166,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
stealthLevel = BMConfigParser().safeGetInt(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
t = (
|
helper_sent.insert(
|
||||||
'',
|
'',
|
||||||
toAddress,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -2183,7 +2183,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
encoding, # encodingtype
|
encoding, # encodingtype
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
toLabel = ''
|
toLabel = ''
|
||||||
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
queryreturn = sqlQuery('''select label from addressbook where address=?''',
|
||||||
toAddress)
|
toAddress)
|
||||||
|
@ -2221,7 +2220,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
ackdata = genAckPayload(streamNumber, 0)
|
ackdata = genAckPayload(streamNumber, 0)
|
||||||
toAddress = str_broadcast_subscribers
|
toAddress = str_broadcast_subscribers
|
||||||
ripe = ''
|
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,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -2237,7 +2237,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
encoding, # encoding type
|
encoding, # encoding type
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
helper_sent.insert(t)
|
|
||||||
|
|
||||||
toLabel = str_broadcast_subscribers
|
toLabel = str_broadcast_subscribers
|
||||||
|
|
||||||
|
|
|
@ -755,7 +755,8 @@ class objectProcessor(threading.Thread):
|
||||||
# set the TTL for mailing list broadcasts. This is obviously
|
# set the TTL for mailing list broadcasts. This is obviously
|
||||||
# hard-coded.
|
# hard-coded.
|
||||||
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
||||||
t = ('',
|
helper_sent.insert(
|
||||||
|
'',
|
||||||
toAddress,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -770,7 +771,6 @@ class objectProcessor(threading.Thread):
|
||||||
'sent',
|
'sent',
|
||||||
messageEncodingType,
|
messageEncodingType,
|
||||||
TTL)
|
TTL)
|
||||||
helper_sent.insert(t)
|
|
||||||
|
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'displayNewSentMessage', (
|
'displayNewSentMessage', (
|
||||||
|
|
|
@ -10,38 +10,41 @@ from helper_ackPayload import genAckPayload
|
||||||
from helper_sql import sqlExecute
|
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"""
|
"""Perform an insert into the `sent` table"""
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
|
# pylint: disable-msg=too-many-locals
|
||||||
|
|
||||||
if '' in t or 0 in t:
|
msgid = msgid if msgid else uuid.uuid4().bytes
|
||||||
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')
|
|
||||||
}
|
|
||||||
|
|
||||||
if not temp[2] or not temp[6]:
|
if not ripe or not ackdata:
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(temp[1])
|
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(toAddress)
|
||||||
if not temp[2]:
|
if not ripe:
|
||||||
temp_dict[2] = ripe
|
ripe = new_ripe
|
||||||
|
|
||||||
if not temp[6]:
|
if not ackdata:
|
||||||
stealthLevel = BMConfigParser().safeGetInt(
|
stealthLevel = BMConfigParser().safeGetInt(
|
||||||
'bitmessagesettings', 'ackstealthlevel')
|
'bitmessagesettings', 'ackstealthlevel')
|
||||||
ackdata = genAckPayload(streamNumber, stealthLevel)
|
new_ackdata = genAckPayload(streamNumber, stealthLevel)
|
||||||
temp_dict[6] = ackdata
|
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)
|
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||||
return t if is_testcase else None
|
return t if is_testcase else None
|
||||||
|
|
|
@ -247,7 +247,8 @@ class TestCore(unittest.TestCase):
|
||||||
message = 'test message'
|
message = 'test message'
|
||||||
subject = 'test subject'
|
subject = 'test subject'
|
||||||
encoding = 2
|
encoding = 2
|
||||||
t = ('', # msgid
|
result = helper_sent.insert(
|
||||||
|
'', # msgid
|
||||||
toAddress,
|
toAddress,
|
||||||
'', # ripe
|
'', # ripe
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -261,17 +262,18 @@ class TestCore(unittest.TestCase):
|
||||||
0,
|
0,
|
||||||
'sent',
|
'sent',
|
||||||
encoding,
|
encoding,
|
||||||
0)
|
0,
|
||||||
result = helper_sent.insert(t, True)
|
True)
|
||||||
self.assertNotEqual(result[0], '')
|
self.assertNotEqual(result[0], '')
|
||||||
|
|
||||||
def test_defalut_insert_values(self):
|
def test_defalut_insert_values(self):
|
||||||
"""Test missing values in insert method for message sending"""
|
"""Test missing values in insert method for message sending"""
|
||||||
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
fromAddress = 'BM-2cTrmD22fLRrumi3pPLg1ELJ6PdAaTRTdfg'
|
||||||
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWgjdfkj89fdf'
|
toAddress = 'BM-2cVWtdUzPwF7UNGDrZftWuHWiJ6xxBpiSP' # autoresponder address
|
||||||
message = 'test message'
|
message = 'test message'
|
||||||
subject = 'test subject'
|
subject = 'test subject'
|
||||||
t = ('', # msgid
|
result = helper_sent.insert(
|
||||||
|
'', # msgid
|
||||||
toAddress,
|
toAddress,
|
||||||
'', # ripe
|
'', # ripe
|
||||||
fromAddress,
|
fromAddress,
|
||||||
|
@ -285,8 +287,7 @@ class TestCore(unittest.TestCase):
|
||||||
'', # retryNumber
|
'', # retryNumber
|
||||||
'', # folder
|
'', # folder
|
||||||
'', # encoding
|
'', # encoding
|
||||||
'') # ttl
|
'', True)
|
||||||
result = helper_sent.insert(t, True)
|
|
||||||
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
|
for index in [0, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14]:
|
||||||
self.assertNotEqual(result[index], '')
|
self.assertNotEqual(result[index], '')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user