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