Clean GroupManager

This commit is contained in:
nielsandriesse 2020-05-12 16:33:04 +10:00
parent 04e14dd5dd
commit 9b4a219b06
7 changed files with 35 additions and 35 deletions

View File

@ -516,7 +516,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
public void createDefaultPublicChatsIfNeeded() {
List<LokiPublicChat> defaultPublicChats = LokiPublicChatAPI.Companion.getDefaultChats(BuildConfig.DEBUG);
for (LokiPublicChat publicChat : defaultPublicChats) {
long threadID = GroupManager.getPublicChatThreadId(publicChat.getId(), this);
long threadID = GroupManager.getOpenGroupThreadID(publicChat.getId(), this);
String migrationKey = publicChat.getId() + "_migrated";
boolean isChatMigrated = TextSecurePreferences.getBooleanPreference(this, migrationKey, false);
boolean isChatSetUp = TextSecurePreferences.isChatSetUp(this, publicChat.getId());
@ -541,7 +541,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
for (LokiRSSFeed feed : feeds) {
boolean isFeedSetUp = TextSecurePreferences.isChatSetUp(this, feed.getId());
if (!isFeedSetUp || !feed.isDeletable()) {
GroupManager.createRSSFeedGroup(feed.getId(), this, null, feed.getDisplayName());
GroupManager.createRSSFeed(feed.getId(), this, null, feed.getDisplayName());
TextSecurePreferences.markChatSetUp(this, feed.getId());
}
}
@ -553,7 +553,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
/*
// Only create the RSS feed pollers if their threads aren't deleted
LokiRSSFeed lokiNewsFeed = lokiNewsFeed();
long lokiNewsFeedThreadID = GroupManager.getRSSFeedThreadId(lokiNewsFeed.getId(), this);
long lokiNewsFeedThreadID = GroupManager.getRSSFeedThreadID(lokiNewsFeed.getId(), this);
if (lokiNewsFeedThreadID >= 0 && lokiNewsFeedPoller == null) {
lokiNewsFeedPoller = new LokiRSSFeedPoller(this, lokiNewsFeed);
// Set up deletion listeners if needed

View File

@ -36,18 +36,18 @@ import java.util.Set;
public class GroupManager {
public static long getPublicChatThreadId(String id, @NonNull Context context) {
final String groupId = GroupUtil.getEncodedPublicChatId(id.getBytes());
return getThreadIdFromGroupId(groupId, context);
public static long getOpenGroupThreadID(String id, @NonNull Context context) {
final String groupID = GroupUtil.getEncodedPublicChatId(id.getBytes());
return getThreadIDFromGroupID(groupID, context);
}
public static long getRSSFeedThreadId(String id, @NonNull Context context) {
final String groupId = GroupUtil.getEncodedRSSFeedId(id.getBytes());
return getThreadIdFromGroupId(groupId, context);
public static long getRSSFeedThreadID(String id, @NonNull Context context) {
final String groupID = GroupUtil.getEncodedRSSFeedId(id.getBytes());
return getThreadIDFromGroupID(groupID, context);
}
public static long getThreadIdFromGroupId(String groupId, @NonNull Context context) {
final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false);
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);
}
@ -78,10 +78,10 @@ public class GroupManager {
final Set<Address> memberAddresses = getMemberAddresses(members);
final Set<Address> adminAddresses = getMemberAddresses(admins);
String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
String ourNumber = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context);
String masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
String publicKeyToUse = masterPublicKey != null ? masterPublicKey : TextSecurePreferences.getLocalNumber(context);
memberAddresses.add(Address.fromSerialized(ourNumber));
memberAddresses.add(Address.fromSerialized(publicKeyToUse));
groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null, new LinkedList<>(adminAddresses));
if (!mms) {
@ -94,22 +94,22 @@ public class GroupManager {
}
}
public static @NonNull GroupActionResult createPublicChatGroup(@NonNull String id,
@NonNull Context context,
@Nullable Bitmap avatar,
@Nullable String name)
public static @NonNull GroupActionResult createOpenGroup(@NonNull String id,
@NonNull Context context,
@Nullable Bitmap avatar,
@Nullable String name)
{
final String groupId = GroupUtil.getEncodedPublicChatId(id.getBytes());
return createLokiGroup(groupId, context, avatar, name);
final String groupID = GroupUtil.getEncodedPublicChatId(id.getBytes());
return createLokiGroup(groupID, context, avatar, name);
}
public static @NonNull GroupActionResult createRSSFeedGroup(@NonNull String id,
@NonNull Context context,
@Nullable Bitmap avatar,
@Nullable String name)
public static @NonNull GroupActionResult createRSSFeed(@NonNull String id,
@NonNull Context context,
@Nullable Bitmap avatar,
@Nullable String name)
{
final String groupId = GroupUtil.getEncodedRSSFeedId(id.getBytes());
return createLokiGroup(groupId, context, avatar, name);
final String groupID = GroupUtil.getEncodedRSSFeedId(id.getBytes());
return createLokiGroup(groupID, context, avatar, name);
}
private static @NonNull GroupActionResult createLokiGroup(@NonNull String groupId,
@ -127,8 +127,8 @@ public class GroupManager {
groupDatabase.updateAvatar(groupId, avatarBytes);
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
return new GroupActionResult(groupRecipient, threadId);
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
return new GroupActionResult(groupRecipient, threadID);
}
public static GroupActionResult updateGroup(@NonNull Context context,

View File

@ -759,7 +759,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
private void handleOpenGroupSyncMessage(@NonNull List<LokiPublicChat> openGroups) {
try {
for (LokiPublicChat openGroup : openGroups) {
long threadID = GroupManager.getPublicChatThreadId(openGroup.getId(), context);
long threadID = GroupManager.getOpenGroupThreadID(openGroup.getId(), context);
if (threadID > -1) continue;
String url = openGroup.getServer();

View File

@ -49,7 +49,7 @@ class MultiDeviceOpenGroupUpdateJob private constructor(parameters: Parameters)
val record = reader.next ?: return@use
if (!record.isPublicChat) { continue; }
val threadID = GroupManager.getThreadIdFromGroupId(record.encodedId, context)
val threadID = GroupManager.getThreadIDFromGroupID(record.encodedId, context)
val openGroup = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID)
if (openGroup != null) {
openGroups.add(openGroup)

View File

@ -48,10 +48,10 @@ class LokiPublicChatManager(private val context: Context) {
public fun addChat(server: String, channel: Long, name: String): LokiPublicChat {
val chat = LokiPublicChat(channel, server, name, true)
var threadID = GroupManager.getPublicChatThreadId(chat.id, context)
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
// Create the group if we don't have one
if (threadID < 0) {
val result = GroupManager.createPublicChatGroup(chat.id, context, null, chat.displayName)
val result = GroupManager.createOpenGroup(chat.id, context, null, chat.displayName)
threadID = result.threadId
}
DatabaseFactory.getLokiThreadDatabase(context).setPublicChat(chat, threadID)
@ -72,7 +72,7 @@ class LokiPublicChatManager(private val context: Context) {
removedChatThreadIds.forEach { pollers.remove(it)?.stop() }
// Only append to chats if we have a thread for the chat
chats = chatsInDB.filter { GroupManager.getPublicChatThreadId(it.value.id, context) > -1 }.toMutableMap()
chats = chatsInDB.filter { GroupManager.getOpenGroupThreadID(it.value.id, context) > -1 }.toMutableMap()
}
private fun listenToThreadDeletion(threadID: Long) {

View File

@ -15,7 +15,7 @@ object OpenGroupUtilities {
@JvmStatic fun addGroup(context: Context, url: String, channel: Long): Promise<LokiPublicChat, Exception> {
// Check for an existing group
val groupID = LokiPublicChat.getId(channel, url)
val threadID = GroupManager.getPublicChatThreadId(groupID, context)
val threadID = GroupManager.getOpenGroupThreadID(groupID, context)
val openGroup = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID)
if (openGroup != null) { return Promise.of(openGroup) }
// Add the new group

View File

@ -52,7 +52,7 @@ class UserView : LinearLayout {
profilePictureView.additionalHexEncodedPublicKey = null
profilePictureView.isRSSFeed = true
} else {
val threadID = GroupManager.getThreadIdFromGroupId(address, context)
val threadID = GroupManager.getThreadIDFromGroupID(address, context)
val users = MentionsManager.shared.userHexEncodedPublicKeyCache[threadID]?.toList() ?: listOf()
val randomUsers = users.sorted() // Sort to provide a level of stability
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""