2015-05-21 23:27:27 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2015-05-21 23:27:27 +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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2015-05-21 23:27:27 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
package org.telegram.messenger;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public class AutoMessageHeardReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2016-04-22 15:49:00 +02:00
|
|
|
ApplicationLoader.postInitApplication();
|
2015-05-21 23:27:27 +02:00
|
|
|
long dialog_id = intent.getLongExtra("dialog_id", 0);
|
|
|
|
int max_id = intent.getIntExtra("max_id", 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
int currentAccount = intent.getIntExtra("currentAccount", 0);
|
2021-04-09 15:17:32 +02:00
|
|
|
if (dialog_id == 0 || max_id == 0 || !UserConfig.isValidAccount(currentAccount)) {
|
2015-05-21 23:27:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
int lowerId = (int) dialog_id;
|
|
|
|
int highId = (int) (dialog_id >> 32);
|
|
|
|
AccountInstance accountInstance = AccountInstance.getInstance(currentAccount);
|
|
|
|
if (lowerId > 0) {
|
|
|
|
TLRPC.User user = accountInstance.getMessagesController().getUser(lowerId);
|
|
|
|
if (user == null) {
|
|
|
|
Utilities.globalQueue.postRunnable(() -> {
|
|
|
|
TLRPC.User user1 = accountInstance.getMessagesStorage().getUserSync(lowerId);
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
accountInstance.getMessagesController().putUser(user1, true);
|
2020-09-30 15:48:47 +02:00
|
|
|
MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, 0, true, 0);
|
2019-07-18 15:01:39 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (lowerId < 0) {
|
|
|
|
TLRPC.Chat chat = accountInstance.getMessagesController().getChat(-lowerId);
|
|
|
|
if (chat == null) {
|
|
|
|
Utilities.globalQueue.postRunnable(() -> {
|
|
|
|
TLRPC.Chat chat1 = accountInstance.getMessagesStorage().getChatSync(-lowerId);
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
accountInstance.getMessagesController().putChat(chat1, true);
|
2020-09-30 15:48:47 +02:00
|
|
|
MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, 0, true, 0);
|
2019-07-18 15:01:39 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, 0, true, 0);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|