Commit 1fa84b15 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'Blackhole16-master' into develop

parents 4cffe95b f0c5bde4
...@@ -38,7 +38,7 @@ public class DatabaseManager extends SQLiteOpenHelper implements ...@@ -38,7 +38,7 @@ public class DatabaseManager extends SQLiteOpenHelper implements
OnLoadListener, OnClearListener { OnLoadListener, OnClearListener {
private static final String DATABASE_NAME = "xabber.db"; 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( private static final SQLiteException DOWNGRAD_EXCEPTION = new SQLiteException(
"Database file was deleted"); "Database file was deleted");
......
...@@ -227,6 +227,11 @@ public class SettingsManager implements OnInitializedListener, ...@@ -227,6 +227,11 @@ public class SettingsManager implements OnInitializedListener,
R.bool.events_vibro_default); 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() { public static boolean eventsIgnoreSystemVibro() {
return getBoolean(R.string.events_ignore_system_vibro_key, return getBoolean(R.string.events_ignore_system_vibro_key,
R.bool.events_ignore_system_vibro_default); R.bool.events_ignore_system_vibro_default);
......
...@@ -22,6 +22,7 @@ import com.xabber.android.data.account.StatusMode; ...@@ -22,6 +22,7 @@ import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.ChatAction; import com.xabber.android.data.message.ChatAction;
import com.xabber.android.data.message.MessageItem; 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.android.data.roster.RosterManager;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.delay.Delay; import com.xabber.xmpp.delay.Delay;
...@@ -199,6 +200,11 @@ public class RoomChat extends AbstractChat { ...@@ -199,6 +200,11 @@ public class RoomChat extends AbstractChat {
onInvitationDeclined(mucUser.getDecline().getFrom(), mucUser.getDecline().getReason()); onInvitationDeclined(mucUser.getDecline().getFrom(), mucUser.getDecline().getReason());
return true; 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 text = message.getBody();
final String subject = message.getSubject(); final String subject = message.getSubject();
if (text == null && subject == null) { if (text == null && subject == null) {
......
...@@ -71,6 +71,10 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -71,6 +71,10 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
* Sound, associated with chat for user in account. * Sound, associated with chat for user in account.
*/ */
private final NestedMap<Uri> sounds; 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() { private ChatManager() {
chatInputs = new NestedMap<ChatInput>(); chatInputs = new NestedMap<ChatInput>();
...@@ -79,6 +83,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -79,6 +83,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
showText = new NestedMap<>(); showText = new NestedMap<>();
makeVibro = new NestedMap<Boolean>(); makeVibro = new NestedMap<Boolean>();
notifyVisible = new NestedMap<Boolean>(); notifyVisible = new NestedMap<Boolean>();
suppress100 = new NestedMap<Boolean>();
} }
public static ChatManager getInstance() { public static ChatManager getInstance() {
...@@ -92,6 +97,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -92,6 +97,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
final NestedMap<ShowMessageTextInNotification> showText = new NestedMap<>(); final NestedMap<ShowMessageTextInNotification> showText = new NestedMap<>();
final NestedMap<Boolean> makeVibro = new NestedMap<Boolean>(); final NestedMap<Boolean> makeVibro = new NestedMap<Boolean>();
final NestedMap<Uri> sounds = new NestedMap<Uri>(); final NestedMap<Uri> sounds = new NestedMap<Uri>();
final NestedMap<Boolean> suppress100 = new NestedMap<Boolean>();
Cursor cursor; Cursor cursor;
cursor = PrivateChatTable.getInstance().list(); cursor = PrivateChatTable.getInstance().list();
try { try {
...@@ -158,18 +164,31 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -158,18 +164,31 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
cursor.close(); 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() { Application.getInstance().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
onLoaded(privateChats, notifyVisible, showText, makeVibro, onLoaded(privateChats, notifyVisible, showText, makeVibro,
sounds); sounds, suppress100);
} }
}); });
} }
private void onLoaded(Set<BaseEntity> privateChats, private void onLoaded(Set<BaseEntity> privateChats,
NestedMap<Boolean> notifyVisible, NestedMap<ShowMessageTextInNotification> showText, 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) for (BaseEntity baseEntity : privateChats)
this.privateChats.put(baseEntity.getAccount(), this.privateChats.put(baseEntity.getAccount(),
baseEntity.getUser(), PRIVATE_CHAT); baseEntity.getUser(), PRIVATE_CHAT);
...@@ -177,6 +196,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -177,6 +196,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
this.showText.addAll(showText); this.showText.addAll(showText);
this.makeVibro.addAll(vibro); this.makeVibro.addAll(vibro);
this.sounds.addAll(sounds); this.sounds.addAll(sounds);
this.suppress100.addAll(suppress100);
} }
@Override @Override
...@@ -187,6 +207,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -187,6 +207,7 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener {
showText.clear(accountItem.getAccount()); showText.clear(accountItem.getAccount());
makeVibro.clear(accountItem.getAccount()); makeVibro.clear(accountItem.getAccount());
notifyVisible.clear(accountItem.getAccount()); notifyVisible.clear(accountItem.getAccount());
suppress100.clear(accountItem.getAccount());
} }
/** /**
...@@ -391,4 +412,26 @@ public class ChatManager implements OnLoadListener, OnAccountRemovedListener { ...@@ -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 { ...@@ -53,6 +53,8 @@ public class ChatContactSettingsFragment extends BaseSettingsFragment {
.isMakeVibro(account, user)); .isMakeVibro(account, user));
putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance() putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance()
.getSound(account, user)); .getSound(account, user));
putValue(map, R.string.chat_events_suppress_100_key, ChatManager.getInstance()
.isSuppress100(account, user));
return map; return map;
} }
...@@ -82,6 +84,9 @@ public class ChatContactSettingsFragment extends BaseSettingsFragment { ...@@ -82,6 +84,9 @@ public class ChatContactSettingsFragment extends BaseSettingsFragment {
ChatManager.getInstance().setSound(account, user, ChatManager.getInstance().setSound(account, user,
getUri(result, R.string.chat_events_sound_key)); 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; return true;
} }
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
<string name="events_message_none">Don\'t notify</string> <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_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_visible_chat">Notify in current chat\nNotify on incoming messages in current chat</string>
<string name="events_suppress_100">Suppress some status messages\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="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_accounts">XMPP accounts\nManage accounts</string>
<string name="preference_security">Security\nSecurity settings</string> <string name="preference_security">Security\nSecurity settings</string>
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
<item>com.xabber.android.data.extension.otr.OTRTable</item> <item>com.xabber.android.data.extension.otr.OTRTable</item>
<item>com.xabber.android.data.message.chat.VibroTable</item> <item>com.xabber.android.data.message.chat.VibroTable</item>
<item>com.xabber.android.data.notification.NotificationTable</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> <item>com.xabber.android.data.message.phrase.PhraseTable</item>
</string-array> </string-array>
...@@ -495,6 +496,9 @@ ...@@ -495,6 +496,9 @@
<string name="chat_events_vibro_key">chat_events_vibro</string> <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_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 --> <!-- preference_xabber -->
<string name="preference_xabber_key">preference_xabber</string> <string name="preference_xabber_key">preference_xabber</string>
......
...@@ -40,4 +40,8 @@ ...@@ -40,4 +40,8 @@
android:key="@string/chat_events_visible_chat_key" android:key="@string/chat_events_visible_chat_key"
android:title="@string/events_visible_chat" android:title="@string/events_visible_chat"
/> />
<CheckBoxPreference
android:key="@string/chat_events_suppress_100_key"
android:title="@string/events_suppress_100"
/>
</PreferenceScreen> </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