mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-02-17 23:40:20 -05:00
Bugfix notification system
* If there's a new message notification, keep showing the "New messages in" content text, even after a disconnect notification. * Handle the case of a channel/query name duplicated between two or more connections more gracefully in new message notifications * Fix a race in updating notifications
This commit is contained in:
parent
35609e5529
commit
06e0849c17
@ -319,6 +319,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) {
|
if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) {
|
||||||
Intent ackIntent = new Intent(this, IRCService.class);
|
Intent ackIntent = new Intent(this, IRCService.class);
|
||||||
ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
||||||
|
ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId);
|
||||||
ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
||||||
startService(ackIntent);
|
startService(ackIntent);
|
||||||
}
|
}
|
||||||
|
@ -248,6 +248,7 @@ public class IRCConnection extends PircBot
|
|||||||
if (mentioned || target.equals(this.getNick())) {
|
if (mentioned || target.equals(this.getNick())) {
|
||||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||||
service.addNewMention(
|
service.addNewMention(
|
||||||
|
server.getId(),
|
||||||
conversation,
|
conversation,
|
||||||
conversation.getName() + ": " + sender + " " + action,
|
conversation.getName() + ": " + sender + " " + action,
|
||||||
service.getSettings().isVibrateHighlightEnabled(),
|
service.getSettings().isVibrateHighlightEnabled(),
|
||||||
@ -423,6 +424,7 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_RED);
|
message.setColor(Message.COLOR_RED);
|
||||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||||
service.addNewMention(
|
service.addNewMention(
|
||||||
|
server.getId(),
|
||||||
conversation,
|
conversation,
|
||||||
target + ": <" + sender + "> " + text,
|
target + ": <" + sender + "> " + text,
|
||||||
service.getSettings().isVibrateHighlightEnabled(),
|
service.getSettings().isVibrateHighlightEnabled(),
|
||||||
@ -632,6 +634,7 @@ public class IRCConnection extends PircBot
|
|||||||
|
|
||||||
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) {
|
||||||
service.addNewMention(
|
service.addNewMention(
|
||||||
|
server.getId(),
|
||||||
conversation,
|
conversation,
|
||||||
"<" + sender + "> " + text,
|
"<" + sender + "> " + text,
|
||||||
service.getSettings().isVibrateHighlightEnabled(),
|
service.getSettings().isVibrateHighlightEnabled(),
|
||||||
|
@ -70,6 +70,7 @@ public class IRCService extends Service
|
|||||||
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
||||||
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
||||||
public static final String ACTION_ACK_NEW_MENTIONS = "org.yaaic.service.ack_new_mentions";
|
public static final String ACTION_ACK_NEW_MENTIONS = "org.yaaic.service.ack_new_mentions";
|
||||||
|
public static final String EXTRA_ACK_SERVERID = "org.yaaic.service.ack_serverid";
|
||||||
public static final String EXTRA_ACK_CONVTITLE = "org.yaaic.service.ack_convtitle";
|
public static final String EXTRA_ACK_CONVTITLE = "org.yaaic.service.ack_convtitle";
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
@ -191,7 +192,7 @@ public class IRCService extends Service
|
|||||||
} else if (ACTION_BACKGROUND.equals(intent.getAction()) && !foreground) {
|
} else if (ACTION_BACKGROUND.equals(intent.getAction()) && !foreground) {
|
||||||
stopForegroundCompat(FOREGROUND_NOTIFICATION);
|
stopForegroundCompat(FOREGROUND_NOTIFICATION);
|
||||||
} else if (ACTION_ACK_NEW_MENTIONS.equals(intent.getAction())) {
|
} else if (ACTION_ACK_NEW_MENTIONS.equals(intent.getAction())) {
|
||||||
ackNewMentions(intent.getStringExtra(EXTRA_ACK_CONVTITLE));
|
ackNewMentions(intent.getIntExtra(EXTRA_ACK_SERVERID, -1), intent.getStringExtra(EXTRA_ACK_CONVTITLE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +213,13 @@ public class IRCService extends Service
|
|||||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
|
||||||
|
|
||||||
if (contentText == null) {
|
if (contentText == null) {
|
||||||
if (!connectedServerTitles.isEmpty()) {
|
if (newMentions >= 1) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Conversation conv : mentions.values()) {
|
||||||
|
sb.append(conv.getName() + " (" + conv.getNewMentions() + "), ");
|
||||||
|
}
|
||||||
|
contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length()-2));
|
||||||
|
} else if (!connectedServerTitles.isEmpty()) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String title : connectedServerTitles) {
|
for (String title : connectedServerTitles) {
|
||||||
sb.append(title + ", ");
|
sb.append(title + ", ");
|
||||||
@ -240,23 +247,10 @@ public class IRCService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the status bar notification for a new mention
|
* Generates a string uniquely identifying a conversation.
|
||||||
*/
|
*/
|
||||||
private void notifyMention(String msg, boolean vibrate, boolean sound)
|
public String getConversationId(int serverId, String title) {
|
||||||
{
|
return "" + serverId + ":" + title;
|
||||||
String contentText = null;
|
|
||||||
|
|
||||||
if (newMentions == 1 && msg != null) {
|
|
||||||
contentText = msg;
|
|
||||||
} else if (newMentions >= 1) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Conversation conv : mentions.values()) {
|
|
||||||
sb.append(conv.getName() + " (" + conv.getNewMentions() + "), ");
|
|
||||||
}
|
|
||||||
contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length()-2));
|
|
||||||
}
|
|
||||||
|
|
||||||
updateNotification(msg, contentText, vibrate, sound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -267,20 +261,23 @@ public class IRCService extends Service
|
|||||||
* @param vibrate Whether the notification should include vibration
|
* @param vibrate Whether the notification should include vibration
|
||||||
* @param sound Whether the notification should include sound
|
* @param sound Whether the notification should include sound
|
||||||
*/
|
*/
|
||||||
public void addNewMention(Conversation conversation, String msg, boolean vibrate, boolean sound)
|
public synchronized void addNewMention(int serverId, Conversation conversation, String msg, boolean vibrate, boolean sound)
|
||||||
{
|
{
|
||||||
if (conversation == null)
|
if (conversation == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String convTitle = conversation.getName();
|
|
||||||
|
|
||||||
conversation.addNewMention();
|
conversation.addNewMention();
|
||||||
++newMentions;
|
++newMentions;
|
||||||
if (!mentions.containsKey(convTitle)) {
|
String convId = getConversationId(serverId, conversation.getName());
|
||||||
mentions.put(convTitle, conversation);
|
if (!mentions.containsKey(convId)) {
|
||||||
|
mentions.put(convId, conversation);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyMention(msg, vibrate, sound);
|
if (newMentions == 1) {
|
||||||
|
updateNotification(msg, msg, vibrate, sound);
|
||||||
|
} else {
|
||||||
|
updateNotification(msg, null, vibrate, sound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,12 +285,12 @@ public class IRCService extends Service
|
|||||||
*
|
*
|
||||||
* @param convTitle The title of the conversation whose new mentions have been read
|
* @param convTitle The title of the conversation whose new mentions have been read
|
||||||
*/
|
*/
|
||||||
public void ackNewMentions(String convTitle)
|
public synchronized void ackNewMentions(int serverId, String convTitle)
|
||||||
{
|
{
|
||||||
if (convTitle == null)
|
if (convTitle == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Conversation conversation = mentions.remove(convTitle);
|
Conversation conversation = mentions.remove(getConversationId(serverId, convTitle));
|
||||||
if (conversation == null)
|
if (conversation == null)
|
||||||
return;
|
return;
|
||||||
newMentions -= conversation.getNewMentions();
|
newMentions -= conversation.getNewMentions();
|
||||||
@ -301,7 +298,7 @@ public class IRCService extends Service
|
|||||||
if (newMentions < 0)
|
if (newMentions < 0)
|
||||||
newMentions = 0;
|
newMentions = 0;
|
||||||
|
|
||||||
notifyMention(null, false, false);
|
updateNotification(null, null, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,7 +306,7 @@ public class IRCService extends Service
|
|||||||
*
|
*
|
||||||
* @param title The title of the newly connected server
|
* @param title The title of the newly connected server
|
||||||
*/
|
*/
|
||||||
public void notifyConnected(String title)
|
public synchronized void notifyConnected(String title)
|
||||||
{
|
{
|
||||||
connectedServerTitles.add(title);
|
connectedServerTitles.add(title);
|
||||||
updateNotification(getString(R.string.notification_connected, title), null, false, false);
|
updateNotification(getString(R.string.notification_connected, title), null, false, false);
|
||||||
@ -320,7 +317,7 @@ public class IRCService extends Service
|
|||||||
*
|
*
|
||||||
* @param title The title of the disconnected server
|
* @param title The title of the disconnected server
|
||||||
*/
|
*/
|
||||||
public void notifyDisconnected(String title)
|
public synchronized void notifyDisconnected(String title)
|
||||||
{
|
{
|
||||||
connectedServerTitles.remove(title);
|
connectedServerTitles.remove(title);
|
||||||
updateNotification(getString(R.string.notification_disconnected, title), null, false, false);
|
updateNotification(getString(R.string.notification_disconnected, title), null, false, false);
|
||||||
|
@ -88,6 +88,7 @@ public class ConversationSelectedListener implements OnItemSelectedListener
|
|||||||
if (conversation.getNewMentions() > 0) {
|
if (conversation.getNewMentions() > 0) {
|
||||||
Intent i = new Intent(ctx, IRCService.class);
|
Intent i = new Intent(ctx, IRCService.class);
|
||||||
i.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
i.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
|
||||||
|
i.putExtra(IRCService.EXTRA_ACK_SERVERID, server.getId());
|
||||||
i.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
i.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
|
||||||
ctx.startService(i);
|
ctx.startService(i);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user