aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api/groups.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/groups.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/groups.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/groups.py b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
index 6dd4275..a8a45c9 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/groups.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
@@ -69,16 +69,17 @@ async def group_online_nodes(
@router.get("")
async def list_public_groups(
db: AsyncSession = Depends(get_db),
+ q: str = "",
limit: int = 50,
offset: int = 0,
include_federated: bool = True,
):
- """List public groups — local and optionally federated. No auth required."""
+ """List/search public groups — local and optionally federated. No auth required."""
+ query = select(Group).where(Group.visibility == "public", Group.status == "active")
+ if q:
+ query = query.where(Group.name.ilike(f"%{q}%"))
result = await db.execute(
- select(Group)
- .where(Group.visibility == "public", Group.status == "active")
- .order_by(Group.created_at.desc())
- .limit(limit).offset(offset)
+ query.order_by(Group.created_at.desc()).limit(limit).offset(offset)
)
local = result.scalars().all()
groups = [
@@ -90,10 +91,11 @@ async def list_public_groups(
]
if include_federated:
+ fed_query = select(FederatedGroup)
+ if q:
+ fed_query = fed_query.where(FederatedGroup.name.ilike(f"%{q}%"))
fed_result = await db.execute(
- select(FederatedGroup)
- .order_by(FederatedGroup.updated_at.desc())
- .limit(limit)
+ fed_query.order_by(FederatedGroup.updated_at.desc()).limit(limit)
)
for fg in fed_result.scalars().all():
groups.append({
@@ -217,6 +219,7 @@ async def store_gek_bundle(
# Upsert GEK bundle
existing = await db.get(GEKBundle, (group_id, target.id))
+ new_member = False
if existing:
existing.pk_eph_b64 = body.pk_eph_b64
existing.nonce_b64 = body.nonce_b64
@@ -233,6 +236,15 @@ async def store_gek_bundle(
mem = await db.get(GroupMember, (group_id, target.id))
if not mem:
db.add(GroupMember(group_id=group_id, user_id=target.id))
+ new_member = True
+
+ if new_member:
+ from meshbay_hub.api.notifications import create_notification
+ await create_notification(
+ db, target.id, "group_invite",
+ f"You were added to {group.name}",
+ link=f"#/group/{group_id}",
+ )
await db.commit()
return {"status": "stored", "group_id": group_id, "username": username}