Java Code Examples for org.telegram.tgnet.TLRPC#Dialog

The following examples show how to use org.telegram.tgnet.TLRPC#Dialog . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogObject.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void initDialog(TLRPC.Dialog dialog) {
    if (dialog == null || dialog.id != 0) {
        return;
    }
    if (dialog instanceof TLRPC.TL_dialog) {
        if (dialog.peer == null) {
            return;
        }
        if (dialog.peer.user_id != 0) {
            dialog.id = dialog.peer.user_id;
        } else if (dialog.peer.chat_id != 0) {
            dialog.id = -dialog.peer.chat_id;
        } else {
            dialog.id = -dialog.peer.channel_id;
        }
    } else if (dialog instanceof TLRPC.TL_dialogFolder) {
        TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
        dialog.id = makeFolderDialogId(dialogFolder.folder.id);
    }
}
 
Example 2
Source File: DialogCell.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setDialog(TLRPC.Dialog dialog, int type, int folder) {
    currentDialogId = dialog.id;
    isDialogCell = true;
    if (dialog instanceof TLRPC.TL_dialogFolder) {
        TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
        currentDialogFolderId = dialogFolder.folder.id;
        if (archivedChatsDrawable != null) {
            archivedChatsDrawable.setCell(this);
        }
    } else {
        currentDialogFolderId = 0;
    }
    dialogsType = type;
    folderId = folder;
    messageId = 0;
    update(0);
    checkOnline();
}
 
Example 3
Source File: DialogsAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public TLObject getItem(int i) {
    if (onlineContacts != null) {
        i -= 3;
        if (i < 0 || i >= onlineContacts.size()) {
            return null;
        }
        return MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(i).user_id);
    }
    if (showArchiveHint) {
        i -= 2;
    }
    ArrayList<TLRPC.Dialog> arrayList = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
    if (hasHints) {
        int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
        if (i < 2 + count) {
            return MessagesController.getInstance(currentAccount).hintDialogs.get(i - 1);
        } else {
            i -= count + 2;
        }
    }
    if (i < 0 || i >= arrayList.size()) {
        return null;
    }
    return arrayList.get(i);
}
 
Example 4
Source File: DialogsAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void notifyItemMoved(int fromPosition, int toPosition) {
    ArrayList<TLRPC.Dialog> dialogs = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, false);
    int fromIndex = fixPosition(fromPosition);
    int toIndex = fixPosition(toPosition);
    TLRPC.Dialog fromDialog = dialogs.get(fromIndex);
    TLRPC.Dialog toDialog = dialogs.get(toIndex);
    if (dialogsType == 7 || dialogsType == 8) {
        MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
        int idx1 = filter.pinnedDialogs.get(fromDialog.id);
        int idx2 = filter.pinnedDialogs.get(toDialog.id);
        filter.pinnedDialogs.put(fromDialog.id, idx2);
        filter.pinnedDialogs.put(toDialog.id, idx1);
    } else {
        int oldNum = fromDialog.pinnedNum;
        fromDialog.pinnedNum = toDialog.pinnedNum;
        toDialog.pinnedNum = oldNum;
    }
    Collections.swap(dialogs, fromIndex, toIndex);
    super.notifyItemMoved(fromPosition, toPosition);
}
 
Example 5
Source File: DialogsAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public TLObject getItem(int i) {
    if (onlineContacts != null) {
        i -= 3;
        if (i < 0 || i >= onlineContacts.size()) {
            return null;
        }
        return MessagesController.getInstance(currentAccount).getUser(onlineContacts.get(i).user_id);
    }
    if (showArchiveHint) {
        i -= 2;
    }
    ArrayList<TLRPC.Dialog> arrayList = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
    if (hasHints) {
        int count = MessagesController.getInstance(currentAccount).hintDialogs.size();
        if (i < 2 + count) {
            return MessagesController.getInstance(currentAccount).hintDialogs.get(i - 1);
        } else {
            i -= count + 2;
        }
    }
    if (i < 0 || i >= arrayList.size()) {
        return null;
    }
    return arrayList.get(i);
}
 
Example 6
Source File: DialogsSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    HintDialogCell cell = (HintDialogCell) holder.itemView;

    TLRPC.TL_topPeer peer = MediaDataController.getInstance(currentAccount).hints.get(position);
    TLRPC.Dialog dialog = new TLRPC.TL_dialog();
    TLRPC.Chat chat = null;
    TLRPC.User user = null;
    int did = 0;
    if (peer.peer.user_id != 0) {
        did = peer.peer.user_id;
        user = MessagesController.getInstance(currentAccount).getUser(peer.peer.user_id);
    } else if (peer.peer.channel_id != 0) {
        did = -peer.peer.channel_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.channel_id);
    } else if (peer.peer.chat_id != 0) {
        did = -peer.peer.chat_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.chat_id);
    }
    cell.setTag(did);
    String name = "";
    if (user != null) {
        name = UserObject.getFirstName(user);
    } else if (chat != null) {
        name = chat.title;
    }
    cell.setDialog(did, true, name);
}
 
Example 7
Source File: DialogsSearchAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    HintDialogCell cell = (HintDialogCell) holder.itemView;

    TLRPC.TL_topPeer peer = MediaDataController.getInstance(currentAccount).hints.get(position);
    TLRPC.Dialog dialog = new TLRPC.TL_dialog();
    TLRPC.Chat chat = null;
    TLRPC.User user = null;
    int did = 0;
    if (peer.peer.user_id != 0) {
        did = peer.peer.user_id;
        user = MessagesController.getInstance(currentAccount).getUser(peer.peer.user_id);
    } else if (peer.peer.channel_id != 0) {
        did = -peer.peer.channel_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.channel_id);
    } else if (peer.peer.chat_id != 0) {
        did = -peer.peer.chat_id;
        chat = MessagesController.getInstance(currentAccount).getChat(peer.peer.chat_id);
    }
    cell.setTag(did);
    String name = "";
    if (user != null) {
        name = UserObject.getFirstName(user);
    } else if (chat != null) {
        name = chat.title;
    }
    cell.setDialog(did, true, name);
}
 
Example 8
Source File: ShareAlert.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder.getItemViewType() == 0) {
        ShareDialogCell cell = (ShareDialogCell) holder.itemView;
        TLRPC.Dialog dialog = getItem(position);
        cell.setDialog((int) dialog.id, selectedDialogs.indexOfKey(dialog.id) >= 0, null);
    }
}
 
Example 9
Source File: HintDialogCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void update(int mask) {
    if ((mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
        if (currentUser != null) {
            currentUser = MessagesController.getInstance(currentAccount).getUser(currentUser.id);
            imageView.invalidate();
            invalidate();
        }
    }
    if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) {
        return;
    }
    TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
    if (dialog != null && dialog.unread_count != 0) {
        if (lastUnreadCount != dialog.unread_count) {
            lastUnreadCount = dialog.unread_count;
            String countString = String.format("%d", dialog.unread_count);
            countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
            countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            if (mask != 0) {
                invalidate();
            }
        }
    } else if (countLayout != null) {
        if (mask != 0) {
            invalidate();
        }
        lastUnreadCount = 0;
        countLayout = null;
    }
}
 
Example 10
Source File: DialogCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void checkCurrentDialogIndex(boolean frozen) {
    ArrayList<TLRPC.Dialog> dialogsArray = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, frozen);
    if (index < dialogsArray.size()) {
        TLRPC.Dialog dialog = dialogsArray.get(index);
        TLRPC.Dialog nextDialog = index + 1 < dialogsArray.size() ? dialogsArray.get(index + 1) : null;
        TLRPC.DraftMessage newDraftMessage = MediaDataController.getInstance(currentAccount).getDraft(currentDialogId);
        MessageObject newMessageObject;
        if (currentDialogFolderId != 0) {
            newMessageObject = findFolderTopMessage();
        } else {
            newMessageObject = MessagesController.getInstance(currentAccount).dialogMessage.get(dialog.id);
        }
        if (currentDialogId != dialog.id ||
                message != null && message.getId() != dialog.top_message ||
                newMessageObject != null && newMessageObject.messageOwner.edit_date != currentEditDate ||
                unreadCount != dialog.unread_count ||
                mentionCount != dialog.unread_mentions_count ||
                markUnread != dialog.unread_mark ||
                message != newMessageObject ||
                message == null && newMessageObject != null || newDraftMessage != draftMessage || drawPin != dialog.pinned) {
            boolean dialogChanged = currentDialogId != dialog.id;
            currentDialogId = dialog.id;
            if (dialog instanceof TLRPC.TL_dialogFolder) {
                TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
                currentDialogFolderId = dialogFolder.folder.id;
            } else {
                currentDialogFolderId = 0;
            }
            if (dialogsType == 7 || dialogsType == 8) {
                MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
                fullSeparator = dialog instanceof TLRPC.TL_dialog && nextDialog != null && filter != null && filter.pinnedDialogs.indexOfKey(dialog.id) >= 0 && filter.pinnedDialogs.indexOfKey(nextDialog.id) < 0;
                fullSeparator2 = false;
            } else {
                fullSeparator = dialog instanceof TLRPC.TL_dialog && dialog.pinned && nextDialog != null && !nextDialog.pinned;
                fullSeparator2 = dialog instanceof TLRPC.TL_dialogFolder && nextDialog != null && !nextDialog.pinned;
            }
            update(0);
            if (dialogChanged) {
                reorderIconProgress = drawPin && drawReorder ? 1.0f : 0.0f;
            }
            checkOnline();
        }
    }
}
 
Example 11
Source File: DialogObject.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static long getLastMessageOrDraftDate(TLRPC.Dialog dialog, TLRPC.DraftMessage draftMessage) {
    return draftMessage != null && draftMessage.date >= dialog.last_message_date ? draftMessage.date : dialog.last_message_date;
}
 
Example 12
Source File: DialogObject.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isChannel(TLRPC.Dialog dialog) {
    return dialog != null && (dialog.flags & 1) != 0;
}
 
Example 13
Source File: DialogCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void checkCurrentDialogIndex(boolean frozen) {
    ArrayList<TLRPC.Dialog> dialogsArray = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, frozen);
    if (index < dialogsArray.size()) {
        TLRPC.Dialog dialog = dialogsArray.get(index);
        TLRPC.Dialog nextDialog = index + 1 < dialogsArray.size() ? dialogsArray.get(index + 1) : null;
        TLRPC.DraftMessage newDraftMessage = MediaDataController.getInstance(currentAccount).getDraft(currentDialogId);
        MessageObject newMessageObject;
        if (currentDialogFolderId != 0) {
            newMessageObject = findFolderTopMessage();
        } else {
            newMessageObject = MessagesController.getInstance(currentAccount).dialogMessage.get(dialog.id);
        }
        if (currentDialogId != dialog.id ||
                message != null && message.getId() != dialog.top_message ||
                newMessageObject != null && newMessageObject.messageOwner.edit_date != currentEditDate ||
                unreadCount != dialog.unread_count ||
                mentionCount != dialog.unread_mentions_count ||
                markUnread != dialog.unread_mark ||
                message != newMessageObject ||
                message == null && newMessageObject != null || newDraftMessage != draftMessage || drawPin != dialog.pinned) {
            boolean dialogChanged = currentDialogId != dialog.id;
            currentDialogId = dialog.id;
            if (dialog instanceof TLRPC.TL_dialogFolder) {
                TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
                currentDialogFolderId = dialogFolder.folder.id;
            } else {
                currentDialogFolderId = 0;
            }
            if (dialogsType == 7 || dialogsType == 8) {
                MessagesController.DialogFilter filter = MessagesController.getInstance(currentAccount).selectedDialogFilter[dialogsType == 8 ? 1 : 0];
                fullSeparator = dialog instanceof TLRPC.TL_dialog && nextDialog != null && filter != null && filter.pinnedDialogs.indexOfKey(dialog.id) >= 0 && filter.pinnedDialogs.indexOfKey(nextDialog.id) < 0;
                fullSeparator2 = false;
            } else {
                fullSeparator = dialog instanceof TLRPC.TL_dialog && dialog.pinned && nextDialog != null && !nextDialog.pinned;
                fullSeparator2 = dialog instanceof TLRPC.TL_dialogFolder && nextDialog != null && !nextDialog.pinned;
            }
            update(0);
            if (dialogChanged) {
                reorderIconProgress = drawPin && drawReorder ? 1.0f : 0.0f;
            }
            checkOnline();
        }
    }
}
 
Example 14
Source File: DialogsAdapter.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getItemCount() {
    ArrayList<TLRPC.Dialog> array = DialogsActivity.getDialogsArray(currentAccount, dialogsType, folderId, dialogsListFrozen);
    int dialogsCount = array.size();
    if (dialogsType != 7 && dialogsType != 8 && dialogsCount == 0 && (folderId != 0 || MessagesController.getInstance(currentAccount).isLoadingDialogs(folderId))) {
        onlineContacts = null;
        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.getInstance(currentAccount).isDialogsEndReached(folderId) || dialogsCount == 0) {
            count++;
        }
    }
    boolean hasContacts = false;
    if (hasHints) {
        count += 2 + MessagesController.getInstance(currentAccount).hintDialogs.size();
    } else if (dialogsType == 0 && dialogsCount == 0 && folderId == 0) {
        if (ContactsController.getInstance(currentAccount).contacts.isEmpty() && ContactsController.getInstance(currentAccount).isLoadingContacts()) {
            onlineContacts = null;
            return (currentCount = 0);
        }

        if (!ContactsController.getInstance(currentAccount).contacts.isEmpty()) {
            if (onlineContacts == null || prevContactsCount != ContactsController.getInstance(currentAccount).contacts.size()) {
                onlineContacts = new ArrayList<>(ContactsController.getInstance(currentAccount).contacts);
                prevContactsCount = onlineContacts.size();
                int selfId = UserConfig.getInstance(currentAccount).clientUserId;
                for (int a = 0, N = onlineContacts.size(); a < N; a++) {
                    if (onlineContacts.get(a).user_id == selfId) {
                        onlineContacts.remove(a);
                        break;
                    }
                }
                sortOnlineContacts(false);
            }
            count += onlineContacts.size() + 2;
            hasContacts = true;
        }
    }
    if (!hasContacts && onlineContacts != null) {
        onlineContacts = null;
    }
    if (folderId == 1 && showArchiveHint) {
        count += 2;
    }
    if (folderId == 0 && dialogsCount != 0) {
        count++;
    }
    currentCount = count;
    return count;
}
 
Example 15
Source File: ProfileSearchCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void update(int mask) {
    TLRPC.FileLocation photo = null;
    if (user != null) {
        avatarDrawable.setInfo(user);
        if (savedMessages) {
            avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
            avatarImage.setImage(null, null, avatarDrawable, null, null, 0);
        } else {
            if (user.photo != null) {
                photo = user.photo.photo_small;
            }
            avatarImage.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, null, user, 0);
        }
    } else if (chat != null) {
        if (chat.photo != null) {
            photo = chat.photo.photo_small;
        }
        avatarDrawable.setInfo(chat);
        avatarImage.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable, null, chat, 0);
    } else {
        avatarDrawable.setInfo(0, null, null);
        avatarImage.setImage(null, null, avatarDrawable, null, null, 0);
    }

    if (mask != 0) {
        boolean continueUpdate = false;
        if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 && user != null || (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 && chat != null) {
            if (lastAvatar != null && photo == null || lastAvatar == null && photo != null || lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0 && user != null) {
            int newStatus = 0;
            if (user.status != null) {
                newStatus = user.status.expires;
            }
            if (newStatus != lastStatus) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && ((mask & MessagesController.UPDATE_MASK_NAME) != 0 && user != null) || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 && chat != null) {
            String newName;
            if (user != null) {
                newName = user.first_name + user.last_name;
            } else {
                newName = chat.title;
            }
            if (!newName.equals(lastName)) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && drawCount && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
            TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
            if (dialog != null && dialog.unread_count != lastUnreadCount) {
                continueUpdate = true;
            }
        }

        if (!continueUpdate) {
            return;
        }
    }

    if (user != null) {
        if (user.status != null) {
            lastStatus = user.status.expires;
        } else {
            lastStatus = 0;
        }
        lastName = user.first_name + user.last_name;
    } else if (chat != null) {
        lastName = chat.title;
    }

    lastAvatar = photo;

    if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
        buildLayout();
    } else {
        requestLayout();
    }
    postInvalidate();
}
 
Example 16
Source File: DialogObject.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isChannel(TLRPC.Dialog dialog) {
    return dialog != null && (dialog.flags & 1) != 0;
}
 
Example 17
Source File: ProfileSearchCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void update(int mask) {
    TLRPC.FileLocation photo = null;
    if (user != null) {
        avatarDrawable.setInfo(user);
        if (savedMessages) {
            avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
            avatarImage.setImage(null, null, avatarDrawable, null, null, 0);
        } else {
            if (user.photo != null) {
                photo = user.photo.photo_small;
            }
            avatarImage.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, null, user, 0);
        }
    } else if (chat != null) {
        if (chat.photo != null) {
            photo = chat.photo.photo_small;
        }
        avatarDrawable.setInfo(chat);
        avatarImage.setImage(ImageLocation.getForChat(chat, false), "50_50", avatarDrawable, null, chat, 0);
    } else {
        avatarDrawable.setInfo(0, null, null);
        avatarImage.setImage(null, null, avatarDrawable, null, null, 0);
    }

    if (mask != 0) {
        boolean continueUpdate = false;
        if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 && user != null || (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 && chat != null) {
            if (lastAvatar != null && photo == null || lastAvatar == null && photo != null || lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0 && user != null) {
            int newStatus = 0;
            if (user.status != null) {
                newStatus = user.status.expires;
            }
            if (newStatus != lastStatus) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && ((mask & MessagesController.UPDATE_MASK_NAME) != 0 && user != null) || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 && chat != null) {
            String newName;
            if (user != null) {
                newName = user.first_name + user.last_name;
            } else {
                newName = chat.title;
            }
            if (!newName.equals(lastName)) {
                continueUpdate = true;
            }
        }
        if (!continueUpdate && drawCount && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
            TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
            if (dialog != null && dialog.unread_count != lastUnreadCount) {
                continueUpdate = true;
            }
        }

        if (!continueUpdate) {
            return;
        }
    }

    if (user != null) {
        if (user.status != null) {
            lastStatus = user.status.expires;
        } else {
            lastStatus = 0;
        }
        lastName = user.first_name + user.last_name;
    } else if (chat != null) {
        lastName = chat.title;
    }

    lastAvatar = photo;

    if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
        buildLayout();
    } else {
        requestLayout();
    }
    postInvalidate();
}
 
Example 18
Source File: SecretChatHelper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected void processUpdateEncryption(TLRPC.TL_updateEncryption update, ConcurrentHashMap<Integer, TLRPC.User> usersDict) {
    final TLRPC.EncryptedChat newChat = update.chat;
    long dialog_id = ((long) newChat.id) << 32;
    TLRPC.EncryptedChat existingChat = getMessagesController().getEncryptedChatDB(newChat.id, false);

    if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) {
        int user_id = newChat.participant_id;
        if (user_id == getUserConfig().getClientUserId()) {
            user_id = newChat.admin_id;
        }
        TLRPC.User user = getMessagesController().getUser(user_id);
        if (user == null) {
            user = usersDict.get(user_id);
        }
        newChat.user_id = user_id;
        final TLRPC.Dialog dialog = new TLRPC.TL_dialog();
        dialog.id = dialog_id;
        dialog.unread_count = 0;
        dialog.top_message = 0;
        dialog.last_message_date = update.date;
        getMessagesController().putEncryptedChat(newChat, false);
        AndroidUtilities.runOnUIThread(() -> {
            getMessagesController().dialogs_dict.put(dialog.id, dialog);
            getMessagesController().allDialogs.add(dialog);
            getMessagesController().sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
        });
        getMessagesStorage().putEncryptedChat(newChat, user, dialog);
        acceptSecretChat(newChat);
    } else if (newChat instanceof TLRPC.TL_encryptedChat) {
        if (existingChat instanceof TLRPC.TL_encryptedChatWaiting && (existingChat.auth_key == null || existingChat.auth_key.length == 1)) {
            newChat.a_or_b = existingChat.a_or_b;
            newChat.user_id = existingChat.user_id;
            processAcceptedSecretChat(newChat);
        } else if (existingChat == null && startingSecretChat) {
            delayedEncryptedChatUpdates.add(update);
        }
    } else {
        final TLRPC.EncryptedChat exist = existingChat;
        if (exist != null) {
            newChat.user_id = exist.user_id;
            newChat.auth_key = exist.auth_key;
            newChat.key_create_date = exist.key_create_date;
            newChat.key_use_count_in = exist.key_use_count_in;
            newChat.key_use_count_out = exist.key_use_count_out;
            newChat.ttl = exist.ttl;
            newChat.seq_in = exist.seq_in;
            newChat.seq_out = exist.seq_out;
            newChat.admin_id = exist.admin_id;
            newChat.mtproto_seq = exist.mtproto_seq;
        }
        AndroidUtilities.runOnUIThread(() -> {
            if (exist != null) {
                getMessagesController().putEncryptedChat(newChat, false);
            }
            getMessagesStorage().updateEncryptedChat(newChat);
            getNotificationCenter().postNotificationName(NotificationCenter.encryptedChatUpdated, newChat);
        });
    }
}
 
Example 19
Source File: DialogObject.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static long getLastMessageOrDraftDate(TLRPC.Dialog dialog, TLRPC.DraftMessage draftMessage) {
    return draftMessage != null && draftMessage.date >= dialog.last_message_date ? draftMessage.date : dialog.last_message_date;
}
 
Example 20
Source File: SecretChatHelper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
protected void processUpdateEncryption(TLRPC.TL_updateEncryption update, ConcurrentHashMap<Integer, TLRPC.User> usersDict) {
    final TLRPC.EncryptedChat newChat = update.chat;
    long dialog_id = ((long) newChat.id) << 32;
    TLRPC.EncryptedChat existingChat = getMessagesController().getEncryptedChatDB(newChat.id, false);

    if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) {
        int user_id = newChat.participant_id;
        if (user_id == getUserConfig().getClientUserId()) {
            user_id = newChat.admin_id;
        }
        TLRPC.User user = getMessagesController().getUser(user_id);
        if (user == null) {
            user = usersDict.get(user_id);
        }
        newChat.user_id = user_id;
        final TLRPC.Dialog dialog = new TLRPC.TL_dialog();
        dialog.id = dialog_id;
        dialog.unread_count = 0;
        dialog.top_message = 0;
        dialog.last_message_date = update.date;
        getMessagesController().putEncryptedChat(newChat, false);
        AndroidUtilities.runOnUIThread(() -> {
            getMessagesController().dialogs_dict.put(dialog.id, dialog);
            getMessagesController().allDialogs.add(dialog);
            getMessagesController().sortDialogs(null);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
        });
        getMessagesStorage().putEncryptedChat(newChat, user, dialog);
        acceptSecretChat(newChat);
    } else if (newChat instanceof TLRPC.TL_encryptedChat) {
        if (existingChat instanceof TLRPC.TL_encryptedChatWaiting && (existingChat.auth_key == null || existingChat.auth_key.length == 1)) {
            newChat.a_or_b = existingChat.a_or_b;
            newChat.user_id = existingChat.user_id;
            processAcceptedSecretChat(newChat);
        } else if (existingChat == null && startingSecretChat) {
            delayedEncryptedChatUpdates.add(update);
        }
    } else {
        final TLRPC.EncryptedChat exist = existingChat;
        if (exist != null) {
            newChat.user_id = exist.user_id;
            newChat.auth_key = exist.auth_key;
            newChat.key_create_date = exist.key_create_date;
            newChat.key_use_count_in = exist.key_use_count_in;
            newChat.key_use_count_out = exist.key_use_count_out;
            newChat.ttl = exist.ttl;
            newChat.seq_in = exist.seq_in;
            newChat.seq_out = exist.seq_out;
            newChat.admin_id = exist.admin_id;
            newChat.mtproto_seq = exist.mtproto_seq;
        }
        AndroidUtilities.runOnUIThread(() -> {
            if (exist != null) {
                getMessagesController().putEncryptedChat(newChat, false);
            }
            getMessagesStorage().updateEncryptedChat(newChat);
            getNotificationCenter().postNotificationName(NotificationCenter.encryptedChatUpdated, newChat);
        });
    }
}