Social composer: send now and rename messy account names (#6)
## Summary Closes #5. - Composer can **Send now** without a schedule time (Schedule and Save draft still available) - Account names wrap and show the platform id so a bad OAuth label is still readable - Social accounts page can rename the display name; re-auth keeps a custom name instead of overwriting it with a placeholder - Worker polls `dispatch_due` every 15s so scheduled campaigns and social posts fire without a manual command; local `docker compose up` now starts the worker ## Test plan - [ ] Open Social → Compose: confirm **Send now**, **Schedule**, and **Save draft** buttons (no combined Save / publish) - [ ] Send now with a connected account and caption → post queues immediately, no datetime required - [ ] Schedule with a datetime → post is scheduled; Schedule with a blank time → validation error - [ ] Composer account list shows full name plus external id, wrapping if the name is long - [ ] Social accounts → rename a messy label → new name shows in composer without reconnecting - [ ] Re-authorize an account that was renamed → custom name is kept - [ ] Rebuild and start compose (`docker compose up --build`) so the **worker** service is running - [ ] Schedule a social post ~2 minutes ahead → after due time, worker logs `Enqueued N due item(s).` and the post leaves Scheduled (published or failed) - [ ] `docker compose logs -f worker` shows `Polling due scheduled work every 15s.` Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -3,6 +3,29 @@ from django.db import models
|
||||
|
||||
from core.models import TimeStampedModel, UUIDPrimaryKeyModel
|
||||
|
||||
_GENERIC_ACCOUNT_LABELS = frozenset(
|
||||
{
|
||||
"linkedin member",
|
||||
"instagram account",
|
||||
"facebook page",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def is_generic_account_label(label: str) -> bool:
|
||||
"""True when OAuth left a placeholder or unreadable name."""
|
||||
text = (label or "").strip()
|
||||
if not text:
|
||||
return True
|
||||
lowered = text.lower()
|
||||
if lowered in _GENERIC_ACCOUNT_LABELS:
|
||||
return True
|
||||
if lowered.startswith("page ") and text.split()[-1].isdigit():
|
||||
return True
|
||||
if text.startswith("urn:"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Platform(models.TextChoices):
|
||||
FACEBOOK = "facebook", "Facebook"
|
||||
@@ -54,6 +77,22 @@ class SocialAccount(UUIDPrimaryKeyModel, TimeStampedModel):
|
||||
def __str__(self) -> str:
|
||||
return f"{self.platform}: {self.label}"
|
||||
|
||||
@property
|
||||
def display_name(self) -> str:
|
||||
return (self.label or "").strip() or self.get_platform_display()
|
||||
|
||||
@staticmethod
|
||||
def resolve_label(existing: "SocialAccount | None", incoming: str) -> str:
|
||||
"""Keep a custom rename; otherwise take the OAuth name."""
|
||||
incoming = (incoming or "").strip()[:120]
|
||||
if existing is not None and not is_generic_account_label(existing.label):
|
||||
return existing.label
|
||||
if incoming:
|
||||
return incoming
|
||||
if existing and existing.label:
|
||||
return existing.label
|
||||
return "Account"
|
||||
|
||||
|
||||
class SocialPost(UUIDPrimaryKeyModel, TimeStampedModel):
|
||||
class Status(models.TextChoices):
|
||||
|
||||
Reference in New Issue
Block a user