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

The following examples show how to use org.telegram.tgnet.TLRPC#Message . 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: SecretChatHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void sendNoopMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }

    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionNoop();
        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 2
Source File: SecretChatHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void sendAcceptKeyMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }

    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionAcceptKey();
        reqSend.action.exchange_id = encryptedChat.exchange_id;
        reqSend.action.key_fingerprint = encryptedChat.future_key_fingerprint;
        reqSend.action.g_b = encryptedChat.g_a_or_b;

        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 3
Source File: SecretChatHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void sendNotifyLayerMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }
    if (sendingNotifyLayer.contains(encryptedChat.id)) {
        return;
    }
    sendingNotifyLayer.add(encryptedChat.id);
    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionNotifyLayer();
        reqSend.action.layer = CURRENT_SECRET_CHAT_LAYER;
        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 4
Source File: SecretChatHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void sendRequestKeyMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }

    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionRequestKey();
        reqSend.action.exchange_id = encryptedChat.exchange_id;
        reqSend.action.g_a = encryptedChat.g_a;

        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 5
Source File: SecretChatHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void sendMessagesDeleteMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }
    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionDeleteMessages();
        reqSend.action.random_ids = random_ids;
        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 6
Source File: SecretChatHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private TLRPC.Message createDeleteMessage(int mid, int seq_out, int seq_in, long random_id, TLRPC.EncryptedChat encryptedChat) {
    TLRPC.TL_messageService newMsg = new TLRPC.TL_messageService();
    newMsg.action = new TLRPC.TL_messageEncryptedAction();
    newMsg.action.encryptedAction = new TLRPC.TL_decryptedMessageActionDeleteMessages();
    newMsg.action.encryptedAction.random_ids.add(random_id);
    newMsg.local_id = newMsg.id = mid;
    newMsg.from_id = UserConfig.getInstance(currentAccount).getClientUserId();
    newMsg.unread = true;
    newMsg.out = true;
    newMsg.flags = TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
    newMsg.dialog_id = ((long) encryptedChat.id) << 32;
    newMsg.to_id = new TLRPC.TL_peerUser();
    newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
    newMsg.seq_in = seq_in;
    newMsg.seq_out = seq_out;
    if (encryptedChat.participant_id == UserConfig.getInstance(currentAccount).getClientUserId()) {
        newMsg.to_id.user_id = encryptedChat.admin_id;
    } else {
        newMsg.to_id.user_id = encryptedChat.participant_id;
    }
    newMsg.date = 0;
    newMsg.random_id = random_id;
    return newMsg;
}
 
Example 7
Source File: SecretChatHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private TLRPC.Message createDeleteMessage(int mid, int seq_out, int seq_in, long random_id, TLRPC.EncryptedChat encryptedChat) {
    TLRPC.TL_messageService newMsg = new TLRPC.TL_messageService();
    newMsg.action = new TLRPC.TL_messageEncryptedAction();
    newMsg.action.encryptedAction = new TLRPC.TL_decryptedMessageActionDeleteMessages();
    newMsg.action.encryptedAction.random_ids.add(random_id);
    newMsg.local_id = newMsg.id = mid;
    newMsg.from_id = getUserConfig().getClientUserId();
    newMsg.unread = true;
    newMsg.out = true;
    newMsg.flags = TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
    newMsg.dialog_id = ((long) encryptedChat.id) << 32;
    newMsg.to_id = new TLRPC.TL_peerUser();
    newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
    newMsg.seq_in = seq_in;
    newMsg.seq_out = seq_out;
    if (encryptedChat.participant_id == getUserConfig().getClientUserId()) {
        newMsg.to_id.user_id = encryptedChat.admin_id;
    } else {
        newMsg.to_id.user_id = encryptedChat.participant_id;
    }
    newMsg.date = 0;
    newMsg.random_id = random_id;
    return newMsg;
}
 
Example 8
Source File: SecretChatHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void sendNoopMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }

    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();
    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionNoop();
        message = createServiceSecretMessage(encryptedChat, reqSend.action);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 9
Source File: ImageLoader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void saveMessagesThumbs(ArrayList<TLRPC.Message> messages) {
    if (messages == null || messages.isEmpty()) {
        return;
    }
    for (int a = 0; a < messages.size(); a++) {
        TLRPC.Message message = messages.get(a);
        saveMessageThumbs(message);
    }
}
 
Example 10
Source File: SecretChatHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void sendScreenshotMessage(TLRPC.EncryptedChat encryptedChat, ArrayList<Long> random_ids, TLRPC.Message resendMessage) {
    if (!(encryptedChat instanceof TLRPC.TL_encryptedChat)) {
        return;
    }

    TLRPC.TL_decryptedMessageService reqSend = new TLRPC.TL_decryptedMessageService();

    TLRPC.Message message;

    if (resendMessage != null) {
        message = resendMessage;
        reqSend.action = message.action.encryptedAction;
    } else {
        reqSend.action = new TLRPC.TL_decryptedMessageActionScreenshotMessages();
        reqSend.action.random_ids = random_ids;
        message = createServiceSecretMessage(encryptedChat, reqSend.action);

        MessageObject newMsgObj = new MessageObject(currentAccount, message, false);
        newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
        ArrayList<MessageObject> objArr = new ArrayList<>();
        objArr.add(newMsgObj);
        MessagesController.getInstance(currentAccount).updateInterfaceWithMessages(message.dialog_id, objArr);
        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.dialogsNeedReload);
    }
    reqSend.random_id = message.random_id;

    performSendEncryptedRequest(reqSend, message, encryptedChat, null, null, null);
}
 
Example 11
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private int getMessageId(TLRPC.Message message) {
    if (message.from_id != 0) {
        return message.from_id;
    } else {
        return (int) MessageObject.getDialogId(message);
    }
}
 
Example 12
Source File: SecretChatHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private TLRPC.TL_messageService createServiceSecretMessage(final TLRPC.EncryptedChat encryptedChat, TLRPC.DecryptedMessageAction decryptedMessage) {
    TLRPC.TL_messageService newMsg = new TLRPC.TL_messageService();

    newMsg.action = new TLRPC.TL_messageEncryptedAction();
    newMsg.action.encryptedAction = decryptedMessage;
    newMsg.local_id = newMsg.id = getUserConfig().getNewMessageId();
    newMsg.from_id = getUserConfig().getClientUserId();
    newMsg.unread = true;
    newMsg.out = true;
    newMsg.flags = TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
    newMsg.dialog_id = ((long) encryptedChat.id) << 32;
    newMsg.to_id = new TLRPC.TL_peerUser();
    newMsg.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
    if (encryptedChat.participant_id == getUserConfig().getClientUserId()) {
        newMsg.to_id.user_id = encryptedChat.admin_id;
    } else {
        newMsg.to_id.user_id = encryptedChat.participant_id;
    }
    if (decryptedMessage instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || decryptedMessage instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
        newMsg.date = getConnectionsManager().getCurrentTime();
    } else {
        newMsg.date = 0;
    }
    newMsg.random_id = getSendMessagesHelper().getNextRandomId();
    getUserConfig().saveConfig(false);

    ArrayList<TLRPC.Message> arr = new ArrayList<>();
    arr.add(newMsg);
    getMessagesStorage().putMessages(arr, false, true, true, 0, false);

    return newMsg;
}
 
Example 13
Source File: ShareActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    ApplicationLoader.postInitApplication();
    AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setTheme(R.style.Theme_TMessages_Transparent);
    super.onCreate(savedInstanceState);
    setContentView(new View(this), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    Intent intent = getIntent();
    if (intent == null || !Intent.ACTION_VIEW.equals(intent.getAction()) || intent.getData() == null)
    {
        finish();
        return;
    }
    Uri data = intent.getData();
    String scheme = data.getScheme();
    String url = data.toString();
    String hash = data.getQueryParameter("hash");
    if (!"tgb".equals(scheme) || !url.toLowerCase().startsWith("tgb://share_game_score") || TextUtils.isEmpty(hash))
    {
        finish();
        return;
    }

    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("botshare", Activity.MODE_PRIVATE);
    String message = sharedPreferences.getString(hash + "_m", null);
    if (TextUtils.isEmpty(message))
    {
        finish();
        return;
    }
    SerializedData serializedData = new SerializedData(Utilities.hexToBytes(message));
    TLRPC.Message mess = TLRPC.Message.TLdeserialize(serializedData, serializedData.readInt32(false), false);
    mess.readAttachPath(serializedData, 0);
    serializedData.cleanup();
    if (mess == null)
    {
        finish();
        return;
    }
    String link = sharedPreferences.getString(hash + "_link", null);
    MessageObject messageObject = new MessageObject(UserConfig.selectedAccount, mess, false);
    messageObject.messageOwner.with_my_score = true;

    try
    {
        visibleDialog = ShareAlert.createShareAlert(this, messageObject, null, false, link, false);
        visibleDialog.setCanceledOnTouchOutside(true);
        visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener()
        {
            @Override
            public void onDismiss(DialogInterface dialog)
            {
                if (!isFinishing())
                {
                    finish();
                }
                visibleDialog = null;
            }
        });
        visibleDialog.show();
    }
    catch (Exception e)
    {
        FileLog.e(e);
        finish();
    }
}
 
Example 14
Source File: DownloadController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDownloadMedia(TLRPC.Message message)
{
    if (!globalAutodownloadEnabled)
    {
        return false;
    }
    int type;
    if (MessageObject.isPhoto(message))
    {
        type = AUTODOWNLOAD_MASK_PHOTO;
    }
    else if (MessageObject.isVoiceMessage(message))
    {
        type = AUTODOWNLOAD_MASK_AUDIO;
    }
    else if (MessageObject.isRoundVideoMessage(message))
    {
        type = AUTODOWNLOAD_MASK_VIDEOMESSAGE;
    }
    else if (MessageObject.isVideoMessage(message))
    {
        type = AUTODOWNLOAD_MASK_VIDEO;
    }
    else if (MessageObject.isMusicMessage(message))
    {
        type = AUTODOWNLOAD_MASK_MUSIC;
    }
    else if (MessageObject.isGifMessage(message))
    {
        type = AUTODOWNLOAD_MASK_GIF;
    }
    else
    {
        type = AUTODOWNLOAD_MASK_DOCUMENT;
    }
    int mask;
    int index;
    int maxSize;
    TLRPC.Peer peer = message.to_id;
    if (peer != null)
    {
        if (peer.user_id != 0)
        {
            if (ContactsController.getInstance(currentAccount).contactsDict.containsKey(peer.user_id))
            {
                index = 0;
            }
            else
            {
                index = 1;
            }
        }
        else if (peer.chat_id != 0)
        {
            index = 2;
        }
        else
        {
            if (MessageObject.isMegagroup(message))
            {
                index = 2;
            }
            else
            {
                index = 3;
            }
        }
    }
    else
    {
        index = 1;
    }
    if (ConnectionsManager.isConnectedToWiFi())
    {
        mask = wifiDownloadMask[index];
        maxSize = wifiMaxFileSize[maskToIndex(type)];
    }
    else if (ConnectionsManager.isRoaming())
    {
        mask = roamingDownloadMask[index];
        maxSize = roamingMaxFileSize[maskToIndex(type)];
    }
    else
    {
        mask = mobileDataDownloadMask[index];
        maxSize = mobileMaxFileSize[maskToIndex(type)];
    }
    return (type == AUTODOWNLOAD_MASK_PHOTO || MessageObject.getMessageSize(message) <= maxSize) && (mask & type) != 0;
}
 
Example 15
Source File: ShareActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ApplicationLoader.postInitApplication();
    AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setTheme(R.style.Theme_TMessages_Transparent);
    super.onCreate(savedInstanceState);
    setContentView(new View(this), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    Intent intent = getIntent();
    if (intent == null || !Intent.ACTION_VIEW.equals(intent.getAction()) || intent.getData() == null) {
        finish();
        return;
    }
    Uri data = intent.getData();
    String scheme = data.getScheme();
    String url = data.toString();
    String hash = data.getQueryParameter("hash");
    if (!"tgb".equals(scheme) || !url.toLowerCase().startsWith("tgb://share_game_score") || TextUtils.isEmpty(hash)) {
        finish();
        return;
    }

    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("botshare", Activity.MODE_PRIVATE);
    String message = sharedPreferences.getString(hash + "_m", null);
    if (TextUtils.isEmpty(message)) {
        finish();
        return;
    }
    SerializedData serializedData = new SerializedData(Utilities.hexToBytes(message));
    TLRPC.Message mess = TLRPC.Message.TLdeserialize(serializedData, serializedData.readInt32(false), false);
    mess.readAttachPath(serializedData, 0);
    serializedData.cleanup();
    if (mess == null) {
        finish();
        return;
    }
    String link = sharedPreferences.getString(hash + "_link", null);
    MessageObject messageObject = new MessageObject(UserConfig.selectedAccount, mess, false);
    messageObject.messageOwner.with_my_score = true;

    try {
        visibleDialog = ShareAlert.createShareAlert(this, messageObject, null, false, link, false);
        visibleDialog.setCanceledOnTouchOutside(true);
        visibleDialog.setOnDismissListener(dialog -> {
            if (!isFinishing()) {
                finish();
            }
            visibleDialog = null;
        });
        visibleDialog.show();
    } catch (Exception e) {
        FileLog.e(e);
        finish();
    }
}
 
Example 16
Source File: FragmentContextView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void checkLocationString()
{
    if (!(fragment instanceof ChatActivity) || titleTextView == null)
    {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    long dialogId = chatActivity.getDialogId();
    int currentAccount = chatActivity.getCurrentAccount();
    ArrayList<TLRPC.Message> messages = LocationController.getInstance(currentAccount).locationsCache.get(dialogId);
    if (!firstLocationsLoaded)
    {
        LocationController.getInstance(currentAccount).loadLiveLocations(dialogId);
        firstLocationsLoaded = true;
    }

    int locationSharingCount = 0;
    TLRPC.User notYouUser = null;
    if (messages != null)
    {
        int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
        int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (int a = 0; a < messages.size(); a++)
        {
            TLRPC.Message message = messages.get(a);
            if (message.media == null)
            {
                continue;
            }
            if (message.date + message.media.period > date)
            {
                if (notYouUser == null && message.from_id != currentUserId)
                {
                    notYouUser = MessagesController.getInstance(currentAccount).getUser(message.from_id);
                }
                locationSharingCount++;
            }
        }
    }
    if (lastLocationSharingCount == locationSharingCount)
    {
        return;
    }
    lastLocationSharingCount = locationSharingCount;

    String liveLocation = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
    String fullString;
    if (locationSharingCount == 0)
    {
        fullString = liveLocation;
    }
    else
    {
        int otherSharingCount = locationSharingCount - 1;
        if (LocationController.getInstance(currentAccount).isSharingLocation(dialogId))
        {
            if (otherSharingCount != 0)
            {
                if (otherSharingCount == 1 && notYouUser != null)
                {
                    fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.formatString("SharingYouAndOtherName", R.string.SharingYouAndOtherName, UserObject.getFirstName(notYouUser)));
                }
                else
                {
                    fullString = String.format("%1$s - %2$s %3$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName), LocaleController.formatPluralString("AndOther", otherSharingCount));
                }
            }
            else
            {
                fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
            }
        }
        else
        {
            if (otherSharingCount != 0)
            {
                fullString = String.format("%1$s - %2$s %3$s", liveLocation, UserObject.getFirstName(notYouUser), LocaleController.formatPluralString("AndOther", otherSharingCount));
            }
            else
            {
                fullString = String.format("%1$s - %2$s", liveLocation, UserObject.getFirstName(notYouUser));
            }
        }
    }
    if (lastString != null && fullString.equals(lastString))
    {
        return;
    }
    lastString = fullString;
    int start = fullString.indexOf(liveLocation);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
    titleTextView.setEllipsize(TextUtils.TruncateAt.END);
    if (start >= 0)
    {
        TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_inappPlayerPerformer));
        stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
    titleTextView.setText(stringBuilder);
}
 
Example 17
Source File: DownloadController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDownloadMedia(TLRPC.Message message)
{
    if (!globalAutodownloadEnabled)
    {
        return false;
    }
    int type;
    if (MessageObject.isPhoto(message))
    {
        type = AUTODOWNLOAD_MASK_PHOTO;
    }
    else if (MessageObject.isVoiceMessage(message))
    {
        type = AUTODOWNLOAD_MASK_AUDIO;
    }
    else if (MessageObject.isRoundVideoMessage(message))
    {
        type = AUTODOWNLOAD_MASK_VIDEOMESSAGE;
    }
    else if (MessageObject.isVideoMessage(message))
    {
        type = AUTODOWNLOAD_MASK_VIDEO;
    }
    else if (MessageObject.isMusicMessage(message))
    {
        type = AUTODOWNLOAD_MASK_MUSIC;
    }
    else if (MessageObject.isGifMessage(message))
    {
        type = AUTODOWNLOAD_MASK_GIF;
    }
    else
    {
        type = AUTODOWNLOAD_MASK_DOCUMENT;
    }
    int mask;
    int index;
    int maxSize;
    TLRPC.Peer peer = message.to_id;
    if (peer != null)
    {
        if (peer.user_id != 0)
        {
            if (ContactsController.getInstance(currentAccount).contactsDict.containsKey(peer.user_id))
            {
                index = 0;
            }
            else
            {
                index = 1;
            }
        }
        else if (peer.chat_id != 0)
        {
            index = 2;
        }
        else
        {
            if (MessageObject.isMegagroup(message))
            {
                index = 2;
            }
            else
            {
                index = 3;
            }
        }
    }
    else
    {
        index = 1;
    }
    if (ConnectionsManager.isConnectedToWiFi())
    {
        mask = wifiDownloadMask[index];
        maxSize = wifiMaxFileSize[maskToIndex(type)];
    }
    else if (ConnectionsManager.isRoaming())
    {
        mask = roamingDownloadMask[index];
        maxSize = roamingMaxFileSize[maskToIndex(type)];
    }
    else
    {
        mask = mobileDataDownloadMask[index];
        maxSize = mobileMaxFileSize[maskToIndex(type)];
    }
    return (type == AUTODOWNLOAD_MASK_PHOTO || MessageObject.getMessageSize(message) <= maxSize) && (mask & type) != 0;
}
 
Example 18
Source File: FragmentContextView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void checkLocationString() {
    if (!(fragment instanceof ChatActivity) || titleTextView == null) {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    long dialogId = chatActivity.getDialogId();
    int currentAccount = chatActivity.getCurrentAccount();
    ArrayList<TLRPC.Message> messages = LocationController.getInstance(currentAccount).locationsCache.get(dialogId);
    if (!firstLocationsLoaded) {
        LocationController.getInstance(currentAccount).loadLiveLocations(dialogId);
        firstLocationsLoaded = true;
    }

    int locationSharingCount = 0;
    TLRPC.User notYouUser = null;
    if (messages != null) {
        int currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
        int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (int a = 0; a < messages.size(); a++) {
            TLRPC.Message message = messages.get(a);
            if (message.media == null) {
                continue;
            }
            if (message.date + message.media.period > date) {
                if (notYouUser == null && message.from_id != currentUserId) {
                    notYouUser = MessagesController.getInstance(currentAccount).getUser(message.from_id);
                }
                locationSharingCount++;
            }
        }
    }
    if (lastLocationSharingCount == locationSharingCount) {
        return;
    }
    lastLocationSharingCount = locationSharingCount;

    String liveLocation = LocaleController.getString("LiveLocationContext", R.string.LiveLocationContext);
    String fullString;
    if (locationSharingCount == 0) {
        fullString = liveLocation;
    } else {
        int otherSharingCount = locationSharingCount - 1;
        if (LocationController.getInstance(currentAccount).isSharingLocation(dialogId)) {
            if (otherSharingCount != 0) {
                if (otherSharingCount == 1 && notYouUser != null) {
                    fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.formatString("SharingYouAndOtherName", R.string.SharingYouAndOtherName, UserObject.getFirstName(notYouUser)));
                } else {
                    fullString = String.format("%1$s - %2$s %3$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName), LocaleController.formatPluralString("AndOther", otherSharingCount));
                }
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
            }
        } else {
            if (otherSharingCount != 0) {
                fullString = String.format("%1$s - %2$s %3$s", liveLocation, UserObject.getFirstName(notYouUser), LocaleController.formatPluralString("AndOther", otherSharingCount));
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, UserObject.getFirstName(notYouUser));
            }
        }
    }
    if (fullString.equals(lastString)) {
        return;
    }
    lastString = fullString;
    int start = fullString.indexOf(liveLocation);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
    titleTextView.setEllipsize(TextUtils.TruncateAt.END);
    if (start >= 0) {
        TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, Theme.getColor(Theme.key_inappPlayerPerformer));
        stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
    titleTextView.setText(stringBuilder);
}
 
Example 19
Source File: ThemePreviewMessagesCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public ThemePreviewMessagesCell(Context context, ActionBarLayout layout, int type) {
    super(context);

    parentLayout = layout;

    setWillNotDraw(false);
    setOrientation(LinearLayout.VERTICAL);
    setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11));

    shadowDrawable = Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow);

    int date = (int) (System.currentTimeMillis() / 1000) - 60 * 60;
    TLRPC.Message message = new TLRPC.TL_message();
    if (type == 0) {
        message.message = LocaleController.getString("FontSizePreviewReply", R.string.FontSizePreviewReply);
    } else {
        message.message = LocaleController.getString("NewThemePreviewReply", R.string.NewThemePreviewReply);
    }
    message.date = date + 60;
    message.dialog_id = 1;
    message.flags = 259;
    message.from_id = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
    message.id = 1;
    message.media = new TLRPC.TL_messageMediaEmpty();
    message.out = true;
    message.to_id = new TLRPC.TL_peerUser();
    message.to_id.user_id = 0;
    MessageObject replyMessageObject = new MessageObject(UserConfig.selectedAccount, message, true);

    message = new TLRPC.TL_message();
    if (type == 0) {
        message.message = LocaleController.getString("FontSizePreviewLine2", R.string.FontSizePreviewLine2);
    } else {
        String text = LocaleController.getString("NewThemePreviewLine3", R.string.NewThemePreviewLine3);
        StringBuilder builder = new StringBuilder(text);
        int index1 = text.indexOf('*');
        int index2 = text.lastIndexOf('*');
        if (index1 != -1 && index2 != -1) {
            builder.replace(index2, index2 + 1, "");
            builder.replace(index1, index1 + 1, "");
            TLRPC.TL_messageEntityTextUrl entityUrl = new TLRPC.TL_messageEntityTextUrl();
            entityUrl.offset = index1;
            entityUrl.length = index2 - index1 - 1;
            entityUrl.url = "https://telegram.org";
            message.entities.add(entityUrl);
        }
        message.message = builder.toString();
    }
    message.date = date + 960;
    message.dialog_id = 1;
    message.flags = 259;
    message.from_id = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
    message.id = 1;
    message.media = new TLRPC.TL_messageMediaEmpty();
    message.out = true;
    message.to_id = new TLRPC.TL_peerUser();
    message.to_id.user_id = 0;
    MessageObject message1 = new MessageObject(UserConfig.selectedAccount, message, true);
    message1.resetLayout();
    message1.eventId = 1;

    message = new TLRPC.TL_message();
    if (type == 0) {
        message.message = LocaleController.getString("FontSizePreviewLine1", R.string.FontSizePreviewLine1);
    } else {
        message.message = LocaleController.getString("NewThemePreviewLine1", R.string.NewThemePreviewLine1);
    }
    message.date = date + 60;
    message.dialog_id = 1;
    message.flags = 257 + 8;
    message.from_id = 0;
    message.id = 1;
    message.reply_to_msg_id = 5;
    message.media = new TLRPC.TL_messageMediaEmpty();
    message.out = false;
    message.to_id = new TLRPC.TL_peerUser();
    message.to_id.user_id = UserConfig.getInstance(UserConfig.selectedAccount).getClientUserId();
    MessageObject message2 = new MessageObject(UserConfig.selectedAccount, message, true);
    if (type == 0) {
        message2.customReplyName = LocaleController.getString("FontSizePreviewName", R.string.FontSizePreviewName);
    } else {
        message2.customReplyName = LocaleController.getString("NewThemePreviewName", R.string.NewThemePreviewName);
    }
    message2.eventId = 1;
    message2.resetLayout();
    message2.replyMessageObject = replyMessageObject;

    for (int a = 0; a < cells.length; a++) {
        cells[a] = new ChatMessageCell(context);
        cells[a].setDelegate(new ChatMessageCell.ChatMessageCellDelegate() {

        });
        cells[a].isChat = false;
        cells[a].setFullyDraw(true);
        cells[a].setMessageObject(a == 0 ? message2 : message1, null, false, false);
        addView(cells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }
}
 
Example 20
Source File: SecretChatHelper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isSecretInvisibleMessage(TLRPC.Message message) {
    return message.action instanceof TLRPC.TL_messageEncryptedAction && !(message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL);
}