load last 10 messages on chat add
This commit is contained in:
@@ -5,8 +5,9 @@ from tempfile import TemporaryDirectory
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from pyrogram import Chat as PyrogramChat, Message as PyrogramMessage, ChatPhoto as PyrogramChatPhoto
|
||||
from pyrogram.api.types.chat_photo import ChatPhoto as MTProtoChatPhoto
|
||||
from pyrogram import Chat as PyrogramChat, Message as PyrogramMessage
|
||||
|
||||
from aggregator.tasks import collect_new_messages
|
||||
|
||||
|
||||
class AggregationSource(models.Model):
|
||||
@@ -27,7 +28,7 @@ class Chat(models.Model):
|
||||
|
||||
@classmethod
|
||||
def from_obj(cls, chat: PyrogramChat, client):
|
||||
obj, _ = Chat.objects.update_or_create(
|
||||
obj, created = Chat.objects.update_or_create(
|
||||
chat_id=chat.id,
|
||||
defaults={
|
||||
'title': chat.title or '{} {}'.format(chat.first_name, chat.last_name).rstrip(),
|
||||
@@ -47,6 +48,8 @@ class Chat(models.Model):
|
||||
obj.photo.save(os.path.basename(path), f, save=True)
|
||||
obj.photo_id = chat.photo.small_file_id
|
||||
obj.save()
|
||||
if created:
|
||||
collect_new_messages.delay(obj.pk)
|
||||
return obj
|
||||
|
||||
def __str__(self):
|
||||
|
||||
Reference in New Issue
Block a user