Search in sources :

Example 61 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessagesStorage method getBotCache.

public void getBotCache(String key, RequestDelegate requestDelegate) {
    if (key == null || requestDelegate == null) {
        return;
    }
    int currentDate = getConnectionsManager().getCurrentTime();
    storageQueue.postRunnable(() -> {
        TLObject result = null;
        try {
            database.executeFast("DELETE FROM botcache WHERE date < " + currentDate).stepThis().dispose();
            SQLiteCursor cursor = database.queryFinalized("SELECT data FROM botcache WHERE id = ?", key);
            if (cursor.next()) {
                try {
                    NativeByteBuffer data = cursor.byteBufferValue(0);
                    if (data != null) {
                        int constructor = data.readInt32(false);
                        if (constructor == TLRPC.TL_messages_botCallbackAnswer.constructor) {
                            result = TLRPC.TL_messages_botCallbackAnswer.TLdeserialize(data, constructor, false);
                        } else {
                            result = TLRPC.messages_BotResults.TLdeserialize(data, constructor, false);
                        }
                        data.reuse();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
            cursor.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            requestDelegate.run(result, null);
        }
    });
}
Also used : TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) SQLiteException(org.telegram.SQLite.SQLiteException)

Example 62 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ProfileActivity method openAddMember.

private void openAddMember() {
    Bundle args = new Bundle();
    args.putBoolean("addToGroup", true);
    args.putLong("chatId", currentChat.id);
    GroupCreateActivity fragment = new GroupCreateActivity(args);
    fragment.setInfo(chatInfo);
    if (chatInfo != null && chatInfo.participants != null) {
        LongSparseArray<TLObject> users = new LongSparseArray<>();
        for (int a = 0; a < chatInfo.participants.participants.size(); a++) {
            users.put(chatInfo.participants.participants.get(a).user_id, null);
        }
        fragment.setIgnoreUsers(users);
    }
    fragment.setDelegate((users, fwdCount) -> {
        HashSet<Long> currentParticipants = new HashSet<>();
        if (chatInfo.participants.participants != null) {
            for (int i = 0; i < chatInfo.participants.participants.size(); i++) {
                currentParticipants.add(chatInfo.participants.participants.get(i).user_id);
            }
        }
        for (int a = 0, N = users.size(); a < N; a++) {
            TLRPC.User user = users.get(a);
            getMessagesController().addUserToChat(chatId, user, fwdCount, null, ProfileActivity.this, null);
            if (!currentParticipants.contains(user.id)) {
                if (chatInfo.participants == null) {
                    chatInfo.participants = new TLRPC.TL_chatParticipants();
                }
                if (ChatObject.isChannel(currentChat)) {
                    TLRPC.TL_chatChannelParticipant channelParticipant1 = new TLRPC.TL_chatChannelParticipant();
                    channelParticipant1.channelParticipant = new TLRPC.TL_channelParticipant();
                    channelParticipant1.channelParticipant.inviter_id = getUserConfig().getClientUserId();
                    channelParticipant1.channelParticipant.peer = new TLRPC.TL_peerUser();
                    channelParticipant1.channelParticipant.peer.user_id = user.id;
                    channelParticipant1.channelParticipant.date = getConnectionsManager().getCurrentTime();
                    channelParticipant1.user_id = user.id;
                    chatInfo.participants.participants.add(channelParticipant1);
                } else {
                    TLRPC.ChatParticipant participant = new TLRPC.TL_chatParticipant();
                    participant.user_id = user.id;
                    participant.inviter_id = getAccountInstance().getUserConfig().clientUserId;
                    chatInfo.participants.participants.add(participant);
                }
                chatInfo.participants_count++;
                getMessagesController().putUser(user, false);
            }
        }
        updateListAnimated(true);
    });
    presentFragment(fragment);
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Bundle(android.os.Bundle) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Point(android.graphics.Point) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 63 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class StatisticActivity method onFragmentCreate.

@Override
public boolean onFragmentCreate() {
    getNotificationCenter().addObserver(this, NotificationCenter.messagesDidLoad);
    TLObject req;
    if (isMegagroup) {
        TLRPC.TL_stats_getMegagroupStats getMegagroupStats = new TLRPC.TL_stats_getMegagroupStats();
        req = getMegagroupStats;
        getMegagroupStats.channel = MessagesController.getInstance(currentAccount).getInputChannel(chat.id);
    } else {
        TLRPC.TL_stats_getBroadcastStats getBroadcastStats = new TLRPC.TL_stats_getBroadcastStats();
        req = getBroadcastStats;
        getBroadcastStats.channel = MessagesController.getInstance(currentAccount).getInputChannel(chat.id);
    }
    int reqId = getConnectionsManager().sendRequest(req, (response, error) -> {
        if (response instanceof TLRPC.TL_stats_broadcastStats) {
            final ChartViewData[] chartsViewData = new ChartViewData[9];
            TLRPC.TL_stats_broadcastStats stats = (TLRPC.TL_stats_broadcastStats) response;
            chartsViewData[0] = createViewData(stats.iv_interactions_graph, LocaleController.getString("IVInteractionsChartTitle", R.string.IVInteractionsChartTitle), 1);
            chartsViewData[1] = createViewData(stats.followers_graph, LocaleController.getString("FollowersChartTitle", R.string.FollowersChartTitle), 0);
            chartsViewData[2] = createViewData(stats.top_hours_graph, LocaleController.getString("TopHoursChartTitle", R.string.TopHoursChartTitle), 0);
            chartsViewData[3] = createViewData(stats.interactions_graph, LocaleController.getString("InteractionsChartTitle", R.string.InteractionsChartTitle), 1);
            chartsViewData[4] = createViewData(stats.growth_graph, LocaleController.getString("GrowthChartTitle", R.string.GrowthChartTitle), 0);
            chartsViewData[5] = createViewData(stats.views_by_source_graph, LocaleController.getString("ViewsBySourceChartTitle", R.string.ViewsBySourceChartTitle), 2);
            chartsViewData[6] = createViewData(stats.new_followers_by_source_graph, LocaleController.getString("NewFollowersBySourceChartTitle", R.string.NewFollowersBySourceChartTitle), 2);
            chartsViewData[7] = createViewData(stats.languages_graph, LocaleController.getString("LanguagesChartTitle", R.string.LanguagesChartTitle), 4, true);
            chartsViewData[8] = createViewData(stats.mute_graph, LocaleController.getString("NotificationsChartTitle", R.string.NotificationsChartTitle), 0);
            if (chartsViewData[2] != null) {
                chartsViewData[2].useHourFormat = true;
            }
            overviewChannelData = new OverviewChannelData(stats);
            maxDateOverview = stats.period.max_date * 1000L;
            minDateOverview = stats.period.min_date * 1000L;
            recentPostsAll.clear();
            for (int i = 0; i < stats.recent_message_interactions.size(); i++) {
                RecentPostInfo recentPostInfo = new RecentPostInfo();
                recentPostInfo.counters = stats.recent_message_interactions.get(i);
                recentPostsAll.add(recentPostInfo);
                recentPostIdtoIndexMap.put(recentPostInfo.counters.msg_id, i);
            }
            if (recentPostsAll.size() > 0) {
                int lastPostId = recentPostsAll.get(0).counters.msg_id;
                int count = recentPostsAll.size();
                getMessagesStorage().getMessages(-chat.id, 0, false, count, lastPostId, 0, 0, classGuid, 0, false, 0, 0, true);
            }
            AndroidUtilities.runOnUIThread(() -> {
                ivInteractionsData = chartsViewData[0];
                followersData = chartsViewData[1];
                topHoursData = chartsViewData[2];
                interactionsData = chartsViewData[3];
                growthData = chartsViewData[4];
                viewsBySourceData = chartsViewData[5];
                newFollowersBySourceData = chartsViewData[6];
                languagesData = chartsViewData[7];
                notificationsData = chartsViewData[8];
                dataLoaded(chartsViewData);
            });
        }
        if (response instanceof TLRPC.TL_stats_megagroupStats) {
            final ChartViewData[] chartsViewData = new ChartViewData[8];
            TLRPC.TL_stats_megagroupStats stats = (TLRPC.TL_stats_megagroupStats) response;
            chartsViewData[0] = createViewData(stats.growth_graph, LocaleController.getString("GrowthChartTitle", R.string.GrowthChartTitle), 0);
            chartsViewData[1] = createViewData(stats.members_graph, LocaleController.getString("GroupMembersChartTitle", R.string.GroupMembersChartTitle), 0);
            chartsViewData[2] = createViewData(stats.new_members_by_source_graph, LocaleController.getString("NewMembersBySourceChartTitle", R.string.NewMembersBySourceChartTitle), 2);
            chartsViewData[3] = createViewData(stats.languages_graph, LocaleController.getString("MembersLanguageChartTitle", R.string.MembersLanguageChartTitle), 4, true);
            chartsViewData[4] = createViewData(stats.messages_graph, LocaleController.getString("MessagesChartTitle", R.string.MessagesChartTitle), 2);
            chartsViewData[5] = createViewData(stats.actions_graph, LocaleController.getString("ActionsChartTitle", R.string.ActionsChartTitle), 1);
            chartsViewData[6] = createViewData(stats.top_hours_graph, LocaleController.getString("TopHoursChartTitle", R.string.TopHoursChartTitle), 0);
            chartsViewData[7] = createViewData(stats.weekdays_graph, LocaleController.getString("TopDaysOfWeekChartTitle", R.string.TopDaysOfWeekChartTitle), 4);
            if (chartsViewData[6] != null) {
                chartsViewData[6].useHourFormat = true;
            }
            if (chartsViewData[7] != null) {
                chartsViewData[7].useWeekFormat = true;
            }
            overviewChatData = new OverviewChatData(stats);
            maxDateOverview = stats.period.max_date * 1000L;
            minDateOverview = stats.period.min_date * 1000L;
            if (stats.top_posters != null && !stats.top_posters.isEmpty()) {
                for (int i = 0; i < stats.top_posters.size(); i++) {
                    MemberData data = MemberData.from(stats.top_posters.get(i), stats.users);
                    if (topMembersVisible.size() < 10) {
                        topMembersVisible.add(data);
                    }
                    topMembersAll.add(data);
                }
                if (topMembersAll.size() - topMembersVisible.size() < 2) {
                    topMembersVisible.clear();
                    topMembersVisible.addAll(topMembersAll);
                }
            }
            if (stats.top_admins != null && !stats.top_admins.isEmpty()) {
                for (int i = 0; i < stats.top_admins.size(); i++) {
                    topAdmins.add(MemberData.from(stats.top_admins.get(i), stats.users));
                }
            }
            if (stats.top_inviters != null && !stats.top_inviters.isEmpty()) {
                for (int i = 0; i < stats.top_inviters.size(); i++) {
                    topInviters.add(MemberData.from(stats.top_inviters.get(i), stats.users));
                }
            }
            AndroidUtilities.runOnUIThread(() -> {
                growthData = chartsViewData[0];
                groupMembersData = chartsViewData[1];
                newMembersBySourceData = chartsViewData[2];
                membersLanguageData = chartsViewData[3];
                messagesData = chartsViewData[4];
                actionsData = chartsViewData[5];
                topHoursData = chartsViewData[6];
                topDayOfWeeksData = chartsViewData[7];
                dataLoaded(chartsViewData);
            });
        }
    }, null, null, 0, chat.stats_dc, ConnectionsManager.ConnectionTypeGeneric, true);
    getConnectionsManager().bindRequestToGuid(reqId, classGuid);
    return super.onFragmentCreate();
}
Also used : TLRPC(org.telegram.tgnet.TLRPC) SuppressLint(android.annotation.SuppressLint) TLObject(org.telegram.tgnet.TLObject)

Example 64 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MessageObject method updateMessageText.

private void updateMessageText(AbstractMap<Long, TLRPC.User> users, AbstractMap<Long, TLRPC.Chat> chats, LongSparseArray<TLRPC.User> sUsers, LongSparseArray<TLRPC.Chat> sChats) {
    TLRPC.User fromUser = null;
    TLRPC.Chat fromChat = null;
    if (messageOwner.from_id instanceof TLRPC.TL_peerUser) {
        fromUser = getUser(users, sUsers, messageOwner.from_id.user_id);
    } else if (messageOwner.from_id instanceof TLRPC.TL_peerChannel) {
        fromChat = getChat(chats, sChats, messageOwner.from_id.channel_id);
    }
    TLObject fromObject = fromUser != null ? fromUser : fromChat;
    if (messageOwner instanceof TLRPC.TL_messageService) {
        if (messageOwner.action != null) {
            if (messageOwner.action instanceof TLRPC.TL_messageActionGroupCallScheduled) {
                TLRPC.TL_messageActionGroupCallScheduled action = (TLRPC.TL_messageActionGroupCallScheduled) messageOwner.action;
                if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                    messageText = LocaleController.formatString("ActionGroupCallScheduled", R.string.ActionGroupCallScheduled, LocaleController.formatStartsTime(action.schedule_date, 3, false));
                } else {
                    messageText = LocaleController.formatString("ActionChannelCallScheduled", R.string.ActionChannelCallScheduled, LocaleController.formatStartsTime(action.schedule_date, 3, false));
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGroupCall) {
                if (messageOwner.action.duration != 0) {
                    String time;
                    int days = messageOwner.action.duration / (3600 * 24);
                    if (days > 0) {
                        time = LocaleController.formatPluralString("Days", days);
                    } else {
                        int hours = messageOwner.action.duration / 3600;
                        if (hours > 0) {
                            time = LocaleController.formatPluralString("Hours", hours);
                        } else {
                            int minutes = messageOwner.action.duration / 60;
                            if (minutes > 0) {
                                time = LocaleController.formatPluralString("Minutes", minutes);
                            } else {
                                time = LocaleController.formatPluralString("Seconds", messageOwner.action.duration);
                            }
                        }
                    }
                    if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                        if (isOut()) {
                            messageText = LocaleController.formatString("ActionGroupCallEndedByYou", R.string.ActionGroupCallEndedByYou, time);
                        } else {
                            messageText = replaceWithLink(LocaleController.formatString("ActionGroupCallEndedBy", R.string.ActionGroupCallEndedBy, time), "un1", fromObject);
                        }
                    } else {
                        messageText = LocaleController.formatString("ActionChannelCallEnded", R.string.ActionChannelCallEnded, time);
                    }
                } else {
                    if (messageOwner.peer_id instanceof TLRPC.TL_peerChat || isSupergroup()) {
                        if (isOut()) {
                            messageText = LocaleController.getString("ActionGroupCallStartedByYou", R.string.ActionGroupCallStartedByYou);
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionGroupCallStarted", R.string.ActionGroupCallStarted), "un1", fromObject);
                        }
                    } else {
                        messageText = LocaleController.getString("ActionChannelCallJustStarted", R.string.ActionChannelCallJustStarted);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionInviteToGroupCall) {
                long singleUserId = messageOwner.action.user_id;
                if (singleUserId == 0 && messageOwner.action.users.size() == 1) {
                    singleUserId = messageOwner.action.users.get(0);
                }
                if (singleUserId != 0) {
                    TLRPC.User whoUser = getUser(users, sUsers, singleUserId);
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallYouInvited", R.string.ActionGroupCallYouInvited), "un2", whoUser);
                    } else if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvitedYou", R.string.ActionGroupCallInvitedYou), "un1", fromObject);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvited", R.string.ActionGroupCallInvited), "un2", whoUser);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                } else {
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallYouInvited", R.string.ActionGroupCallYouInvited), "un2", messageOwner.action.users, users, sUsers);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionGroupCallInvited", R.string.ActionGroupCallInvited), "un2", messageOwner.action.users, users, sUsers);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGeoProximityReached) {
                TLRPC.TL_messageActionGeoProximityReached action = (TLRPC.TL_messageActionGeoProximityReached) messageOwner.action;
                long fromId = getPeerId(action.from_id);
                TLObject from;
                if (fromId > 0) {
                    from = getUser(users, sUsers, fromId);
                } else {
                    from = getChat(chats, sChats, -fromId);
                }
                long toId = getPeerId(action.to_id);
                long selfUserId = UserConfig.getInstance(currentAccount).getClientUserId();
                if (toId == selfUserId) {
                    messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinRadius", R.string.ActionUserWithinRadius, LocaleController.formatDistance(action.distance, 2)), "un1", from);
                } else {
                    TLObject to;
                    if (toId > 0) {
                        to = getUser(users, sUsers, toId);
                    } else {
                        to = getChat(chats, sChats, -toId);
                    }
                    if (fromId == selfUserId) {
                        messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinYouRadius", R.string.ActionUserWithinYouRadius, LocaleController.formatDistance(action.distance, 2)), "un1", to);
                    } else {
                        messageText = replaceWithLink(LocaleController.formatString("ActionUserWithinOtherRadius", R.string.ActionUserWithinOtherRadius, LocaleController.formatDistance(action.distance, 2)), "un2", to);
                        messageText = replaceWithLink(messageText, "un1", from);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionCustomAction) {
                messageText = messageOwner.action.message;
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                if (isOut()) {
                    messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionCreateGroup", R.string.ActionCreateGroup), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                if (isFromUser() && messageOwner.action.user_id == messageOwner.from_id.user_id) {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionLeftUser", R.string.ActionLeftUser), "un1", fromObject);
                    }
                } else {
                    TLRPC.User whoUser = getUser(users, sUsers, messageOwner.action.user_id);
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", whoUser);
                    } else if (messageOwner.action.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", fromObject);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionKickUser", R.string.ActionKickUser), "un2", whoUser);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                long singleUserId = messageOwner.action.user_id;
                if (singleUserId == 0 && messageOwner.action.users.size() == 1) {
                    singleUserId = messageOwner.action.users.get(0);
                }
                if (singleUserId != 0) {
                    TLRPC.User whoUser = getUser(users, sUsers, singleUserId);
                    TLRPC.Chat chat = null;
                    if (messageOwner.peer_id.channel_id != 0) {
                        chat = getChat(chats, sChats, messageOwner.peer_id.channel_id);
                    }
                    if (messageOwner.from_id != null && singleUserId == messageOwner.from_id.user_id) {
                        if (ChatObject.isChannel(chat) && !chat.megagroup) {
                            messageText = LocaleController.getString("ChannelJoined", R.string.ChannelJoined);
                        } else {
                            if (messageOwner.peer_id.channel_id != 0) {
                                if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                                    messageText = LocaleController.getString("ChannelMegaJoined", R.string.ChannelMegaJoined);
                                } else {
                                    messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelfMega", R.string.ActionAddUserSelfMega), "un1", fromObject);
                                }
                            } else if (isOut()) {
                                messageText = LocaleController.getString("ActionAddUserSelfYou", R.string.ActionAddUserSelfYou);
                            } else {
                                messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelf", R.string.ActionAddUserSelf), "un1", fromObject);
                            }
                        }
                    } else {
                        if (isOut()) {
                            messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", whoUser);
                        } else if (singleUserId == UserConfig.getInstance(currentAccount).getClientUserId()) {
                            if (messageOwner.peer_id.channel_id != 0) {
                                if (chat != null && chat.megagroup) {
                                    messageText = replaceWithLink(LocaleController.getString("MegaAddedBy", R.string.MegaAddedBy), "un1", fromObject);
                                } else {
                                    messageText = replaceWithLink(LocaleController.getString("ChannelAddedBy", R.string.ChannelAddedBy), "un1", fromObject);
                                }
                            } else {
                                messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", fromObject);
                            }
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", whoUser);
                            messageText = replaceWithLink(messageText, "un1", fromObject);
                        }
                    }
                } else {
                    if (isOut()) {
                        messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", messageOwner.action.users, users, sUsers);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", messageOwner.action.users, users, sUsers);
                        messageText = replaceWithLink(messageText, "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                if (isOut()) {
                    messageText = LocaleController.getString("ActionInviteYou", R.string.ActionInviteYou);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionInviteUser", R.string.ActionInviteUser), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    if (isVideoAvatar()) {
                        messageText = LocaleController.getString("ActionChannelChangedVideo", R.string.ActionChannelChangedVideo);
                    } else {
                        messageText = LocaleController.getString("ActionChannelChangedPhoto", R.string.ActionChannelChangedPhoto);
                    }
                } else {
                    if (isOut()) {
                        if (isVideoAvatar()) {
                            messageText = LocaleController.getString("ActionYouChangedVideo", R.string.ActionYouChangedVideo);
                        } else {
                            messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
                        }
                    } else {
                        if (isVideoAvatar()) {
                            messageText = replaceWithLink(LocaleController.getString("ActionChangedVideo", R.string.ActionChangedVideo), "un1", fromObject);
                        } else {
                            messageText = replaceWithLink(LocaleController.getString("ActionChangedPhoto", R.string.ActionChangedPhoto), "un1", fromObject);
                        }
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    messageText = LocaleController.getString("ActionChannelChangedTitle", R.string.ActionChannelChangedTitle).replace("un2", messageOwner.action.title);
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", messageOwner.action.title);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionChangedTitle", R.string.ActionChangedTitle).replace("un2", messageOwner.action.title), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && !chat.megagroup) {
                    messageText = LocaleController.getString("ActionChannelRemovedPhoto", R.string.ActionChannelRemovedPhoto);
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionRemovedPhoto", R.string.ActionRemovedPhoto), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionTTLChange) {
                if (messageOwner.action.ttl != 0) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(messageOwner.action.ttl));
                    } else {
                        messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(messageOwner.action.ttl));
                    }
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                    } else {
                        messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSetMessagesTTL) {
                TLRPC.TL_messageActionSetMessagesTTL action = (TLRPC.TL_messageActionSetMessagesTTL) messageOwner.action;
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (chat != null && !chat.megagroup) {
                    if (action.period != 0) {
                        messageText = LocaleController.formatString("ActionTTLChannelChanged", R.string.ActionTTLChannelChanged, LocaleController.formatTTLString(action.period));
                    } else {
                        messageText = LocaleController.getString("ActionTTLChannelDisabled", R.string.ActionTTLChannelDisabled);
                    }
                } else if (action.period != 0) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("ActionTTLYouChanged", R.string.ActionTTLYouChanged, LocaleController.formatTTLString(action.period));
                    } else {
                        messageText = replaceWithLink(LocaleController.formatString("ActionTTLChanged", R.string.ActionTTLChanged, LocaleController.formatTTLString(action.period)), "un1", fromObject);
                    }
                } else {
                    if (isOut()) {
                        messageText = LocaleController.getString("ActionTTLYouDisabled", R.string.ActionTTLYouDisabled);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionTTLDisabled", R.string.ActionTTLDisabled), "un1", fromObject);
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                String date;
                long time = ((long) messageOwner.date) * 1000;
                if (LocaleController.getInstance().formatterDay != null && LocaleController.getInstance().formatterYear != null) {
                    date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(time), LocaleController.getInstance().formatterDay.format(time));
                } else {
                    date = "" + messageOwner.date;
                }
                TLRPC.User to_user = UserConfig.getInstance(currentAccount).getCurrentUser();
                if (to_user == null) {
                    to_user = getUser(users, sUsers, messageOwner.peer_id.user_id);
                }
                String name = to_user != null ? UserObject.getFirstName(to_user) : "";
                messageText = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, name, date, messageOwner.action.title, messageOwner.action.address);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionUserJoined || messageOwner.action instanceof TLRPC.TL_messageActionContactSignUp) {
                messageText = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, UserObject.getUserName(fromUser));
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                messageText = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, UserObject.getUserName(fromUser));
            } else if (messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
                if (messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
                    if (isOut()) {
                        messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
                    } else {
                        messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", fromObject);
                    }
                } else if (messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
                    TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) messageOwner.action.encryptedAction;
                    if (action.ttl_seconds != 0) {
                        if (isOut()) {
                            messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(action.ttl_seconds));
                        } else {
                            messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(action.ttl_seconds));
                        }
                    } else {
                        if (isOut()) {
                            messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                        } else {
                            messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
                        }
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
                if (isOut()) {
                    messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", fromObject);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionCreatedBroadcastList) {
                messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                TLRPC.Chat chat = messageOwner.peer_id != null && messageOwner.peer_id.channel_id != 0 ? getChat(chats, sChats, messageOwner.peer_id.channel_id) : null;
                if (ChatObject.isChannel(chat) && chat.megagroup) {
                    messageText = LocaleController.getString("ActionCreateMega", R.string.ActionCreateMega);
                } else {
                    messageText = LocaleController.getString("ActionCreateChannel", R.string.ActionCreateChannel);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                TLRPC.Chat chat;
                if (fromUser == null) {
                    chat = getChat(chats, sChats, messageOwner.peer_id.channel_id);
                } else {
                    chat = null;
                }
                generatePinMessageText(fromUser, chat);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear) {
                messageText = LocaleController.getString("HistoryCleared", R.string.HistoryCleared);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
                generateGameMessageText(fromUser);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
                TLRPC.TL_messageActionPhoneCall call = (TLRPC.TL_messageActionPhoneCall) messageOwner.action;
                boolean isMissed = call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed;
                if (isFromUser() && messageOwner.from_id.user_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                    if (isMissed) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoOutgoingMissed", R.string.CallMessageVideoOutgoingMissed);
                        } else {
                            messageText = LocaleController.getString("CallMessageOutgoingMissed", R.string.CallMessageOutgoingMissed);
                        }
                    } else {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoOutgoing", R.string.CallMessageVideoOutgoing);
                        } else {
                            messageText = LocaleController.getString("CallMessageOutgoing", R.string.CallMessageOutgoing);
                        }
                    }
                } else {
                    if (isMissed) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncomingMissed", R.string.CallMessageVideoIncomingMissed);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
                        }
                    } else if (call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncomingDeclined", R.string.CallMessageVideoIncomingDeclined);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncomingDeclined", R.string.CallMessageIncomingDeclined);
                        }
                    } else {
                        if (call.video) {
                            messageText = LocaleController.getString("CallMessageVideoIncoming", R.string.CallMessageVideoIncoming);
                        } else {
                            messageText = LocaleController.getString("CallMessageIncoming", R.string.CallMessageIncoming);
                        }
                    }
                }
                if (call.duration > 0) {
                    String duration = LocaleController.formatCallDuration(call.duration);
                    messageText = LocaleController.formatString("CallMessageWithDuration", R.string.CallMessageWithDuration, messageText, duration);
                    String _messageText = messageText.toString();
                    int start = _messageText.indexOf(duration);
                    if (start != -1) {
                        SpannableString sp = new SpannableString(messageText);
                        int end = start + duration.length();
                        if (start > 0 && _messageText.charAt(start - 1) == '(') {
                            start--;
                        }
                        if (end < _messageText.length() && _messageText.charAt(end) == ')') {
                            end++;
                        }
                        sp.setSpan(new TypefaceSpan(Typeface.DEFAULT), start, end, 0);
                        messageText = sp;
                    }
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
                TLRPC.User user = getUser(users, sUsers, getDialogId());
                generatePaymentSentMessageText(user);
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionBotAllowed) {
                String domain = ((TLRPC.TL_messageActionBotAllowed) messageOwner.action).domain;
                String text = LocaleController.getString("ActionBotAllowed", R.string.ActionBotAllowed);
                int start = text.indexOf("%1$s");
                SpannableString str = new SpannableString(String.format(text, domain));
                if (start >= 0) {
                    str.setSpan(new URLSpanNoUnderlineBold("http://" + domain), start, start + domain.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                messageText = str;
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSecureValuesSent) {
                TLRPC.TL_messageActionSecureValuesSent valuesSent = (TLRPC.TL_messageActionSecureValuesSent) messageOwner.action;
                StringBuilder str = new StringBuilder();
                for (int a = 0, size = valuesSent.types.size(); a < size; a++) {
                    TLRPC.SecureValueType type = valuesSent.types.get(a);
                    if (str.length() > 0) {
                        str.append(", ");
                    }
                    if (type instanceof TLRPC.TL_secureValueTypePhone) {
                        str.append(LocaleController.getString("ActionBotDocumentPhone", R.string.ActionBotDocumentPhone));
                    } else if (type instanceof TLRPC.TL_secureValueTypeEmail) {
                        str.append(LocaleController.getString("ActionBotDocumentEmail", R.string.ActionBotDocumentEmail));
                    } else if (type instanceof TLRPC.TL_secureValueTypeAddress) {
                        str.append(LocaleController.getString("ActionBotDocumentAddress", R.string.ActionBotDocumentAddress));
                    } else if (type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                        str.append(LocaleController.getString("ActionBotDocumentIdentity", R.string.ActionBotDocumentIdentity));
                    } else if (type instanceof TLRPC.TL_secureValueTypePassport) {
                        str.append(LocaleController.getString("ActionBotDocumentPassport", R.string.ActionBotDocumentPassport));
                    } else if (type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                        str.append(LocaleController.getString("ActionBotDocumentDriverLicence", R.string.ActionBotDocumentDriverLicence));
                    } else if (type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                        str.append(LocaleController.getString("ActionBotDocumentIdentityCard", R.string.ActionBotDocumentIdentityCard));
                    } else if (type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                        str.append(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
                    } else if (type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                        str.append(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
                    } else if (type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                        str.append(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
                    } else if (type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                        str.append(LocaleController.getString("ActionBotDocumentInternalPassport", R.string.ActionBotDocumentInternalPassport));
                    } else if (type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                        str.append(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
                    } else if (type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                        str.append(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
                    }
                }
                TLRPC.User user = null;
                if (messageOwner.peer_id != null) {
                    user = getUser(users, sUsers, messageOwner.peer_id.user_id);
                }
                messageText = LocaleController.formatString("ActionBotDocuments", R.string.ActionBotDocuments, UserObject.getFirstName(user), str.toString());
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) {
                String emoticon = ((TLRPC.TL_messageActionSetChatTheme) messageOwner.action).emoticon;
                String userName = UserObject.getFirstName(fromUser);
                boolean isUserSelf = UserObject.isUserSelf(fromUser);
                if (TextUtils.isEmpty(emoticon)) {
                    messageText = isUserSelf ? LocaleController.formatString("ChatThemeDisabledYou", R.string.ChatThemeDisabledYou) : LocaleController.formatString("ChatThemeDisabled", R.string.ChatThemeDisabled, userName, emoticon);
                } else {
                    messageText = isUserSelf ? LocaleController.formatString("ChatThemeChangedYou", R.string.ChatThemeChangedYou, emoticon) : LocaleController.formatString("ChatThemeChangedTo", R.string.ChatThemeChangedTo, userName, emoticon);
                }
            } else if (messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByRequest) {
                if (UserObject.isUserSelf(fromUser)) {
                    boolean isChannel = ChatObject.isChannelAndNotMegaGroup(messageOwner.peer_id.channel_id, currentAccount);
                    messageText = isChannel ? LocaleController.getString("RequestToJoinChannelApproved", R.string.RequestToJoinChannelApproved) : LocaleController.getString("RequestToJoinGroupApproved", R.string.RequestToJoinGroupApproved);
                } else {
                    messageText = replaceWithLink(LocaleController.getString("UserAcceptedToGroupAction", R.string.UserAcceptedToGroupAction), "un1", fromObject);
                }
            }
        }
    } else {
        isRestrictedMessage = false;
        String restrictionReason = MessagesController.getRestrictionReason(messageOwner.restriction_reason);
        if (!TextUtils.isEmpty(restrictionReason)) {
            messageText = restrictionReason;
            isRestrictedMessage = true;
        } else if (!isMediaEmpty()) {
            if (messageOwner.media instanceof TLRPC.TL_messageMediaDice) {
                messageText = getDiceEmoji();
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                if (((TLRPC.TL_messageMediaPoll) messageOwner.media).poll.quiz) {
                    messageText = LocaleController.getString("QuizPoll", R.string.QuizPoll);
                } else {
                    messageText = LocaleController.getString("Poll", R.string.Poll);
                }
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                if (messageOwner.media.ttl_seconds != 0 && !(messageOwner instanceof TLRPC.TL_message_secret)) {
                    messageText = LocaleController.getString("AttachDestructingPhoto", R.string.AttachDestructingPhoto);
                } else {
                    messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
                }
            } else if (isVideo() || messageOwner.media instanceof TLRPC.TL_messageMediaDocument && getDocument() instanceof TLRPC.TL_documentEmpty && messageOwner.media.ttl_seconds != 0) {
                if (messageOwner.media.ttl_seconds != 0 && !(messageOwner instanceof TLRPC.TL_message_secret)) {
                    messageText = LocaleController.getString("AttachDestructingVideo", R.string.AttachDestructingVideo);
                } else {
                    messageText = LocaleController.getString("AttachVideo", R.string.AttachVideo);
                }
            } else if (isVoice()) {
                messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
            } else if (isRoundVideo()) {
                messageText = LocaleController.getString("AttachRound", R.string.AttachRound);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
                messageText = LocaleController.getString("AttachLocation", R.string.AttachLocation);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
                messageText = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                messageText = LocaleController.getString("AttachContact", R.string.AttachContact);
                if (!TextUtils.isEmpty(messageOwner.media.vcard)) {
                    vCardData = VCardData.parse(messageOwner.media.vcard);
                }
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                messageText = messageOwner.message;
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                messageText = messageOwner.media.description;
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported) {
                messageText = LocaleController.getString("UnsupportedMedia", R.string.UnsupportedMedia).replace("https://telegram.org/update", "https://github.com/Telegram-FOSS-Team/Telegram-FOSS/blob/master/Update.md");
            } else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                if (isSticker() || isAnimatedStickerDocument(getDocument(), true)) {
                    String sch = getStickerChar();
                    if (sch != null && sch.length() > 0) {
                        messageText = String.format("%s %s", sch, LocaleController.getString("AttachSticker", R.string.AttachSticker));
                    } else {
                        messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
                    }
                } else if (isMusic()) {
                    messageText = LocaleController.getString("AttachMusic", R.string.AttachMusic);
                } else if (isGif()) {
                    messageText = LocaleController.getString("AttachGif", R.string.AttachGif);
                } else {
                    String name = FileLoader.getDocumentFileName(getDocument());
                    if (!TextUtils.isEmpty(name)) {
                        messageText = name;
                    } else {
                        messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
                    }
                }
            }
        } else {
            if (messageOwner.message != null) {
                try {
                    if (messageOwner.message.length() > 200) {
                        messageText = AndroidUtilities.BAD_CHARS_MESSAGE_LONG_PATTERN.matcher(messageOwner.message).replaceAll("\u200C");
                    } else {
                        messageText = AndroidUtilities.BAD_CHARS_MESSAGE_PATTERN.matcher(messageOwner.message).replaceAll("\u200C");
                    }
                } catch (Throwable e) {
                    messageText = messageOwner.message;
                }
            } else {
                messageText = messageOwner.message;
            }
        }
    }
    if (messageText == null) {
        messageText = "";
    }
}
Also used : SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) SpannableString(android.text.SpannableString) URLSpanNoUnderlineBold(org.telegram.ui.Components.URLSpanNoUnderlineBold) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint) TLObject(org.telegram.tgnet.TLObject)

Example 65 with TLObject

use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class MediaDataController method loadStickers.

public void loadStickers(int type, boolean cache, boolean force, boolean scheduleIfLoading) {
    if (loadingStickers[type]) {
        if (scheduleIfLoading) {
            scheduledLoadStickers[type] = () -> loadStickers(type, false, force, false);
        }
        return;
    }
    if (type == TYPE_FEATURED) {
        if (featuredStickerSets.isEmpty() || !getMessagesController().preloadFeaturedStickers) {
            return;
        }
    } else if (type != TYPE_EMOJI) {
        loadArchivedStickersCount(type, cache);
    }
    loadingStickers[type] = true;
    if (cache) {
        getMessagesStorage().getStorageQueue().postRunnable(() -> {
            ArrayList<TLRPC.TL_messages_stickerSet> newStickerArray = null;
            int date = 0;
            long hash = 0;
            SQLiteCursor cursor = null;
            try {
                cursor = getMessagesStorage().getDatabase().queryFinalized("SELECT data, date, hash FROM stickers_v2 WHERE id = " + (type + 1));
                if (cursor.next()) {
                    NativeByteBuffer data = cursor.byteBufferValue(0);
                    if (data != null) {
                        newStickerArray = new ArrayList<>();
                        int count = data.readInt32(false);
                        for (int a = 0; a < count; a++) {
                            TLRPC.TL_messages_stickerSet stickerSet = TLRPC.TL_messages_stickerSet.TLdeserialize(data, data.readInt32(false), false);
                            newStickerArray.add(stickerSet);
                        }
                        data.reuse();
                    }
                    date = cursor.intValue(1);
                    hash = calcStickersHash(newStickerArray);
                }
            } catch (Throwable e) {
                FileLog.e(e);
            } finally {
                if (cursor != null) {
                    cursor.dispose();
                }
            }
            processLoadedStickers(type, newStickerArray, true, date, hash);
        });
    } else {
        if (type == TYPE_FEATURED) {
            TLRPC.TL_messages_allStickers response = new TLRPC.TL_messages_allStickers();
            response.hash = loadFeaturedHash;
            for (int a = 0, size = featuredStickerSets.size(); a < size; a++) {
                response.sets.add(featuredStickerSets.get(a).set);
            }
            processLoadStickersResponse(type, response);
        } else if (type == TYPE_EMOJI) {
            TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
            req.stickerset = new TLRPC.TL_inputStickerSetAnimatedEmoji();
            getConnectionsManager().sendRequest(req, (response, error) -> {
                if (response instanceof TLRPC.TL_messages_stickerSet) {
                    ArrayList<TLRPC.TL_messages_stickerSet> newStickerArray = new ArrayList<>();
                    newStickerArray.add((TLRPC.TL_messages_stickerSet) response);
                    processLoadedStickers(type, newStickerArray, false, (int) (System.currentTimeMillis() / 1000), calcStickersHash(newStickerArray));
                } else {
                    processLoadedStickers(type, null, false, (int) (System.currentTimeMillis() / 1000), 0);
                }
            });
        } else {
            TLObject req;
            long hash;
            if (type == TYPE_IMAGE) {
                req = new TLRPC.TL_messages_getAllStickers();
                hash = ((TLRPC.TL_messages_getAllStickers) req).hash = force ? 0 : loadHash[type];
            } else {
                req = new TLRPC.TL_messages_getMaskStickers();
                hash = ((TLRPC.TL_messages_getMaskStickers) req).hash = force ? 0 : loadHash[type];
            }
            getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                if (response instanceof TLRPC.TL_messages_allStickers) {
                    processLoadStickersResponse(type, (TLRPC.TL_messages_allStickers) response);
                } else {
                    processLoadedStickers(type, null, false, (int) (System.currentTimeMillis() / 1000), hash);
                }
            }));
        }
    }
}
Also used : SparseLongArray(org.telegram.messenger.support.SparseLongArray) Spannable(android.text.Spannable) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) RectF(android.graphics.RectF) BitmapShader(android.graphics.BitmapShader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) UUID(java.util.UUID) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) List(java.util.List) LaunchActivity(org.telegram.ui.LaunchActivity) Paint(android.graphics.Paint) Pattern(java.util.regex.Pattern) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) Context(android.content.Context) Path(android.graphics.Path) SpannedString(android.text.SpannedString) Spanned(android.text.Spanned) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Build(android.os.Build) SQLiteException(org.telegram.SQLite.SQLiteException) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) SerializedData(org.telegram.tgnet.SerializedData) LongSparseArray(androidx.collection.LongSparseArray) SQLiteDatabase(org.telegram.SQLite.SQLiteDatabase) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement) ShortcutManager(android.content.pm.ShortcutManager) File(java.io.File) Color(android.graphics.Color) PorterDuffXfermode(android.graphics.PorterDuffXfermode) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) Bitmap(android.graphics.Bitmap) CharacterStyle(android.text.style.CharacterStyle) StickersArchiveAlert(org.telegram.ui.Components.StickersArchiveAlert) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) StickerSetBulletinLayout(org.telegram.ui.Components.StickerSetBulletinLayout) ArrayList(java.util.ArrayList) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Paint(android.graphics.Paint) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject)

Aggregations

TLObject (org.telegram.tgnet.TLObject)85 TLRPC (org.telegram.tgnet.TLRPC)79 Paint (android.graphics.Paint)36 ArrayList (java.util.ArrayList)36 TextPaint (android.text.TextPaint)25 SuppressLint (android.annotation.SuppressLint)22 ConnectionsManager (org.telegram.tgnet.ConnectionsManager)22 File (java.io.File)21 HashMap (java.util.HashMap)20 Context (android.content.Context)19 Build (android.os.Build)19 TextUtils (android.text.TextUtils)19 MessageObject (org.telegram.messenger.MessageObject)19 Theme (org.telegram.ui.ActionBar.Theme)19 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)18 LongSparseArray (androidx.collection.LongSparseArray)17 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)17 Bundle (android.os.Bundle)16 SpannableStringBuilder (android.text.SpannableStringBuilder)16 ChatObject (org.telegram.messenger.ChatObject)16