Update to 8.0.1 (2428)

This commit is contained in:
xaxtix 2021-09-20 08:54:41 +03:00
parent 368822d20f
commit 42feed0f42
351 changed files with 22083 additions and 13428 deletions

View file

@ -13,6 +13,8 @@ import android.os.SystemClock;
import android.text.TextUtils;
import android.util.SparseArray;
import com.google.android.exoplayer2.util.Log;
import org.telegram.messenger.voip.Instance;
import org.telegram.messenger.voip.VoIPService;
import org.telegram.tgnet.TLRPC;
@ -24,6 +26,8 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import androidx.collection.LongSparseArray;
public class ChatObject {
public static final int CHAT_TYPE_CHAT = 0;
@ -55,16 +59,16 @@ public class ChatObject {
public static class Call {
public TLRPC.GroupCall call;
public int chatId;
public SparseArray<TLRPC.TL_groupCallParticipant> participants = new SparseArray<>();
public long chatId;
public LongSparseArray<TLRPC.TL_groupCallParticipant> participants = new LongSparseArray<>();
public final ArrayList<TLRPC.TL_groupCallParticipant> sortedParticipants = new ArrayList<>();
public final ArrayList<ChatObject.VideoParticipant> visibleVideoParticipants = new ArrayList<>();
public final ArrayList<VideoParticipant> visibleVideoParticipants = new ArrayList<>();
public final ArrayList<TLRPC.TL_groupCallParticipant> visibleParticipants = new ArrayList<>();
public final HashMap<String, Bitmap> thumbs = new HashMap<>();
private final HashMap<String, VideoParticipant> videoParticipantsCache = new HashMap<>();
public ArrayList<Integer> invitedUsers = new ArrayList<>();
public HashSet<Integer> invitedUsersMap = new HashSet<>();
public ArrayList<Long> invitedUsers = new ArrayList<>();
public HashSet<Long> invitedUsersMap = new HashSet<>();
public SparseArray<TLRPC.TL_groupCallParticipant> participantsBySources = new SparseArray<>();
public SparseArray<TLRPC.TL_groupCallParticipant> participantsByVideoSources = new SparseArray<>();
public SparseArray<TLRPC.TL_groupCallParticipant> participantsByPresentationSources = new SparseArray<>();
@ -91,8 +95,8 @@ public class ChatObject {
public TLRPC.Peer selfPeer;
private HashSet<Integer> loadingUids = new HashSet<>();
private HashSet<Integer> loadingSsrcs = new HashSet<>();
private HashSet<Long> loadingUids = new HashSet<>();
private HashSet<Long> loadingSsrcs = new HashSet<>();
private Runnable checkQueueRunnable;
@ -100,7 +104,7 @@ public class ChatObject {
private boolean loadingGroupCall;
private static int videoPointer;
public final SparseArray<TLRPC.TL_groupCallParticipant> currentSpeakingPeers = new SparseArray<>();
public final LongSparseArray<TLRPC.TL_groupCallParticipant> currentSpeakingPeers = new LongSparseArray<>();
private final Runnable updateCurrentSpeakingRunnable = new Runnable() {
@Override
@ -108,11 +112,19 @@ public class ChatObject {
long uptime = SystemClock.uptimeMillis();
boolean update = false;
for(int i = 0; i < currentSpeakingPeers.size(); i++) {
int key = currentSpeakingPeers.keyAt(i);
long key = currentSpeakingPeers.keyAt(i);
TLRPC.TL_groupCallParticipant participant = currentSpeakingPeers.get(key);
if (uptime - participant.lastSpeakTime >= 500) {
update = true;
currentSpeakingPeers.remove(key);
if (key > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getUser(key);
Log.d("GroupCall", "remove from speaking " + key + " " + (user == null ? null : user.first_name));
} else {
TLRPC.Chat user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getChat(-key);
Log.d("GroupCall", "remove from speaking " + key + " " + (user == null ? null : user.title));
}
i--;
}
}
@ -126,7 +138,7 @@ public class ChatObject {
}
};
public void setCall(AccountInstance account, int chatId, TLRPC.TL_phone_groupCall groupCall) {
public void setCall(AccountInstance account, long chatId, TLRPC.TL_phone_groupCall groupCall) {
this.chatId = chatId;
currentAccount = account;
call = groupCall.call;
@ -162,7 +174,7 @@ public class ChatObject {
}
public void addSelfDummyParticipant(boolean notify) {
int selfId = getSelfId();
long selfId = getSelfId();
if (participants.indexOfKey(selfId) >= 0) {
return;
}
@ -212,8 +224,8 @@ public class ChatObject {
return (call.flags & 128) != 0;
}
private int getSelfId() {
int selfId;
private long getSelfId() {
long selfId;
if (selfPeer != null) {
return MessageObject.getPeerId(selfPeer);
} else {
@ -222,13 +234,13 @@ public class ChatObject {
}
private void onParticipantsLoad(ArrayList<TLRPC.TL_groupCallParticipant> loadedParticipants, boolean fromBegin, String reqOffset, String nextOffset, int version, int participantCount) {
SparseArray<TLRPC.TL_groupCallParticipant> old = null;
int selfId = getSelfId();
LongSparseArray<TLRPC.TL_groupCallParticipant> old = null;
long selfId = getSelfId();
TLRPC.TL_groupCallParticipant oldSelf = participants.get(selfId);
if (TextUtils.isEmpty(reqOffset)) {
if (participants.size() != 0) {
old = participants;
participants = new SparseArray<>();
participants = new LongSparseArray<>();
} else {
participants.clear();
}
@ -357,7 +369,7 @@ public class ChatObject {
});
}
public void addInvitedUser(int uid) {
public void addInvitedUser(long uid) {
if (participants.get(uid) != null || invitedUsersMap.contains(uid)) {
return;
}
@ -365,13 +377,13 @@ public class ChatObject {
invitedUsers.add(uid);
}
public void processTypingsUpdate(AccountInstance accountInstance, ArrayList<Integer> uids, int date) {
public void processTypingsUpdate(AccountInstance accountInstance, ArrayList<Long> uids, int date) {
boolean updated = false;
ArrayList<Integer> participantsToLoad = null;
ArrayList<Long> participantsToLoad = null;
long time = SystemClock.elapsedRealtime();
currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.applyGroupCallVisibleParticipants, time);
for (int a = 0, N = uids.size(); a < N; a++) {
Integer id = uids.get(a);
Long id = uids.get(a);
TLRPC.TL_groupCallParticipant participant = participants.get(id);
if (participant != null) {
if (date - participant.lastTypingDate > 10) {
@ -397,8 +409,8 @@ public class ChatObject {
}
}
private void loadUnknownParticipants(ArrayList<Integer> participantsToLoad, boolean isIds, OnParticipantsLoad onLoad) {
HashSet<Integer> set = isIds ? loadingUids : loadingSsrcs;
private void loadUnknownParticipants(ArrayList<Long> participantsToLoad, boolean isIds, OnParticipantsLoad onLoad) {
HashSet<Long> set = isIds ? loadingUids : loadingSsrcs;
for (int a = 0, N = participantsToLoad.size(); a < N; a++) {
if (set.contains(participantsToLoad.get(a))) {
participantsToLoad.remove(a);
@ -414,9 +426,9 @@ public class ChatObject {
set.addAll(participantsToLoad);
TLRPC.TL_phone_getGroupParticipants req = new TLRPC.TL_phone_getGroupParticipants();
req.call = getInputGroupCall();
if (isIds) {
for (int a = 0, N = participantsToLoad.size(); a < N; a++) {
Integer uid = participantsToLoad.get(a);
for (int a = 0, N = participantsToLoad.size(); a < N; a++) {
long uid = participantsToLoad.get(a);
if (isIds) {
if (uid > 0) {
TLRPC.TL_inputPeerUser peerUser = new TLRPC.TL_inputPeerUser();
peerUser.user_id = uid;
@ -433,9 +445,9 @@ public class ChatObject {
}
req.ids.add(inputPeer);
}
} else {
req.sources.add((int) uid);
}
} else {
req.sources = participantsToLoad;
}
req.offset = "";
req.limit = 100;
@ -449,7 +461,7 @@ public class ChatObject {
currentAccount.getMessagesController().putChats(groupParticipants.chats, false);
for (int a = 0, N = groupParticipants.participants.size(); a < N; a++) {
TLRPC.TL_groupCallParticipant participant = groupParticipants.participants.get(a);
int pid = MessageObject.getPeerId(participant.peer);
long pid = MessageObject.getPeerId(participant.peer);
TLRPC.TL_groupCallParticipant oldParticipant = participants.get(pid);
if (oldParticipant != null) {
sortedParticipants.remove(oldParticipant);
@ -459,7 +471,7 @@ public class ChatObject {
sortedParticipants.add(participant);
processAllSources(participant, true);
if (invitedUsersMap.contains(pid)) {
Integer id = pid;
Long id = pid;
invitedUsersMap.remove(id);
invitedUsers.remove(id);
}
@ -530,7 +542,7 @@ public class ChatObject {
boolean updated = false;
boolean updateCurrentSpeakingList = false;
int currentTime = currentAccount.getConnectionsManager().getCurrentTime();
ArrayList<Integer> participantsToLoad = null;
ArrayList<Long> participantsToLoad = null;
long time = SystemClock.elapsedRealtime();
long uptime = SystemClock.uptimeMillis();
currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.applyGroupCallVisibleParticipants, time);
@ -547,7 +559,7 @@ public class ChatObject {
participant.hasVoiceDelayed = voice[a];
participant.lastVoiceUpdateTime = time;
}
int peerId = MessageObject.getPeerId(participant.peer);
long peerId = MessageObject.getPeerId(participant.peer);
if (levels[a] > 0.1f) {
if (voice[a] && participant.lastTypingDate + 1 < currentTime) {
if (time != participant.lastVisibleDate) {
@ -560,6 +572,13 @@ public class ChatObject {
participant.amplitude = levels[a];
if (currentSpeakingPeers.get(peerId, null) == null) {
if (peerId > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getUser(peerId);
Log.d("GroupCall", "add to current speaking " + peerId + " " + (user == null ? null : user.first_name));
} else {
TLRPC.Chat user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getChat(-peerId);
Log.d("GroupCall", "add to current speaking " + peerId + " " + (user == null ? null : user.title));
}
currentSpeakingPeers.put(peerId, participant);
updateCurrentSpeakingList = true;
}
@ -567,6 +586,15 @@ public class ChatObject {
if (uptime - participant.lastSpeakTime >= 500) {
if (currentSpeakingPeers.get(peerId, null) != null) {
currentSpeakingPeers.remove(peerId);
if (peerId > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getUser(peerId);
Log.d("GroupCall", "remove from speaking " + peerId + " " + (user == null ? null : user.first_name));
} else {
TLRPC.Chat user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getChat(-peerId);
Log.d("GroupCall", "remove from speaking " + peerId + " " + (user == null ? null : user.title));
}
updateCurrentSpeakingList = true;
}
}
@ -576,7 +604,7 @@ public class ChatObject {
if (participantsToLoad == null) {
participantsToLoad = new ArrayList<>();
}
participantsToLoad.add(ssrc[a]);
participantsToLoad.add((long) ssrc[a]);
}
}
if (participantsToLoad != null) {
@ -610,11 +638,11 @@ public class ChatObject {
}
public interface OnParticipantsLoad {
void onLoad(ArrayList<Integer> ssrcs);
void onLoad(ArrayList<Long> ssrcs);
}
public void processUnknownVideoParticipants(int[] ssrc, OnParticipantsLoad onLoad) {
ArrayList<Integer> participantsToLoad = null;
ArrayList<Long> participantsToLoad = null;
for (int a = 0; a < ssrc.length; a++) {
if (participantsBySources.get(ssrc[a]) != null || participantsByVideoSources.get(ssrc[a]) != null || participantsByPresentationSources.get(ssrc[a]) != null) {
continue;
@ -622,7 +650,7 @@ public class ChatObject {
if (participantsToLoad == null) {
participantsToLoad = new ArrayList<>();
}
participantsToLoad.add(ssrc[a]);
participantsToLoad.add((long) ssrc[a]);
}
if (participantsToLoad != null) {
loadUnknownParticipants(participantsToLoad, false, onLoad);
@ -797,7 +825,7 @@ public class ChatObject {
boolean changedOrAdded = false;
boolean speakingUpdated = false;
int selfId = getSelfId();
long selfId = getSelfId();
long time = SystemClock.elapsedRealtime();
long justJoinedId = 0;
int lastParticipantDate;
@ -809,7 +837,7 @@ public class ChatObject {
currentAccount.getNotificationCenter().postNotificationName(NotificationCenter.applyGroupCallVisibleParticipants, time);
for (int a = 0, N = update.participants.size(); a < N; a++) {
TLRPC.TL_groupCallParticipant participant = update.participants.get(a);
int pid = MessageObject.getPeerId(participant.peer);
long pid = MessageObject.getPeerId(participant.peer);
if (BuildVars.LOGS_ENABLED) {
FileLog.d("process participant " + pid + " left = " + participant.left + " versioned " + participant.versioned + " flags = " + participant.flags + " self = " + selfId + " volume = " + participant.volume);
}
@ -827,6 +855,13 @@ public class ChatObject {
sortedParticipants.remove(oldParticipant);
visibleParticipants.remove(oldParticipant);
if (currentSpeakingPeers.get(pid, null) != null) {
if (pid > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getUser(pid);
Log.d("GroupCall", "left remove from speaking " + pid + " " + (user == null ? null : user.first_name));
} else {
TLRPC.Chat user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getChat(-pid);
Log.d("GroupCall", "left remove from speaking " + pid + " " + (user == null ? null : user.title));
}
currentSpeakingPeers.remove(pid);
speakingUpdated = true;
}
@ -845,7 +880,7 @@ public class ChatObject {
updated = true;
} else {
if (invitedUsersMap.contains(pid)) {
Integer id = pid;
Long id = pid;
invitedUsersMap.remove(id);
invitedUsers.remove(id);
}
@ -856,6 +891,13 @@ public class ChatObject {
oldParticipant.muted = participant.muted;
if (participant.muted && currentSpeakingPeers.get(pid, null) != null) {
currentSpeakingPeers.remove(pid);
if (pid > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getUser(pid);
Log.d("GroupCall", "muted remove from speaking " + pid + " " + (user == null ? null : user.first_name));
} else {
TLRPC.Chat user = MessagesController.getInstance(currentAccount.getCurrentAccount()).getChat(-pid);
Log.d("GroupCall", "muted remove from speaking " + pid + " " + (user == null ? null : user.title));
}
speakingUpdated = true;
}
if (!participant.min) {
@ -1032,7 +1074,8 @@ public class ChatObject {
visibleParticipants.clear();
TLRPC.Chat chat = currentAccount.getMessagesController().getChat(chatId);
boolean isAdmin = ChatObject.canManageCalls(chat);
int selfId = getSelfId();
long selfId = getSelfId();
VoIPService service = VoIPService.getSharedInstance();
TLRPC.TL_groupCallParticipant selfParticipant = participants.get(selfId);
canStreamVideo = true;//selfParticipant != null && selfParticipant.video_joined || BuildVars.DEBUG_PRIVATE_VERSION;
@ -1447,7 +1490,7 @@ public class ChatObject {
return (chat instanceof TLRPC.TL_channel || chat instanceof TLRPC.TL_channelForbidden) && chat.megagroup;
}
public static boolean isMegagroup(int currentAccount, int chatId) {
public static boolean isMegagroup(int currentAccount, long chatId) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(chatId);
return ChatObject.isChannel(chat) && chat.megagroup;
}
@ -1521,12 +1564,12 @@ public class ChatObject {
return canUserDoAction(chat, ACTION_PIN) || ChatObject.isChannel(chat) && !chat.megagroup && chat.admin_rights != null && chat.admin_rights.edit_messages;
}
public static boolean isChannel(int chatId, int currentAccount) {
public static boolean isChannel(long chatId, int currentAccount) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(chatId);
return chat instanceof TLRPC.TL_channel || chat instanceof TLRPC.TL_channelForbidden;
}
public static boolean isCanWriteToChannel(int chatId, int currentAccount) {
public static boolean isCanWriteToChannel(long chatId, int currentAccount) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(chatId);
return ChatObject.canSendMessages(chat) || chat.megagroup;
}
@ -1553,15 +1596,6 @@ public class ChatObject {
return currentBannedRights;
}
public static TLRPC.Chat getChatByDialog(long did, int currentAccount) {
int lower_id = (int) did;
int high_id = (int) (did >> 32);
if (lower_id < 0) {
return MessagesController.getInstance(currentAccount).getChat(-lower_id);
}
return null;
}
public static boolean hasPhoto(TLRPC.Chat chat) {
return chat != null && chat.photo != null && !(chat.photo instanceof TLRPC.TL_chatPhotoEmpty);
}