Skip to content

Commit baed412

Browse files
author
DrKLO
committed
Bug fixes
1 parent a38e46c commit baed412

26 files changed

+444
-85
lines changed

TMessagesProj/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ android {
8080
defaultConfig {
8181
minSdkVersion 8
8282
targetSdkVersion 21
83-
versionCode 392
83+
versionCode 393
8484
versionName "2.0.3"
8585
}
8686
}

TMessagesProj/src/main/java/org/telegram/android/LocaleController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,11 @@ public static String formatUserStatus(TLRPC.User user) {
791791
user.status.expires = -102;
792792
}
793793
}
794+
if (user != null && user.status != null && user.status.expires <= 0) {
795+
if (MessagesController.getInstance().onlinePrivacy.containsKey(user.id)) {
796+
return getString("Online", R.string.Online);
797+
}
798+
}
794799
if (user == null || user.status == null || user.status.expires == 0 || user instanceof TLRPC.TL_userDeleted || user instanceof TLRPC.TL_userEmpty) {
795800
return getString("ALongTimeAgo", R.string.ALongTimeAgo);
796801
} else {

TMessagesProj/src/main/java/org/telegram/android/MessagesController.java

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
5252
public ArrayList<TLRPC.TL_dialog> dialogsServerOnly = new ArrayList<TLRPC.TL_dialog>();
5353
public ConcurrentHashMap<Long, TLRPC.TL_dialog> dialogs_dict = new ConcurrentHashMap<Long, TLRPC.TL_dialog>(100, 1.0f, 2);
5454
public HashMap<Integer, MessageObject> dialogMessage = new HashMap<Integer, MessageObject>();
55-
public ConcurrentHashMap<Long, ArrayList<PrintingUser>> printingUsers = new ConcurrentHashMap<Long, ArrayList<PrintingUser>>(100, 1.0f, 2);
55+
public ConcurrentHashMap<Long, ArrayList<PrintingUser>> printingUsers = new ConcurrentHashMap<Long, ArrayList<PrintingUser>>(20, 1.0f, 2);
5656
public HashMap<Long, CharSequence> printingStrings = new HashMap<Long, CharSequence>();
5757
public HashMap<Long, Boolean> sendingTypings = new HashMap<Long, Boolean>();
58+
public ConcurrentHashMap<Integer, Integer> onlinePrivacy = new ConcurrentHashMap<Integer, Integer>(20, 1.0f, 2);
5859
private int lastPrintingStringCount = 0;
5960

6061
public boolean loadingBlockedUsers = false;
@@ -316,6 +317,7 @@ public void cleanUp() {
316317
dialogMessage.clear();
317318
printingUsers.clear();
318319
printingStrings.clear();
320+
onlinePrivacy.clear();
319321
totalDialogsCount = 0;
320322
lastPrintingStringCount = 0;
321323
updatesQueue.clear();
@@ -1068,15 +1070,17 @@ public void deleteDialog(final long did, int offset, final boolean onlyHistory)
10681070

10691071
if (offset == 0) {
10701072
TLRPC.TL_dialog dialog = dialogs_dict.get(did);
1071-
if (!onlyHistory) {
1072-
dialogs.remove(dialog);
1073-
dialogsServerOnly.remove(dialog);
1074-
dialogs_dict.remove(did);
1075-
totalDialogsCount--;
1076-
} else {
1077-
dialog.unread_count = 0;
1073+
if (dialog != null) {
1074+
if (!onlyHistory) {
1075+
dialogs.remove(dialog);
1076+
dialogsServerOnly.remove(dialog);
1077+
dialogs_dict.remove(did);
1078+
totalDialogsCount--;
1079+
} else {
1080+
dialog.unread_count = 0;
1081+
}
1082+
dialogMessage.remove(dialog.top_message);
10781083
}
1079-
dialogMessage.remove(dialog.top_message);
10801084
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
10811085
@Override
10821086
public void run() {
@@ -1214,6 +1218,29 @@ public void run(TLObject response, TLRPC.TL_error error) {
12141218
processUpdatesQueue(0);
12151219
}
12161220
}
1221+
if (!onlinePrivacy.isEmpty()) {
1222+
ArrayList<Integer> toRemove = null;
1223+
int currentServerTime = ConnectionsManager.getInstance().getCurrentTime();
1224+
for (ConcurrentHashMap.Entry<Integer, Integer> entry : onlinePrivacy.entrySet()) {
1225+
if (entry.getValue() < currentServerTime - 30) {
1226+
if (toRemove == null) {
1227+
toRemove = new ArrayList<Integer>();
1228+
}
1229+
toRemove.add(entry.getKey());
1230+
}
1231+
}
1232+
if (toRemove != null) {
1233+
for (Integer uid : toRemove) {
1234+
onlinePrivacy.remove(uid);
1235+
}
1236+
AndroidUtilities.runOnUIThread(new Runnable() {
1237+
@Override
1238+
public void run() {
1239+
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_STATUS);
1240+
}
1241+
});
1242+
}
1243+
}
12171244
if (!printingUsers.isEmpty() || lastPrintingStringCount != printingUsers.size()) {
12181245
boolean updated = false;
12191246
ArrayList<Long> keys = new ArrayList<Long>(printingUsers.keySet());
@@ -2678,12 +2705,18 @@ public void processUpdates(final TLRPC.Updates updates, boolean fromQueue) {
26782705
boolean needGetDiff = false;
26792706
boolean needReceivedQueue = false;
26802707
boolean addedToQueue = false;
2708+
boolean updateStatus = false;
26812709
if (updates instanceof TLRPC.TL_updateShort) {
26822710
ArrayList<TLRPC.Update> arr = new ArrayList<TLRPC.Update>();
26832711
arr.add(updates.update);
26842712
processUpdateArray(arr, null, null);
26852713
} else if (updates instanceof TLRPC.TL_updateShortChatMessage) {
2686-
boolean missingData = getChat(updates.chat_id) == null || getUser(updates.from_id) == null;
2714+
TLRPC.User user = getUser(updates.from_id);
2715+
if (user != null && user.status != null && user.status.expires <= 0) {
2716+
onlinePrivacy.put(user.id, ConnectionsManager.getInstance().getCurrentTime());
2717+
updateStatus = true;
2718+
}
2719+
boolean missingData = getChat(updates.chat_id) == null || user == null;
26872720
if (missingData) {
26882721
needGetDiff = true;
26892722
} else {
@@ -2748,7 +2781,12 @@ public void run() {
27482781
}
27492782
}
27502783
} else if (updates instanceof TLRPC.TL_updateShortMessage) {
2751-
boolean missingData = getUser(updates.from_id) == null;
2784+
TLRPC.User user = getUser(updates.from_id);
2785+
if (user != null && user.status != null && user.status.expires <= 0) {
2786+
onlinePrivacy.put(user.id, ConnectionsManager.getInstance().getCurrentTime());
2787+
updateStatus = true;
2788+
}
2789+
boolean missingData = user == null;
27522790
if (missingData) {
27532791
needGetDiff = true;
27542792
} else {
@@ -2895,6 +2933,14 @@ public void run(TLObject response, TLRPC.TL_error error) {
28952933
}
28962934
});
28972935
}
2936+
if (updateStatus) {
2937+
AndroidUtilities.runOnUIThread(new Runnable() {
2938+
@Override
2939+
public void run() {
2940+
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_STATUS);
2941+
}
2942+
});
2943+
}
28982944
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
28992945
}
29002946

@@ -2954,9 +3000,15 @@ public void run() {
29543000
if (update instanceof TLRPC.TL_updateNewMessage) {
29553001
TLRPC.TL_updateNewMessage upd = (TLRPC.TL_updateNewMessage)update;
29563002
if (checkForUsers) {
2957-
if (usersDict.get(upd.message.from_id) == null && getUser(upd.message.from_id) == null || upd.message.to_id.chat_id != 0 && chatsDict.get(upd.message.to_id.chat_id) == null && getChat(upd.message.to_id.chat_id) == null) {
3003+
TLRPC.User user = getUser(upd.message.from_id);
3004+
if (usersDict.get(upd.message.from_id) == null && user == null || upd.message.to_id.chat_id != 0 && chatsDict.get(upd.message.to_id.chat_id) == null && getChat(upd.message.to_id.chat_id) == null) {
29583005
return false;
29593006
}
3007+
3008+
if (user != null && user.status != null && user.status.expires <= 0) {
3009+
onlinePrivacy.put(upd.message.from_id, ConnectionsManager.getInstance().getCurrentTime());
3010+
interfaceUpdateMask |= UPDATE_MASK_STATUS;
3011+
}
29603012
}
29613013
messagesArr.add(upd.message);
29623014
MessageObject obj = new MessageObject(upd.message, usersDict, 2);
@@ -3018,6 +3070,7 @@ public void run() {
30183070
arr.add(newUser);
30193071
printChanged = true;
30203072
}
3073+
onlinePrivacy.put(update.user_id, ConnectionsManager.getInstance().getCurrentTime());
30213074
}
30223075
} else if (update instanceof TLRPC.TL_updateChatParticipants) {
30233076
interfaceUpdateMask |= UPDATE_MASK_CHAT_MEMBERS;
@@ -3143,6 +3196,7 @@ public void run() {
31433196
arr.add(newUser);
31443197
printChanged = true;
31453198
}
3199+
onlinePrivacy.put(update.user_id, ConnectionsManager.getInstance().getCurrentTime());
31463200
}
31473201
} else if (update instanceof TLRPC.TL_updateEncryptedMessagesRead) {
31483202
markAsReadEncrypted.put(update.chat_id, Math.max(update.max_date, update.date));

TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.telegram.android;
1010

11+
import android.app.Activity;
1112
import android.app.AlarmManager;
1213
import android.app.PendingIntent;
1314
import android.content.Context;
@@ -235,8 +236,10 @@ private void scheduleNotificationRepeat() {
235236
try {
236237
AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE);
237238
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
238-
if (personal_count > 0) {
239-
alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000, pintent);
239+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
240+
int minutes = preferences.getInt("repeat_messages", 60);
241+
if (minutes > 0 || personal_count > 0) {
242+
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + minutes * 60 * 1000, pintent);
240243
} else {
241244
alarm.cancel(pintent);
242245
}
@@ -289,6 +292,9 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
289292
boolean inAppSounds = false;
290293
boolean inAppVibrate = false;
291294
boolean inAppPreview = false;
295+
boolean inAppPriority = false;
296+
int priority = 0;
297+
int priority_override = 0;
292298
int vibrate_override = 0;
293299

294300
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
@@ -302,7 +308,9 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
302308
inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
303309
inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
304310
inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
311+
inAppPriority = preferences.getBoolean("EnableInAppPriority", false);
305312
vibrate_override = preferences.getInt("vibrate_" + dialog_id, 0);
313+
priority_override = preferences.getInt("priority_" + dialog_id, 3);
306314

307315
choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null);
308316
if (chat_id != 0) {
@@ -312,6 +320,7 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
312320
choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
313321
}
314322
needVibrate = preferences.getInt("vibrate_group", 0);
323+
priority = preferences.getInt("priority_group", 1);
315324
ledColor = preferences.getInt("GroupLed", 0xff00ff00);
316325
} else if (user_id != 0) {
317326
if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
@@ -320,12 +329,17 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
320329
choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
321330
}
322331
needVibrate = preferences.getInt("vibrate_messages", 0);
332+
priority = preferences.getInt("priority_group", 1);
323333
ledColor = preferences.getInt("MessagesLed", 0xff00ff00);
324334
}
325335
if (preferences.contains("color_" + dialog_id)) {
326336
ledColor = preferences.getInt("color_" + dialog_id, 0);
327337
}
328338

339+
if (priority_override != 3) {
340+
priority = priority_override;
341+
}
342+
329343
if (needVibrate == 2 && (vibrate_override == 1 || vibrate_override == 3 || vibrate_override == 5) || needVibrate != 2 && vibrate_override == 2 || vibrate_override != 0) {
330344
needVibrate = vibrate_override;
331345
}
@@ -336,6 +350,11 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
336350
if (!inAppVibrate) {
337351
needVibrate = 2;
338352
}
353+
if (!inAppPriority) {
354+
priority = 0;
355+
} else if (priority == 2) {
356+
priority = 1;
357+
}
339358
}
340359
}
341360

@@ -397,9 +416,13 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
397416
.setGroup("messages")
398417
.setGroupSummary(true);
399418

400-
//if (ApplicationLoader.mainInterfacePaused) {
401-
// mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
402-
//}
419+
if (priority == 0) {
420+
mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
421+
} else if (priority == 1) {
422+
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
423+
} else if (priority == 2) {
424+
mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
425+
}
403426

404427
String lastMessage = null;
405428
String lastMessageFull = null;

TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,10 +1856,21 @@ public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
18561856
}
18571857
}
18581858

1859-
private static void prepareSendingDocumentInternal(final String path, String originalPath, final long dialog_id) {
1860-
if (path == null || path.length() == 0) {
1859+
private static void prepareSendingDocumentInternal(String path, String originalPath, Uri uri, String mime, final long dialog_id) {
1860+
if ((path == null || path.length() == 0) && uri == null) {
18611861
return;
18621862
}
1863+
MimeTypeMap myMime = MimeTypeMap.getSingleton();
1864+
if (uri != null) {
1865+
String extension = null;
1866+
if (mime != null) {
1867+
extension = myMime.getExtensionFromMimeType(mime);
1868+
}
1869+
if (extension == null) {
1870+
extension = "txt";
1871+
}
1872+
path = MediaController.copyDocumentToCache(uri, extension);
1873+
}
18631874
final File f = new File(path);
18641875
if (!f.exists() || f.length() == 0) {
18651876
return;
@@ -1893,7 +1904,6 @@ private static void prepareSendingDocumentInternal(final String path, String ori
18931904
document.size = (int)f.length();
18941905
document.dc_id = 0;
18951906
if (ext.length() != 0) {
1896-
MimeTypeMap myMime = MimeTypeMap.getSingleton();
18971907
String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
18981908
if (mimeType != null) {
18991909
document.mime_type = mimeType;
@@ -1921,34 +1931,46 @@ private static void prepareSendingDocumentInternal(final String path, String ori
19211931

19221932
final TLRPC.TL_document documentFinal = document;
19231933
final String originalPathFinal = originalPath;
1934+
final String pathFinal = path;
19241935
AndroidUtilities.runOnUIThread(new Runnable() {
19251936
@Override
19261937
public void run() {
1927-
SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, path, dialog_id);
1938+
SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, pathFinal, dialog_id);
19281939
}
19291940
});
19301941
}
19311942

1932-
public static void prepareSendingDocument(String path, String originalPath, long dialog_id) {
1933-
if (path == null || originalPath == null) {
1943+
public static void prepareSendingDocument(String path, String originalPath, Uri uri, String mine, long dialog_id) {
1944+
if ((path == null || originalPath == null) && uri == null) {
19341945
return;
19351946
}
19361947
ArrayList<String> paths = new ArrayList<String>();
19371948
ArrayList<String> originalPaths = new ArrayList<String>();
1949+
ArrayList<Uri> uris = null;
1950+
if (uri != null) {
1951+
uris = new ArrayList<Uri>();
1952+
}
19381953
paths.add(path);
19391954
originalPaths.add(originalPath);
1940-
prepareSendingDocuments(paths, originalPaths, dialog_id);
1955+
prepareSendingDocuments(paths, originalPaths, uris, mine, dialog_id);
19411956
}
19421957

1943-
public static void prepareSendingDocuments(final ArrayList<String> paths, final ArrayList<String> originalPaths, final long dialog_id) {
1944-
if (paths == null && originalPaths == null || paths != null && originalPaths != null && paths.size() != originalPaths.size()) {
1958+
public static void prepareSendingDocuments(final ArrayList<String> paths, final ArrayList<String> originalPaths, final ArrayList<Uri> uris, final String mime, final long dialog_id) {
1959+
if (paths == null && originalPaths == null && uris == null || paths != null && originalPaths != null && paths.size() != originalPaths.size()) {
19451960
return;
19461961
}
19471962
new Thread(new Runnable() {
19481963
@Override
19491964
public void run() {
1950-
for (int a = 0; a < paths.size(); a++) {
1951-
prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), dialog_id);
1965+
if (paths != null) {
1966+
for (int a = 0; a < paths.size(); a++) {
1967+
prepareSendingDocumentInternal(paths.get(a), originalPaths.get(a), null, mime, dialog_id);
1968+
}
1969+
}
1970+
if (uris != null) {
1971+
for (int a = 0; a < uris.size(); a++) {
1972+
prepareSendingDocumentInternal(null, null, uris.get(a), mime, dialog_id);
1973+
}
19521974
}
19531975
}
19541976
}).start();
@@ -2050,7 +2072,7 @@ public void run() {
20502072
}
20512073
if (sendAsDocuments != null && !sendAsDocuments.isEmpty()) {
20522074
for (int a = 0; a < sendAsDocuments.size(); a++) {
2053-
prepareSendingDocumentInternal(sendAsDocuments.get(a), sendAsDocumentsOriginal.get(a), dialog_id);
2075+
prepareSendingDocumentInternal(sendAsDocuments.get(a), sendAsDocumentsOriginal.get(a), null, "gif", dialog_id);
20542076
}
20552077
}
20562078
}

0 commit comments

Comments
 (0)