Release v0.1.54: scheduled location sessions and paged voice delivery history
This commit is contained in:
+14
-7
@@ -42,11 +42,13 @@ class VoiceHistory:
|
||||
attempts INTEGER DEFAULT 0, next_try REAL DEFAULT 0)''')
|
||||
a.DB.execute('CREATE INDEX IF NOT EXISTS voice_history_sender ON voice_history(family,sender,seq)')
|
||||
a.DB.execute('CREATE INDEX IF NOT EXISTS voice_history_target ON voice_history(family,target,seq)')
|
||||
a.DB.execute('CREATE INDEX IF NOT EXISTS voice_history_pair ON voice_history(family,sender,target,seq)')
|
||||
a.DB.execute('CREATE INDEX IF NOT EXISTS voice_history_pending ON voice_history(state,next_try,seq)')
|
||||
if not a.setting('voice_history_key'):
|
||||
a.set_setting('voice_history_key', base64.b64encode(secrets.token_bytes(32)).decode())
|
||||
# A restart ends live playback, but never removes the conversation.
|
||||
a.DB.execute("UPDATE voice_history SET delivery='expired' WHERE delivery IN ('queued','received')")
|
||||
a.DB.execute("UPDATE voice_history SET delivery='expired' WHERE delivery IN ('queued','transferring','received')")
|
||||
a.DB.execute("UPDATE voice_history SET state='retry' WHERE state='uploading'")
|
||||
self.folder.mkdir(parents=True, exist_ok=True)
|
||||
os.chmod(self.folder, 0o700)
|
||||
with a.LOCK:
|
||||
@@ -123,12 +125,16 @@ class VoiceHistory:
|
||||
if not isinstance(peer, str) or not re.fullmatch(r'[a-f0-9]{64}', peer) or type(before) is not int or before < 0 or before > 2**63-1:
|
||||
raise self.a.Problem('请选择有效的沟通对象和记录页')
|
||||
me = actor['archiveKey']
|
||||
rows = self.a.DB.execute('''SELECT * FROM voice_history WHERE family=?
|
||||
AND ((sender=? AND target=?) OR (target=? AND sender=?))
|
||||
AND (?=0 OR seq<?) ORDER BY seq DESC LIMIT 51''',
|
||||
(actor['familyId'], me, peer, me, peer, before, before)).fetchall()
|
||||
more = len(rows) > 50
|
||||
rows = rows[:50]
|
||||
# Two bounded index scans; do not sort a lifetime of messages to fetch ten rows.
|
||||
cutoff=before or 2**63-1
|
||||
rows = self.a.DB.execute('''SELECT * FROM (SELECT * FROM voice_history
|
||||
WHERE family=? AND sender=? AND target=? AND seq<? ORDER BY seq DESC LIMIT 11)
|
||||
UNION ALL SELECT * FROM (SELECT * FROM voice_history
|
||||
WHERE family=? AND sender=? AND target=? AND seq<? ORDER BY seq DESC LIMIT 11)
|
||||
ORDER BY seq DESC LIMIT 11''',
|
||||
(actor['familyId'],me,peer,cutoff,actor['familyId'],peer,me,cutoff)).fetchall()
|
||||
more = len(rows) > 10
|
||||
rows = rows[:10]
|
||||
return dict(items=[dict(id=r['id'], seq=r['seq'], mine=r['sender']==me,
|
||||
senderName=r['sender_name'], targetName=r['target_name'], at=r['at'],
|
||||
seconds=r['seconds'], delivery=r['delivery'], archive=r['state']) for r in reversed(rows)],
|
||||
@@ -172,6 +178,7 @@ class VoiceHistory:
|
||||
row=a.DB.execute("SELECT * FROM voice_history WHERE state!='cloud' AND next_try<=? ORDER BY seq LIMIT 1", (time.time(),)).fetchone()
|
||||
if not row:return
|
||||
row=dict(row)
|
||||
with a.DB:a.DB.execute("UPDATE voice_history SET state='uploading' WHERE id=?",(row['id'],))
|
||||
local=self.folder/self.filename(row['id'])
|
||||
try:
|
||||
with local.open('rb') as stream: cipher=stream.read(MAX_FILE+1)
|
||||
|
||||
Reference in New Issue
Block a user