Commit ad9187ca authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'master' of https://github.com/Blackhole16/xabber-android into Blackhole16-master

parents 14f86fcb c0c12250
......@@ -38,7 +38,7 @@ public class DatabaseManager extends SQLiteOpenHelper implements
OnLoadListener, OnClearListener {
private static final String DATABASE_NAME = "xabber.db";
private static final int DATABASE_VERSION = 67;
private static final int DATABASE_VERSION = 68;
private static final SQLiteException DOWNGRAD_EXCEPTION = new SQLiteException(
"Database file was deleted");
......
......@@ -227,6 +227,11 @@ public class SettingsManager implements OnInitializedListener,
R.bool.events_vibro_default);
}
public static boolean eventsSuppress100() {
return getBoolean(R.string.chat_events_suppress_100_key,
R.bool.chat_events_suppress_100_default);
}
public static boolean eventsIgnoreSystemVibro() {
return getBoolean(R.string.events_ignore_system_vibro_key,
R.bool.events_ignore_system_vibro_default);
......
......@@ -22,6 +22,7 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.ChatAction;
import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.delay.Delay;
......@@ -199,6 +200,11 @@ public class RoomChat extends AbstractChat {
onInvitationDeclined(mucUser.getDecline().getFrom(), mucUser.getDecline().getReason());
return true;
}
if (mucUser != null && mucUser.getStatus() != null && mucUser.getStatus().getCode().equals("100")
&& ChatManager.getInstance().isSuppress100(account, user)) {
// 'This room is not anonymous'
return true;
}
final String text = message.getBody();
final String subject = message.getSubject();
if (text == null && subject == null) {
......
......@@ -71,6 +71,10 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
* Sound, associated with chat for user in account.
*/
private final NestedMap<Uri> sounds;
/**
* Whether 'This room is not anonymous'-messages (Status Code 100) should be suppressed
*/
private final NestedMap<Boolean> suppress100;
private ChatManager() {
chatInputs = new NestedMap<ChatInput>();
......@@ -79,6 +83,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
showText = new NestedMap<>();
makeVibro = new NestedMap<Boolean>();
notifyVisible = new NestedMap<Boolean>();
suppress100 = new NestedMap<Boolean>();
}
public static ChatManager getInstance() {
......@@ -92,6 +97,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
final NestedMap<ShowMessageTextInNotification> showText = new NestedMap<>();
final NestedMap<Boolean> makeVibro = new NestedMap<Boolean>();
final NestedMap<Uri> sounds = new NestedMap<Uri>();
final NestedMap<Boolean> suppress100 = new NestedMap<Boolean>();
Cursor cursor;
cursor = PrivateChatTable.getInstance().list();
try {
......@@ -158,18 +164,31 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
cursor.close();
}
cursor = Suppress100Table.getInstance().list();
try {
if (cursor.moveToFirst()) {
do {
makeVibro.put(Suppress100Table.getAccount(cursor),
Suppress100Table.getUser(cursor),
Suppress100Table.getValue(cursor));
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
onLoaded(privateChats, notifyVisible, showText, makeVibro,
sounds);
sounds, suppress100);
}
});
}
private void onLoaded(Set<BaseEntity> privateChats,
NestedMap<Boolean> notifyVisible, NestedMap<ShowMessageTextInNotification> showText,
NestedMap<Boolean> vibro, NestedMap<Uri> sounds) {
NestedMap<Boolean> vibro, NestedMap<Uri> sounds, NestedMap<Boolean> suppress100) {
for (BaseEntity baseEntity : privateChats)
this.privateChats.put(baseEntity.getAccount(),
baseEntity.getUser(), PRIVATE_CHAT);
......@@ -177,6 +196,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
this.showText.addAll(showText);
this.makeVibro.addAll(vibro);
this.sounds.addAll(sounds);
this.suppress100.addAll(suppress100);
}
@Override
......@@ -187,6 +207,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
showText.clear(accountItem.getAccount());
makeVibro.clear(accountItem.getAccount());
notifyVisible.clear(accountItem.getAccount());
suppress100.clear(accountItem.getAccount());
}
/**
......@@ -391,4 +412,26 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
});
}
/**
* @param account
* @param user
* @return Whether 'This Room is not Anonymous'-messages (Status Code 100) should be suppressed.
*/
public boolean isSuppress100(String account, String user) {
Boolean value = suppress100.get(account, user);
if (value == null)
return SettingsManager.eventsSuppress100();
return value;
}
public void setSuppress100(final String account, final String user,
final boolean value) {
suppress100.put(account, user, value);
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
Suppress100Table.getInstance().write(account, user, value);
}
});
}
}
package com.xabber.android.data.message.chat;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import com.xabber.android.data.DatabaseManager;
/**
* Storage with suppress100 settings for each chat.
* @author <a href="mailto:jaro.fietz@uniscon.de">Jaro Fietz</a>.
*/
class Suppress100Table extends AbstractChatPropertyTable<Boolean> {
static final String NAME = "chat_suppress_100";
private final static Suppress100Table instance;
static {
instance = new Suppress100Table(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static Suppress100Table getInstance() {
return instance;
}
private Suppress100Table(DatabaseManager databaseManager) {
super(databaseManager);
}
@Override
protected String getTableName() {
return NAME;
}
@Override
String getValueType() {
return "INTEGER";
}
@Override
void bindValue(SQLiteStatement writeStatement, Boolean value) {
writeStatement.bindLong(3, value ? 1 : 0);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
switch (toVersion) {
case 68:
initialMigrate(db, NAME, "INTEGER");
break;
default:
break;
}
}
static boolean getValue(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields.VALUE)) != 0;
}
}
......@@ -53,6 +53,8 @@ public class ChatContactSettingsFragment extends BaseSettingsFragment {
.isMakeVibro(account, user));
putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance()
.getSound(account, user));
putValue(map, R.string.chat_events_suppress_100_key, ChatManager.getInstance()
.isSuppress100(account, user));
return map;
}
......@@ -82,6 +84,9 @@ public class ChatContactSettingsFragment extends BaseSettingsFragment {
ChatManager.getInstance().setSound(account, user,
getUri(result, R.string.chat_events_sound_key));
if (hasChanges(source, result, R.string.chat_events_suppress_100_key))
ChatManager.getInstance().setSuppress100(account, user,
getBoolean(result, R.string.chat_events_suppress_100_key));
return true;
}
......
......@@ -65,6 +65,7 @@
<string name="events_message_none">Nicht benachrichtigen</string>
<string name="events_show_text">Nachricht in der Statusleiste anzeigen\nNachricht in der Statusleiste anzeigen</string>
<string name="events_visible_chat">Benachrichtigung bei offenem Chat\nBenachrichtigung bei eingehender Nachricht im offenen Chat</string>
<string name="events_suppress_100">Unterdrücke Status Code 100\nUnterdrücke \'Dieser Raum ist nicht anonym\' Meldungen</string>
<string name="negative_priotiry_summary">%s (Du wirst aus keinem Chat Nachrichten erhalten)</string>
<string name="preference_accounts">XMPP-Konten\nKonten verwalten</string>
<string name="preference_security">Sicherheit\nSicherheitseinstellungen</string>
......
......@@ -64,6 +64,7 @@
<string name="events_message_none">Don\'t notify</string>
<string name="events_show_text">Show message in notification\nShow message text in notification area</string>
<string name="events_visible_chat">Notify in current chat\nNotify on incoming messages in current chat</string>
<string name="events_suppress_100">Suppress Status Code 100\nDon\'t get \'This room is not anonymous\' messages</string>
<string name="negative_priotiry_summary">%s (you won\'t receive messages from any chat)</string>
<string name="preference_accounts">XMPP accounts\nManage accounts</string>
<string name="preference_security">Security\nSecurity settings</string>
......
......@@ -74,6 +74,7 @@
<item>com.xabber.android.data.extension.otr.OTRTable</item>
<item>com.xabber.android.data.message.chat.VibroTable</item>
<item>com.xabber.android.data.notification.NotificationTable</item>
<item>com.xabber.android.data.message.chat.Suppress100Table</item>
<item>com.xabber.android.data.message.phrase.PhraseTable</item>
</string-array>
......@@ -495,6 +496,9 @@
<string name="chat_events_vibro_key">chat_events_vibro</string>
<string name="chat_events_visible_chat_key">chat_events_visible_chat</string>
<string name="chat_events_suppress_100_key">chat_events_suppress_100</string>
<bool name="chat_events_suppress_100_default">false</bool>
<!-- preference_xabber -->
<string name="preference_xabber_key">preference_xabber</string>
......
......@@ -40,4 +40,8 @@
android:key="@string/chat_events_visible_chat_key"
android:title="@string/events_visible_chat"
/>
<CheckBoxPreference
android:key="@string/chat_events_suppress_100_key"
android:title="@string/events_suppress_100"
/>
</PreferenceScreen>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment