添加活跃时间
This commit is contained in:
@@ -680,3 +680,19 @@ class ContactsDBOperator(BaseDBOperator):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"获取所有联系人头像信息失败: {e}")
|
self.LOG.error(f"获取所有联系人头像信息失败: {e}")
|
||||||
return []
|
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
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from threading import Lock
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from db.connection import DBConnectionManager
|
from db.connection import DBConnectionManager
|
||||||
|
from db.contacts_db import ContactsDBOperator
|
||||||
from db.levels_db import LevelsDBOperator
|
from db.levels_db import LevelsDBOperator
|
||||||
from db.message_storage import MessageStorageDB
|
from db.message_storage import MessageStorageDB
|
||||||
# 导入积分系统
|
# 导入积分系统
|
||||||
@@ -31,6 +32,7 @@ class MessageStorage:
|
|||||||
# 获取数据库连接管理器的单例
|
# 获取数据库连接管理器的单例
|
||||||
self.db_manager = DBConnectionManager.get_instance()
|
self.db_manager = DBConnectionManager.get_instance()
|
||||||
self.message_db = MessageStorageDB(self.db_manager)
|
self.message_db = MessageStorageDB(self.db_manager)
|
||||||
|
self.contacts_db = ContactsDBOperator(self.db_manager)
|
||||||
|
|
||||||
self.points_db = PointsDBOperator(self.db_manager)
|
self.points_db = PointsDBOperator(self.db_manager)
|
||||||
# 初始化本地缓存字典,使用 group_id 作为键
|
# 初始化本地缓存字典,使用 group_id 作为键
|
||||||
@@ -93,6 +95,10 @@ class MessageStorage:
|
|||||||
def _archive_message_task(self, msg: WxMessage):
|
def _archive_message_task(self, msg: WxMessage):
|
||||||
"""实际执行消息存档的任务函数"""
|
"""实际执行消息存档的任务函数"""
|
||||||
try:
|
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 类存档消息
|
# 使用 MessageStorageDB 类存档消息
|
||||||
result = self.message_db.archive_message(msg)
|
result = self.message_db.archive_message(msg)
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user