Commit 8c77c525 by Lee Munkyeong

オフライン対応

parent 259e877d
......@@ -15,7 +15,8 @@ import jp.agentec.adf.util.DateTimeUtil;
public class RoomListJSON extends AcmsCommonJSON {
private static final String Body = "body";
private static final String ChatRoomInfoList = "chatRoomInfoList";
private static final String MessageInsertDate = "messageInsertDate";
private static final String InsertDate = "insertDate";
private static final String Time = "time";
private static final String RoomId = "roomId";
private static final String RoomName = "roomName";
private static final String RoomType = "roomType";
......@@ -57,21 +58,13 @@ public class RoomListJSON extends AcmsCommonJSON {
//最後メッセージ情報がある場合の処理
JSONObject lastMessageInfoJSON = roomListJsonArray.getJSONObject(listCount).has(LastMessageInfo) ? roomListJsonArray.getJSONObject(listCount).getJSONObject(LastMessageInfo) : null;
if (lastMessageInfoJSON != null) {
if (lastMessageInfoJSON != null && lastMessageInfoJSON.has(MessageId)) {
chatMessageDto.chatRoomId = chatRoomDto.chatRoomId;
chatMessageDto.message = lastMessageInfoJSON.getString(Message);
chatMessageDto.messageType = lastMessageInfoJSON.getInt(MessageType);
lastMessageInfoJSON.getJSONObject(MessageInsertDate);
//TODO Change InsertDate Type
chatMessageDto.insertDate = lastMessageInfoJSON.getString(MessageInsertDate);
if (lastMessageInfoJSON.has(MessageInsertDate)) {
chatMessageDto.insertDate = DateTimeUtil.toDate(lastMessageInfoJSON.getString(MessageInsertDate), DateTimeFormat.yyyyMMddHHmmss_hyphen);
if (lastMessageInfoJSON.has(InsertDate)) {
chatMessageDto.insertDate = DateTimeUtil.millToDateString(lastMessageInfoJSON.getJSONObject(InsertDate).getLong(Time));
}
chatMessageDto.shopMemberId = lastMessageInfoJSON.getInt(ShopMemberId);
chatMessageDto.chatMessageId = lastMessageInfoJSON.getInt(MessageId);
chatRoomDto.lastMessageInfo = chatMessageDto;
......
......@@ -67,7 +67,7 @@ public class ChatMessageDao extends AbstractDao {
}
public void insertChatMessage(ChatMessageDto dto) {
insert("insert into t_chat_message (chat_message_id, chat_room_id, shop_member_id, message, message_type, image_name, download_file_name, save_path, insert_date) values (?,?,?,?,?,?,?,?)", dto.getInsertValues());
insert("insert into t_chat_message (chat_message_id, chat_room_id, shop_member_id, message, message_type, image_name, download_file_name, save_path, insert_date) values (?,?,?,?,?,?,?,?,?)", dto.getInsertValues());
}
public boolean updateChatMessage(ChatMessageDto dto) {
......
......@@ -80,6 +80,7 @@ public class ChatRoomDao extends AbstractDao {
sql.append(" ( SELECT max(insert_date) insert_date, message, message_type, chat_room_id FROM t_chat_message GROUP BY chat_room_id ) AS cm ");
sql.append(" ON cr.chat_room_id = cm.chat_room_id ");
sql.append(" GROUP BY cr.chat_room_id ");
sql.append(" ORDER BY cm.insert_date DESC ");
List<ChatRoomDto> list = rawQueryGetDtoList(sql.toString(), null, ChatRoomDto.class);
return list;
}
......@@ -93,7 +94,7 @@ public class ChatRoomDao extends AbstractDao {
}
public void insertChatRoom(ChatRoomDto dto) {
insert("insert into t_chat_room (chat_room_id, chat_room_name, type, unread_count, user_count, favorite_register_date) values (?,?,?,?)", dto.getInsertValues());
insert("insert into t_chat_room (chat_room_id, chat_room_name, type, unread_count, user_count, favorite_register_date) values (?,?,?,?,?,?)", dto.getInsertValues());
}
public boolean updateChatRoom(ChatRoomDto dto) {
......
......@@ -19,7 +19,7 @@ public class MShopMember extends SQLiteTableScript {
sql.append(" shop_member_id INTEGER NOT NULL ");
sql.append(" , shop_member_name VARCHAR(64) ");
sql.append(" , profile_url VARCHAR(64) ");
sql.append(" , favorite_register_date DATETIME ");
sql.append(" , favorite_register_date VARCHAR2(64) ");
sql.append(" , PRIMARY KEY (shop_member_id) ");
sql.append(" ) ");
......
......@@ -24,7 +24,7 @@ public class TChatMessage extends SQLiteTableScript {
sql.append(" , image_name VARCHAR2 ");
sql.append(" , download_file_name VARCHAR2 ");
sql.append(" , save_path VARCHAR2 ");
sql.append(" , insert_date DATETIME");
sql.append(" , insert_date VARCHAR2(64)");
sql.append(" , PRIMARY KEY (chat_message_id) ");
sql.append(" ) ");
......
......@@ -21,7 +21,7 @@ public class TChatRoom extends SQLiteTableScript {
sql.append(" , type INTEGER NOT NULL ");
sql.append(" , unread_count INTEGER ");
sql.append(" , user_count INTEGER ");
sql.append(" , favorite_register_date DATETIME ");
sql.append(" , favorite_register_date VARCHAR2(64) ");
sql.append(" , PRIMARY KEY (chat_room_id) ");
sql.append(" ) ");
......
......@@ -11,10 +11,11 @@ public class ChatMessageDto extends AbstractDto {
public String imageName;
public String downloadFileName;
public String savePath;
public Date insertDate;
public String insertDate;
@Override
public Object[] getInsertValues() {
Object[] test = new Object[]{chatMessageId, chatRoomId, shopMemberId, message, messageType, imageName, downloadFileName, savePath, insertDate};
return new Object[]{chatMessageId, chatRoomId, shopMemberId, message, messageType, imageName, downloadFileName, savePath, insertDate};
}
......
......@@ -8,12 +8,12 @@ public class ChatRoomDto extends AbstractDto {
public Integer chatRoomId;
public String chatRoomName;
public Integer type;
public Date favoriteRegisterDate;
public String favoriteRegisterDate = "";
public Integer unreadCount;
public Integer userCount;
public String message;
public Integer messageType;
public Date insertDate;
public String insertDate;
public ChatMessageDto lastMessageInfo;
@Override
......
......@@ -6,7 +6,7 @@ public class ShopMemberDto extends AbstractDto {
public Integer shopMemberId;
public String shopMemberName;
public String profileUrl;
public Date favoriteRegisterDate;
public String favoriteRegisterDate;
@Override
public Object[] getInsertValues() {
......
......@@ -88,7 +88,9 @@ public class CommunicationLogic extends AbstractLogic {
public void insertChatRoomList(List<ChatRoomDto> roomList) {
for (ChatRoomDto chatRoomDto : roomList) {
chatRoomDao.insertChatRoom(chatRoomDto);
chatMessageDao.insertChatMessage(chatRoomDto.lastMessageInfo);
if (chatRoomDto.lastMessageInfo != null) {
chatMessageDao.insertChatMessage(chatRoomDto.lastMessageInfo);
}
}
}
......
......@@ -584,4 +584,13 @@ public class DateTimeUtil {
return calendar1.before(calendar2);
}
public static String millToDateString(long mills) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Date timeInDate = new Date(mills);
String timeInFormat = sdf.format(timeInDate);
return timeInFormat;
}
}
......@@ -23,15 +23,11 @@
let IS_ONLINE = false;
function getGlobalParam(chatServerUrl, cmsServerUrl, platform, isMobile, isOnline) {
console.log('TEST get GP');
CHAT_SERVER_URL = chatServerUrl;
CMS_SERVER_URL = cmsServerUrl;
PLATFORM = platform;
IS_MOBILE = isMobile;
IS_ONLINE = isOnline;
console.log(CHAT_SERVER_URL);
console.log(CMS_SERVER_URL);
console.log(isOnline);
};
android.getGlobalParameter();
......
......@@ -50,9 +50,7 @@ $('#createChatRoom').on('click', function(){
let isInvite = false;
CHAT.globalIsInvite = isInvite;
CHAT_UI.loadInviteScreen(isInvite);
//socket.emit('getGroupList', isInvite);
socket.emit('getGroupList', isInvite);
});
// Room Delete
......@@ -769,9 +767,7 @@ CHAT_UI.waitForLoadingImage = function(div, callback) {
}
CHAT_UI.refreshRoomList = function() {
var rooms = CHAT_DB.getRoomList();
console.log(rooms);
CHAT.globalIsInvite = false;
activeRoomId = null;
// #36146に対応
......@@ -794,7 +790,7 @@ CHAT_UI.refreshRoomList = function() {
}
// チャットルームの様式を読み込む
const template = $('#room-template').html();
rooms.forEach( function(room) {
rooms.forEach(function(room) {
room.profileImagePath = ASSET_PATH + 'images/user-profile.png'
if (room.message) {
room.message = room.message.toString()
......@@ -803,46 +799,27 @@ CHAT_UI.refreshRoomList = function() {
}
var displayMsg;
//TODO 協業の場合処理追加必要
if (room.messageType == 0 || room.messageType == 3) displayMsg = room.message;
if (room.messageType == 1 || room.messageType == 2) displayMsg = getLocalizedString("image");
console.log(displayMsg);
if (room.messageType == messageType.TEXT || room.messageType == messageType.TEXT) displayMsg = room.message;
if (room.messageType == messageType.IMAGE || room.messageType == messageType.SYSTEM) displayMsg = getLocalizedString("image");
let html = Mustache.render(template, {
roomName: room.chatRoomName,
roomId: room.chatRoomId,
profileImage: room.profileImagePath,
active: activeRoomId === room.chatRoomId ? 'active_chat' : null, // 現在、入っているルームだとhilight表示
lastMessage: displayMsg ,
time: '',
unreadMsgCnt: room.unreadCount,
time: room.insertDate ? CHAT_UTIL.formatDate(room.insertDate).createdAt : '',
unreadMsgCnt: room.unreadCount == 0 ? '' : room.unreadCount,
userCnt: room.userCount
});
console.log('TestPoint1');
// Click event
let obj = $(jQuery.parseHTML(html)).on('click',function(){
/*if (activeRoomId === room.roomId) {
// 既存チャットルームをタッチする場合、チャット画面に遷移
$('#pills-chat-tab').tab('show');
} else {
// loadingIndicatorを表示しない
CHAT_UI.showLoadingIndicator();
// 新しいチャットルームをタッチする場合、チャットルームの接続処理を実行
socket.emit('joinRoom', room.roomId, room.roomName, function (){
CHAT.saveRoomInfo(room.roomId, room.roomName);
$('#messages').html('');
// チャットルーム名を変更する
$('.titleRoomName').text(room.roomName).data('roomName', room.roomName);
});
}*/
let obj = $(jQuery.parseHTML(html)).on('click', function() {
//TODO ルームに入る処理追加必要
});
// チャットルームリストに追加する
$('#room_list').append(obj);
});
console.log('TestPoint2');
if(rooms.length > 0) {
console.log('TestPoint3');
if(!keywordSearchMode) {
if (rooms.length > 0) {
if (!keywordSearchMode) {
$(".roomListIcon").show()
$('#roomDeleteButton, #arrangeRooms').show()
} else {
......@@ -850,94 +827,22 @@ CHAT_UI.refreshRoomList = function() {
$('#roomDeleteButton, #arrangeRooms').hide()
}
} else {
console.log('TestPoint4');
if(!keywordSearchMode) {
if (!keywordSearchMode) {
$(".roomListIcon").hide()
} else {
$(".roomListIcon").show()
$('#roomDeleteButton, #arrangeRooms').hide()
}
}
console.log('TestPoint5');
$('#createChatRoom').show();
console.log($('#createChatRoom'));
if(CHAT_UI.isLandscapeMode()) {
if (CHAT_UI.isLandscapeMode()) {
$(".chat_list").removeClass("col-12").addClass("col-6");
}
$("#userSelectionDeleteBtn").hide();
// チャットルームリスト画面に遷移
$('#pills-chatlist-tab').tab('show');
// loadingIndicatorを表示しない
console.log('TestPoint6');
// loadingIndicatorを表示しない
CHAT_UI.dismissLoadingIndicator();
};
CHAT_UI.loadInviteScreen = function(isInvite){
var groups = [];
$('#group_list').html('');
const template = $('#group-template').html();
if (groups.length === 0) {
$('#group_list').append('<center class="text-secondary">'+ getLocalizedString('everyoneIsHere') +'</center>');
}
// グループ名と人数を表記する。
groups.forEach( function(group) {
let html = Mustache.render(template, {
name: group.groupName,
info: group.memberCnt + getLocalizedString("people")
});
// グループをクリックすると、該当グループのユーザーリストを読み込むようにイベントを与える
let obj = $(jQuery.parseHTML(html)).on('click',function(){
// loadingIndicatorを表示
CHAT_UI.showLoadingIndicator();
//TODO ソケットでなくローカルDBより画面を構成するように修正必要。
//socket.emit('getUserListInGroup', group.groupId, isInvite);
$('#groupName').text(group.groupName);
});
$('#group_list').append(obj);
});
// Rotate
if(CHAT_UI.isLandscapeMode()) {
$(".group_list").addClass("col-6").removeClass("col-12");
}
// Set Title
let memberSelectTitle = getLocalizedString("groupSearch")
$('#pills-group-tab').tab('show');
$('#backButton').show();
if (isInvite) {
$('.titleRoomName').text(memberSelectTitle);
$('#newRoomName, .roomListIcon, .chatRoomIcon').hide();
$('#userSelectionConfirmBtn').show();
$("#userSelectionConfirmBtn").off().on('click', function(){
CHAT_UI.setConfirmButtonEvent(isInvite);
});
} else {
$('.titleRoomName').text(memberSelectTitle);
$('.roomListIcon, .chatRoomIcon, #newRoomName').hide();
$('#userSelectionConfirmBtn').show();
$("#userSelectionConfirmBtn").off().on('click', function(){
CHAT_UI.setConfirmButtonEvent(isInvite);
});
}
if (CHAT.globalSelectedUserList.length > 0) {
$('#userSelectionLength').text(CHAT.globalSelectedUserList.length);
} else {
$('#userSelectionLength').text('');
}
$('#backButton').off().on('click', function() {
// loadingIndicatorを表示
CHAT_UI.showLoadingIndicator();
if (isInvite) {
$('#pills-chat-tab').tab('show');
} else {
CHAT_UI.refreshRoomList();
}
});
};
\ No newline at end of file
console.log('isOnlineRead');
console.log(IS_ONLINE);
var socket;
connectSocket(IS_ONLINE);
function connectSocket(isOnline) {
console.log(isOnline);
if (isOnline == 'true') {
socket = io(CHAT_SERVER_URL);
setSocketAction();
android.updateRoomList();
CHAT_UI.refreshRoomList();
CHAT_UI.dismissLoadingIndicator();
$('#createChatRoom').show();
} else {
//オフラインの場合、DBからルーム一覧を表示。
if (CHAT_UTIL.isIOS()) {
//TODO IOSの場合
} else if (CHAT_UTIL.isAndroid()) {
$('.overlay').removeClass('active undismissable');
// loadingIndicatorを表示
CHAT_UI.showLoadingIndicator();
// チャットルームに入場する際、sid, loginId, shopName, roomId, roomNameの情報を取得しNodeJsに渡す
android.getLoginParameter();
CHAT_UI.refreshRoomList();
CHAT_UI.dismissLoadingIndicator();
$('#createChatRoom').show();
}
}
......@@ -37,7 +32,6 @@ function connectSocket(isOnline) {
* --------------------------------------------------- */
function setSocketAction () {
socket.on('connect', function (){
console.log('connect');
// socketが接続されたらチャット画面で画面を更新する
$('.overlay').removeClass('active undismissable');
// loadingIndicatorを表示
......@@ -48,6 +42,7 @@ function setSocketAction () {
} else if (CHAT_UTIL.isAndroid()) {
android.getLoginParameter();
}
CHAT_UI.dismissLoadingIndicator();
});
socket.on('disconnect', function (){
......@@ -60,17 +55,6 @@ function setSocketAction () {
socket.on('connect_error', function (){
console.log('connect_error');
// $('.overlay').addClass('active undismissable');
// #36174
// $("#customAlertTitle").text(getLocalizedString("errorConnect"));
// $("#customAlertOk").text(getLocalizedString("yesTitle"));
//
// $('#customAlert').appendTo("body").modal({
// backdrop: 'static',
// keyboard: false
// })
// .on('click', '#customAlertOk', function(e) {
// });
CHAT_UI.dismissLoadingIndicator();
});
......@@ -81,7 +65,8 @@ function setSocketAction () {
* ---------------------------------------------------------------------- */
// Update Room List
socket.on('refreshRoomList--', function(rooms, activeRoomId = null){
//TODO APIの連動が終わったら削除予定
/*socket.on('refreshRoomList', function(rooms, activeRoomId = null){
CHAT.globalIsInvite = false;
......@@ -182,7 +167,7 @@ function setSocketAction () {
// loadingIndicatorを表示しない
CHAT_UI.dismissLoadingIndicator();
});
});*/
// New Message
// #36170
......@@ -254,12 +239,9 @@ function setSocketAction () {
// #36147
message.message = message.message.toString();
console.log(message.message);
//message.message.replaceAll('/acms',CHAT_SERVER_URL+"/acms");
var replacePath = message.message;
replacePath = replacePath.replaceAll('/acms',CHAT_SERVER_URL+'/acms');
message.message = replacePath;
console.log(message.message);
let html = Mustache.render(template, {
text: message.message,
from: message.loginId,
......@@ -267,7 +249,6 @@ function setSocketAction () {
createdAtDay: messageTime.createdAtDay,
createdAtTime: messageTime.createdAtTime
});
console.log(message.message);
html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? CHAT_UTIL.htmlDecode(html) : html;
workVal = html + workVal;
})
......
/**
* Constant定義ファイル
*/
const readyState = {
UNINITIALIZED : 0 ,
LOADING : 1 ,
LOADED : 2 ,
INTERACTIVE : 3 ,
COMPLETED : 4
}
\ No newline at end of file
}
const messageType = {
TEXT : 0 ,
IMAGE : 1 ,
VIDEO : 2 ,
SYSTEM : 3 ,
COMMUNICATION : 4
}
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