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

The following examples show how to use org.telegram.tgnet.TLRPC#ChatParticipant . 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: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateOnlineCount()
{
    onlineCount = 0;
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null)
    {
        sortParticipants(chatOnlineParticipantsList);
        int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (TLRPC.ChatParticipant participant : chatOnlineParticipantsList)
        {
            if (!isParticipantOnline(participant, currentTime))
                break;

            onlineCount++;
        }
    }
}
 
Example 2
Source File: ChatAvatarContainer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void updateOnlineCount() {
    if (parentFragment == null) {
        return;
    }
    onlineCount = 0;
    TLRPC.ChatFull info = parentFragment.getCurrentChatInfo();
    if (info == null) {
        return;
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null) {
        for (int a = 0; a < info.participants.participants.size(); a++) {
            TLRPC.ChatParticipant participant = info.participants.participants.get(a);
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(participant.user_id);
            if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getInstance(currentAccount).getClientUserId()) && user.status.expires > 10000) {
                onlineCount++;
            }
        }
    }
}
 
Example 3
Source File: ChatAvatarContainer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void updateOnlineCount() {
    if (parentFragment == null) {
        return;
    }
    onlineCount = 0;
    TLRPC.ChatFull info = parentFragment.getCurrentChatInfo();
    if (info == null) {
        return;
    }
    int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null) {
        for (int a = 0; a < info.participants.participants.size(); a++) {
            TLRPC.ChatParticipant participant = info.participants.participants.get(a);
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(participant.user_id);
            if (user != null && user.status != null && (user.status.expires > currentTime || user.id == UserConfig.getInstance(currentAccount).getClientUserId()) && user.status.expires > 10000) {
                onlineCount++;
            }
        }
    } else if (info instanceof TLRPC.TL_channelFull && info.participants_count > 200) {
        onlineCount = info.online_count;
    }
}
 
Example 4
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void updateOnlineCount()
{
    onlineCount = 0;
    if (info instanceof TLRPC.TL_chatFull || info instanceof TLRPC.TL_channelFull && info.participants_count <= 200 && info.participants != null)
    {
        sortParticipants(chatOnlineParticipantsList);
        int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (TLRPC.ChatParticipant participant : chatOnlineParticipantsList)
        {
            if (!isParticipantOnline(participant, currentTime))
                break;

            onlineCount++;
        }
    }
}
 
Example 5
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setChatInfo(TLRPC.ChatFull chatInfo)
{
    info = chatInfo;
    if (info != null && info.migrated_from_chat_id != 0)
        mergeDialogId = -info.migrated_from_chat_id;

    if (info != null && info.participants != null && info.participants.participants.size() > 0)
    {
        chatParticipantsList.clear();
        chatAdminParticipantsList.clear();
        chatOnlineParticipantsList.clear();
        for (TLRPC.ChatParticipant participant : info.participants.participants)
        {
            chatParticipantsList.add(participant);
            chatAdminParticipantsList.add(participant);
            chatOnlineParticipantsList.add(participant);
        }
        sortParticipants(chatAdminParticipantsList);
        sortParticipants(chatOnlineParticipantsList);
        updateOnlineCount();
    }

    fetchUsersFromChannelInfo();
}
 
Example 6
Source File: SetAdminsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType()) {
        case 0:
            TextCheckCell checkCell = (TextCheckCell) holder.itemView;
            chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
            checkCell.setTextAndCheck(LocaleController.getString("SetAdminsAll", R.string.SetAdminsAll), chat != null && !chat.admins_enabled, false);
            break;
        case 1:
            TextInfoPrivacyCell privacyCell = (TextInfoPrivacyCell) holder.itemView;
            if (position == allAdminsInfoRow) {
                if (chat.admins_enabled) {
                    privacyCell.setText(LocaleController.getString("SetAdminsNotAllInfo", R.string.SetAdminsNotAllInfo));
                } else {
                    privacyCell.setText(LocaleController.getString("SetAdminsAllInfo", R.string.SetAdminsAllInfo));
                }
                if (usersStartRow != -1) {
                    privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                } else {
                    privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                }
            } else if (position == usersEndRow) {
                privacyCell.setText("");
                privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            }
            break;
        case 2:
            UserCell userCell = (UserCell) holder.itemView;
            TLRPC.ChatParticipant part = participants.get(position - usersStartRow);
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(part.user_id);
            userCell.setData(user, null, null, 0);
            chat = MessagesController.getInstance(currentAccount).getChat(chat_id);
            userCell.setChecked(!(part instanceof TLRPC.TL_chatParticipant) || chat != null && !chat.admins_enabled, false);
            userCell.setCheckDisabled(chat == null || !chat.admins_enabled || part.user_id == UserConfig.getInstance(currentAccount).getClientUserId());
            break;
    }
}
 
Example 7
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TLRPC.ChatParticipant> getChatParticipantsList()
{
    if (membersSortType == MembersSortType.Admin)
        return chatAdminParticipantsList;
    else if (membersSortType == MembersSortType.Online)
        return chatOnlineParticipantsList;

    return chatParticipantsList;
}
 
Example 8
Source File: ChannelEditActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void fetchUsersFromChannelInfo() {
    if (info instanceof TLRPC.TL_channelFull && info.participants != null) {
        for (int a = 0; a < info.participants.participants.size(); a++) {
            TLRPC.ChatParticipant chatParticipant = info.participants.participants.get(a);
            participantsMap.put(chatParticipant.user_id, chatParticipant);
        }
    }
}
 
Example 9
Source File: ChatUsersActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean createMenuForParticipant(final TLRPC.ChatParticipant participant, boolean resultOnly) {
    if (participant == null) {
        return false;
    }
    int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
    if (participant.user_id == currentUserId) {
        return false;
    }
    boolean allowKick = false;
    if (currentChat.creator) {
        allowKick = true;
    } else if (participant instanceof TLRPC.TL_chatParticipant) {
        if (currentChat.admin && currentChat.admins_enabled || participant.inviter_id == currentUserId) {
            allowKick = true;
        }
    }
    if (!allowKick) {
        return false;
    }
    if (resultOnly) {
        return true;
    }
    ArrayList<String> items = new ArrayList<>();
    final ArrayList<Integer> actions = new ArrayList<>();
    items.add(LocaleController.getString("KickFromGroup", R.string.KickFromGroup));
    actions.add(0);
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setItems(items.toArray(new CharSequence[actions.size()]), (dialogInterface, i) -> {
        if (actions.get(i) == 0) {
            MessagesController.getInstance(currentAccount).deleteUserFromChat(chatId, MessagesController.getInstance(currentAccount).getUser(participant.user_id), info);
        }
    });
    showDialog(builder.create());
    return true;
}
 
Example 10
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TLRPC.ChatParticipant> getChatParticipantsList()
{
    if (membersSortType == MembersSortType.Admin)
        return chatAdminParticipantsList;
    else if (membersSortType == MembersSortType.Online)
        return chatOnlineParticipantsList;

    return chatParticipantsList;
}
 
Example 11
Source File: SetAdminsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateSearchResults(final ArrayList<TLRPC.ChatParticipant> users, final ArrayList<CharSequence> names) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            searchResult = users;
            searchResultNames = names;
            notifyDataSetChanged();
        }
    });
}
 
Example 12
Source File: SetAdminsActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateSearchResults(final ArrayList<TLRPC.ChatParticipant> users, final ArrayList<CharSequence> names) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            searchResult = users;
            searchResultNames = names;
            notifyDataSetChanged();
        }
    });
}
 
Example 13
Source File: ChatUsersActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean createMenuForParticipant(final TLRPC.ChatParticipant participant, boolean resultOnly) {
    if (participant == null) {
        return false;
    }
    int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
    if (participant.user_id == currentUserId) {
        return false;
    }
    boolean allowKick = false;
    if (currentChat.creator) {
        allowKick = true;
    } else if (participant instanceof TLRPC.TL_chatParticipant) {
        if (currentChat.admin && currentChat.admins_enabled || participant.inviter_id == currentUserId) {
            allowKick = true;
        }
    }
    if (!allowKick) {
        return false;
    }
    if (resultOnly) {
        return true;
    }
    ArrayList<String> items = new ArrayList<>();
    final ArrayList<Integer> actions = new ArrayList<>();
    items.add(LocaleController.getString("KickFromGroup", R.string.KickFromGroup));
    actions.add(0);
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setItems(items.toArray(new CharSequence[actions.size()]), (dialogInterface, i) -> {
        if (actions.get(i) == 0) {
            MessagesController.getInstance(currentAccount).deleteUserFromChat(chatId, MessagesController.getInstance(currentAccount).getUser(participant.user_id), info);
        }
    });
    showDialog(builder.create());
    return true;
}
 
Example 14
Source File: ChatUsersActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void removeParticipants(TLObject object) {
    if (object instanceof TLRPC.ChatParticipant) {
        TLRPC.ChatParticipant chatParticipant = (TLRPC.ChatParticipant) object;
        removeParticipants(chatParticipant.user_id);
    } else if (object instanceof TLRPC.ChannelParticipant) {
        TLRPC.ChannelParticipant channelParticipant = (TLRPC.ChannelParticipant) object;
        removeParticipants(channelParticipant.user_id);
    }
}
 
Example 15
Source File: ChatEditActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private int getAdminCount() {
    if (info == null) {
        return 1;
    }
    int count = 0;
    for (int a = 0, N = info.participants.participants.size(); a < N; a++) {
        TLRPC.ChatParticipant chatParticipant = info.participants.participants.get(a);
        if (chatParticipant instanceof TLRPC.TL_chatParticipantAdmin ||
                chatParticipant instanceof TLRPC.TL_chatParticipantCreator) {
            count++;
        }
    }
    return count;
}
 
Example 16
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean isParticipantAdmin(TLRPC.ChatParticipant participant)
{
    if (participant instanceof TLRPC.TL_chatChannelParticipant)
    {
        TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) participant).channelParticipant;
        return channelParticipant instanceof TLRPC.TL_channelParticipantCreator || channelParticipant instanceof TLRPC.TL_channelParticipantAdmin;
    }
    else
    {
        return participant instanceof TLRPC.TL_chatParticipantCreator || (currentChat != null &&
                currentChat.admins_enabled && participant instanceof TLRPC.TL_chatParticipantAdmin);
    }
}
 
Example 17
Source File: SetAdminsActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.ChatParticipant getItem(int i) {
    return searchResult.get(i);
}
 
Example 18
Source File: ChannelEditActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
    boolean checkBackground = true;
    switch (holder.getItemViewType()) {
        case 0:
            ManageChatTextCell textCell = (ManageChatTextCell) holder.itemView;
            textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            textCell.setTag(Theme.key_windowBackgroundWhiteBlackText);

            if (i == managementRow) {
                textCell.setText(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), info != null ? String.format("%d", info.admins_count) : null, R.drawable.group_admin, blockedUsersRow != -1);
            } else if (i == blockedUsersRow) {
                textCell.setText(LocaleController.getString("ChannelBlacklist", R.string.ChannelBlacklist), info != null ? String.format("%d", info.kicked_count + info.banned_count) : null, R.drawable.group_banned, false);
            } else if (i == eventLogRow) {
                textCell.setText(LocaleController.getString("EventLog", R.string.EventLog), null, R.drawable.group_log, true);
            } else if (i == infoRow) {
                textCell.setText(currentChat.megagroup ? LocaleController.getString("EventLogFilterGroupInfo", R.string.EventLogFilterGroupInfo) : LocaleController.getString("EventLogFilterChannelInfo", R.string.EventLogFilterChannelInfo), null, R.drawable.group_edit, true);
            } else if (i == permissionsRow) {
                //textCell.setText(LocaleController.getString("ChatPermissions", R.string.ChatPermissions), null, R.drawable.group_log, true); //TODO icon
            }
            break;
        case 1:
            ManageChatUserCell userCell = ((ManageChatUserCell) holder.itemView);
            userCell.setTag(i);
            TLRPC.ChatParticipant part;
            if (!sortedUsers.isEmpty()) {
                part = info.participants.participants.get(sortedUsers.get(i - membersStartRow));
            } else {
                part = info.participants.participants.get(i - membersStartRow);
            }
            if (part != null) {
                if (part instanceof TLRPC.TL_chatChannelParticipant) {
                    TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) part).channelParticipant;
                    userCell.setIsAdmin(channelParticipant instanceof TLRPC.TL_channelParticipantCreator || channelParticipant instanceof TLRPC.TL_channelParticipantAdmin);
                } else {
                    userCell.setIsAdmin(part instanceof TLRPC.TL_chatParticipantAdmin);
                }
                userCell.setData(MessagesController.getInstance(currentAccount).getUser(part.user_id), null, null);
            }
            break;
        case 2:
            if (i == membersSectionRow && membersStartRow != -1) {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            } else {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            }
            break;
    }
}
 
Example 19
Source File: ChannelEditActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
    boolean checkBackground = true;
    switch (holder.getItemViewType()) {
        case 0:
            ManageChatTextCell textCell = (ManageChatTextCell) holder.itemView;
            textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            textCell.setTag(Theme.key_windowBackgroundWhiteBlackText);

            if (i == managementRow) {
                textCell.setText(LocaleController.getString("ChannelAdministrators", R.string.ChannelAdministrators), info != null ? String.format("%d", info.admins_count) : null, R.drawable.group_admin, blockedUsersRow != -1);
            } else if (i == blockedUsersRow) {
                textCell.setText(LocaleController.getString("ChannelBlacklist", R.string.ChannelBlacklist), info != null ? String.format("%d", info.kicked_count + info.banned_count) : null, R.drawable.group_banned, false);
            } else if (i == eventLogRow) {
                textCell.setText(LocaleController.getString("EventLog", R.string.EventLog), null, R.drawable.group_log, true);
            } else if (i == infoRow) {
                textCell.setText(currentChat.megagroup ? LocaleController.getString("EventLogFilterGroupInfo", R.string.EventLogFilterGroupInfo) : LocaleController.getString("EventLogFilterChannelInfo", R.string.EventLogFilterChannelInfo), null, R.drawable.group_edit, true);
            } else if (i == permissionsRow) {
                //textCell.setText(LocaleController.getString("ChatPermissions", R.string.ChatPermissions), null, R.drawable.group_log, true); //TODO icon
            }
            break;
        case 1:
            ManageChatUserCell userCell = ((ManageChatUserCell) holder.itemView);
            userCell.setTag(i);
            TLRPC.ChatParticipant part;
            if (!sortedUsers.isEmpty()) {
                part = info.participants.participants.get(sortedUsers.get(i - membersStartRow));
            } else {
                part = info.participants.participants.get(i - membersStartRow);
            }
            if (part != null) {
                if (part instanceof TLRPC.TL_chatChannelParticipant) {
                    TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) part).channelParticipant;
                    userCell.setIsAdmin(channelParticipant instanceof TLRPC.TL_channelParticipantCreator || channelParticipant instanceof TLRPC.TL_channelParticipantAdmin);
                } else {
                    userCell.setIsAdmin(part instanceof TLRPC.TL_chatParticipantAdmin);
                }
                userCell.setData(MessagesController.getInstance(currentAccount).getUser(part.user_id), null, null);
            }
            break;
        case 2:
            if (i == membersSectionRow && membersStartRow != -1) {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            } else {
                holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            }
            break;
    }
}
 
Example 20
Source File: ChatUsersActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public TLRPC.ChatParticipant getItem(int position) {
    if (participantsStartRow != -1 && position >= participantsStartRow && position < participantsEndRow) {
        return participants.get(position - participantsStartRow);
    }
    return null;
}