diff options
author | fiaxh <git@mx.ax.lt> | 2017-03-19 12:55:36 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-03-20 22:28:27 +0100 |
commit | db57a973534f099af2b150f1a1307d1948553d9f (patch) | |
tree | 238ae1d4e53412a33e3febd07318dfd38b0eb2f8 | |
parent | 233f2b35d033cd20d1ac648bf2d723bcb7a918fc (diff) | |
download | dino-db57a973534f099af2b150f1a1307d1948553d9f.tar.gz dino-db57a973534f099af2b150f1a1307d1948553d9f.zip |
Add typed identity to manager modules and stream flags
63 files changed, 341 insertions, 447 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 032bd576..1c0a3b51 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -7,7 +7,8 @@ using Dino.Entities; namespace Dino { public class AvatarManager : StreamInteractionModule, Object { - public const string id = "avatar_manager"; + public static ModuleIdentity<AvatarManager> IDENTITY = new ModuleIdentity<AvatarManager>("avatar_manager"); + public string id { get { return IDENTITY.id; } } public signal void received_avatar(Pixbuf avatar, Jid jid, Account account); @@ -46,7 +47,7 @@ public class AvatarManager : StreamInteractionModule, Object { public Pixbuf? get_avatar(Account account, Jid jid) { Jid jid_ = jid; - if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) { + if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { jid_ = jid.bare_jid; } string? user_avatars_id = user_avatars[jid_]; @@ -61,7 +62,6 @@ public class AvatarManager : StreamInteractionModule, Object { } public void publish(Account account, string file) { - print(file + "\n"); try { Pixbuf pixbuf = new Pixbuf.from_file(file); if (pixbuf.width >= pixbuf.height && pixbuf.width > MAX_PIXEL) { @@ -83,14 +83,6 @@ public class AvatarManager : StreamInteractionModule, Object { } } - public static AvatarManager? get_instance(StreamInteractor stream_interaction) { - return (AvatarManager) stream_interaction.get_module(id); - } - - internal string get_id() { - return id; - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xep.UserAvatars.Module.IDENTITY).received_avatar.connect((stream, jid, id) => on_user_avatar_received(account, new Jid(jid), id) diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 88ddbd19..f6da1ee6 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -6,7 +6,8 @@ using Dino.Entities; namespace Dino { public class ChatInteraction : StreamInteractionModule, Object { - private const string id = "chat_interaction"; + public static ModuleIdentity<ChatInteraction> IDENTITY = new ModuleIdentity<ChatInteraction>("chat_interaction"); + public string id { get { return IDENTITY.id; } } public signal void conversation_read(Conversation conversation); public signal void conversation_unread(Conversation conversation); @@ -26,8 +27,8 @@ public class ChatInteraction : StreamInteractionModule, Object { private ChatInteraction(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; Timeout.add_seconds(30, update_interactions); - MessageManager.get_instance(stream_interactor).message_received.connect(on_message_received); - MessageManager.get_instance(stream_interactor).message_sent.connect(on_message_sent); + stream_interactor.get_module(MessageManager.IDENTITY).message_received.connect(on_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).message_sent.connect(on_message_sent); } public bool is_active_focus(Conversation? conversation = null) { @@ -67,14 +68,6 @@ public class ChatInteraction : StreamInteractionModule, Object { on_conversation_focused(conversation); } - internal string get_id() { - return id; - } - - public static ChatInteraction? get_instance(StreamInteractor stream_interactor) { - return (ChatInteraction) stream_interactor.get_module(id); - } - private void on_message_sent(Entities.Message message, Conversation conversation) { last_input_interaction.unset(conversation); last_interface_interaction.unset(conversation); @@ -86,7 +79,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (conversation == null) return; conversation_read(selected_conversation); check_send_read(); - selected_conversation.read_up_to = MessageManager.get_instance(stream_interactor).get_last_message(conversation); + selected_conversation.read_up_to = stream_interactor.get_module(MessageManager.IDENTITY).get_last_message(conversation); } private void on_conversation_unfocused(Conversation? conversation) { @@ -100,7 +93,7 @@ public class ChatInteraction : StreamInteractionModule, Object { private void check_send_read() { if (selected_conversation == null || selected_conversation.type_ == Conversation.Type.GROUPCHAT) return; - Entities.Message? message = MessageManager.get_instance(stream_interactor).get_last_message(selected_conversation); + Entities.Message? message = stream_interactor.get_module(MessageManager.IDENTITY).get_last_message(selected_conversation); if (message != null && message.direction == Entities.Message.DIRECTION_RECEIVED && message.stanza != null && !message.equals(selected_conversation.read_up_to)) { selected_conversation.read_up_to = message; diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index 263bc815..17e31c01 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -109,7 +109,7 @@ public class ConnectionManager { if (!connection_todo.contains(account)) { stream_states.unset(account); } else { - interpret_reconnect_flags(account, StreamError.Flag.get_flag(stream) ?? + interpret_reconnect_flags(account, stream.get_flag(StreamError.Flag.IDENTITY) ?? new StreamError.Flag() { reconnection_recomendation = StreamError.Flag.Reconnect.NOW }); } } diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index df4300e2..ada9ee9d 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -5,8 +5,8 @@ using Dino.Entities; namespace Dino { public class ConversationManager : StreamInteractionModule, Object { - - public const string id = "conversation_manager"; + public static ModuleIdentity<ConversationManager> IDENTITY = new ModuleIdentity<ConversationManager>("conversation_manager"); + public string id { get { return IDENTITY.id; } } public signal void conversation_activated(Conversation conversation); @@ -25,9 +25,9 @@ public class ConversationManager : StreamInteractionModule, Object { this.stream_interactor = stream_interactor; stream_interactor.add_module(this); stream_interactor.account_added.connect(on_account_added); - MucManager.get_instance(stream_interactor).groupchat_joined.connect(on_groupchat_joined); - MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_message_received); - MessageManager.get_instance(stream_interactor).message_sent.connect(on_message_sent); + stream_interactor.get_module(MucManager.IDENTITY).groupchat_joined.connect(on_groupchat_joined); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_received.connect(on_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).message_sent.connect(on_message_sent); } public Conversation? get_conversation(Jid jid, Account account) { @@ -55,14 +55,6 @@ public class ConversationManager : StreamInteractionModule, Object { } - public string get_id() { - return id; - } - - public static ConversationManager? get_instance(StreamInteractor stream_interaction) { - return (ConversationManager) stream_interaction.get_module(id); - } - private void on_account_added(Account account) { conversations[account] = new HashMap<Jid, Conversation>(Jid.hash_bare_func, Jid.equals_bare_func); foreach (Conversation conversation in db.get_conversations(account)) { diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala index 221fc4d4..bfd473a2 100644 --- a/libdino/src/service/counterpart_interaction_manager.vala +++ b/libdino/src/service/counterpart_interaction_manager.vala @@ -5,7 +5,8 @@ using Dino.Entities; namespace Dino { public class CounterpartInteractionManager : StreamInteractionModule, Object { - public const string id = "counterpart_interaction_manager"; + public static ModuleIdentity<CounterpartInteractionManager> IDENTITY = new ModuleIdentity<CounterpartInteractionManager>("counterpart_interaction_manager"); + public string id { get { return IDENTITY.id; } } public signal void received_state(Account account, Jid jid, string state); public signal void received_marker(Account account, Jid jid, Entities.Message message, string marker); @@ -24,7 +25,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { private CounterpartInteractionManager(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; stream_interactor.account_added.connect(on_account_added); - MessageManager.get_instance(stream_interactor).message_received.connect(on_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).message_received.connect(on_message_received); } public string? get_chat_state(Account account, Jid jid) { @@ -35,14 +36,6 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { return last_read[jid]; } - public static CounterpartInteractionManager? get_instance(StreamInteractor stream_interactor) { - return (CounterpartInteractionManager) stream_interactor.get_module(id); - } - - internal string get_id() { - return id; - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xep.ChatMarkers.Module.IDENTITY).marker_received.connect( (stream, jid, marker, id) => { on_chat_marker_received(account, new Jid(jid), marker, id); @@ -61,9 +54,9 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object { } private void on_chat_marker_received(Account account, Jid jid, string marker, string stanza_id) { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); if (conversation != null) { - Gee.List<Entities.Message>? messages = MessageManager.get_instance(stream_interactor).get_messages(conversation); + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageManager.IDENTITY).get_messages(conversation); if (messages != null) { // TODO not here foreach (Entities.Message message in messages) { if (message.stanza_id == stanza_id) { diff --git a/libdino/src/service/message_manager.vala b/libdino/src/service/message_manager.vala index d159158b..e83e82b1 100644 --- a/libdino/src/service/message_manager.vala +++ b/libdino/src/service/message_manager.vala @@ -6,7 +6,8 @@ using Dino.Entities; namespace Dino { public class MessageManager : StreamInteractionModule, Object { - public const string ID = "message_manager"; + public static ModuleIdentity<MessageManager> IDENTITY = new ModuleIdentity<MessageManager>("message_manager"); + public string id { get { return IDENTITY.id; } } public signal void pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation); public signal void message_received(Entities.Message message, Conversation conversation); @@ -68,14 +69,6 @@ public class MessageManager : StreamInteractionModule, Object { return db_messages; } - public string get_id() { - return ID; - } - - public static MessageManager? get_instance(StreamInteractor stream_interactor) { - return (MessageManager) stream_interactor.get_module(ID); - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xmpp.Message.Module.IDENTITY).received_message.connect( (stream, message) => { on_message_received(account, message); @@ -85,7 +78,7 @@ public class MessageManager : StreamInteractionModule, Object { private void send_unsent_messages(Account account) { Gee.List<Entities.Message> unsend_messages = db.get_unsend_messages(account); foreach (Entities.Message message in unsend_messages) { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(message.counterpart, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account); if (conversation != null) { send_xmpp_message(message, conversation, true); } @@ -100,7 +93,7 @@ public class MessageManager : StreamInteractionModule, Object { new_message.stanza_id = message.id; Jid from_jid = new Jid(message.from); if (!account.bare_jid.equals_bare(from_jid) || - MucManager.get_instance(stream_interactor).get_nick(from_jid.bare_jid, account) == from_jid.resourcepart) { + stream_interactor.get_module(MucManager.IDENTITY).get_nick(from_jid.bare_jid, account) == from_jid.resourcepart) { new_message.direction = Entities.Message.DIRECTION_RECEIVED; } else { new_message.direction = Entities.Message.DIRECTION_SENT; @@ -113,7 +106,7 @@ public class MessageManager : StreamInteractionModule, Object { Xep.DelayedDelivery.MessageFlag? deleyed_delivery_flag = Xep.DelayedDelivery.MessageFlag.get_flag(message); new_message.time = deleyed_delivery_flag != null ? deleyed_delivery_flag.datetime : new DateTime.now_utc(); new_message.local_time = new DateTime.now_utc(); - Conversation conversation = ConversationManager.get_instance(stream_interactor).get_add_conversation(new_message.counterpart, account); + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_add_conversation(new_message.counterpart, account); pre_message_received(new_message, message, conversation); bool is_uuid = new_message.stanza_id != null && Regex.match_simple("""[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}""", new_message.stanza_id); diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 17a6d975..f8520064 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -5,7 +5,8 @@ using Dino.Entities; namespace Dino { public class MucManager : StreamInteractionModule, Object { - public const string id = "muc_manager"; + public static ModuleIdentity<MucManager> IDENTITY = new ModuleIdentity<MucManager>("muc_manager"); + public string id { get { return IDENTITY.id; } } public signal void groupchat_joined(Account account, Jid jid, string nick); public signal void groupchat_subject_set(Account account, Jid jid, string subject); @@ -23,7 +24,7 @@ public class MucManager : StreamInteractionModule, Object { this.stream_interactor = stream_interactor; stream_interactor.account_added.connect(on_account_added); stream_interactor.stream_negotiated.connect(on_stream_negotiated); - MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_received.connect(on_pre_message_received); } public void join(Account account, Jid jid, string nick, string? password = null) { @@ -52,7 +53,7 @@ public class MucManager : StreamInteractionModule, Object { } public ArrayList<Jid>? get_occupants(Jid jid, Account account) { - return PresenceManager.get_instance(stream_interactor).get_full_jids(jid, account); + return stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(jid, account); } public ArrayList<Jid>? get_other_occupants(Jid jid, Account account) { @@ -65,7 +66,7 @@ public class MucManager : StreamInteractionModule, Object { } public bool is_groupchat(Jid jid, Account account) { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); return !jid.is_full() && conversation != null && conversation.type_ == Conversation.Type.GROUPCHAT; } @@ -104,7 +105,7 @@ public class MucManager : StreamInteractionModule, Object { public string? get_groupchat_subject(Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - return Xep.Muc.Flag.get_flag(stream).get_muc_subject(jid.bare_jid.to_string()); + return stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_subject(jid.bare_jid.to_string()); } return null; } @@ -112,7 +113,7 @@ public class MucManager : StreamInteractionModule, Object { public Jid? get_real_jid(Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - string? real_jid = Xep.Muc.Flag.get_flag(stream).get_real_jid(jid.to_string()); + string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(jid.to_string()); if (real_jid != null) { return new Jid(real_jid); } @@ -130,20 +131,12 @@ public class MucManager : StreamInteractionModule, Object { public string? get_nick(Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - Xep.Muc.Flag? flag = Xep.Muc.Flag.get_flag(stream); + Xep.Muc.Flag? flag = stream.get_flag(Xep.Muc.Flag.IDENTITY); if (flag != null) return flag.get_muc_nick(jid.bare_jid.to_string()); } return null; } - public static MucManager? get_instance(StreamInteractor stream_interactor) { - return (MucManager) stream_interactor.get_module(id); - } - - internal string get_id() { - return id; - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).subject_set.connect( (stream, subject, jid) => { on_subject_set(account, new Jid(jid), subject); @@ -167,14 +160,14 @@ public class MucManager : StreamInteractionModule, Object { Core.XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream == null) return; if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) { - string? real_jid = Xep.Muc.Flag.get_flag(stream).get_real_jid(message.counterpart.to_string()); + string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart.to_string()); if (real_jid != null && real_jid != message.counterpart.to_string()) { message.real_jid = real_jid; } } - string muc_nick = Xep.Muc.Flag.get_flag(stream).get_muc_nick(conversation.counterpart.bare_jid.to_string()); + string muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string()); if (message.from.equals(new Jid(@"$(message.from.bare_jid)/$muc_nick"))) { // TODO better from own - Gee.List<Entities.Message>? messages = MessageManager.get_instance(stream_interactor).get_messages(conversation); + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageManager.IDENTITY).get_messages(conversation); if (messages != null) { // TODO not here foreach (Entities.Message m in messages) { if (m.equals(message)) { @@ -207,4 +200,5 @@ public class MucManager : StreamInteractionModule, Object { } } } + }
\ No newline at end of file diff --git a/libdino/src/service/presence_manager.vala b/libdino/src/service/presence_manager.vala index 7ff74e1a..effeb59f 100644 --- a/libdino/src/service/presence_manager.vala +++ b/libdino/src/service/presence_manager.vala @@ -5,7 +5,8 @@ using Dino.Entities; namespace Dino { public class PresenceManager : StreamInteractionModule, Object { - public const string id = "presence_manager"; + public static ModuleIdentity<PresenceManager> IDENTITY = new ModuleIdentity<PresenceManager>("presence_manager"); + public string id { get { return IDENTITY.id; } } public signal void show_received(Show show, Jid jid, Account account); public signal void received_subscription_request(Jid jid, Account account); @@ -27,7 +28,7 @@ public class PresenceManager : StreamInteractionModule, Object { public Show get_last_show(Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - Xmpp.Presence.Stanza? presence = Xmpp.Presence.Flag.get_flag(stream).get_presence(jid.to_string()); + Xmpp.Presence.Stanza? presence = stream.get_flag(Presence.Flag.IDENTITY).get_presence(jid.to_string()); if (presence != null) { return new Show(jid, presence.show, new DateTime.now_local()); } @@ -42,7 +43,7 @@ public class PresenceManager : StreamInteractionModule, Object { public ArrayList<Jid>? get_full_jids(Jid jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { - Xmpp.Presence.Flag flag = Xmpp.Presence.Flag.get_flag(stream); + Xmpp.Presence.Flag flag = stream.get_flag(Presence.Flag.IDENTITY); if (flag == null) return null; Gee.List<string> resources = flag.get_resources(jid.bare_jid.to_string()); if (resources == null) { @@ -73,14 +74,6 @@ public class PresenceManager : StreamInteractionModule, Object { if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string()); } - public static PresenceManager? get_instance(StreamInteractor stream_interactor) { - return (PresenceManager) stream_interactor.get_module(id); - } - - internal string get_id() { - return id; - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_available_show.connect((stream, jid, show) => on_received_available_show(account, new Jid(jid), show) diff --git a/libdino/src/service/roster_manager.vala b/libdino/src/service/roster_manager.vala index 720a746a..86bd7a21 100644 --- a/libdino/src/service/roster_manager.vala +++ b/libdino/src/service/roster_manager.vala @@ -4,79 +4,74 @@ using Xmpp; using Dino.Entities; namespace Dino { - public class RosterManager : StreamInteractionModule, Object { - public const string id = "roster_manager"; - public signal void removed_roster_item(Account account, Jid jid, Roster.Item roster_item); - public signal void updated_roster_item(Account account, Jid jid, Roster.Item roster_item); +public class RosterManager : StreamInteractionModule, Object { + public static ModuleIdentity<RosterManager> IDENTITY = new ModuleIdentity<RosterManager>("roster_manager"); + public string id { get { return IDENTITY.id; } } - private StreamInteractor stream_interactor; + public signal void removed_roster_item(Account account, Jid jid, Roster.Item roster_item); + public signal void updated_roster_item(Account account, Jid jid, Roster.Item roster_item); - public static void start(StreamInteractor stream_interactor) { - RosterManager m = new RosterManager(stream_interactor); - stream_interactor.add_module(m); - } - - public RosterManager(StreamInteractor stream_interactor) { - this.stream_interactor = stream_interactor; - stream_interactor.account_added.connect(on_account_added); - } + private StreamInteractor stream_interactor; - public ArrayList<Roster.Item> get_roster(Account account) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - ArrayList<Roster.Item> ret = new ArrayList<Roster.Item>(); - if (stream != null) { - ret.add_all(Xmpp.Roster.Flag.get_flag(stream).get_roster()); - } - return ret; - } + public static void start(StreamInteractor stream_interactor) { + RosterManager m = new RosterManager(stream_interactor); + stream_interactor.add_module(m); + } - public Roster.Item? get_roster_item(Account account, Jid jid) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) { - return Xmpp.Roster.Flag.get_flag(stream).get_item(jid.bare_jid.to_string()); - } - return null; - } + public RosterManager(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + stream_interactor.account_added.connect(on_account_added); + } - public void remove_jid(Account account, Jid jid) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).remove_jid(stream, jid.bare_jid.to_string()); + public ArrayList<Roster.Item> get_roster(Account account) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + ArrayList<Roster.Item> ret = new ArrayList<Roster.Item>(); + if (stream != null) { + ret.add_all(stream.get_flag(Roster.Flag.IDENTITY).get_roster()); } + return ret; + } - public void add_jid(Account account, Jid jid, string? handle) { - Core.XmppStream? stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid.to_string(), handle); + public Roster.Item? get_roster_item(Account account, Jid jid) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) { + return stream.get_flag(Roster.Flag.IDENTITY).get_item(jid.bare_jid.to_string()); } + return null; + } - public static RosterManager? get_instance(StreamInteractor stream_interactor) { - return (RosterManager) stream_interactor.get_module(id); - } + public void remove_jid(Account account, Jid jid) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).remove_jid(stream, jid.bare_jid.to_string()); + } - internal string get_id() { - return id; - } + public void add_jid(Account account, Jid jid, string? handle) { + Core.XmppStream? stream = stream_interactor.get_stream(account); + if (stream != null) stream.get_module(Xmpp.Roster.Module.IDENTITY).add_jid(stream, jid.bare_jid.to_string(), handle); + } - private void on_account_added(Account account) { - stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).received_roster.connect( (stream, roster) => { - on_roster_received(account, roster); - }); - stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_removed.connect( (stream, roster_item) => { - removed_roster_item(account, new Jid(roster_item.jid), roster_item); - }); - stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_updated.connect( (stream, roster_item) => { - on_roster_item_updated(account, roster_item); - }); - } + private void on_account_added(Account account) { + stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).received_roster.connect( (stream, roster) => { + on_roster_received(account, roster); + }); + stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_removed.connect( (stream, roster_item) => { + removed_roster_item(account, new Jid(roster_item.jid), roster_item); + }); + stream_interactor.module_manager.get_module(account, Roster.Module.IDENTITY).item_updated.connect( (stream, roster_item) => { + on_roster_item_updated(account, roster_item); + }); + } - private void on_roster_received(Account account, Collection<Roster.Item> roster_items) { - foreach (Roster.Item roster_item in roster_items) { - on_roster_item_updated(account, roster_item); - } + private void on_roster_received(Account account, Collection<Roster.Item> roster_items) { + foreach (Roster.Item roster_item in roster_items) { + on_roster_item_updated(account, roster_item); } + } - private void on_roster_item_updated(Account account, Roster.Item roster_item) { - updated_roster_item(account, new Jid(roster_item.jid), roster_item); - } + private void on_roster_item_updated(Account account, Roster.Item roster_item) { + updated_roster_item(account, new Jid(roster_item.jid), roster_item); } +} + }
\ No newline at end of file diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index f42eb41b..bdc1ac96 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -13,7 +13,7 @@ public class StreamInteractor { public ModuleManager module_manager; public ConnectionManager connection_manager; - private ArrayList<StreamInteractionModule> interaction_modules = new ArrayList<StreamInteractionModule>(); + private ArrayList<StreamInteractionModule> modules = new ArrayList<StreamInteractionModule>(); public StreamInteractor(Database db) { module_manager = new ModuleManager(db); @@ -46,14 +46,13 @@ public class StreamInteractor { } public void add_module(StreamInteractionModule module) { - interaction_modules.add(module); + modules.add(module); } - public StreamInteractionModule? get_module(string id) { - foreach (StreamInteractionModule module in interaction_modules) { - if (module.get_id() == id) { - return module; - } + public T? get_module<T>(ModuleIdentity<T>? identity) { + if (identity == null) return null; + foreach (StreamInteractionModule module in modules) { + if (identity.matches(module)) return identity.cast(module); } return null; } @@ -65,8 +64,24 @@ public class StreamInteractor { } } +public class ModuleIdentity<T> : Object { + public string id { get; private set; } + + public ModuleIdentity(string id) { + this.id = id; + } + + public T? cast(StreamInteractionModule module) { + return (T?) module; + } + + public bool matches(StreamInteractionModule module) { + return module.id== id; + } +} + public interface StreamInteractionModule : Object { - public abstract string get_id(); + public abstract string id { get; } } }
\ No newline at end of file diff --git a/main/src/ui/add_conversation/chat/add_contact_dialog.vala b/main/src/ui/add_conversation/chat/add_contact_dialog.vala index df8fbeb9..88bfe2be 100644 --- a/main/src/ui/add_conversation/chat/add_contact_dialog.vala +++ b/main/src/ui/add_conversation/chat/add_contact_dialog.vala @@ -41,9 +41,9 @@ protected class AddContactDialog : Gtk.Dialog { account = account2; } } - RosterManager.get_instance(stream_interactor).add_jid(account, jid, alias); + stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); if (subscribe_checkbutton.active) { - PresenceManager.get_instance(stream_interactor).request_subscription(account, jid); + stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); } close(); } diff --git a/main/src/ui/add_conversation/chat/dialog.vala b/main/src/ui/add_conversation/chat/dialog.vala index cad2b367..15624731 100644 --- a/main/src/ui/add_conversation/chat/dialog.vala +++ b/main/src/ui/add_conversation/chat/dialog.vala @@ -60,7 +60,7 @@ public class Dialog : Gtk.Dialog { }); select_jid_fragment.remove_jid.connect((row) => { ListRow list_row = roster_list.get_selected_row() as ListRow; - RosterManager.get_instance(stream_interactor).remove_jid(list_row.account, list_row.jid); + stream_interactor.get_module(RosterManager.IDENTITY).remove_jid(list_row.account, list_row.jid); }); select_jid_fragment.notify["done"].connect(() => { ok_button.sensitive = select_jid_fragment.done; @@ -72,8 +72,8 @@ public class Dialog : Gtk.Dialog { ListRow? selected_row = roster_list.get_selected_row() as ListRow; if (selected_row != null) { // TODO move in list to front immediately - ConversationManager.get_instance(stream_interactor).ensure_start_conversation(selected_row.jid, selected_row.account); - Conversation conversation = ConversationManager.get_instance(stream_interactor).get_conversation(selected_row.jid, selected_row.account); + stream_interactor.get_module(ConversationManager.IDENTITY).ensure_start_conversation(selected_row.jid, selected_row.account); + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(selected_row.jid, selected_row.account); conversation_opened(conversation); } close(); diff --git a/main/src/ui/add_conversation/chat/roster_list.vala b/main/src/ui/add_conversation/chat/roster_list.vala index 92388597..c395dc3a 100644 --- a/main/src/ui/add_conversation/chat/roster_list.vala +++ b/main/src/ui/add_conversation/chat/roster_list.vala @@ -20,13 +20,13 @@ protected class RosterList : FilterableList { set_header_func(header); set_sort_func(sort); - RosterManager.get_instance(stream_interactor).removed_roster_item.connect( (account, jid, roster_item) => { + stream_interactor.get_module(RosterManager.IDENTITY).removed_roster_item.connect( (account, jid, roster_item) => { Idle.add(() => { on_removed_roster_item(account, jid, roster_item); return false;});}); - RosterManager.get_instance(stream_interactor).updated_roster_item.connect( (account, jid, roster_item) => { + stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect( (account, jid, roster_item) => { Idle.add(() => { on_updated_roster_item(account, jid, roster_item); return false;});}); foreach (Account account in stream_interactor.get_accounts()) { - foreach (Roster.Item roster_item in RosterManager.get_instance(stream_interactor).get_roster(account)) { + foreach (Roster.Item roster_item in stream_interactor.get_module(RosterManager.IDENTITY).get_roster(account)) { on_updated_roster_item(account, new Jid(roster_item.jid), roster_item); } } diff --git a/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala b/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala index 8cc5ac72..c097ef06 100644 --- a/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala +++ b/main/src/ui/add_conversation/conference/add_groupchat_dialog.vala @@ -80,9 +80,9 @@ protected class AddGroupchatDialog : Gtk.Dialog { conference.name = alias_entry.text; conference.autojoin = autojoin_checkbutton.active; if (edit_confrence == null) { - MucManager.get_instance(stream_interactor).add_bookmark(account, conference); + stream_interactor.get_module(MucManager.IDENTITY).add_bookmark(account, conference); } else { - MucManager.get_instance(stream_interactor).replace_bookmark(account, edit_confrence, conference); + stream_interactor.get_module(MucManager.IDENTITY).replace_bookmark(account, edit_confrence, conference); } close(); } diff --git a/main/src/ui/add_conversation/conference/conference_list.vala b/main/src/ui/add_conversation/conference/conference_list.vala index 7743ced5..c44f989a 100644 --- a/main/src/ui/add_conversation/conference/conference_list.vala +++ b/main/src/ui/add_conversation/conference/conference_list.vala @@ -20,7 +20,7 @@ protected class ConferenceList : FilterableList { set_header_func(header); set_sort_func(sort); - MucManager.get_instance(stream_interactor).bookmarks_updated.connect((account, conferences) => { + stream_interactor.get_module(MucManager.IDENTITY).bookmarks_updated.connect((account, conferences) => { Idle.add(() => { lists[account] = conferences; refresh_conferences(); @@ -29,7 +29,7 @@ protected class ConferenceList : FilterableList { }); foreach (Account account in stream_interactor.get_accounts()) { - MucManager.get_instance(stream_interactor).get_bookmarks(account, on_conference_bookmarks_received, Tuple.create(this, account)); + stream_interactor.get_module(MucManager.IDENTITY).get_bookmarks(account, on_conference_bookmarks_received, Tuple.create(this, account)); } } diff --git a/main/src/ui/add_conversation/conference/dialog.vala b/main/src/ui/add_conversation/conference/dialog.vala index ff548699..bfb25888 100644 --- a/main/src/ui/add_conversation/conference/dialog.vala +++ b/main/src/ui/add_conversation/conference/dialog.vala @@ -102,7 +102,7 @@ public class Dialog : Gtk.Dialog { }); select_fragment.remove_jid.connect((row) => { ConferenceListRow conference_row = row as ConferenceListRow; - MucManager.get_instance(stream_interactor).remove_bookmark(conference_row.account, conference_row.bookmark); + stream_interactor.get_module(MucManager.IDENTITY).remove_bookmark(conference_row.account, conference_row.bookmark); }); stack.add_named(select_fragment, "select"); } @@ -137,7 +137,7 @@ public class Dialog : Gtk.Dialog { } private void on_ok_button_clicked() { - MucManager.get_instance(stream_interactor).join(details_fragment.account, new Jid(details_fragment.jid), details_fragment.nick, details_fragment.password); + stream_interactor.get_module(MucManager.IDENTITY).join(details_fragment.account, new Jid(details_fragment.jid), details_fragment.nick, details_fragment.password); close(); } diff --git a/main/src/ui/avatar_generator.vala b/main/src/ui/avatar_generator.vala index b668444c..eb87a3e2 100644 --- a/main/src/ui/avatar_generator.vala +++ b/main/src/ui/avatar_generator.vala @@ -31,7 +31,7 @@ public class AvatarGenerator { } public Pixbuf draw_message(StreamInteractor stream_interactor, Message message) { - Jid? real_jid = MucManager.get_instance(stream_interactor).get_message_real_jid(message); + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_message_real_jid(message); return draw_jid(stream_interactor, real_jid != null ? real_jid : message.from, message.account); } @@ -73,7 +73,7 @@ public class AvatarGenerator { } private Pixbuf draw_tile(Jid jid, Account account, int width, int height) { - if (MucManager.get_instance(stream_interactor).is_groupchat(jid, account)) { + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)) { return draw_groupchat_tile(jid, account, width, height); } else { return draw_chat_tile(jid, account, width, height); @@ -81,13 +81,13 @@ public class AvatarGenerator { } private Pixbuf draw_chat_tile(Jid jid, Account account, int width, int height) { - if (MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) { - Jid? real_jid = MucManager.get_instance(stream_interactor).get_real_jid(jid, account); + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, account); if (real_jid != null) { return draw_tile(real_jid, account, width, height); } } - Pixbuf? avatar = AvatarManager.get_instance(stream_interactor).get_avatar(account, jid); + Pixbuf? avatar = stream_interactor.get_module(AvatarManager.IDENTITY).get_avatar(account, jid); if (avatar != null) { double desired_ratio = (double) width / height; double avatar_ratio = (double) avatar.width / avatar.height; @@ -109,7 +109,7 @@ public class AvatarGenerator { } private Pixbuf draw_groupchat_tile(Jid jid, Account account, int width, int height) { - ArrayList<Jid>? occupants = MucManager.get_instance(stream_interactor).get_other_occupants(jid, account); + ArrayList<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_other_occupants(jid, account); if (stateless || occupants == null || occupants.size == 0) { return draw_chat_tile(jid, account, width, height); } diff --git a/main/src/ui/chat_input.vala b/main/src/ui/chat_input.vala index 92d0ccc6..1ca38786 100644 --- a/main/src/ui/chat_input.vala +++ b/main/src/ui/chat_input.vala @@ -62,20 +62,20 @@ public class ChatInput : Box { string[] token = text.split(" ", 2); switch(token[0]) { case "/kick": - MucManager.get_instance(stream_interactor).kick(conversation.account, conversation.counterpart, token[1]); + stream_interactor.get_module(MucManager.IDENTITY).kick(conversation.account, conversation.counterpart, token[1]); break; case "/me": - MessageManager.get_instance(stream_interactor).send_message(text, conversation); + stream_interactor.get_module(MessageManager.IDENTITY).send_message(text, conversation); break; case "/nick": - MucManager.get_instance(stream_interactor).change_nick(conversation.account, conversation.counterpart, token[1]); + stream_interactor.get_module(MucManager.IDENTITY).change_nick(conversation.account, conversation.counterpart, token[1]); break; case "/topic": - MucManager.get_instance(stream_interactor).change_subject(conversation.account, conversation.counterpart, token[1]); + stream_interactor.get_module(MucManager.IDENTITY).change_subject(conversation.account, conversation.counterpart, token[1]); break; } } else { - MessageManager.get_instance(stream_interactor).send_message(text, conversation); + stream_interactor.get_module(MessageManager.IDENTITY).send_message(text, conversation); } text_input.buffer.text = ""; } @@ -117,9 +117,9 @@ public class ChatInput : Box { private void on_text_input_changed() { if (text_input.buffer.text != "") { - ChatInteraction.get_instance(stream_interactor).on_message_entered(conversation); + stream_interactor.get_module(ChatInteraction.IDENTITY).on_message_entered(conversation); } else { - ChatInteraction.get_instance(stream_interactor).on_message_cleared(conversation); + stream_interactor.get_module(ChatInteraction.IDENTITY).on_message_cleared(conversation); } } } diff --git a/main/src/ui/conversation_selector/chat_row.vala b/main/src/ui/conversation_selector/chat_row.vala index 96f6921d..5e3270aa 100644 --- a/main/src/ui/conversation_selector/chat_row.vala +++ b/main/src/ui/conversation_selector/chat_row.vala @@ -40,7 +40,7 @@ public class ChatRow : ConversationRow { } public void update_avatar() { - ArrayList<Jid> full_jids = PresenceManager.get_instance(stream_interactor).get_full_jids(conversation.counterpart, conversation.account); + ArrayList<Jid> full_jids = stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(conversation.counterpart, conversation.account); set_avatar((new AvatarGenerator(AVATAR_SIZE, AVATAR_SIZE, image.scale_factor)) .set_greyscale(full_jids == null) .draw_conversation(stream_interactor, conversation), image.scale_factor); @@ -54,12 +54,12 @@ public class ChatRow : ConversationRow { jid_label.label = conversation.counterpart.to_string(); - ArrayList<Jid>? full_jids = PresenceManager.get_instance(stream_interactor).get_full_jids(conversation.counterpart, conversation.account); + ArrayList<Jid>? full_jids = stream_interactor.get_module(PresenceManager.IDENTITY).get_full_jids(conversation.counterpart, conversation.account); if (full_jids != null) { for (int i = 0; i < full_jids.size; i++) { Box box = new Box(Orientation.HORIZONTAL, 5); - Show show = PresenceManager.get_instance(stream_interactor).get_last_show(full_jids[i], conversation.account); + Show show = stream_interactor.get_module(PresenceManager.IDENTITY).get_last_show(full_jids[i], conversation.account); Image image = new Image(); if (show.as == Show.AWAY) { image.set_from_icon_name("dino-status-away", IconSize.SMALL_TOOLBAR); diff --git a/main/src/ui/conversation_selector/conversation_row.vala b/main/src/ui/conversation_selector/conversation_row.vala index ef3984c1..c16da287 100644 --- a/main/src/ui/conversation_selector/conversation_row.vala +++ b/main/src/ui/conversation_selector/conversation_row.vala @@ -46,7 +46,7 @@ public abstract class ConversationRow : ListBoxRow { x_button.clicked.connect(on_x_button_clicked); update_name(Util.get_conversation_display_name(stream_interactor, conversation)); - Entities.Message message = MessageManager.get_instance(stream_interactor).get_last_message(conversation); + Entities.Message message = stream_interactor.get_module(MessageManager.IDENTITY).get_last_message(conversation); if (message != null) { message_received(message); } diff --git a/main/src/ui/conversation_selector/groupchat_row.vala b/main/src/ui/conversation_selector/groupchat_row.vala index 7fe52d89..598902cc 100644 --- a/main/src/ui/conversation_selector/groupchat_row.vala +++ b/main/src/ui/conversation_selector/groupchat_row.vala @@ -23,12 +23,12 @@ public class GroupchatRow : ConversationRow { public override void network_connection(bool connected) { set_avatar((new AvatarGenerator(AVATAR_SIZE, AVATAR_SIZE, image.scale_factor)) .set_greyscale(!connected || - MucManager.get_instance(stream_interactor).get_nick(conversation.counterpart, conversation.account) == null) // TODO better currently joined + stream_interactor.get_module(MucManager.IDENTITY).get_nick(conversation.counterpart, conversation.account) == null) // TODO better currently joined .draw_conversation(stream_interactor, conversation), image.scale_factor); } private void on_x_button_clicked() { - MucManager.get_instance(stream_interactor).part(conversation.account, conversation.counterpart); + stream_interactor.get_module(MucManager.IDENTITY).part(conversation.account, conversation.counterpart); } } diff --git a/main/src/ui/conversation_selector/list.vala b/main/src/ui/conversation_selector/list.vala index 071ac504..d95128f1 100644 --- a/main/src/ui/conversation_selector/list.vala +++ b/main/src/ui/conversation_selector/list.vala @@ -22,31 +22,31 @@ public class List : ListBox { set_header_func(header); set_sort_func(sort); - ChatInteraction.get_instance(stream_interactor).conversation_read.connect((conversation) => { + stream_interactor.get_module(ChatInteraction.IDENTITY).conversation_read.connect((conversation) => { Idle.add(() => {if (rows.has_key(conversation)) rows[conversation].mark_read(); return false;}); }); - ChatInteraction.get_instance(stream_interactor).conversation_unread.connect((conversation) => { + stream_interactor.get_module(ChatInteraction.IDENTITY).conversation_unread.connect((conversation) => { Idle.add(() => {if (rows.has_key(conversation)) rows[conversation].mark_unread(); return false;}); }); - ConversationManager.get_instance(stream_interactor).conversation_activated.connect((conversation) => { + stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect((conversation) => { Idle.add(() => {add_conversation(conversation); return false;}); }); - MessageManager.get_instance(stream_interactor).message_received.connect((message, conversation) => { + stream_interactor.get_module(MessageManager.IDENTITY).message_received.connect((message, conversation) => { Idle.add(() => {on_message_received(message, conversation); return false;}); }); - MessageManager.get_instance(stream_interactor).message_sent.connect((message, conversation) => { + stream_interactor.get_module(MessageManager.IDENTITY).message_sent.connect((message, conversation) => { Idle.add(() => {on_message_received(message, conversation); return false;}); }); - PresenceManager.get_instance(stream_interactor).show_received.connect((show, jid, account) => { + stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((show, jid, account) => { Idle.add(() => { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); if (conversation != null && rows.has_key(conversation)) rows[conversation].on_show_received(show); return false; }); }); - RosterManager.get_instance(stream_interactor).updated_roster_item.connect((account, jid, roster_item) => { + stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect((account, jid, roster_item) => { Idle.add(() => { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); if (conversation != null && rows.has_key(conversation)) { ChatRow row = rows[conversation] as ChatRow; if (row != null) row.on_updated_roster_item(roster_item); @@ -54,9 +54,9 @@ public class List : ListBox { return false; }); }); - AvatarManager.get_instance(stream_interactor).received_avatar.connect((avatar, jid, account) => { + stream_interactor.get_module(AvatarManager.IDENTITY).received_avatar.connect((avatar, jid, account) => { Idle.add(() => { - Conversation? conversation = ConversationManager.get_instance(stream_interactor).get_conversation(jid, account); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(jid, account); if (conversation != null && rows.has_key(conversation)) { ChatRow row = rows[conversation] as ChatRow; if (row != null) row.update_avatar(); diff --git a/main/src/ui/conversation_summary/view.vala b/main/src/ui/conversation_summary/view.vala index 33b3a836..0e06a80a 100644 --- a/main/src/ui/conversation_summary/view.vala +++ b/main/src/ui/conversation_summary/view.vala @@ -32,16 +32,16 @@ public class View : Box { scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify); scrolled.vadjustment.notify["value"].connect(on_value_notify); - CounterpartInteractionManager.get_instance(stream_interactor).received_state.connect((account, jid, state) => { + stream_interactor.get_module(CounterpartInteractionManager.IDENTITY).received_state.connect((account, jid, state) => { Idle.add(() => { on_received_state(account, jid, state); return false; }); }); - MessageManager.get_instance(stream_interactor).message_received.connect((message, conversation) => { + stream_interactor.get_module(MessageManager.IDENTITY).message_received.connect((message, conversation) => { Idle.add(() => { show_message(message, conversation, true); return false; }); }); - MessageManager.get_instance(stream_interactor).message_sent.connect((message, conversation) => { + stream_interactor.get_module(MessageManager.IDENTITY).message_sent.connect((message, conversation) => { Idle.add(() => { show_message(message, conversation, true); return false; }); }); - PresenceManager.get_instance(stream_interactor).show_received.connect((show, jid, account) => { + stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((show, jid, account) => { Idle.add(() => { on_show_received(show, jid, account); return false; }); }); Timeout.add_seconds(60, () => { @@ -65,12 +65,12 @@ public class View : Box { last_conversation_item = null; ArrayList<Object> objects = new ArrayList<Object>(); - Gee.List<Entities.Message>? messages = MessageManager.get_instance(stream_interactor).get_messages(conversation); + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageManager.IDENTITY).get_messages(conversation); if (messages != null && messages.size > 0) { earliest_message = messages[0]; objects.add_all(messages); } - HashMap<Jid, ArrayList<Show>>? shows = PresenceManager.get_instance(stream_interactor).get_shows(conversation.counterpart, conversation.account); + HashMap<Jid, ArrayList<Show>>? shows = stream_interactor.get_module(PresenceManager.IDENTITY).get_shows(conversation.counterpart, conversation.account); if (shows != null) { foreach (Jid jid in shows.keys) objects.add_all(shows[jid]); } @@ -109,7 +109,7 @@ public class View : Box { private void update_chat_state(string? state = null) { string? state_ = state; if (state_ == null) { - state_ = CounterpartInteractionManager.get_instance(stream_interactor).get_chat_state(conversation.account, conversation.counterpart); + state_ = stream_interactor.get_module(CounterpartInteractionManager.IDENTITY).get_chat_state(conversation.account, conversation.counterpart); } if (typing_status != null) { main.remove(typing_status); @@ -156,7 +156,7 @@ public class View : Box { if(reloading) return; reloading = true; } - Gee.List<Entities.Message>? messages = MessageManager.get_instance(stream_interactor).get_messages_before(conversation, earliest_message); + Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageManager.IDENTITY).get_messages_before(conversation, earliest_message); if (messages != null && messages.size > 0) { earliest_message = messages[0]; MergedMessageItem? current_item = null; diff --git a/main/src/ui/conversation_titlebar.vala b/main/src/ui/conversation_titlebar.vala index 96b154e3..45c4c9c1 100644 --- a/main/src/ui/conversation_titlebar.vala +++ b/main/src/ui/conversation_titlebar.vala @@ -20,7 +20,7 @@ public class ConversationTitlebar : Gtk.HeaderBar { public ConversationTitlebar(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - MucManager.get_instance(stream_interactor).groupchat_subject_set.connect((account, jid, subject) => { + stream_interactor.get_module(MucManager.IDENTITY).groupchat_subject_set.connect((account, jid, subject) => { Idle.add(() => { on_groupchat_subject_set(account, jid, subject); return false; }); }); create_conversation_menu(); @@ -77,7 +77,7 @@ public class ConversationTitlebar : Gtk.HeaderBar { if (subtitle != null) { set_subtitle(subtitle); } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { - string subject = MucManager.get_instance(stream_interactor).get_groupchat_subject(conversation.counterpart, conversation.account); + string subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); set_subtitle(subject != "" ? subject : null); } else { set_subtitle(null); diff --git a/main/src/ui/manage_accounts/dialog.vala b/main/src/ui/manage_accounts/dialog.vala index 3616c403..db40761d 100644 --- a/main/src/ui/manage_accounts/dialog.vala +++ b/main/src/ui/manage_accounts/dialog.vala @@ -78,7 +78,7 @@ public class Dialog : Gtk.Window { add_account(account); } - AvatarManager.get_instance(stream_interactor).received_avatar.connect((pixbuf, jid, account) => { + stream_interactor.get_module(AvatarManager.IDENTITY).received_avatar.connect((pixbuf, jid, account) => { Idle.add(() => { on_received_avatar(pixbuf, jid, account); return false; @@ -166,7 +166,7 @@ public class Dialog : Gtk.Window { if (chooser.run() == Gtk.ResponseType.ACCEPT) { string uri = chooser.get_filename(); Account account = (account_list.get_selected_row() as AccountRow).account; - AvatarManager.get_instance(stream_interactor).publish(account, uri); + stream_interactor.get_module(AvatarManager.IDENTITY).publish(account, uri); } chooser.close(); } diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 17636995..18e33c56 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -13,14 +13,14 @@ public class Notifications : GLib.Object { } public void start() { - MessageManager.get_instance(stream_interactor).message_received.connect(on_message_received); - PresenceManager.get_instance(stream_interactor).received_subscription_request.connect(on_received_subscription_request); + stream_interactor.get_module(MessageManager.IDENTITY).message_received.connect(on_message_received); + stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); } private void on_message_received(Entities.Message message, Conversation conversation) { - if (!ChatInteraction.get_instance(stream_interactor).is_active_focus()) { + if (!stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) { string display_name = Util.get_conversation_display_name(stream_interactor, conversation); - if (MucManager.get_instance(stream_interactor).is_groupchat(conversation.counterpart, conversation.account)) { + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)) { string muc_occupant = Util.get_display_name(stream_interactor, message.from, conversation.account); display_name = muc_occupant + " in " + display_name; } @@ -37,13 +37,13 @@ public class Notifications : GLib.Object { Notify.Notification notification = new Notify.Notification("Subscription request", jid.bare_jid.to_string(), null); notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)); notification.add_action("accept", "Accept", () => { - PresenceManager.get_instance(stream_interactor).approve_subscription(account, jid); + stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(account, jid); try { notification.close(); } catch (Error error) { } }); notification.add_action("deny", "Deny", () => { - PresenceManager.get_instance(stream_interactor).deny_subscription(account, jid); + stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(account, jid); try { notification.close(); } catch (Error error) { } diff --git a/main/src/ui/occupant_list.vala b/main/src/ui/occupant_list.vala index ba7c01d1..309289fc 100644 --- a/main/src/ui/occupant_list.vala +++ b/main/src/ui/occupant_list.vala @@ -25,17 +25,17 @@ public class OccupantList : Box { list_box.set_filter_func(filter); search_entry.search_changed.connect(search_changed); - PresenceManager.get_instance(stream_interactor).show_received.connect((show, jid, account) => { + stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((show, jid, account) => { Idle.add(() => { on_show_received(show, jid, account); return false; }); }); - RosterManager.get_instance(stream_interactor).updated_roster_item.connect(on_updated_roster_item); + stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect(on_updated_roster_item); initialize_for_conversation(conversation); } public void initialize_for_conversation(Conversation conversation) { this.conversation = conversation; - ArrayList<Jid>? occupants = MucManager.get_instance(stream_interactor).get_occupants(conversation.counterpart, conversation.account); + ArrayList<Jid>? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); if (occupants != null) { foreach (Jid occupant in occupants) { add_occupant(occupant); diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala index 27240a58..8feb9a05 100644 --- a/main/src/ui/unified_window.vala +++ b/main/src/ui/unified_window.vala @@ -99,7 +99,7 @@ public class UnifiedWindow : Window { private void on_conversation_selected(Conversation conversation) { this.conversation = conversation; - ChatInteraction.get_instance(stream_interactor).on_conversation_selected(conversation); + stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation); conversation.active = true; // only for conversation_selected filterable_conversation_list.conversation_list.on_conversation_selected(conversation); // only for conversation_opened @@ -109,12 +109,12 @@ public class UnifiedWindow : Window { } private bool on_focus_in_event() { - ChatInteraction.get_instance(stream_interactor).on_window_focus_in(conversation); + stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation); return false; } private bool on_focus_out_event() { - ChatInteraction.get_instance(stream_interactor).on_window_focus_out(conversation); + stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_out(conversation); return false; } } diff --git a/main/src/ui/util.vala b/main/src/ui/util.vala index 2cf070b0..810ab13d 100644 --- a/main/src/ui/util.vala +++ b/main/src/ui/util.vala @@ -44,7 +44,7 @@ public class Util : Object { } public static string get_display_name(StreamInteractor stream_interactor, Jid jid, Account account) { - if (MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) { + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { return jid.resourcepart; } else { if (jid.bare_jid.equals(account.bare_jid.bare_jid)) { @@ -54,7 +54,7 @@ public class Util : Object { return account.alias; } } - Roster.Item roster_item = RosterManager.get_instance(stream_interactor).get_roster_item(account, jid); + Roster.Item roster_item = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(account, jid); if (roster_item != null && roster_item.name != null) { return roster_item.name; } @@ -63,7 +63,7 @@ public class Util : Object { } public static string get_message_display_name(StreamInteractor stream_interactor, Entities.Message message, Account account) { - Jid? real_jid = MucManager.get_instance(stream_interactor).get_message_real_jid(message); + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_message_real_jid(message); if (real_jid != null) { return get_display_name(stream_interactor, real_jid, account); } else { diff --git a/plugins/omemo/src/encryption_list_entry.vala b/plugins/omemo/src/encryption_list_entry.vala index 753ffe67..7b769e85 100644 --- a/plugins/omemo/src/encryption_list_entry.vala +++ b/plugins/omemo/src/encryption_list_entry.vala @@ -16,7 +16,7 @@ public class EncryptionListEntry : Plugins.EncryptionListEntry, Object { }} public bool can_encrypt(Entities.Conversation conversation) { - return Manager.get_instance(plugin.app.stream_interaction).can_encrypt(conversation); + return plugin.app.stream_interaction.get_module(Manager.IDENTITY).can_encrypt(conversation); } } diff --git a/plugins/omemo/src/manager.vala b/plugins/omemo/src/manager.vala index a48f4748..67b38bc5 100644 --- a/plugins/omemo/src/manager.vala +++ b/plugins/omemo/src/manager.vala @@ -7,7 +7,8 @@ using Gee; namespace Dino.Plugins.Omemo { public class Manager : StreamInteractionModule, Object { - public const string id = "omemo_manager"; + public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("omemo_manager"); + public string id { get { return IDENTITY.id; } } private StreamInteractor stream_interactor; private Database db; @@ -64,8 +65,8 @@ public class Manager : StreamInteractionModule, Object { stream_interactor.stream_negotiated.connect(on_stream_negotiated); stream_interactor.account_added.connect(on_account_added); - MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received); - MessageManager.get_instance(stream_interactor).pre_message_send.connect(on_pre_message_send); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_received.connect(on_pre_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_send.connect(on_pre_message_send); } private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { @@ -143,8 +144,8 @@ public class Manager : StreamInteractionModule, Object { } } foreach (Entities.Message msg in send_now) { - Entities.Conversation conv = ConversationManager.get_instance(stream_interactor).get_conversation(msg.counterpart, account); - MessageManager.get_instance(stream_interactor).send_xmpp_message(msg, conv, true); + Entities.Conversation conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(msg.counterpart, account); + stream_interactor.get_module(MessageManager.IDENTITY).send_xmpp_message(msg, conv, true); } } @@ -167,8 +168,8 @@ public class Manager : StreamInteractionModule, Object { } } foreach (Entities.Message msg in send_now) { - Entities.Conversation conv = ConversationManager.get_instance(stream_interactor).get_conversation(msg.counterpart, account); - MessageManager.get_instance(stream_interactor).send_xmpp_message(msg, conv, true); + Entities.Conversation conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(msg.counterpart, account); + stream_interactor.get_module(MessageManager.IDENTITY).send_xmpp_message(msg, conv, true); } } @@ -222,18 +223,10 @@ public class Manager : StreamInteractionModule, Object { return stream.get_module(StreamModule.IDENTITY).is_known_address(conversation.counterpart.bare_jid.to_string()); } - internal string get_id() { - return id; - } - public static void start(StreamInteractor stream_interactor, Database db) { Manager m = new Manager(stream_interactor, db); stream_interactor.add_module(m); } - - public static Manager? get_instance(StreamInteractor stream_interactor) { - return (Manager) stream_interactor.get_module(id); - } } }
\ No newline at end of file diff --git a/plugins/omemo/src/stream_module.vala b/plugins/omemo/src/stream_module.vala index 14b1a93e..480d8705 100644 --- a/plugins/omemo/src/stream_module.vala +++ b/plugins/omemo/src/stream_module.vala @@ -14,8 +14,7 @@ private const string NODE_VERIFICATION = NS_URI + ".verification"; private const int NUM_KEYS_TO_PUBLISH = 100; public class StreamModule : XmppStreamModule { - private const string ID = "omemo_module"; - public static ModuleIdentity<StreamModule> IDENTITY = new ModuleIdentity<StreamModule>(NS_URI, ID); + public static Core.ModuleIdentity<StreamModule> IDENTITY = new Core.ModuleIdentity<StreamModule>(NS_URI, "omemo_module"); private Store store; private ConcurrentSet<string> active_bundle_requests = new ConcurrentSet<string>(); @@ -189,7 +188,7 @@ public class StreamModule : XmppStreamModule { public void on_devicelist(XmppStream stream, string jid, string id, StanzaNode? node_) { StanzaNode? node = node_; - if (jid == get_bare_jid(Bind.Flag.get_flag(stream).my_jid) && store.local_registration_id != 0) { + if (jid == get_bare_jid(stream.get_flag(Bind.Flag.IDENTITY).my_jid) && store.local_registration_id != 0) { if (node == null) { node = new StanzaNode.build("list", NS_URI).add_self_xmlns().put_node(new StanzaNode.build("device", NS_URI)); } @@ -422,7 +421,7 @@ public class StreamModule : XmppStreamModule { } public override string get_id() { - return ID; + return IDENTITY.id; } } diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala index 96607e1e..9aac3db2 100644 --- a/plugins/openpgp/src/encryption_list_entry.vala +++ b/plugins/openpgp/src/encryption_list_entry.vala @@ -19,7 +19,7 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object { }} public bool can_encrypt(Entities.Conversation conversation) { - return Manager.get_instance(stream_interactor).get_key_id(conversation.account, conversation.counterpart) != null; + return stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart) != null; } } diff --git a/plugins/openpgp/src/manager.vala b/plugins/openpgp/src/manager.vala index 0941362e..a261c2cb 100644 --- a/plugins/openpgp/src/manager.vala +++ b/plugins/openpgp/src/manager.vala @@ -7,7 +7,8 @@ using Dino.Entities; namespace Dino.Plugins.OpenPgp { public class Manager : StreamInteractionModule, Object { - public const string id = "pgp_manager"; + public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("pgp_manager"); + public string id { get { return IDENTITY.id; } } public const string MESSAGE_ENCRYPTED = "pgp"; @@ -25,8 +26,8 @@ namespace Dino.Plugins.OpenPgp { this.db = db; stream_interactor.account_added.connect(on_account_added); - MessageManager.get_instance(stream_interactor).pre_message_received.connect(on_pre_message_received); - MessageManager.get_instance(stream_interactor).pre_message_send.connect(on_pre_message_send); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_received.connect(on_pre_message_received); + stream_interactor.get_module(MessageManager.IDENTITY).pre_message_send.connect(on_pre_message_send); } private void on_pre_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { @@ -40,7 +41,8 @@ namespace Dino.Plugins.OpenPgp { string? key_id = get_key_id(conversation.account, message.counterpart); bool encrypted = false; if (key_id != null) { - encrypted = stream_interactor.get_stream(conversation.account).get_module(Module.IDENTITY).encrypt(message_stanza, key_id); + Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream != null) encrypted = stream.get_module(Module.IDENTITY).encrypt(message_stanza, key_id); } if (!encrypted) { message.marked = Entities.Message.Marked.WONTSEND; @@ -52,14 +54,6 @@ namespace Dino.Plugins.OpenPgp { return db.get_contact_key(jid); } - public static Manager? get_instance(StreamInteractor stream_interactor) { - return (Manager) stream_interactor.get_module(id); - } - - internal string get_id() { - return id; - } - private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Module.IDENTITY).received_jid_key_id.connect((stream, jid, key_id) => { on_jid_key_received(account, new Jid(jid), key_id); @@ -69,7 +63,7 @@ namespace Dino.Plugins.OpenPgp { private void on_jid_key_received(Account account, Jid jid, string key_id) { lock (pgp_key_ids) { if (!pgp_key_ids.has_key(jid) || pgp_key_ids[jid] != key_id) { - if (!MucManager.get_instance(stream_interactor).is_groupchat_occupant(jid, account)) { + if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { db.set_contact_key(jid.bare_jid, key_id); } } diff --git a/plugins/openpgp/src/stream_flag.vala b/plugins/openpgp/src/stream_flag.vala index 5ace26bd..165327b9 100644 --- a/plugins/openpgp/src/stream_flag.vala +++ b/plugins/openpgp/src/stream_flag.vala @@ -6,20 +6,17 @@ using Xmpp.Core; namespace Dino.Plugins.OpenPgp { public class Flag : XmppStreamFlag { - public const string ID = "pgp"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "pgp"); + public HashMap<string, string> key_ids = new HashMap<string, string>(); public string? get_key_id(string jid) { return key_ids[get_bare_jid(jid)]; } public void set_key_id(string jid, string key) { key_ids[get_bare_jid(jid)] = key; } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/plugins/openpgp/src/stream_module.vala b/plugins/openpgp/src/stream_module.vala index 6de97066..b9742624 100644 --- a/plugins/openpgp/src/stream_module.vala +++ b/plugins/openpgp/src/stream_module.vala @@ -9,8 +9,7 @@ namespace Dino.Plugins.OpenPgp { private const string NS_URI_SIGNED = NS_URI + ":signed"; public class Module : XmppStreamModule { - public const string ID = "0027_current_pgp_usage"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static Core.ModuleIdentity<Module> IDENTITY = new Core.ModuleIdentity<Module>(NS_URI, "0027_current_pgp_usage"); public signal void received_jid_key_id(XmppStream stream, string jid, string key_id); @@ -69,7 +68,7 @@ namespace Dino.Plugins.OpenPgp { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_presence(XmppStream stream, Presence.Stanza presence) { StanzaNode x_node = presence.stanza.get_subnode("x", NS_URI_SIGNED); @@ -79,7 +78,7 @@ namespace Dino.Plugins.OpenPgp { string signed_data = presence.status == null ? "" : presence.status; string? key_id = get_sign_key(sig, signed_data); if (key_id != null) { - Flag.get_flag(stream).set_key_id(presence.from, key_id); + stream.get_flag(Flag.IDENTITY).set_key_id(presence.from, key_id); received_jid_key_id(stream, presence.from, key_id); } } diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 57eafe45..f3be115d 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -101,11 +101,14 @@ public class XmppStream { flags.add(flag); } - public XmppStreamFlag? get_flag(string ns, string id) { + public bool has_flag<T>(FlagIdentity<T>? identity) { + return get_flag(identity) != null; + } + + public T? get_flag<T>(FlagIdentity<T>? identity) { + if (identity == null) return null; foreach (var flag in flags) { - if (flag.get_ns() == ns && flag.get_id() == id) { - return flag; - } + if (identity.matches(flag)) return identity.cast(flag); } return null; } @@ -225,6 +228,24 @@ public class XmppStream { } } +public class FlagIdentity<T> : Object { + public string ns { get; private set; } + public string id { get; private set; } + + public FlagIdentity(string ns, string id) { + this.ns = ns; + this.id = id; + } + + public T? cast(XmppStreamFlag module) { + return (T?) module; + } + + public bool matches(XmppStreamFlag module) { + return module.get_ns() == ns && module.get_id() == id; + } +} + public abstract class XmppStreamFlag { public abstract string get_ns(); public abstract string get_id(); diff --git a/xmpp-vala/src/module/bind.vala b/xmpp-vala/src/module/bind.vala index 0bc271fb..f4b1a948 100644 --- a/xmpp-vala/src/module/bind.vala +++ b/xmpp-vala/src/module/bind.vala @@ -5,8 +5,7 @@ namespace Xmpp.Bind { /** The parties to a stream MUST consider resource binding as mandatory-to-negotiate. (RFC6120 7.3.1) */ public class Module : XmppStreamNegotiationModule { - public const string ID = "bind_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "bind_module"); private string requested_resource; @@ -17,7 +16,7 @@ namespace Xmpp.Bind { } public void iq_response_stanza(XmppStream stream, Iq.Stanza iq) { - var flag = Flag.get_flag(stream); + var flag = stream.get_flag(Flag.IDENTITY); if (flag == null || flag.finished) return; if (iq.type_ == Iq.Stanza.TYPE_RESULT) { @@ -54,15 +53,15 @@ namespace Xmpp.Bind { } public override bool mandatory_outstanding(XmppStream stream) { - return !Flag.has_flag(stream) || !Flag.get_flag(stream).finished; + return !stream.has_flag(Flag.IDENTITY) || !stream.get_flag(Flag.IDENTITY).finished; } public override bool negotiation_active(XmppStream stream) { - return Flag.has_flag(stream) && !Flag.get_flag(stream).finished; + return stream.has_flag(Flag.IDENTITY) && !stream.get_flag(Flag.IDENTITY).finished; } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private static void on_bind_response(XmppStream stream, Iq.Stanza iq) { stream.get_module(Bind.Module.IDENTITY).iq_response_stanza(stream, iq); @@ -70,19 +69,11 @@ namespace Xmpp.Bind { } public class Flag : XmppStreamFlag { - public const string ID = "bind"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "bind"); public string? my_jid; public bool finished = false; - public static Flag? get_flag(XmppStream stream) { - return (Flag?) stream.get_flag(NS_URI, ID); - } - - public static bool has_flag(XmppStream stream) { - return get_flag(stream) != null; - } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/iq/module.vala b/xmpp-vala/src/module/iq/module.vala index 693f1da3..eed3389d 100644 --- a/xmpp-vala/src/module/iq/module.vala +++ b/xmpp-vala/src/module/iq/module.vala @@ -6,8 +6,7 @@ namespace Xmpp.Iq { private const string NS_URI = "jabber:client"; public class Module : XmppStreamNegotiationModule { - public const string ID = "iq_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "iq_module"); private HashMap<string, ResponseListener> responseListeners = new HashMap<string, ResponseListener>(); private HashMap<string, ArrayList<Handler>> namespaceRegistrants = new HashMap<string, ArrayList<Handler>>(); @@ -48,10 +47,10 @@ namespace Xmpp.Iq { public override bool negotiation_active(XmppStream stream) { return false; } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_iq_stanza(XmppStream stream, StanzaNode node) { - Iq.Stanza iq = new Iq.Stanza.from_stanza(node, Bind.Flag.has_flag(stream) ? Bind.Flag.get_flag(stream).my_jid : null); + Iq.Stanza iq = new Iq.Stanza.from_stanza(node, stream.has_flag(Bind.Flag.IDENTITY) ? stream.get_flag(Bind.Flag.IDENTITY).my_jid : null); if (iq.type_ == Iq.Stanza.TYPE_RESULT || iq.is_error()) { if (responseListeners.has_key(iq.id)) { diff --git a/xmpp-vala/src/module/message/module.vala b/xmpp-vala/src/module/message/module.vala index 1d54443c..060cb4cb 100644 --- a/xmpp-vala/src/module/message/module.vala +++ b/xmpp-vala/src/module/message/module.vala @@ -6,8 +6,7 @@ namespace Xmpp.Message { private const string NS_URI = "jabber:client"; public class Module : XmppStreamModule { - public const string ID = "message_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "message_module"); public signal void pre_send_message(XmppStream stream, Message.Stanza message); public signal void pre_received_message(XmppStream stream, Message.Stanza message); @@ -19,7 +18,7 @@ namespace Xmpp.Message { } public void received_message_stanza(XmppStream stream, StanzaNode node) { - Message.Stanza message = new Message.Stanza.from_stanza(node, Bind.Flag.get_flag(stream).my_jid); + Message.Stanza message = new Message.Stanza.from_stanza(node, stream.get_flag(Bind.Flag.IDENTITY).my_jid); do { message.rerun_parsing = false; pre_received_message(stream, message); @@ -41,7 +40,7 @@ namespace Xmpp.Message { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/presence/flag.vala b/xmpp-vala/src/module/presence/flag.vala index a92c9405..8fb44e13 100644 --- a/xmpp-vala/src/module/presence/flag.vala +++ b/xmpp-vala/src/module/presence/flag.vala @@ -5,7 +5,7 @@ using Xmpp.Core; namespace Xmpp.Presence { public class Flag : XmppStreamFlag { - public const string ID = "presence"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "presence"); private HashMap<string, ConcurrentList<string>> resources = new HashMap<string, ConcurrentList<string>>(); private HashMap<string, Presence.Stanza> presences = new HashMap<string, Presence.Stanza>(); @@ -52,13 +52,9 @@ public class Flag : XmppStreamFlag { } } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/presence/module.vala b/xmpp-vala/src/module/presence/module.vala index 7e5dca17..3c078453 100644 --- a/xmpp-vala/src/module/presence/module.vala +++ b/xmpp-vala/src/module/presence/module.vala @@ -4,8 +4,7 @@ namespace Xmpp.Presence { private const string NS_URI = "jabber:client"; public class Module : XmppStreamModule { - public const string ID = "presence_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "presence_module"); public signal void received_presence(XmppStream stream, Presence.Stanza presence); public signal void pre_send_presence_stanza(XmppStream stream, Presence.Stanza presence); @@ -67,16 +66,16 @@ namespace Xmpp.Presence { } private void on_received_presence_stanza(XmppStream stream, StanzaNode node) { - Presence.Stanza presence = new Presence.Stanza.from_stanza(node, Bind.Flag.get_flag(stream).my_jid); + Presence.Stanza presence = new Presence.Stanza.from_stanza(node, stream.get_flag(Bind.Flag.IDENTITY).my_jid); received_presence(stream, presence); switch (presence.type_) { case Presence.Stanza.TYPE_AVAILABLE: - Flag.get_flag(stream).add_presence(presence); + stream.get_flag(Flag.IDENTITY).add_presence(presence); received_available(stream, presence); received_available_show(stream, presence.from, presence.show); break; case Presence.Stanza.TYPE_UNAVAILABLE: - Flag.get_flag(stream).remove_presence(presence.from); + stream.get_flag(Flag.IDENTITY).remove_presence(presence.from); received_unavailable(stream, presence.from); break; case Presence.Stanza.TYPE_SUBSCRIBE: @@ -101,7 +100,7 @@ namespace Xmpp.Presence { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/roster/flag.vala b/xmpp-vala/src/module/roster/flag.vala index c3e35158..43d185d9 100644 --- a/xmpp-vala/src/module/roster/flag.vala +++ b/xmpp-vala/src/module/roster/flag.vala @@ -6,9 +6,11 @@ namespace Xmpp.Roster { public class Flag : XmppStreamFlag { public const string ID = "roster"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, ID); + public HashMap<string, Item> roster_items = new HashMap<string, Item>(); - internal string? iq_id; + public string? iq_id; public Collection<Item> get_roster() { return roster_items.values; @@ -18,13 +20,8 @@ public class Flag : XmppStreamFlag { return roster_items[jid]; } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/roster/module.vala b/xmpp-vala/src/module/roster/module.vala index f29b73f7..1ebb7f22 100644 --- a/xmpp-vala/src/module/roster/module.vala +++ b/xmpp-vala/src/module/roster/module.vala @@ -6,8 +6,7 @@ namespace Xmpp.Roster { private const string NS_URI = "jabber:iq:roster"; public class Module : XmppStreamModule, Iq.Handler { - public const string ID = "roster_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "roster_module"); public signal void received_roster(XmppStream stream, Collection<Item> roster); public signal void item_removed(XmppStream stream, Item roster_item); @@ -56,7 +55,7 @@ namespace Xmpp.Roster { StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI); if (query_node == null) return; - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); Item item = new Item.from_stanza_node(query_node.get_subnode("item", NS_URI)); switch (item.subscription) { case Item.SUBSCRIPTION_REMOVE: @@ -89,17 +88,17 @@ namespace Xmpp.Roster { } internal override string get_ns() { return NS_URI; } - internal override string get_id() { return ID; } + internal override string get_id() { return IDENTITY.id; } private void roster_get(XmppStream stream) { - Flag.get_flag(stream).iq_id = random_uuid(); + stream.get_flag(Flag.IDENTITY).iq_id = random_uuid(); StanzaNode query_node = new StanzaNode.build("query", NS_URI).add_self_xmlns(); - Iq.Stanza iq = new Iq.Stanza.get(query_node, Flag.get_flag(stream).iq_id); + Iq.Stanza iq = new Iq.Stanza.get(query_node, stream.get_flag(Flag.IDENTITY).iq_id); stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_roster_get_received); } private static void on_roster_get_received(XmppStream stream, Iq.Stanza iq) { - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); if (iq.id == flag.iq_id) { StanzaNode? query_node = iq.stanza.get_subnode("query", NS_URI); foreach (StanzaNode item_node in query_node.sub_nodes) { diff --git a/xmpp-vala/src/module/sasl.vala b/xmpp-vala/src/module/sasl.vala index 79748211..ee6a87f7 100644 --- a/xmpp-vala/src/module/sasl.vala +++ b/xmpp-vala/src/module/sasl.vala @@ -4,8 +4,7 @@ namespace Xmpp.PlainSasl { private const string NS_URI = "urn:ietf:params:xml:ns:xmpp-sasl"; public class Module : XmppStreamNegotiationModule { - public const string ID = "plain_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "plain_module"); private const string MECHANISM = "PLAIN"; private string name; @@ -33,18 +32,18 @@ namespace Xmpp.PlainSasl { if (node.ns_uri == NS_URI) { if (node.name == "success") { stream.require_setup(); - Flag.get_flag(stream).finished = true; + stream.get_flag(Flag.IDENTITY).finished = true; } else if (node.name == "failure") { - stream.remove_flag(Flag.get_flag(stream)); + stream.remove_flag(stream.get_flag(Flag.IDENTITY)); received_auth_failure(stream, node); } } } public void received_features_node(XmppStream stream) { - if (Flag.has_flag(stream)) return; + if (stream.has_flag(Flag.IDENTITY)) return; if (stream.is_setup_needed()) return; - if (!Tls.Flag.has_flag(stream) || !Tls.Flag.get_flag(stream).finished) return; + if (!stream.has_flag(Tls.Flag.IDENTITY) || !stream.get_flag(Tls.Flag.IDENTITY).finished) return; var mechanisms = stream.features.get_subnode("mechanisms", NS_URI); if (mechanisms != null) { @@ -105,32 +104,24 @@ namespace Xmpp.PlainSasl { } public override bool mandatory_outstanding(XmppStream stream) { - return !Flag.has_flag(stream) || !Flag.get_flag(stream).finished; + return !stream.has_flag(Flag.IDENTITY) || !stream.get_flag(Flag.IDENTITY).finished; } public override bool negotiation_active(XmppStream stream) { - return Flag.has_flag(stream) && !Flag.get_flag(stream).finished; + return stream.has_flag(Flag.IDENTITY) && !stream.get_flag(Flag.IDENTITY).finished; } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } public class Flag : XmppStreamFlag { - public const string ID = "sasl"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "sasl"); public string mechanism; public string name; public bool finished = false; - public static Flag? get_flag(XmppStream stream) { - return (Flag?) stream.get_flag(NS_URI, ID); - } - - public static bool has_flag(XmppStream stream) { - return get_flag(stream) != null; - } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/stream_error.vala b/xmpp-vala/src/module/stream_error.vala index c775bdaa..bd292d2b 100644 --- a/xmpp-vala/src/module/stream_error.vala +++ b/xmpp-vala/src/module/stream_error.vala @@ -7,8 +7,7 @@ namespace Xmpp.StreamError { private const string NS_ERROR = "urn:ietf:params:xml:ns:xmpp-streams"; public class Module : XmppStreamModule { - public const string ID = "stream_error_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "stream_error_module"); public override void attach(XmppStream stream) { stream.received_nonza.connect(on_received_nonstanza); @@ -23,7 +22,7 @@ namespace Xmpp.StreamError { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_nonstanza(XmppStream stream, StanzaNode node) { if (node.name == "error" && node.ns_uri == "http://etherx.jabber.org/streams") { @@ -89,7 +88,7 @@ namespace Xmpp.StreamError { } public class Flag : XmppStreamFlag { - public const string ID = "stream_error"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "stream_error"); public enum Reconnect { UNKNOWN, @@ -102,15 +101,7 @@ namespace Xmpp.StreamError { public Reconnect reconnection_recomendation = Reconnect.UNKNOWN; public bool resource_rejected = false; - public static Flag? get_flag(XmppStream stream) { - return (Flag?) stream.get_flag(NS_URI, ID); - } - - public static bool has_flag(XmppStream stream) { - return get_flag(stream) != null; - } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/tls.vala b/xmpp-vala/src/module/tls.vala index 01dcf51d..8cc7ad16 100644 --- a/xmpp-vala/src/module/tls.vala +++ b/xmpp-vala/src/module/tls.vala @@ -4,8 +4,7 @@ namespace Xmpp.Tls { private const string NS_URI = "urn:ietf:params:xml:ns:xmpp-tls"; public class Module : XmppStreamNegotiationModule { - public const string ID = "tls_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "tls_module"); public bool require { get; set; default = true; } public bool server_supports_tls = false; @@ -34,7 +33,7 @@ namespace Xmpp.Tls { // not allowed to continue in case that there is an error. stream.reset_stream(conn); - var flag = Flag.get_flag(stream); + var flag = stream.get_flag(Flag.IDENTITY); flag.peer_certificate = conn.get_peer_certificate(); flag.finished = true; } catch (Error e) { @@ -44,7 +43,7 @@ namespace Xmpp.Tls { } private void received_features_node(XmppStream stream) { - if (Flag.has_flag(stream)) return; + if (stream.has_flag(Flag.IDENTITY)) return; if (stream.is_setup_needed()) return; var starttls = stream.features.get_subnode("starttls", NS_URI); @@ -68,31 +67,23 @@ namespace Xmpp.Tls { } public override bool mandatory_outstanding(XmppStream stream) { - return require && (!Flag.has_flag(stream) || !Flag.get_flag(stream).finished); + return require && (!stream.has_flag(Flag.IDENTITY) || !stream.get_flag(Flag.IDENTITY).finished); } public override bool negotiation_active(XmppStream stream) { - return Flag.has_flag(stream) && !Flag.get_flag(stream).finished; + return stream.has_flag(Flag.IDENTITY) && !stream.get_flag(Flag.IDENTITY).finished; } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } public class Flag : XmppStreamFlag { - public const string ID = "tls_flag"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "tls"); public TlsCertificate? peer_certificate; public bool finished = false; - public static Flag? get_flag(XmppStream stream) { - return (Flag?) stream.get_flag(NS_URI, ID); - } - - public static bool has_flag(XmppStream stream) { - return get_flag(stream) != null; - } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } } diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala index 5be9f2eb..0f82f498 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/flag.vala @@ -5,7 +5,7 @@ using Xmpp.Core; namespace Xmpp.Xep.ServiceDiscovery { public class Flag : XmppStreamFlag { - public const string ID = "service_discovery"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "service_discovery"); private HashMap<string, ArrayList<string>> entity_features = new HashMap<string, ArrayList<string>>(); public ArrayList<string> features = new ArrayList<string>(); @@ -21,13 +21,9 @@ public class Flag : XmppStreamFlag { public void add_own_feature(string feature) { features.add(feature); } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala index 56df7771..4b51e230 100644 --- a/xmpp-vala/src/module/xep/0030_service_discovery/module.vala +++ b/xmpp-vala/src/module/xep/0030_service_discovery/module.vala @@ -8,8 +8,7 @@ namespace Xmpp.Xep.ServiceDiscovery { public const string NS_URI_ITEMS = NS_URI + "#items"; public class Module : XmppStreamModule, Iq.Handler { - public const string ID = "0030_service_discovery_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0030_service_discovery_module"); public ArrayList<Identity> identities = new ArrayList<Identity>(); @@ -18,7 +17,7 @@ namespace Xmpp.Xep.ServiceDiscovery { } public void add_feature(XmppStream stream, string feature) { - Flag.get_flag(stream).add_own_feature(feature); + stream.get_flag(Flag.IDENTITY).add_own_feature(feature); } public void add_feature_notify(XmppStream stream, string feature) { @@ -66,21 +65,21 @@ namespace Xmpp.Xep.ServiceDiscovery { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private static void on_request_info_response(XmppStream stream, Iq.Stanza iq, Object o) { Tuple<OnInfoResult, Object> tuple = o as Tuple<OnInfoResult, Object>; OnInfoResult on_result = tuple.a; InfoResult? result = InfoResult.create_from_iq(iq); if (result != null) { - Flag.get_flag(stream).set_entitiy_features(iq.from, result.features); + stream.get_flag(Flag.IDENTITY).set_entitiy_features(iq.from, result.features); on_result(stream, result, tuple.b); } } private void send_query_result(XmppStream stream, Iq.Stanza iq_request) { InfoResult query_result = new ServiceDiscovery.InfoResult(iq_request); - query_result.features = Flag.get_flag(stream).features; + query_result.features = stream.get_flag(Flag.IDENTITY).features; query_result.identities = identities; stream.get_module(Iq.Module.IDENTITY).send_iq(stream, query_result.iq); } diff --git a/xmpp-vala/src/module/xep/0045_muc/flag.vala b/xmpp-vala/src/module/xep/0045_muc/flag.vala index 13363220..f6340a5c 100644 --- a/xmpp-vala/src/module/xep/0045_muc/flag.vala +++ b/xmpp-vala/src/module/xep/0045_muc/flag.vala @@ -5,7 +5,7 @@ using Xmpp.Core; namespace Xmpp.Xep.Muc { public class Flag : XmppStreamFlag { - public const string ID = "muc"; + public static FlagIdentity<Flag> IDENTITY = new FlagIdentity<Flag>(NS_URI, "muc"); private HashMap<string, ListenerHolder> enter_listeners = new HashMap<string, ListenerHolder>(); private HashMap<string, string> enter_ids = new HashMap<string, string>(); @@ -68,13 +68,9 @@ public class Flag : XmppStreamFlag { occupant_role.unset(full_jid); } - public static Flag? get_flag(XmppStream stream) { return (Flag?) stream.get_flag(NS_URI, ID); } - - public static bool has_flag(XmppStream stream) { return get_flag(stream) != null; } - public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } } }
\ No newline at end of file diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 8e139799..624d8421 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -29,8 +29,7 @@ public enum MucEnterError { } public class Module : XmppStreamModule { - public const string ID = "0045_muc_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0045_muc_module"); public signal void received_occupant_affiliation(XmppStream stream, string jid, string? affiliation); public signal void received_occupant_jid(XmppStream stream, string jid, string? real_jid); @@ -46,13 +45,13 @@ public class Module : XmppStreamModule { } presence.stanza.put_node(x_node); - Muc.Flag.get_flag(stream).start_muc_enter(bare_jid, presence.id, new ListenerHolder(success_listener, error_listener, store)); + stream.get_flag(Flag.IDENTITY).start_muc_enter(bare_jid, presence.id, new ListenerHolder(success_listener, error_listener, store)); stream.get_module(Presence.Module.IDENTITY).send_presence(stream, presence); } public void exit(XmppStream stream, string jid) { - string nick = Flag.get_flag(stream).get_muc_nick(jid); + string nick = stream.get_flag(Flag.IDENTITY).get_muc_nick(jid); Presence.Stanza presence = new Presence.Stanza(); presence.to = jid + "/" + nick; presence.type_ = Presence.Stanza.TYPE_UNAVAILABLE; @@ -103,7 +102,7 @@ public class Module : XmppStreamModule { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void change_role(XmppStream stream, string jid, string nick, string new_role) { StanzaNode query = new StanzaNode.build("query", NS_URI_ADMIN).add_self_xmlns(); @@ -118,14 +117,14 @@ public class Module : XmppStreamModule { StanzaNode? subject_node = message.stanza.get_subnode("subject"); if (subject_node != null) { string subject = subject_node.get_string_content(); - Muc.Flag.get_flag(stream).set_muc_subject(message.from, subject); + stream.get_flag(Flag.IDENTITY).set_muc_subject(message.from, subject); subject_set(stream, subject, message.from); } } } private void on_received_presence(XmppStream stream, Presence.Stanza presence) { - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); if (presence.is_error() && flag.is_muc_enter_outstanding() && flag.is_occupant(presence.from)) { string bare_jid = get_bare_jid(presence.from); ErrorStanza? error_stanza = presence.get_error(); @@ -152,7 +151,7 @@ public class Module : XmppStreamModule { } private void on_received_available(XmppStream stream, Presence.Stanza presence) { - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); if (flag.is_occupant(presence.from)) { StanzaNode? x_node = presence.stanza.get_subnode("x", NS_URI_USER); if (x_node != null) { @@ -181,7 +180,7 @@ public class Module : XmppStreamModule { } private void on_received_unavailable(XmppStream stream, string jid) { - Flag flag = Flag.get_flag(stream); + Flag flag = stream.get_flag(Flag.IDENTITY); if (flag.is_occupant(jid)) { flag.remove_occupant_info(jid); } diff --git a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala index 656ea6fd..4cb91a5b 100644 --- a/xmpp-vala/src/module/xep/0048_bookmarks/module.vala +++ b/xmpp-vala/src/module/xep/0048_bookmarks/module.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.Bookmarks { private const string NS_URI = "storage:bookmarks"; public class Module : XmppStreamModule { - public const string ID = "0048_bookmarks_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0048_bookmarks_module"); public signal void conferences_updated(XmppStream stream, ArrayList<Conference> conferences); @@ -91,7 +90,7 @@ public class Module : XmppStreamModule { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private static ArrayList<Conference> get_conferences_from_stanza(StanzaNode node) { ArrayList<Conference> conferences = new ArrayList<Conference>(); diff --git a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala index a5d872b6..b843f63b 100644 --- a/xmpp-vala/src/module/xep/0049_private_xml_storage.vala +++ b/xmpp-vala/src/module/xep/0049_private_xml_storage.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.PrivateXmlStorage { private const string NS_URI = "jabber:iq:private"; public class Module : XmppStreamModule { - public const string ID = "0049_private_xml_storage"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0049_private_xml_storage"); [CCode (has_target = false)] public delegate void OnSuccess(XmppStream stream, Object? reference); public void store(XmppStream stream, StanzaNode node, OnSuccess listener, Object? reference) { @@ -34,7 +33,7 @@ namespace Xmpp.Xep.PrivateXmlStorage { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private static void on_store_response(XmppStream stream, Iq.Stanza iq, Object o) { Tuple<OnSuccess, Object> tuple = o as Tuple<OnSuccess, Object>; diff --git a/xmpp-vala/src/module/xep/0054_vcard/module.vala b/xmpp-vala/src/module/xep/0054_vcard/module.vala index b4c6910b..040e0646 100644 --- a/xmpp-vala/src/module/xep/0054_vcard/module.vala +++ b/xmpp-vala/src/module/xep/0054_vcard/module.vala @@ -5,8 +5,7 @@ private const string NS_URI = "vcard-temp"; private const string NS_URI_UPDATE = NS_URI + ":x:update"; public class Module : XmppStreamModule { - public const string ID = "0027_current_pgp_usage"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0027_current_pgp_usage"); public signal void received_avatar(XmppStream stream, string jid, string id); @@ -31,7 +30,7 @@ public class Module : XmppStreamModule { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_presence(XmppStream stream, Presence.Stanza presence) { StanzaNode? update_node = presence.stanza.get_subnode("x", NS_URI_UPDATE); @@ -41,14 +40,14 @@ public class Module : XmppStreamModule { string? sha1 = photo_node.get_string_content(); if (sha1 == null) return; if (storage.has_image(sha1)) { - if (Muc.Flag.get_flag(stream).is_occupant(presence.from)) { + if (stream.get_flag(Muc.Flag.IDENTITY).is_occupant(presence.from)) { received_avatar(stream, presence.from, sha1); } else { received_avatar(stream, get_bare_jid(presence.from), sha1); } } else { Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("vCard", NS_URI).add_self_xmlns()); - if (Muc.Flag.get_flag(stream).is_occupant(presence.from)) { + if (stream.get_flag(Muc.Flag.IDENTITY).is_occupant(presence.from)) { iq.to = presence.from; } else { iq.to = get_bare_jid(presence.from); diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala index 9c2f4ebf..84b7fe9a 100644 --- a/xmpp-vala/src/module/xep/0060_pubsub.vala +++ b/xmpp-vala/src/module/xep/0060_pubsub.vala @@ -7,8 +7,7 @@ namespace Xmpp.Xep.Pubsub { private const string NS_URI_EVENT = NS_URI + "#event"; public class Module : XmppStreamModule { - public const string ID = "0060_pubsub_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0060_pubsub_module"); private HashMap<string, EventListenerDelegate> event_listeners = new HashMap<string, EventListenerDelegate>(); @@ -51,7 +50,7 @@ namespace Xmpp.Xep.Pubsub { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_message(XmppStream stream, Message.Stanza message) { StanzaNode event_node = message.stanza.get_subnode("event", NS_URI_EVENT); if (event_node == null) return; diff --git a/xmpp-vala/src/module/xep/0084_user_avatars.vala b/xmpp-vala/src/module/xep/0084_user_avatars.vala index 248620fa..fec46675 100644 --- a/xmpp-vala/src/module/xep/0084_user_avatars.vala +++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.UserAvatars { private const string NS_URI_METADATA = NS_URI + ":metadata"; public class Module : XmppStreamModule { - public const string ID = "0084_user_avatars"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0084_user_avatars"); public signal void received_avatar(XmppStream stream, string jid, string id); @@ -58,7 +57,7 @@ namespace Xmpp.Xep.UserAvatars { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private static void on_pubsub_data_response(XmppStream stream, string jid, string? id, StanzaNode? node, Object? o) { if (node == null) return; diff --git a/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala b/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala index 6dbbb6f6..6212cade 100644 --- a/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala +++ b/xmpp-vala/src/module/xep/0085_chat_state_notifications.vala @@ -14,8 +14,7 @@ public const string STATE_PAUSED = "paused"; private const string[] STATES = {STATE_ACTIVE, STATE_INACTIVE, STATE_GONE, STATE_COMPOSING, STATE_PAUSED}; public class Module : XmppStreamModule { - public const string ID = "0085_chat_state_notifications"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0085_chat_state_notifications"); public signal void chat_state_received(XmppStream stream, string jid, string state); @@ -47,7 +46,7 @@ public class Module : XmppStreamModule { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_pre_send_message(XmppStream stream, Message.Stanza message) { if (message.body == null) return; diff --git a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala index 9387faaa..e1d6e6ff 100644 --- a/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala +++ b/xmpp-vala/src/module/xep/0115_entitiy_capabilities.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.EntityCapabilities { private const string NS_URI = "http://jabber.org/protocol/caps"; public class Module : XmppStreamModule { - public const string ID = "0115_entity_capabilities"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0115_entity_capabilities"); private string own_ver_hash; private Storage storage; @@ -18,7 +17,7 @@ namespace Xmpp.Xep.EntityCapabilities { private string get_own_hash(XmppStream stream) { if (own_ver_hash == null) { - own_ver_hash = compute_hash(stream.get_module(ServiceDiscovery.Module.IDENTITY).identities, ServiceDiscovery.Flag.get_flag(stream).features); + own_ver_hash = compute_hash(stream.get_module(ServiceDiscovery.Module.IDENTITY).identities, stream.get_flag(ServiceDiscovery.Flag.IDENTITY).features); } return own_ver_hash; } @@ -41,7 +40,7 @@ namespace Xmpp.Xep.EntityCapabilities { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_pre_send_presence_stanza(XmppStream stream, Presence.Stanza presence) { if (presence.type_ == Presence.Stanza.TYPE_AVAILABLE) { @@ -60,7 +59,7 @@ namespace Xmpp.Xep.EntityCapabilities { if (capabilities.size == 0) { stream.get_module(ServiceDiscovery.Module.IDENTITY).request_info(stream, presence.from, on_received_info_response, Tuple.create(storage, ver_attribute)); } else { - ServiceDiscovery.Flag.get_flag(stream).set_entitiy_features(presence.from, capabilities); + stream.get_flag(ServiceDiscovery.Flag.IDENTITY).set_entitiy_features(presence.from, capabilities); } } } diff --git a/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala b/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala index b8597d07..ed19f9a4 100644 --- a/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala +++ b/xmpp-vala/src/module/xep/0184_message_delivery_receipts.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.MessageDeliveryReceipts { private const string NS_URI = "urn:xmpp:receipts"; public class Module : XmppStreamModule { - public const string ID = "0184_message_delivery_receipts"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0184_message_delivery_receipts"); public signal void receipt_received(XmppStream stream, string jid, string id); @@ -30,7 +29,7 @@ namespace Xmpp.Xep.MessageDeliveryReceipts { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void received_message(XmppStream stream, Message.Stanza message) { StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI); diff --git a/xmpp-vala/src/module/xep/0199_ping.vala b/xmpp-vala/src/module/xep/0199_ping.vala index 35cad26c..3b11bd73 100644 --- a/xmpp-vala/src/module/xep/0199_ping.vala +++ b/xmpp-vala/src/module/xep/0199_ping.vala @@ -6,8 +6,7 @@ namespace Xmpp.Xep.Ping { private const string NS_URI = "urn:xmpp:ping"; public class Module : XmppStreamModule { - public const string ID = "0199_ping"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0199_ping"); public void send_ping(XmppStream stream, string jid, ResponseListener listener) { Iq.Stanza iq = new Iq.Stanza.get(new StanzaNode.build("ping", NS_URI).add_self_xmlns()); @@ -27,7 +26,7 @@ namespace Xmpp.Xep.Ping { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private class IqHandlerImpl : Iq.Handler, Object { public void on_iq_get(XmppStream stream, Iq.Stanza iq) { diff --git a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala index 4dbe33ff..fe56abc2 100644 --- a/xmpp-vala/src/module/xep/0203_delayed_delivery.vala +++ b/xmpp-vala/src/module/xep/0203_delayed_delivery.vala @@ -4,8 +4,7 @@ namespace Xmpp.Xep.DelayedDelivery { private const string NS_URI = "urn:xmpp:delay"; public class Module : XmppStreamModule { - public const string ID = "0203_delayed_delivery"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0203_delayed_delivery"); public static void set_message_delay(Message.Stanza message, DateTime datetime) { StanzaNode delay_node = (new StanzaNode.build("delay", NS_URI)).add_self_xmlns(); @@ -34,7 +33,7 @@ namespace Xmpp.Xep.DelayedDelivery { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_pre_received_message(XmppStream stream, Message.Stanza message) { DateTime? datetime = get_send_time(message); diff --git a/xmpp-vala/src/module/xep/0280_message_carbons.vala b/xmpp-vala/src/module/xep/0280_message_carbons.vala index 6f11ec05..58805a96 100644 --- a/xmpp-vala/src/module/xep/0280_message_carbons.vala +++ b/xmpp-vala/src/module/xep/0280_message_carbons.vala @@ -4,8 +4,7 @@ namespace Xmpp.Xep.MessageCarbons { private const string NS_URI = "urn:xmpp:carbons:2"; public class Module : XmppStreamModule { - public const string ID = "0280_message_carbons_module"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0280_message_carbons_module"); public void enable(XmppStream stream) { Iq.Stanza iq = new Iq.Stanza.set(new StanzaNode.build("enable", NS_URI).add_self_xmlns()); @@ -38,7 +37,7 @@ namespace Xmpp.Xep.MessageCarbons { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void pre_received_message(XmppStream stream, Message.Stanza message) { StanzaNode? received_node = message.stanza.get_subnode("received", NS_URI); @@ -51,7 +50,7 @@ namespace Xmpp.Xep.MessageCarbons { string? from_attribute = message_node.get_attribute("from", Message.NS_URI); // The security model assumed by this document is that all of the resources for a single user are in the same trust boundary. // Any forwarded copies received by a Carbons-enabled client MUST be from that user's bare JID; any copies that do not meet this requirement MUST be ignored. - if (from_attribute != null && from_attribute == get_bare_jid(Bind.Flag.get_flag(stream).my_jid)) { + if (from_attribute != null && from_attribute == get_bare_jid(stream.get_flag(Bind.Flag.IDENTITY).my_jid)) { if (received_node != null) { message.add_flag(new MessageFlag(MessageFlag.TYPE_RECEIVED)); } else if (sent_node != null) { @@ -68,7 +67,7 @@ namespace Xmpp.Xep.MessageCarbons { } public class MessageFlag : Message.MessageFlag { - public const string id = "message_carbons"; + public const string ID = "message_carbons"; public const string TYPE_RECEIVED = "received"; public const string TYPE_SENT = "sent"; @@ -79,10 +78,10 @@ namespace Xmpp.Xep.MessageCarbons { } public static MessageFlag? get_flag(Message.Stanza message) { - return (MessageFlag) message.get_flag(NS_URI, id); + return (MessageFlag) message.get_flag(NS_URI, ID); } public override string get_ns() { return NS_URI; } - public override string get_id() { return id; } + public override string get_id() { return ID; } } } diff --git a/xmpp-vala/src/module/xep/0333_chat_markers.vala b/xmpp-vala/src/module/xep/0333_chat_markers.vala index 46fb92fa..7ac70806 100644 --- a/xmpp-vala/src/module/xep/0333_chat_markers.vala +++ b/xmpp-vala/src/module/xep/0333_chat_markers.vala @@ -12,8 +12,7 @@ public const string MARKER_ACKNOWLEDGED = "acknowledged"; private const string[] MARKERS = {MARKER_RECEIVED, MARKER_DISPLAYED, MARKER_ACKNOWLEDGED}; public class Module : XmppStreamModule { - public const string ID = "0333_chat_markers"; - public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, ID); + public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0333_chat_markers"); public signal void marker_received(XmppStream stream, string jid, string marker, string id); @@ -50,7 +49,7 @@ public class Module : XmppStreamModule { } public override string get_ns() { return NS_URI; } - public override string get_id() { return ID; } + public override string get_id() { return IDENTITY.id; } private void on_received_message(XmppStream stream, Message.Stanza message) { if (message.type_ != Message.Stanza.TYPE_CHAT) return; |