pull/22/head
Niels Andriesse 5 years ago
parent 3b242e7435
commit 52b55652c8

@ -478,16 +478,14 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
}
private void createGroupChatPollersIfNeeded() {
// Only add the public chat poller if we have the thread
// Only create the group chat pollers if their threads aren't deleted
LokiGroupChat publicChat = lokiPublicChat();
long threadId = GroupManager.getThreadId(publicChat.getId(), this);
if (threadId >= 0 && lokiPublicChatPoller == null) {
long threadID = GroupManager.getThreadId(publicChat.getId(), this);
if (threadID >= 0 && lokiPublicChatPoller == null) {
lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat);
// Attach a deletion listener to the thread if we have it
setupThreadDeletionListeners(threadId, () -> {
// Set up deletion listeners if needed
setUpThreadDeletionListeners(threadID, () -> {
if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop();
lokiPublicChatPoller = null;
});
@ -495,43 +493,42 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
private void createRSSFeedPollersIfNeeded() {
// Only add the feed poller if we have the thread
// Only create the RSS feed pollers if their threads aren't deleted
LokiRSSFeed lokiNewsFeed = lokiNewsFeed();
long lokiNewsFeedThreadId = GroupManager.getThreadId(lokiNewsFeed.getId(), this);
if (lokiNewsFeedThreadId >= 0 && lokiNewsFeedPoller == null) {
long lokiNewsFeedThreadID = GroupManager.getThreadId(lokiNewsFeed.getId(), this);
if (lokiNewsFeedThreadID >= 0 && lokiNewsFeedPoller == null) {
lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed);
// Attach a deletion listener to the thread if we have it
setupThreadDeletionListeners(lokiNewsFeedThreadId, () -> {
// Set up deletion listeners if needed
setUpThreadDeletionListeners(lokiNewsFeedThreadID, () -> {
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop();
lokiNewsFeedPoller = null;
});
}
// This one is not stoppable
if (lokiMessengerUpdatesFeedPoller == null) { lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed()); }
// The user can't delete the Loki Messenger Updates RSS feed
if (lokiMessengerUpdatesFeedPoller == null) {
lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed());
}
}
private void setupThreadDeletionListeners(long threadId, Runnable onDelete) {
if (threadId < 0) { return; }
private void setUpThreadDeletionListeners(long threadID, Runnable onDelete) {
if (threadID < 0) { return; }
ContentObserver observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
// Stop the poller if thread doesn't exist
// Stop the poller if thread is deleted
try {
if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadId)) {
if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadID)) {
onDelete.run();
getContentResolver().unregisterContentObserver(this);
}
} catch (Exception e) {
// Failed to call delete
// TODO: Handle
}
}
};
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadId), true, observer);
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadID), true, observer);
}
public void startGroupChatPollersIfNeeded() {

@ -2101,10 +2101,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
Context context = ConversationActivity.this;
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
// Only notify on private chats
if (!getRecipient().isGroupRecipient()) {
MessageNotifier.updateNotification(context);
}
// Only send notifications for private chats
if (!getRecipient().isGroupRecipient()) { MessageNotifier.updateNotification(context); }
MarkReadReceiver.process(context, messageIds);

@ -473,14 +473,11 @@ public class ThreadDatabase extends Database {
}
public boolean hasThread(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{ID}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{ ID }, ID_WHERE, new String[]{ String.valueOf(threadId) }, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
return true;
}
if (cursor != null && cursor.moveToFirst()) { return true; }
return false;
} finally {
if (cursor != null) cursor.close();

@ -37,12 +37,12 @@ import java.util.Set;
public class GroupManager {
public static long getThreadId(String id, @NonNull Context context) {
final String groupId = GroupUtil.getEncodedId(id.getBytes(), false);
final String groupId = GroupUtil.getEncodedId(id.getBytes(), false);
return getThreadIdFromGroupId(groupId, context);
}
public static long getThreadIdFromGroupId(String groupId, @NonNull Context context) {
final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false);
final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false);
return DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(groupRecipient);
}

@ -812,8 +812,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
database.endTransaction();
}
// Loki - Map message id to server id
updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult);
// Loki - Store message server ID
updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
if (insertResult.isPresent()) {
MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
@ -982,8 +982,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
// Loki - Map message id to server id
updatePublicChatMessageWithServerID(messageServerIDOrNull, insertResult);
// Loki - Store message server ID
updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
boolean isGroupMessage = message.getGroupInfo().isPresent();
if (threadId != null && !isGroupMessage) {
@ -993,10 +993,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
}
}
private void updatePublicChatMessageWithServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> databaseInsert) {
if (messageServerIDOrNull == null) { return; }
if (databaseInsert.isPresent() && messageServerIDOrNull.isPresent()) {
long messageID = databaseInsert.get().getMessageId();
private void updateGroupChatMessageServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> insertResult) {
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
long messageID = insertResult.get().getMessageId();
long messageServerID = messageServerIDOrNull.get();
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
}

@ -388,10 +388,8 @@ public class MessageNotifier {
}
private static void sendInThreadNotification(Context context, Recipient recipient) {
// Keep group messages muted!
if (recipient.isGroupRecipient()) {
return;
}
// Mute group chats
if (recipient.isGroupRecipient()) { return; }
if (!TextSecurePreferences.isInThreadNotifications(context) ||
ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)

Loading…
Cancel
Save