Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from .tasks import cleanup_empty_chats, wait_for_paid_invoices
from .views import chat_generic_router
from .views_api import chat_api_router
from .views_lnurl import chat_lnurl_router

chat_ext: APIRouter = APIRouter(prefix="/chat", tags=["Chat"])
chat_ext.include_router(chat_generic_router)
chat_ext.include_router(chat_lnurl_router)
chat_ext.include_router(chat_api_router)
chat_ext.include_router(chat_generic_router)


chat_static_files = [
Expand Down
16 changes: 16 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import re

from fastapi import Request
from lnurl import encode as lnurl_encode


def is_valid_email_address(email: str) -> bool:
email_regex = r"[A-Za-z0-9\._%+-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,63}"
return re.fullmatch(email_regex, email) is not None


def chat_lnurl_url(req: Request, chat_id: str) -> str:
url = req.url_for("chat.api_lnurl_response", chat_id=chat_id)
url = url.replace(path=url.path)
url_str = str(url)
if url.netloc.endswith(".onion"):
url_str = url_str.replace("https://", "http://")
return url_str


def lnurl_encode_chat(req: Request, chat_id: str) -> str:
return str(lnurl_encode(chat_lnurl_url(req, chat_id)).bech32)
46 changes: 46 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,49 @@ async def m007_chats_public_url(db):
ALTER TABLE chat.chats ADD COLUMN public_url TEXT;
"""
)


async def m008_chat_lnurlp_balance(db):
"""
Add lnurlp toggle to categories and balance to chats.
"""

await db.execute(
"""
ALTER TABLE chat.categories ADD COLUMN lnurlp BOOLEAN DEFAULT 0;
"""
)
await db.execute(
f"""
ALTER TABLE chat.chats ADD COLUMN balance {db.big_int} DEFAULT 0;
"""
)


async def m009_chat_claims(db):
"""
Add chat claim fields.
"""

await db.execute(
"""
ALTER TABLE chat.chats ADD COLUMN claimed_by_id TEXT;
"""
)
await db.execute(
"""
ALTER TABLE chat.chats ADD COLUMN claimed_by_name TEXT;
"""
)


async def m010_chat_claim_split(db):
"""
Add claim split percentage to categories.
"""

await db.execute(
"""
ALTER TABLE chat.categories ADD COLUMN claim_split REAL DEFAULT 0;
"""
)
13 changes: 13 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class CreateCategories(BaseModel):
name: str
wallet: str | None = None
paid: bool | None = False
lnurlp: bool | None = False
tips: bool | None = False
chars: int | None = None
price_chars: float | None = None
denomination: str | None = "sat"
claim_split: float | None = 0
notify_telegram: str | None = None
notify_nostr: str | None = None
notify_email: str | None = None
Expand All @@ -23,10 +25,12 @@ class Categories(BaseModel):
name: str
wallet: str | None = None
paid: bool | None = False
lnurlp: bool | None = False
tips: bool | None = False
chars: int | None = None
price_chars: float | None = None
denomination: str | None = "sat"
claim_split: float | None = 0
notify_telegram: str | None = None
notify_nostr: str | None = None
notify_email: str | None = None
Expand All @@ -39,29 +43,35 @@ class PublicCategories(BaseModel):
id: str
name: str
paid: bool | None = False
lnurlp: bool | None = False
tips: bool | None = False
chars: int | None = None
price_chars: float | None = None
denomination: str | None = "sat"
claim_split: float | None = 0


class CategoriesFilters(FilterModel):
__search_fields__ = [
"name",
"paid",
"lnurlp",
"tips",
"chars",
"price_chars",
"denomination",
"claim_split",
]

__sort_fields__ = [
"name",
"paid",
"lnurlp",
"tips",
"chars",
"price_chars",
"denomination",
"claim_split",
"created_at",
"updated_at",
]
Expand Down Expand Up @@ -98,6 +108,9 @@ class ChatSession(BaseModel):
resolved: bool = False
unread: bool = True
public_url: str | None = None
balance: int = 0
claimed_by_id: str | None = None
claimed_by_name: str | None = None
participants: list[dict] = Field(default_factory=list)
messages: list[dict] = Field(default_factory=list)
last_message_at: datetime | None = None
Expand Down
Loading