diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/db/models.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/db/models.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/models.py b/packages/meshbay-hub/src/meshbay_hub/db/models.py index 5b140f1..a0437d6 100644 --- a/packages/meshbay-hub/src/meshbay_hub/db/models.py +++ b/packages/meshbay-hub/src/meshbay_hub/db/models.py @@ -145,6 +145,53 @@ class GroupMember(Base): user: Mapped["User"] = relationship(back_populates="group_memberships") +class GroupInvitation(Base): + """ + Somebody asked to add this account to a group, and it has not said yes. + + Separate from `GroupMember` on purpose. A membership row is what the hub + acts on — it lets an account's client dial the group's nodes, names the + group in the account's MNP tokens and lists the group in its sidebar and in + Search — and an owner could create one for any username, unasked. That made + any account able to have any other account's client connect to a node of + its choosing. So an owner's addition is an invitation until the invitee + accepts it; redeeming an invitation link, joining an open group and creating + a group are the account's own acts and still write the membership directly. + """ + __tablename__ = "group_invitations" + + group_id: Mapped[str] = mapped_column(ForeignKey("groups.id"), primary_key=True) + user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), primary_key=True) + invited_by: Mapped[str | None] = mapped_column(ForeignKey("users.id")) + created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now) + + __table_args__ = (Index("ix_group_invitations_user", "user_id"),) + + +class GroupHost(Base): + """ + A node the group's owner has approved as a host, refused, or not yet + answered (`approved` / `refused` / `pending`). + + A node registers for the groups it claims, and clients connect to whichever + registered node answers first. Every member holds the group key, so a + member's node passes the handshake like the real host would: the ceiling on + what a node may claim cannot be "groups its account belongs to". It is + "groups its account owns", plus the nodes listed here as `approved`. A node + that claims a group it may not host is recorded `pending`, and the owner is + told, so a legitimate second host is one click away rather than refused. + """ + __tablename__ = "group_hosts" + + group_id: Mapped[str] = mapped_column(ForeignKey("groups.id"), primary_key=True) + node_id: Mapped[str] = mapped_column(ForeignKey("nodes.id"), primary_key=True) + status: Mapped[str] = mapped_column(String(16), default="pending", nullable=False) + requested_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now) + decided_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True)) + + __table_args__ = (Index("ix_group_hosts_node", "node_id"),) + + class GroupInviteLink(Base): """ The hub's half of an invitation link (docs/MESHBAY_DESIGN.md §7.3). |