Store a group voice message (plaintext on disk).
(gm_id: int, file_storage)
| 14616 | return jsonify(ok=False, locked=True, error="PIN required"), 423 |
| 14617 | try: |
| 14618 | since_id = int(request.args.get("id") or 0) |
| 14619 | except Exception: |
| 14620 | since_id = 0 |
| 14621 | |
| 14622 | conn = db_connect() |
| 14623 | # Mark newly received messages as delivered (recipient fetched them). |
| 14624 | try: |
| 14625 | conn.execute( |
| 14626 | "UPDATE dm_messages SET delivered_at=? WHERE sender=? AND recipient=? AND delivered_at IS NULL", |
| 14627 | (now_z(), peer, me), |
| 14628 | ) |
| 14629 | conn.commit() |
| 14630 | except Exception: |
| 14631 | pass |
| 14632 | |
| 14633 | # Mark as read when the chat tab is open (this endpoint is called by the active chat view). |
| 14634 | try: |
| 14635 | conn.execute( |
| 14636 | "UPDATE dm_messages SET read_at=? WHERE sender=? AND recipient=? AND read_at IS NULL", |
| 14637 | (now_z(), peer, me), |
| 14638 | ) |
| 14639 | conn.commit() |
| 14640 | except Exception: |
| 14641 | pass |
| 14642 | |
| 14643 | |
| 14644 | rows = conn.execute(""" |
| 14645 | SELECT id, sender, recipient, body_enc, created_at, delivered_at, read_at, has_voice, has_file, edited_at, deleted_at |
| 14646 | FROM dm_messages |
| 14647 | WHERE id > ? AND ((sender=? AND recipient=?) OR (sender=? AND recipient=?)) |
| 14648 | ORDER BY id ASC |
| 14649 | LIMIT 120 |
| 14650 | """, (since_id, me, peer, peer, me)).fetchall() |
| 14651 | |
| 14652 | out = [] |
| 14653 | want_html = (request.args.get('html') == '1') |
| 14654 | for r in rows: |
| 14655 | if r["has_voice"]: |
| 14656 | v = conn.execute("SELECT id, mime FROM dm_voice WHERE dm_id=? ORDER BY id DESC LIMIT 1", (r["id"],)).fetchone() |
| 14657 | else: |
| 14658 | v = None |
| 14659 | if r["has_file"]: |
| 14660 | f = conn.execute("SELECT id, filename, mime, size FROM dm_files WHERE dm_id=? ORDER BY id DESC LIMIT 1", (r["id"],)).fetchone() |
| 14661 | else: |
| 14662 | f = None |
| 14663 | try: |
| 14664 | body = aesgcm_decrypt_text(r["body_enc"]) |
| 14665 | except Exception: |
| 14666 | body = "[decrypt failed]" |
| 14667 | out.append({ |
| 14668 | "id": r["id"], |
| 14669 | "sender": r["sender"], |
| 14670 | "kind": ("deleted" if r["deleted_at"] else ("voice" if r["has_voice"] else ("file" if r["has_file"] else "text"))), |
| 14671 | "deleted": True if r["deleted_at"] else False, |
| 14672 | "body": ("[deleted]" if r["deleted_at"] else (body if (not r["has_voice"] and not r["has_file"]) else "")), |
| 14673 | "created_at_local": _local_time_str(r["created_at"]), |
| 14674 | "created_at_utc": r["created_at"], |
| 14675 | "read_at_local": _local_time_str(r["read_at"]) if r["sender"] == me else None, |
nothing calls this directly
no test coverage detected