diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 351738cae..45b43fcd9 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -721,24 +721,7 @@ public class LinphoneActivity extends FragmentActivity implements } @Override - public void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message) { - if (getResources().getBoolean(R.bool.disable_chat)) { - return; - } - - String textMessage = message.getMessage(); - String url = message.getExternalBodyUrl(); - String notificationText = null; - int id = -1; - if (textMessage != null && textMessage.length() > 0) { - id = getChatStorage().saveMessage(from.asStringUriOnly(), "", textMessage); - notificationText = textMessage; - } else if (url != null && url.length() > 0) { - Bitmap bm = ChatFragment.downloadImage(url); - id = getChatStorage().saveMessage(from.asStringUriOnly(), "", bm); - notificationText = url; - } - + public void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id) { ChatFragment chatFragment = ((ChatFragment) messageListenerFragment); if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) { chatFragment.onMessageReceived(id, from, message); @@ -749,8 +732,6 @@ public class LinphoneActivity extends FragmentActivity implements ((ChatListFragment) messageListFragment).refresh(); } } - LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver()); - LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText); } public void updateMissedChatCount() { diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 33cd9f5a2..5c583f5f7 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -86,6 +86,7 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; +import android.graphics.Bitmap; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; @@ -920,8 +921,31 @@ public final class LinphoneManager implements LinphoneCoreListener { @Override public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { + if (mServiceContext.getResources().getBoolean(R.bool.disable_chat)) { + return; + } + + LinphoneAddress from = message.getFrom(); + ChatStorage chatStorage = new ChatStorage(mServiceContext); + + String textMessage = message.getMessage(); + String url = message.getExternalBodyUrl(); + String notificationText = null; + int id = -1; + if (textMessage != null && textMessage.length() > 0) { + id = chatStorage.saveMessage(from.asStringUriOnly(), "", textMessage); + notificationText = textMessage; + } else if (url != null && url.length() > 0) { + Bitmap bm = ChatFragment.downloadImage(url); + id = chatStorage.saveMessage(from.asStringUriOnly(), "", bm); + notificationText = url; + } + + LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, mServiceContext.getContentResolver()); + LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText); + for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneActivity.class)) { - ((LinphoneOnMessageReceivedListener) listener).onMessageReceived(message.getFrom(), message); + ((LinphoneOnMessageReceivedListener) listener).onMessageReceived(from, message, id); } } diff --git a/src/org/linphone/LinphoneSimpleListener.java b/src/org/linphone/LinphoneSimpleListener.java index 4af9f1027..b34fa7469 100644 --- a/src/org/linphone/LinphoneSimpleListener.java +++ b/src/org/linphone/LinphoneSimpleListener.java @@ -61,7 +61,7 @@ public interface LinphoneSimpleListener { } public static interface LinphoneOnMessageReceivedListener extends LinphoneSimpleListener { - void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message); + void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id); } public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener {