添加活跃时间

This commit is contained in:
liuwei
2026-01-19 16:42:41 +08:00
parent 99de72a0fb
commit 6629479a66
2 changed files with 22 additions and 0 deletions

View File

@@ -680,3 +680,19 @@ class ContactsDBOperator(BaseDBOperator):
except Exception as e:
self.LOG.error(f"获取所有联系人头像信息失败: {e}")
return []
# 新增更新群成员最后活跃时间接口
def update_chatroom_member_active_time(self, chatroom_id: str, wxid: str) -> bool:
"""更新群成员的最后活跃时间"""
try:
# 只有当成员确实存在时才更新
sql = """
UPDATE t_chatroom_member
SET latest_active_time = CURRENT_TIMESTAMP
WHERE chatroom_id = %s AND wxid = %s
"""
self.execute_update(sql, (chatroom_id, wxid))
return True
except Exception as e:
self.LOG.error(f"更新群{chatroom_id}成员{wxid}活跃时间失败: {e}")
return False

View File

@@ -12,6 +12,7 @@ from threading import Lock
from typing import Dict
from db.connection import DBConnectionManager
from db.contacts_db import ContactsDBOperator
from db.levels_db import LevelsDBOperator
from db.message_storage import MessageStorageDB
# 导入积分系统
@@ -31,6 +32,7 @@ class MessageStorage:
# 获取数据库连接管理器的单例
self.db_manager = DBConnectionManager.get_instance()
self.message_db = MessageStorageDB(self.db_manager)
self.contacts_db = ContactsDBOperator(self.db_manager)
self.points_db = PointsDBOperator(self.db_manager)
# 初始化本地缓存字典,使用 group_id 作为键
@@ -93,6 +95,10 @@ class MessageStorage:
def _archive_message_task(self, msg: WxMessage):
"""实际执行消息存档的任务函数"""
try:
# 更新群成员最后活跃时间
if msg.roomid and msg.roomid.endswith('@chatroom') and msg.sender:
self.contacts_db.update_chatroom_member_active_time(msg.roomid, msg.sender)
# 使用 MessageStorageDB 类存档消息
result = self.message_db.archive_message(msg)
return {