Notifications: add new virtual type for subscriptions

main
Alibek Omarov 4 years ago
parent 8982f7af28
commit 0bdad9ad7a
  1. 4
      app/src/husky/res/values/strings.xml
  2. 39
      app/src/main/java/com/keylesspalace/tusky/components/notifications/NotificationHelper.java
  3. 11
      app/src/main/java/com/keylesspalace/tusky/components/preference/NotificationPreferencesFragment.kt
  4. 1
      app/src/main/java/com/keylesspalace/tusky/db/AccountEntity.kt
  5. 9
      app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java
  6. 3
      app/src/main/java/com/keylesspalace/tusky/di/AppModule.kt
  7. 1
      app/src/main/java/com/keylesspalace/tusky/settings/SettingsConstants.kt

@ -34,6 +34,9 @@
<string name="notification_chat_message_format">%s sent you a message</string>
<string name="notification_chat_message_name">Chat Messages</string>
<string name="notification_chat_message_description">Notifications about new chat messages</string>
<string name="notification_subscription_format">%s published a new post</string>
<string name="notification_subscription_name">Subscriptions</string>
<string name="notification_subscription_description">Notifications when somebody you\'re subscribed to published a new post</string>
<string name="pref_title_other">Other</string>
<string name="pref_title_privacy">Privacy</string>
@ -44,6 +47,7 @@
<string name="pref_title_default_formatting">Default formatting syntax(if supported by instance)</string>
<string name="pref_title_notification_filter_emoji">my posts are reacted with emojis</string>
<string name="pref_title_notification_filter_chat_messages">received a chat message</string>
<string name="pref_title_notification_filter_subscriptions">somebody I\'m subscribed to published a new post</string>
<string name="pref_title_hide_muted_users">Hide muted users</string>
<string name="pref_title_enable_big_emojis">Enable bigger custom emojis</string>
<string name="pref_title_enable_experimental_stickers">Enable experimental Pleroma-FE stickers(if available)</string>

@ -128,7 +128,7 @@ public class NotificationHelper {
public static final String CHANNEL_POLL = "CHANNEL_POLL";
public static final String CHANNEL_EMOJI_REACTION = "CHANNEL_EMOJI_REACTION";
public static final String CHANNEL_CHAT_MESSAGES = "CHANNEL_CHAT_MESSAGES";
public static final String CHANNEL_SUBSCRIPTIONS = "CHANNEL_SUBSCRIPTIONS";
/**
* WorkManager Tag
@ -400,7 +400,8 @@ public class NotificationHelper {
CHANNEL_FAVOURITE + account.getIdentifier(),
CHANNEL_POLL + account.getIdentifier(),
CHANNEL_EMOJI_REACTION + account.getIdentifier(),
CHANNEL_CHAT_MESSAGES + account.getIdentifier()
CHANNEL_CHAT_MESSAGES + account.getIdentifier(),
CHANNEL_SUBSCRIPTIONS + account.getIdentifier()
};
int[] channelNames = {
R.string.notification_mention_name,
@ -411,6 +412,7 @@ public class NotificationHelper {
R.string.notification_poll_name,
R.string.notification_emoji_name,
R.string.notification_chat_message_name,
R.string.notification_subscription_name
};
int[] channelDescriptions = {
R.string.notification_mention_descriptions,
@ -421,9 +423,10 @@ public class NotificationHelper {
R.string.notification_poll_description,
R.string.notification_emoji_description,
R.string.notification_chat_message_description,
R.string.notification_subscription_description
};
List<NotificationChannel> channels = new ArrayList<>(6);
List<NotificationChannel> channels = new ArrayList<>(9);
NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(), account.getFullName());
@ -565,7 +568,9 @@ public class NotificationHelper {
switch (notification.getType()) {
case MENTION:
return account.getNotificationsMentioned();
if(isMentionedInNotification(notification, account.getAccountId()))
return account.getNotificationsMentioned();
else return account.getNotificationsSubscriptions();
case FOLLOW:
return account.getNotificationsFollowed();
case FOLLOW_REQUEST:
@ -589,7 +594,9 @@ public class NotificationHelper {
private static String getChannelId(AccountEntity account, Notification notification) {
switch (notification.getType()) {
case MENTION:
return CHANNEL_MENTION + account.getIdentifier();
if(isMentionedInNotification(notification, account.getAccountId()))
return CHANNEL_MENTION + account.getIdentifier();
else return CHANNEL_SUBSCRIPTIONS + account.getIdentifier();
case FOLLOW:
return CHANNEL_FOLLOW + account.getIdentifier();
case FOLLOW_REQUEST:
@ -656,14 +663,32 @@ public class NotificationHelper {
return null;
}
private static boolean isMentionedInNotification(Notification not, String id) {
if(not.getStatus() != null) {
for(int i = 0; i < not.getStatus().getMentions().length; i++) {
if(not.getStatus().getMentions()[i].getId().equals(id)) {
return true;
}
}
return false;
}
return true; // actually should never happen, true just in case someone breaks API again
}
@Nullable
private static String titleForType(Context context, Notification notification, AccountEntity account) {
String accountName = StringUtils.unicodeWrap(notification.getAccount().getName());
switch (notification.getType()) {
case MENTION:
return String.format(context.getString(R.string.notification_mention_format),
accountName);
if(isMentionedInNotification(notification, account.getAccountId())) {
return String.format(context.getString(R.string.notification_mention_format),
accountName);
} else {
return String.format(context.getString(R.string.notification_subscription_format), accountName);
}
case FOLLOW:
return String.format(context.getString(R.string.notification_follow_format),
accountName);

@ -133,6 +133,17 @@ class NotificationPreferencesFragment : PreferenceFragmentCompat(), Injectable {
true
}
}
switchPreference {
setTitle(R.string.pref_title_notification_filter_subscriptions)
key = PrefKeys.NOTIFICATION_FILTER_SUBSCRIPTIONS
isIconSpaceReserved = false
isChecked = activeAccount.notificationsSubscriptions
setOnPreferenceChangeListener { _, newValue ->
updateAccount { it.notificationsSubscriptions = newValue as Boolean }
true
}
}
}
preferenceCategory(R.string.pref_title_notification_alerts) { category ->

@ -46,6 +46,7 @@ data class AccountEntity(@field:PrimaryKey(autoGenerate = true) var id: Long,
var notificationsPolls: Boolean = true,
var notificationsEmojiReactions: Boolean = true,
var notificationsChatMessages: Boolean = true,
var notificationsSubscriptions: Boolean = true,
var notificationSound: Boolean = true,
var notificationVibration: Boolean = true,
var notificationLight: Boolean = true,

@ -29,7 +29,7 @@ import androidx.annotation.NonNull;
*/
@Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
TimelineAccountEntity.class, ConversationEntity.class, ChatEntity.class, ChatMessageEntity.class}, version = 25)
TimelineAccountEntity.class, ConversationEntity.class, ChatEntity.class, ChatMessageEntity.class}, version = 26)
public abstract class AppDatabase extends RoomDatabase {
public abstract TootDao tootDao();
@ -376,4 +376,11 @@ public abstract class AppDatabase extends RoomDatabase {
database.execSQL("ALTER TABLE `TimelineStatusEntity` ADD COLUMN `pleroma` TEXT");
}
};
public static final Migration MIGRATION_25_26 = new Migration(25, 26) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE `AccountEntity` ADD COLUMN `notificationsSubscriptions` INTEGER NOT NULL DEFAULT 1");
}
};
}

@ -80,7 +80,8 @@ class AppModule {
AppDatabase.MIGRATION_13_14, AppDatabase.MIGRATION_14_15, AppDatabase.MIGRATION_15_16,
AppDatabase.MIGRATION_16_17, AppDatabase.MIGRATION_17_18, AppDatabase.MIGRATION_18_19,
AppDatabase.MIGRATION_19_20, AppDatabase.MIGRATION_20_21, AppDatabase.MIGRATION_21_22,
AppDatabase.MIGRATION_22_23, AppDatabase.MIGRATION_23_24, AppDatabase.MIGRATION_24_25)
AppDatabase.MIGRATION_22_23, AppDatabase.MIGRATION_23_24, AppDatabase.MIGRATION_24_25,
AppDatabase.MIGRATION_25_26)
.build()
}

@ -61,6 +61,7 @@ object PrefKeys {
const val NOTIFICATION_FILTER_REBLOGS = "notificationFilterReblogs"
const val NOTIFICATION_FILTER_FOLLOW_REQUESTS = "notificationFilterFollowRequests"
const val NOTIFICATION_FILTER_EMOJI_REACTIONS = "notificationFilterEmojis"
const val NOTIFICATION_FILTER_SUBSCRIPTIONS = "notificationFilterSubscriptions"
const val NOTIFICATIONS_FILTER_FOLLOWS = "notificationFilterFollows"
const val TAB_FILTER_HOME_REPLIES = "tabFilterHomeReplies"

Loading…
Cancel
Save