Reduce invalid inline requests + error messages

This commit is contained in:
John Gibbon 2021-01-11 10:19:00 +01:00
parent fe6ba8ac0d
commit c031e56284
2 changed files with 10 additions and 12 deletions

View file

@ -27,14 +27,15 @@ Loader {
active: userName.length > 1 active: userName.length > 1
asynchronous: true asynchronous: true
anchors.fill: parent anchors.fill: parent
property bool hasOverlay: active && status === Loader.Ready && item.overlay && item.overlay.status === Loader.Ready property bool hasOverlay: active && userNameIsValid && status === Loader.Ready && item.overlay && item.overlay.status === Loader.Ready
property bool hasButton: active && status === Loader.Ready && item.button && item.button.status === Loader.Ready property bool hasButton: active && userNameIsValid && status === Loader.Ready && item.button && item.button.status === Loader.Ready
property int buttonPadding: hasButton ? item.button.height + Theme.paddingSmall : 0 property int buttonPadding: hasButton ? item.button.height + Theme.paddingSmall : 0
Behavior on buttonPadding { NumberAnimation { duration: 200} } Behavior on buttonPadding { NumberAnimation { duration: 200} }
property string chatId property string chatId
property string userName property string userName
property bool userNameIsValid: userName !== "" && inlineBotInformation && userName === inlineBotInformation.username
property string query property string query
property int currentOffset: 0 property int currentOffset: 0
property string responseExtra: chatId+"|"+userName+"|"+query+"|"+currentOffset property string responseExtra: chatId+"|"+userName+"|"+query+"|"+currentOffset
@ -49,7 +50,7 @@ Loader {
onStatusChanged: { onStatusChanged: {
inlineBotInformation = null; inlineBotInformation = null;
if(status === Loader.Ready && userName !== "") { if(status === Loader.Ready && userName !== "") {
isLoading = true; isLoading = true; inlineQueryLoader.chatId
tdLibWrapper.searchPublicChat(userName, false); tdLibWrapper.searchPublicChat(userName, false);
} }
} }
@ -87,12 +88,7 @@ Loader {
inlineQueryLoader.currentOffset = offset || 0 inlineQueryLoader.currentOffset = offset || 0
} }
function request() { function request() {
if(!inlineBotInformation || !userNameIsValid) {
if(userName.length === 0) {
return;
}
if(!inlineBotInformation) {
queued = true; queued = true;
} else { } else {
queued = false; queued = false;
@ -202,7 +198,7 @@ Loader {
useDelegateSize = sizeKey; useDelegateSize = sizeKey;
} }
function loadMore() { function loadMore() {
if(nextOffset) { if(nextOffset && inlineQueryLoader.userNameIsValid) {
inlineQueryLoader.currentOffset = nextOffset; inlineQueryLoader.currentOffset = nextOffset;
inlineQueryLoader.request(); inlineQueryLoader.request();
} }

View file

@ -444,8 +444,10 @@ function getMessagesArrayText(messages) {
} }
function handleErrorMessage(code, message) { function handleErrorMessage(code, message) {
if (code === 404) { if (code === 404 || (code === 400 && message === "USERNAME_INVALID")) {
// Silently ignore 404 Not Found messages (occur sometimes, without clear context...) // Silently ignore
// - 404 Not Found messages (occur sometimes, without clear context...)
// - searchPublicChat messages for "invalid" inline queries
return; return;
} }
if (message === "USER_ALREADY_PARTICIPANT") { if (message === "USER_ALREADY_PARTICIPANT") {