Commit d57e2d08 by Takuya Ogawa

Merge branch 'features/1.3.0_chat' into 'features/1.3.0'

- redmineのチャットについて

See merge request !55
parents 3080b545 aceb0adc
......@@ -89,10 +89,21 @@ function isLandscapeMode(){
function profileImgPathValidCheck(path, checkProfileExist) {
if (checkProfileExist == 1 && path.length > 0) {
path = './images/user-profile.png'
}
return path;
}
// #36170
function profileImgPathValidCheck2(path) {
if(path == undefined) {
return './images/user-profile.png';
} else if (path == "") {
return './images/user-profile.png';
}
return path
}
window.onload = function(){
let navbarHeight = document.getElementsByClassName("navbar")[0].offsetHeight
$(".tab-pane").css('padding', `${navbarHeight + 'px'} 0px 0px`)
......@@ -222,7 +233,7 @@ socket.on('refreshRoomList', function(rooms, activeRoomId = null){
roomId: room.roomId,
profileImage: room.profileImagePath,
active: activeRoomId === room.roomId ? 'active_chat' : null, //現在、入っているルームだとhilight表示
lastMessage: room.message.includes('<img') ? getLocalizedString("image") : (keywordSearchMode? `${room.message}${getLocalizedString("searchResult")}` : room.message) ,
lastMessage: room.message.includes('<img') ? getLocalizedString("image") : (keywordSearchMode ? `${room.message}${getLocalizedString("searchResult")}` : room.message) ,
time: room.time ? formatDate(room.time.time).createdAt : '',
unreadMsgCnt: room.unreadCnt,
userCnt: room.userCnt
......@@ -417,7 +428,8 @@ jQuery('#roomKeyButton').on('click', function(event) {
/* ---------------------------------------------------------------------- */
// New Message
socket.on('newMessage', function (message){
// #36170
socket.on('newMessage', function (message, roomId, roomName){
let template = jQuery('#message-template').html();
if (message.id === socket.id) {
// ユーザーが送信したメッセージの場合、自分のメッセージ様式を適用して表示する
......@@ -425,8 +437,42 @@ socket.on('newMessage', function (message){
}
let messageTime = formatDate(message.createdAt);
//userProfilePathが使えるpathかをcheckして使えないpathの場合、default画像の経路に変更
message.profileImagePath = profileImgPathValidCheck(message.profileImagePath, message.checkProfileExist)
readStringFromFile(message.from, message.timeStamp, message.userId).then((value) => {
if(value.profileImagePath.length > 0 && value.timeStamp == "0") { //差分がある場合
message.profileImagePath = value.profileImagePath
} else if(value.profileImagePath.length == 0 && value.timeStamp == "0") { //差分がない場合
message.profileImagePath = ""
}
if(message.profileImagePath == undefined) {
socket.emit('getProfileImageBeforeJoinRoom', roomId, roomName, value.shopMemberId, value.timeStamp, (data) => {
saveProfileImageFile(data.loginId, data.shopMemberId, data.timeStamp, data.profileImage)
.then((diffValue) => {
message.profileImagePath = diffValue.profileImagePath;
message.profileImagePath = profileImgPathValidCheck2(message.profileImagePath)
try {
message.text = decodeURIComponent(message.text)
} catch(e) {
message.text = message.text
}
let html = Mustache.render(template, {
text: message.text,
from: message.from,
profileImage: message.profileImagePath,
createdAtDay: messageTime.createdAtDay,
createdAtTime: messageTime.createdAtTime
});
// イメージの場合、img tagを追加する
html = message.text.includes('attachedImages') || message.text.includes('attachedVideos') ? htmlDecode(html) : html;
jQuery('#messages').append(html);
scrollToBottom();
})
})
} else {
message.profileImagePath = profileImgPathValidCheck2(message.profileImagePath)
try {
message.text = decodeURIComponent(message.text)
} catch(e) {
......@@ -444,6 +490,8 @@ socket.on('newMessage', function (message){
html = message.text.includes('attachedImages') || message.text.includes('attachedVideos') ? htmlDecode(html) : html;
jQuery('#messages').append(html);
scrollToBottom();
}
})
});
// Notification
......@@ -469,7 +517,69 @@ jQuery('#messages').scroll(function(){
});
// 新しいメッセージを受信する場合の処理
socket.on('loadMessages', function(messages, shopMemberId){
// #36170
socket.on('loadMessages', function(messages, shopMemberId, users, roomId, roomName){
if(users != undefined) {
var promisesGroup = new Array();
users.forEach((user) => {
//timeStampのCheckして、timeStampが0だったらpromisesGroupに入れない
promisesGroup.push(readStringFromFile(user.loginId, user.timeStamp, user.ShopMemberId == undefined ? user.shopMemberId : user.ShopMemberId));//FIXME: ShopMemberId
});
Promise.all(promisesGroup).then((values) => {
users.forEach((part, index) => {
const value = values.find((value) => {
let shopMemberId = users[index].shopMemberId == undefined ? users[index].ShopMemberId : users[index].shopMemberId
if(value.shopMemberId == shopMemberId) {
if(value.profileImagePath.length > 0 && value.timeStamp == "0") { //差分がある場合
return true
} else if(value.profileImagePath.length == 0 && value.timeStamp != "0") { //差分がない場合
return false
} else {
return true
}
}
})
if(value != undefined) {
users[index].profileImagePath = value.profileImagePath
}
})
var requestList = new Array()
values.forEach((value) => {
if(value.profileImagePath.length == 0 && value.timeStamp != "0"){
requestList.push(value)
}
})
let userList = requestList.map((user) => { return user.shopMemberId })
let timeStamps = requestList.map((user) => { return user.timeStamp })
if(requestList.length > 0) {
//AISDevelop
socket.emit('getProfileImageBeforeJoinRoom', roomId, roomName, userList, timeStamps, (userData) => {
console.log('getProfileImageBeforeJoinRoom callback');
var promisesGroupInDiffer = new Array();
userData.forEach((data) => {
promisesGroupInDiffer.push(saveProfileImageFile(data.loginId, data.shopMemberId, data.timeStamp, data.profileImage));
});
//image change
Promise.all(promisesGroupInDiffer)
.then((diffValues)=> {
diffValues.forEach((differ) => {
//differ object - > loginId, shopMemberId, profileImagePath,
//save end
console.log("differ");
users.forEach((part, index) => {
const value = diffValues.find((value) => {
return value.shopMemberId == users[index].shopMemberId
})
if(value){
users[index].profileImagePath = value.profileImagePath;
}
})
})
let jQueryMessages = jQuery('#messages');
// スクロールの変化を防ぐため以前画面の高さを保存する
let beforeHeight = jQueryMessages.prop('scrollHeight');
......@@ -481,11 +591,15 @@ socket.on('loadMessages', function(messages, shopMemberId){
}
let messageTime = formatDate(message.time.time);
//userProfilePathが使えるpathかをcheckして使えないpathの場合、default画像の経路に変更
message.profileImagePath = profileImgPathValidCheck(message.profileImagePath, message.checkProfileExist)
let user = users.find((user) => user.loginId == message.loginId)
if(user) {
message.profileImagePath = profileImgPathValidCheck2(user.profileImagePath)
} else {
message.profileImagePath = profileImgPathValidCheck2("")
}
// #36147
message.message = message.message.toString()
message.message = message.message.toString();
let html = Mustache.render(template, {
text: message.message,
......@@ -494,7 +608,7 @@ socket.on('loadMessages', function(messages, shopMemberId){
createdAtDay: messageTime.createdAtDay,
createdAtTime: messageTime.createdAtTime
});
html = message.message.includes('attachedImages') ? htmlDecode(html) : html;
html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? htmlDecode(html) : html;
jQueryMessages.prepend(html);
})
// 保存した以前画面の高さで現在のスクロールを設定する
......@@ -502,10 +616,93 @@ socket.on('loadMessages', function(messages, shopMemberId){
// ユーザ削除ボタン表示しない
jQuery("#userSelectionDeleteBtn").hide();
dismissLoadingIndicator();
dismissLoadingIndicator();//add some...
// チャットに遷移する
jQuery('#pills-chat-tab').tab('show');
})
})
//request end
} else {
let jQueryMessages = jQuery('#messages');
// スクロールの変化を防ぐため以前画面の高さを保存する
let beforeHeight = jQueryMessages.prop('scrollHeight');
// 順番でメッセージを画面に追加する
messages.forEach(function(message) {
let template = jQuery('#message-template').html();
if (message.shopMemberId == shopMemberId) {
template = jQuery('#message-template-me').html();
}
let messageTime = formatDate(message.time.time);
let user = users.find((user) => user.loginId == message.loginId)
//userProfilePathが使えるpathかをcheckして使えないpathの場合、default画像の経路に変更
if(user) {
message.profileImagePath = profileImgPathValidCheck2(user.profileImagePath)
} else {
message.profileImagePath = profileImgPathValidCheck2("")
}
// #36147
message.message = message.message.toString();
let html = Mustache.render(template, {
text: message.message,
from: message.loginId,
profileImage: message.profileImagePath,
createdAtDay: messageTime.createdAtDay,
createdAtTime: messageTime.createdAtTime
});
html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? htmlDecode(html) : html;
jQueryMessages.prepend(html);
})
// 保存した以前画面の高さで現在のスクロールを設定する
jQueryMessages.scrollTop(jQueryMessages.prop('scrollHeight') - beforeHeight);
// ユーザ削除ボタン表示しない
jQuery("#userSelectionDeleteBtn").hide();
dismissLoadingIndicator();//add some...
// チャットに遷移する
jQuery('#pills-chat-tab').tab('show');
}
})
} else {
let jQueryMessages = jQuery('#messages');
// スクロールの変化を防ぐため以前画面の高さを保存する
let beforeHeight = jQueryMessages.prop('scrollHeight');
// 順番でメッセージを画面に追加する
messages.forEach(function(message) {
let template = jQuery('#message-template').html();
if (message.shopMemberId == shopMemberId) {
template = jQuery('#message-template-me').html();
}
let messageTime = formatDate(message.time.time);
//userProfilePathが使えるpathかをcheckして使えないpathの場合、default画像の経路に変更
message.profileImagePath = profileImgPathValidCheck2(message.profileImagePath)
//message.profileImagePath = profileImgPathValidCheck(message.profileImagePath, message.checkProfileExist)
// #36147
message.message = message.message.toString();
let html = Mustache.render(template, {
text: message.message,
from: message.loginId,
profileImage: message.profileImagePath,
createdAtDay: messageTime.createdAtDay,
createdAtTime: messageTime.createdAtTime
});
html = message.message.includes('attachedImages') || message.message.includes('attachedVideos') ? htmlDecode(html) : html;
jQueryMessages.prepend(html);
})
// 保存した以前画面の高さで現在のスクロールを設定する
jQueryMessages.scrollTop(jQueryMessages.prop('scrollHeight') - beforeHeight);
// ユーザ削除ボタン表示しない
jQuery("#userSelectionDeleteBtn").hide();
dismissLoadingIndicator();//add some...
// チャットに遷移する
jQuery('#pills-chat-tab').tab('show');
}
});
// メッセージ送信
......@@ -999,16 +1196,88 @@ socket.on('refreshGroupList', function(groups, isInvite){
});
// Update User List(Invite)
socket.on('refreshUserListInGroup', function(users, isInvite){
// #36170
socket.on('refreshUserListInGroup', function(users, groupId, isInvite){
jQuery('#user_list').html('');
//promise Array
var promisesGroup = new Array();
users.forEach((user) => {
//timeStamp場合 0を確認, 0なら設定しない
promisesGroup.push(readStringFromFile(user.loginId, user.timeStamp, user.shopMemberId));
});
//promises synchronize
Promise.all(promisesGroup)
.then(values => { // Promise.all(promises)
//渡す値をobjectにする
users.forEach((part, index) => {
const value = values.find((value) => {
if(value.shopMemberId == users[index].shopMemberId) {
if(value.profileImagePath.length > 0 && value.timeStamp == "0") { //차분이 있는 경우
return true
} else if(value.profileImagePath.length == 0 && value.timeStamp != "0") {
return false
} else {
return true
}
}
})
if(value != undefined) {
users[index].profileImagePath = value.profileImagePath
}
})
var requestList = new Array()
values.forEach((value) => {
if(value.profileImagePath.length == 0 && value.timeStamp != "0"){
requestList.push(value)
}
})
let userList = requestList.map((user) => {
return user.shopMemberId
})
let timeStamps = requestList.map((user) => {
return user.timeStamp
})
//AISDevelop
if(userList.length > 0) {
socket.emit('getUserImageDataInGroup', groupId, userList, timeStamps, (userData) => {
var promisesGroupInDiffer = new Array();
userData.forEach((data) => {
if(data.timeStamp != undefined && data.profileImage != undefined) {
promisesGroupInDiffer.push(saveProfileImageFile(data.loginId, data.shopMemberId, data.timeStamp, data.profileImage));
}
});
//image change
Promise.all(promisesGroupInDiffer)
.then(diffValues => {
diffValues.forEach((differ) => {
//differ object - > loginId, shopMemberId, profileImagePath,
//save end
console.log("differ");
users.forEach((part, index) => {
const value = diffValues.find((value) => {
return value.shopMemberId == users[index].shopMemberId
})
if(value){
users[index].profileImagePath = value.profileImagePath;
}
})
})
const template = jQuery('#user-template').html();
users.forEach( function(user) {
//loadingIndicatorを表示
showLoadingIndicator();
user.profileImagePath = profileImgPathValidCheck(user.profileImagePath, user.checkProfileExist);
//user.profileImagePath = profileImgPathValidCheck(user.profileImagePath, user.checkProfileExist);
user.profileImagePath = profileImgPathValidCheck2(user.profileImagePath)
let html = Mustache.render(template, {
id: user.shopMemberId,
profileImage: user.profileImagePath,
......@@ -1021,7 +1290,7 @@ socket.on('refreshUserListInGroup', function(users, isInvite){
//remove
globalSelectedUserList = globalSelectedUserList.filter(function(element) {
return user.loginId != element.loginId;
})
});
} else {
//add
globalSelectedUserList.push({loginId:user.loginId, shopMemberId : user.shopMemberId, profileImagePath: user.profileImagePath});
......@@ -1034,17 +1303,91 @@ socket.on('refreshUserListInGroup', function(users, isInvite){
jQuery('#userSelectionLength').text('');
}
});
//
let findObj = globalSelectedUserList.find(function(selectedUser) {
return selectedUser.loginId == user.loginId;
})
if (findObj) {
jQuery(obj).find('.userCheckBox').toggleClass('active');
}
jQuery('#user_list').append(obj);
})
jQuery('.userCheckBox').show();
// Rotate
if(isLandscapeMode()) {
jQuery(".user_list").addClass("col-6").removeClass("col-12");
$(".squareBoxContent span").addClass("landscape_span");
}
jQuery('#backButton').off().on('click', function() {
//loadingIndicatorを表示
showLoadingIndicator();
socket.emit('getGroupList', isInvite)
});
jQuery("#userSelectionConfirmBtn").off().on('click', function(){
//loadingIndicatorを表示
showLoadingIndicator();
setConfirmButtonEvent(isInvite);
});
jQuery('#backButton').show();
jQuery('.roomListIcon, .chatRoomIcon').hide();
jQuery('#userSelectionConfirmBtn').show();
jQuery('.userCheckBox').show();
jQuery('#pills-user-tab').tab('show');
})
})
} else {
const template = jQuery('#user-template').html();
users.forEach( function(user) {
//loadingIndicatorを表示
showLoadingIndicator();
user.profileImagePath = profileImgPathValidCheck2(user.profileImagePath)
let html = Mustache.render(template, {
id: user.shopMemberId,
profileImage: user.profileImagePath,
name: user.loginId
});
// クリックするとactive クラスを与え、チェック表示を出させる。
let obj = jQuery(jQuery.parseHTML(html)).on('click',function(){
if (jQuery(this).find('.userCheckBox.active').length > 0) {
//remove
globalSelectedUserList = globalSelectedUserList.filter(function(element) {
return user.loginId != element.loginId;
});
} else {
//add
globalSelectedUserList.push({loginId:user.loginId, shopMemberId : user.shopMemberId, profileImagePath: user.profileImagePath});
}
jQuery(this).find('.userCheckBox').toggleClass('active');
if (globalSelectedUserList.length > 0) {
jQuery('#userSelectionLength').text(globalSelectedUserList.length);
} else {
jQuery('#userSelectionLength').text('');
}
});
let findObj = globalSelectedUserList.find(function(selectedUser) {
return selectedUser.loginId == user.loginId;
})
if (findObj) {
jQuery(obj).find('.userCheckBox').toggleClass('active');
}
jQuery('#user_list').append(obj);
})
jQuery('.userCheckBox').show();
// Rotate
if(isLandscapeMode()) {
jQuery(".user_list").addClass("col-6").removeClass("col-12");
......@@ -1057,7 +1400,6 @@ socket.on('refreshUserListInGroup', function(users, isInvite){
socket.emit('getGroupList', isInvite)
});
//
jQuery("#userSelectionConfirmBtn").off().on('click', function(){
//loadingIndicatorを表示
showLoadingIndicator();
......@@ -1069,6 +1411,8 @@ socket.on('refreshUserListInGroup', function(users, isInvite){
jQuery('#userSelectionConfirmBtn').show();
jQuery('.userCheckBox').show();
jQuery('#pills-user-tab').tab('show');
}
});
});
// グループ画面での検索
......@@ -1553,3 +1897,86 @@ function getLoginParameter(sid, loginId, shopName, roomId = undefined, roomName
dismissLoadingIndicator();
});
}
// #36170
function getLocalProfileFilePath(localSavedJsonPath) {
profileJsonFilePath = localSavedJsonPath;
}
//local file save develop part
////////////////////////////////////////////////////////////////////////
// object for storing references to our promise-objects
var promises = new Array();
// generates a unique id, not obligator a UUID
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uuid;
};
// this funciton is called by native methods
// @param promiseId - id of the promise stored in global variable promises
function resolvePromise(promiseId, userId, imagePath, timeStamp, shopMemberId, error) {
let object = new Object()
object.userId = userId;
object.profileImagePath = imagePath;
object.timeStamp = timeStamp;
object.shopMemberId = shopMemberId;
if (error) {
promises[promiseId].reject(error);
} else {
promises[promiseId].resolve(object);
}
}
function saveProfileImageFile(loginId, shopMemberId, timeStamp, profileImage) {
var promise = new Promise(function(resolve, reject) {
// we generate a unique id to reference the promise later
// from native function
var promiseId = generateUUID();
// save reference to promise in the global variable
this.promises[promiseId] = { resolve, reject};
try {
// call native function
android.requestProfileImagesJsonFilePath(promiseId, loginId, timeStamp, shopMemberId, profileImage);
}
catch(exception) {
alert(exception);
}
});
return promise;
}
function fileSaveResolvePromise(promiseId, loginId, profileImagePath, shopMemberId, error) {
let object = new Object();
object.loginId = loginId;
object.profileImagePath = profileImagePath;
object.shopMemberId = shopMemberId;
if (error) {
promises[promiseId].reject(error);
} else {
promises[promiseId].resolve(object);
}
}
function readStringFromFile(loginId, timeStamp, shopMemberId) {
var promise = new Promise(function(resolve, reject) {
var promiseId = generateUUID();
this.promises[promiseId] = { resolve, reject};
try {
android.readFileHandler(promiseId, loginId, timeStamp, shopMemberId);
}
catch(exception) {
alert(exception);
}
});
return promise;
}
......@@ -11,7 +11,7 @@ $.lang.en = {
"roomListEmptyString":"There is no room available.",
"left":"%@ has left",
"join":"%@ has joined",
"added":"%@ has been added",
"added":"%@ has been invited",
"welcome":"Welcome to %@",
"userListDivideString":", ",
"orderByTime":"OrderByTime",
......
......@@ -11,7 +11,7 @@ $.lang.ja = {
"roomListEmptyString":"入場できるルームがありません。",
"left":"%@ 様が退場しました。",
"join":"%@ 様が入場しました。",
"added":"%@ 様がルームに招待されました。",
"added":"%@ 様を招待しました。",
"welcome":"%@ に入場しました。",
"userListDivideString":" 様, ",
"orderByTime":"新着順",
......
......@@ -11,7 +11,7 @@ $.lang.ko = {
"roomListEmptyString":"입장 가능한 방이 없습니다.",
"left":"%@ 님이 방을 떠났습니다.",
"join":"%@ 님이 참가했습니다.",
"added":"%@ 님이 방에 초대되었습니다.",
"added":"%@ 님을 초대했습니다.",
"welcome":"%@ 에 입장했습니다.",
"userListDivideString":" 님, ",
"orderByTime":"최신순",
......
......@@ -90,10 +90,9 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
private BroadcastReceiver receiver;
// 絞り検索マスタ参照パス
// ユーザプロファイルの保存場所パス
private static final String ProfileDirFormat = "%s/ABook/operation/profileimages";
// 絞り検索マスタファイル名
private static final String ProFileName = "profileImages.json";
// private static final String ProfileImgDirFormat = "%s/ABook/operation/profileimages/images";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -127,17 +126,14 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
mChatWebView.addJavascriptInterface(jsInf, "android");
//ページをロード
if(roomId != 0 && roomName != null) { // by push message
// mChatWebView.loadUrl(chatWebviewUrl + "?sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName + "&roomId=" + roomId + "&roomName=" + roomName);
String parameterData = "sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName + "&roomId=" + roomId + "&roomName=" + roomName;
mChatWebView.postUrl(chatWebviewUrl, parameterData.getBytes());
}
else { // Chat
if (lastRoomName.length() > 0 && lastRoomId.length() > 0) {
// mChatWebView.loadUrl(chatWebviewUrl + "?sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName + "&roomId=" + lastRoomId + "&roomName=" + lastRoomName);
String parameterData = "sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName + "&roomId=" + lastRoomId + "&roomName=" + lastRoomName;
mChatWebView.postUrl(chatWebviewUrl, parameterData.getBytes());
} else {
// mChatWebView.loadUrl(chatWebviewUrl + "?sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName);
String parameterData = "sid=" + sid + "&loginId=" + loginId + "&shopName=" + shopName;
mChatWebView.postUrl(chatWebviewUrl, parameterData.getBytes());
}
......@@ -506,6 +502,95 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
}
}
// #36170
// ユーザプロファイルのイメージを求める
public void getrofileImagesJsonFilePath(String promiseId, String loginId, String timeStamp, String shopMemberId, String profileImage) {
String mimeType = "";
String javascript = "";
// Binary からファイルフォマットを取る
if (profileImage.contains("jpg")) {
mimeType = "jpg";
} else if (profileImage.contains("jpeg")) {
mimeType = "jpeg";
} else if (profileImage.contains("png")) {
mimeType = "png";
}
// ファイルパースを生成する。
String profileImagesPath = String.format(ProfileDirFormat, ABVEnvironment.getInstance().rootDirectory) + File.separator + loginId + '_' + timeStamp + "." + mimeType;
// 差分があるアルバあい既存ファイルを確認する
File file = new File(profileImagesPath);
if (file.exists()) {
javascript = String.format("javascript:fileSaveResolvePromise('%s', '%s', '%s', '%s', null);", promiseId, loginId, profileImagesPath, shopMemberId);
mChatWebView.loadUrl(javascript);
return;
}
// 差分がある場合既存ファイルを削除する
// String differceImageFilePath = searchDifferceImageFiles(userID + "_", timeStamp);
// if (deleteTargetFilePath.length() > 0) {
// // ファイルがある場合のみ、削除
// FileUtil.delete(deleteTargetFilePath);
// }
String isError = null;
try {
ABookCheckWebViewHelper.getInstance().decodeToImage(profileImage, profileImagesPath);
} catch (Exception e) {
isError = "Error";
Logger.e(TAG, e);
}
if (isError != null) {
javascript = String.format("javascript:fileSaveResolvePromise('%s', '%s', '%s', '%s', '%s');", promiseId, loginId, profileImagesPath, shopMemberId, isError);
} else {
javascript = String.format("javascript:fileSaveResolvePromise('%s', '%s', '%s', '%s', null);", promiseId, loginId, profileImagesPath, shopMemberId);
}
mChatWebView.loadUrl(javascript);
}
// ユーザプロファイルの差分のためファイル検索
public void getFileHandler(String promiseId, String loginId, String timeStamp, String shopMemberId) {
String javascript = "";
// timeStampが「0」の場合、そのまま値を返す
if (timeStamp.equals("0")) {
//ここに既存のイメージの削除logicが必要だ
String deleteImageFilePath = searchImageFiles(loginId + "_");
if (deleteImageFilePath.length() > 0) {
// ファイルがある場合のみ、削除
if (FileUtil.delete(deleteImageFilePath)) {
Logger.d("Delete imageFile ", "delete file path :" + deleteImageFilePath);
}
}
javascript = String.format("javascript:resolvePromise('%s', '%s', '%s', '%s', '%s', null);", promiseId, loginId, "", "0", shopMemberId); // default
} else {
//差分を確認し差分がある場合、差分対象のファイルのtimeStampを返す
String searchFileInfo = searchDifferceImageFiles(loginId + "_", timeStamp);
String profileImagesPath = "";
// 差分がない場合、同じファイルで
if (searchFileInfo.lastIndexOf(".") > 0) {
profileImagesPath = String.format(ProfileDirFormat, ABVEnvironment.getInstance().rootDirectory) + File.separator + searchFileInfo;
searchFileInfo = "0";
}
// 差分がある場合、既存ファイルのTimeStampでsearchFileInfoにoldTimeStampとして返す
else if (searchFileInfo.length() > 1) {
profileImagesPath = "";
// 差分がない、ファイルがない場合
} else if (searchFileInfo.equals("0")) {
profileImagesPath = "";
searchFileInfo = "20000101121211"; // サーバに差分のファイルを要求するためダミー日付を渡す
}
String error = null;
javascript = String.format("javascript:resolvePromise('%s', '%s', '%s', '%s', '%s', null);", promiseId, loginId, profileImagesPath, searchFileInfo, shopMemberId);
}
mChatWebView.loadUrl(javascript);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
......@@ -595,6 +680,157 @@ public class ChatWebviewActivity extends ParentWebViewActivity {
});
}
// #36170
@JavascriptInterface
public void requestProfileImagesJsonFilePath(final String promiseId, final String loginId, final String timeStamp, final String shopMemberId, final String profileImage) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
getrofileImagesJsonFilePath(promiseId, loginId, timeStamp, shopMemberId, profileImage);
}
});
}
@JavascriptInterface
public String getProfileImage(String loginId) {
String profileImage = searchImageFiles( loginId+"_" );
if (profileImage.length() > 0) {
return profileImage;
} else {
profileImage = "";
}
return profileImage; // logidId, profileimagePath, timestamp
}
@JavascriptInterface
// public String getProfileimageDifference(String loginId, String timeStamp) {
public void getfileimageDifference(String promiseId, String loginId, String timeStamp) {
String profileImageStamp = searchDifferceImageFiles(loginId + "_", timeStamp);
if (profileImageStamp.length() > 0) {
// return profileImageStamp;
} else {
profileImageStamp = "";
}
String javascript = String.format("javascript:resolvePromise('%s', '%s', '%s', null, null);", promiseId, loginId, profileImageStamp);
mChatWebView.loadUrl(javascript);
}
@JavascriptInterface
public void readFileHandler(final String promiseId, final String loginId, final String timeStamp, final String shopMemberId) {
mChatWebView.post(new Runnable() {
@Override
public void run() {
getFileHandler(promiseId, loginId, timeStamp, shopMemberId);
}
});
}
}
// 保存されているユーザプロファイルの場所からファイルを検索
private String searchImageFiles( String loginId ) {
String profileImagePath = "";
String profileImagesJsonPath = String.format(ProfileDirFormat, ABVEnvironment.getInstance().rootDirectory);
List<String> listDirectory = new ArrayList<>();
listDirectory.add(profileImagesJsonPath);
int m = 0;
int n = 0;
String[] fileName;
String imgPath = null;
// dirList.size() は動的変化あり注意
while(listDirectory.size() > m){
// get(m) リスト内の指定された位置 m にある要素を返す
File directory = new File(listDirectory.get(m));
// java.io.File クラスのメソッド list()
// 指定したディレクトリに含まれるファイル、ディレクトリの一覧を String 型の配列で返す。
fileName = directory.list();
if (fileName == null) break;
n = 0;
while(fileName.length > n){
File subFile;
subFile = new File(directory.getPath() + "/" + fileName[n]);
if (subFile.isDirectory()) {
listDirectory.add(directory.getPath() + "/" + fileName[n]);
imgPath = directory.getPath() + "/" + fileName[n];
} else if (subFile.getName().startsWith(loginId)) {
imgPath = directory.getPath() + "/" + fileName[n];
profileImagePath = imgPath;
break;
} else {
profileImagePath = "";
}
n++;
}
m++;
}
return profileImagePath;
}
// User Profile ついて差分を確認する
private String searchDifferceImageFiles( String loginId, String timeStamp ) {
String profileImageTimeStamp = "0";
String profileImagesJsonPath = String.format(ProfileDirFormat, ABVEnvironment.getInstance().rootDirectory);
List<String> listDirectory = new ArrayList<>();
listDirectory.add(profileImagesJsonPath);
int m = 0;
int n = 0;
String[] fileName;
String imgPath = null;
// dirList.size() は動的変化あり注意
while(listDirectory.size() > m){
// get(m) リスト内の指定された位置 m にある要素を返す
File directory = new File(listDirectory.get(m));
// java.io.File クラスのメソッド list()
// 指定したディレクトリに含まれるファイル、ディレクトリの一覧を String 型の配列で返す。
fileName = directory.list();
if (fileName == null) break;
n = 0;
while(fileName.length > n){
File subFile;
subFile = new File(directory.getPath() + "/" + fileName[n]);
if (subFile.isDirectory()) {
listDirectory.add(directory.getPath() + "/" + fileName[n]);
imgPath = directory.getPath() + "/" + fileName[n];
} else if (subFile.getName().startsWith(loginId)) {
imgPath = directory.getPath() + "/" + fileName[n];
fileName[n].substring(0, fileName[n].lastIndexOf(".")); // 拡張子を抜けて比較する
if (!fileName[n].substring(0, fileName[n].lastIndexOf(".")).equals(loginId + timeStamp)) {
// loginId だけ同じファイルの場合timeStampを返す
profileImageTimeStamp = fileName[n].substring(fileName[n].indexOf("_")+1, fileName[n].lastIndexOf("."));
} else if (fileName[n].substring(0, fileName[n].lastIndexOf(".")).equals(loginId + timeStamp)) {
// loginId + timestamp と同じファイルの場合、拡張子を抜けた値を返す
profileImageTimeStamp = fileName[n];
}
break;
} else {
profileImageTimeStamp = "0";
}
n++;
}
m++;
}
return profileImageTimeStamp;
}
/**
......
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