Commit ffa0c90b by Kim Peace

Fixed chat room list to show properly

parent 6e009873
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
$("#loadingArea").load("./loading.html"); $("#loadingArea").load("./loading.html");
if (deviceInfo.isAndroid()) { if (deviceInfo.isAndroid()) {
var needHostAlert = android.getExitHostAlert(); const needHostAlert = android.getExitHostAlert();
if (needHostAlert) { if (needHostAlert) {
alert(getLocalizedString("inform_exit_host_collaboration")); alert(getLocalizedString("inform_exit_host_collaboration"));
} }
......
...@@ -87,13 +87,13 @@ Common.dismissLoadingIndicator = function () { ...@@ -87,13 +87,13 @@ Common.dismissLoadingIndicator = function () {
Common.refreshForOnline = function () { Common.refreshForOnline = function () {
serverInfo.isOnline = "true"; serverInfo.isOnline = "true";
$(".footer_item a").removeClass("ui-state-disabled"); $(".footer_item a").removeClass("ui-state-disabled");
if (ChatList != "undefined") { if (typeof ChatList != "undefined") {
ChatList.refreshForOnline(); ChatList.refreshForOnline();
} }
if (ChatRoom != "undefined") { if (typeof ChatRoom != "undefined") {
ChatRoom.refreshForOnline(); ChatRoom.refreshForOnline();
} }
if (Namecard != "undefined") { if (typeof Namecard != "undefined") {
Namecard.refreshForOnline(); Namecard.refreshForOnline();
} }
}; };
...@@ -101,16 +101,16 @@ Common.refreshForOnline = function () { ...@@ -101,16 +101,16 @@ Common.refreshForOnline = function () {
Common.refreshForOffline = function () { Common.refreshForOffline = function () {
serverInfo.isOnline = "false"; serverInfo.isOnline = "false";
$(".footer_item a").addClass("ui-state-disabled"); $(".footer_item a").addClass("ui-state-disabled");
if (ChatList != "undefined") { if (typeof ChatList != "undefined") {
ChatList.refreshForOffline(); ChatList.refreshForOffline();
} }
if (ChatRoom != "undefined") { if (typeof ChatRoom != "undefined") {
ChatRoom.refreshForOffline(); ChatRoom.refreshForOffline();
} }
if (CollaborationUI != "undefined") { if (typeof CollaborationUI != "undefined") {
CollaborationUI.refreshForOffline(); CollaborationUI.refreshForOffline();
} }
if (Namecard != "undefined") { if (typeof Namecard != "undefined") {
Namecard.refreshForOffline(); Namecard.refreshForOffline();
} }
}; };
...@@ -120,21 +120,19 @@ Common.refreshForOffline = function () { ...@@ -120,21 +120,19 @@ Common.refreshForOffline = function () {
Common.getProfileImgUrl = function (path) { Common.getProfileImgUrl = function (path) {
if (path == undefined || path == "") { if (path == undefined || path == "") {
return "./img/noImage.png"; return "./img/noImage.png";
} else if (path.includes("/mnt")) {
const userInfo = path.split("/").reverse();
return (
serverInfo.cmsURL +
"/chatapi/user?profileFileName=" +
userInfo[0] +
"&profileGetLoginId=" +
userInfo[1] +
"&sid=" +
currentUserInfo.sid +
"&cmd=12"
);
} else { } else {
if (path.includes("/mnt")) { return path;
const userInfo = path.split("/").reverse();
return (
serverInfo.cmsURL +
"/chatapi/user?profileFileName=" +
userInfo[0] +
"&profileGetLoginId=" +
userInfo[1] +
"&sid=" +
currentUserInfo.sid +
"&cmd=12"
);
} else {
return path;
}
} }
}; };
...@@ -9,10 +9,11 @@ $("#tabGroup").on("click", function (e) { ...@@ -9,10 +9,11 @@ $("#tabGroup").on("click", function (e) {
}); });
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
bindChatSearch(); ChatList.bindChatSearch();
Common.dismissLoadingIndicator();
}); });
var bindChatSearch = function () { ChatList.bindChatSearch = function () {
const chatSearchInput = $('#chat .search_form input[type="search"]'); const chatSearchInput = $('#chat .search_form input[type="search"]');
const chatSearchCancel = $("#chat .search_form .cancel"); const chatSearchCancel = $("#chat .search_form .cancel");
chatSearchInput.click(function () { chatSearchInput.click(function () {
...@@ -62,6 +63,7 @@ ChatList.refreshRoomList = function (roomType) { ...@@ -62,6 +63,7 @@ ChatList.refreshRoomList = function (roomType) {
} else { } else {
Common.refreshForOffline(); Common.refreshForOffline();
} }
const beforeRoomType = NativeBridgeDataSource.getBeforeRoomType(); const beforeRoomType = NativeBridgeDataSource.getBeforeRoomType();
if (beforeRoomType != null) { if (beforeRoomType != null) {
...@@ -69,51 +71,36 @@ ChatList.refreshRoomList = function (roomType) { ...@@ -69,51 +71,36 @@ ChatList.refreshRoomList = function (roomType) {
NativeBridgeDelegate.clearBeforeRoomType(); NativeBridgeDelegate.clearBeforeRoomType();
} }
Common.showLoadingIndicator(); Common.showLoadingIndicator();
if (roomType == ChatRoomType.DM) {
$("#tabDM").prop("checked", true);
} else {
$("#tabGroup").prop("checked", true);
}
// select tab as room type
ChatList.selectTab(roomType);
// update room info in native db
if (serverInfo.isOnline == "true") { if (serverInfo.isOnline == "true") {
NativeBridgeDelegate.updateRoomList(); NativeBridgeDelegate.updateRoomList();
} }
var rooms = NativeBridgeDataSource.getRoomList(roomType, null);
// #36146に対応 // get room list from native db
$("#groupChatList").empty(); const rooms = NativeBridgeDataSource.getRoomList(roomType, null);
$("#dmChatList").empty();
let roomListTitle = getLocalizedString("roomListTitle"); // Room list 初期化
$("#chatTitle").text(roomListTitle); ChatList.initializeRoomList();
// set room title
ChatList.setRoomTitle();
// メッセージがない時、最新メッセージにempty messageを追加
if (rooms.length === 0) { if (rooms.length === 0) {
addEmptyRoomListLabel(roomType); ChatList.addEmptyRoomListLabel(roomType);
} }
const template = getTemplate(TemplateURL.ROOM_LIST); // リストにルームを追加
ChatList.appendRoomList(rooms);
rooms.forEach(function (room) {
let html = renderRoom(template, room);
// Click event
let obj = $(jQuery.parseHTML(html)).on("click", function () {
//TODO ルームに入る処理追加必要
});
// ルームグループごとに追加。
switch (roomType) {
case ChatRoomType.GROUP:
$("#groupChatList").append(obj);
break;
case ChatRoomType.DM:
$("#dmChatList").append(obj);
break;
default:
break;
}
});
Common.dismissLoadingIndicator(); Common.dismissLoadingIndicator();
}; };
var addEmptyRoomListLabel = function (roomType) { ChatList.addEmptyRoomListLabel = function (roomType) {
// 検索結果がない場合のメッセージを追加 // 検索結果がない場合のメッセージを追加
const emptyListString = getLocalizedString("roomListEmptyString"); const emptyListString = getLocalizedString("roomListEmptyString");
switch (roomType) { switch (roomType) {
...@@ -131,7 +118,40 @@ var addEmptyRoomListLabel = function (roomType) { ...@@ -131,7 +118,40 @@ var addEmptyRoomListLabel = function (roomType) {
} }
}; };
var getDefaultChatRoomName = function (roomAttendUsers) { ChatList.selectTab = function (roomType) {
if (roomType == ChatRoomType.DM) {
$("#tabDM").prop("checked", true);
} else {
$("#tabGroup").prop("checked", true);
}
};
ChatList.initializeRoomList = function () {
// #36146に対応
$("#groupChatList").empty();
$("#dmChatList").empty();
};
ChatList.setRoomTitle = function () {
let roomListTitle = getLocalizedString("roomListTitle");
$("#chatTitle").text(roomListTitle);
};
ChatList.appendRoomList = function (rooms) {
const template = getTemplate(TemplateURL.ROOM_LIST);
rooms.forEach(function (room) {
let html = ChatList.renderRoom(template, room);
let obj = jQuery.parseHTML(html);
if (room.type.toString() == ChatRoomType.GROUP) {
$("#groupChatList").append(obj);
} else if (room.type.toString() == ChatRoomType.DM) {
$("#dmChatList").append(obj);
}
});
};
ChatList.getDefaultChatRoomName = function (roomAttendUsers) {
let attendUserName = []; let attendUserName = [];
roomAttendUsers.forEach(function (user) { roomAttendUsers.forEach(function (user) {
user.profileUrl = Common.getProfileImgUrl(user.profileUrl); user.profileUrl = Common.getProfileImgUrl(user.profileUrl);
...@@ -141,7 +161,7 @@ var getDefaultChatRoomName = function (roomAttendUsers) { ...@@ -141,7 +161,7 @@ var getDefaultChatRoomName = function (roomAttendUsers) {
return attendUserName.join(", "); return attendUserName.join(", ");
}; };
var getUnreadCount = function (roomUnreadCount) { ChatList.getUnreadCount = function (roomUnreadCount) {
if (roomUnreadCount == 0) { if (roomUnreadCount == 0) {
return ""; return "";
} else if (roomUnreadCount > 999) { } else if (roomUnreadCount > 999) {
...@@ -158,9 +178,9 @@ ChatList.searchRoom = function (keyword, rooms) { ...@@ -158,9 +178,9 @@ ChatList.searchRoom = function (keyword, rooms) {
let roomListTitle = getLocalizedString("room_search_placeholder"); let roomListTitle = getLocalizedString("room_search_placeholder");
$("#chatTitle").text(roomListTitle); $("#chatTitle").text(roomListTitle);
var template = getTemplate(TemplateURL.ROOM_LIST); const template = getTemplate(TemplateURL.ROOM_LIST);
rooms.forEach(function (room) { rooms.forEach(function (room) {
let html = renderRoom(template, room); let html = ChatList.renderRoom(template, room);
// Click event // Click event
let obj = jQuery.parseHTML(html); let obj = jQuery.parseHTML(html);
...@@ -173,7 +193,7 @@ ChatList.searchRoom = function (keyword, rooms) { ...@@ -173,7 +193,7 @@ ChatList.searchRoom = function (keyword, rooms) {
} }
}; };
var getRoomMessage = function (message) { ChatList.getRoomMessage = function (message) {
if (message) { if (message) {
return message.toString(); return message.toString();
} else { } else {
...@@ -181,7 +201,7 @@ var getRoomMessage = function (message) { ...@@ -181,7 +201,7 @@ var getRoomMessage = function (message) {
} }
}; };
var getDisplayMessage = function (messageType, roomMessage) { ChatList.getDisplayMessage = function (messageType, roomMessage) {
switch (messageType) { switch (messageType) {
case MessageType.TEXT: case MessageType.TEXT:
return roomMessage; return roomMessage;
...@@ -200,20 +220,34 @@ var getDisplayMessage = function (messageType, roomMessage) { ...@@ -200,20 +220,34 @@ var getDisplayMessage = function (messageType, roomMessage) {
} }
}; };
var renderRoom = function (template, room) { ChatList.renderRoom = function (template, room) {
// thumbnail counts
const thumbnailCount = Math.min(room.attendUsers.length, 4);
// set room name
if (room.chatRoomName == "") {
room.chatRoomName = ChatList.getDefaultChatRoomName(room.attendUsers);
}
// set profile images
room.profileImagePath = "./images/user-profile.png"; room.profileImagePath = "./images/user-profile.png";
const roomMessage = getRoomMessage(room.message); room.attendUsers.forEach(function (user) {
const displayMessage = getDisplayMessage(room.messageType, roomMessage); user.profileUrl = Common.getProfileImgUrl(user.profileUrl);
});
// set room messages
const roomMessage = ChatList.getRoomMessage(room.message);
const displayMessage = ChatList.getDisplayMessage(
room.messageType,
roomMessage
);
const thumbnailCount = // set date string
room.attendUsers.length > 4 ? 4 : room.attendUsers.length;
const time = room.insertDate const time = room.insertDate
? CHAT_UTIL.formatDate(room.insertDate).createdAt ? CHAT_UTIL.formatDate(room.insertDate).createdAt
: ""; : "";
if (room.chatRoomName == "") {
room.chatRoomName = getDefaultChatRoomName(room.attendUsers); const messageUnreadCount = ChatList.getUnreadCount(room.unreadCount);
}
const messageUnreadCount = getUnreadCount(room.unreadCount);
return Mustache.render(template, { return Mustache.render(template, {
thumbnailCount: thumbnailCount, thumbnailCount: thumbnailCount,
...@@ -224,7 +258,7 @@ var renderRoom = function (template, room) { ...@@ -224,7 +258,7 @@ var renderRoom = function (template, room) {
time: time, time: time,
unreadMsgCnt: messageUnreadCount, unreadMsgCnt: messageUnreadCount,
userCnt: room.attendUsers.length + 1, userCnt: room.attendUsers.length + 1,
attendUsers: room.attendUsers, attendUsers: room.attendUsers.splice(0, thumbnailCount),
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment