diff options
author | fiaxh <git@mx.ax.lt> | 2017-06-11 13:59:24 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-06-11 13:59:24 +0200 |
commit | e63d59eb3450471b33a22efda6df8871818209b1 (patch) | |
tree | 11660e951bf049318f6c0eae8a60fcfbff4c029e /libdino/src | |
parent | 205bd444a5ba9d119952ecddbf815f50174da8c7 (diff) | |
download | dino-e63d59eb3450471b33a22efda6df8871818209b1.tar.gz dino-e63d59eb3450471b33a22efda6df8871818209b1.zip |
Muc Invite + Kick
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/chat_interaction.vala | 14 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 2 | ||||
-rw-r--r-- | libdino/src/service/muc_manager.vala | 47 |
3 files changed, 45 insertions, 18 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index f13623ea..d7b8f839 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -124,26 +124,36 @@ public class ChatInteraction : StreamInteractionModule, Object { } private void on_message_received(Entities.Message message, Conversation conversation) { + send_delivery_receipt(conversation, message); if (is_active_focus(conversation)) { check_send_read(); conversation.read_up_to = message; send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_DISPLAYED); } else { + send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_RECEIVED); conversation_unread(conversation); } } 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_marker && + if (stream != null && + (marker == Xep.ChatMarkers.MARKER_RECEIVED || conversation.get_send_marker_setting() == Conversation.Setting.ON) && 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); } } + private void send_delivery_receipt(Conversation conversation, Entities.Message message) { + Core.XmppStream stream = stream_interactor.get_stream(conversation.account); + if (stream != null && Xep.MessageDeliveryReceipts.Module.requests_receipt(message.stanza)) { + stream.get_module(Xep.MessageDeliveryReceipts.Module.IDENTITY).send_received(stream, message.from.to_string(), message.stanza_id); + } + } + 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_typing && + if (stream != null && conversation.get_send_typing_setting() == Conversation.Setting.ON && 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/message_processor.vala b/libdino/src/service/message_processor.vala index e8fa3c03..ccaec915 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -72,7 +72,7 @@ public class MessageProcessor : StreamInteractionModule, Object { new_message.stanza_id = message.id; Jid from_jid = new Jid(message.from); if (!account.bare_jid.equals_bare(from_jid) || - stream_interactor.get_module(MucManager.IDENTITY).get_nick(from_jid.bare_jid, account) == from_jid.resourcepart) { + from_jid.equals(stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(from_jid.bare_jid, account))) { new_message.direction = Entities.Message.DIRECTION_RECEIVED; } else { new_message.direction = Entities.Message.DIRECTION_SENT; diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 71a66bb4..d6132d19 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -28,7 +28,7 @@ public class MucManager : StreamInteractionModule, Object { } public void join(Account account, Jid jid, string? nick, string? password) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; string nick_ = nick ?? account.bare_jid.localpart ?? account.bare_jid.domainpart; set_autojoin(stream, jid, nick_, password); @@ -36,7 +36,7 @@ public class MucManager : StreamInteractionModule, Object { } public void part(Account account, Jid jid) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; unset_autojoin(stream, jid); stream.get_module(Xep.Muc.Module.IDENTITY).exit(stream, jid.bare_jid.to_string()); @@ -47,7 +47,7 @@ public class MucManager : StreamInteractionModule, Object { [CCode (has_target = false)] public delegate void OnResult(Jid jid, Xep.DataForms.DataForm data_form, Object? store); public void get_config_form(Account account, Jid jid, OnResult on_result, Object? store) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream == null) return; stream.get_module(Xep.Muc.Module.IDENTITY).get_config_form(stream, jid.to_string(), (stream, jid, data_form, store) => { Tuple<OnResult, Object?> tuple = store as Tuple<OnResult, Object?>; @@ -56,20 +56,31 @@ public class MucManager : StreamInteractionModule, Object { } public void change_subject(Account account, Jid jid, string subject) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_subject(stream, jid.bare_jid.to_string(), subject); } public void change_nick(Account account, Jid jid, string new_nick) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).change_nick(stream, jid.bare_jid.to_string(), new_nick); } + public void invite(Account account, Jid muc, Jid invitee) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).invite(stream, muc.bare_jid.to_string(), invitee.bare_jid.to_string()); + } + public void kick(Account account, Jid jid, string nick) { - Core.XmppStream stream = stream_interactor.get_stream(account); + Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) stream.get_module(Xep.Muc.Module.IDENTITY).kick(stream, jid.bare_jid.to_string(), nick); } + public bool kick_possible(Account account, Jid occupant) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) return stream.get_module(Xep.Muc.Module.IDENTITY).kick_possible(stream, occupant.to_string()); + return false; + } + public ArrayList<Jid>? get_occupants(Jid jid, Account account) { if (is_groupchat(jid, account)) { return stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(jid, account); @@ -79,9 +90,9 @@ public class MucManager : StreamInteractionModule, Object { public ArrayList<Jid>? get_other_occupants(Jid jid, Account account) { ArrayList<Jid>? occupants = get_occupants(jid, account); - string? nick = get_nick(jid, account); - if (occupants != null && nick != null) { - occupants.remove(new Jid(@"$(jid.bare_jid)/$nick")); + Jid? own_jid = get_own_jid(jid, account); + if (occupants != null && own_jid != null) { + occupants.remove(own_jid); } return occupants; } @@ -142,11 +153,15 @@ public class MucManager : StreamInteractionModule, Object { return null; } + public Xep.Muc.Role? get_role(Jid jid, Account account) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_occupant_role(jid.to_string()); + return null; + } + public Xep.Muc.Affiliation? get_affiliation(Jid muc_jid, Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) { - return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_affiliation(muc_jid.to_string(), jid.to_string()); - } + if (stream != null) return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_affiliation(muc_jid.to_string(), jid.to_string()); return null; } @@ -170,17 +185,19 @@ public class MucManager : StreamInteractionModule, Object { return null; } - public string? get_nick(Jid jid, Account account) { + public Jid? get_own_jid(Jid muc_jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY); - if (flag != null) return flag.get_muc_nick(jid.bare_jid.to_string()); + if (flag == null) return null; + string? nick = flag.get_muc_nick(muc_jid.bare_jid.to_string()); + if (nick != null) return new Jid.with_resource(muc_jid.bare_jid.to_string(), nick); } return null; } public bool is_joined(Jid jid, Account account) { - return get_nick(jid, account) != null; + return get_own_jid(jid, account) != null; } private void on_account_added(Account account) { |