def dispatch_request(self): config = app.config['yada_config'] mongo = app.config['yada_mongo'] my_bulletin_secret = config.get_bulletin_secret() their_bulletin_secret = request.json.get('bulletin_secret') rids = sorted([str(my_bulletin_secret), str(their_bulletin_secret)], key=str.lower) rid = hashlib.sha256(str(rids[0]) + str(rids[1])).digest().encode('hex') client = app.test_client() response = client.post('/post-fastgraph-transaction', json=request.json.get('txn'), headers=list(request.headers)) fastgraph = FastGraph(config, mongo, request.json.get('txn')) try: response.get_json() except: return 'error posting react', 400 rids = sorted([str(my_bulletin_secret), str(their_bulletin_secret)], key=str.lower) rid = hashlib.sha256(str(rids[0]) + str(rids[1])).digest().encode('hex') friend = BU.get_transactions(config, mongo, wif=config.wif, both=False, query={ 'txn.relationship.their_username': { '$exists': True }, 'txn.relationship.id': { '$in': signatures } }, queryType="searchUsername") if friend: username = [x for x in friend][0]['relationship']['their_username'] else: username = '' res = mongo.site_db.fcmtokens.find({"rid": rid}) for token in res: result = push_service.notify_single_device( registration_id=token['token'], message_title='%s reacted to your post!' % username, message_body='Go see how they reacted!', extra_kwargs={'priority': 'high'}) return 'ok'
def show_users(): users = BU.get_transactions() rids = set([x['rid'] for x in users]) return render_template('show-users.html', users=rids)