mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-19 23:51:30 +00:00
commit
dbb07d78b0
@ -21,6 +21,7 @@ import android.arch.lifecycle.DefaultLifecycleObserver;
|
|||||||
import android.arch.lifecycle.LifecycleOwner;
|
import android.arch.lifecycle.LifecycleOwner;
|
||||||
import android.arch.lifecycle.ProcessLifecycleOwner;
|
import android.arch.lifecycle.ProcessLifecycleOwner;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -35,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.signal.aesgcmprovider.AesGcmProvider;
|
import org.signal.aesgcmprovider.AesGcmProvider;
|
||||||
import org.thoughtcrime.securesms.components.TypingStatusRepository;
|
import org.thoughtcrime.securesms.components.TypingStatusRepository;
|
||||||
import org.thoughtcrime.securesms.components.TypingStatusSender;
|
import org.thoughtcrime.securesms.components.TypingStatusSender;
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseContentProviders;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
|
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
|
||||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||||
@ -458,7 +460,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
LokiGroupChat publicChat = lokiPublicChat();
|
LokiGroupChat publicChat = lokiPublicChat();
|
||||||
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publicChat.getId());
|
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publicChat.getId());
|
||||||
if (!isChatSetUp || !publicChat.isDeletable()) {
|
if (!isChatSetUp || !publicChat.isDeletable()) {
|
||||||
GroupManager.createGroup(publicChat.getId(), this, new HashSet<>(), null, publicChat.getDisplayName(), false);
|
GroupManager.GroupActionResult result = GroupManager.createGroup(publicChat.getId(), this, new HashSet<>(), null, publicChat.getDisplayName(), false);
|
||||||
TextSecurePreferences.markChatSetUp(this, publicChat.getId());
|
TextSecurePreferences.markChatSetUp(this, publicChat.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,23 +479,67 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createGroupChatPollersIfNeeded() {
|
private void createGroupChatPollersIfNeeded() {
|
||||||
if (lokiPublicChatPoller == null) lokiPublicChatPoller = new LokiGroupChatPoller(this, lokiPublicChat());
|
// 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) {
|
||||||
|
lokiPublicChatPoller = new LokiGroupChatPoller(this, publicChat);
|
||||||
|
// Set up deletion listeners if needed
|
||||||
|
setUpThreadDeletionListeners(threadID, () -> {
|
||||||
|
if (lokiPublicChatPoller != null) lokiPublicChatPoller.stop();
|
||||||
|
lokiPublicChatPoller = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRSSFeedPollersIfNeeded() {
|
private void createRSSFeedPollersIfNeeded() {
|
||||||
if (lokiNewsFeedPoller == null) lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed());
|
// Only create the RSS feed pollers if their threads aren't deleted
|
||||||
if (lokiMessengerUpdatesFeedPoller == null) lokiMessengerUpdatesFeedPoller = new LokiRSSFeedPoller(this, lokiMessengerUpdatesFeed());
|
LokiRSSFeed lokiNewsFeed = lokiNewsFeed();
|
||||||
|
long lokiNewsFeedThreadID = GroupManager.getThreadId(lokiNewsFeed.getId(), this);
|
||||||
|
if (lokiNewsFeedThreadID >= 0 && lokiNewsFeedPoller == null) {
|
||||||
|
lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed);
|
||||||
|
// Set up deletion listeners if needed
|
||||||
|
setUpThreadDeletionListeners(lokiNewsFeedThreadID, () -> {
|
||||||
|
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.stop();
|
||||||
|
lokiNewsFeedPoller = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 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; }
|
||||||
|
ContentObserver observer = new ContentObserver(null) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
super.onChange(selfChange);
|
||||||
|
// Stop the poller if thread is deleted
|
||||||
|
try {
|
||||||
|
if (!DatabaseFactory.getThreadDatabase(getApplicationContext()).hasThread(threadID)) {
|
||||||
|
onDelete.run();
|
||||||
|
getContentResolver().unregisterContentObserver(this);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: Handle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadID), true, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGroupChatPollersIfNeeded() {
|
public void startGroupChatPollersIfNeeded() {
|
||||||
createGroupChatPollersIfNeeded();
|
createGroupChatPollersIfNeeded();
|
||||||
lokiPublicChatPoller.startIfNeeded();
|
if (lokiPublicChatPoller != null) lokiPublicChatPoller.startIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRSSFeedPollersIfNeeded() {
|
public void startRSSFeedPollersIfNeeded() {
|
||||||
createRSSFeedPollersIfNeeded();
|
createRSSFeedPollersIfNeeded();
|
||||||
lokiNewsFeedPoller.startIfNeeded();
|
if (lokiNewsFeedPoller != null) lokiNewsFeedPoller.startIfNeeded();
|
||||||
lokiMessengerUpdatesFeedPoller.startIfNeeded();
|
if (lokiMessengerUpdatesFeedPoller != null) lokiMessengerUpdatesFeedPoller.startIfNeeded();
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
@ -2101,7 +2101,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
Context context = ConversationActivity.this;
|
Context context = ConversationActivity.this;
|
||||||
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(params[0], false);
|
||||||
|
|
||||||
MessageNotifier.updateNotification(context);
|
// Only send notifications for private chats
|
||||||
|
if (!getRecipient().isGroupRecipient()) { MessageNotifier.updateNotification(context); }
|
||||||
|
|
||||||
MarkReadReceiver.process(context, messageIds);
|
MarkReadReceiver.process(context, messageIds);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -472,6 +472,18 @@ public class ThreadDatabase extends Database {
|
|||||||
deleteAllThreads();
|
deleteAllThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (cursor != null && cursor.moveToFirst()) { return true; }
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long getThreadIdIfExistsFor(Recipient recipient) {
|
public long getThreadIdIfExistsFor(Recipient recipient) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String where = ADDRESS + " = ?";
|
String where = ADDRESS + " = ?";
|
||||||
|
@ -36,6 +36,16 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class GroupManager {
|
public class GroupManager {
|
||||||
|
|
||||||
|
public static long getThreadId(String id, @NonNull Context context) {
|
||||||
|
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);
|
||||||
|
return DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(groupRecipient);
|
||||||
|
}
|
||||||
|
|
||||||
public static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
public static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
||||||
@NonNull Set<Recipient> members,
|
@NonNull Set<Recipient> members,
|
||||||
@Nullable Bitmap avatar,
|
@Nullable Bitmap avatar,
|
||||||
@ -63,6 +73,16 @@ public class GroupManager {
|
|||||||
memberAddresses.add(Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)));
|
memberAddresses.add(Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)));
|
||||||
groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null);
|
groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null);
|
||||||
|
|
||||||
|
if (!mms) {
|
||||||
|
groupDatabase.updateAvatar(groupId, avatarBytes);
|
||||||
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||||
|
return new GroupActionResult(groupRecipient, threadId);
|
||||||
|
|
||||||
|
/* Loki: Original Code
|
||||||
|
==================
|
||||||
if (!mms) {
|
if (!mms) {
|
||||||
groupDatabase.updateAvatar(groupId, avatarBytes);
|
groupDatabase.updateAvatar(groupId, avatarBytes);
|
||||||
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true);
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true);
|
||||||
@ -71,6 +91,7 @@ public class GroupManager {
|
|||||||
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
|
||||||
return new GroupActionResult(groupRecipient, threadId);
|
return new GroupActionResult(groupRecipient, threadId);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GroupActionResult updateGroup(@NonNull Context context,
|
public static GroupActionResult updateGroup(@NonNull Context context,
|
||||||
|
@ -736,7 +736,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
public void handleMediaMessage(@NonNull SignalServiceContent content,
|
public void handleMediaMessage(@NonNull SignalServiceContent content,
|
||||||
@NonNull SignalServiceDataMessage message,
|
@NonNull SignalServiceDataMessage message,
|
||||||
@NonNull Optional<Long> smsMessageId,
|
@NonNull Optional<Long> smsMessageId,
|
||||||
@Nullable Optional<Long> messageServerIDOrNull)
|
@NonNull Optional<Long> messageServerIDOrNull)
|
||||||
throws StorageFailedException
|
throws StorageFailedException
|
||||||
{
|
{
|
||||||
notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice());
|
notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice());
|
||||||
@ -812,11 +812,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
// Loki - Store message server ID
|
||||||
long messageID = insertResult.get().getMessageId();
|
updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
|
||||||
long messageServerID = messageServerIDOrNull.get();
|
|
||||||
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (insertResult.isPresent()) {
|
if (insertResult.isPresent()) {
|
||||||
MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
|
MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
|
||||||
@ -927,7 +924,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
public void handleTextMessage(@NonNull SignalServiceContent content,
|
public void handleTextMessage(@NonNull SignalServiceContent content,
|
||||||
@NonNull SignalServiceDataMessage message,
|
@NonNull SignalServiceDataMessage message,
|
||||||
@NonNull Optional<Long> smsMessageId,
|
@NonNull Optional<Long> smsMessageId,
|
||||||
@Nullable Optional<Long> messageServerIDOrNull)
|
@NonNull Optional<Long> messageServerIDOrNull)
|
||||||
throws StorageFailedException
|
throws StorageFailedException
|
||||||
{
|
{
|
||||||
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||||
@ -985,17 +982,23 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
|
|
||||||
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
||||||
|
|
||||||
|
// Loki - Store message server ID
|
||||||
|
updateGroupChatMessageServerID(messageServerIDOrNull, insertResult);
|
||||||
|
|
||||||
|
boolean isGroupMessage = message.getGroupInfo().isPresent();
|
||||||
|
if (threadId != null && !isGroupMessage) {
|
||||||
|
MessageNotifier.updateNotification(context, threadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateGroupChatMessageServerID(Optional<Long> messageServerIDOrNull, Optional<InsertResult> insertResult) {
|
||||||
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
||||||
long messageID = insertResult.get().getMessageId();
|
long messageID = insertResult.get().getMessageId();
|
||||||
long messageServerID = messageServerIDOrNull.get();
|
long messageServerID = messageServerIDOrNull.get();
|
||||||
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threadId != null) {
|
|
||||||
MessageNotifier.updateNotification(context, threadId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
||||||
|
@ -388,6 +388,9 @@ public class MessageNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void sendInThreadNotification(Context context, Recipient recipient) {
|
private static void sendInThreadNotification(Context context, Recipient recipient) {
|
||||||
|
// Mute group chats
|
||||||
|
if (recipient.isGroupRecipient()) { return; }
|
||||||
|
|
||||||
if (!TextSecurePreferences.isInThreadNotifications(context) ||
|
if (!TextSecurePreferences.isInThreadNotifications(context) ||
|
||||||
ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
|
ServiceUtil.getAudioManager(context).getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user