@@ -52,9 +52,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
52
52
public ArrayList <TLRPC .TL_dialog > dialogsServerOnly = new ArrayList <TLRPC .TL_dialog >();
53
53
public ConcurrentHashMap <Long , TLRPC .TL_dialog > dialogs_dict = new ConcurrentHashMap <Long , TLRPC .TL_dialog >(100 , 1.0f , 2 );
54
54
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 );
56
56
public HashMap <Long , CharSequence > printingStrings = new HashMap <Long , CharSequence >();
57
57
public HashMap <Long , Boolean > sendingTypings = new HashMap <Long , Boolean >();
58
+ public ConcurrentHashMap <Integer , Integer > onlinePrivacy = new ConcurrentHashMap <Integer , Integer >(20 , 1.0f , 2 );
58
59
private int lastPrintingStringCount = 0 ;
59
60
60
61
public boolean loadingBlockedUsers = false ;
@@ -316,6 +317,7 @@ public void cleanUp() {
316
317
dialogMessage .clear ();
317
318
printingUsers .clear ();
318
319
printingStrings .clear ();
320
+ onlinePrivacy .clear ();
319
321
totalDialogsCount = 0 ;
320
322
lastPrintingStringCount = 0 ;
321
323
updatesQueue .clear ();
@@ -1068,15 +1070,17 @@ public void deleteDialog(final long did, int offset, final boolean onlyHistory)
1068
1070
1069
1071
if (offset == 0 ) {
1070
1072
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 );
1078
1083
}
1079
- dialogMessage .remove (dialog .top_message );
1080
1084
MessagesStorage .getInstance ().getStorageQueue ().postRunnable (new Runnable () {
1081
1085
@ Override
1082
1086
public void run () {
@@ -1214,6 +1218,29 @@ public void run(TLObject response, TLRPC.TL_error error) {
1214
1218
processUpdatesQueue (0 );
1215
1219
}
1216
1220
}
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
+ }
1217
1244
if (!printingUsers .isEmpty () || lastPrintingStringCount != printingUsers .size ()) {
1218
1245
boolean updated = false ;
1219
1246
ArrayList <Long > keys = new ArrayList <Long >(printingUsers .keySet ());
@@ -2678,12 +2705,18 @@ public void processUpdates(final TLRPC.Updates updates, boolean fromQueue) {
2678
2705
boolean needGetDiff = false ;
2679
2706
boolean needReceivedQueue = false ;
2680
2707
boolean addedToQueue = false ;
2708
+ boolean updateStatus = false ;
2681
2709
if (updates instanceof TLRPC .TL_updateShort ) {
2682
2710
ArrayList <TLRPC .Update > arr = new ArrayList <TLRPC .Update >();
2683
2711
arr .add (updates .update );
2684
2712
processUpdateArray (arr , null , null );
2685
2713
} 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 ;
2687
2720
if (missingData ) {
2688
2721
needGetDiff = true ;
2689
2722
} else {
@@ -2748,7 +2781,12 @@ public void run() {
2748
2781
}
2749
2782
}
2750
2783
} 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 ;
2752
2790
if (missingData ) {
2753
2791
needGetDiff = true ;
2754
2792
} else {
@@ -2895,6 +2933,14 @@ public void run(TLObject response, TLRPC.TL_error error) {
2895
2933
}
2896
2934
});
2897
2935
}
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
+ }
2898
2944
MessagesStorage .getInstance ().saveDiffParams (MessagesStorage .lastSeqValue , MessagesStorage .lastPtsValue , MessagesStorage .lastDateValue , MessagesStorage .lastQtsValue );
2899
2945
}
2900
2946
@@ -2954,9 +3000,15 @@ public void run() {
2954
3000
if (update instanceof TLRPC .TL_updateNewMessage ) {
2955
3001
TLRPC .TL_updateNewMessage upd = (TLRPC .TL_updateNewMessage )update ;
2956
3002
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 ) {
2958
3005
return false ;
2959
3006
}
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
+ }
2960
3012
}
2961
3013
messagesArr .add (upd .message );
2962
3014
MessageObject obj = new MessageObject (upd .message , usersDict , 2 );
@@ -3018,6 +3070,7 @@ public void run() {
3018
3070
arr .add (newUser );
3019
3071
printChanged = true ;
3020
3072
}
3073
+ onlinePrivacy .put (update .user_id , ConnectionsManager .getInstance ().getCurrentTime ());
3021
3074
}
3022
3075
} else if (update instanceof TLRPC .TL_updateChatParticipants ) {
3023
3076
interfaceUpdateMask |= UPDATE_MASK_CHAT_MEMBERS ;
@@ -3143,6 +3196,7 @@ public void run() {
3143
3196
arr .add (newUser );
3144
3197
printChanged = true ;
3145
3198
}
3199
+ onlinePrivacy .put (update .user_id , ConnectionsManager .getInstance ().getCurrentTime ());
3146
3200
}
3147
3201
} else if (update instanceof TLRPC .TL_updateEncryptedMessagesRead ) {
3148
3202
markAsReadEncrypted .put (update .chat_id , Math .max (update .max_date , update .date ));
0 commit comments