Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages Filter #516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ public static Object fillMessageOptions (MessagesController m, TGMessage msg, @N
boolean isSent = !msg.isNotSent();
Object tag = null;

final boolean isHiddenByMessagesFilter = msg.isHiddenByMessagesFilter();

if (!isMore && (isHiddenByMessagesFilter /*|| BuildConfig.DEBUG*/)) {
ids.append(R.id.btn_messageChangeMessageFilterVisibility);
strings.append(Lang.getString(R.string.MessagesFilterShowMessage));
icons.append(R.drawable.baseline_visibility_24);
}

// Promotion

if (msg.isSponsoredMessage()) {
Expand Down Expand Up @@ -1502,7 +1510,7 @@ public boolean onTouchEvent (MotionEvent e) {
} else {
preventLongPress();
}
if (c.inSelectMode() || !msg.onTouchEvent(this, e)) {
if (c.inSelectMode() || msg.isHiddenByMessagesFilter() || !msg.onTouchEvent(this, e)) {
flags |= FLAG_CAUGHT_CLICK;
} else {
flags |= FLAG_CAUGHT_MESSAGE_TOUCH;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is a part of Telegram X
* Copyright © 2014 ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* File created on 17/11/2023
*/
package org.thunderdog.challegram.component.chat.filter;

import android.net.Uri;

import org.drinkless.tdlib.TdApi;
import org.thunderdog.challegram.data.TD;

import java.util.HashSet;
import java.util.Set;

import me.vkryl.td.ChatId;
import me.vkryl.td.Td;

class Content {
public final Set<String> mentionsUsername = new HashSet<>();
public final Set<Long> mentionsId = new HashSet<>();
public final Set<String> internalLinks = new HashSet<>();
public final Set<String> externalLinks = new HashSet<>();

public Content () {}

public void add (TdApi.MessageContent content) {
final TdApi.FormattedText textOrCaption = Td.textOrCaption(content);
if (textOrCaption == null || textOrCaption.text == null) return;

if (textOrCaption.entities != null) {
for (TdApi.TextEntity entity : textOrCaption.entities) {
switch (entity.type.getConstructor()) {
case TdApi.TextEntityTypeMention.CONSTRUCTOR: {
mentionsUsername.add(Td.substring(textOrCaption.text, entity));
break;
}
case TdApi.TextEntityTypeMentionName.CONSTRUCTOR: {
mentionsId.add(ChatId.fromUserId(((TdApi.TextEntityTypeMentionName) entity.type).userId));
break;
}
case TdApi.TextEntityTypeUrl.CONSTRUCTOR: {
addLink(Td.substring(textOrCaption.text, entity));
break;
}
case TdApi.TextEntityTypeTextUrl.CONSTRUCTOR: {
addLink(((TdApi.TextEntityTypeTextUrl) entity.type).url);
break;
}
default: {
break;
}
}
}
}
}

private void addLink (String link) {
if (TD.isTelegramOwnedHost(Uri.parse(link), false)) {
internalLinks.add(link);
} else {
externalLinks.add(link);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is a part of Telegram X
* Copyright © 2014 ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* File created on 16/11/2023
*/
package org.thunderdog.challegram.component.chat.filter;

import androidx.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.SOURCE)
@IntDef({
FilterReason.PENDING,
FilterReason.NONE,
FilterReason.BLOCKED_SENDER,
FilterReason.BLOCKED_SENDER_MENTION,
FilterReason.CONTAINS_INTERNAL_LINK,
FilterReason.CONTAINS_EXTERNAL_LINK
})
public @interface FilterReason {
int
PENDING = -1,
NONE = 0,
BLOCKED_SENDER = 1,
BLOCKED_SENDER_MENTION = 2,
CONTAINS_INTERNAL_LINK = 3,
CONTAINS_EXTERNAL_LINK = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is a part of Telegram X
* Copyright © 2014 ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* File created on 16/11/2023
*/
package org.thunderdog.challegram.component.chat.filter;

import androidx.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.SOURCE)
@IntDef({
FilterState.VISIBLE,
FilterState.HIDDEN,
FilterState.LAST_STATE_VISIBLE,
FilterState.LAST_STATE_HIDDEN
})
public @interface FilterState {
int
VISIBLE = 0,
HIDDEN = 1,
LAST_STATE_VISIBLE = 2,
LAST_STATE_HIDDEN = 3;
}
Loading