aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-05-30 22:31:05 +0200
committerfiaxh <git@mx.ax.lt>2017-05-30 22:33:33 +0200
commit387433ebb9bab442502f812e0364111f37270bcb (patch)
tree5dba69992da0a402380d7bde27433c750f5be920 /libdino
parent3a8df2069eba3a5a4174749fc46a6698c1877ec1 (diff)
downloaddino-387433ebb9bab442502f812e0364111f37270bcb.tar.gz
dino-387433ebb9bab442502f812e0364111f37270bcb.zip
Notifications + typing notifications + message marker settings per conversation
Diffstat (limited to 'libdino')
-rw-r--r--libdino/data/dino.gschema.xml14
-rw-r--r--libdino/src/entity/conversation.vala44
-rw-r--r--libdino/src/service/chat_interaction.vala4
-rw-r--r--libdino/src/service/database.vala7
-rw-r--r--libdino/src/settings.vala16
5 files changed, 75 insertions, 10 deletions
diff --git a/libdino/data/dino.gschema.xml b/libdino/data/dino.gschema.xml
index f3d342cf..19cad0e4 100644
--- a/libdino/data/dino.gschema.xml
+++ b/libdino/data/dino.gschema.xml
@@ -1,9 +1,19 @@
<schemalist>
<schema id="org.dino-im" path="/org/dino-im/" gettext-domain="dino">
- <key name="send-read" type="b">
+ <key name="send-typing" type="b">
<default>true</default>
- <summary>Whether to confirm that a message was received per default</summary>
+ <summary>Whether to send typing notifications</summary>
+ </key>
+
+ <key name="send-marker" type="b">
+ <default>true</default>
+ <summary>Whether to confirm that a message was received or read</summary>
+ </key>
+
+ <key name="notifications" type="b">
+ <default>true</default>
+ <summary>Whether to get notifications</summary>
</key>
<key name="convert-utf8-smileys" type="b">
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index e820af4d..d4f2f7a7 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -28,6 +28,14 @@ public class Conversation : Object {
public Type type_ { get; set; }
public Message read_up_to { get; set; }
+ public enum NotifySetting { DEFAULT, ON, OFF, HIGHLIGHT }
+ public NotifySetting notify_setting { get; set; default = NotifySetting.DEFAULT; }
+
+ public enum Setting { DEFAULT, ON, OFF }
+ public Setting send_typing { get; set; default = Setting.DEFAULT; }
+
+ public Setting send_marker { get; set; default = Setting.DEFAULT; }
+
private Database? db;
public Conversation(Jid jid, Account account, Type type) {
@@ -51,6 +59,9 @@ public class Conversation : Object {
encryption = (Encryption) row[db.conversation.encryption];
int? read_up_to = row[db.conversation.read_up_to];
if (read_up_to != null) this.read_up_to = db.get_message_by_id(read_up_to);
+ notify_setting = (NotifySetting) row[db.conversation.notification];
+ send_typing = (Setting) row[db.conversation.send_typing];
+ send_marker = (Setting) row[db.conversation.send_marker];
notify.connect(on_update);
}
@@ -62,7 +73,7 @@ public class Conversation : Object {
.value(db.conversation.jid_id, db.get_jid_id(counterpart))
.value(db.conversation.type_, type_)
.value(db.conversation.encryption, encryption)
- //.value(conversation.read_up_to, new_conversation.read_up_to)
+ .value(db.conversation.read_up_to, read_up_to.id)
.value(db.conversation.active, active);
if (counterpart.is_full()) {
insert.value(db.conversation.resource, counterpart.resourcepart);
@@ -70,10 +81,35 @@ public class Conversation : Object {
if (last_active != null) {
insert.value(db.conversation.last_active, (long) last_active.to_unix());
}
+ insert.value(db.conversation.notification, notify_setting);
+ insert.value(db.conversation.send_typing, send_typing);
+ insert.value(db.conversation.send_marker, send_marker);
id = (int) insert.perform();
notify.connect(on_update);
}
+ public NotifySetting get_notification_setting(StreamInteractor stream_interactor) {
+ Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account);
+ if (notify_setting != NotifySetting.DEFAULT) return notify_setting;
+ if (!Settings.instance().notifications) return NotifySetting.OFF;
+ if (type_ == Type.GROUPCHAT) {
+ bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
+ return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT;
+ } else {
+ return NotifySetting.ON;
+ }
+ }
+
+ public Setting get_send_typing_setting() {
+ if (send_typing != Setting.DEFAULT) return send_typing;
+ return Settings.instance().send_typing ? Setting.ON : Setting.OFF;
+ }
+
+ public Setting get_send_marker_setting() {
+ if (send_marker != Setting.DEFAULT) return send_marker;
+ return Settings.instance().send_marker ? Setting.ON : Setting.OFF;
+ }
+
public bool equals(Conversation? conversation) {
if (conversation == null) return false;
return equals_func(this, conversation);
@@ -110,6 +146,12 @@ public class Conversation : Object {
update.set_null(db.conversation.last_active);
}
break;
+ case "notify-setting":
+ update.set(db.conversation.notification, notify_setting); break;
+ case "send-typing":
+ update.set(db.conversation.send_typing, send_typing); break;
+ case "send-marker":
+ update.set(db.conversation.send_marker, send_marker); break;
}
update.perform();
}
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala
index 891abf29..f13623ea 100644
--- a/libdino/src/service/chat_interaction.vala
+++ b/libdino/src/service/chat_interaction.vala
@@ -135,7 +135,7 @@ public class ChatInteraction : StreamInteractionModule, Object {
private void send_chat_marker(Conversation conversation, Entities.Message message, string marker) {
Core.XmppStream stream = stream_interactor.get_stream(conversation.account);
- if (stream != null && Settings.instance().send_read &&
+ if (stream != null && Settings.instance().send_marker &&
Xep.ChatMarkers.Module.requests_marking(message.stanza)) {
stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.stanza.from, message.stanza_id, message.get_type_string(), marker);
}
@@ -143,7 +143,7 @@ public class ChatInteraction : StreamInteractionModule, Object {
private void send_chat_state_notification(Conversation conversation, string state) {
Core.XmppStream stream = stream_interactor.get_stream(conversation.account);
- if (stream != null && Settings.instance().send_read &&
+ if (stream != null && Settings.instance().send_typing &&
conversation.type_ != Conversation.Type.GROUPCHAT) {
stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart.to_string(), state);
}
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index 19ca0b06..ae8d5412 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -6,7 +6,7 @@ using Dino.Entities;
namespace Dino {
public class Database : Qlite.Database {
- private const int VERSION = 2;
+ private const int VERSION = 3;
public class AccountTable : Table {
public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true };
@@ -86,10 +86,13 @@ public class Database : Qlite.Database {
public Column<int> type_ = new Column.Integer("type");
public Column<int> encryption = new Column.Integer("encryption");
public Column<int> read_up_to = new Column.Integer("read_up_to");
+ public Column<int> notification = new Column.Integer("notification") { min_version=3 };
+ public Column<int> send_typing = new Column.Integer("send_typing") { min_version=3 };
+ public Column<int> send_marker = new Column.Integer("send_marker") { min_version=3 };
internal ConversationTable(Database db) {
base(db, "conversation");
- init({id, account_id, jid_id, resource, active, last_active, type_, encryption, read_up_to});
+ init({id, account_id, jid_id, resource, active, last_active, type_, encryption, read_up_to, notification, send_typing, send_marker});
}
}
diff --git a/libdino/src/settings.vala b/libdino/src/settings.vala
index 3700583b..45d2192f 100644
--- a/libdino/src/settings.vala
+++ b/libdino/src/settings.vala
@@ -4,9 +4,19 @@ public class Settings {
private GLib.Settings gsettings;
- public bool send_read {
- get { return gsettings.get_boolean("send-read"); }
- set { gsettings.set_boolean("send-read", value); }
+ public bool send_typing {
+ get { return gsettings.get_boolean("send-typing"); }
+ set { gsettings.set_boolean("send-typing", value); }
+ }
+
+ public bool send_marker {
+ get { return gsettings.get_boolean("send-marker"); }
+ set { gsettings.set_boolean("send-marker", value); }
+ }
+
+ public bool notifications {
+ get { return gsettings.get_boolean("notifications"); }
+ set { gsettings.set_boolean("notifications", value); }
}
public bool convert_utf8_smileys {