feat: add preview=1 to chat announcements

This commit is contained in:
Vasily Zubarev 2023-01-27 15:03:27 +01:00
parent 5bb6d3c575
commit 16199815c9
2 changed files with 7 additions and 1 deletions

View File

@ -10,13 +10,16 @@ from notifications.telegram.bot import bot
@receiver(post_save, sender=Comment)
def create_comment(sender, instance, created, **kwargs):
if not created:
return
return # skip updates
comment = instance
post = comment.post
link = f"https://{settings.APP_HOST}/{post.type}/{post.slug}/"
if not post.is_published():
link += "?preview=1"
if comment.block:
link += f"#block-{comment.block}-{comment.id}"
else:

View File

@ -71,6 +71,9 @@ class Post(models.Model):
self.updated_at = datetime.utcnow()
return super().save(*args, **kwargs)
def is_published(self):
return self.is_visible and self.published_at < datetime.utcnow()
def get_absolute_url(self):
if self.url:
return self.url