use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaDataController method fetchNewEmojiKeywords.
public void fetchNewEmojiKeywords(String[] langCodes) {
if (langCodes == null) {
return;
}
for (int a = 0; a < langCodes.length; a++) {
String langCode = langCodes[a];
if (TextUtils.isEmpty(langCode)) {
return;
}
if (currentFetchingEmoji.get(langCode) != null) {
return;
}
currentFetchingEmoji.put(langCode, true);
getMessagesStorage().getStorageQueue().postRunnable(() -> {
int version = -1;
String alias = null;
long date = 0;
try {
SQLiteCursor cursor = getMessagesStorage().getDatabase().queryFinalized("SELECT alias, version, date FROM emoji_keywords_info_v2 WHERE lang = ?", langCode);
if (cursor.next()) {
alias = cursor.stringValue(0);
version = cursor.intValue(1);
date = cursor.longValue(2);
}
cursor.dispose();
} catch (Exception e) {
FileLog.e(e);
}
if (!BuildVars.DEBUG_VERSION && Math.abs(System.currentTimeMillis() - date) < 60 * 60 * 1000) {
AndroidUtilities.runOnUIThread(() -> currentFetchingEmoji.remove(langCode));
return;
}
TLObject request;
if (version == -1) {
TLRPC.TL_messages_getEmojiKeywords req = new TLRPC.TL_messages_getEmojiKeywords();
req.lang_code = langCode;
request = req;
} else {
TLRPC.TL_messages_getEmojiKeywordsDifference req = new TLRPC.TL_messages_getEmojiKeywordsDifference();
req.lang_code = langCode;
req.from_version = version;
request = req;
}
String aliasFinal = alias;
int versionFinal = version;
getConnectionsManager().sendRequest(request, (response, error) -> {
if (response != null) {
TLRPC.TL_emojiKeywordsDifference res = (TLRPC.TL_emojiKeywordsDifference) response;
if (versionFinal != -1 && !res.lang_code.equals(aliasFinal)) {
getMessagesStorage().getStorageQueue().postRunnable(() -> {
try {
SQLitePreparedStatement deleteState = getMessagesStorage().getDatabase().executeFast("DELETE FROM emoji_keywords_info_v2 WHERE lang = ?");
deleteState.bindString(1, langCode);
deleteState.step();
deleteState.dispose();
AndroidUtilities.runOnUIThread(() -> {
currentFetchingEmoji.remove(langCode);
fetchNewEmojiKeywords(new String[] { langCode });
});
} catch (Exception e) {
FileLog.e(e);
}
});
} else {
putEmojiKeywords(langCode, res);
}
} else {
AndroidUtilities.runOnUIThread(() -> currentFetchingEmoji.remove(langCode));
}
});
});
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaController method loadMoreMusic.
public void loadMoreMusic() {
if (loadingPlaylist || playingMessageObject == null || playingMessageObject.scheduled || DialogObject.isEncryptedDialog(playingMessageObject.getDialogId()) || playlistClassGuid == 0) {
return;
}
if (playlistGlobalSearchParams != null) {
int finalPlaylistGuid = playlistClassGuid;
if (!playlistGlobalSearchParams.endReached && !playlist.isEmpty()) {
int currentAccount = playlist.get(0).currentAccount;
TLObject request;
if (playlistGlobalSearchParams.dialogId != 0) {
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.q = playlistGlobalSearchParams.query;
req.limit = 20;
req.filter = playlistGlobalSearchParams.filter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : playlistGlobalSearchParams.filter.filter;
req.peer = AccountInstance.getInstance(currentAccount).getMessagesController().getInputPeer(playlistGlobalSearchParams.dialogId);
MessageObject lastMessage = playlist.get(playlist.size() - 1);
req.offset_id = lastMessage.getId();
if (playlistGlobalSearchParams.minDate > 0) {
req.min_date = (int) (playlistGlobalSearchParams.minDate / 1000);
}
if (playlistGlobalSearchParams.maxDate > 0) {
req.min_date = (int) (playlistGlobalSearchParams.maxDate / 1000);
}
request = req;
} else {
final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
req.limit = 20;
req.q = playlistGlobalSearchParams.query;
req.filter = playlistGlobalSearchParams.filter.filter;
MessageObject lastMessage = playlist.get(playlist.size() - 1);
req.offset_id = lastMessage.getId();
req.offset_rate = playlistGlobalSearchParams.nextSearchRate;
req.flags |= 1;
req.folder_id = playlistGlobalSearchParams.folderId;
long id;
if (lastMessage.messageOwner.peer_id.channel_id != 0) {
id = -lastMessage.messageOwner.peer_id.channel_id;
} else if (lastMessage.messageOwner.peer_id.chat_id != 0) {
id = -lastMessage.messageOwner.peer_id.chat_id;
} else {
id = lastMessage.messageOwner.peer_id.user_id;
}
req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id);
if (playlistGlobalSearchParams.minDate > 0) {
req.min_date = (int) (playlistGlobalSearchParams.minDate / 1000);
}
if (playlistGlobalSearchParams.maxDate > 0) {
req.min_date = (int) (playlistGlobalSearchParams.maxDate / 1000);
}
request = req;
}
loadingPlaylist = true;
ConnectionsManager.getInstance(currentAccount).sendRequest(request, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (playlistClassGuid != finalPlaylistGuid || playlistGlobalSearchParams == null || playingMessageObject == null) {
return;
}
if (error != null) {
return;
}
loadingPlaylist = false;
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
playlistGlobalSearchParams.nextSearchRate = res.next_rate;
MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
MessagesController.getInstance(currentAccount).putUsers(res.users, false);
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
int n = res.messages.size();
int addedCount = 0;
for (int i = 0; i < n; i++) {
MessageObject messageObject = new MessageObject(currentAccount, res.messages.get(i), false, true);
if (playlistMap.containsKey(messageObject.getId())) {
continue;
}
playlist.add(0, messageObject);
playlistMap.put(messageObject.getId(), messageObject);
addedCount++;
}
sortPlaylist();
loadingPlaylist = false;
playlistGlobalSearchParams.endReached = playlist.size() == playlistGlobalSearchParams.totalCount;
if (SharedConfig.shuffleMusic) {
buildShuffledPlayList();
}
if (addedCount != 0) {
NotificationCenter.getInstance(playingMessageObject.currentAccount).postNotificationName(NotificationCenter.moreMusicDidLoad, addedCount);
}
}));
}
return;
}
if (!playlistEndReached[0]) {
loadingPlaylist = true;
AccountInstance.getInstance(playingMessageObject.currentAccount).getMediaDataController().loadMedia(playingMessageObject.getDialogId(), 50, playlistMaxId[0], 0, MediaDataController.MEDIA_MUSIC, 1, playlistClassGuid, 0);
} else if (playlistMergeDialogId != 0 && !playlistEndReached[1]) {
loadingPlaylist = true;
AccountInstance.getInstance(playingMessageObject.currentAccount).getMediaDataController().loadMedia(playlistMergeDialogId, 50, playlistMaxId[0], 0, MediaDataController.MEDIA_MUSIC, 1, playlistClassGuid, 0);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class LocationController method markLiveLoactionsAsRead.
public void markLiveLoactionsAsRead(long dialogId) {
if (DialogObject.isEncryptedDialog(dialogId)) {
return;
}
ArrayList<TLRPC.Message> messages = locationsCache.get(dialogId);
if (messages == null || messages.isEmpty()) {
return;
}
Integer date = lastReadLocationTime.get(dialogId);
int currentDate = (int) (SystemClock.elapsedRealtime() / 1000);
if (date != null && date + 60 > currentDate) {
return;
}
lastReadLocationTime.put(dialogId, currentDate);
TLObject request;
if (DialogObject.isChatDialog(dialogId) && ChatObject.isChannel(-dialogId, currentAccount)) {
TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
for (int a = 0, N = messages.size(); a < N; a++) {
req.id.add(messages.get(a).id);
}
req.channel = getMessagesController().getInputChannel(-dialogId);
request = req;
} else {
TLRPC.TL_messages_readMessageContents req = new TLRPC.TL_messages_readMessageContents();
for (int a = 0, N = messages.size(); a < N; a++) {
req.id.add(messages.get(a).id);
}
request = req;
}
getConnectionsManager().sendRequest(request, (response, error) -> {
if (response instanceof TLRPC.TL_messages_affectedMessages) {
TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
getMessagesController().processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
}
});
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class AvatarsDarawable method animateFromState.
public void animateFromState(AvatarsDarawable avatarsDarawable, int currentAccount) {
TLObject[] objects = new TLObject[3];
for (int i = 0; i < 3; i++) {
objects[i] = currentStates[i].object;
setObject(i, currentAccount, avatarsDarawable.currentStates[i].object);
}
commitTransition(false);
for (int i = 0; i < 3; i++) {
setObject(i, currentAccount, objects[i]);
}
wasDraw = true;
commitTransition(true);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickerMasksAlert method updateStickerTabs.
private void updateStickerTabs() {
if (stickersTab == null) {
return;
}
if (stickersButton != null) {
if (currentType == MediaDataController.TYPE_IMAGE) {
stickersButton.setSelected(true);
masksButton.setSelected(false);
} else {
stickersButton.setSelected(false);
masksButton.setSelected(true);
}
}
recentTabBum = -2;
favTabBum = -2;
stickersTabOffset = 0;
int lastPosition = stickersTab.getCurrentPosition();
stickersTab.beginUpdate(false);
if (currentType == MediaDataController.TYPE_IMAGE && !favouriteStickers.isEmpty()) {
favTabBum = stickersTabOffset;
stickersTabOffset++;
stickersTab.addIconTab(1, stickerIcons[1]).setContentDescription(LocaleController.getString("FavoriteStickers", R.string.FavoriteStickers));
}
if (!recentStickers[currentType].isEmpty()) {
recentTabBum = stickersTabOffset;
stickersTabOffset++;
stickersTab.addIconTab(0, stickerIcons[0]).setContentDescription(LocaleController.getString("RecentStickers", R.string.RecentStickers));
}
stickerSets[currentType].clear();
ArrayList<TLRPC.TL_messages_stickerSet> packs = MediaDataController.getInstance(currentAccount).getStickerSets(currentType);
for (int a = 0; a < packs.size(); a++) {
TLRPC.TL_messages_stickerSet pack = packs.get(a);
if (pack.set.archived || pack.documents == null || pack.documents.isEmpty()) {
continue;
}
stickerSets[currentType].add(pack);
}
for (int a = 0; a < stickerSets[currentType].size(); a++) {
TLRPC.TL_messages_stickerSet stickerSet = stickerSets[currentType].get(a);
TLRPC.Document document = stickerSet.documents.get(0);
TLObject thumb = FileLoader.getClosestPhotoSizeWithSize(stickerSet.set.thumbs, 90);
if (thumb == null) {
thumb = document;
}
stickersTab.addStickerTab(thumb, document, stickerSet).setContentDescription(stickerSet.set.title + ", " + LocaleController.getString("AccDescrStickerSet", R.string.AccDescrStickerSet));
}
stickersTab.commitUpdate();
stickersTab.updateTabStyles();
if (lastPosition != 0) {
stickersTab.onPageScrolled(lastPosition, lastPosition);
}
checkPanels();
}
Aggregations