Commit e9ef8fa4 by Kim Peace

Merge branch 'communication/feature/#43306_push_message_not_in_same_room' into…

Merge branch 'communication/feature/#43306_push_message_not_in_same_room' into 'communication/develop'

Communication/feature/#43306 push message not in same room

See merge request !196
parents 2bf4c869 a94c84ce
package jp.agentec.abook.abv.cl.push; package jp.agentec.abook.abv.cl.push;
import android.app.Activity;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
...@@ -11,13 +12,14 @@ import android.util.Log; ...@@ -11,13 +12,14 @@ import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage; import com.google.firebase.messaging.RemoteMessage;
import org.json.adf.JSONException;
import org.json.adf.JSONObject; import org.json.adf.JSONObject;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import jp.agentec.abook.abv.bl.common.exception.ABVException; import jp.agentec.abook.abv.bl.common.exception.ABVException;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.ChatMessageDto;
import jp.agentec.abook.abv.bl.dto.MemberInfoDto; import jp.agentec.abook.abv.bl.dto.MemberInfoDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic; import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.UserAuthenticateLogic; import jp.agentec.abook.abv.bl.logic.UserAuthenticateLogic;
...@@ -25,15 +27,17 @@ import jp.agentec.abook.abv.cl.util.AppUtil; ...@@ -25,15 +27,17 @@ import jp.agentec.abook.abv.cl.util.AppUtil;
import jp.agentec.abook.abv.launcher.android.R; import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ShowPushMessageDailogActivity; import jp.agentec.abook.abv.ui.common.activity.ShowPushMessageDailogActivity;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType; import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
import jp.agentec.abook.abv.ui.home.activity.ChatWebViewActivity;
import jp.agentec.abook.abv.ui.home.activity.SplashScreenActivity; import jp.agentec.abook.abv.ui.home.activity.SplashScreenActivity;
import jp.agentec.abook.abv.ui.home.helper.ActivityHandlingHelper;
import jp.agentec.adf.util.StringUtil; import jp.agentec.adf.util.StringUtil;
public class ABVFcmListenerService extends FirebaseMessagingService { public class ABVFcmListenerService extends FirebaseMessagingService {
private static final String TAG = "ABVFcmListenerService"; private static final String TAG = "ABVFcmListenerService";
private NotificationManager mNotificationManager; private NotificationManager mNotificationManager;
private static int mNotificationConnect = 0; private static int mNotificationConnect = 0;
private final String INVITE_COLLABORATION = "inviteCollaboration<::split>"; private final String CHAT_MESSAGE_SEPERATOR = "<::split>";
private final String INVITE_COLLABORATION = "inviteCollaboration" + CHAT_MESSAGE_SEPERATOR;
@Override @Override
public void onCreate() { public void onCreate() {
...@@ -57,79 +61,59 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -57,79 +61,59 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
try { try {
UserAuthenticateLogic logic = AbstractLogic.getLogic(UserAuthenticateLogic.class); UserAuthenticateLogic logic = AbstractLogic.getLogic(UserAuthenticateLogic.class);
MemberInfoDto memberInfo = logic.getMemberInfo(); MemberInfoDto memberInfo = logic.getMemberInfo();
if (!StringUtil.isNullOrWhiteSpace(msg.get(AppDefType.PushMessageKey.message)) && this.getResources().getInteger(R.integer.push_message) == 1 && memberInfo != null) { boolean hasMessageBody = !StringUtil.isNullOrWhiteSpace(msg.get(AppDefType.PushMessageKey.message));
boolean isPushMessageEnabled = this.getResources().getInteger(R.integer.push_message) == 1;
if (hasMessageBody && isPushMessageEnabled && memberInfo != null) {
// Check pushmessage by chat // Check pushmessage by chat
String tempMsg = msg.get(AppDefType.PushMessageKey.message); String tempMsg = msg.get(AppDefType.PushMessageKey.message);
String pushMsg = "";
Long roomId = null; Long roomId = null;
String roomName = ""; String roomName = "";
String pushSendLoginId = ""; String pushSendLoginId = "";
long pushSendDate = 0; long pushSendDate = 0;
Integer insertId = 0;
Integer messageType = 0;
Integer messageId = 0;
String roomType = "";
Log.d(TAG,"tempMsg : "+ tempMsg); Log.d(TAG,"tempMsg : "+ tempMsg);
if (tempMsg.indexOf("pushSendLoginId") > 0) { if (Objects.requireNonNull(tempMsg).indexOf(AppDefType.ChatPushMessageKey.pushSendLoginId) > 0) {
JSONObject json = new JSONObject(tempMsg); JSONObject json = new JSONObject(tempMsg);
Object Obj = json.getString("pushSendLoginId"); roomId = json.getLong(AppDefType.ChatPushMessageKey.roomId);
roomName = json.getString(AppDefType.ChatPushMessageKey.roomName);
roomId = json.getLong("roomId"); pushSendLoginId = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId);
roomName = json.getString("roomName"); pushSendDate = json.getLong(AppDefType.ChatPushMessageKey.pushSendDate);
pushSendLoginId = json.getString("pushSendLoginId"); String textMessage = json.getString(AppDefType.PushMessageKey.message);
pushSendDate = json.getLong("pushSendDate");
pushMsg = json.getString("message");
//TODO pushメッセージが到着した際、新着メッセージかルーム招待か判別してDB格納が必要 //TODO pushメッセージが到着した際、新着メッセージかルーム招待か判別してDB格納が必要
//Integer insertId = 0;
//Integer messageType = 0;
//insertId = json.getString("insertId"); //insertId = json.getString("insertId");
//ChatMessageDto chatMessageDto = new ChatMessageDto(); //ChatMessageDto chatMessageDto = new ChatMessageDto();
//chatMessageDto.chatRoomId = //chatMessageDto.chatRoomId =
//chatRoomId shopMemberId messge messageType insertDate //chatRoomId shopMemberId messge messageType insertDate
if (pushMsg.length() > 0) { if (textMessage.length() > 0) {
tempMsg = pushMsg; tempMsg = textMessage;
} }
if (AppUtil.isAppForground(this)) { if (AppUtil.isAppForground(this)) {
msg.put(AppDefType.PushMessageKey.message, pushMsg); msg.put(AppDefType.PushMessageKey.message, textMessage);
} }
if (pushMsg.contains(INVITE_COLLABORATION)) { if (textMessage.contains(INVITE_COLLABORATION)) {
roomType = Integer.toString(json.getInt("roomType")); String roomType = Integer.toString(json.getInt(AppDefType.ChatPushMessageKey.roomType));
String[] inviteMessage = pushMsg.split("<::split>"); String[] inviteMessage = textMessage.split(CHAT_MESSAGE_SEPERATOR);
tempMsg = getString(R.string.msg_invite_collaboration); showCollaborationPopUpMessage(roomId, roomName, roomType, pushSendLoginId, pushSendDate, inviteMessage[1]);
Intent pushMsgDialog = new Intent(ABVFcmListenerService.this, ShowPushMessageDailogActivity.class);
pushMsgDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.message, tempMsg);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomId, roomId); // Room Id
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName); // Room Name
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId); // sendLoginId
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.collaborationType, inviteMessage[1]);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomType, roomType);
startActivity(pushMsgDialog);
return; return;
} }
} }
if (AppUtil.isAppForground(this)) { if (AppUtil.isAppForground(this)) {
Intent pushMsgDialog = new Intent(ABVFcmListenerService.this, ShowPushMessageDailogActivity.class); String data = msg.get(AppDefType.PushMessageKey.data);
pushMsgDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String operationID = msg.get(AppDefType.PushMessageKey.operationId);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.message, tempMsg);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.data, msg.get(AppDefType.PushMessageKey.data));
pushMsgDialog.putExtra(AppDefType.PushMessageKey.operationId, msg.get(AppDefType.PushMessageKey.operationId));
// push message
if (roomName.length() > 0) { if (roomName.length() > 0) {
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomId, roomId); // Room Id showChatRoomPopupMessage(tempMsg, data, operationID, roomId, roomName, pushSendLoginId, pushSendDate);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName); // Room Name } else {
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId); // sendLoginId showOperationPopUpMessage(tempMsg, data, operationID);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate);
} }
startActivity(pushMsgDialog);
} else { } else {
sendNotification(msg); sendNotification(msg);
} }
...@@ -137,60 +121,73 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -137,60 +121,73 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
} catch (ABVException e) { } catch (ABVException e) {
// ignore // ignore
Logger.e(TAG, e.toString()); Logger.e(TAG, e.toString());
} catch (JSONException e) {
Logger.e(TAG, e.toString());
} }
} }
private void sendNotification(Map<String, String> message) { private void showCollaborationPopUpMessage(
Intent intent = new Intent(); Long roomId,
String roomName,
// 定期点検用 String roomType,
if (message.get(AppDefType.PushMessageKey.operationId) != null) { String pushSendLoginId,
intent.putExtra(AppDefType.PushMessageKey.operationId, message.get(AppDefType.PushMessageKey.operationId)); long pushSendDate,
intent.putExtra(AppDefType.PushMessageKey.message, message.get(AppDefType.PushMessageKey.message)); String collaborationType)
} else { {
// Check pushmessage by chat Intent pushMsgDialog = new Intent(ABVFcmListenerService.this, ShowPushMessageDailogActivity.class);
try { String collaobrationInvitedMessage = getString(R.string.msg_invite_collaboration);
// チャットプッシュメッセージがある場合
UserAuthenticateLogic logic = AbstractLogic.getLogic(UserAuthenticateLogic.class);
MemberInfoDto memberInfo = logic.getMemberInfo();
if (!StringUtil.isNullOrWhiteSpace(message.get(AppDefType.PushMessageKey.message))) {
String tempMsg = message.get(AppDefType.PushMessageKey.message);
String pushMsg = "";
Long roomId = null;
String roomName = "";
String pushSendLoginId = "";
long pushSendDate = 0;
Log.d(TAG,"tempMsg : "+ tempMsg);
if (tempMsg.indexOf("pushSendLoginId") > 0) {
JSONObject json = new JSONObject(tempMsg);
Object Obj = json.getString("pushSendLoginId");
roomId = json.getLong("roomId");
roomName = json.getString("roomName");
pushSendLoginId = json.getString("pushSendLoginId");
pushSendDate = json.getLong("pushSendDate");
pushMsg = json.getString("message");
message.put(AppDefType.PushMessageKey.message, pushMsg);
// push message pushMsgDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (roomName.length() > 0) { pushMsgDialog.putExtra(AppDefType.PushMessageKey.message, collaobrationInvitedMessage);
intent.putExtra(AppDefType.ChatPushMessageKey.roomId, roomId); // Room Id pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomId, roomId);
intent.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName); // Room Name pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName);
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId); // sendLoginId pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId);
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate); pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.collaborationType, collaborationType);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomType, roomType);
startActivity(pushMsgDialog);
} }
private void showChatRoomPopupMessage(
String textMessage,
String data,
String operationID,
Long roomID,
String roomName,
String pushSendLoginId,
long pushSendDate)
{
Activity currentActivity = ActivityHandlingHelper.getInstance().getCurrentActivity();
if (currentActivity.getClass().equals(ChatWebViewActivity.class)) {
ChatWebViewActivity chatWebViewActivity = (ChatWebViewActivity) currentActivity;
if (chatWebViewActivity.getRoomID().equals(roomID)) {
// push messageと同じ部屋にいる場合はpushmessageを送信しない。
return;
} }
} }
} catch (ABVException e) { Intent pushMsgDialog = new Intent(ABVFcmListenerService.this, ShowPushMessageDailogActivity.class);
// ignore pushMsgDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Logger.e(TAG, e.toString()); pushMsgDialog.putExtra(AppDefType.PushMessageKey.message, textMessage);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.data, data);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.operationId, operationID);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomId, roomID);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId);
pushMsgDialog.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate);
startActivity(pushMsgDialog);
} }
private void showOperationPopUpMessage(String textMessage, String data, String operationID) {
Intent pushMsgDialog = new Intent(ABVFcmListenerService.this, ShowPushMessageDailogActivity.class);
pushMsgDialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.message, textMessage);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.data, data);
pushMsgDialog.putExtra(AppDefType.PushMessageKey.operationId, operationID);
startActivity(pushMsgDialog);
} }
intent.setClassName(getApplicationContext(), SplashScreenActivity.class.getName()); private void sendNotification(Map<String, String> message) {
Intent intent = instantiatePushNotificationIntent(message);
Notification notification; Notification notification;
...@@ -229,6 +226,48 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -229,6 +226,48 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
} }
} }
Intent instantiatePushNotificationIntent(Map<String, String> message) {
Intent intent = new Intent();
intent.setClassName(getApplicationContext(), SplashScreenActivity.class.getName());
// 定期点検用
if (message.get(AppDefType.PushMessageKey.operationId) != null) {
intent.putExtra(AppDefType.PushMessageKey.operationId, message.get(AppDefType.PushMessageKey.operationId));
intent.putExtra(AppDefType.PushMessageKey.message, message.get(AppDefType.PushMessageKey.message));
return intent;
}
// Check pushmessage by chat
// チャットプッシュメッセージがある場合
if (StringUtil.isNullOrWhiteSpace(message.get(AppDefType.PushMessageKey.message))) {
return intent;
}
String tempMsg = message.get(AppDefType.PushMessageKey.message);
Log.d(TAG,"tempMsg : "+ tempMsg);
if (Objects.requireNonNull(tempMsg).indexOf(AppDefType.ChatPushMessageKey.pushSendLoginId) <= 0) {
return intent;
}
JSONObject json = new JSONObject(tempMsg);
String roomName = json.getString(AppDefType.ChatPushMessageKey.roomName);
String pushMsg = json.getString(AppDefType.PushMessageKey.message);
message.put(AppDefType.PushMessageKey.message, pushMsg);
if (roomName.length() <= 0) { return intent; }
long roomId = json.getLong(AppDefType.ChatPushMessageKey.roomId);
long pushSendDate = json.getLong(AppDefType.ChatPushMessageKey.pushSendDate);
String pushSendLoginId = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId);
intent.putExtra(AppDefType.ChatPushMessageKey.roomId, roomId);
intent.putExtra(AppDefType.ChatPushMessageKey.roomName, roomName);
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, pushSendLoginId);
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, pushSendDate);
return intent;
}
private Notification.Builder getNotificationBuilder(PendingIntent pendingIntent, Map<String, String> message) { private Notification.Builder getNotificationBuilder(PendingIntent pendingIntent, Map<String, String> message) {
return new Notification.Builder(this) return new Notification.Builder(this)
.setDefaults(Notification.DEFAULT_ALL) .setDefaults(Notification.DEFAULT_ALL)
...@@ -247,6 +286,4 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -247,6 +286,4 @@ public class ABVFcmListenerService extends FirebaseMessagingService {
} }
return downloadUrl; return downloadUrl;
} }
} }
...@@ -124,6 +124,9 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity implements ...@@ -124,6 +124,9 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity implements
private boolean needHostAlert = false; private boolean needHostAlert = false;
public Long getRoomID() {
return chatData.roomId;
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
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