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

The following examples show how to use org.telegram.tgnet.TLRPC#InputFileLocation . 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: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private byte[] getFileReference(TLRPC.User user, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (user == null || user.photo == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    byte[] result = getFileReference(user.photo.photo_small, location, needReplacement);
    if (getPeerReferenceReplacement(user, null, false, location, replacement, needReplacement)) {
        return new byte[0];
    }
    if (result == null) {
        result = getFileReference(user.photo.photo_big, location, needReplacement);
        if (getPeerReferenceReplacement(user, null, true, location, replacement, needReplacement)) {
            return new byte[0];
        }
    }
    return result;
}
 
Example 2
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private byte[] getFileReference(TLRPC.Chat chat, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (chat == null || chat.photo == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    byte[] result = getFileReference(chat.photo.photo_small, location, needReplacement);
    if (getPeerReferenceReplacement(null, chat, false, location, replacement, needReplacement)) {
        return new byte[0];
    }
    if (result == null) {
        result = getFileReference(chat.photo.photo_big, location, needReplacement);
        if (getPeerReferenceReplacement(null, chat, true, location, replacement, needReplacement)) {
            return new byte[0];
        }
    }
    return result;
}
 
Example 3
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private byte[] getFileReference(TLRPC.User user, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (user == null || user.photo == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    byte[] result = getFileReference(user.photo.photo_small, location, needReplacement);
    if (getPeerReferenceReplacement(user, null, false, location, replacement, needReplacement)) {
        return new byte[0];
    }
    if (result == null) {
        result = getFileReference(user.photo.photo_big, location, needReplacement);
        if (getPeerReferenceReplacement(user, null, true, location, replacement, needReplacement)) {
            return new byte[0];
        }
    }
    return result;
}
 
Example 4
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private byte[] getFileReference(TLRPC.Chat chat, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (chat == null || chat.photo == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    byte[] result = getFileReference(chat.photo.photo_small, location, needReplacement);
    if (getPeerReferenceReplacement(null, chat, false, location, replacement, needReplacement)) {
        return new byte[0];
    }
    if (result == null) {
        result = getFileReference(chat.photo.photo_big, location, needReplacement);
        if (getPeerReferenceReplacement(null, chat, true, location, replacement, needReplacement)) {
            return new byte[0];
        }
    }
    return result;
}
 
Example 5
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.Document document, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (document == null || location == null) {
        return null;
    }
    if (location instanceof TLRPC.TL_inputDocumentFileLocation) {
        if (document.id == location.id) {
            return document.file_reference;
        }
    } else {
        for (int a = 0, size = document.thumbs.size(); a < size; a++) {
            TLRPC.PhotoSize photoSize = document.thumbs.get(a);
            byte[] result = getFileReference(photoSize, location, needReplacement);
            if (needReplacement != null && needReplacement[0]) {
                replacement[0] = new TLRPC.TL_inputDocumentFileLocation();
                replacement[0].id = document.id;
                replacement[0].volume_id = location.volume_id;
                replacement[0].local_id = location.local_id;
                replacement[0].access_hash = document.access_hash;
                replacement[0].file_reference = document.file_reference;
                replacement[0].thumb_size = photoSize.type;
                return document.file_reference;
            }
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 6
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private boolean getPeerReferenceReplacement(TLRPC.User user, TLRPC.Chat chat, boolean big, TLRPC.InputFileLocation location, TLRPC.InputFileLocation[] replacement, boolean[] needReplacement) {
    if (needReplacement != null && needReplacement[0]) {
        replacement[0] = new TLRPC.TL_inputPeerPhotoFileLocation();
        replacement[0].id = location.volume_id;
        replacement[0].volume_id = location.volume_id;
        replacement[0].local_id = location.local_id;
        replacement[0].big = big;
        TLRPC.InputPeer peer;
        if (user != null) {
            TLRPC.TL_inputPeerUser inputPeerUser = new TLRPC.TL_inputPeerUser();
            inputPeerUser.user_id = user.id;
            inputPeerUser.access_hash = user.access_hash;
            peer = inputPeerUser;
        } else {
            if (ChatObject.isChannel(chat)) {
                TLRPC.TL_inputPeerChat inputPeerChat = new TLRPC.TL_inputPeerChat();
                inputPeerChat.chat_id = chat.id;
                peer = inputPeerChat;
            } else {
                TLRPC.TL_inputPeerChannel inputPeerChannel = new TLRPC.TL_inputPeerChannel();
                inputPeerChannel.channel_id = chat.id;
                inputPeerChannel.access_hash = chat.access_hash;
                peer = inputPeerChannel;
            }
        }
        replacement[0].peer = peer;
        return true;
    }
    return false;
}
 
Example 7
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.Photo photo, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (photo == null) {
        return null;
    }
    if (location instanceof TLRPC.TL_inputPhotoFileLocation) {
        return photo.id == location.id ? photo.file_reference : null;
    } else if (location instanceof TLRPC.TL_inputFileLocation) {
        for (int a = 0, size = photo.sizes.size(); a < size; a++) {
            TLRPC.PhotoSize photoSize = photo.sizes.get(a);
            byte[] result = getFileReference(photoSize, location, needReplacement);
            if (needReplacement != null && needReplacement[0]) {
                replacement[0] = new TLRPC.TL_inputPhotoFileLocation();
                replacement[0].id = photo.id;
                replacement[0].volume_id = location.volume_id;
                replacement[0].local_id = location.local_id;
                replacement[0].access_hash = photo.access_hash;
                replacement[0].file_reference = photo.file_reference;
                replacement[0].thumb_size = photoSize.type;
                return photo.file_reference;
            }
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 8
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.FileLocation fileLocation, TLRPC.InputFileLocation location, boolean[] needReplacement) {
    if (fileLocation == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    if (fileLocation.local_id == location.local_id && fileLocation.volume_id == location.volume_id) {
        if (fileLocation.file_reference == null && needReplacement != null) {
            needReplacement[0] = true;
        }
        return fileLocation.file_reference;
    }
    return null;
}
 
Example 9
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.WebPage webpage, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    byte[] result = getFileReference(webpage.document, location, needReplacement, replacement);
    if (result != null) {
        return result;
    }
    result = getFileReference(webpage.photo, location, needReplacement, replacement);
    if (result != null) {
        return result;
    }
    if (!webpage.attributes.isEmpty()) {
        for (int a = 0, size1 = webpage.attributes.size(); a < size1; a++) {
            TLRPC.TL_webPageAttributeTheme attribute = webpage.attributes.get(a);
            for (int b = 0, size2 = attribute.documents.size(); b < size2; b++) {
                result = getFileReference(attribute.documents.get(b), location, needReplacement, replacement);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    if (webpage.cached_page != null) {
        for (int b = 0, size2 = webpage.cached_page.documents.size(); b < size2; b++) {
            result = getFileReference(webpage.cached_page.documents.get(b), location, needReplacement, replacement);
            if (result != null) {
                return result;
            }
        }
        for (int b = 0, size2 = webpage.cached_page.photos.size(); b < size2; b++) {
            result = getFileReference(webpage.cached_page.photos.get(b), location, needReplacement, replacement);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 10
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.Document document, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (document == null || location == null) {
        return null;
    }
    if (location instanceof TLRPC.TL_inputDocumentFileLocation) {
        if (document.id == location.id) {
            return document.file_reference;
        }
    } else {
        for (int a = 0, size = document.thumbs.size(); a < size; a++) {
            TLRPC.PhotoSize photoSize = document.thumbs.get(a);
            byte[] result = getFileReference(photoSize, location, needReplacement);
            if (needReplacement != null && needReplacement[0]) {
                replacement[0] = new TLRPC.TL_inputDocumentFileLocation();
                replacement[0].id = document.id;
                replacement[0].volume_id = location.volume_id;
                replacement[0].local_id = location.local_id;
                replacement[0].access_hash = document.access_hash;
                replacement[0].file_reference = document.file_reference;
                replacement[0].thumb_size = photoSize.type;
                return document.file_reference;
            }
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 11
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean getPeerReferenceReplacement(TLRPC.User user, TLRPC.Chat chat, boolean big, TLRPC.InputFileLocation location, TLRPC.InputFileLocation[] replacement, boolean[] needReplacement) {
    if (needReplacement != null && needReplacement[0]) {
        replacement[0] = new TLRPC.TL_inputPeerPhotoFileLocation();
        replacement[0].id = location.volume_id;
        replacement[0].volume_id = location.volume_id;
        replacement[0].local_id = location.local_id;
        replacement[0].big = big;
        TLRPC.InputPeer peer;
        if (user != null) {
            TLRPC.TL_inputPeerUser inputPeerUser = new TLRPC.TL_inputPeerUser();
            inputPeerUser.user_id = user.id;
            inputPeerUser.access_hash = user.access_hash;
            peer = inputPeerUser;
        } else {
            if (ChatObject.isChannel(chat)) {
                TLRPC.TL_inputPeerChat inputPeerChat = new TLRPC.TL_inputPeerChat();
                inputPeerChat.chat_id = chat.id;
                peer = inputPeerChat;
            } else {
                TLRPC.TL_inputPeerChannel inputPeerChannel = new TLRPC.TL_inputPeerChannel();
                inputPeerChannel.channel_id = chat.id;
                inputPeerChannel.access_hash = chat.access_hash;
                peer = inputPeerChannel;
            }
        }
        replacement[0].peer = peer;
        return true;
    }
    return false;
}
 
Example 12
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.Photo photo, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    if (photo == null) {
        return null;
    }
    if (location instanceof TLRPC.TL_inputPhotoFileLocation) {
        return photo.id == location.id ? photo.file_reference : null;
    } else if (location instanceof TLRPC.TL_inputFileLocation) {
        for (int a = 0, size = photo.sizes.size(); a < size; a++) {
            TLRPC.PhotoSize photoSize = photo.sizes.get(a);
            byte[] result = getFileReference(photoSize, location, needReplacement);
            if (needReplacement != null && needReplacement[0]) {
                replacement[0] = new TLRPC.TL_inputPhotoFileLocation();
                replacement[0].id = photo.id;
                replacement[0].volume_id = location.volume_id;
                replacement[0].local_id = location.local_id;
                replacement[0].access_hash = photo.access_hash;
                replacement[0].file_reference = photo.file_reference;
                replacement[0].thumb_size = photoSize.type;
                return photo.file_reference;
            }
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 13
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.FileLocation fileLocation, TLRPC.InputFileLocation location, boolean[] needReplacement) {
    if (fileLocation == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    if (fileLocation.local_id == location.local_id && fileLocation.volume_id == location.volume_id) {
        if (fileLocation.file_reference == null && needReplacement != null) {
            needReplacement[0] = true;
        }
        return fileLocation.file_reference;
    }
    return null;
}
 
Example 14
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private byte[] getFileReference(TLRPC.WebPage webpage, TLRPC.InputFileLocation location, boolean[] needReplacement, TLRPC.InputFileLocation[] replacement) {
    byte[] result = getFileReference(webpage.document, location, needReplacement, replacement);
    if (result != null) {
        return result;
    }
    result = getFileReference(webpage.photo, location, needReplacement, replacement);
    if (result != null) {
        return result;
    }
    if (!webpage.attributes.isEmpty()) {
        for (int a = 0, size1 = webpage.attributes.size(); a < size1; a++) {
            TLRPC.TL_webPageAttributeTheme attribute = webpage.attributes.get(a);
            for (int b = 0, size2 = attribute.documents.size(); b < size2; b++) {
                result = getFileReference(attribute.documents.get(b), location, needReplacement, replacement);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    if (webpage.cached_page != null) {
        for (int b = 0, size2 = webpage.cached_page.documents.size(); b < size2; b++) {
            result = getFileReference(webpage.cached_page.documents.get(b), location, needReplacement, replacement);
            if (result != null) {
                return result;
            }
        }
        for (int b = 0, size2 = webpage.cached_page.photos.size(); b < size2; b++) {
            result = getFileReference(webpage.cached_page.photos.get(b), location, needReplacement, replacement);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example 15
Source File: FileRefController.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getFileReference(TLRPC.PhotoSize photoSize, TLRPC.InputFileLocation location, boolean[] needReplacement) {
    if (photoSize == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    return getFileReference(photoSize.location, location, needReplacement);
}
 
Example 16
Source File: FileRefController.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private byte[] getFileReference(TLRPC.PhotoSize photoSize, TLRPC.InputFileLocation location, boolean[] needReplacement) {
    if (photoSize == null || !(location instanceof TLRPC.TL_inputFileLocation)) {
        return null;
    }
    return getFileReference(photoSize.location, location, needReplacement);
}