Esempio n. 1
0
        private async Task MucClient_PrivateMessageReceived(object Sender, RoomOccupantMessageEventArgs e)
        {
            RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain);

            OccupantNode Occupant = RoomNode.GetOccupantNode(e.NickName, null, null, null);

            MainWindow.ParseChatMessage(e, out string Message, out bool IsMarkdown, out DateTime Timestamp);

            MainWindow.currentInstance.MucPrivateChatMessage(e.From, XmppClient.GetBareJID(e.To), Message, e.ThreadID,
                                                             IsMarkdown, Timestamp, Occupant, e.From);
        }
Esempio n. 2
0
        private async Task MucClient_RoomSubject(object Sender, RoomOccupantMessageEventArgs e)
        {
            RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain);

            if (!RoomNode.Entered)
            {
                return;
            }

            MainWindow.UpdateGui(() =>
            {
                MainWindow.currentInstance.MucChatSubject(e.From, XmppClient.GetBareJID(e.To), RoomNode, e.Subject);
            });
        }
Esempio n. 3
0
        internal async Task MucClient_OccupantPresence(object Sender, UserPresenceEventArgs e)
        {
            RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain);

            OccupantNode OccupantNode = RoomNode.GetOccupantNode(e.NickName, e.Affiliation, e.Role, e.FullJid);
            ChatView     View         = null;

            if (!OccupantNode.Availability.HasValue || e.Availability != OccupantNode.Availability.Value)
            {
                OccupantNode.Availability = e.Availability;
                OccupantNode.OnUpdated();

                View = MainWindow.currentInstance.FindRoomView(e.From, XmppClient.GetBareJID(e.To));

                if (!(View is null))
                {
                    switch (OccupantNode.Availability)
                    {
                    case Availability.Online:
                        View.Event("Online.", e.NickName, string.Empty);
                        break;

                    case Availability.Offline:
                        View.Event("Offline.", e.NickName, string.Empty);
                        break;

                    case Availability.Away:
                        View.Event("Away.", e.NickName, string.Empty);
                        break;

                    case Availability.Chat:
                        View.Event("Ready to chat.", e.NickName, string.Empty);
                        break;

                    case Availability.DoNotDisturb:
                        View.Event("Busy.", e.NickName, string.Empty);
                        break;

                    case Availability.ExtendedAway:
                        View.Event("Away (extended).", e.NickName, string.Empty);
                        break;
                    }
                }
            }

            await this.MucClient_RoomPresence(Sender, e, View);
        }
Esempio n. 4
0
        private RoomNode AddRoomNode(string RoomId, string Domain, string NickName, string Password, string Name, bool Entered)
        {
            RoomNode Node = new RoomNode(this, RoomId, Domain, NickName, Password, Name, Entered);

            lock (this.roomByJid)
            {
                this.roomByJid[RoomId + "@" + Domain] = Node;
            }

            if (this.IsLoaded)
            {
                if (this.children is null)
                {
                    this.children = new SortedDictionary <string, TreeNode>()
                    {
                        { Node.Key, Node }
                    }
                }
                ;
                else
                {
                    lock (this.children)
                    {
                        this.children[Node.Key] = Node;
                    }
                }

                MainWindow.UpdateGui(() =>
                {
                    this.Account?.View?.NodeAdded(this, Node);

                    foreach (TreeNode Node2 in Node.Children)
                    {
                        this.Account?.View?.NodeAdded(Node, Node2);
                    }

                    this.OnUpdated();
                });
            }

            return(Node);
        }
Esempio n. 5
0
        private async Task MucClient_RoomOccupantMessage(object Sender, RoomOccupantMessageEventArgs e)
        {
            RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain);

            string       NickName = XmppClient.GetResource(e.From);
            ChatItemType Type     = ChatItemType.Received;

            if (!string.IsNullOrEmpty(NickName) && RoomNode.NickName == NickName)
            {
                bool HasDelay = false;

                foreach (XmlNode N in e.Message.ChildNodes)
                {
                    if (N is XmlElement E && E.LocalName == "delay")
                    {
                        HasDelay = true;
                        break;
                    }
                }

                if (!HasDelay)
                {
                    return;
                }

                Type = ChatItemType.Transmitted;
            }

            RoomNode.EnterIfNotAlready(true);

            MainWindow.UpdateGui(() =>
            {
                MainWindow.ParseChatMessage(e, out string Message, out bool IsMarkdown, out DateTime Timestamp);
                MainWindow.currentInstance.MucGroupChatMessage(e.From, XmppClient.GetBareJID(e.To), Message, e.ThreadID,
                                                               IsMarkdown, Timestamp, Type, RoomNode, RoomNode.Header);
            });
        }
Esempio n. 6
0
        private async Task MucClient_RoomPresence(object _, UserPresenceEventArgs e, ChatView View)
        {
            if ((e.MucStatus?.Length ?? 0) > 0 || e.RoomDestroyed)
            {
                RoomNode RoomNode = await this.GetRoomNode(e.RoomId, e.Domain);

                if (View is null)
                {
                    View = MainWindow.currentInstance.FindRoomView(e.From, XmppClient.GetBareJID(e.To));
                }

                if (!(View is null))
                {
                    foreach (MucStatus Status in e.MucStatus ?? new MucStatus[0])
                    {
                        switch (Status)
                        {
                        case MucStatus.AffiliationChanged:
                            if (e.Affiliation.HasValue)
                            {
                                View.Event("New affiliation: " + e.Affiliation.ToString(), e.NickName, string.Empty);
                            }
                            break;

                        case MucStatus.LoggingEnabled:
                            View.Event("This room logs messages.", e.NickName, string.Empty);
                            break;

                        case MucStatus.LoggingDisabled:
                            View.Event("This room does not log messages.", e.NickName, string.Empty);
                            break;

                        case MucStatus.NickModified:
                            View.Event("Nick-name changed.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RoomNonAnonymous:
                            View.Event("This room does not anonymous.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RoomSemiAnonymous:
                            View.Event("This room is semi-anonymous.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RoomAnonymous:
                            View.Event("This room does anonymous.", e.NickName, string.Empty);
                            break;

                        case MucStatus.FullJidVisisble:
                            View.Event("All participants in this room have access to the full JID of each other.", e.NickName, string.Empty);
                            break;

                        case MucStatus.ShowsUnavailableMembers:
                            View.Event("This room displays unavailable members.", e.NickName, string.Empty);
                            break;

                        case MucStatus.DoesNotShowUnavailableMembers:
                            View.Event("This room hieds unavailable members.", e.NickName, string.Empty);
                            break;

                        case MucStatus.NonPrivacyRelatedConfigurationChange:
                            View.Event("A configuration that does not affect privacy changed.", e.NickName, string.Empty);
                            break;

                        case MucStatus.OwnPresence:
                            break;

                        case MucStatus.Created:
                            View.Event("Room created.", e.NickName, string.Empty);
                            break;

                        case MucStatus.Banned:
                            View.Event("Banned from the room.", e.NickName, string.Empty);
                            break;

                        case MucStatus.NewRoomNickName:
                            View.Event("New room nick-name.", e.NickName, string.Empty);
                            break;

                        case MucStatus.Kicked:
                            View.Event("Temporarily kicked from the room.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RemovedDueToAffiliationChange:
                            View.Event("Removed from the room due to an affiliation change.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RemovedDueToNonMembership:
                            View.Event("Removed from the room, since no longer member.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RemovedDueToSystemShutdown:
                            View.Event("Removed from the room due to system shutdown.", e.NickName, string.Empty);
                            break;

                        case MucStatus.RemovedDueToFailure:
                            View.Event("Removed from the room due to technical problems.", e.NickName, string.Empty);
                            break;
                        }
                    }
                }

                if (e.RoomDestroyed)
                {
                    View?.Event("Room has been destroyed on the host.", e.NickName, string.Empty);

                    RoomNode.Parent.RemoveChild(RoomNode);
                    RoomNode.Parent.OnUpdated();
                }
            }
        }
Esempio n. 7
0
        protected override void LoadChildren()
        {
            if (!this.loadingChildren && !this.IsLoaded)
            {
                Mouse.OverrideCursor = Cursors.Wait;

                this.loadingChildren = true;
                this.Account.Client.SendServiceItemsDiscoveryRequest(this.mucClient.ComponentAddress, async(sender, e) =>
                {
                    this.loadingChildren = false;
                    MainWindow.MouseDefault();

                    if (e.Ok)
                    {
                        SortedDictionary <string, TreeNode> Children = new SortedDictionary <string, TreeNode>();

                        this.NodesRemoved(this.children.Values, this);

                        lock (this.roomByJid)
                        {
                            foreach (KeyValuePair <string, RoomNode> P in this.roomByJid)
                            {
                                Children[P.Key] = P.Value;
                            }
                        }

                        foreach (Item Item in e.Items)
                        {
                            string RoomId;
                            string Domain;
                            int i = Item.JID.IndexOf('@');

                            if (i < 0)
                            {
                                RoomId = string.Empty;
                                Domain = Item.JID;
                            }
                            else
                            {
                                RoomId = Item.JID.Substring(0, i);
                                Domain = Item.JID.Substring(i + 1);
                            }

                            string Jid = RoomId + "@" + Domain;

                            string Prefix   = this.mucClient.Client.BareJID + "." + Jid;
                            string NickName = await RuntimeSettings.GetAsync(Prefix + ".Nick", string.Empty);
                            string Password = await RuntimeSettings.GetAsync(Prefix + ".Pwd", string.Empty);

                            lock (this.roomByJid)
                            {
                                if (!this.roomByJid.TryGetValue(Jid, out RoomNode Node))
                                {
                                    Node = new RoomNode(this, RoomId, Domain, NickName, Password, Item.Name, false);
                                    this.roomByJid[Jid] = Node;
                                    Children[Item.JID]  = Node;
                                }
                            }
                        }

                        this.children = new SortedDictionary <string, TreeNode>(Children);
                        this.OnUpdated();
                        this.NodesAdded(Children.Values, this);
                    }
                    else
                    {
                        MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to get rooms." : e.ErrorText);
                    }
                }, null);
            }

            base.LoadChildren();
        }