更新会话列表

This commit is contained in:
2025-12-03 14:29:55 +08:00
parent c4f64e73be
commit 1eb3a46ea2
3 changed files with 26 additions and 7 deletions

View File

@@ -51,8 +51,6 @@ class ChatMessage extends BaseModel
}else {
$lastMsg = '';
}
if($session['chat_type'] == 1) {
$chat_user = Db::name('chat_user')->where(['user_id' => $session['group_id']])->field('nick_name,avatar')->find();
$avatar = $chat_user['avatar'];
@@ -89,11 +87,30 @@ class ChatMessage extends BaseModel
$data[$i]['group_id'] = $group_id;
$i ++;
}
// Redis::set('usermsg:list:' . $user_type . ':' . $uid, json_encode($data));
Redis::setEx('usermsg:list:' . $user_type . ':' . $uid, 30 * 86400, json_encode($data));
}
return $data;
}
// 更新会话列表
public static function updateConverList($uid, $user_type, $session_id)
{
$is_update = false;
$list_json = Redis::get('usermsg:list:' . $user_type . ':' . $uid);
if($list_json) {
$list_arr = json_decode($list_json, true);
foreach ($list_arr as $k => $list) {
if($list['session_id'] == $session_id) {
$is_update = true;
}
}
}
if($is_update) {
self::getconverlist($uid, $user_type);
}
}
public static function getUserIsQuit($uid, $group_id)
{
// $auit = Db::name('')->where()->find();

View File

@@ -282,6 +282,8 @@ namespace extend\chat\model;
Db::name('chat_unread_count')->where(['user_id' => $grep['user_id'], 'session_id' => $session_id])->inc('count')->update(['updated_time' => d()]);
}
}
// 更新对方会话列表
ChatMessage::updateConverList($grep['user_id'], $user_type, $session_id);
}
}
}

View File

@@ -8,7 +8,7 @@ use support\Redis;
class Business
{
// 存消息
// 存消息 未读消息保存30天 30天以后自动删除
public static function setRedisMessage($uid, $user_type, $data, $open_id = '')
{
$str_uid = Base::getUid($uid, $user_type);
@@ -19,11 +19,11 @@ class Business
if($sent) {
$sent = json_decode($sent, true);
$sent[count($sent)] = $set_info_str;
Redis::set($set_str, json_encode($sent));
Redis::setEx($set_str, 30 * 86400, json_encode($sent));
}else {
Redis::set($set_str, json_encode([$set_info_str]));
Redis::setEx($set_str, 30 * 86400, json_encode([$set_info_str]));
}
Redis::set($set_info_str, json_encode($data));
Redis::setEx($set_info_str, 30 * 86400, json_encode($data));
if($open_id) {