use of org.telegram.messenger.MessagesController in project Telegram-FOSS by Telegram-FOSS-Team.
the class VoIPPendingCall method onConnectionStateUpdated.
private boolean onConnectionStateUpdated(boolean force) {
if (!released && (force || isConnected(accountInstance) || isAirplaneMode())) {
final MessagesController messagesController = accountInstance.getMessagesController();
final TLRPC.User user = messagesController.getUser(userId);
if (user != null) {
final TLRPC.UserFull userFull = messagesController.getUserFull(user.id);
VoIPHelper.startCall(user, video, userFull != null && userFull.video_calls_available, activity, userFull, accountInstance);
} else if (isAirplaneMode()) {
VoIPHelper.startCall(null, video, false, activity, null, accountInstance);
}
release();
return true;
}
return false;
}
use of org.telegram.messenger.MessagesController in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsAdapter method sortOnlineContacts.
public void sortOnlineContacts(boolean notify) {
if (onlineContacts == null || notify && (SystemClock.elapsedRealtime() - lastSortTime) < 2000) {
return;
}
lastSortTime = SystemClock.elapsedRealtime();
try {
int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
MessagesController messagesController = MessagesController.getInstance(currentAccount);
Collections.sort(onlineContacts, (o1, o2) -> {
TLRPC.User user1 = messagesController.getUser(o2.user_id);
TLRPC.User user2 = messagesController.getUser(o1.user_id);
int status1 = 0;
int status2 = 0;
if (user1 != null) {
if (user1.self) {
status1 = currentTime + 50000;
} else if (user1.status != null) {
status1 = user1.status.expires;
}
}
if (user2 != null) {
if (user2.self) {
status2 = currentTime + 50000;
} else if (user2.status != null) {
status2 = user2.status.expires;
}
}
if (status1 > 0 && status2 > 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 < 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
return -1;
} else if (status2 < 0 || status1 != 0) {
return 1;
}
return 0;
});
if (notify) {
notifyDataSetChanged();
}
} catch (Exception e) {
FileLog.e(e);
}
}
use of org.telegram.messenger.MessagesController in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsAdapter method getItemCount.
@Override
public int getItemCount() {
MessagesController messagesController = MessagesController.getInstance(currentAccount);
ArrayList<TLRPC.Dialog> array = parentFragment.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
dialogsCount = array.size();
if (!forceShowEmptyCell && dialogsType != 7 && dialogsType != 8 && dialogsType != 11 && dialogsCount == 0 && (folderId != 0 || messagesController.isLoadingDialogs(folderId) || !MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId))) {
onlineContacts = null;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("DialogsAdapter dialogsCount=" + dialogsCount + " dialogsType=" + dialogsType + " isLoadingDialogs=" + messagesController.isLoadingDialogs(folderId) + " isDialogsEndReached=" + MessagesController.getInstance(currentAccount).isDialogsEndReached(folderId));
}
if (folderId == 1 && showArchiveHint) {
return (currentCount = 2);
}
return (currentCount = 0);
}
int count = dialogsCount;
if (dialogsType == 7 || dialogsType == 8) {
if (dialogsCount == 0) {
count++;
}
} else {
if (!messagesController.isDialogsEndReached(folderId) || dialogsCount == 0) {
count++;
}
}
boolean hasContacts = false;
if (hasHints) {
count += 2 + messagesController.hintDialogs.size();
} else if (dialogsType == 0 && messagesController.dialogs_dict.size() <= 10 && folderId == 0 && messagesController.isDialogsEndReached(folderId)) {
if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts) {
onlineContacts = null;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("DialogsAdapter loadingContacts=" + (ContactsController.getInstance(currentAccount).contacts.isEmpty() && !ContactsController.getInstance(currentAccount).doneLoadingContacts) + "dialogsCount=" + dialogsCount + " dialogsType=" + dialogsType);
}
return (currentCount = 0);
}
if (!ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
if (onlineContacts == null || prevDialogsCount != messagesController.dialogs_dict.size() || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
prevContactsCount = onlineContacts.size();
prevDialogsCount = messagesController.dialogs_dict.size();
long selfId = UserConfig.getInstance(currentAccount).clientUserId;
for (int a = 0, N = onlineContacts.size(); a < N; a++) {
long userId = onlineContacts.get(a).user_id;
if (userId == selfId || messagesController.dialogs_dict.get(userId) != null) {
onlineContacts.remove(a);
a--;
N--;
}
}
if (onlineContacts.isEmpty()) {
onlineContacts = null;
}
sortOnlineContacts(false);
}
if (onlineContacts != null) {
count += onlineContacts.size() + 2;
hasContacts = true;
}
}
}
if (folderId == 0 && onlineContacts != null) {
if (!hasContacts) {
onlineContacts = null;
}
}
if (folderId == 1 && showArchiveHint) {
count += 2;
}
if (folderId == 0 && dialogsCount != 0) {
count++;
if (dialogsCount > 10 && dialogsType == 0) {
count++;
}
}
if (dialogsType == 11 || dialogsType == 13) {
count += 2;
} else if (dialogsType == 12) {
count += 1;
}
currentCount = count;
return count;
}
use of org.telegram.messenger.MessagesController in project Telegram-FOSS by Telegram-FOSS-Team.
the class MentionsAdapter method searchForContextBot.
private void searchForContextBot(final String username, final String query) {
if (foundContextBot != null && foundContextBot.username != null && foundContextBot.username.equals(username) && searchingContextQuery != null && searchingContextQuery.equals(query)) {
return;
}
searchResultBotContext = null;
searchResultBotContextSwitch = null;
notifyDataSetChanged();
if (foundContextBot != null) {
if (!inlineMediaEnabled && username != null && query != null) {
return;
}
delegate.needChangePanelVisibility(false);
}
if (contextQueryRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(contextQueryRunnable);
contextQueryRunnable = null;
}
if (TextUtils.isEmpty(username) || searchingContextUsername != null && !searchingContextUsername.equals(username)) {
if (contextUsernameReqid != 0) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(contextUsernameReqid, true);
contextUsernameReqid = 0;
}
if (contextQueryReqid != 0) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(contextQueryReqid, true);
contextQueryReqid = 0;
}
foundContextBot = null;
inlineMediaEnabled = true;
searchingContextUsername = null;
searchingContextQuery = null;
locationProvider.stop();
noUserName = false;
if (delegate != null) {
delegate.onContextSearch(false);
}
if (username == null || username.length() == 0) {
return;
}
}
if (query == null) {
if (contextQueryReqid != 0) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(contextQueryReqid, true);
contextQueryReqid = 0;
}
searchingContextQuery = null;
if (delegate != null) {
delegate.onContextSearch(false);
}
return;
}
if (delegate != null) {
if (foundContextBot != null) {
delegate.onContextSearch(true);
} else if (username.equals("gif")) {
searchingContextUsername = "gif";
delegate.onContextSearch(false);
}
}
final MessagesController messagesController = MessagesController.getInstance(currentAccount);
final MessagesStorage messagesStorage = MessagesStorage.getInstance(currentAccount);
searchingContextQuery = query;
contextQueryRunnable = new Runnable() {
@Override
public void run() {
if (contextQueryRunnable != this) {
return;
}
contextQueryRunnable = null;
if (foundContextBot != null || noUserName) {
if (noUserName) {
return;
}
searchForContextBotResults(true, foundContextBot, query, "");
} else {
searchingContextUsername = username;
TLObject object = messagesController.getUserOrChat(searchingContextUsername);
if (object instanceof TLRPC.User) {
processFoundUser((TLRPC.User) object);
} else {
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
req.username = searchingContextUsername;
contextUsernameReqid = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (searchingContextUsername == null || !searchingContextUsername.equals(username)) {
return;
}
TLRPC.User user = null;
if (error == null) {
TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
if (!res.users.isEmpty()) {
user = res.users.get(0);
messagesController.putUser(user, false);
messagesStorage.putUsersAndChats(res.users, null, true, true);
}
}
processFoundUser(user);
}));
}
}
}
};
AndroidUtilities.runOnUIThread(contextQueryRunnable, 400);
}
use of org.telegram.messenger.MessagesController in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatMessageCell method updateCurrentUserAndChat.
private void updateCurrentUserAndChat() {
MessagesController messagesController = MessagesController.getInstance(currentAccount);
TLRPC.MessageFwdHeader fwd_from = currentMessageObject.messageOwner.fwd_from;
long currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
if (fwd_from != null && fwd_from.from_id instanceof TLRPC.TL_peerChannel && currentMessageObject.getDialogId() == currentUserId) {
currentChat = MessagesController.getInstance(currentAccount).getChat(fwd_from.from_id.channel_id);
} else if (fwd_from != null && fwd_from.saved_from_peer != null) {
if (fwd_from.saved_from_peer.user_id != 0) {
if (fwd_from.from_id instanceof TLRPC.TL_peerUser) {
currentUser = messagesController.getUser(fwd_from.from_id.user_id);
} else {
currentUser = messagesController.getUser(fwd_from.saved_from_peer.user_id);
}
} else if (fwd_from.saved_from_peer.channel_id != 0) {
if (currentMessageObject.isSavedFromMegagroup() && fwd_from.from_id instanceof TLRPC.TL_peerUser) {
currentUser = messagesController.getUser(fwd_from.from_id.user_id);
} else {
currentChat = messagesController.getChat(fwd_from.saved_from_peer.channel_id);
}
} else if (fwd_from.saved_from_peer.chat_id != 0) {
if (fwd_from.from_id instanceof TLRPC.TL_peerUser) {
currentUser = messagesController.getUser(fwd_from.from_id.user_id);
} else {
currentChat = messagesController.getChat(fwd_from.saved_from_peer.chat_id);
}
}
} else if (fwd_from != null && fwd_from.from_id instanceof TLRPC.TL_peerUser && (fwd_from.imported || currentMessageObject.getDialogId() == currentUserId)) {
currentUser = messagesController.getUser(fwd_from.from_id.user_id);
} else if (fwd_from != null && !TextUtils.isEmpty(fwd_from.from_name) && (fwd_from.imported || currentMessageObject.getDialogId() == currentUserId)) {
currentUser = new TLRPC.TL_user();
currentUser.first_name = fwd_from.from_name;
} else {
long fromId = currentMessageObject.getFromChatId();
if (DialogObject.isUserDialog(fromId) && !currentMessageObject.messageOwner.post) {
currentUser = messagesController.getUser(fromId);
} else if (DialogObject.isChatDialog(fromId)) {
currentChat = messagesController.getChat(-fromId);
} else if (currentMessageObject.messageOwner.post) {
currentChat = messagesController.getChat(currentMessageObject.messageOwner.peer_id.channel_id);
}
}
}
Aggregations