diff --git a/app/api/routes/dashboard.py b/app/api/routes/dashboard.py index ede0590..e25bbd7 100644 --- a/app/api/routes/dashboard.py +++ b/app/api/routes/dashboard.py @@ -73,13 +73,19 @@ async def dashboard_home(request: Request, db: Session = Depends(get_db)): Interaction.responded == False ).order_by(Interaction.interaction_at.desc()).limit(5).all() + # Posts publicados recientemente + recent_published = db.query(Post).filter( + Post.status == "published" + ).order_by(Post.published_at.desc()).limit(5).all() + return templates.TemplateResponse("index.html", { "request": request, "user": user.to_dict(), "stats": stats, "pending_posts": [p.to_dict() for p in pending_posts], "scheduled_posts": [p.to_dict() for p in scheduled_posts], - "recent_interactions": [i.to_dict() for i in recent_interactions] + "recent_interactions": [i.to_dict() for i in recent_interactions], + "recent_published": [p.to_dict() for p in recent_published] }) diff --git a/app/publishers/x_publisher.py b/app/publishers/x_publisher.py index 33c8f71..780ee91 100644 --- a/app/publishers/x_publisher.py +++ b/app/publishers/x_publisher.py @@ -214,30 +214,45 @@ class XPublisher(BasePublisher): return [] async def get_comments(self, post_id: str) -> List[Dict]: - """Obtener respuestas a un tweet.""" + """Obtener respuestas a un tweet (excluyendo las propias).""" if not self.client: return [] try: + # Obtener ID del usuario autenticado para filtrar auto-respuestas + me = self.client.get_me() + my_user_id = str(me.data.id) if me.data else None + # Buscar respuestas al tweet query = f"conversation_id:{post_id}" tweets = self.client.search_recent_tweets( query=query, max_results=50, - tweet_fields=['created_at', 'author_id', 'in_reply_to_user_id'] + tweet_fields=['created_at', 'author_id', 'in_reply_to_user_id'], + user_fields=['username'], + expansions=['author_id'] ) if not tweets.data: return [] + # Crear mapa de usuarios para obtener usernames + users_map = {} + if tweets.includes and 'users' in tweets.includes: + for user in tweets.includes['users']: + users_map[str(user.id)] = user.username + + # Filtrar tweets propios (auto-respuestas del hilo) return [ { "id": str(tweet.id), "text": tweet.text, "author_id": str(tweet.author_id), + "username": users_map.get(str(tweet.author_id), "unknown"), "created_at": tweet.created_at.isoformat() if tweet.created_at else None } for tweet in tweets.data + if str(tweet.author_id) != my_user_id # Excluir tweets propios ] except tweepy.TweepyException: diff --git a/dashboard/templates/index.html b/dashboard/templates/index.html index 1763dd7..202abc8 100644 --- a/dashboard/templates/index.html +++ b/dashboard/templates/index.html @@ -166,6 +166,46 @@ + +
{{ post.content[:120] }}{% if post.content|length > 120 %}...{% endif %}
+No hay publicaciones recientes
+