Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 19b54d7

Browse files
committed
Cache profile and load avatar into conversations
1 parent a0f8256 commit 19b54d7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

db/datastore.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,17 @@ def get_conversations(self):
562562
WHERE guid=? and messageType=?''', (g[0], "CHAT"))
563563
val = cursor.fetchone()
564564
if val[0] is not None:
565+
avatar_hash = None
566+
try:
567+
with open(DATA_FOLDER + 'cache/' + g[0], "r") as filename:
568+
profile = filename.read()
569+
p = objects.Profile()
570+
p.ParseFromString(profile)
571+
avatar_hash = p.avatar_hash.encode("hex")
572+
except Exception:
573+
pass
565574
ret.append({"guid": g[0],
566-
"avatar_hash": val[0].encode("hex"),
575+
"avatar_hash": avatar_hash,
567576
"last_message": val[1],
568577
"timestamp": val[2],
569578
"public_key": val[3].encode("hex"),
@@ -842,7 +851,7 @@ def get_all(self):
842851
def get_unfunded(self):
843852
conn = Database.connect_database(self.PATH)
844853
cursor = conn.cursor()
845-
cursor.execute('''SELECT id FROM purchases WHERE status=0''')
854+
cursor.execute('''SELECT id, timestamp FROM purchases WHERE status=0''')
846855
ret = cursor.fetchall()
847856
conn.close()
848857
return ret

market/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def get_result(result):
196196
self.get_image(node_to_ask, p.avatar_hash)
197197
if not os.path.isfile(DATA_FOLDER + 'cache/' + p.header_hash.encode("hex")):
198198
self.get_image(node_to_ask, p.header_hash)
199+
self.cache(result[1][0], node_to_ask.id.encode("hex"))
199200
return p
200201
except Exception:
201202
return None

net/rpcudp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def __getattr__(self, name):
158158

159159
def func(node, *args):
160160
msgID = sha1(str(random.getrandbits(255))).digest()
161-
162161
m = Message()
163162
m.messageID = msgID
164163
m.sender.MergeFrom(self.sourceNode.getProto())

0 commit comments

Comments
 (0)