Skip to content

Commit 63eca02

Browse files
committed
UPDATE: No longer sort direct messages before group conversations.
Also revive notification with API reviveNotification() instead of recastNotification(). These tweaks avoid explicit "group" and "sort key" which prevents auto-grouping in app-specific mirror.
1 parent 2d4be5f commit 63eca02

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/main/java/com/oasisfeng/nevo/decorators/wechat/WeChatDecorator.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Arrays;
4646
import java.util.Collections;
4747
import java.util.List;
48+
import java.util.Objects;
4849
import java.util.Optional;
4950

5051
import androidx.annotation.ColorInt;
@@ -71,7 +72,6 @@ public class WeChatDecorator extends NevoDecoratorService {
7172

7273
public static final String WECHAT_PACKAGE = "com.tencent.mm";
7374
private static final int MAX_NUM_ARCHIVED = 20;
74-
private static final long GROUP_CHAT_SORT_KEY_SHIFT = 24 * 60 * 60 * 1000L; // Sort group chat like one day older message.
7575
private static final String CHANNEL_MESSAGE = "message_channel_new_id"; // Channel ID used by WeChat for all message notifications
7676
private static final String OLD_CHANNEL_MESSAGE = "message"; // old name for migration
7777
private static final String CHANNEL_MISC = "reminder_channel_id"; // Channel ID used by WeChat for misc. notifications
@@ -83,7 +83,6 @@ public class WeChatDecorator extends NevoDecoratorService {
8383
private static final @ColorInt int LIGHT_COLOR = 0xFF00FF00;
8484
static final String ACTION_SETTINGS_CHANGED = "SETTINGS_CHANGED";
8585
static final String ACTION_DEBUG_NOTIFICATION = "DEBUG";
86-
private static final String KEY_SILENT_REVIVAL = "nevo.wechat.revival";
8786

8887
@Override public void apply(final MutableStatusBarNotification evolving) {
8988
final MutableNotification n = evolving.getNotification();
@@ -131,12 +130,7 @@ public class WeChatDecorator extends NevoDecoratorService {
131130

132131
extras.putBoolean(Notification.EXTRA_SHOW_WHEN, true);
133132
if (mPreferences.getBoolean(mPrefKeyWear, false)) n.flags &= ~ Notification.FLAG_LOCAL_ONLY;
134-
n.setSortKey(String.valueOf(Long.MAX_VALUE - n.when + (is_group_chat ? GROUP_CHAT_SORT_KEY_SHIFT : 0))); // Place group chat below other messages
135133
if (SDK_INT >= O) {
136-
if (extras.containsKey(KEY_SILENT_REVIVAL)) {
137-
n.setGroup("nevo.group.auto"); // Special group name to let Nevolution auto-group it as if not yet grouped. (To be standardized in SDK)
138-
n.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY); // This trick makes notification silent
139-
}
140134
if (is_group_chat && ! CHANNEL_DND.equals(channel_id)) n.setChannelId(CHANNEL_GROUP_CONVERSATION);
141135
else if (channel_id == null) n.setChannelId(CHANNEL_MESSAGE); // WeChat versions targeting O+ have its own channel for message
142136
}
@@ -177,19 +171,12 @@ private boolean isDistinctId(final Notification n, final String pkg) {
177171
Log.d(TAG, "Cancel notification: " + key);
178172
cancelNotification(key); // Will cancel all notifications evolved from this original key, thus trigger the "else" branch below
179173
} else if (reason == REASON_CHANNEL_BANNED) { // In case WeChat deleted our notification channel for group conversation in Insider delivery mode
180-
mHandler.post(() -> reviveNotificationAfterChannelDeletion(key));
174+
mHandler.post(() -> reviveNotification(key));
181175
} else if (SDK_INT < O || reason == REASON_CANCEL) { // Exclude the removal request by us in above case. (Removal-Aware is only supported on Android 8+)
182176
mMessagingBuilder.markRead(key);
183177
}
184178
}
185179

186-
private void reviveNotificationAfterChannelDeletion(final String key) {
187-
Log.d(TAG, ("Revive silently: ") + key);
188-
final Bundle addition = new Bundle();
189-
addition.putBoolean(KEY_SILENT_REVIVAL, true);
190-
recastNotification(key, addition);
191-
}
192-
193180
@Override protected void onConnected() {
194181
if (SDK_INT >= O) {
195182
mWeChatTargetingO = isWeChatTargeting26OrAbove();
@@ -283,7 +270,7 @@ private boolean isWeChatTargeting26OrAbove() {
283270
if (n.tickerText != null) n.extras.putCharSequence(Notification.EXTRA_BIG_TEXT, n.extras.getCharSequence(EXTRA_TEXT) + "\n" + n.tickerText);
284271
n.extras.putString(Notification.EXTRA_TEMPLATE, Notification.BigTextStyle.class.getName());
285272
}
286-
final NotificationManager nm = getSystemService(NotificationManager.class);
273+
final NotificationManager nm = Objects.requireNonNull(getSystemService(NotificationManager.class));
287274
nm.createNotificationChannel(new NotificationChannel(n.getChannelId(), "Debug:" + n.getChannelId(), NotificationManager.IMPORTANCE_LOW));
288275
nm.notify(tag, id, n);
289276
} catch (final PackageManager.NameNotFoundException | RuntimeException e) {

0 commit comments

Comments
 (0)