feat: Add recent published section and filter self-interactions
- Add "Publicaciones Recientes" section to dashboard showing published posts - Filter out self-generated interactions in X API (thread auto-replies) - Improve username resolution for X interactions using user expansions - Pass recent_published data to dashboard template Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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]
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user