Java Code Examples for org.telegram.tgnet.TLRPC#TL_inputPeerEmpty
The following examples show how to use
org.telegram.tgnet.TLRPC#TL_inputPeerEmpty .
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: BaseLocationAdapter.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void searchPlacesWithQuery(final String query, final Location coordinate, boolean searchUser) { if (coordinate == null || lastSearchLocation != null && coordinate.distanceTo(lastSearchLocation) < 200) { return; } lastSearchLocation = coordinate; lastSearchQuery = query; if (searching) { searching = false; if (currentRequestNum != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(currentRequestNum, true); currentRequestNum = 0; } } searching = true; TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(MessagesController.getInstance(currentAccount).venueSearchBot); if (!(object instanceof TLRPC.User)) { if (searchUser) { searchBotUser(); } return; } TLRPC.User user = (TLRPC.User) object; TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults(); req.query = query == null ? "" : query; req.bot = MessagesController.getInstance(currentAccount).getInputUser(user); req.offset = ""; req.geo_point = new TLRPC.TL_inputGeoPoint(); req.geo_point.lat = AndroidUtilities.fixLocationCoord(coordinate.getLatitude()); req.geo_point._long = AndroidUtilities.fixLocationCoord(coordinate.getLongitude()); req.flags |= 1; int lower_id = (int) dialogId; int high_id = (int) (dialogId >> 32); if (lower_id != 0) { req.peer = MessagesController.getInstance(currentAccount).getInputPeer(lower_id); } else { req.peer = new TLRPC.TL_inputPeerEmpty(); } currentRequestNum = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { currentRequestNum = 0; searching = false; places.clear(); iconUrls.clear(); if (error != null) { if (delegate != null) { delegate.didLoadedSearchResult(places); } } else { TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response; for (int a = 0, size = res.results.size(); a < size; a++) { TLRPC.BotInlineResult result = res.results.get(a); if (!"venue".equals(result.type) || !(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) { continue; } TLRPC.TL_botInlineMessageMediaVenue mediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) result.send_message; iconUrls.add("https://ss3.4sqi.net/img/categories_v2/" + mediaVenue.venue_type + "_64.png"); TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue(); venue.geo = mediaVenue.geo; venue.address = mediaVenue.address; venue.title = mediaVenue.title; venue.venue_type = mediaVenue.venue_type; venue.venue_id = mediaVenue.venue_id; venue.provider = mediaVenue.provider; places.add(venue); } } notifyDataSetChanged(); })); notifyDataSetChanged(); }
Example 2
Source File: DialogsSearchAdapter.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void searchMessagesInternal(final String query) { if (needMessagesSearch == 0 || (lastMessagesSearchString == null || lastMessagesSearchString.length() == 0) && (query == null || query.length() == 0)) { return; } if (reqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true); reqId = 0; } if (query == null || query.length() == 0) { searchResultMessages.clear(); lastReqId = 0; lastMessagesSearchString = null; notifyDataSetChanged(); if (delegate != null) { delegate.searchStateChanged(false); } return; } final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal(); req.limit = 20; req.q = query; if (lastMessagesSearchString != null && query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) { MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1); req.offset_id = lastMessage.getId(); req.offset_date = lastMessage.messageOwner.date; int id; if (lastMessage.messageOwner.to_id.channel_id != 0) { id = -lastMessage.messageOwner.to_id.channel_id; } else if (lastMessage.messageOwner.to_id.chat_id != 0) { id = -lastMessage.messageOwner.to_id.chat_id; } else { id = lastMessage.messageOwner.to_id.user_id; } req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id); } else { req.offset_date = 0; req.offset_id = 0; req.offset_peer = new TLRPC.TL_inputPeerEmpty(); } lastMessagesSearchString = query; final int currentReqId = ++lastReqId; if (delegate != null) { delegate.searchStateChanged(true); } reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (currentReqId == lastReqId) { if (error == null) { TLRPC.messages_Messages res = (TLRPC.messages_Messages) response; MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true); MessagesController.getInstance(currentAccount).putUsers(res.users, false); MessagesController.getInstance(currentAccount).putChats(res.chats, false); if (req.offset_id == 0) { searchResultMessages.clear(); } for (int a = 0; a < res.messages.size(); a++) { TLRPC.Message message = res.messages.get(a); searchResultMessages.add(new MessageObject(currentAccount, message, false)); long dialog_id = MessageObject.getDialogId(message); ConcurrentHashMap<Long, Integer> read_max = message.out ? MessagesController.getInstance(currentAccount).dialogs_read_outbox_max : MessagesController.getInstance(currentAccount).dialogs_read_inbox_max; Integer value = read_max.get(dialog_id); if (value == null) { value = MessagesStorage.getInstance(currentAccount).getDialogReadMax(message.out, dialog_id); read_max.put(dialog_id, value); } message.unread = value < message.id; } messagesSearchEndReached = res.messages.size() != 20; notifyDataSetChanged(); } } if (delegate != null) { delegate.searchStateChanged(false); } reqId = 0; }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 3
Source File: CallLogActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void getCalls(int max_id, final int count) { if (loading) { return; } loading = true; if (emptyView != null && !firstLoaded) { emptyView.showProgress(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } TLRPC.TL_messages_search req = new TLRPC.TL_messages_search(); req.limit = count; req.peer = new TLRPC.TL_inputPeerEmpty(); req.filter = new TLRPC.TL_inputMessagesFilterPhoneCalls(); req.q = ""; req.offset_id = max_id; int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { SparseArray<TLRPC.User> users = new SparseArray<>(); TLRPC.messages_Messages msgs = (TLRPC.messages_Messages) response; endReached = msgs.messages.isEmpty(); for (int a = 0; a < msgs.users.size(); a++) { TLRPC.User user = msgs.users.get(a); users.put(user.id, user); } CallLogRow currentRow = calls.size() > 0 ? calls.get(calls.size() - 1) : null; for (int a = 0; a < msgs.messages.size(); a++) { TLRPC.Message msg = msgs.messages.get(a); if (msg.action == null || msg.action instanceof TLRPC.TL_messageActionHistoryClear) { continue; } int callType = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? TYPE_OUT : TYPE_IN; TLRPC.PhoneCallDiscardReason reason = msg.action.reason; if (callType == TYPE_IN && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed || reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy)) { callType = TYPE_MISSED; } int userID = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? msg.to_id.user_id : msg.from_id; if (currentRow == null || currentRow.user.id != userID || currentRow.type != callType) { if (currentRow != null && !calls.contains(currentRow)) { calls.add(currentRow); } CallLogRow row = new CallLogRow(); row.calls = new ArrayList<>(); row.user = users.get(userID); row.type = callType; currentRow = row; } currentRow.calls.add(msg); } if (currentRow != null && currentRow.calls.size() > 0 && !calls.contains(currentRow)) { calls.add(currentRow); } } else { endReached = true; } loading = false; firstLoaded = true; if (emptyView != null) { emptyView.showTextView(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } }), ConnectionsManager.RequestFlagFailOnServerErrors); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); }
Example 4
Source File: BaseLocationAdapter.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public void searchPlacesWithQuery(final String query, final Location coordinate, boolean searchUser) { if (coordinate == null || lastSearchLocation != null && coordinate.distanceTo(lastSearchLocation) < 200) { return; } lastSearchLocation = coordinate; lastSearchQuery = query; if (searching) { searching = false; if (currentRequestNum != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(currentRequestNum, true); currentRequestNum = 0; } } searching = true; TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(MessagesController.getInstance(currentAccount).venueSearchBot); if (!(object instanceof TLRPC.User)) { if (searchUser) { searchBotUser(); } return; } TLRPC.User user = (TLRPC.User) object; TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults(); req.query = query == null ? "" : query; req.bot = MessagesController.getInstance(currentAccount).getInputUser(user); req.offset = ""; req.geo_point = new TLRPC.TL_inputGeoPoint(); req.geo_point.lat = AndroidUtilities.fixLocationCoord(coordinate.getLatitude()); req.geo_point._long = AndroidUtilities.fixLocationCoord(coordinate.getLongitude()); req.flags |= 1; int lower_id = (int) dialogId; int high_id = (int) (dialogId >> 32); if (lower_id != 0) { req.peer = MessagesController.getInstance(currentAccount).getInputPeer(lower_id); } else { req.peer = new TLRPC.TL_inputPeerEmpty(); } currentRequestNum = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { currentRequestNum = 0; searching = false; places.clear(); iconUrls.clear(); if (error != null) { if (delegate != null) { delegate.didLoadedSearchResult(places); } } else { TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response; for (int a = 0, size = res.results.size(); a < size; a++) { TLRPC.BotInlineResult result = res.results.get(a); if (!"venue".equals(result.type) || !(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) { continue; } TLRPC.TL_botInlineMessageMediaVenue mediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) result.send_message; iconUrls.add("https://ss3.4sqi.net/img/categories_v2/" + mediaVenue.venue_type + "_64.png"); TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue(); venue.geo = mediaVenue.geo; venue.address = mediaVenue.address; venue.title = mediaVenue.title; venue.venue_type = mediaVenue.venue_type; venue.venue_id = mediaVenue.venue_id; venue.provider = mediaVenue.provider; places.add(venue); } } notifyDataSetChanged(); })); notifyDataSetChanged(); }
Example 5
Source File: DialogsSearchAdapter.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void searchMessagesInternal(final String query) { if (needMessagesSearch == 0 || (lastMessagesSearchString == null || lastMessagesSearchString.length() == 0) && (query == null || query.length() == 0)) { return; } if (reqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true); reqId = 0; } if (query == null || query.length() == 0) { searchResultMessages.clear(); lastReqId = 0; lastMessagesSearchString = null; notifyDataSetChanged(); if (delegate != null) { delegate.searchStateChanged(false); } return; } final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal(); req.limit = 20; req.q = query; if (lastMessagesSearchString != null && query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) { MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1); req.offset_id = lastMessage.getId(); req.offset_date = lastMessage.messageOwner.date; int id; if (lastMessage.messageOwner.to_id.channel_id != 0) { id = -lastMessage.messageOwner.to_id.channel_id; } else if (lastMessage.messageOwner.to_id.chat_id != 0) { id = -lastMessage.messageOwner.to_id.chat_id; } else { id = lastMessage.messageOwner.to_id.user_id; } req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id); } else { req.offset_date = 0; req.offset_id = 0; req.offset_peer = new TLRPC.TL_inputPeerEmpty(); } lastMessagesSearchString = query; final int currentReqId = ++lastReqId; if (delegate != null) { delegate.searchStateChanged(true); } reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (currentReqId == lastReqId) { if (error == null) { TLRPC.messages_Messages res = (TLRPC.messages_Messages) response; MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true); MessagesController.getInstance(currentAccount).putUsers(res.users, false); MessagesController.getInstance(currentAccount).putChats(res.chats, false); if (req.offset_id == 0) { searchResultMessages.clear(); } for (int a = 0; a < res.messages.size(); a++) { TLRPC.Message message = res.messages.get(a); searchResultMessages.add(new MessageObject(currentAccount, message, false)); long dialog_id = MessageObject.getDialogId(message); ConcurrentHashMap<Long, Integer> read_max = message.out ? MessagesController.getInstance(currentAccount).dialogs_read_outbox_max : MessagesController.getInstance(currentAccount).dialogs_read_inbox_max; Integer value = read_max.get(dialog_id); if (value == null) { value = MessagesStorage.getInstance(currentAccount).getDialogReadMax(message.out, dialog_id); read_max.put(dialog_id, value); } message.unread = value < message.id; } messagesSearchEndReached = res.messages.size() != 20; notifyDataSetChanged(); } } if (delegate != null) { delegate.searchStateChanged(false); } reqId = 0; }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 6
Source File: CallLogActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void getCalls(int max_id, final int count) { if (loading) { return; } loading = true; if (emptyView != null && !firstLoaded) { emptyView.showProgress(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } TLRPC.TL_messages_search req = new TLRPC.TL_messages_search(); req.limit = count; req.peer = new TLRPC.TL_inputPeerEmpty(); req.filter = new TLRPC.TL_inputMessagesFilterPhoneCalls(); req.q = ""; req.offset_id = max_id; int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { SparseArray<TLRPC.User> users = new SparseArray<>(); TLRPC.messages_Messages msgs = (TLRPC.messages_Messages) response; endReached = msgs.messages.isEmpty(); for (int a = 0; a < msgs.users.size(); a++) { TLRPC.User user = msgs.users.get(a); users.put(user.id, user); } CallLogRow currentRow = calls.size() > 0 ? calls.get(calls.size() - 1) : null; for (int a = 0; a < msgs.messages.size(); a++) { TLRPC.Message msg = msgs.messages.get(a); if (msg.action == null || msg.action instanceof TLRPC.TL_messageActionHistoryClear) { continue; } int callType = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? TYPE_OUT : TYPE_IN; TLRPC.PhoneCallDiscardReason reason = msg.action.reason; if (callType == TYPE_IN && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed || reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy)) { callType = TYPE_MISSED; } int userID = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? msg.to_id.user_id : msg.from_id; if (currentRow == null || currentRow.user.id != userID || currentRow.type != callType) { if (currentRow != null && !calls.contains(currentRow)) { calls.add(currentRow); } CallLogRow row = new CallLogRow(); row.calls = new ArrayList<>(); row.user = users.get(userID); row.type = callType; currentRow = row; } currentRow.calls.add(msg); } if (currentRow != null && currentRow.calls.size() > 0 && !calls.contains(currentRow)) { calls.add(currentRow); } } else { endReached = true; } loading = false; firstLoaded = true; if (emptyView != null) { emptyView.showTextView(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } }), ConnectionsManager.RequestFlagFailOnServerErrors); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); }
Example 7
Source File: DialogsSearchAdapter.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void searchMessagesInternal(final String query, int searchId) { if (needMessagesSearch == 0 || TextUtils.isEmpty(lastMessagesSearchString) && TextUtils.isEmpty(query)) { return; } if (reqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true); reqId = 0; } if (TextUtils.isEmpty(query)) { searchResultMessages.clear(); lastReqId = 0; lastMessagesSearchString = null; searchWas = false; notifyDataSetChanged(); if (delegate != null) { delegate.searchStateChanged(false); } return; } final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal(); req.limit = 20; req.q = query; if (query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) { MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1); req.offset_id = lastMessage.getId(); req.offset_rate = nextSearchRate; int id; if (lastMessage.messageOwner.to_id.channel_id != 0) { id = -lastMessage.messageOwner.to_id.channel_id; } else if (lastMessage.messageOwner.to_id.chat_id != 0) { id = -lastMessage.messageOwner.to_id.chat_id; } else { id = lastMessage.messageOwner.to_id.user_id; } req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id); } else { req.offset_rate = 0; req.offset_id = 0; req.offset_peer = new TLRPC.TL_inputPeerEmpty(); } lastMessagesSearchString = query; final int currentReqId = ++lastReqId; /*if (delegate != null) { delegate.searchStateChanged(true); }*/ reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (currentReqId == lastReqId && (searchId <= 0 || searchId == lastSearchId)) { if (error == null) { TLRPC.messages_Messages res = (TLRPC.messages_Messages) response; MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true); MessagesController.getInstance(currentAccount).putUsers(res.users, false); MessagesController.getInstance(currentAccount).putChats(res.chats, false); if (req.offset_id == 0) { searchResultMessages.clear(); } nextSearchRate = res.next_rate; for (int a = 0; a < res.messages.size(); a++) { TLRPC.Message message = res.messages.get(a); long did = MessageObject.getDialogId(message); Integer maxId = MessagesController.getInstance(currentAccount).deletedHistory.get(did); if (maxId != null && message.id <= maxId) { continue; } searchResultMessages.add(new MessageObject(currentAccount, message, false)); long dialog_id = MessageObject.getDialogId(message); ConcurrentHashMap<Long, Integer> read_max = message.out ? MessagesController.getInstance(currentAccount).dialogs_read_outbox_max : MessagesController.getInstance(currentAccount).dialogs_read_inbox_max; Integer value = read_max.get(dialog_id); if (value == null) { value = MessagesStorage.getInstance(currentAccount).getDialogReadMax(message.out, dialog_id); read_max.put(dialog_id, value); } message.unread = value < message.id; } searchWas = true; messagesSearchEndReached = res.messages.size() != 20; if (searchId > 0) { lastMessagesSearchId = searchId; if (lastLocalSearchId != searchId) { searchResult.clear(); } if (lastGlobalSearchId != searchId) { searchAdapterHelper.clear(); } } notifyDataSetChanged(); } } reqId = 0; if (!searchAdapterHelper.isSearchInProgress() && delegate != null) { delegate.searchStateChanged(false); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 8
Source File: CallLogActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void getCalls(int max_id, final int count) { if (loading) { return; } loading = true; if (emptyView != null && !firstLoaded) { emptyView.showProgress(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } TLRPC.TL_messages_search req = new TLRPC.TL_messages_search(); req.limit = count; req.peer = new TLRPC.TL_inputPeerEmpty(); req.filter = new TLRPC.TL_inputMessagesFilterPhoneCalls(); req.q = ""; req.offset_id = max_id; int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { SparseArray<TLRPC.User> users = new SparseArray<>(); TLRPC.messages_Messages msgs = (TLRPC.messages_Messages) response; endReached = msgs.messages.isEmpty(); for (int a = 0; a < msgs.users.size(); a++) { TLRPC.User user = msgs.users.get(a); users.put(user.id, user); } CallLogRow currentRow = calls.size() > 0 ? calls.get(calls.size() - 1) : null; for (int a = 0; a < msgs.messages.size(); a++) { TLRPC.Message msg = msgs.messages.get(a); if (msg.action == null || msg.action instanceof TLRPC.TL_messageActionHistoryClear) { continue; } int callType = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? TYPE_OUT : TYPE_IN; TLRPC.PhoneCallDiscardReason reason = msg.action.reason; if (callType == TYPE_IN && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed || reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy)) { callType = TYPE_MISSED; } int userID = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? msg.to_id.user_id : msg.from_id; if (currentRow == null || currentRow.user.id != userID || currentRow.type != callType) { if (currentRow != null && !calls.contains(currentRow)) { calls.add(currentRow); } CallLogRow row = new CallLogRow(); row.calls = new ArrayList<>(); row.user = users.get(userID); row.type = callType; currentRow = row; } currentRow.calls.add(msg); } if (currentRow != null && currentRow.calls.size() > 0 && !calls.contains(currentRow)) { calls.add(currentRow); } } else { endReached = true; } loading = false; firstLoaded = true; if (emptyView != null) { emptyView.showTextView(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } }), ConnectionsManager.RequestFlagFailOnServerErrors); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); }
Example 9
Source File: DialogsSearchAdapter.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void searchMessagesInternal(final String query, int searchId) { if (needMessagesSearch == 0 || TextUtils.isEmpty(lastMessagesSearchString) && TextUtils.isEmpty(query)) { return; } if (reqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true); reqId = 0; } if (TextUtils.isEmpty(query)) { searchResultMessages.clear(); lastReqId = 0; lastMessagesSearchString = null; searchWas = false; notifyDataSetChanged(); if (delegate != null) { delegate.searchStateChanged(false); } return; } final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal(); req.limit = 20; req.q = query; if (query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) { MessageObject lastMessage = searchResultMessages.get(searchResultMessages.size() - 1); req.offset_id = lastMessage.getId(); req.offset_rate = nextSearchRate; int id; if (lastMessage.messageOwner.to_id.channel_id != 0) { id = -lastMessage.messageOwner.to_id.channel_id; } else if (lastMessage.messageOwner.to_id.chat_id != 0) { id = -lastMessage.messageOwner.to_id.chat_id; } else { id = lastMessage.messageOwner.to_id.user_id; } req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id); } else { req.offset_rate = 0; req.offset_id = 0; req.offset_peer = new TLRPC.TL_inputPeerEmpty(); } lastMessagesSearchString = query; final int currentReqId = ++lastReqId; /*if (delegate != null) { delegate.searchStateChanged(true); }*/ reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (currentReqId == lastReqId && (searchId <= 0 || searchId == lastSearchId)) { if (error == null) { TLRPC.messages_Messages res = (TLRPC.messages_Messages) response; MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true); MessagesController.getInstance(currentAccount).putUsers(res.users, false); MessagesController.getInstance(currentAccount).putChats(res.chats, false); if (req.offset_id == 0) { searchResultMessages.clear(); } nextSearchRate = res.next_rate; for (int a = 0; a < res.messages.size(); a++) { TLRPC.Message message = res.messages.get(a); long did = MessageObject.getDialogId(message); Integer maxId = MessagesController.getInstance(currentAccount).deletedHistory.get(did); if (maxId != null && message.id <= maxId) { continue; } searchResultMessages.add(new MessageObject(currentAccount, message, false)); long dialog_id = MessageObject.getDialogId(message); ConcurrentHashMap<Long, Integer> read_max = message.out ? MessagesController.getInstance(currentAccount).dialogs_read_outbox_max : MessagesController.getInstance(currentAccount).dialogs_read_inbox_max; Integer value = read_max.get(dialog_id); if (value == null) { value = MessagesStorage.getInstance(currentAccount).getDialogReadMax(message.out, dialog_id); read_max.put(dialog_id, value); } message.unread = value < message.id; } searchWas = true; messagesSearchEndReached = res.messages.size() != 20; if (searchId > 0) { lastMessagesSearchId = searchId; if (lastLocalSearchId != searchId) { searchResult.clear(); } if (lastGlobalSearchId != searchId) { searchAdapterHelper.clear(); } } notifyDataSetChanged(); } } reqId = 0; if (!searchAdapterHelper.isSearchInProgress() && delegate != null) { delegate.searchStateChanged(false); } }), ConnectionsManager.RequestFlagFailOnServerErrors); }
Example 10
Source File: CallLogActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void getCalls(int max_id, final int count) { if (loading) { return; } loading = true; if (emptyView != null && !firstLoaded) { emptyView.showProgress(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } TLRPC.TL_messages_search req = new TLRPC.TL_messages_search(); req.limit = count; req.peer = new TLRPC.TL_inputPeerEmpty(); req.filter = new TLRPC.TL_inputMessagesFilterPhoneCalls(); req.q = ""; req.offset_id = max_id; int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { SparseArray<TLRPC.User> users = new SparseArray<>(); TLRPC.messages_Messages msgs = (TLRPC.messages_Messages) response; endReached = msgs.messages.isEmpty(); for (int a = 0; a < msgs.users.size(); a++) { TLRPC.User user = msgs.users.get(a); users.put(user.id, user); } CallLogRow currentRow = calls.size() > 0 ? calls.get(calls.size() - 1) : null; for (int a = 0; a < msgs.messages.size(); a++) { TLRPC.Message msg = msgs.messages.get(a); if (msg.action == null || msg.action instanceof TLRPC.TL_messageActionHistoryClear) { continue; } int callType = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? TYPE_OUT : TYPE_IN; TLRPC.PhoneCallDiscardReason reason = msg.action.reason; if (callType == TYPE_IN && (reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed || reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy)) { callType = TYPE_MISSED; } int userID = msg.from_id == UserConfig.getInstance(currentAccount).getClientUserId() ? msg.to_id.user_id : msg.from_id; if (currentRow == null || currentRow.user.id != userID || currentRow.type != callType) { if (currentRow != null && !calls.contains(currentRow)) { calls.add(currentRow); } CallLogRow row = new CallLogRow(); row.calls = new ArrayList<>(); row.user = users.get(userID); row.type = callType; currentRow = row; } currentRow.calls.add(msg); } if (currentRow != null && currentRow.calls.size() > 0 && !calls.contains(currentRow)) { calls.add(currentRow); } } else { endReached = true; } loading = false; firstLoaded = true; if (emptyView != null) { emptyView.showTextView(); } if (listViewAdapter != null) { listViewAdapter.notifyDataSetChanged(); } }), ConnectionsManager.RequestFlagFailOnServerErrors); ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid); }