Private
Public Access
Add custom emoji support (#18)
Site-wide, any user can upload -- usable both as reactions and inline in message text via :shortcode:, alongside the existing built-in Unicode picker. A :shortcode: reference is stored/sent as literal text (same as the built-in shortcode convention) and resolved to an image at render time, so it degrades to plain text if the emoji is later deleted. Backend: new custom_emoji table (shortcode unique, sized to fit MessageReaction.emoji's existing column alongside its colons), upload/ list/delete endpoints (delete restricted to uploader or site admin). Frontend: a CustomEmojiProvider context feeds a new "Custom" category in the emoji picker (inline upload + hover-to-remove), extends the composer's shortcode autocomplete, and a shared EmojiGlyph resolver renders custom emoji wherever a value can appear -- message text, reaction pills, and the picker itself. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class CustomEmoji(Base):
|
||||
__tablename__ = "custom_emoji"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4)
|
||||
# #18: site-wide, not room-scoped -- kept globally unique so a bare
|
||||
# `:shortcode:` in any message/reaction is unambiguous without also
|
||||
# knowing which room it was posted in. 30 chars, not 32 -- the stored
|
||||
# *reference* in MessageReaction.emoji (String(32)) is the shortcode
|
||||
# wrapped in colons, so this is sized to leave room for both without
|
||||
# widening that column.
|
||||
shortcode: Mapped[str] = mapped_column(String(30), unique=True, index=True, nullable=False)
|
||||
storage_filename: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
content_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
uploaded_by: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||||
)
|
||||
|
||||
uploader = relationship("User")
|
||||
Reference in New Issue
Block a user