99use App \Foundation \Facades \MessageParser ;
1010use App \Model \Auth \User ;
1111use App \Model \Laboratory \FriendChatHistory ;
12+ use App \Model \Laboratory \FriendRelation ;
1213use App \Model \Laboratory \GroupChatHistory ;
1314use App \Pool \Redis ;
1415use App \Service \Laboratory \MessageService ;
@@ -34,6 +35,8 @@ public function sendMessage()
3435
3536 $ contactId = Redis::getInstance ()->hget (ChatRedisKey::ONLINE_USER_FD_KEY , (string )$ contactData ['toContactId ' ]);
3637 $ receptionState = empty ($ contactId ) ? FriendChatHistory::RECEPTION_STATE_NO : FriendChatHistory::RECEPTION_STATE_YES ;
38+ if (!empty ($ name = FriendRelation::getFriendRemarkNameById ($ contactData ['fromUser ' ]['id ' ], $ contactData ['toContactId ' ]))) $ contactData ['fromUser ' ]['displayName ' ] = $ name ;
39+
3740 //添加聊天记录
3841 FriendChatHistory::addMessage ($ contactData , $ receptionState );
3942 $ contactData ['status ' ] = FriendChatHistory::FRIEND_CHAT_MESSAGE_STATUS_SUCCEED ;
@@ -87,6 +90,12 @@ public function pullMessage()
8790
8891 $ list = [];
8992 foreach ($ messageList as $ key => $ value ) {
93+ //获取用户联系人
94+ $ userInfo = User::query ()->select ('id ' , 'desc ' , 'avatar ' )->where ('id ' , $ value ['from_uid ' ])->first ();
95+ $ displayName = $ userInfo ['desc ' ];
96+ $ friendRemark = FriendRelation::query ()->where ('uid ' , $ value ['to_uid ' ])->where ('friend_id ' , $ value ['from_uid ' ])->value ('friend_remark ' );
97+ if (!empty ($ friendRemark ) && $ value ['from_uid ' ] != $ contactData ['user_id ' ]) $ displayName = $ friendRemark ;
98+
9099 $ temp = [
91100 'id ' => $ value ['message_id ' ],
92101 'status ' => $ value ['status ' ],
@@ -99,12 +108,13 @@ public function pullMessage()
99108 'fileExt ' => $ value ['file_ext ' ],
100109 'isGroup ' => false ,
101110 'fromUser ' => [
102- 'id ' => $ value [ ' from_uid ' ],
103- 'avatar ' => User:: query ()-> where ( ' id ' , $ value [ ' from_uid ' ])-> value ( ' avatar ' ) ,
104- 'displayName ' => User:: query ()-> where ( ' id ' , $ value [ ' from_uid ' ])-> value ( ' desc ' ) ,
111+ 'id ' => $ userInfo [ ' id ' ],
112+ 'avatar ' => $ userInfo [ ' avatar ' ] ?? '' ,
113+ 'displayName ' => $ displayName ,
105114 ],
106115 ];
107- if ($ temp ['type ' ] == FriendChatHistory::FRIEND_CHAT_MESSAGE_TYPE_FORWARD ) $ temp ['content ' ] = MessageService::getInstance ()->formatForwardMessage ($ temp ['content ' ], $ temp ['fromUser ' ]);
116+ if ($ temp ['type ' ] == FriendChatHistory::FRIEND_CHAT_MESSAGE_TYPE_FORWARD )
117+ $ temp ['content ' ] = MessageService::getInstance ()->formatForwardMessage ($ temp ['content ' ], $ temp ['fromUser ' ]);
108118 $ list [] = $ temp ;
109119 }
110120 return [
0 commit comments