forked from mirror/monocles_chat_clean
Optionally allow notifications for replies to my messages (Cheogram)
This commit is contained in:
parent
17ca2ab0a1
commit
d1ce34f304
4 changed files with 25 additions and 4 deletions
|
@ -212,6 +212,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
|||
|
||||
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
|
||||
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
|
||||
|
||||
public static final String ATTRIBUTE_NOTIFY_REPLIES = "notify_replies";
|
||||
public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history";
|
||||
public static final String ATTRIBUTE_FORMERLY_PRIVATE_NON_ANONYMOUS = "formerly_private_non_anonymous";
|
||||
public static final String ATTRIBUTE_PINNED_ON_TOP = "pinned_on_top";
|
||||
|
@ -1368,6 +1370,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
|||
return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPrivateAndNonAnonymous());
|
||||
}
|
||||
|
||||
public boolean notifyReplies() {
|
||||
return alwaysNotify() || getBooleanAttribute(ATTRIBUTE_NOTIFY_REPLIES, false);
|
||||
}
|
||||
|
||||
public boolean setAttribute(String key, boolean value) {
|
||||
return setAttribute(key, String.valueOf(value));
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection;
|
|||
import eu.siacs.conversations.xmpp.jingle.Media;
|
||||
import eu.siacs.conversations.entities.MucOptions;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
|
||||
|
||||
public class NotificationService {
|
||||
|
@ -539,7 +540,7 @@ public class NotificationService {
|
|||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
return message.getStatus() == Message.STATUS_RECEIVED
|
||||
&& !conversation.isMuted()
|
||||
&& (conversation.alwaysNotify() || wasHighlightedOrPrivate(message))
|
||||
&& (conversation.alwaysNotify() || (wasHighlightedOrPrivate(message) || (conversation.notifyReplies() && wasReplyToMe(message))))
|
||||
&& (!conversation.isWithStranger() || notificationsFromStrangers())
|
||||
&& message.getType() != Message.TYPE_RTP_SESSION;
|
||||
}
|
||||
|
@ -1909,6 +1910,14 @@ public class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean wasReplyToMe(final Message message) {
|
||||
final Element reply = message.getReply();
|
||||
if (reply == null || reply.getAttribute("id") == null) return false;
|
||||
final Message parent = ((Conversation) message.getConversation()).findMessageWithRemoteIdAndCounterpart(reply.getAttribute("id"), null);
|
||||
if (parent == null) return false;
|
||||
return parent.getStatus() >= Message.STATUS_SEND;
|
||||
}
|
||||
|
||||
public void setOpenConversation(final Conversation conversation) {
|
||||
this.mOpenConversation = conversation;
|
||||
}
|
||||
|
|
|
@ -152,18 +152,19 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
|||
String[] choices = {
|
||||
getString(R.string.notify_on_all_messages),
|
||||
getString(R.string.notify_only_when_highlighted),
|
||||
getString(R.string.notify_only_when_highlighted_or_replied),
|
||||
getString(R.string.notify_never)
|
||||
};
|
||||
final AtomicInteger choice;
|
||||
if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0) == Long.MAX_VALUE) {
|
||||
choice = new AtomicInteger(2);
|
||||
choice = new AtomicInteger(3);
|
||||
} else {
|
||||
choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
|
||||
choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : (mConversation.notifyReplies() ? 2 : 1));
|
||||
}
|
||||
builder.setSingleChoiceItems(choices, choice.get(), (dialog, which) -> choice.set(which));
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||
if (choice.get() == 2) {
|
||||
if (choice.get() == 3) {
|
||||
final AlertDialog.Builder builder1 = new AlertDialog.Builder(ConferenceDetailsActivity.this);
|
||||
builder1.setTitle(R.string.disable_notifications);
|
||||
final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
|
||||
|
@ -190,6 +191,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
|||
} else {
|
||||
mConversation.setMutedTill(0);
|
||||
mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY, String.valueOf(choice.get() == 0));
|
||||
mConversation.setAttribute(Conversation.ATTRIBUTE_NOTIFY_REPLIES, String.valueOf(choice.get() == 2));
|
||||
}
|
||||
xmppConnectionService.updateConversation(mConversation);
|
||||
updateView();
|
||||
|
@ -771,6 +773,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
|||
} else if (mConversation.alwaysNotify()) {
|
||||
this.binding.notificationStatusText.setText(R.string.notify_on_all_messages);
|
||||
this.binding.notificationStatusButton.setImageResource(ic_notifications);
|
||||
} else if (mConversation.notifyReplies()) {
|
||||
this.binding.notificationStatusText.setText(R.string.notify_only_when_highlighted_or_replied);
|
||||
this.binding.notificationStatusButton.setImageResource(ic_notifications_none);
|
||||
} else {
|
||||
this.binding.notificationStatusText.setText(R.string.notify_only_when_highlighted);
|
||||
this.binding.notificationStatusButton.setImageResource(ic_notifications_none);
|
||||
|
|
|
@ -1310,4 +1310,5 @@
|
|||
<string name="settings_restore_message_failure">Failed to restore settings: %s</string>
|
||||
<string name="pref_follow_thread_in_channel">Auto-follow thread in channels</string>
|
||||
<string name="pref_follow_thread_in_channel_summary">Set the thread marker to match the message currently being looked at</string>
|
||||
<string name="notify_only_when_highlighted_or_replied">Notify for mentions and replies</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue