mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Clean
This commit is contained in:
parent
65f95839d9
commit
4a613df52d
Binary file not shown.
@ -13,12 +13,12 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.thoughtcrime.securesms.components.LabeledEditText
|
||||
android:id="@+id/serverUrlEditText"
|
||||
android:id="@+id/urlEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
app:labeledEditText_background="@color/loki_darkest_gray"
|
||||
app:labeledEditText_label="@string/fragment_add_public_chat_server_url_edit_text_label"/>
|
||||
app:labeledEditText_label="@string/fragment_add_public_chat_url_edit_text_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/explanationTextView"
|
||||
@ -41,7 +41,7 @@
|
||||
app:cpb_colorProgress="@color/textsecure_primary"
|
||||
app:cpb_cornerRadius="4dp"
|
||||
app:cpb_selectorIdle="@drawable/progress_button_state"
|
||||
app:cpb_textIdle="@string/fragment_add_public_chat_add_button_title" />
|
||||
app:cpb_textIdle="@string/fragment_add_public_chat_add_button_title_1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -1575,7 +1575,6 @@
|
||||
<string name="activity_settings_public_key_copied_message">Copied to clipboard</string>
|
||||
<string name="activity_settings_share_public_key_button_title">Share Public Key</string>
|
||||
<string name="activity_settings_show_qr_code_button_title">Show QR Code</string>
|
||||
<string name="activity_settings_add_public_chat_button_title">Add Public Chat</string>
|
||||
<string name="activity_settings_link_device_button_title">Link Device</string>
|
||||
<string name="activity_settings_show_seed_button_title">Show Seed</string>
|
||||
<string name="activity_settings_seed_dialog_title">Your Seed</string>
|
||||
@ -1601,13 +1600,12 @@
|
||||
<string name="fragment_new_conversation_note_to_self_not_supported_message">Please enter the public key of the person you\'d like to message</string>
|
||||
<!-- Add public chat activity -->
|
||||
<string name="fragment_add_public_chat_title">Add Public Chat</string>
|
||||
<string name="fragment_add_public_chat_server_url_edit_text_label">Server URL</string>
|
||||
<string name="fragment_add_public_chat_explanation">Enter the full URL of the public server. E.g https://public-server.url</string>
|
||||
<string name="fragment_add_public_chat_add_button_title">Add</string>
|
||||
<string name="fragment_add_public_chat_adding_server_button_title">Adding Server...</string>
|
||||
<string name="fragment_add_public_chat_invalid_url_message">Invalid Url provided</string>
|
||||
<string name="fragment_add_public_chat_failed_connect_message">Failed to connect to server</string>
|
||||
<string name="fragment_add_public_chat_success_message">Added public chat server</string>
|
||||
<string name="fragment_add_public_chat_url_edit_text_label">URL</string>
|
||||
<string name="fragment_add_public_chat_explanation">Enter the URL of the public chat you\'d like to join. The Loki Public Chat URL is https://chat.lokinet.org.</string>
|
||||
<string name="fragment_add_public_chat_add_button_title_1">Add</string>
|
||||
<string name="fragment_add_public_chat_add_button_title_2">Adding Server...</string>
|
||||
<string name="fragment_add_public_chat_invalid_url_message">Invalid URL</string>
|
||||
<string name="fragment_add_public_chat_connection_failed_message">Couldn\'t Connect</string>
|
||||
<!-- Friend request view -->
|
||||
<string name="view_friend_request_accept_button_title">Accept</string>
|
||||
<string name="view_friend_request_reject_button_title">Reject</string>
|
||||
|
@ -41,10 +41,6 @@
|
||||
android:title="@string/activity_settings_show_qr_code_button_title"
|
||||
android:icon="@drawable/icon_qr_code"/>
|
||||
|
||||
<Preference android:key="preference_category_public_chat"
|
||||
android:title="@string/activity_settings_add_public_chat_button_title"
|
||||
android:icon="@drawable/ic_group_white_24dp"/>
|
||||
|
||||
<Preference android:key="preference_category_link_device"
|
||||
android:title="@string/activity_settings_link_device_button_title"
|
||||
android:icon="@drawable/icon_link"/>
|
||||
|
@ -40,10 +40,8 @@ import android.support.v7.preference.Preference;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||
import org.thoughtcrime.securesms.loki.AddPublicChatActivity;
|
||||
import org.thoughtcrime.securesms.loki.DeviceLinkingDialog;
|
||||
import org.thoughtcrime.securesms.loki.DeviceLinkingView;
|
||||
import org.thoughtcrime.securesms.loki.NewConversationActivity;
|
||||
import org.thoughtcrime.securesms.loki.QRCodeDialog;
|
||||
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
|
||||
@ -87,7 +85,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
private static final String PREFERENCE_CATEGORY_QR_CODE = "preference_category_qr_code";
|
||||
private static final String PREFERENCE_CATEGORY_LINK_DEVICE = "preference_category_link_device";
|
||||
private static final String PREFERENCE_CATEGORY_SEED = "preference_category_seed";
|
||||
private static final String PREFERENCE_CATEGORY_PUBLIC_CHAT = "preference_category_public_chat";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
@ -190,8 +187,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY));
|
||||
this.findPreference(PREFERENCE_CATEGORY_QR_CODE)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE));
|
||||
this.findPreference(PREFERENCE_CATEGORY_PUBLIC_CHAT)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_CHAT));
|
||||
|
||||
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
|
||||
// Hide if this is a slave device
|
||||
@ -262,7 +257,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
Drawable qrCode = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_qr_code));
|
||||
Drawable linkDevice = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_link));
|
||||
Drawable seed = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_seedling));
|
||||
Drawable publicChat = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_group_white_24dp));
|
||||
|
||||
int[] tintAttr = new int[]{R.attr.pref_icon_tint};
|
||||
TypedArray typedArray = context.obtainStyledAttributes(tintAttr);
|
||||
@ -280,7 +274,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
DrawableCompat.setTint(qrCode, color);
|
||||
DrawableCompat.setTint(linkDevice, color);
|
||||
DrawableCompat.setTint(seed, color);
|
||||
DrawableCompat.setTint(publicChat, color);
|
||||
|
||||
// this.findPreference(PREFERENCE_CATEGORY_SMS_MMS).setIcon(sms);
|
||||
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS).setIcon(notifications);
|
||||
@ -293,7 +286,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
this.findPreference(PREFERENCE_CATEGORY_QR_CODE).setIcon(qrCode);
|
||||
this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE).setIcon(linkDevice);
|
||||
this.findPreference(PREFERENCE_CATEGORY_SEED).setIcon(seed);
|
||||
this.findPreference(PREFERENCE_CATEGORY_PUBLIC_CHAT).setIcon(publicChat);
|
||||
}
|
||||
|
||||
private class CategoryClickListener implements Preference.OnPreferenceClickListener {
|
||||
@ -378,9 +370,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
// Do nothing
|
||||
}
|
||||
break;
|
||||
case PREFERENCE_CATEGORY_PUBLIC_CHAT:
|
||||
startActivity(new Intent(getActivity(), AddPublicChatActivity.class));
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@ -378,11 +378,11 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
Analytics.Companion.getShared().track("Display Name Updated");
|
||||
|
||||
TextSecurePreferences.setProfileName(context, name);
|
||||
LokiPublicChatAPI chatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI();
|
||||
if (chatAPI != null) {
|
||||
LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(context).getLokiPublicChatAPI();
|
||||
if (publicChatAPI != null) {
|
||||
Set<String> groupChatServers = DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChatServers();
|
||||
for (String server : groupChatServers) {
|
||||
chatAPI.setDisplayName(name, server);
|
||||
publicChatAPI.setDisplayName(name, server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,9 +197,9 @@ public class QuoteView extends FrameLayout implements RecipientModifiedListener
|
||||
// If we're in a group then try and use the display name in the group
|
||||
if (conversationRecipient.isGroupRecipient()) {
|
||||
long threadId = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(conversationRecipient);
|
||||
LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
if (chat != null) {
|
||||
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(chat.getId(), author.getAddress().serialize());
|
||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
if (publicChat != null) {
|
||||
String senderDisplayName = DatabaseFactory.getLokiUserDatabase(getContext()).getServerDisplayName(publicChat.getId(), author.getAddress().serialize());
|
||||
if (senderDisplayName != null) { quoteeDisplayName = senderDisplayName; }
|
||||
}
|
||||
}
|
||||
|
@ -406,14 +406,14 @@ public class ConversationFragment extends Fragment
|
||||
boolean isGroupChat = recipient.isGroupRecipient();
|
||||
|
||||
if (isGroupChat) {
|
||||
LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
boolean isPublicChat = groupChat != null;
|
||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
boolean isPublicChat = publicChat != null;
|
||||
int selectedMessageCount = messageRecords.size();
|
||||
boolean isSentByUser = ((MessageRecord)messageRecords.toArray()[0]).isOutgoing();
|
||||
menu.findItem(R.id.menu_context_copy_public_key).setVisible(isPublicChat && selectedMessageCount == 1 && !isSentByUser);
|
||||
menu.findItem(R.id.menu_context_reply).setVisible(isPublicChat && selectedMessageCount == 1);
|
||||
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
boolean userCanModerate = groupChat != null && LokiPublicChatAPI.Companion.isUserModerator(userHexEncodedPublicKey, groupChat.getChannel(), groupChat.getServer());
|
||||
boolean userCanModerate = isPublicChat && LokiPublicChatAPI.Companion.isUserModerator(userHexEncodedPublicKey, publicChat.getChannel(), publicChat.getServer());
|
||||
boolean isDeleteOptionVisible = isPublicChat && selectedMessageCount == 1 && (isSentByUser || userCanModerate);
|
||||
menu.findItem(R.id.menu_context_delete_message).setVisible(isDeleteOptionVisible);
|
||||
} else {
|
||||
@ -508,8 +508,8 @@ public class ConversationFragment extends Fragment
|
||||
builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
|
||||
builder.setCancelable(true);
|
||||
|
||||
// Loki - The delete option is only visible to the user in a group chat
|
||||
LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
// Loki - The delete option is only visible to the user in a public chat
|
||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
||||
|
||||
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -523,16 +523,16 @@ public class ConversationFragment extends Fragment
|
||||
for (MessageRecord messageRecord : messageRecords) {
|
||||
boolean isThreadDeleted;
|
||||
|
||||
if (groupChat != null) {
|
||||
if (publicChat != null) {
|
||||
final SettableFuture<?>[] future = { new SettableFuture<Unit>() };
|
||||
|
||||
LokiPublicChatAPI chatAPI = ApplicationContext.getInstance(getContext()).getLokiPublicChatAPI();
|
||||
LokiPublicChatAPI publicChatAPI = ApplicationContext.getInstance(getContext()).getLokiPublicChatAPI();
|
||||
boolean isSentByUser = messageRecord.isOutgoing();
|
||||
Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id);
|
||||
|
||||
if (chatAPI != null && serverID != null) {
|
||||
chatAPI
|
||||
.deleteMessage(serverID, groupChat.getChannel(), groupChat.getServer(), isSentByUser)
|
||||
if (publicChatAPI != null && serverID != null) {
|
||||
publicChatAPI
|
||||
.deleteMessage(serverID, publicChat.getChannel(), publicChat.getServer(), isSentByUser)
|
||||
.success(l -> {
|
||||
@SuppressWarnings("unchecked") SettableFuture<Unit> f = (SettableFuture<Unit>) future[0];
|
||||
f.set(Unit.INSTANCE);
|
||||
|
@ -939,10 +939,9 @@ public class ConversationItem extends LinearLayout
|
||||
contactPhoto.setVisibility(VISIBLE);
|
||||
int visibility = View.GONE;
|
||||
|
||||
// If we have a chat then use that to determine mod status
|
||||
LokiPublicChat groupChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(messageRecord.getThreadId());
|
||||
if (groupChat != null) {
|
||||
boolean isModerator = LokiPublicChatAPI.Companion.isUserModerator(current.getRecipient().getAddress().toString(), groupChat.getChannel(), groupChat.getServer());
|
||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(messageRecord.getThreadId());
|
||||
if (publicChat != null) {
|
||||
boolean isModerator = LokiPublicChatAPI.Companion.isUserModerator(current.getRecipient().getAddress().toString(), publicChat.getChannel(), publicChat.getServer());
|
||||
visibility = isModerator ? View.VISIBLE : View.GONE;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
|
||||
private final String address;
|
||||
|
||||
// Loki - Special flag to indicate whether this address is meant to representing a public chat or not
|
||||
// Loki - Special flag to indicate whether this address represents a public chat or not
|
||||
private Boolean isPublicChat;
|
||||
|
||||
private Address(@NonNull String address) {
|
||||
|
@ -287,12 +287,12 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
private @NonNull List<Address> getGroupMessageRecipients(String groupId, long messageId) {
|
||||
ArrayList<Address> result = new ArrayList<>();
|
||||
|
||||
// Loki - All group messages should be directed to their servers
|
||||
// Loki - All group messages should be directed to their respective servers
|
||||
long threadID = GroupManager.getThreadIdFromGroupId(groupId, context);
|
||||
LokiPublicChat chat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID);
|
||||
if (chat != null) {
|
||||
LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID);
|
||||
if (publicChat != null) {
|
||||
// We need to somehow maintain information that will allow the sender to map
|
||||
// a Recipient to the correct public chat thread, and so this might be a bit hacky
|
||||
// a recipient to the correct public chat thread, and so this might be a bit hacky
|
||||
result.add(Address.fromPublicChatGroupID(groupId));
|
||||
}
|
||||
|
||||
|
@ -44,26 +44,25 @@ class AddPublicChatActivity : PassphraseRequiredActionBarActivity() {
|
||||
|
||||
private fun addPublicChatIfPossible() {
|
||||
val inputMethodManager = getSystemService(BaseActionBarActivity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
inputMethodManager.hideSoftInputFromWindow(serverUrlEditText.windowToken, 0)
|
||||
inputMethodManager.hideSoftInputFromWindow(urlEditText.windowToken, 0)
|
||||
|
||||
val url = serverUrlEditText.text.toString().toLowerCase().replace("http://", "https://")
|
||||
val url = urlEditText.text.toString().toLowerCase().replace("http://", "https://")
|
||||
if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) { return Toast.makeText(this, R.string.fragment_add_public_chat_invalid_url_message, Toast.LENGTH_SHORT).show() }
|
||||
|
||||
setButtonEnabled(false)
|
||||
|
||||
ApplicationContext.getInstance(this).lokiPublicChatManager.addChat(url, 1).successUi {
|
||||
Toast.makeText(this, R.string.fragment_add_public_chat_success_message, Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}.failUi {
|
||||
setButtonEnabled(true)
|
||||
Toast.makeText(this, R.string.fragment_add_public_chat_failed_connect_message, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, R.string.fragment_add_public_chat_connection_failed_message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setButtonEnabled(enabled: Boolean) {
|
||||
addButton.isEnabled = enabled
|
||||
val text = if (enabled) R.string.fragment_add_public_chat_add_button_title else R.string.fragment_add_public_chat_adding_server_button_title
|
||||
val text = if (enabled) R.string.fragment_add_public_chat_add_button_title_1 else R.string.fragment_add_public_chat_add_button_title_2
|
||||
addButton.setText(text)
|
||||
serverUrlEditText.isEnabled = enabled
|
||||
urlEditText.isEnabled = enabled
|
||||
}
|
||||
}
|
@ -43,11 +43,10 @@ class DisplayNameActivity : BaseActionBarActivity() {
|
||||
application.setUpStorageAPIIfNeeded()
|
||||
startActivity(Intent(this, ConversationListActivity::class.java))
|
||||
finish()
|
||||
|
||||
val chatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
|
||||
if (chatAPI != null && name != null) {
|
||||
val publicChatAPI = ApplicationContext.getInstance(this).lokiPublicChatAPI
|
||||
if (publicChatAPI != null) {
|
||||
val servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers()
|
||||
servers.forEach { chatAPI.setDisplayName(name, it) }
|
||||
servers.forEach { publicChatAPI.setDisplayName(name, it) }
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ fun toPx(dp: Int, resources: Resources): Int {
|
||||
return (dp * scale).roundToInt()
|
||||
}
|
||||
|
||||
fun isGroupRecipient(context: Context, recipient: String): Boolean {
|
||||
fun isPublicChat(context: Context, recipient: String): Boolean {
|
||||
return DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats().values.map { it.server }.contains(recipient)
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ class LokiPublicChatManager(private val context: Context) {
|
||||
// Set our name on the server
|
||||
val displayName = TextSecurePreferences.getProfileName(context)
|
||||
if (!TextUtils.isEmpty(displayName)) {
|
||||
ApplicationContext.getInstance(context).lokiPublicChatAPI?.setDisplayName(server, displayName)
|
||||
ApplicationContext.getInstance(context).lokiPublicChatAPI?.setDisplayName(displayName, server)
|
||||
}
|
||||
// Start polling
|
||||
Util.runOnMain{ startPollersIfNeeded() }
|
||||
|
@ -20,14 +20,14 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
companion object {
|
||||
private val friendRequestTableName = "loki_thread_friend_request_database"
|
||||
private val sessionResetTableName = "loki_thread_session_reset_database"
|
||||
public val groupChatMappingTableName = "loki_group_chat_mapping_database"
|
||||
public val publicChatTableName = "loki_public_chat_database"
|
||||
public val threadID = "thread_id"
|
||||
private val friendRequestStatus = "friend_request_status"
|
||||
private val sessionResetStatus = "session_reset_status"
|
||||
public val groupChatJSON = "group_chat_json"
|
||||
public val publicChat = "public_chat"
|
||||
@JvmStatic val createFriendRequestTableCommand = "CREATE TABLE $friendRequestTableName ($threadID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
@JvmStatic val createSessionResetTableCommand = "CREATE TABLE $sessionResetTableName ($threadID INTEGER PRIMARY KEY, $sessionResetStatus INTEGER DEFAULT 0);"
|
||||
@JvmStatic val createGroupChatMappingTableCommand = "CREATE TABLE $groupChatMappingTableName ($threadID INTEGER PRIMARY KEY, $groupChatJSON TEXT);"
|
||||
@JvmStatic val createGroupChatMappingTableCommand = "CREATE TABLE $publicChatTableName ($threadID INTEGER PRIMARY KEY, $publicChat TEXT);"
|
||||
}
|
||||
|
||||
override fun getThreadID(hexEncodedPublicKey: String): Long {
|
||||
@ -94,50 +94,46 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
fun getAllPublicChats(): Map<Long, LokiPublicChat> {
|
||||
val database = databaseHelper.readableDatabase
|
||||
var cursor: Cursor? = null
|
||||
|
||||
val result = mutableMapOf<Long, LokiPublicChat>()
|
||||
try {
|
||||
val map = mutableMapOf<Long, LokiPublicChat>()
|
||||
cursor = database.rawQuery("select * from $groupChatMappingTableName", null)
|
||||
cursor = database.rawQuery("select * from $publicChatTableName", null)
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
val threadID = cursor.getLong(Companion.threadID)
|
||||
val string = cursor.getString(groupChatJSON)
|
||||
val chat = LokiPublicChat.fromJSON(string)
|
||||
if (chat != null) { map[threadID] = chat }
|
||||
val threadID = cursor.getLong(threadID)
|
||||
val string = cursor.getString(publicChat)
|
||||
val publicChat = LokiPublicChat.fromJSON(string)
|
||||
if (publicChat != null) { result[threadID] = publicChat }
|
||||
}
|
||||
return map
|
||||
} catch (e: Exception) {
|
||||
|
||||
// Do nothing
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
return mapOf()
|
||||
return result
|
||||
}
|
||||
|
||||
fun getAllPublicChatServers(): Set<String> {
|
||||
return getAllPublicChats().values.fold(setOf<String>()) { set, chat -> set.plus(chat.server) }
|
||||
return getAllPublicChats().values.fold(setOf()) { set, chat -> set.plus(chat.server) }
|
||||
}
|
||||
|
||||
override fun getPublicChat(threadID: Long): LokiPublicChat? {
|
||||
if (threadID < 0) { return null }
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(groupChatMappingTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
||||
val string = cursor.getString(groupChatJSON)
|
||||
LokiPublicChat.fromJSON(string)
|
||||
return database.get(publicChatTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
||||
val publicChatAsJSON = cursor.getString(publicChat)
|
||||
LokiPublicChat.fromJSON(publicChatAsJSON)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPublicChat(groupChat: LokiPublicChat, threadID: Long) {
|
||||
override fun setPublicChat(publicChat: LokiPublicChat, threadID: Long) {
|
||||
if (threadID < 0) { return }
|
||||
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.threadID, threadID)
|
||||
contentValues.put(Companion.groupChatJSON, JsonUtil.toJson(groupChat.toJSON()))
|
||||
database.insertOrUpdate(groupChatMappingTableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
|
||||
contentValues.put(Companion.publicChat, JsonUtil.toJson(publicChat.toJSON()))
|
||||
database.insertOrUpdate(publicChatTableName, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
|
||||
}
|
||||
|
||||
override fun removePublicChat(threadID: Long) {
|
||||
databaseHelper.writableDatabase.delete(groupChatMappingTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
|
||||
databaseHelper.writableDatabase.delete(publicChatTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() ))
|
||||
}
|
||||
}
|
@ -213,7 +213,7 @@ public class MessageSender {
|
||||
|
||||
// Just send the message normally if it's a group message
|
||||
String recipientPublicKey = recipient.getAddress().serialize();
|
||||
if (GeneralUtilitiesKt.isGroupRecipient(context, recipientPublicKey)) {
|
||||
if (GeneralUtilitiesKt.isPublicChat(context, recipientPublicKey)) {
|
||||
jobManager.add(new PushTextSendJob(messageId, recipient.getAddress()));
|
||||
return;
|
||||
}
|
||||
@ -243,7 +243,7 @@ public class MessageSender {
|
||||
|
||||
// Just send the message normally if it's a group message
|
||||
String recipientPublicKey = recipient.getAddress().serialize();
|
||||
if (GeneralUtilitiesKt.isGroupRecipient(context, recipientPublicKey)) {
|
||||
if (GeneralUtilitiesKt.isPublicChat(context, recipientPublicKey)) {
|
||||
PushMediaSendJob.enqueue(context, jobManager, messageId, recipient.getAddress());
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user