Do not emit a notification for currently displayed chat room when receiving a message

This commit is contained in:
Sylvain Berfini 2017-10-31 11:52:26 +01:00
parent 52aef086bc
commit de0fee9306
3 changed files with 19 additions and 19 deletions

View file

@ -199,6 +199,7 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
private Sensor mProximity;
private boolean mProximitySensingEnabled;
private boolean handsetON = false;
private Address mCurrentChatRoomAddress;
public String wizardLoginViewDomain = null;
@ -1222,6 +1223,11 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
return;
}
if (mCurrentChatRoomAddress != null && cr.getPeerAddress().asStringUriOnly().equals(mCurrentChatRoomAddress.asStringUriOnly())) {
Log.i("Message received for currently displayed chat room, do not make a notification");
return;
}
Address from = message.getFromAddress();
String to = message.getToAddress().asString();
@ -1231,9 +1237,9 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
if (contact != null) {
LinphoneService.instance().removedNotification(to, from.asStringUriOnly(), contact.getFullName(), textMessage);
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(), contact.getFullName(), textMessage);
} else {
LinphoneService.instance().removedNotification(to, from.asStringUriOnly(), from.getUsername(), textMessage);
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(), from.getUsername(), textMessage);
}
}
} catch (Exception e) {
@ -1241,6 +1247,10 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
}
}
public void setCurrentChatRoomAddress(Address address) {
mCurrentChatRoomAddress = address;
}
@Override
public void onEcCalibrationResult(Core lc, EcCalibratorStatus status, int delay_ms) {
((AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE)).setMode(AudioManager.MODE_NORMAL);
@ -1248,19 +1258,6 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
Log.i("Set audio mode on 'Normal'");
}
public void setAreDisplayAlertMessage(boolean b) {
mAreDisplayAlertMessage = b;
}
public String getLastLcStatusMessage() {
return lastLcStatusMessage;
}
public void removed(final Core lc, final String message) {
Log.i(message);
lastLcStatusMessage=message;
}
public void onGlobalStateChanged(final Core lc, final GlobalState state, final String message) {
Log.i("New global state [",state,"]");
if (state == Core.GlobalState.On){

View file

@ -595,7 +595,7 @@ public final class LinphoneService extends Service {
resetIntentLaunchedOnNotificationClick();
}
public void removedNotification(String to, String fromSipUri, String fromName, String message) {
public void displayMessageNotification(String to, String fromSipUri, String fromName, String message) {
Intent notifIntent = new Intent(this, LinphoneActivity.class);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", fromSipUri);

View file

@ -261,12 +261,15 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
initChatRoom();
displayChatRoomHeader();
displayChatRoomHistory();
LinphoneManager.getInstance().setCurrentChatRoomAddress(mRemoteSipAddress);
}
@Override
public void onPause() {
ContactsManager.removeContactsListener(this);
removeVirtualKeyboardVisiblityListener();
LinphoneManager.getInstance().setCurrentChatRoomAddress(null);
super.onPause();
}
@ -411,7 +414,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
return;
}
mChatRoom = core.getChatRoomFromUri(mRemoteSipAddress.asStringUriOnly());
mChatRoom = core.getChatRoomFromUri(mRemoteSipAddress.asString());
mChatRoom.setListener(this);
mChatRoom.markAsRead();
LinphoneActivity.instance().updateMissedChatCount();
@ -595,10 +598,10 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
if (!getResources().getBoolean(R.bool.disable_chat_message_notification)) {
String to = msg.getToAddress().asString();
if (contact != null) {
LinphoneService.instance().removedNotification(to, from.asStringUriOnly(),
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
contact.getFullName(), getString(R.string.message_cant_be_decrypted_notif));
} else {
LinphoneService.instance().removedNotification(to, from.asStringUriOnly(),
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
from.getUsername(), getString(R.string.message_cant_be_decrypted_notif));
}
}