fix transaction id

This commit is contained in:
Morgan McMillian 2017-03-04 18:35:51 -08:00
parent ffc4af4b9b
commit 4037a8a68b

View file

@ -13,12 +13,11 @@ _shutdown = threading.Event()
class ChannelMonitor(threading.Thread): class ChannelMonitor(threading.Thread):
txId = 0
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.matrix_api_url = app.config['MATRIX_HOST'] + '/_matrix/client/r0' self.matrix_api_url = app.config['MATRIX_HOST'] + '/_matrix/client/r0'
self.matrix_api_token = app.config['MATRIX_AS_TOKEN'] self.matrix_api_token = app.config['MATRIX_AS_TOKEN']
self.txId = 0
def generate_matrix_id(self, username): def generate_matrix_id(self, username):
m_username = app.config['MATRIX_PNUT_PREFIX'] + username m_username = app.config['MATRIX_PNUT_PREFIX'] + username
@ -73,7 +72,7 @@ class ChannelMonitor(threading.Thread):
r = requests.post(url, params=params) r = requests.post(url, params=params)
def send_message(self, roomid, msg): def send_message(self, roomid, msg):
url = self.matrix_api_url + '/rooms/' + roomid +'/send/m.room.message' + '/' + str(txId) url = self.matrix_api_url + '/rooms/' + roomid +'/send/m.room.message' + '/' + str(self.txId)
params = { params = {
'access_token': self.matrix_api_token, 'access_token': self.matrix_api_token,
'user_id': msg['user']['user_id'], 'user_id': msg['user']['user_id'],
@ -139,7 +138,7 @@ class ChannelMonitor(threading.Thread):
db.session.commit() db.session.commit()
for item in pqueue: for item in pqueue:
txId += 1 self.txId += 1
d = self.is_registered(item['user']['user_id']) d = self.is_registered(item['user']['user_id'])
if not d: if not d:
@ -157,6 +156,8 @@ class ChannelMonitor(threading.Thread):
def run(self): def run(self):
logging.info("-- Starting channel monitor --") logging.info("-- Starting channel monitor --")
app.app_context().push() app.app_context().push()
rooms = MatrixRoom.query.all()
self.txId = int(rooms[0].pnut_since)
while not _shutdown.isSet(): while not _shutdown.isSet():
rooms = MatrixRoom.query.all() rooms = MatrixRoom.query.all()
for r in rooms: for r in rooms: