优化代码

main
gzydong 2021-05-22 21:45:18 +08:00
parent 67c0e0adee
commit ddae0895a3
3 changed files with 13 additions and 20 deletions

View File

@ -10,10 +10,6 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Cache\FriendApply;
use App\Cache\FriendRemark;
use App\Cache\ServerRunID;
use App\Model\UsersFriendsApply;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -24,10 +20,12 @@ use App\Amqp\Producer\ChatMessageProducer;
use App\Service\ContactsService; use App\Service\ContactsService;
use App\Service\SocketClientService; use App\Service\SocketClientService;
use App\Service\UserService; use App\Service\UserService;
use App\Cache\ApplyNumCache;
use App\Cache\FriendRemarkCache;
use App\Model\UsersChatList;
use App\Constants\SocketConstants; use App\Constants\SocketConstants;
use App\Model\UsersFriendsApply;
use App\Model\UsersChatList;
use App\Cache\FriendApply;
use App\Cache\FriendRemark;
use App\Cache\ServerRunID;
/** /**
* Class ContactsController * Class ContactsController

View File

@ -60,12 +60,7 @@ class TalkController extends CController
$this->talkService->updateUnreadTalkList($user_id, $list); $this->talkService->updateUnreadTalkList($user_id, $list);
} }
// 获取聊天列表 return $this->response->success($this->talkService->talks($user_id));
if ($rows = $this->talkService->talks($user_id)) {
$rows = arraysSort($rows, 'updated_at');
}
return $this->response->success($rows);
} }
/** /**

View File

@ -57,14 +57,14 @@ class TalkService extends BaseService
$data['friend_id'] = $item['friend_id']; $data['friend_id'] = $item['friend_id'];
$data['group_id'] = $item['group_id']; $data['group_id'] = $item['group_id'];
$data['name'] = ''; // 对方昵称/群名称 $data['name'] = ''; // 对方昵称/群名称
$data['unread_num'] = 0; //未读消息数量
$data['avatar'] = ''; // 默认头像 $data['avatar'] = ''; // 默认头像
$data['remark_name'] = ''; // 好友备注 $data['remark_name'] = ''; // 好友备注
$data['unread_num'] = 0; // 未读消息数量
$data['msg_text'] = '......'; $data['msg_text'] = '......';
$data['updated_at'] = $item['updated_at']; $data['updated_at'] = $item['updated_at'];
$data['online'] = 0; $data['online'] = 0;
$data['not_disturb'] = $item['not_disturb'];
$data['is_top'] = $item['is_top']; $data['is_top'] = $item['is_top'];
$data['not_disturb'] = $item['not_disturb'];
if ($item['type'] == 1) { if ($item['type'] == 1) {
$data['name'] = $item['nickname']; $data['name'] = $item['nickname'];
@ -80,7 +80,7 @@ class TalkService extends BaseService
->where('user1', ($user_id < $item['friend_id']) ? $user_id : $item['friend_id']) ->where('user1', ($user_id < $item['friend_id']) ? $user_id : $item['friend_id'])
->where('user2', ($user_id < $item['friend_id']) ? $item['friend_id'] : $user_id)->first(); ->where('user2', ($user_id < $item['friend_id']) ? $item['friend_id'] : $user_id)->first();
if ($info) { if ($info) {
$data['remark_name'] = ($info->user1 == $item['friend_id']) ? $info->user2_remark : $info->user1_remark; $data['remark_name'] = $info->user1 == $item['friend_id'] ? $info->user2_remark : $info->user1_remark;
FriendRemark::getInstance()->save($user_id, (int)$item['friend_id'], $data['remark_name']); FriendRemark::getInstance()->save($user_id, (int)$item['friend_id'], $data['remark_name']);
} }
@ -505,7 +505,7 @@ class TalkService extends BaseService
* 1,'id' => 1658]] 二维数组 * 1,'id' => 1658]] 二维数组
* @return array|bool * @return array|bool
*/ */
public function mergeForwardRecords(int $user_id, int $receive_id, int $source, $records_ids, array $receive_ids) public function mergeForwardRecords(int $user_id, int $receive_id, int $source, array $records_ids, array $receive_ids)
{ {
// 支持转发的消息类型 // 支持转发的消息类型
$msg_type = [1, 2, 5]; $msg_type = [1, 2, 5];