Skip to content

Commit ab91a84

Browse files
committed
a
1 parent 0cba373 commit ab91a84

3 files changed

Lines changed: 59 additions & 29 deletions

File tree

src/public/js/im/zalyGroupMsg.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,8 @@ $(document).on("click", ".u2-profile", function () {
11391139

11401140
$(document).on("click", ".chatsession-row", function(){
11411141
var roomType = $(this).attr("roomType");
1142+
var chatSessionId = $(this).attr("chat-session-id");
1143+
updateRoomChatSessionContent(chatSessionId);
11421144
if(roomType == U2_MSG) {
11431145
getFriendProfileByClickChatSessionRow($(this));
11441146
} else {

src/public/js/im/zalyMsg.js

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,10 @@ function removeRoomFromRoomList(chatSessionId)
100100
return roomList;
101101
}
102102

103-
function appendOrInsertRoomList(msg, isInsert, showNotification)
103+
function getMsgContentForChatSession(msg)
104104
{
105-
if(msg != undefined && msg.hasOwnProperty("type") && msg.type == MessageStatus.MessageEventSyncEnd) {
106-
return ;
107-
}
108-
var unReadNum = localStorage.getItem(roomMsgUnReadNum + msg.chatSessionId) ? localStorage.getItem(roomMsgUnReadNum + msg.chatSessionId): 0;
109-
unReadNum = unReadNum > 99 ? "99+" : unReadNum;
110-
var name = msg.roomType == GROUP_MSG ? msg.name : msg.nickname;
111-
var msgType = msg.msgType != undefined ? msg.msgType : msg.type;
112105
var msgContent;
106+
var msgType = msg.msgType != undefined ? msg.msgType : msg.type;
113107

114108
switch (msgType) {
115109
case MessageType.MessageText:
@@ -142,37 +136,55 @@ function appendOrInsertRoomList(msg, isInsert, showNotification)
142136
default:
143137
msgContent = "[暂不支持此类型消息]";
144138
}
139+
return msgContent;
140+
}
141+
142+
function updateRoomChatSessionContentFoMsg(msg, nodes, msgContent) {
143+
var msgTime = msg.msgTime != undefined ? msg.msgTime : msg.timeServer;
144+
msgTime = getRoomMsgTime(msgTime);
145+
var childrens = $(nodes)[0].children;
146+
var unReadNum = getRoomMsgUnreadNum(msg.chatSessionId);
147+
var isMuteNum = localStorage.getItem(msgUnReadMuteKey+msg.chatSessionId);
148+
var isMute = localStorage.getItem(msgMuteKey+msg.chatSessionId);
149+
if(isMuteNum == 1 && isMute == 1) {
150+
$(".room-chatsession-unread_"+msg.chatSessionId)[0].style.display = "none";
151+
$(".room-chatsession-mute-num_"+msg.chatSessionId)[0].style.display = "block";
152+
} else {
153+
if(unReadNum>0 && (msg.chatSessionId != localStorage.getItem(chatSessionIdKey))) {
154+
$(".room-chatsession-unread_"+msg.chatSessionId).html(unReadNum);
155+
$(".room-chatsession-unread_"+msg.chatSessionId)[0].style.display = "block";
156+
$(".room-chatsession-mute-num_"+msg.chatSessionId)[0].style.display = "none";
157+
}
158+
}
159+
if(msgContent != undefined && msgContent.length>0) {
160+
$(childrens[2]).html(msgContent);
161+
}
162+
163+
var subChildrens = $(childrens[1])[0].children;
164+
$(subChildrens[1]).html(msgTime);
165+
}
166+
167+
function appendOrInsertRoomList(msg, isInsert, showNotification)
168+
{
169+
if(msg != undefined && msg.hasOwnProperty("type") && msg.type == MessageStatus.MessageEventSyncEnd) {
170+
return ;
171+
}
172+
var unReadNum = localStorage.getItem(roomMsgUnReadNum + msg.chatSessionId) ? localStorage.getItem(roomMsgUnReadNum + msg.chatSessionId): 0;
173+
unReadNum = unReadNum > 99 ? "99+" : unReadNum;
174+
var name = msg.roomType == GROUP_MSG ? msg.name : msg.nickname;
145175

146176
var nodes = $(".chat_session_id_" + msg.chatSessionId);
147177
var msgTime = msg.msgTime != undefined ? msg.msgTime : msg.timeServer;
148178
msgTime = getRoomMsgTime(msgTime);
179+
var msgContent = getMsgContentForChatSession(msg);
149180

150181
if(isInsert) {
151182
handleRoomListFromLocalStorage(msg);
152183
}
153184

154185
if(nodes.length) {
155186
if($(nodes).attr("msg_time") < msg.timeServer) {
156-
var childrens = $(nodes)[0].children;
157-
var unReadNum = getRoomMsgUnreadNum(msg.chatSessionId);
158-
var isMuteNum = localStorage.getItem(msgUnReadMuteKey+msg.chatSessionId);
159-
var isMute = localStorage.getItem(msgMuteKey+msg.chatSessionId);
160-
if(isMuteNum == 1 && isMute == 1) {
161-
$(".room-chatsession-unread_"+msg.chatSessionId)[0].style.display = "none";
162-
$(".room-chatsession-mute-num_"+msg.chatSessionId)[0].style.display = "block";
163-
} else {
164-
if(unReadNum>0 && (msg.chatSessionId != localStorage.getItem(chatSessionIdKey))) {
165-
$(".room-chatsession-unread_"+msg.chatSessionId).html(unReadNum);
166-
$(".room-chatsession-unread_"+msg.chatSessionId)[0].style.display = "block";
167-
$(".room-chatsession-mute-num_"+msg.chatSessionId)[0].style.display = "none";
168-
}
169-
}
170-
if(msgContent != undefined && msgContent.length>0) {
171-
$(childrens[2]).html(msgContent);
172-
}
173-
174-
var subChildrens = $(childrens[1])[0].children;
175-
$(subChildrens[1]).html(msgTime);
187+
updateRoomChatSessionContentFoMsg(msg, nodes, msgContent);
176188
sortRoomList($(nodes));
177189
}
178190
if(msg.chatSessionId == localStorage.getItem(chatSessionIdKey)) {
@@ -220,6 +232,22 @@ function appendOrInsertRoomList(msg, isInsert, showNotification)
220232
showWebNotification(msg, msgContent);
221233
}
222234
}
235+
////防止两个浏览器开着,点击的时候消息列表的内容不是最新的
236+
function updateRoomChatSessionContent(chatSessionId)
237+
{
238+
var nodes = $(".chat_session_id_" + chatSessionId);
239+
var roomList = handleRoomListFromLocalStorage();
240+
var length = roomList.length;
241+
var i;
242+
for(i =0; i<length; i++) {
243+
var msg = roomList[i];
244+
if(msg.chatSessionId == chatSessionId) {
245+
msg = handleMsgInfo(msg);
246+
var msgContent = getMsgContentForChatSession(msg);
247+
updateRoomChatSessionContentFoMsg(msg, nodes, msgContent);
248+
}
249+
}
250+
}
223251

224252
function handleMsgInfo(msg)
225253
{

src/views/base/template_msg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
<div class="chatsession-row-title nickname_{{chatSessionId}}">{{name}}</div>
297297
<div class="chatsession-row-time" msgTime="{{msgServerTime}}">{{msgTime}}</div>
298298
</div>
299-
<div class="chatsession-row-desc">{{msgContent}}</div>
299+
<div class="chatsession-row-desc chatsession-row-desc-{{chatSessionId}}">{{msgContent}}</div>
300300
{{ if isMute >0 }}
301301
<div class="room-chatsession-mute room-chatsession-mute_{{chatSessionId}}" >
302302
<img src="../../public/img/msg/ic_notification_off.png" class="mute">

0 commit comments

Comments
 (0)