Skip to content

Commit

Permalink
feat: Message Filters
Browse files Browse the repository at this point in the history
THanks to @ayugram1338 @AyuGram
  • Loading branch information
omg-xtao committed May 19, 2024
1 parent d43d2b6 commit a0a2dbb
Show file tree
Hide file tree
Showing 12 changed files with 867 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import cn.hutool.core.util.StrUtil;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.helpers.AyuFilter;

public class DownloadController extends BaseController implements NotificationCenter.NotificationCenterDelegate {

Expand Down Expand Up @@ -646,6 +647,16 @@ public int canDownloadMedia(TLRPC.Message message) {
if (message == null || message.media instanceof TLRPC.TL_messageMediaStory) {
return canPreloadStories() ? 2 : 0;
}

// --- AyuGram hook

var isFiltered = AyuFilter.isFiltered(new MessageObject(currentAccount, message, false, false), null);
if (isFiltered) {
return 0;
}

// --- AyuGram hook

int type;
boolean isVideo;
if ((isVideo = MessageObject.isVideoMessage(message)) || MessageObject.isGifMessage(message) || MessageObject.isRoundVideoMessage(message) || MessageObject.isGameMessage(message)) {
Expand Down
19 changes: 18 additions & 1 deletion TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
import tw.nekomimi.nekogram.DialogConfig;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.helpers.AyuFilter;
import tw.nekomimi.nekogram.helpers.remote.EmojiHelper;
import tw.nekomimi.nekogram.helpers.remote.PagePreviewRulesHelper;
import tw.nekomimi.nekogram.parts.MessageTransKt;
Expand Down Expand Up @@ -33846,6 +33847,8 @@ public boolean canDrawOutboundsContent() {
});
} else if (viewType == 4) {
view = new ChatLoadingCell(mContext, contentView, themeDelegate);
} else if (viewType == -1000) {
view = new View(mContext);
}
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
return new RecyclerListView.Holder(view);
Expand Down Expand Up @@ -34328,7 +34331,21 @@ public int getItemViewType(int position) {
} else {
messages = ChatActivity.this.messages;
}
return messages.get(position - messagesStartRow).contentType;

var msg = messages.get(position - messagesStartRow);

// --- AyuGram hook
if (NaConfig.INSTANCE.getRegexFiltersEnabled().Bool() && (NaConfig.INSTANCE.getRegexFiltersEnableInChats().Bool() || ChatObject.isChannel(currentChat))) {
var group = getGroup(msg.getGroupId());
var msgToCheck = group == null ? msg : group.findPrimaryMessageObject();

if (AyuFilter.isFiltered(msgToCheck, group)) {
return -1000;
}
}
// --- AyuGram hook

return msg.contentType;
} else if (position == botInfoRow) {
return 3;
}
Expand Down
12 changes: 12 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
import tw.nekomimi.nekogram.helpers.ProfileDateHelper;
import tw.nekomimi.nekogram.helpers.SettingsHelper;
import tw.nekomimi.nekogram.helpers.SettingsSearchResult;
import tw.nekomimi.nekogram.settings.RegexFiltersSettingActivity;
import tw.nekomimi.nekogram.transtale.popupwrapper.AutoTranslatePopupWrapper;
import tw.nekomimi.nekogram.ui.BottomBuilder;
import tw.nekomimi.nekogram.InternalUpdater;
Expand Down Expand Up @@ -545,6 +546,7 @@ public void setAlpha(int a) {
private final static int start_secret_chat = 20;
private final static int gallery_menu_save = 21;
private final static int event_log = 102;
private final static int message_filter = 103;
private final static int view_discussion = 22;
private final static int delete_topic = 23;

Expand Down Expand Up @@ -2318,6 +2320,8 @@ public void onItemClick(final int id) {
leaveChatPressed();
} else if (id == event_log) {
presentFragment(new ChannelAdminLogActivity(currentChat));
} else if (id == message_filter){
presentFragment(new RegexFiltersSettingActivity(chatId != 0 ? -chatId : userId));
} else if (id == aliasChannelName) {
setChannelAlias();
} else if (id == delete_topic) {
Expand Down Expand Up @@ -10258,6 +10262,7 @@ private void createActionBarMenu(boolean animated) {
if (isBot || getContactsController().contactsDict.get(userId) == null) {
if (MessagesController.isSupportUser(user)) {
createAutoTranslateItem(userId);
createMessageFilterItem();
if (userBlocked) {
otherItem.addSubItem(block_contact, R.drawable.msg_block, LocaleController.getString("Unblock", R.string.Unblock));
}
Expand All @@ -10267,6 +10272,7 @@ private void createActionBarMenu(boolean animated) {
createAutoDeleteItem(context);
}
createAutoTranslateItem(userId);
createMessageFilterItem();
otherItem.addSubItem(add_shortcut, R.drawable.msg_home, LocaleController.getString("AddShortcut", R.string.AddShortcut));
if (isBot) {
otherItem.addSubItem(share, R.drawable.msg_share, LocaleController.getString("BotShare", R.string.BotShare));
Expand All @@ -10291,6 +10297,7 @@ private void createActionBarMenu(boolean animated) {
createAutoDeleteItem(context);
}
createAutoTranslateItem(userId);
createMessageFilterItem();

if (!TextUtils.isEmpty(user.phone)) {
otherItem.addSubItem(share_contact, R.drawable.msg_share, LocaleController.getString("ShareContact", R.string.ShareContact));
Expand Down Expand Up @@ -10321,6 +10328,7 @@ private void createActionBarMenu(boolean animated) {
createAutoDeleteItem(context);
}
createAutoTranslateItem(-chatId, topicId, !isTopic || chatInfo == null || !chatInfo.participants_hidden || ChatObject.hasAdminRights(chat));
createMessageFilterItem();
if (chat != null && (chat.has_link || (chatInfo != null && chatInfo.linked_chat_id != 0))) {
String text;
if (!chat.megagroup) {
Expand Down Expand Up @@ -10573,6 +10581,10 @@ private void createAutoTranslateItem(long dialogId, long topicId, boolean gap) {
if (gap) otherItem.addColoredGap();
}

private void createMessageFilterItem() {
otherItem.addSubItem(message_filter, R.drawable.hide_title, LocaleController.getString("RegexFilters", R.string.RegexFilters));
}

private void setAutoDeleteHistory(int time, int action) {
long did = getDialogId();
getMessagesController().setDialogHistoryTTL(did, time);
Expand Down
Loading

0 comments on commit a0a2dbb

Please sign in to comment.