Commit a94c84ce by Kim Peace

Fixed not to display push notification for same chat room

parent 25eadc52
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,6 +12,7 @@ import android.util.Log; ...@@ -11,6 +12,7 @@ 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;
...@@ -25,10 +27,11 @@ import jp.agentec.abook.abv.cl.util.AppUtil; ...@@ -25,10 +27,11 @@ 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;
...@@ -58,79 +61,59 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -58,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 (Objects.requireNonNull(tempMsg).indexOf(AppDefType.ChatPushMessageKey.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(AppDefType.ChatPushMessageKey.pushSendLoginId);
roomId = json.getLong(AppDefType.ChatPushMessageKey.roomId); roomId = json.getLong(AppDefType.ChatPushMessageKey.roomId);
roomName = json.getString(AppDefType.ChatPushMessageKey.roomName); roomName = json.getString(AppDefType.ChatPushMessageKey.roomName);
pushSendLoginId = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId); pushSendLoginId = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId);
pushSendDate = json.getLong(AppDefType.ChatPushMessageKey.pushSendDate); pushSendDate = json.getLong(AppDefType.ChatPushMessageKey.pushSendDate);
pushMsg = json.getString(AppDefType.PushMessageKey.message); String textMessage = json.getString(AppDefType.PushMessageKey.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(AppDefType.ChatPushMessageKey.roomType)); String roomType = Integer.toString(json.getInt(AppDefType.ChatPushMessageKey.roomType));
String[] inviteMessage = pushMsg.split(CHAT_MESSAGE_SEPERATOR); 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);
} }
...@@ -138,60 +121,73 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -138,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 (Objects.requireNonNull(tempMsg).indexOf(AppDefType.ChatPushMessageKey.pushSendLoginId) > 0) {
JSONObject json = new JSONObject(tempMsg);
Object Obj = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId);
roomId = json.getLong(AppDefType.ChatPushMessageKey.roomId);
roomName = json.getString(AppDefType.ChatPushMessageKey.roomName);
pushSendLoginId = json.getString(AppDefType.ChatPushMessageKey.pushSendLoginId);
pushSendDate = json.getLong(AppDefType.ChatPushMessageKey.pushSendDate);
pushMsg = json.getString(AppDefType.PushMessageKey.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;
...@@ -230,6 +226,48 @@ public class ABVFcmListenerService extends FirebaseMessagingService { ...@@ -230,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)
......
...@@ -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