Skip to content

Commit

Permalink
added full shadowban
Browse files Browse the repository at this point in the history
How simple shadowban works:
* someone writes you
* your client pickup these messages 1st
* filter and shadowbanning it
* et voilà

If you run another client with same account somewhere and that another client pickup the messages, they are become cached messages on the TG servers and your db too. Cause your client will sync it. So simple shadowban it's just to have a good conversations and read sometimes when banned folks are wrote in chat w/o unbanning them.

So if you will reload the chat you will see these messahes. It's how "simple shadowban mode" works here.

Now i added a "full shadowban mode". This mode fully filter another folks. What does it mean? it mean no more folks in new messages (simple SB mode) and nore more folks in cached messages (database or tg servers). Full shadowban include also PM ban, so your client will ignore these folks until you unban them (or remove simple shadowban which do not affect the PMs). Once you did it, your client will sync your personal chat and you will see all ignores messages.

So, short:
* simple shadowban for actual group chats and NOT for private cloud chats (the simple ones)
* full shadowban it for total block (group chats and simple cloud chats between 2 folks).
  • Loading branch information
nikitasius committed Mar 18, 2022
1 parent fec0166 commit bab6fe9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class TelegraherSettingsActivity extends BaseFragment implements Notifica

private int chatLabelRow;
private int chatDeleteMarkRow;
private int chatSBFullRow;

private int rowCount = 0;

Expand All @@ -88,6 +89,7 @@ public boolean onFragmentCreate() {

chatLabelRow = rowCount++;
chatDeleteMarkRow = rowCount++;
chatSBFullRow = rowCount++;

NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.telegraherSettingsUpdated);

Expand Down Expand Up @@ -181,6 +183,12 @@ public boolean supportsPredictiveItemAnimations() {
enabled = preferences.getBoolean("EnableChatDeleteMark", true);
editor.putBoolean("EnableChatDeleteMark", !enabled);
editor.commit();
} else if (position == chatSBFullRow) {
SharedPreferences preferences = MessagesController.getTelegraherSettings(currentAccount);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableChatSBFull", false);
editor.putBoolean("EnableChatSBFull", !enabled);
editor.commit();
}
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!enabled);
Expand Down Expand Up @@ -298,7 +306,9 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
} else if (position == profileSBRow) {
checkCell.setTextAndCheck("Show Shadowban", localPreps.getBoolean("EnableProfileSB", true), true);
} else if (position == chatDeleteMarkRow) {
checkCell.setTextAndCheck(String.format("Show `%s`", LocaleController.getString("DeletedMessage", R.string.DeletedMessage)), localPreps.getBoolean("EnableChatDeleteMark", true), true);
checkCell.setTextAndCheck(String.format("Show `%s` mark", LocaleController.getString("DeletedMessage", R.string.DeletedMessage)), localPreps.getBoolean("EnableChatDeleteMark", true), true);
} else if (position == chatSBFullRow) {
checkCell.setTextAndCheck("Full ShadowBan \uD83D\uDE48", localPreps.getBoolean("EnableChatSBFull", false), true);
}
break;
}
Expand All @@ -316,7 +326,7 @@ public int getItemViewType(int position) {
} else if (
position == voiceHDRow || position == voiceBadmanRow || position == voipHDRow
|| position == profileUIDRow || position == profileDCIDRow || position == profileSBRow
|| position == chatDeleteMarkRow
|| position == chatDeleteMarkRow || position == chatSBFullRow
) {
return 1;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12151,8 +12151,6 @@ public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, ArrayList<TLR
} else {
message = ((TLRPC.TL_updateNewChannelMessage) baseUpdate).message;

if (SharedConfig.isShadowBanned(message)) continue;

if (BuildVars.LOGS_ENABLED) {
FileLog.d(baseUpdate + " channelId = " + message.peer_id.channel_id);
}
Expand All @@ -12163,6 +12161,8 @@ public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, ArrayList<TLR
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}
if (SharedConfig.isShadowBanned(message)) continue;

TLRPC.Chat chat = null;
long chatId = 0;
long userId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7178,6 +7178,7 @@ public Runnable getMessagesInternal(long dialogId, long mergeDialogId, int count
if (message.ttl == 0) {
message.ttl = cursor.intValue(6);
}
if (getMessagesController().getTelegraherSettings(currentAccount).getBoolean("EnableChatSBFull", false) && SharedConfig.isShadowBanned(message)) continue;
res.messages.add(message);

addUsersAndChatsFromMessage(message, usersToLoad, chatsToLoad);
Expand Down Expand Up @@ -7606,6 +7607,7 @@ public Runnable getMessagesInternal(long dialogId, long mergeDialogId, int count
} else if ((flags & 2) != 0) {
message.stickerVerified = 2;
}
if (getMessagesController().getTelegraherSettings(currentAccount).getBoolean("EnableChatSBFull", false) && SharedConfig.isShadowBanned(message)) continue;
res.messages.add(message);

addUsersAndChatsFromMessage(message, usersToLoad, chatsToLoad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ public static HashSet<Long> getShadowBannedHS() {
return shadowBannedHS;
}

public static boolean isShadowBanned(Long id) {
// System.out.printf("isShadowBanned `%s`%n", "the id");
if (shadowBannedHS == null) {
shadowBannedHS = new HashSet<>();
return false;
}
return isShadowBanned(id);
}

public static boolean isShadowBanned(TLRPC.Message m) {
// System.out.printf("isShadowBanned `%s`%n", "the message");
if (shadowBannedHS == null) {
Expand All @@ -481,6 +490,15 @@ public static boolean isShadowBanned(TLRPC.Message m) {
return isShadowBanned(m.from_id.channel_id) || isShadowBanned(m.from_id.chat_id) || isShadowBanned(m.from_id.user_id);
}

public static boolean isShadowBanned(TLRPC.Updates m) {
// System.out.printf("isShadowBanned `%s`%n", "the Updates");
if (shadowBannedHS == null) {
shadowBannedHS = new HashSet<>();
return false;
}
return m instanceof TLRPC.TL_updateShortChatMessage ? isShadowBanned(m.from_id) : isShadowBanned(m.user_id);
}

public static boolean isShadowBanned(long id) {
// System.out.printf("isShadowBanned `%d`%n", id);
if (shadowBannedHS == null) {
Expand Down

0 comments on commit bab6fe9

Please sign in to comment.