2014-07-10 02:15:58 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2014-07-10 02:15:58 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2014-07-10 02:15:58 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
package org.telegram.messenger;
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.annotation.TargetApi;
|
2014-08-22 16:24:33 +02:00
|
|
|
import android.app.AlarmManager;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.graphics.Point;
|
2014-08-22 16:24:33 +02:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.media.AudioAttributes;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.media.AudioManager;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.media.SoundPool;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.net.Uri;
|
2014-10-04 17:56:09 +02:00
|
|
|
import android.os.Build;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.os.PowerManager;
|
2014-08-22 16:24:33 +02:00
|
|
|
import android.os.SystemClock;
|
2014-07-10 02:15:58 +02:00
|
|
|
import android.provider.Settings;
|
|
|
|
import android.support.v4.app.NotificationCompat;
|
2014-08-22 16:24:33 +02:00
|
|
|
import android.support.v4.app.NotificationManagerCompat;
|
2014-10-04 17:56:09 +02:00
|
|
|
import android.support.v4.app.RemoteInput;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.support.v4.content.FileProvider;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.text.TextUtils;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.util.LongSparseArray;
|
2015-09-24 22:52:02 +02:00
|
|
|
import android.util.SparseArray;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.util.SparseIntArray;
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.telegram.messenger.support.SparseLongArray;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-07-10 02:15:58 +02:00
|
|
|
import org.telegram.ui.LaunchActivity;
|
|
|
|
import org.telegram.ui.PopupNotificationActivity;
|
|
|
|
|
2017-07-23 19:29:17 +02:00
|
|
|
import java.io.File;
|
2014-07-10 02:15:58 +02:00
|
|
|
import java.util.ArrayList;
|
2014-08-22 16:24:33 +02:00
|
|
|
import java.util.Calendar;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.util.List;
|
2014-07-10 02:15:58 +02:00
|
|
|
|
|
|
|
public class NotificationsController {
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
|
2018-07-30 04:07:02 +02:00
|
|
|
public static final String OTHER_NOTIFICATIONS_CHANNEL = "Other3";
|
2014-08-22 16:24:33 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private static DispatchQueue notificationsQueue = new DispatchQueue("notificationsQueue");
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<MessageObject> pushMessages = new ArrayList<>();
|
2015-05-03 13:48:36 +02:00
|
|
|
private ArrayList<MessageObject> delayedPushMessages = new ArrayList<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private LongSparseArray<MessageObject> pushMessagesDict = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<MessageObject> fcmRandomMessagesDict = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<Point> smartNotificationsDialogs = new LongSparseArray<>();
|
|
|
|
private static NotificationManagerCompat notificationManager = null;
|
|
|
|
private static NotificationManager systemNotificationManager = null;
|
|
|
|
private LongSparseArray<Integer> pushDialogs = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<Integer> wearNotificationsIds = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<Integer> lastWearNotifiedMessageId = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<Integer> pushDialogsOverrideMention = new LongSparseArray<>();
|
2015-01-02 23:15:07 +01:00
|
|
|
public ArrayList<MessageObject> popupMessages = new ArrayList<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
public ArrayList<MessageObject> popupReplyMessages = new ArrayList<>();
|
2016-03-16 13:26:32 +01:00
|
|
|
private long opened_dialog_id = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
private int lastButtonId = 5000;
|
2014-07-11 15:54:17 +02:00
|
|
|
private int total_unread_count = 0;
|
2014-09-25 05:54:35 +02:00
|
|
|
private int personal_count = 0;
|
2014-07-10 02:15:58 +02:00
|
|
|
private boolean notifyCheck = false;
|
2015-02-01 19:51:02 +01:00
|
|
|
private int lastOnlineFromOtherDevice = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean inChatSoundEnabled;
|
2017-03-31 01:58:05 +02:00
|
|
|
private int lastBadgeCount = -1;
|
2015-05-21 23:27:27 +02:00
|
|
|
private String launcherClassName;
|
2015-03-26 18:34:47 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static long globalSecretChatId = -(1L << 32);
|
|
|
|
|
|
|
|
private boolean lastNotificationIsNoData;
|
|
|
|
public static long lastNoDataNotificationTime;
|
|
|
|
|
|
|
|
public boolean showBadgeNumber;
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private Runnable notificationDelayRunnable;
|
|
|
|
private PowerManager.WakeLock notificationDelayWakelock;
|
|
|
|
|
2015-03-26 18:34:47 +01:00
|
|
|
private long lastSoundPlay;
|
2015-05-21 23:27:27 +02:00
|
|
|
private long lastSoundOutPlay;
|
2015-05-03 13:48:36 +02:00
|
|
|
private SoundPool soundPool;
|
|
|
|
private int soundIn;
|
|
|
|
private int soundOut;
|
2016-03-06 02:49:31 +01:00
|
|
|
private int soundRecord;
|
2015-06-29 19:12:11 +02:00
|
|
|
private boolean soundInLoaded;
|
|
|
|
private boolean soundOutLoaded;
|
2016-03-06 02:49:31 +01:00
|
|
|
private boolean soundRecordLoaded;
|
2018-07-30 04:07:02 +02:00
|
|
|
protected static AudioManager audioManager;
|
2015-06-29 19:12:11 +02:00
|
|
|
private AlarmManager alarmManager;
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int notificationId;
|
|
|
|
private String notificationGroup;
|
|
|
|
|
|
|
|
static {
|
|
|
|
if (Build.VERSION.SDK_INT >= 26 && ApplicationLoader.applicationContext != null) {
|
|
|
|
notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
|
|
|
|
systemNotificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
NotificationChannel notificationChannel = new NotificationChannel(OTHER_NOTIFICATIONS_CHANNEL, "Other", NotificationManager.IMPORTANCE_DEFAULT);
|
|
|
|
notificationChannel.enableLights(false);
|
|
|
|
notificationChannel.enableVibration(false);
|
|
|
|
notificationChannel.setSound(null, null);
|
|
|
|
systemNotificationManager.createNotificationChannel(notificationChannel);
|
|
|
|
}
|
|
|
|
audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int currentAccount;
|
|
|
|
private static volatile NotificationsController Instance[] = new NotificationsController[UserConfig.MAX_ACCOUNT_COUNT];
|
|
|
|
|
|
|
|
public static NotificationsController getInstance(int num) {
|
|
|
|
NotificationsController localInstance = Instance[num];
|
2014-07-10 02:15:58 +02:00
|
|
|
if (localInstance == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
synchronized (NotificationsController.class) {
|
2018-07-30 04:07:02 +02:00
|
|
|
localInstance = Instance[num];
|
2014-07-10 02:15:58 +02:00
|
|
|
if (localInstance == null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
Instance[num] = localInstance = new NotificationsController(num);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localInstance;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public NotificationsController(int instance) {
|
|
|
|
currentAccount = instance;
|
|
|
|
notificationId = currentAccount + 1;
|
|
|
|
notificationGroup = "messages" + (currentAccount == 0 ? "" : currentAccount);
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2015-03-26 18:34:47 +01:00
|
|
|
inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true);
|
2018-07-30 04:07:02 +02:00
|
|
|
showBadgeNumber = preferences.getBoolean("badgeNumber", true);
|
|
|
|
|
|
|
|
notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext);
|
|
|
|
systemNotificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
2015-03-26 18:34:47 +01:00
|
|
|
|
|
|
|
try {
|
2015-03-27 11:32:33 +01:00
|
|
|
audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(Context.AUDIO_SERVICE);
|
2015-03-26 18:34:47 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
try {
|
|
|
|
alarmManager = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
|
|
|
notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
|
|
|
|
notificationDelayWakelock.setReferenceCounted(false);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
notificationDelayRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("delay reached");
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!delayedPushMessages.isEmpty()) {
|
|
|
|
showOrUpdateNotification(true);
|
|
|
|
delayedPushMessages.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (lastNotificationIsNoData) {
|
|
|
|
notificationManager.cancel(notificationId);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (notificationDelayWakelock.isHeld()) {
|
|
|
|
notificationDelayWakelock.release();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cleanup() {
|
|
|
|
popupMessages.clear();
|
2016-10-11 13:57:01 +02:00
|
|
|
popupReplyMessages.clear();
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-03-16 13:26:32 +01:00
|
|
|
opened_dialog_id = 0;
|
2015-10-29 18:10:07 +01:00
|
|
|
total_unread_count = 0;
|
|
|
|
personal_count = 0;
|
|
|
|
pushMessages.clear();
|
|
|
|
pushMessagesDict.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
fcmRandomMessagesDict.clear();
|
2015-10-29 18:10:07 +01:00
|
|
|
pushDialogs.clear();
|
|
|
|
wearNotificationsIds.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
lastWearNotifiedMessageId.clear();
|
2015-10-29 18:10:07 +01:00
|
|
|
delayedPushMessages.clear();
|
|
|
|
notifyCheck = false;
|
|
|
|
lastBadgeCount = 0;
|
|
|
|
try {
|
|
|
|
if (notificationDelayWakelock.isHeld()) {
|
|
|
|
notificationDelayWakelock.release();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
setBadge(getTotalAllUnreadCount());
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2015-10-29 18:10:07 +01:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.clear();
|
|
|
|
editor.commit();
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
try {
|
|
|
|
String keyStart = currentAccount + "channel";
|
|
|
|
List<NotificationChannel> list = systemNotificationManager.getNotificationChannels();
|
|
|
|
int count = list.size();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
NotificationChannel channel = list.get(a);
|
|
|
|
String id = channel.getId();
|
|
|
|
if (id.startsWith(keyStart)) {
|
|
|
|
systemNotificationManager.deleteNotificationChannel(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
});
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 18:34:47 +01:00
|
|
|
public void setInChatSoundEnabled(boolean value) {
|
|
|
|
inChatSoundEnabled = value;
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:26:32 +01:00
|
|
|
public void setOpenedDialogId(final long dialog_id) {
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-03-16 13:26:32 +01:00
|
|
|
opened_dialog_id = dialog_id;
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastOnlineFromOtherDevice(final int time) {
|
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("set last online from other device = " + time);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
lastOnlineFromOtherDevice = time;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public void removeNotificationsForDialog(long did) {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationsController.getInstance(currentAccount).processReadMessages(null, did, 0, Integer.MAX_VALUE, false);
|
|
|
|
LongSparseArray<Integer> dialogsToUpdate = new LongSparseArray<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
dialogsToUpdate.put(did, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationsController.getInstance(currentAccount).processDialogsUpdateRead(dialogsToUpdate);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean hasMessagesToReply() {
|
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
|
|
|
long dialog_id = messageObject.getDialogId();
|
|
|
|
if (messageObject.messageOwner.mentioned && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage ||
|
|
|
|
(int) dialog_id == 0 || messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void forceShowPopupForReply() {
|
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final ArrayList<MessageObject> popupArray = new ArrayList<>();
|
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
|
|
|
long dialog_id = messageObject.getDialogId();
|
|
|
|
if (messageObject.messageOwner.mentioned && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage ||
|
|
|
|
(int) dialog_id == 0 || messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
popupArray.add(0, messageObject);
|
|
|
|
}
|
|
|
|
if (!popupArray.isEmpty() && !AndroidUtilities.needShowPasscode(false)) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
popupReplyMessages = popupArray;
|
|
|
|
Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class);
|
|
|
|
popupIntent.putExtra("force", true);
|
2018-07-30 04:07:02 +02:00
|
|
|
popupIntent.putExtra("currentAccount", currentAccount);
|
2016-10-11 13:57:01 +02:00
|
|
|
popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
|
|
|
|
ApplicationLoader.applicationContext.startActivity(popupIntent);
|
|
|
|
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
|
|
|
|
ApplicationLoader.applicationContext.sendBroadcast(it);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public void removeDeletedMessagesFromNotifications(final SparseArray<ArrayList<Integer>> deletedMessages) {
|
2018-07-30 04:07:02 +02:00
|
|
|
final ArrayList<MessageObject> popupArrayRemove = new ArrayList<>(0);
|
2015-11-26 22:04:02 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int old_unread_count = total_unread_count;
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2015-11-26 22:04:02 +01:00
|
|
|
for (int a = 0; a < deletedMessages.size(); a++) {
|
|
|
|
int key = deletedMessages.keyAt(a);
|
|
|
|
long dialog_id = -key;
|
|
|
|
ArrayList<Integer> mids = deletedMessages.get(key);
|
|
|
|
Integer currentCount = pushDialogs.get(dialog_id);
|
|
|
|
if (currentCount == null) {
|
|
|
|
currentCount = 0;
|
|
|
|
}
|
|
|
|
Integer newCount = currentCount;
|
|
|
|
for (int b = 0; b < mids.size(); b++) {
|
|
|
|
long mid = mids.get(b);
|
|
|
|
mid |= ((long) key) << 32;
|
|
|
|
MessageObject messageObject = pushMessagesDict.get(mid);
|
|
|
|
if (messageObject != null) {
|
|
|
|
pushMessagesDict.remove(mid);
|
|
|
|
delayedPushMessages.remove(messageObject);
|
|
|
|
pushMessages.remove(messageObject);
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count--;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayRemove.add(messageObject);
|
2015-11-26 22:04:02 +01:00
|
|
|
newCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newCount <= 0) {
|
|
|
|
newCount = 0;
|
|
|
|
smartNotificationsDialogs.remove(dialog_id);
|
|
|
|
}
|
|
|
|
if (!newCount.equals(currentCount)) {
|
|
|
|
total_unread_count -= currentCount;
|
|
|
|
total_unread_count += newCount;
|
|
|
|
pushDialogs.put(dialog_id, newCount);
|
|
|
|
}
|
|
|
|
if (newCount == 0) {
|
|
|
|
pushDialogs.remove(dialog_id);
|
|
|
|
pushDialogsOverrideMention.remove(dialog_id);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!popupArrayRemove.isEmpty()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0, size = popupArrayRemove.size(); a < size; a++) {
|
|
|
|
popupMessages.remove(popupArrayRemove.get(a));
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (old_unread_count != total_unread_count) {
|
|
|
|
if (!notifyCheck) {
|
|
|
|
delayedPushMessages.clear();
|
|
|
|
showOrUpdateNotification(notifyCheck);
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
scheduleNotificationDelay(lastOnlineFromOtherDevice > ConnectionsManager.getInstance(currentAccount).getCurrentTime());
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
final int pushDialogsCount = pushDialogs.size();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.notificationsCountUpdated, currentAccount);
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsUnreadCounterChanged, pushDialogsCount);
|
|
|
|
}
|
|
|
|
});
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
notifyCheck = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (showBadgeNumber) {
|
|
|
|
setBadge(getTotalAllUnreadCount());
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void removeDeletedHisoryFromNotifications(final SparseIntArray deletedMessages) {
|
|
|
|
final ArrayList<MessageObject> popupArrayRemove = new ArrayList<>(0);
|
2017-12-08 18:35:59 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int old_unread_count = total_unread_count;
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < deletedMessages.size(); a++) {
|
|
|
|
int key = deletedMessages.keyAt(a);
|
|
|
|
long dialog_id = -key;
|
2018-07-30 04:07:02 +02:00
|
|
|
int id = deletedMessages.get(key);
|
2017-12-08 18:35:59 +01:00
|
|
|
Integer currentCount = pushDialogs.get(dialog_id);
|
|
|
|
if (currentCount == null) {
|
|
|
|
currentCount = 0;
|
|
|
|
}
|
|
|
|
Integer newCount = currentCount;
|
|
|
|
|
|
|
|
for (int c = 0; c < pushMessages.size(); c++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(c);
|
|
|
|
if (messageObject.getDialogId() == dialog_id && messageObject.getId() <= id) {
|
|
|
|
pushMessagesDict.remove(messageObject.getIdWithChannel());
|
|
|
|
delayedPushMessages.remove(messageObject);
|
|
|
|
pushMessages.remove(messageObject);
|
|
|
|
c--;
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count--;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayRemove.add(messageObject);
|
2017-12-08 18:35:59 +01:00
|
|
|
newCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newCount <= 0) {
|
|
|
|
newCount = 0;
|
|
|
|
smartNotificationsDialogs.remove(dialog_id);
|
|
|
|
}
|
|
|
|
if (!newCount.equals(currentCount)) {
|
|
|
|
total_unread_count -= currentCount;
|
|
|
|
total_unread_count += newCount;
|
|
|
|
pushDialogs.put(dialog_id, newCount);
|
|
|
|
}
|
|
|
|
if (newCount == 0) {
|
|
|
|
pushDialogs.remove(dialog_id);
|
|
|
|
pushDialogsOverrideMention.remove(dialog_id);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (popupArrayRemove.isEmpty()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0, size = popupArrayRemove.size(); a < size; a++) {
|
|
|
|
popupMessages.remove(popupArrayRemove.get(a));
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (old_unread_count != total_unread_count) {
|
|
|
|
if (!notifyCheck) {
|
|
|
|
delayedPushMessages.clear();
|
|
|
|
showOrUpdateNotification(notifyCheck);
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
scheduleNotificationDelay(lastOnlineFromOtherDevice > ConnectionsManager.getInstance(currentAccount).getCurrentTime());
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
final int pushDialogsCount = pushDialogs.size();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.notificationsCountUpdated, currentAccount);
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsUnreadCounterChanged, pushDialogsCount);
|
|
|
|
}
|
|
|
|
});
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
notifyCheck = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (showBadgeNumber) {
|
|
|
|
setBadge(getTotalAllUnreadCount());
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void processReadMessages(final SparseLongArray inbox, final long dialog_id, final int max_date, final int max_id, final boolean isPopup) {
|
|
|
|
final ArrayList<MessageObject> popupArrayRemove = new ArrayList<>(0);
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (inbox != null) {
|
|
|
|
for (int b = 0; b < inbox.size(); b++) {
|
|
|
|
int key = inbox.keyAt(b);
|
|
|
|
long messageId = inbox.get(key);
|
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
|
|
|
if (messageObject.getDialogId() == key && messageObject.getId() <= (int) messageId) {
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count--;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayRemove.add(messageObject);
|
|
|
|
long mid = messageObject.getId();
|
2015-10-29 18:10:07 +01:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
|
|
|
|
}
|
|
|
|
pushMessagesDict.remove(mid);
|
|
|
|
delayedPushMessages.remove(messageObject);
|
|
|
|
pushMessages.remove(a);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dialog_id != 0 && (max_id != 0 || max_date != 0)) {
|
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
|
|
|
if (messageObject.getDialogId() == dialog_id) {
|
|
|
|
boolean remove = false;
|
|
|
|
if (max_date != 0) {
|
|
|
|
if (messageObject.messageOwner.date <= max_date) {
|
|
|
|
remove = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!isPopup) {
|
|
|
|
if (messageObject.getId() <= max_id || max_id < 0) {
|
|
|
|
remove = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messageObject.getId() == max_id || max_id < 0) {
|
|
|
|
remove = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (remove) {
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count--;
|
|
|
|
}
|
|
|
|
pushMessages.remove(a);
|
|
|
|
delayedPushMessages.remove(messageObject);
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayRemove.add(messageObject);
|
|
|
|
long mid = messageObject.getId();
|
2015-10-29 18:10:07 +01:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
|
|
|
|
}
|
|
|
|
pushMessagesDict.remove(mid);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!popupArrayRemove.isEmpty()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0, size = popupArrayRemove.size(); a < size; a++) {
|
|
|
|
popupMessages.remove(popupArrayRemove.get(a));
|
|
|
|
}
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast, final boolean isFcm) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (messageObjects.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
final ArrayList<MessageObject> popupArrayAdd = new ArrayList<>(0);
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
boolean added = false;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
LongSparseArray<Boolean> settingsCache = new LongSparseArray<>();
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2016-04-22 15:49:00 +02:00
|
|
|
boolean allowPinned = preferences.getBoolean("PinnedMessages", true);
|
2015-10-29 18:10:07 +01:00
|
|
|
int popup = 0;
|
|
|
|
|
|
|
|
for (int a = 0; a < messageObjects.size(); a++) {
|
|
|
|
MessageObject messageObject = messageObjects.get(a);
|
2018-07-30 04:07:02 +02:00
|
|
|
long mid = messageObject.getId();
|
|
|
|
long random_id = messageObject.isFcmMessage() ? messageObject.messageOwner.random_id : 0;
|
2015-10-29 18:10:07 +01:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
MessageObject oldMessageObject = pushMessagesDict.get(mid);
|
|
|
|
if (oldMessageObject == null && messageObject.messageOwner.random_id != 0) {
|
|
|
|
oldMessageObject = fcmRandomMessagesDict.get(messageObject.messageOwner.random_id);
|
|
|
|
if (oldMessageObject != null) {
|
|
|
|
fcmRandomMessagesDict.remove(messageObject.messageOwner.random_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldMessageObject != null) {
|
|
|
|
if (oldMessageObject.isFcmMessage()) {
|
|
|
|
pushMessagesDict.put(mid, messageObject);
|
|
|
|
int idxOld = pushMessages.indexOf(oldMessageObject);
|
|
|
|
if (idxOld >= 0) {
|
|
|
|
pushMessages.set(idxOld, messageObject);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
long dialog_id = messageObject.getDialogId();
|
|
|
|
long original_dialog_id = dialog_id;
|
2016-03-16 13:26:32 +01:00
|
|
|
if (dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!isFcm) {
|
|
|
|
playInChatSound();
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (messageObject.messageOwner.mentioned) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (!allowPinned && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
dialog_id = messageObject.messageOwner.from_id;
|
|
|
|
}
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count++;
|
|
|
|
}
|
|
|
|
added = true;
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
int lower_id = (int) dialog_id;
|
|
|
|
boolean isChat = lower_id < 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
int index = settingsCache.indexOfKey(dialog_id);
|
|
|
|
boolean value;
|
|
|
|
if (index >= 0) {
|
|
|
|
value = settingsCache.valueAt(index);
|
|
|
|
} else {
|
|
|
|
int notifyOverride = getNotifyOverride(preferences, dialog_id);
|
|
|
|
if (notifyOverride == -1) {
|
|
|
|
value = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
value = notifyOverride != 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
settingsCache.put(dialog_id, value);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lower_id != 0) {
|
|
|
|
if (preferences.getBoolean("custom_" + dialog_id, false)) {
|
|
|
|
popup = preferences.getInt("popup_" + dialog_id, 0);
|
|
|
|
} else {
|
|
|
|
popup = 0;
|
|
|
|
}
|
|
|
|
if (popup == 0) {
|
|
|
|
popup = preferences.getInt((int) dialog_id < 0 ? "popupGroup" : "popupAll", 0);
|
|
|
|
} else if (popup == 1) {
|
|
|
|
popup = 3;
|
|
|
|
} else if (popup == 2) {
|
|
|
|
popup = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-26 01:27:33 +02:00
|
|
|
if (popup != 0 && messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) {
|
|
|
|
popup = 0;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (value) {
|
|
|
|
if (popup != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayAdd.add(0, messageObject);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
delayedPushMessages.add(messageObject);
|
|
|
|
pushMessages.add(0, messageObject);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (mid != 0) {
|
|
|
|
pushMessagesDict.put(mid, messageObject);
|
|
|
|
} else if (random_id != 0) {
|
|
|
|
fcmRandomMessagesDict.put(random_id, messageObject);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (original_dialog_id != dialog_id) {
|
|
|
|
pushDialogsOverrideMention.put(original_dialog_id, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (added) {
|
|
|
|
notifyCheck = isLast;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!popupArrayAdd.isEmpty() && !AndroidUtilities.needShowPasscode(false)) {
|
2015-10-29 18:10:07 +01:00
|
|
|
final int popupFinal = popup;
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
popupMessages.addAll(0, popupArrayAdd);
|
|
|
|
if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn && !SharedConfig.isWaitingForPasscodeEnter) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn || popupFinal == 2 && !ApplicationLoader.isScreenOn) {
|
|
|
|
Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class);
|
|
|
|
popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND);
|
|
|
|
ApplicationLoader.applicationContext.startActivity(popupIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (added && isFcm) {
|
|
|
|
long dialog_id = messageObjects.get(0).getDialogId();
|
|
|
|
int old_unread_count = total_unread_count;
|
|
|
|
|
|
|
|
int notifyOverride = getNotifyOverride(preferences, dialog_id);
|
|
|
|
if (notifyCheck) {
|
|
|
|
Integer override = pushDialogsOverrideMention.get(dialog_id);
|
|
|
|
if (override != null && override == 1) {
|
|
|
|
pushDialogsOverrideMention.put(dialog_id, 0);
|
|
|
|
notifyOverride = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean canAddValue;
|
|
|
|
if (notifyOverride == -1) {
|
|
|
|
canAddValue = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
canAddValue = notifyOverride != 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer currentCount = pushDialogs.get(dialog_id);
|
|
|
|
Integer newCount = currentCount != null ? currentCount + 1 : 1;
|
|
|
|
|
|
|
|
if (canAddValue) {
|
|
|
|
if (currentCount != null) {
|
|
|
|
total_unread_count -= currentCount;
|
|
|
|
}
|
|
|
|
total_unread_count += newCount;
|
|
|
|
pushDialogs.put(dialog_id, newCount);
|
|
|
|
}
|
|
|
|
if (old_unread_count != total_unread_count) {
|
|
|
|
if (!notifyCheck) {
|
|
|
|
delayedPushMessages.clear();
|
|
|
|
showOrUpdateNotification(notifyCheck);
|
|
|
|
} else {
|
|
|
|
scheduleNotificationDelay(lastOnlineFromOtherDevice > ConnectionsManager.getInstance(currentAccount).getCurrentTime());
|
|
|
|
}
|
|
|
|
final int pushDialogsCount = pushDialogs.size();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.notificationsCountUpdated, currentAccount);
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsUnreadCounterChanged, pushDialogsCount);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
notifyCheck = false;
|
|
|
|
if (showBadgeNumber) {
|
|
|
|
setBadge(getTotalAllUnreadCount());
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public int getTotalUnreadCount() {
|
|
|
|
return total_unread_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void processDialogsUpdateRead(final LongSparseArray<Integer> dialogsToUpdate) {
|
|
|
|
final ArrayList<MessageObject> popupArrayToRemove = new ArrayList<>();
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int old_unread_count = total_unread_count;
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
for (int b = 0; b < dialogsToUpdate.size(); b++) {
|
|
|
|
long dialog_id = dialogsToUpdate.keyAt(b);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
|
|
int notifyOverride = getNotifyOverride(preferences, dialog_id);
|
|
|
|
if (notifyCheck) {
|
|
|
|
Integer override = pushDialogsOverrideMention.get(dialog_id);
|
|
|
|
if (override != null && override == 1) {
|
|
|
|
pushDialogsOverrideMention.put(dialog_id, 0);
|
|
|
|
notifyOverride = 1;
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean canAddValue;
|
|
|
|
if (notifyOverride == -1) {
|
|
|
|
canAddValue = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
canAddValue = notifyOverride != 2;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
|
|
Integer currentCount = pushDialogs.get(dialog_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
Integer newCount = dialogsToUpdate.get(dialog_id);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (newCount == 0) {
|
|
|
|
smartNotificationsDialogs.remove(dialog_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newCount < 0) {
|
|
|
|
if (currentCount == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
newCount = currentCount + newCount;
|
|
|
|
}
|
|
|
|
if (canAddValue || newCount == 0) {
|
|
|
|
if (currentCount != null) {
|
|
|
|
total_unread_count -= currentCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newCount == 0) {
|
|
|
|
pushDialogs.remove(dialog_id);
|
|
|
|
pushDialogsOverrideMention.remove(dialog_id);
|
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
|
|
|
if (messageObject.getDialogId() == dialog_id) {
|
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count--;
|
|
|
|
}
|
|
|
|
pushMessages.remove(a);
|
|
|
|
a--;
|
|
|
|
delayedPushMessages.remove(messageObject);
|
2018-07-30 04:07:02 +02:00
|
|
|
long mid = messageObject.getId();
|
2015-10-29 18:10:07 +01:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
|
|
|
|
}
|
|
|
|
pushMessagesDict.remove(mid);
|
2018-07-30 04:07:02 +02:00
|
|
|
popupArrayToRemove.add(messageObject);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (canAddValue) {
|
|
|
|
total_unread_count += newCount;
|
|
|
|
pushDialogs.put(dialog_id, newCount);
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!popupArrayToRemove.isEmpty()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0, size = popupArrayToRemove.size(); a < size; a++) {
|
|
|
|
popupMessages.remove(popupArrayToRemove.get(a));
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (old_unread_count != total_unread_count) {
|
|
|
|
if (!notifyCheck) {
|
|
|
|
delayedPushMessages.clear();
|
|
|
|
showOrUpdateNotification(notifyCheck);
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
scheduleNotificationDelay(lastOnlineFromOtherDevice > ConnectionsManager.getInstance(currentAccount).getCurrentTime());
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
final int pushDialogsCount = pushDialogs.size();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.notificationsCountUpdated, currentAccount);
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsUnreadCounterChanged, pushDialogsCount);
|
|
|
|
}
|
|
|
|
});
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
notifyCheck = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (showBadgeNumber) {
|
|
|
|
setBadge(getTotalAllUnreadCount());
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void processLoadedUnreadMessages(final LongSparseArray<Integer> dialogs, final ArrayList<TLRPC.Message> messages, final ArrayList<TLRPC.User> users, final ArrayList<TLRPC.Chat> chats, final ArrayList<TLRPC.EncryptedChat> encryptedChats) {
|
|
|
|
MessagesController.getInstance(currentAccount).putUsers(users, true);
|
|
|
|
MessagesController.getInstance(currentAccount).putChats(chats, true);
|
|
|
|
MessagesController.getInstance(currentAccount).putEncryptedChats(encryptedChats, true);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
pushDialogs.clear();
|
|
|
|
pushMessages.clear();
|
|
|
|
pushMessagesDict.clear();
|
|
|
|
total_unread_count = 0;
|
|
|
|
personal_count = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
LongSparseArray<Boolean> settingsCache = new LongSparseArray<>();
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
|
|
if (messages != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
for (int a = 0; a < messages.size(); a++) {
|
|
|
|
TLRPC.Message message = messages.get(a);
|
2015-10-29 18:10:07 +01:00
|
|
|
long mid = message.id;
|
|
|
|
if (message.to_id.channel_id != 0) {
|
|
|
|
mid |= ((long) message.to_id.channel_id) << 32;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (pushMessagesDict.indexOfKey(mid) >= 0) {
|
2015-10-29 18:10:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
MessageObject messageObject = new MessageObject(currentAccount, message, false);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (isPersonalMessage(messageObject)) {
|
|
|
|
personal_count++;
|
|
|
|
}
|
|
|
|
long dialog_id = messageObject.getDialogId();
|
|
|
|
long original_dialog_id = dialog_id;
|
2015-11-26 22:04:02 +01:00
|
|
|
if (messageObject.messageOwner.mentioned) {
|
2015-10-29 18:10:07 +01:00
|
|
|
dialog_id = messageObject.messageOwner.from_id;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int index = settingsCache.indexOfKey(dialog_id);
|
|
|
|
boolean value;
|
|
|
|
if (index >= 0) {
|
|
|
|
value = settingsCache.valueAt(index);
|
|
|
|
} else {
|
2015-10-29 18:10:07 +01:00
|
|
|
int notifyOverride = getNotifyOverride(preferences, dialog_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (notifyOverride == -1) {
|
|
|
|
value = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
value = notifyOverride != 2;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
settingsCache.put(dialog_id, value);
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
if (!value || dialog_id == opened_dialog_id && ApplicationLoader.isScreenOn) {
|
2015-10-29 18:10:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pushMessagesDict.put(mid, messageObject);
|
|
|
|
pushMessages.add(0, messageObject);
|
|
|
|
if (original_dialog_id != dialog_id) {
|
|
|
|
pushDialogsOverrideMention.put(original_dialog_id, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < dialogs.size(); a++) {
|
|
|
|
long dialog_id = dialogs.keyAt(a);
|
|
|
|
int index = settingsCache.indexOfKey(dialog_id);
|
|
|
|
boolean value;
|
|
|
|
if (index >= 0) {
|
|
|
|
value = settingsCache.valueAt(index);
|
|
|
|
} else {
|
2015-10-29 18:10:07 +01:00
|
|
|
int notifyOverride = getNotifyOverride(preferences, dialog_id);
|
|
|
|
Integer override = pushDialogsOverrideMention.get(dialog_id);
|
|
|
|
if (override != null && override == 1) {
|
|
|
|
pushDialogsOverrideMention.put(dialog_id, 0);
|
|
|
|
notifyOverride = 1;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (notifyOverride == -1) {
|
|
|
|
value = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
value = notifyOverride != 2;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
settingsCache.put(dialog_id, value);
|
|
|
|
}
|
|
|
|
if (!value) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int count = dialogs.valueAt(a);
|
2015-10-29 18:10:07 +01:00
|
|
|
pushDialogs.put(dialog_id, count);
|
|
|
|
total_unread_count += count;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
final int pushDialogsCount = pushDialogs.size();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (total_unread_count == 0) {
|
2015-10-29 18:10:07 +01:00
|
|
|
popupMessages.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.notificationsCountUpdated, currentAccount);
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsUnreadCounterChanged, pushDialogsCount);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showOrUpdateNotification(SystemClock.elapsedRealtime() / 1000 < 60);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (showBadgeNumber) {
|
|
|
|
setBadge(getTotalAllUnreadCount());
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int getTotalAllUnreadCount() {
|
|
|
|
int count = 0;
|
|
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
|
|
if (UserConfig.getInstance(a).isClientActivated()) {
|
|
|
|
NotificationsController controller = getInstance(a);
|
|
|
|
if (controller.showBadgeNumber) {
|
|
|
|
count += controller.total_unread_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setBadgeEnabled(boolean enabled) {
|
|
|
|
showBadgeNumber = enabled;
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
setBadge(getTotalAllUnreadCount());
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void setBadge(final int count) {
|
|
|
|
if (lastBadgeCount == count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastBadgeCount = count;
|
|
|
|
NotificationBadge.applyCount(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getShortStringForMessage(MessageObject messageObject, String[] userName) {
|
|
|
|
if (AndroidUtilities.needShowPasscode(false) || SharedConfig.isWaitingForPasscodeEnter) {
|
|
|
|
return LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
|
|
|
}
|
|
|
|
long dialog_id = messageObject.messageOwner.dialog_id;
|
|
|
|
int chat_id = messageObject.messageOwner.to_id.chat_id != 0 ? messageObject.messageOwner.to_id.chat_id : messageObject.messageOwner.to_id.channel_id;
|
|
|
|
int from_id = messageObject.messageOwner.to_id.user_id;
|
|
|
|
if (messageObject.isFcmMessage()) {
|
|
|
|
if (chat_id == 0 && from_id != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
if (!preferences.getBoolean("EnablePreviewAll", true)) {
|
|
|
|
return LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, messageObject.localName);
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
|
|
|
|
userName[0] = messageObject.localName;
|
|
|
|
}
|
|
|
|
} else if (chat_id != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
if (!preferences.getBoolean("EnablePreviewGroup", true)) {
|
|
|
|
if (!messageObject.isMegagroup() && messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
return LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, messageObject.localName);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, messageObject.localUserName, messageObject.localName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (messageObject.messageOwner.to_id.channel_id == 0 || messageObject.isMegagroup()) {
|
|
|
|
userName[0] = messageObject.localUserName;
|
|
|
|
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
|
|
|
|
userName[0] = messageObject.localName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return messageObject.messageOwner.message;
|
|
|
|
}
|
|
|
|
if (from_id == 0) {
|
|
|
|
if (messageObject.isFromUser() || messageObject.getId() < 0) {
|
|
|
|
from_id = messageObject.messageOwner.from_id;
|
|
|
|
} else {
|
|
|
|
from_id = -chat_id;
|
|
|
|
}
|
|
|
|
} else if (from_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
|
|
|
from_id = messageObject.messageOwner.from_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog_id == 0) {
|
|
|
|
if (chat_id != 0) {
|
|
|
|
dialog_id = -chat_id;
|
|
|
|
} else if (from_id != 0) {
|
|
|
|
dialog_id = from_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String name = null;
|
|
|
|
if (from_id > 0) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(from_id);
|
|
|
|
if (user != null) {
|
|
|
|
name = UserObject.getUserName(user);
|
|
|
|
if (chat_id != 0) {
|
|
|
|
userName[0] = name;
|
|
|
|
} else {
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {
|
|
|
|
userName[0] = name;
|
|
|
|
} else {
|
|
|
|
userName[0] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-from_id);
|
|
|
|
if (chat != null) {
|
|
|
|
name = chat.title;
|
|
|
|
userName[0] = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
TLRPC.Chat chat = null;
|
|
|
|
if (chat_id != 0) {
|
|
|
|
chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
|
|
|
|
if (chat == null) {
|
|
|
|
return null;
|
|
|
|
} else if (ChatObject.isChannel(chat) && !chat.megagroup) {
|
|
|
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
|
|
|
|
userName[0] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg = null;
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
return LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
|
|
|
} else {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
if (chat_id == 0 && from_id != 0 && preferences.getBoolean("EnablePreviewAll", true) || chat_id != 0 && preferences.getBoolean("EnablePreviewGroup", true)) {
|
|
|
|
if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
userName[0] = null;
|
|
|
|
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
|
|
|
|
return LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, name);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
|
|
|
return LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, name);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
|
|
|
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(((long) messageObject.messageOwner.date) * 1000), LocaleController.getInstance().formatterDay.format(((long) messageObject.messageOwner.date) * 1000));
|
|
|
|
return LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getInstance(currentAccount).getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
|
|
|
|
return messageObject.messageText.toString();
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
|
|
|
|
TLRPC.PhoneCallDiscardReason reason = messageObject.messageOwner.action.reason;
|
|
|
|
if (!messageObject.isOut() && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)) {
|
|
|
|
return LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
|
|
|
int singleUserId = messageObject.messageOwner.action.user_id;
|
|
|
|
if (singleUserId == 0 && messageObject.messageOwner.action.users.size() == 1) {
|
|
|
|
singleUserId = messageObject.messageOwner.action.users.get(0);
|
|
|
|
}
|
|
|
|
if (singleUserId != 0) {
|
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0 && !chat.megagroup) {
|
|
|
|
return LocaleController.formatString("ChannelAddedByNotification", R.string.ChannelAddedByNotification, name, chat.title);
|
|
|
|
} else {
|
|
|
|
if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
|
|
|
return LocaleController.formatString("NotificationInvitedToGroup", R.string.NotificationInvitedToGroup, name, chat.title);
|
|
|
|
} else {
|
|
|
|
TLRPC.User u2 = MessagesController.getInstance(currentAccount).getUser(singleUserId);
|
|
|
|
if (u2 == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (from_id == u2.id) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
return LocaleController.formatString("NotificationGroupAddSelfMega", R.string.NotificationGroupAddSelfMega, name, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationGroupAddSelf", R.string.NotificationGroupAddSelf, name, chat.title);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, name, chat.title, UserObject.getUserName(u2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StringBuilder names = new StringBuilder("");
|
|
|
|
for (int a = 0; a < messageObject.messageOwner.action.users.size(); a++) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.action.users.get(a));
|
|
|
|
if (user != null) {
|
|
|
|
String name2 = UserObject.getUserName(user);
|
|
|
|
if (names.length() != 0) {
|
|
|
|
names.append(", ");
|
|
|
|
}
|
|
|
|
names.append(name2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, name, chat.title, names.toString());
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
|
|
|
|
return LocaleController.formatString("NotificationInvitedToGroupByLink", R.string.NotificationInvitedToGroupByLink, name, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
|
|
|
return LocaleController.formatString("NotificationEditedGroupName", R.string.NotificationEditedGroupName, name, messageObject.messageOwner.action.title);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0 && !chat.megagroup) {
|
|
|
|
return LocaleController.formatString("ChannelPhotoEditNotification", R.string.ChannelPhotoEditNotification, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationEditedGroupPhoto", R.string.NotificationEditedGroupPhoto, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
|
|
|
if (messageObject.messageOwner.action.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
|
|
|
return LocaleController.formatString("NotificationGroupKickYou", R.string.NotificationGroupKickYou, name, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.action.user_id == from_id) {
|
|
|
|
return LocaleController.formatString("NotificationGroupLeftMember", R.string.NotificationGroupLeftMember, name, chat.title);
|
|
|
|
} else {
|
|
|
|
TLRPC.User u2 = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.action.user_id);
|
|
|
|
if (u2 == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("NotificationGroupKickMember", R.string.NotificationGroupKickMember, name, chat.title, UserObject.getUserName(u2));
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
|
|
|
|
return messageObject.messageText.toString();
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
|
|
|
|
return messageObject.messageText.toString();
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
|
|
|
|
return LocaleController.formatString("ActionMigrateFromGroupNotify", R.string.ActionMigrateFromGroupNotify, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
|
|
|
|
return LocaleController.formatString("ActionMigrateFromGroupNotify", R.string.ActionMigrateFromGroupNotify, messageObject.messageOwner.action.title);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
|
|
|
|
return messageObject.messageText.toString();
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
|
|
|
|
if (chat != null && chat.megagroup) {
|
|
|
|
if (messageObject.replyMessageObject == null) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedNoText", R.string.NotificationActionPinnedNoText, name, chat.title);
|
|
|
|
} else {
|
|
|
|
MessageObject object = messageObject.replyMessageObject;
|
|
|
|
if (object.isMusic()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedMusic", R.string.NotificationActionPinnedMusic, name, chat.title);
|
|
|
|
} else if (object.isVideo()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCF9 " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedVideo", R.string.NotificationActionPinnedVideo, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.isGif()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83C\uDFAC " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGif", R.string.NotificationActionPinnedGif, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.isVoice()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedVoice", R.string.NotificationActionPinnedVoice, name, chat.title);
|
|
|
|
} else if (object.isRoundVideo()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedRound", R.string.NotificationActionPinnedRound, name, chat.title);
|
|
|
|
} else if (object.isSticker()) {
|
|
|
|
String emoji = object.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedStickerEmoji", R.string.NotificationActionPinnedStickerEmoji, name, chat.title, emoji);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedSticker", R.string.NotificationActionPinnedSticker, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCCE " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedFile", R.string.NotificationActionPinnedFile, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || object.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGeo", R.string.NotificationActionPinnedGeo, name, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGeoLive", R.string.NotificationActionPinnedGeoLive, name, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedContact", R.string.NotificationActionPinnedContact, name, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDDBC " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedPhoto", R.string.NotificationActionPinnedPhoto, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGame", R.string.NotificationActionPinnedGame, name, chat.title);
|
|
|
|
} else if (object.messageText != null && object.messageText.length() > 0) {
|
|
|
|
CharSequence message = object.messageText;
|
|
|
|
if (message.length() > 20) {
|
|
|
|
message = message.subSequence(0, 20) + "...";
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedNoText", R.string.NotificationActionPinnedNoText, name, chat.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messageObject.replyMessageObject == null) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedNoTextChannel", R.string.NotificationActionPinnedNoTextChannel, chat.title);
|
|
|
|
} else {
|
|
|
|
MessageObject object = messageObject.replyMessageObject;
|
|
|
|
if (object.isMusic()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedMusicChannel", R.string.NotificationActionPinnedMusicChannel, chat.title);
|
|
|
|
} else if (object.isVideo()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCF9 " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedVideoChannel", R.string.NotificationActionPinnedVideoChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.isGif()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83C\uDFAC " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGifChannel", R.string.NotificationActionPinnedGifChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.isVoice()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedVoiceChannel", R.string.NotificationActionPinnedVoiceChannel, chat.title);
|
|
|
|
} else if (object.isRoundVideo()) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedRoundChannel", R.string.NotificationActionPinnedRoundChannel, chat.title);
|
|
|
|
} else if (object.isSticker()) {
|
|
|
|
String emoji = object.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedStickerEmojiChannel", R.string.NotificationActionPinnedStickerEmojiChannel, chat.title, emoji);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedStickerChannel", R.string.NotificationActionPinnedStickerChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCCE " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedFileChannel", R.string.NotificationActionPinnedFileChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || object.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGeoChannel", R.string.NotificationActionPinnedGeoChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGeoLiveChannel", R.string.NotificationActionPinnedGeoLiveChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedContactChannel", R.string.NotificationActionPinnedContactChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDDBC " + object.messageOwner.message;
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedPhotoChannel", R.string.NotificationActionPinnedPhotoChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedGameChannel", R.string.NotificationActionPinnedGameChannel, chat.title);
|
|
|
|
} else if (object.messageText != null && object.messageText.length() > 0) {
|
|
|
|
CharSequence message = object.messageText;
|
|
|
|
if (message.length() > 20) {
|
|
|
|
message = message.subSequence(0, 20) + "...";
|
|
|
|
}
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationActionPinnedNoTextChannel", R.string.NotificationActionPinnedNoTextChannel, chat.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
|
|
|
|
return messageObject.messageText.toString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messageObject.isMediaEmpty()) {
|
|
|
|
if (!TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
return messageObject.messageOwner.message;
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("Message", R.string.Message);
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
return "\uD83D\uDDBC " + messageObject.messageOwner.message;
|
|
|
|
} else if (messageObject.messageOwner.media.ttl_seconds != 0) {
|
|
|
|
return LocaleController.getString("AttachDestructingPhoto", R.string.AttachDestructingPhoto);
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isVideo()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
return "\uD83D\uDCF9 " + messageObject.messageOwner.message;
|
|
|
|
} else if (messageObject.messageOwner.media.ttl_seconds != 0) {
|
|
|
|
return LocaleController.getString("AttachDestructingVideo", R.string.AttachDestructingVideo);
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("AttachVideo", R.string.AttachVideo);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isGame()) {
|
|
|
|
return LocaleController.getString("AttachGame", R.string.AttachGame);
|
|
|
|
} else if (messageObject.isVoice()) {
|
|
|
|
return LocaleController.getString("AttachAudio", R.string.AttachAudio);
|
|
|
|
} else if (messageObject.isRoundVideo()) {
|
|
|
|
return LocaleController.getString("AttachRound", R.string.AttachRound);
|
|
|
|
} else if (messageObject.isMusic()) {
|
|
|
|
return LocaleController.getString("AttachMusic", R.string.AttachMusic);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
return LocaleController.getString("AttachContact", R.string.AttachContact);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
return LocaleController.getString("AttachLocation", R.string.AttachLocation);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
return LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
if (messageObject.isSticker()) {
|
|
|
|
String emoji = messageObject.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
return emoji + " " + LocaleController.getString("AttachSticker", R.string.AttachSticker);
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("AttachSticker", R.string.AttachSticker);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isGif()) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
return "\uD83C\uDFAC " + messageObject.messageOwner.message;
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("AttachGif", R.string.AttachGif);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
return "\uD83D\uDCCE " + messageObject.messageOwner.message;
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("AttachDocument", R.string.AttachDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return LocaleController.getString("Message", R.string.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private String getStringForMessage(MessageObject messageObject, boolean shortMessage, boolean text[]) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (AndroidUtilities.needShowPasscode(false) || SharedConfig.isWaitingForPasscodeEnter) {
|
|
|
|
return LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
long dialog_id = messageObject.messageOwner.dialog_id;
|
2015-09-24 22:52:02 +02:00
|
|
|
int chat_id = messageObject.messageOwner.to_id.chat_id != 0 ? messageObject.messageOwner.to_id.chat_id : messageObject.messageOwner.to_id.channel_id;
|
|
|
|
int from_id = messageObject.messageOwner.to_id.user_id;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (messageObject.isFcmMessage()) {
|
|
|
|
if (chat_id == 0 && from_id != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
if (!preferences.getBoolean("EnablePreviewAll", true)) {
|
|
|
|
return LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, messageObject.localName);
|
|
|
|
}
|
|
|
|
} else if (chat_id != 0) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
if (!preferences.getBoolean("EnablePreviewGroup", true)) {
|
|
|
|
if (!messageObject.isMegagroup() && messageObject.messageOwner.to_id.channel_id != 0) {
|
|
|
|
return LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, messageObject.localName);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, messageObject.localUserName, messageObject.localName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
text[0] = true;
|
|
|
|
return (String) messageObject.messageText;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
if (from_id == 0) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (messageObject.isFromUser() || messageObject.getId() < 0) {
|
2016-03-06 02:49:31 +01:00
|
|
|
from_id = messageObject.messageOwner.from_id;
|
|
|
|
} else {
|
|
|
|
from_id = -chat_id;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (from_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
from_id = messageObject.messageOwner.from_id;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog_id == 0) {
|
|
|
|
if (chat_id != 0) {
|
|
|
|
dialog_id = -chat_id;
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (from_id != 0) {
|
|
|
|
dialog_id = from_id;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
String name = null;
|
|
|
|
if (from_id > 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(from_id);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (user != null) {
|
|
|
|
name = UserObject.getUserName(user);
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-from_id);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chat != null) {
|
|
|
|
name = chat.title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == null) {
|
2014-07-10 02:15:58 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
TLRPC.Chat chat = null;
|
|
|
|
if (chat_id != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
|
2014-07-10 02:15:58 +02:00
|
|
|
if (chat == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String msg = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((int) dialog_id == 0) {
|
2015-02-26 02:32:51 +01:00
|
|
|
msg = LocaleController.getString("YouHaveNewMessage", R.string.YouHaveNewMessage);
|
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chat_id == 0 && from_id != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2014-07-10 02:15:58 +02:00
|
|
|
if (preferences.getBoolean("EnablePreviewAll", true)) {
|
|
|
|
if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
2015-11-26 22:04:02 +01:00
|
|
|
String date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(((long) messageObject.messageOwner.date) * 1000), LocaleController.getInstance().formatterDay.format(((long) messageObject.messageOwner.date) * 1000));
|
2018-07-30 04:07:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getInstance(currentAccount).getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = messageObject.messageText.toString();
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
|
|
|
|
TLRPC.PhoneCallDiscardReason reason = messageObject.messageOwner.action.reason;
|
|
|
|
if (!messageObject.isOut() && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed)) {
|
|
|
|
msg = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (messageObject.isMediaEmpty()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
if (!shortMessage) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2014-09-25 05:54:35 +02:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, name);
|
2014-09-25 05:54:35 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDDBC " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (messageObject.messageOwner.media.ttl_seconds != 0) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageSDPhoto", R.string.NotificationMessageSDPhoto, name);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessagePhoto", R.string.NotificationMessagePhoto, name);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (messageObject.isVideo()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCF9 " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (messageObject.messageOwner.media.ttl_seconds != 0) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageSDVideo", R.string.NotificationMessageSDVideo, name);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageVideo", R.string.NotificationMessageVideo, name);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else if (messageObject.isGame()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGame", R.string.NotificationMessageGame, name, messageObject.messageOwner.media.game.title);
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (messageObject.isVoice()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageAudio", R.string.NotificationMessageAudio, name);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (messageObject.isRoundVideo()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageRound", R.string.NotificationMessageRound, name);
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (messageObject.isMusic()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageMusic", R.string.NotificationMessageMusic, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageContact", R.string.NotificationMessageContact, name);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageMap", R.string.NotificationMessageMap, name);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageLiveLocation", R.string.NotificationMessageLiveLocation, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (messageObject.isSticker()) {
|
2016-05-25 23:49:47 +02:00
|
|
|
String emoji = messageObject.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageStickerEmoji", R.string.NotificationMessageStickerEmoji, name, emoji);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageSticker", R.string.NotificationMessageSticker, name);
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (messageObject.isGif()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83C\uDFAC " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGif", R.string.NotificationMessageGif, name);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCCE " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageDocument", R.string.NotificationMessageDocument, name);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else if (chat_id != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2014-07-10 02:15:58 +02:00
|
|
|
if (preferences.getBoolean("EnablePreviewGroup", true)) {
|
|
|
|
if (messageObject.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
2015-11-26 22:04:02 +01:00
|
|
|
int singleUserId = messageObject.messageOwner.action.user_id;
|
|
|
|
if (singleUserId == 0 && messageObject.messageOwner.action.users.size() == 1) {
|
|
|
|
singleUserId = messageObject.messageOwner.action.users.get(0);
|
|
|
|
}
|
|
|
|
if (singleUserId != 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0 && !chat.megagroup) {
|
2015-11-26 22:04:02 +01:00
|
|
|
msg = LocaleController.formatString("ChannelAddedByNotification", R.string.ChannelAddedByNotification, name, chat.title);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
msg = LocaleController.formatString("NotificationInvitedToGroup", R.string.NotificationInvitedToGroup, name, chat.title);
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User u2 = MessagesController.getInstance(currentAccount).getUser(singleUserId);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (u2 == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (from_id == u2.id) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (chat.megagroup) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationGroupAddSelfMega", R.string.NotificationGroupAddSelfMega, name, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationGroupAddSelf", R.string.NotificationGroupAddSelf, name, chat.title);
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, name, chat.title, UserObject.getUserName(u2));
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
StringBuilder names = new StringBuilder("");
|
|
|
|
for (int a = 0; a < messageObject.messageOwner.action.users.size(); a++) {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.action.users.get(a));
|
2015-11-26 22:04:02 +01:00
|
|
|
if (user != null) {
|
|
|
|
String name2 = UserObject.getUserName(user);
|
|
|
|
if (names.length() != 0) {
|
|
|
|
names.append(", ");
|
|
|
|
}
|
|
|
|
names.append(name2);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
msg = LocaleController.formatString("NotificationGroupAddMember", R.string.NotificationGroupAddMember, name, chat.title, names.toString());
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationInvitedToGroupByLink", R.string.NotificationInvitedToGroupByLink, name, chat.title);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationEditedGroupName", R.string.NotificationEditedGroupName, name, messageObject.messageOwner.action.title);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (messageObject.messageOwner.to_id.channel_id != 0 && !chat.megagroup) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("ChannelPhotoEditNotification", R.string.ChannelPhotoEditNotification, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationEditedGroupPhoto", R.string.NotificationEditedGroupPhoto, name, chat.title);
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (messageObject.messageOwner.action.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationGroupKickYou", R.string.NotificationGroupKickYou, name, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.action.user_id == from_id) {
|
|
|
|
msg = LocaleController.formatString("NotificationGroupLeftMember", R.string.NotificationGroupLeftMember, name, chat.title);
|
2014-07-10 02:15:58 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User u2 = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.action.user_id);
|
2014-07-10 02:15:58 +02:00
|
|
|
if (u2 == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
msg = LocaleController.formatString("NotificationGroupKickMember", R.string.NotificationGroupKickMember, name, chat.title, UserObject.getUserName(u2));
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-07-30 09:49:39 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
|
|
|
|
msg = messageObject.messageText.toString();
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
|
|
|
|
msg = messageObject.messageText.toString();
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
|
|
|
|
msg = LocaleController.formatString("ActionMigrateFromGroupNotify", R.string.ActionMigrateFromGroupNotify, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
|
|
|
|
msg = LocaleController.formatString("ActionMigrateFromGroupNotify", R.string.ActionMigrateFromGroupNotify, messageObject.messageOwner.action.title);
|
2017-07-23 14:56:38 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
|
|
|
|
msg = messageObject.messageText.toString();
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (chat != null && chat.megagroup) {
|
|
|
|
if (messageObject.replyMessageObject == null) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedNoText", R.string.NotificationActionPinnedNoText, name, chat.title);
|
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
MessageObject object = messageObject.replyMessageObject;
|
|
|
|
if (object.isMusic()) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedMusic", R.string.NotificationActionPinnedMusic, name, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isVideo()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCF9 " + object.messageOwner.message;
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedVideo", R.string.NotificationActionPinnedVideo, name, chat.title);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isGif()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83C\uDFAC " + object.messageOwner.message;
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGif", R.string.NotificationActionPinnedGif, name, chat.title);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isVoice()) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedVoice", R.string.NotificationActionPinnedVoice, name, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isRoundVideo()) {
|
2017-07-08 18:32:04 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedRound", R.string.NotificationActionPinnedRound, name, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isSticker()) {
|
|
|
|
String emoji = object.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
2016-05-25 23:49:47 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedStickerEmoji", R.string.NotificationActionPinnedStickerEmoji, name, chat.title, emoji);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedSticker", R.string.NotificationActionPinnedSticker, name, chat.title);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCCE " + object.messageOwner.message;
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedFile", R.string.NotificationActionPinnedFile, name, chat.title);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || object.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGeo", R.string.NotificationActionPinnedGeo, name, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGeoLive", R.string.NotificationActionPinnedGeoLive, name, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedContact", R.string.NotificationActionPinnedContact, name, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDDBC " + object.messageOwner.message;
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedPhoto", R.string.NotificationActionPinnedPhoto, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGame", R.string.NotificationActionPinnedGame, name, chat.title);
|
|
|
|
} else if (object.messageText != null && object.messageText.length() > 0) {
|
|
|
|
CharSequence message = object.messageText;
|
|
|
|
if (message.length() > 20) {
|
|
|
|
message = message.subSequence(0, 20) + "...";
|
|
|
|
}
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedText", R.string.NotificationActionPinnedText, name, message, chat.title);
|
2016-03-16 13:26:32 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedNoText", R.string.NotificationActionPinnedNoText, name, chat.title);
|
2016-03-16 13:26:32 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messageObject.replyMessageObject == null) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel", R.string.NotificationActionPinnedNoTextChannel, chat.title);
|
|
|
|
} else {
|
|
|
|
MessageObject object = messageObject.replyMessageObject;
|
|
|
|
if (object.isMusic()) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedMusicChannel", R.string.NotificationActionPinnedMusicChannel, chat.title);
|
|
|
|
} else if (object.isVideo()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCF9 " + object.messageOwner.message;
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedVideoChannel", R.string.NotificationActionPinnedVideoChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.isGif()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83C\uDFAC " + object.messageOwner.message;
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGifChannel", R.string.NotificationActionPinnedGifChannel, chat.title);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.isVoice()) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedVoiceChannel", R.string.NotificationActionPinnedVoiceChannel, chat.title);
|
|
|
|
} else if (object.isRoundVideo()) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedRoundChannel", R.string.NotificationActionPinnedRoundChannel, chat.title);
|
|
|
|
} else if (object.isSticker()) {
|
|
|
|
String emoji = object.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedStickerEmojiChannel", R.string.NotificationActionPinnedStickerEmojiChannel, chat.title, emoji);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedStickerChannel", R.string.NotificationActionPinnedStickerChannel, chat.title);
|
|
|
|
}
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDCCE " + object.messageOwner.message;
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedFileChannel", R.string.NotificationActionPinnedFileChannel, chat.title);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || object.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGeoChannel", R.string.NotificationActionPinnedGeoChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGeoLiveChannel", R.string.NotificationActionPinnedGeoLiveChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedContactChannel", R.string.NotificationActionPinnedContactChannel, chat.title);
|
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(object.messageOwner.message)) {
|
|
|
|
String message = "\uD83D\uDDBC " + object.messageOwner.message;
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedPhotoChannel", R.string.NotificationActionPinnedPhotoChannel, chat.title);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
2016-10-11 13:57:01 +02:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedGameChannel", R.string.NotificationActionPinnedGameChannel, chat.title);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (object.messageText != null && object.messageText.length() > 0) {
|
|
|
|
CharSequence message = object.messageText;
|
|
|
|
if (message.length() > 20) {
|
|
|
|
message = message.subSequence(0, 20) + "...";
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedTextChannel", R.string.NotificationActionPinnedTextChannel, chat.title, message);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationActionPinnedNoTextChannel", R.string.NotificationActionPinnedNoTextChannel, chat.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
|
|
|
|
msg = messageObject.messageText.toString();
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (ChatObject.isChannel(chat) && !chat.megagroup) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (messageObject.isMediaEmpty()) {
|
|
|
|
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, messageObject.messageOwner.message);
|
|
|
|
text[0] = true;
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, name);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDDBC " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("ChannelMessagePhoto", R.string.ChannelMessagePhoto, name);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isVideo()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCF9 " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageVideo", R.string.ChannelMessageVideo, name);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isVoice()) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageAudio", R.string.ChannelMessageAudio, name);
|
|
|
|
} else if (messageObject.isRoundVideo()) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageRound", R.string.ChannelMessageRound, name);
|
|
|
|
} else if (messageObject.isMusic()) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageMusic", R.string.ChannelMessageMusic, name);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageContact", R.string.ChannelMessageContact, name);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageMap", R.string.ChannelMessageMap, name);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageLiveLocation", R.string.ChannelMessageLiveLocation, name);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
if (messageObject.isSticker()) {
|
|
|
|
String emoji = messageObject.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
msg = LocaleController.formatString("ChannelMessageStickerEmoji", R.string.ChannelMessageStickerEmoji, name, emoji);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("ChannelMessageSticker", R.string.ChannelMessageSticker, name);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (messageObject.isGif()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83C\uDFAC " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("ChannelMessageGIF", R.string.ChannelMessageGIF, name);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, name, "\uD83D\uDCCE " + messageObject.messageOwner.message);
|
2017-12-08 18:35:59 +01:00
|
|
|
text[0] = true;
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
msg = LocaleController.formatString("ChannelMessageDocument", R.string.ChannelMessageDocument, name);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
if (messageObject.isMediaEmpty()) {
|
|
|
|
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, messageObject.messageOwner.message);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDDBC " + messageObject.messageOwner.message);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupPhoto", R.string.NotificationMessageGroupPhoto, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isVideo()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCF9 " + messageObject.messageOwner.message);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupVideo", R.string.NotificationMessageGroupVideo, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isVoice()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupAudio", R.string.NotificationMessageGroupAudio, name, chat.title);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (messageObject.isRoundVideo()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupRound", R.string.NotificationMessageGroupRound, name, chat.title);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageObject.isMusic()) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupMusic", R.string.NotificationMessageGroupMusic, name, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupContact", R.string.NotificationMessageGroupContact, name, chat.title);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupGame", R.string.NotificationMessageGroupGame, name, chat.title, messageObject.messageOwner.media.game.title);
|
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupMap", R.string.NotificationMessageGroupMap, name, chat.title);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupLiveLocation", R.string.NotificationMessageGroupLiveLocation, name, chat.title);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
if (messageObject.isSticker()) {
|
|
|
|
String emoji = messageObject.getStickerEmoji();
|
|
|
|
if (emoji != null) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupStickerEmoji", R.string.NotificationMessageGroupStickerEmoji, name, chat.title, emoji);
|
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupSticker", R.string.NotificationMessageGroupSticker, name, chat.title);
|
|
|
|
}
|
|
|
|
} else if (messageObject.isGif()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83C\uDFAC " + messageObject.messageOwner.message);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupGif", R.string.NotificationMessageGroupGif, name, chat.title);
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!shortMessage && Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(messageObject.messageOwner.message)) {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, name, chat.title, "\uD83D\uDCCE " + messageObject.messageOwner.message);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupDocument", R.string.NotificationMessageGroupDocument, name, chat.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (ChatObject.isChannel(chat) && !chat.megagroup) {
|
2018-07-30 04:07:02 +02:00
|
|
|
msg = LocaleController.formatString("ChannelMessageNoText", R.string.ChannelMessageNoText, name);
|
2016-03-06 02:49:31 +01:00
|
|
|
} else {
|
|
|
|
msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, name, chat.title);
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
private void scheduleNotificationRepeat() {
|
2014-09-25 05:54:35 +02:00
|
|
|
try {
|
2018-07-30 04:07:02 +02:00
|
|
|
Intent intent = new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class);
|
|
|
|
intent.putExtra("currentAccount", currentAccount);
|
|
|
|
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, intent, 0);
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2014-11-21 01:14:44 +01:00
|
|
|
int minutes = preferences.getInt("repeat_messages", 60);
|
2014-11-21 11:59:05 +01:00
|
|
|
if (minutes > 0 && personal_count > 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent);
|
2014-09-25 05:54:35 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
alarmManager.cancel(pintent);
|
2014-09-25 05:54:35 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-09-25 05:54:35 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private boolean isPersonalMessage(MessageObject messageObject) {
|
|
|
|
return messageObject.messageOwner.to_id != null && messageObject.messageOwner.to_id.chat_id == 0 && messageObject.messageOwner.to_id.channel_id == 0
|
|
|
|
&& (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getNotifyOverride(SharedPreferences preferences, long dialog_id) {
|
2018-07-30 04:07:02 +02:00
|
|
|
int notifyOverride = preferences.getInt("notify2_" + dialog_id, -1);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (notifyOverride == 3) {
|
|
|
|
int muteUntil = preferences.getInt("notifyuntil_" + dialog_id, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (muteUntil >= ConnectionsManager.getInstance(currentAccount).getCurrentTime()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
notifyOverride = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return notifyOverride;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dismissNotification() {
|
|
|
|
try {
|
2018-07-30 04:07:02 +02:00
|
|
|
lastNotificationIsNoData = false;
|
|
|
|
notificationManager.cancel(notificationId);
|
2015-10-29 18:10:07 +01:00
|
|
|
pushMessages.clear();
|
|
|
|
pushMessagesDict.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
lastWearNotifiedMessageId.clear();
|
|
|
|
for (int a = 0; a < wearNotificationsIds.size(); a++) {
|
|
|
|
notificationManager.cancel(wearNotificationsIds.valueAt(a));
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
wearNotificationsIds.clear();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
if (WearDataLayerListenerService.isWatchConnected()) {
|
|
|
|
try {
|
|
|
|
JSONObject o = new JSONObject();
|
|
|
|
o.put("id", UserConfig.getInstance(currentAccount).getClientUserId());
|
|
|
|
o.put("cancel_all", true);
|
|
|
|
WearDataLayerListenerService.sendMessageToWatch("/notify", o.toString().getBytes("UTF-8"), "remote_notifications");
|
|
|
|
} catch (JSONException ignore) {
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
/*public void playRecordSound() {
|
|
|
|
try {
|
|
|
|
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
if (soundPool == null) {
|
|
|
|
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
|
|
|
|
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
|
|
|
if (status == 0) {
|
|
|
|
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (soundRecord == 0 && !soundRecordLoaded) {
|
|
|
|
soundRecordLoaded = true;
|
|
|
|
soundRecord = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_record, 1);
|
|
|
|
}
|
|
|
|
if (soundRecord != 0) {
|
|
|
|
soundPool.play(soundRecord, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private void playInChatSound() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2016-03-16 13:26:32 +01:00
|
|
|
int notifyOverride = getNotifyOverride(preferences, opened_dialog_id);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (notifyOverride == 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) {
|
2015-10-29 18:10:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (soundPool == null) {
|
2016-03-06 02:49:31 +01:00
|
|
|
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
|
2015-10-29 18:10:07 +01:00
|
|
|
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
|
|
|
if (status == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (soundIn == 0 && !soundInLoaded) {
|
|
|
|
soundInLoaded = true;
|
|
|
|
soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
|
|
|
|
}
|
|
|
|
if (soundIn != 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private void scheduleNotificationDelay(boolean onlineReason) {
|
|
|
|
try {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("delay notification start, onlineReason = " + onlineReason);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
notificationDelayWakelock.acquire(10000);
|
2018-07-30 04:07:02 +02:00
|
|
|
notificationsQueue.cancelRunnable(notificationDelayRunnable);
|
|
|
|
notificationsQueue.postRunnable(notificationDelayRunnable, (onlineReason ? 3 * 1000 : 1000));
|
2015-02-01 19:51:02 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
showOrUpdateNotification(notifyCheck);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
protected void repeatNotificationMaybe() {
|
2015-10-29 18:10:07 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
2015-02-01 19:51:02 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-10-29 18:10:07 +01:00
|
|
|
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
|
|
|
if (hour >= 11 && hour <= 22) {
|
2018-07-30 04:07:02 +02:00
|
|
|
notificationManager.cancel(notificationId);
|
2015-10-29 18:10:07 +01:00
|
|
|
showOrUpdateNotification(true);
|
|
|
|
} else {
|
|
|
|
scheduleNotificationRepeat();
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean isEmptyVibration(long[] pattern) {
|
|
|
|
if (pattern == null || pattern.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < pattern.length; a++) {
|
|
|
|
if (pattern[0] != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TargetApi(26)
|
|
|
|
private String validateChannelId(long dialogId, String name, long[] vibrationPattern, int ledColor, Uri sound, int importance, long[] configVibrationPattern, Uri configSound, int configImportance) {
|
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
|
|
|
String key = "org.telegram.key" + dialogId;
|
|
|
|
String channelId = preferences.getString(key, null);
|
|
|
|
String settings = preferences.getString(key + "_s", null);
|
|
|
|
boolean edited = false;
|
|
|
|
StringBuilder newSettings = new StringBuilder();
|
|
|
|
String newSettingsHash;
|
|
|
|
|
|
|
|
/*NotificationChannel existingChannel = systemNotificationManager.getNotificationChannel(channelId);
|
|
|
|
if (existingChannel != null) {
|
|
|
|
int channelImportance = existingChannel.getImportance();
|
|
|
|
Uri channelSound = existingChannel.getSound();
|
|
|
|
long[] channelVibrationPattern = existingChannel.getVibrationPattern();
|
|
|
|
int channelLedColor = existingChannel.getLightColor();
|
|
|
|
if (channelVibrationPattern != null) {
|
|
|
|
for (int a = 0; a < channelVibrationPattern.length; a++) {
|
|
|
|
newSettings.append(channelVibrationPattern[a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newSettings.append(channelLedColor);
|
|
|
|
if (channelSound != null) {
|
|
|
|
newSettings.append(channelSound.toString());
|
|
|
|
}
|
|
|
|
newSettings.append(channelImportance);
|
|
|
|
newSettingsHash = Utilities.MD5(newSettings.toString());
|
|
|
|
newSettings.setLength(0);
|
|
|
|
if (!settings.equals(newSettingsHash)) {
|
|
|
|
SharedPreferences.Editor editor = null;
|
|
|
|
if (channelImportance != configImportance) {
|
|
|
|
if (editor == null) {
|
|
|
|
editor = preferences.edit();
|
|
|
|
}
|
|
|
|
int priority;
|
|
|
|
if (channelImportance == NotificationManager.IMPORTANCE_HIGH || channelImportance == NotificationManager.IMPORTANCE_MAX) {
|
|
|
|
priority = 1;
|
|
|
|
} else if (channelImportance == NotificationManager.IMPORTANCE_MIN) {
|
|
|
|
priority = 4;
|
|
|
|
} else if (channelImportance == NotificationManager.IMPORTANCE_LOW) {
|
|
|
|
priority = 5;
|
|
|
|
} else {
|
|
|
|
priority = 0;
|
|
|
|
}
|
|
|
|
editor.putInt("priority_" + dialogId, priority);
|
|
|
|
if (configImportance == importance) {
|
|
|
|
importance = channelImportance;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (configSound == null || channelSound != null || configSound != null && channelSound == null || !configSound.equals(channelSound)) {
|
|
|
|
if (editor == null) {
|
|
|
|
editor = preferences.edit();
|
|
|
|
}
|
|
|
|
String newSound;
|
|
|
|
if (channelSound == null) {
|
|
|
|
newSound = "NoSound";
|
|
|
|
editor.putString("sound_" + dialogId, "NoSound");
|
|
|
|
} else {
|
|
|
|
newSound = channelSound.toString();
|
|
|
|
Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, channelSound);
|
|
|
|
String ringtoneName = null;
|
|
|
|
if (rng != null) {
|
|
|
|
if (channelSound.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
|
|
|
|
ringtoneName = LocaleController.getString("DefaultRingtone", R.string.DefaultRingtone);
|
|
|
|
} else {
|
|
|
|
ringtoneName = rng.getTitle(ApplicationLoader.applicationContext);
|
|
|
|
}
|
|
|
|
rng.stop();
|
|
|
|
}
|
|
|
|
if (ringtoneName != null) {
|
|
|
|
editor.putString("sound_" + dialogId, ringtoneName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.putString("sound_path_" + dialogId, newSound);
|
|
|
|
if (configSound == null && sound == null || configSound != null && sound != null || configSound.equals(sound)) {
|
|
|
|
sound = channelSound;
|
|
|
|
edited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean vibrate = existingChannel.shouldVibrate();
|
|
|
|
if (isEmptyVibration(configVibrationPattern) != vibrate) {
|
|
|
|
if (editor == null) {
|
|
|
|
editor = preferences.edit();
|
|
|
|
}
|
|
|
|
editor.putInt("vibrate_" + dialogId, vibrate ? 0 : 2);
|
|
|
|
}
|
|
|
|
if (editor != null) {
|
|
|
|
editor.putBoolean("custom_" + dialogId, true);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
for (int a = 0; a < vibrationPattern.length; a++) {
|
|
|
|
newSettings.append(vibrationPattern[a]);
|
|
|
|
}
|
|
|
|
newSettings.append(ledColor);
|
|
|
|
if (sound != null) {
|
|
|
|
newSettings.append(sound.toString());
|
|
|
|
}
|
|
|
|
newSettings.append(importance);
|
|
|
|
|
|
|
|
newSettingsHash = Utilities.MD5(newSettings.toString());
|
|
|
|
if (channelId != null && !settings.equals(newSettingsHash)) {
|
|
|
|
if (edited) {
|
|
|
|
preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit();
|
|
|
|
} else {
|
|
|
|
systemNotificationManager.deleteNotificationChannel(channelId);
|
|
|
|
channelId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (channelId == null) {
|
|
|
|
channelId = currentAccount + "channel" + dialogId + "_" + Utilities.random.nextLong();
|
|
|
|
NotificationChannel notificationChannel = new NotificationChannel(channelId, name, importance);
|
|
|
|
if (ledColor != 0) {
|
|
|
|
notificationChannel.enableLights(true);
|
|
|
|
notificationChannel.setLightColor(ledColor);
|
|
|
|
}
|
|
|
|
if (!isEmptyVibration(vibrationPattern)) {
|
|
|
|
notificationChannel.enableVibration(true);
|
|
|
|
if (vibrationPattern != null && vibrationPattern.length > 0) {
|
|
|
|
notificationChannel.setVibrationPattern(vibrationPattern);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
notificationChannel.enableVibration(false);
|
|
|
|
}
|
|
|
|
AudioAttributes.Builder builder = new AudioAttributes.Builder();
|
|
|
|
builder.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
|
|
|
|
builder.setUsage(AudioAttributes.USAGE_NOTIFICATION);
|
|
|
|
if (sound != null) {
|
|
|
|
notificationChannel.setSound(sound, builder.build());
|
|
|
|
} else {
|
|
|
|
notificationChannel.setSound(null, builder.build());
|
|
|
|
}
|
|
|
|
systemNotificationManager.createNotificationChannel(notificationChannel);
|
|
|
|
preferences.edit().putString(key, channelId).putString(key + "_s", newSettingsHash).commit();
|
|
|
|
}
|
|
|
|
return channelId;
|
|
|
|
}
|
|
|
|
|
2014-07-10 02:15:58 +02:00
|
|
|
private void showOrUpdateNotification(boolean notifyAboutLast) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!UserConfig.getInstance(currentAccount).isClientActivated() || pushMessages.isEmpty()) {
|
2014-07-10 02:15:58 +02:00
|
|
|
dismissNotification();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2018-07-30 04:07:02 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).resumeNetworkMaybe();
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2014-07-11 15:54:17 +02:00
|
|
|
MessageObject lastMessageObject = pushMessages.get(0);
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2016-06-24 12:27:15 +02:00
|
|
|
int dismissDate = preferences.getInt("dismissDate", 0);
|
|
|
|
if (lastMessageObject.messageOwner.date <= dismissDate) {
|
|
|
|
dismissNotification();
|
|
|
|
return;
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
|
|
|
|
long dialog_id = lastMessageObject.getDialogId();
|
2015-03-19 00:09:45 +01:00
|
|
|
long override_dialog_id = dialog_id;
|
2015-11-26 22:04:02 +01:00
|
|
|
if (lastMessageObject.messageOwner.mentioned) {
|
2015-03-19 00:09:45 +01:00
|
|
|
override_dialog_id = lastMessageObject.messageOwner.from_id;
|
|
|
|
}
|
|
|
|
int mid = lastMessageObject.getId();
|
2015-09-24 22:52:02 +02:00
|
|
|
int chat_id = lastMessageObject.messageOwner.to_id.chat_id != 0 ? lastMessageObject.messageOwner.to_id.chat_id : lastMessageObject.messageOwner.to_id.channel_id;
|
2014-07-10 02:15:58 +02:00
|
|
|
int user_id = lastMessageObject.messageOwner.to_id.user_id;
|
|
|
|
if (user_id == 0) {
|
|
|
|
user_id = lastMessageObject.messageOwner.from_id;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
|
2014-07-10 02:15:58 +02:00
|
|
|
user_id = lastMessageObject.messageOwner.from_id;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(user_id);
|
2014-07-15 21:57:09 +02:00
|
|
|
TLRPC.Chat chat = null;
|
|
|
|
if (chat_id != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
TLRPC.FileLocation photoPath = null;
|
|
|
|
|
|
|
|
boolean notifyDisabled = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
int needVibrate = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
String choosenSoundPath;
|
2017-03-31 01:58:05 +02:00
|
|
|
int ledColor = 0xff0000ff;
|
2014-11-21 01:14:44 +01:00
|
|
|
int priority = 0;
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
int notifyOverride = getNotifyOverride(preferences, override_dialog_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean value;
|
|
|
|
if (notifyOverride == -1) {
|
|
|
|
value = (int) dialog_id < 0 ? preferences.getBoolean("EnableGroup", true) : preferences.getBoolean("EnableAll", true);
|
|
|
|
} else {
|
|
|
|
value = notifyOverride != 2;
|
|
|
|
}
|
|
|
|
if (!notifyAboutLast || !value) {
|
2014-07-10 02:15:58 +02:00
|
|
|
notifyDisabled = true;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!notifyDisabled && dialog_id == override_dialog_id && chat != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int notifyMaxCount;
|
|
|
|
int notifyDelay;
|
|
|
|
if (preferences.getBoolean("custom_" + dialog_id, false)) {
|
|
|
|
notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2);
|
|
|
|
notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60);
|
|
|
|
} else {
|
|
|
|
notifyMaxCount = 2;
|
|
|
|
notifyDelay = 3 * 60;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (notifyMaxCount != 0) {
|
|
|
|
Point dialogInfo = smartNotificationsDialogs.get(dialog_id);
|
|
|
|
if (dialogInfo == null) {
|
|
|
|
dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000));
|
|
|
|
smartNotificationsDialogs.put(dialog_id, dialogInfo);
|
|
|
|
} else {
|
|
|
|
int lastTime = dialogInfo.y;
|
|
|
|
if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) {
|
|
|
|
dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000));
|
|
|
|
} else {
|
|
|
|
int count = dialogInfo.x;
|
|
|
|
if (count < notifyMaxCount) {
|
|
|
|
dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000));
|
|
|
|
} else {
|
|
|
|
notifyDisabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 02:15:58 +02:00
|
|
|
String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
//
|
|
|
|
boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
|
|
|
|
boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
|
|
|
|
boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
|
|
|
|
boolean inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
|
|
|
|
boolean custom;
|
|
|
|
int vibrateOverride;
|
|
|
|
int priorityOverride;
|
|
|
|
if (custom = preferences.getBoolean("custom_" + dialog_id, false)) {
|
|
|
|
vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0);
|
|
|
|
priorityOverride = preferences.getInt("priority_" + dialog_id, 3);
|
|
|
|
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
|
|
|
|
} else {
|
|
|
|
vibrateOverride = 0;
|
|
|
|
priorityOverride = 3;
|
|
|
|
choosenSoundPath = null;
|
|
|
|
}
|
|
|
|
boolean vibrateOnlyIfSilent = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (chat_id != 0) {
|
|
|
|
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
|
|
|
|
choosenSoundPath = null;
|
|
|
|
} else if (choosenSoundPath == null) {
|
|
|
|
choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
|
|
|
|
}
|
|
|
|
needVibrate = preferences.getInt("vibrate_group", 0);
|
|
|
|
priority = preferences.getInt("priority_group", 1);
|
|
|
|
ledColor = preferences.getInt("GroupLed", 0xff0000ff);
|
|
|
|
} else if (user_id != 0) {
|
|
|
|
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
|
|
|
|
choosenSoundPath = null;
|
|
|
|
} else if (choosenSoundPath == null) {
|
|
|
|
choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
needVibrate = preferences.getInt("vibrate_messages", 0);
|
|
|
|
priority = preferences.getInt("priority_messages", 1);
|
|
|
|
ledColor = preferences.getInt("MessagesLed", 0xff0000ff);
|
|
|
|
}
|
|
|
|
if (custom) {
|
|
|
|
if (preferences.contains("color_" + dialog_id)) {
|
|
|
|
ledColor = preferences.getInt("color_" + dialog_id, 0);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (priorityOverride != 3) {
|
|
|
|
priority = priorityOverride;
|
|
|
|
}
|
2014-11-21 01:14:44 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (needVibrate == 4) {
|
|
|
|
vibrateOnlyIfSilent = true;
|
|
|
|
needVibrate = 0;
|
|
|
|
}
|
|
|
|
if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0 && vibrateOverride != 4) {
|
|
|
|
needVibrate = vibrateOverride;
|
|
|
|
}
|
|
|
|
if (!ApplicationLoader.mainInterfacePaused) {
|
|
|
|
if (!inAppSounds) {
|
|
|
|
choosenSoundPath = null;
|
2015-03-27 11:32:33 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!inAppVibrate) {
|
|
|
|
needVibrate = 2;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!inAppPriority) {
|
|
|
|
priority = 0;
|
|
|
|
} else if (priority == 2) {
|
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vibrateOnlyIfSilent && needVibrate != 2) {
|
|
|
|
try {
|
|
|
|
int mode = audioManager.getRingerMode();
|
|
|
|
if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) {
|
2014-08-22 16:24:33 +02:00
|
|
|
needVibrate = 2;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
//
|
|
|
|
Uri configSound = null;
|
|
|
|
long configVibrationPattern[] = null;
|
|
|
|
int configImportance = 0;
|
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
if (needVibrate == 2) {
|
|
|
|
configVibrationPattern = new long[]{0, 0};
|
|
|
|
} else if (needVibrate == 1) {
|
|
|
|
configVibrationPattern = new long[]{0, 100, 0, 100};
|
|
|
|
} else if (needVibrate == 0 || needVibrate == 4) {
|
|
|
|
configVibrationPattern = new long[]{};
|
|
|
|
} else if (needVibrate == 3) {
|
|
|
|
configVibrationPattern = new long[]{0, 1000};
|
|
|
|
}
|
|
|
|
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
|
|
|
|
if (choosenSoundPath.equals(defaultPath)) {
|
|
|
|
configSound = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
} else {
|
|
|
|
configSound = Uri.parse(choosenSoundPath);
|
2015-03-27 11:32:33 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (priority == 0) {
|
|
|
|
configImportance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
|
} else if (priority == 1 || priority == 2) {
|
|
|
|
configImportance = NotificationManager.IMPORTANCE_HIGH;
|
|
|
|
} else if (priority == 4) {
|
|
|
|
configImportance = NotificationManager.IMPORTANCE_MIN;
|
|
|
|
} else if (priority == 5) {
|
|
|
|
configImportance = NotificationManager.IMPORTANCE_LOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notifyDisabled) {
|
|
|
|
needVibrate = 0;
|
|
|
|
priority = 0;
|
|
|
|
ledColor = 0;
|
|
|
|
choosenSoundPath = null;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
|
|
|
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
|
2018-07-30 04:07:02 +02:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
if ((int) dialog_id != 0) {
|
2014-07-23 01:27:00 +02:00
|
|
|
if (pushDialogs.size() == 1) {
|
|
|
|
if (chat_id != 0) {
|
|
|
|
intent.putExtra("chatId", chat_id);
|
|
|
|
} else if (user_id != 0) {
|
|
|
|
intent.putExtra("userId", user_id);
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (AndroidUtilities.needShowPasscode(false) || SharedConfig.isWaitingForPasscodeEnter) {
|
2015-02-26 02:32:51 +01:00
|
|
|
photoPath = null;
|
|
|
|
} else {
|
|
|
|
if (pushDialogs.size() == 1) {
|
|
|
|
if (chat != null) {
|
|
|
|
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
|
|
|
|
photoPath = chat.photo.photo_small;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else if (user != null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
|
|
|
|
photoPath = user.photo.photo_small;
|
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (pushDialogs.size() == 1 && dialog_id != globalSecretChatId) {
|
2014-07-23 01:27:00 +02:00
|
|
|
intent.putExtra("encId", (int) (dialog_id >> 32));
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
intent.putExtra("currentAccount", currentAccount);
|
2014-07-10 02:15:58 +02:00
|
|
|
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
String name;
|
2018-07-30 04:07:02 +02:00
|
|
|
String chatName;
|
2014-07-10 02:15:58 +02:00
|
|
|
boolean replace = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (((chat_id != 0 && chat == null) || user == null) && lastMessageObject.isFcmMessage()) {
|
|
|
|
chatName = lastMessageObject.localName;
|
|
|
|
} else if (chat != null) {
|
|
|
|
chatName = chat.title;
|
|
|
|
} else {
|
|
|
|
chatName = UserObject.getUserName(user);
|
|
|
|
}
|
|
|
|
if ((int) dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || SharedConfig.isWaitingForPasscodeEnter) {
|
2014-07-10 02:15:58 +02:00
|
|
|
name = LocaleController.getString("AppName", R.string.AppName);
|
|
|
|
replace = false;
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
name = chatName;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
String detailText;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (UserConfig.getActivatedAccountsCount() > 1) {
|
|
|
|
if (pushDialogs.size() == 1) {
|
|
|
|
detailText = UserObject.getFirstName(UserConfig.getInstance(currentAccount).getCurrentUser());
|
|
|
|
} else {
|
|
|
|
detailText = UserObject.getFirstName(UserConfig.getInstance(currentAccount).getCurrentUser()) + "・";
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
detailText = "";
|
|
|
|
}
|
|
|
|
if (pushDialogs.size() != 1 || Build.VERSION.SDK_INT < 23) {
|
|
|
|
if (pushDialogs.size() == 1) {
|
|
|
|
detailText += LocaleController.formatPluralString("NewMessages", total_unread_count);
|
|
|
|
} else {
|
|
|
|
detailText += LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size()));
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 13:30:55 +02:00
|
|
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
|
|
|
|
.setContentTitle(name)
|
|
|
|
.setSmallIcon(R.drawable.notification)
|
|
|
|
.setAutoCancel(true)
|
2014-08-29 23:06:04 +02:00
|
|
|
.setNumber(total_unread_count)
|
2014-10-04 17:56:09 +02:00
|
|
|
.setContentIntent(contentIntent)
|
2018-07-30 04:07:02 +02:00
|
|
|
.setGroup(notificationGroup)
|
2015-01-02 23:15:07 +01:00
|
|
|
.setGroupSummary(true)
|
2018-07-30 04:07:02 +02:00
|
|
|
.setShowWhen(true)
|
|
|
|
.setWhen(((long) lastMessageObject.messageOwner.date) * 1000)
|
2015-01-02 23:15:07 +01:00
|
|
|
.setColor(0xff2ca5e0);
|
2014-07-10 13:30:55 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
long vibrationPattern[] = null;
|
|
|
|
int importance = 0;
|
|
|
|
Uri sound = null;
|
|
|
|
|
2014-11-21 20:36:21 +01:00
|
|
|
mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
|
2014-11-24 15:14:40 +01:00
|
|
|
if (chat == null && user != null && user.phone != null && user.phone.length() > 0) {
|
|
|
|
mBuilder.addPerson("tel:+" + user.phone);
|
|
|
|
}
|
2014-11-21 20:36:21 +01:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
int silent = 2;
|
2014-07-10 02:15:58 +02:00
|
|
|
String lastMessage = null;
|
2016-06-24 12:27:15 +02:00
|
|
|
boolean hasNewMessages = false;
|
2014-07-20 01:31:49 +02:00
|
|
|
if (pushMessages.size() == 1) {
|
2016-03-06 02:49:31 +01:00
|
|
|
MessageObject messageObject = pushMessages.get(0);
|
2017-12-08 18:35:59 +01:00
|
|
|
boolean text[] = new boolean[1];
|
|
|
|
String message = lastMessage = getStringForMessage(messageObject, false, text);
|
2016-03-06 02:49:31 +01:00
|
|
|
silent = messageObject.messageOwner.silent ? 1 : 0;
|
2014-07-10 02:15:58 +02:00
|
|
|
if (message == null) {
|
2014-07-20 01:31:49 +02:00
|
|
|
return;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-07-20 01:31:49 +02:00
|
|
|
if (replace) {
|
|
|
|
if (chat != null) {
|
|
|
|
message = message.replace(" @ " + name, "");
|
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (text[0]) {
|
|
|
|
message = message.replace(name + ": ", "");
|
|
|
|
} else {
|
|
|
|
message = message.replace(name + " ", "");
|
|
|
|
}
|
2014-07-20 01:31:49 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-07-23 01:27:00 +02:00
|
|
|
mBuilder.setContentText(message);
|
2014-07-20 01:31:49 +02:00
|
|
|
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
|
|
|
|
} else {
|
2014-07-23 01:27:00 +02:00
|
|
|
mBuilder.setContentText(detailText);
|
2014-07-20 01:31:49 +02:00
|
|
|
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
|
|
|
|
inboxStyle.setBigContentTitle(name);
|
|
|
|
int count = Math.min(10, pushMessages.size());
|
2017-12-08 18:35:59 +01:00
|
|
|
boolean text[] = new boolean[1];
|
2014-07-20 01:31:49 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2016-03-06 02:49:31 +01:00
|
|
|
MessageObject messageObject = pushMessages.get(i);
|
2017-12-08 18:35:59 +01:00
|
|
|
String message = getStringForMessage(messageObject, false, text);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (message == null || messageObject.messageOwner.date <= dismissDate) {
|
2014-07-20 01:31:49 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (silent == 2) {
|
2015-07-22 20:56:37 +02:00
|
|
|
lastMessage = message;
|
2016-03-06 02:49:31 +01:00
|
|
|
silent = messageObject.messageOwner.silent ? 1 : 0;
|
2014-07-20 01:31:49 +02:00
|
|
|
}
|
|
|
|
if (pushDialogs.size() == 1) {
|
|
|
|
if (replace) {
|
|
|
|
if (chat != null) {
|
|
|
|
message = message.replace(" @ " + name, "");
|
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (text[0]) {
|
|
|
|
message = message.replace(name + ": ", "");
|
|
|
|
} else {
|
|
|
|
message = message.replace(name + " ", "");
|
|
|
|
}
|
2014-07-20 01:31:49 +02:00
|
|
|
}
|
2014-07-15 21:57:09 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-07-20 01:31:49 +02:00
|
|
|
inboxStyle.addLine(message);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-07-20 01:31:49 +02:00
|
|
|
inboxStyle.setSummaryText(detailText);
|
|
|
|
mBuilder.setStyle(inboxStyle);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
Intent dismissIntent = new Intent(ApplicationLoader.applicationContext, NotificationDismissReceiver.class);
|
|
|
|
dismissIntent.putExtra("messageDate", lastMessageObject.messageOwner.date);
|
2018-07-30 04:07:02 +02:00
|
|
|
dismissIntent.putExtra("currentAccount", currentAccount);
|
2016-06-24 12:27:15 +02:00
|
|
|
mBuilder.setDeleteIntent(PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 1, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
|
2014-07-10 02:15:58 +02:00
|
|
|
if (photoPath != null) {
|
2015-02-01 19:51:02 +01:00
|
|
|
BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
|
2014-07-10 02:15:58 +02:00
|
|
|
if (img != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
mBuilder.setLargeIcon(img.getBitmap());
|
2016-06-24 12:27:15 +02:00
|
|
|
} else {
|
|
|
|
try {
|
2017-07-23 19:29:17 +02:00
|
|
|
File file = FileLoader.getPathToAttach(photoPath, true);
|
|
|
|
if (file.exists()) {
|
|
|
|
float scaleFactor = 160.0f / AndroidUtilities.dp(50);
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor;
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
|
|
if (bitmap != null) {
|
|
|
|
mBuilder.setLargeIcon(bitmap);
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
//ignore
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
if (!notifyAboutLast || silent == 1) {
|
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
importance = NotificationManager.IMPORTANCE_LOW;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
} else {
|
|
|
|
if (priority == 0) {
|
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
|
}
|
|
|
|
} else if (priority == 1 || priority == 2) {
|
2016-03-06 02:49:31 +01:00
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
importance = NotificationManager.IMPORTANCE_HIGH;
|
|
|
|
}
|
|
|
|
} else if (priority == 4) {
|
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
|
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
importance = NotificationManager.IMPORTANCE_MIN;
|
|
|
|
}
|
|
|
|
} else if (priority == 5) {
|
|
|
|
mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
|
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
importance = NotificationManager.IMPORTANCE_LOW;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (silent != 1 && !notifyDisabled) {
|
2014-07-10 02:15:58 +02:00
|
|
|
if (ApplicationLoader.mainInterfacePaused || inAppPreview) {
|
2014-09-30 00:48:11 +02:00
|
|
|
if (lastMessage.length() > 100) {
|
2016-04-22 15:49:00 +02:00
|
|
|
lastMessage = lastMessage.substring(0, 100).replace('\n', ' ').trim() + "...";
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
mBuilder.setTicker(lastMessage);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (!MediaController.getInstance().isRecordingAudio()) {
|
|
|
|
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
if (choosenSoundPath.equals(defaultPath)) {
|
|
|
|
sound = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
} else {
|
|
|
|
sound = Uri.parse(choosenSoundPath);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (choosenSoundPath.equals(defaultPath)) {
|
|
|
|
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION);
|
|
|
|
} else {
|
|
|
|
mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ledColor != 0) {
|
|
|
|
mBuilder.setLights(ledColor, 1000, 1000);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (needVibrate == 2 || MediaController.getInstance().isRecordingAudio()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
mBuilder.setVibrate(vibrationPattern = new long[]{0, 0});
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (needVibrate == 1) {
|
2018-07-30 04:07:02 +02:00
|
|
|
mBuilder.setVibrate(vibrationPattern = new long[]{0, 100, 0, 100});
|
2014-09-14 01:40:36 +02:00
|
|
|
} else if (needVibrate == 0 || needVibrate == 4) {
|
2014-08-22 16:24:33 +02:00
|
|
|
mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
|
2018-07-30 04:07:02 +02:00
|
|
|
vibrationPattern = new long[]{};
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (needVibrate == 3) {
|
2018-07-30 04:07:02 +02:00
|
|
|
mBuilder.setVibrate(vibrationPattern = new long[]{0, 1000});
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
mBuilder.setVibrate(vibrationPattern = new long[]{0, 0});
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean hasCallback = false;
|
|
|
|
if (!AndroidUtilities.needShowPasscode(false) && !SharedConfig.isWaitingForPasscodeEnter && lastMessageObject.getDialogId() == 777000) {
|
|
|
|
if (lastMessageObject.messageOwner.reply_markup != null) {
|
|
|
|
ArrayList<TLRPC.TL_keyboardButtonRow> rows = lastMessageObject.messageOwner.reply_markup.rows;
|
|
|
|
for (int a = 0, size = rows.size(); a < size; a++) {
|
|
|
|
TLRPC.TL_keyboardButtonRow row = rows.get(a);
|
|
|
|
for (int b = 0, size2 = row.buttons.size(); b < size2; b++) {
|
|
|
|
TLRPC.KeyboardButton button = row.buttons.get(b);
|
|
|
|
if (button instanceof TLRPC.TL_keyboardButtonCallback) {
|
|
|
|
Intent callbackIntent = new Intent(ApplicationLoader.applicationContext, NotificationCallbackReceiver.class);
|
|
|
|
callbackIntent.putExtra("currentAccount", currentAccount);
|
|
|
|
callbackIntent.putExtra("did", dialog_id);
|
|
|
|
if (button.data != null) {
|
|
|
|
callbackIntent.putExtra("data", button.data);
|
|
|
|
}
|
|
|
|
callbackIntent.putExtra("mid", lastMessageObject.getId());
|
|
|
|
mBuilder.addAction(0, button.text, PendingIntent.getBroadcast(ApplicationLoader.applicationContext, lastButtonId++, callbackIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
hasCallback = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!hasCallback && Build.VERSION.SDK_INT < 24 && SharedConfig.passcodeHash.length() == 0 && hasMessagesToReply()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
Intent replyIntent = new Intent(ApplicationLoader.applicationContext, PopupReplyReceiver.class);
|
2018-07-30 04:07:02 +02:00
|
|
|
replyIntent.putExtra("currentAccount", currentAccount);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
mBuilder.addAction(R.drawable.ic_ab_reply2, LocaleController.getString("Reply", R.string.Reply), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 2, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
} else {
|
|
|
|
mBuilder.addAction(R.drawable.ic_ab_reply, LocaleController.getString("Reply", R.string.Reply), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 2, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
mBuilder.setChannelId(validateChannelId(dialog_id, chatName, vibrationPattern, ledColor, sound, importance, configVibrationPattern, configSound, configImportance));
|
|
|
|
}
|
|
|
|
showExtraNotifications(mBuilder, notifyAboutLast, detailText);
|
|
|
|
lastNotificationIsNoData = false;
|
2014-08-22 16:24:33 +02:00
|
|
|
scheduleNotificationRepeat();
|
2014-07-10 02:15:58 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@SuppressLint("InlinedApi")
|
2018-07-30 04:07:02 +02:00
|
|
|
private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast, String summary) {
|
|
|
|
Notification mainNotification = notificationBuilder.build();
|
2015-09-24 22:52:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT < 18) {
|
2018-07-30 04:07:02 +02:00
|
|
|
notificationManager.notify(notificationId, mainNotification);
|
2014-10-04 17:56:09 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
ArrayList<Long> sortedDialogs = new ArrayList<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
LongSparseArray<ArrayList<MessageObject>> messagesByDialogs = new LongSparseArray<>();
|
2015-06-29 19:12:11 +02:00
|
|
|
for (int a = 0; a < pushMessages.size(); a++) {
|
|
|
|
MessageObject messageObject = pushMessages.get(a);
|
2014-10-04 17:56:09 +02:00
|
|
|
long dialog_id = messageObject.getDialogId();
|
|
|
|
|
|
|
|
ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id);
|
|
|
|
if (arrayList == null) {
|
2015-01-02 23:15:07 +01:00
|
|
|
arrayList = new ArrayList<>();
|
2014-10-04 17:56:09 +02:00
|
|
|
messagesByDialogs.put(dialog_id, arrayList);
|
|
|
|
sortedDialogs.add(0, dialog_id);
|
|
|
|
}
|
|
|
|
arrayList.add(messageObject);
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
LongSparseArray<Integer> oldIdsWear = wearNotificationsIds.clone();
|
2015-05-21 23:27:27 +02:00
|
|
|
wearNotificationsIds.clear();
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
class NotificationHolder {
|
|
|
|
int id;
|
|
|
|
Notification notification;
|
|
|
|
|
|
|
|
NotificationHolder(int i, Notification n) {
|
|
|
|
id = i;
|
|
|
|
notification = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void call() {
|
|
|
|
notificationManager.notify(id, notification);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<NotificationHolder> holders = new ArrayList<>();
|
|
|
|
JSONArray serializedNotifications = null;
|
|
|
|
if (WearDataLayerListenerService.isWatchConnected()) {
|
|
|
|
serializedNotifications = new JSONArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int b = 0, size = sortedDialogs.size(); b < size; b++) {
|
2015-06-29 19:12:11 +02:00
|
|
|
long dialog_id = sortedDialogs.get(b);
|
2014-10-04 17:56:09 +02:00
|
|
|
ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id);
|
2015-03-19 00:09:45 +01:00
|
|
|
int max_id = messageObjects.get(0).getId();
|
2018-07-30 04:07:02 +02:00
|
|
|
int lowerId = (int) dialog_id;
|
|
|
|
int highId = (int) (dialog_id >> 32);
|
|
|
|
|
|
|
|
Integer internalId = oldIdsWear.get(dialog_id);
|
|
|
|
if (internalId == null) {
|
|
|
|
if (lowerId != 0) {
|
|
|
|
internalId = lowerId;
|
|
|
|
} else {
|
|
|
|
internalId = highId;
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
oldIdsWear.remove(dialog_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject serializedChat = null;
|
|
|
|
if (serializedNotifications != null) {
|
|
|
|
serializedChat = new JSONObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if (lastWearNotifiedMessageId.get(dialog_id, 0) == max_id) {
|
|
|
|
continue;
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
lastWearNotifiedMessageId.put(dialog_id, max_id);*/
|
|
|
|
MessageObject lastMessageObject = messageObjects.get(0);
|
|
|
|
int max_date = lastMessageObject.messageOwner.date;
|
|
|
|
TLRPC.Chat chat = null;
|
|
|
|
TLRPC.User user = null;
|
|
|
|
boolean isChannel = false;
|
|
|
|
boolean isSupergroup = false;
|
|
|
|
String name;
|
2015-11-26 22:04:02 +01:00
|
|
|
TLRPC.FileLocation photoPath = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean canReply;
|
|
|
|
if (lowerId != 0) {
|
|
|
|
canReply = true;
|
|
|
|
if (lowerId > 0) {
|
|
|
|
user = MessagesController.getInstance(currentAccount).getUser(lowerId);
|
|
|
|
if (user == null) {
|
|
|
|
if (lastMessageObject.isFcmMessage()) {
|
|
|
|
name = lastMessageObject.localName;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = UserObject.getUserName(user);
|
|
|
|
if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) {
|
|
|
|
photoPath = user.photo.photo_small;
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
chat = MessagesController.getInstance(currentAccount).getChat(-lowerId);
|
|
|
|
if (chat == null) {
|
|
|
|
if (lastMessageObject.isFcmMessage()) {
|
|
|
|
isSupergroup = lastMessageObject.isMegagroup();
|
|
|
|
name = lastMessageObject.localName;
|
|
|
|
isChannel = lastMessageObject.localChannel;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isSupergroup = chat.megagroup;
|
|
|
|
isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
|
|
|
|
name = chat.title;
|
|
|
|
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
|
|
|
|
photoPath = chat.photo.photo_small;
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
|
|
|
canReply = false;
|
|
|
|
if (dialog_id != globalSecretChatId) {
|
|
|
|
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(highId);
|
|
|
|
if (encryptedChat == null) {
|
|
|
|
continue;
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
|
|
|
|
if (user == null) {
|
|
|
|
continue;
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
name = LocaleController.getString("SecretChatName", R.string.SecretChatName);
|
|
|
|
photoPath = null;
|
|
|
|
serializedChat = null;
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (AndroidUtilities.needShowPasscode(false) || SharedConfig.isWaitingForPasscodeEnter) {
|
|
|
|
name = LocaleController.getString("AppName", R.string.AppName);
|
|
|
|
photoPath = null;
|
|
|
|
canReply = false;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(name).setLatestTimestamp((long) max_date * 1000);
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
Intent msgHeardIntent = new Intent(ApplicationLoader.applicationContext, AutoMessageHeardReceiver.class);
|
2015-05-21 23:27:27 +02:00
|
|
|
msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
|
|
msgHeardIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_HEARD");
|
|
|
|
msgHeardIntent.putExtra("dialog_id", dialog_id);
|
|
|
|
msgHeardIntent.putExtra("max_id", max_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
msgHeardIntent.putExtra("currentAccount", currentAccount);
|
|
|
|
PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, internalId, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
2015-09-24 22:52:02 +02:00
|
|
|
unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent);
|
|
|
|
|
|
|
|
NotificationCompat.Action wearReplyAction = null;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((!isChannel || isSupergroup) && canReply && !SharedConfig.isWaitingForPasscodeEnter) {
|
2017-12-08 18:35:59 +01:00
|
|
|
Intent msgReplyIntent = new Intent(ApplicationLoader.applicationContext, AutoMessageReplyReceiver.class);
|
2015-09-24 22:52:02 +02:00
|
|
|
msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
|
|
msgReplyIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_REPLY");
|
|
|
|
msgReplyIntent.putExtra("dialog_id", dialog_id);
|
|
|
|
msgReplyIntent.putExtra("max_id", max_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
msgReplyIntent.putExtra("currentAccount", currentAccount);
|
|
|
|
PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, internalId, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
2017-12-08 18:35:59 +01:00
|
|
|
RemoteInput remoteInputAuto = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
|
2015-09-24 22:52:02 +02:00
|
|
|
unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto);
|
|
|
|
|
|
|
|
Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class);
|
|
|
|
replyIntent.putExtra("dialog_id", dialog_id);
|
|
|
|
replyIntent.putExtra("max_id", max_id);
|
2018-07-30 04:07:02 +02:00
|
|
|
replyIntent.putExtra("currentAccount", currentAccount);
|
|
|
|
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, internalId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
2015-09-24 22:52:02 +02:00
|
|
|
RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(LocaleController.getString("Reply", R.string.Reply)).build();
|
|
|
|
String replyToString;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (lowerId < 0) {
|
2015-09-24 22:52:02 +02:00
|
|
|
replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name);
|
|
|
|
} else {
|
|
|
|
replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).setAllowGeneratedReplies(true).addRemoteInput(remoteInputWear).build();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2014-10-04 17:56:09 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
Integer count = pushDialogs.get(dialog_id);
|
|
|
|
if (count == null) {
|
|
|
|
count = 0;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle("").setConversationTitle(String.format("%1$s (%2$s)", name, LocaleController.formatPluralString("NewMessages", Math.max(count, messageObjects.size()))));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
StringBuilder text = new StringBuilder();
|
2018-07-30 04:07:02 +02:00
|
|
|
String senderName[] = new String[1];
|
|
|
|
ArrayList<TLRPC.TL_keyboardButtonRow> rows = null;
|
|
|
|
int rowsMid = 0;
|
|
|
|
JSONArray serializedMsgs = null;
|
|
|
|
if (serializedChat != null) {
|
|
|
|
serializedMsgs = new JSONArray();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
for (int a = messageObjects.size() - 1; a >= 0; a--) {
|
|
|
|
MessageObject messageObject = messageObjects.get(a);
|
2018-07-30 04:07:02 +02:00
|
|
|
String message = getShortStringForMessage(messageObject, senderName);
|
2014-10-04 17:56:09 +02:00
|
|
|
if (message == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (text.length() > 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
text.append("\n\n");
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (senderName[0] != null) {
|
|
|
|
text.append(String.format("%1$s: %2$s", senderName[0], message));
|
|
|
|
} else {
|
|
|
|
text.append(message);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
unreadConvBuilder.addMessage(message);
|
2018-07-30 04:07:02 +02:00
|
|
|
messagingStyle.addMessage(message, ((long) messageObject.messageOwner.date) * 1000, senderName[0] == null ? "" : senderName[0]);
|
|
|
|
if (messageObject.isVoice()) {
|
|
|
|
List<NotificationCompat.MessagingStyle.Message> messages = messagingStyle.getMessages();
|
|
|
|
if (!messages.isEmpty()) {
|
|
|
|
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
|
|
|
Uri uri;
|
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
try {
|
|
|
|
uri = FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", f);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
uri = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uri = Uri.fromFile(f);
|
|
|
|
}
|
|
|
|
if (uri != null) {
|
|
|
|
NotificationCompat.MessagingStyle.Message addedMessage = messages.get(messages.size() - 1);
|
|
|
|
addedMessage.setData("audio/ogg", uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serializedMsgs != null) {
|
|
|
|
try {
|
|
|
|
JSONObject jmsg = new JSONObject();
|
|
|
|
jmsg.put("text", message);
|
|
|
|
jmsg.put("date", messageObject.messageOwner.date);
|
|
|
|
if (messageObject.isFromUser() && lowerId < 0) {
|
|
|
|
TLRPC.User sender = MessagesController.getInstance(currentAccount).getUser(messageObject.getFromId());
|
|
|
|
if (sender != null) {
|
|
|
|
jmsg.put("fname", sender.first_name);
|
|
|
|
jmsg.put("lname", sender.last_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
serializedMsgs.put(jmsg);
|
|
|
|
} catch (JSONException ignore) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog_id == 777000 && messageObject.messageOwner.reply_markup != null) {
|
|
|
|
rows = messageObject.messageOwner.reply_markup.rows;
|
|
|
|
rowsMid = messageObject.getId();
|
|
|
|
}
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 23:23:57 +02:00
|
|
|
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
|
|
|
|
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
|
2018-07-30 04:07:02 +02:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
if (lowerId != 0) {
|
|
|
|
if (lowerId > 0) {
|
|
|
|
intent.putExtra("userId", lowerId);
|
|
|
|
} else {
|
|
|
|
intent.putExtra("chatId", -lowerId);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
intent.putExtra("encId", highId);
|
2014-10-05 23:23:57 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
intent.putExtra("currentAccount", currentAccount);
|
2014-10-05 23:23:57 +02:00
|
|
|
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
|
|
|
|
if (wearReplyAction != null) {
|
|
|
|
wearableExtender.addAction(wearReplyAction);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
PendingIntent readPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, internalId, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
NotificationCompat.Action readAction = new NotificationCompat.Action.Builder(R.drawable.menu_read, LocaleController.getString("MarkAsRead", R.string.MarkAsRead).toUpperCase(), readPendingIntent).build();
|
2015-09-24 22:52:02 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
String dismissalID;
|
|
|
|
if (lowerId != 0) {
|
|
|
|
if (lowerId > 0) {
|
|
|
|
dismissalID = "tguser" + lowerId + "_" + max_id;
|
|
|
|
} else {
|
|
|
|
dismissalID = "tgchat" + (-lowerId) + "_" + max_id;
|
|
|
|
}
|
|
|
|
} else if (dialog_id != globalSecretChatId) {
|
|
|
|
dismissalID = "tgenc" + highId + "_" + max_id;
|
|
|
|
} else {
|
|
|
|
dismissalID = null;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (dismissalID != null) {
|
|
|
|
wearableExtender.setDismissalId(dismissalID);
|
|
|
|
NotificationCompat.WearableExtender summaryExtender = new NotificationCompat.WearableExtender();
|
|
|
|
summaryExtender.setDismissalId("summary_" + dismissalID);
|
|
|
|
notificationBuilder.extend(summaryExtender);
|
|
|
|
}
|
|
|
|
wearableExtender.setBridgeTag("tgaccount" + UserConfig.getInstance(currentAccount).getClientUserId());
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
long date = ((long) messageObjects.get(0).messageOwner.date) * 1000;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2014-10-04 17:56:09 +02:00
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext)
|
|
|
|
.setContentTitle(name)
|
|
|
|
.setSmallIcon(R.drawable.notification)
|
2018-07-30 04:07:02 +02:00
|
|
|
.setGroup(notificationGroup)
|
2017-12-08 18:35:59 +01:00
|
|
|
.setContentText(text.toString())
|
2016-06-24 12:27:15 +02:00
|
|
|
.setAutoCancel(true)
|
2016-10-11 13:57:01 +02:00
|
|
|
.setNumber(messageObjects.size())
|
2015-05-21 23:27:27 +02:00
|
|
|
.setColor(0xff2ca5e0)
|
2014-10-04 17:56:09 +02:00
|
|
|
.setGroupSummary(false)
|
2018-07-30 04:07:02 +02:00
|
|
|
.setWhen(date)
|
|
|
|
.setShowWhen(true)
|
|
|
|
.setShortcutId("sdid_" + dialog_id)
|
|
|
|
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
|
2016-10-11 13:57:01 +02:00
|
|
|
.setStyle(messagingStyle)
|
2014-10-05 23:23:57 +02:00
|
|
|
.setContentIntent(contentIntent)
|
2015-09-24 22:52:02 +02:00
|
|
|
.extend(wearableExtender)
|
2018-07-30 04:07:02 +02:00
|
|
|
.setSortKey("" + (Long.MAX_VALUE - date))
|
2015-06-29 19:12:11 +02:00
|
|
|
.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()))
|
2014-11-21 20:36:21 +01:00
|
|
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
if (wearReplyAction != null) {
|
|
|
|
builder.addAction(wearReplyAction);
|
|
|
|
}
|
|
|
|
builder.addAction(readAction);
|
|
|
|
if (pushDialogs.size() == 1 && !TextUtils.isEmpty(summary)) {
|
|
|
|
builder.setSubText(summary);
|
|
|
|
}
|
|
|
|
if (lowerId == 0) {
|
|
|
|
builder.setLocalOnly(true);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (photoPath != null) {
|
|
|
|
BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
|
|
|
|
if (img != null) {
|
|
|
|
builder.setLargeIcon(img.getBitmap());
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
try {
|
2017-07-23 19:29:17 +02:00
|
|
|
File file = FileLoader.getPathToAttach(photoPath, true);
|
|
|
|
if (file.exists()) {
|
|
|
|
float scaleFactor = 160.0f / AndroidUtilities.dp(50);
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor;
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
|
|
|
if (bitmap != null) {
|
|
|
|
builder.setLargeIcon(bitmap);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
//ignore
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-04 17:56:09 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!AndroidUtilities.needShowPasscode(false) && !SharedConfig.isWaitingForPasscodeEnter && rows != null) {
|
|
|
|
for (int r = 0, rc = rows.size(); r < rc; r++) {
|
|
|
|
TLRPC.TL_keyboardButtonRow row = rows.get(r);
|
|
|
|
for (int c = 0, cc = row.buttons.size(); c < cc; c++) {
|
|
|
|
TLRPC.KeyboardButton button = row.buttons.get(c);
|
|
|
|
if (button instanceof TLRPC.TL_keyboardButtonCallback) {
|
|
|
|
Intent callbackIntent = new Intent(ApplicationLoader.applicationContext, NotificationCallbackReceiver.class);
|
|
|
|
callbackIntent.putExtra("currentAccount", currentAccount);
|
|
|
|
callbackIntent.putExtra("did", dialog_id);
|
|
|
|
if (button.data != null) {
|
|
|
|
callbackIntent.putExtra("data", button.data);
|
|
|
|
}
|
|
|
|
callbackIntent.putExtra("mid", rowsMid);
|
|
|
|
builder.addAction(0, button.text, PendingIntent.getBroadcast(ApplicationLoader.applicationContext, lastButtonId++, callbackIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-24 15:14:40 +01:00
|
|
|
if (chat == null && user != null && user.phone != null && user.phone.length() > 0) {
|
|
|
|
builder.addPerson("tel:+" + user.phone);
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 26) {
|
|
|
|
builder.setChannelId(OTHER_NOTIFICATIONS_CHANNEL);
|
|
|
|
}
|
|
|
|
holders.add(new NotificationHolder(internalId, builder.build()));
|
|
|
|
wearNotificationsIds.put(dialog_id, internalId);
|
|
|
|
|
|
|
|
if (lowerId != 0) {
|
|
|
|
try {
|
|
|
|
if (serializedChat != null) {
|
|
|
|
serializedChat.put("reply", canReply);
|
|
|
|
serializedChat.put("name", name);
|
|
|
|
serializedChat.put("max_id", max_id);
|
|
|
|
serializedChat.put("max_date", max_date);
|
|
|
|
serializedChat.put("id", Math.abs(lowerId));
|
|
|
|
if (photoPath != null) {
|
|
|
|
serializedChat.put("photo", photoPath.dc_id + "_" + photoPath.volume_id + "_" + photoPath.secret);
|
|
|
|
}
|
|
|
|
if (serializedMsgs != null) {
|
|
|
|
serializedChat.put("msgs", serializedMsgs);
|
|
|
|
}
|
|
|
|
if (lowerId > 0) {
|
|
|
|
serializedChat.put("type", "user");
|
|
|
|
} else if (lowerId < 0) {
|
|
|
|
if (isChannel || isSupergroup) {
|
|
|
|
serializedChat.put("type", "channel");
|
|
|
|
} else {
|
|
|
|
serializedChat.put("type", "group");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
serializedNotifications.put(serializedChat);
|
|
|
|
}
|
|
|
|
} catch (JSONException ignore) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationManager.notify(notificationId, mainNotification);
|
|
|
|
for (int a = 0, size = holders.size(); a < size; a++) {
|
|
|
|
holders.get(a).call();
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < oldIdsWear.size(); a++) {
|
|
|
|
notificationManager.cancel(oldIdsWear.valueAt(a));
|
|
|
|
}
|
|
|
|
if (serializedNotifications != null) {
|
|
|
|
try {
|
|
|
|
JSONObject s = new JSONObject();
|
|
|
|
s.put("id", UserConfig.getInstance(currentAccount).getClientUserId());
|
|
|
|
s.put("n", serializedNotifications);
|
|
|
|
WearDataLayerListenerService.sendMessageToWatch("/notify", s.toString().getBytes("UTF-8"), "remote_notifications");
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
}
|
2014-10-04 17:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:34:47 +01:00
|
|
|
public void playOutChatSound() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
|
2015-03-26 18:34:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2015-03-27 11:32:33 +01:00
|
|
|
if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-26 18:34:47 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-03-27 11:32:33 +01:00
|
|
|
notificationsQueue.postRunnable(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) {
|
2015-05-21 23:27:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastSoundOutPlay = System.currentTimeMillis();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (soundPool == null) {
|
2016-03-06 02:49:31 +01:00
|
|
|
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
|
2015-05-21 23:27:27 +02:00
|
|
|
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
|
|
|
|
@Override
|
|
|
|
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
|
|
|
|
if (status == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (soundOut == 0 && !soundOutLoaded) {
|
|
|
|
soundOutLoaded = true;
|
2015-05-03 13:48:36 +02:00
|
|
|
soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (soundOut != 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-03-27 11:32:33 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-03-27 11:32:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void updateServerNotificationsSettings(long dialog_id) {
|
|
|
|
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.notificationsSettingsUpdated);
|
2016-03-06 02:49:31 +01:00
|
|
|
if ((int) dialog_id == 0) {
|
2015-02-01 19:51:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
|
|
|
|
req.settings = new TLRPC.TL_inputPeerNotifySettings();
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
req.settings.flags |= 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
req.settings.flags |= 2;
|
2016-03-06 02:49:31 +01:00
|
|
|
req.settings.silent = preferences.getBoolean("silent_" + dialog_id, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
int mute_type = preferences.getInt("notify2_" + dialog_id, -1);
|
|
|
|
if (mute_type != -1) {
|
|
|
|
req.settings.flags |= 4;
|
|
|
|
if (mute_type == 3) {
|
|
|
|
req.settings.mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
|
|
|
|
} else {
|
|
|
|
req.settings.mute_until = mute_type != 2 ? 0 : Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
req.peer = new TLRPC.TL_inputNotifyPeer();
|
2018-07-30 04:07:02 +02:00
|
|
|
((TLRPC.TL_inputNotifyPeer) req.peer).peer = MessagesController.getInstance(currentAccount).getInputPeer((int) dialog_id);
|
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
|
2015-02-01 19:51:02 +01:00
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|