示例#1
0
文件: MatrixRoom.cs 项目: mistay/yuck
        public override string ToString()
        {
            string direct = directRoom == null ? "" : directRoom ? "direct:" : "room:";


            string ret = "";

            if (directRoom)
            {
                ret = Businesslogic.MatrixUsernameToShortUsername(roomNameHumanReadable);
            }
            else
            {
                if (roomNameHumanReadable == null)
                {
                    ret = roomID;
                }
                else
                {
                    ret = roomNameHumanReadable;
                }

                ret += " Room";
            }
            return(ret);
        }
示例#2
0
        private void UserPresenceReceivedCallback(Dictionary <string, string> changed)
        {
            if (presenceLoaded)
            {
                foreach (KeyValuePair <string, string> c in changed)
                {
                    Console.WriteLine("user came " + c.Value + ": " + c.Key);

                    string message = "";
                    switch (c.Value)
                    {
                    case "online":
                        message = "user came online";
                        break;

                    case "offline":
                        message = "user went offline";
                        break;

                    default:
                        message = "presence changed but dunno how. neither online nor offline. from server: " + c.Value;
                        break;
                    }

                    Notification n = new Notification(3000, message, Businesslogic.MatrixUsernameToShortUsername(c.Key));
                    n.NotificationClickedEvent += NotificationClickedCallback;
                    n.Tag       = c.Key; //todo: keep users in list of e.g. class MatrixUsers and lookup user. pass as instance
                    n.Audiofile = Properties.Resources.icq_knock;
                    n.Show();
                    //notifyIcon1.ShowBalloonTip(1000, message, c.Key, ToolTipIcon.Info);
                }
            }
            presenceLoaded = true;

            lstUsers.Items.Clear();
            foreach (KeyValuePair <string, string> presence in Businesslogic.Instance.presence)
            {
                lstUsers.Items.Add(presence.Key + ": " + presence.Value);
            }
        }
示例#3
0
        private void AvatarURLReceivedCallback(MatrixAvatarResult matrixAvatarResult)
        {
            Uri uri = Businesslogic.MXC2HTTP(matrixAvatarResult.avatar_url);

            if (uri == null)
            {
                Bitmap   b     = new Bitmap(100, 100);
                Graphics g     = Graphics.FromImage(b);
                Brush    brush = Brushes.White;
                g.FillEllipse(Brushes.Blue, new Rectangle(0, 0, 100, 100));
                string firstcharusername = (Businesslogic.MatrixUsernameToShortUsername(Businesslogic.Instance.loggedInUserID)).Substring(0, 1).ToUpper();
                g.DrawString(firstcharusername, new Font(FontFamily.GenericSansSerif, 70), brush, new Point(5, 0));

                pbAvatar.Image = b;  // Properties.Resources.User_Avatar;

                pbAvatar.SizeMode = PictureBoxSizeMode.Zoom;
            }
            else
            {
                Businesslogic.Instance.downloadAvatar(uri, null);
            }
        }
示例#4
0
        private void RoomsDirectResolvedCallback()
        {
            foreach (MatrixRoom matrixRoom in matrixRooms)
            {
                foreach (KeyValuePair <string, List <string> > d in Businesslogic.Instance.direct)
                {
                    foreach (string roomID in d.Value)
                    {
                        if (roomID == matrixRoom.roomID)
                        {
                            Console.WriteLine("resolved room (direct contact): " + d.Key);
                            matrixRoom.roomNameHumanReadable = d.Key;
                            matrixRoom.directRoom            = true;


                            //Businesslogic.Instance.downloadAvatar(uri)
                            //Businesslogic.Instance.avatar .downloadAvatar(uri);
                        }
                    }
                }
            }

            for (int i = 0; i < lvRooms.Items.Count; i++)
            {
                foreach (KeyValuePair <string, List <string> > d in Businesslogic.Instance.direct)
                {
                    foreach (string roomID in d.Value)
                    {
                        if (roomID == lvRooms.Items[i].ImageKey)
                        {
                            Console.WriteLine("resolved room (direct contact): " + d.Key);
                            lvRooms.Items[i].Text = Businesslogic.MatrixUsernameToShortUsername(d.Key); // resolved name, e.g. "armin"
                        }
                    }
                }
            }
            refreshlstRoomsUpdate();
        }
示例#5
0
        private void SyncCompletedCallback(MatrixSyncResult matrixSyncResult, bool initSync)
        {
            if (matrixSyncResult != null)
            {
                if (!initSync)
                {
                    // raise notifications for messages closed room-windows
                    foreach (KeyValuePair <string, MatrixSyncResultTimelineWrapper> messagesForRoomID in matrixSyncResult.rooms.join)
                    {
                        Console.WriteLine("syncCompletedCallback()");

                        string roomID = messagesForRoomID.Key;

                        bool skip = false;
                        foreach (Form form in Application.OpenForms)
                        {
                            if (form is Chat)
                            {
                                Chat chat = (Chat)form;
                                if (chat.MatrixRoom.roomID == messagesForRoomID.Key)
                                {
                                    // skip notifcation because window is open
                                    skip = true;
                                    break;
                                }
                            }
                        }
                        if (skip)
                        {
                            continue;
                        }

                        MatrixSyncResultTimelineWrapper wrapper = messagesForRoomID.Value;
                        foreach (MatrixSyncResultEvents events in wrapper.timeline.events)
                        {
                            string sender  = String.Format("{0}", Businesslogic.MatrixUsernameToShortUsername(events.sender));
                            int    timeout = 3000;
                            string message = "";
                            if (events.content.msgtype == "m.text")
                            {
                                if (events.content.format == "org.matrix.custom.html")
                                {
                                }
                                else
                                {
                                    timeout = calcTimeoutFromWords(events.content.body);
                                    message = events.content.body;
                                }
                            }

                            if (events.content.msgtype == "m.image")
                            {
                                message = "new image received";
                            }
                            Notification n = new Notification(timeout, sender, message);

                            // todo: loop through matrixrooms in businesslogic and resolve there. note: Businesslogic.Instance.roomCache does not contain MatrixRooms
                            foreach (MatrixRoom m in matrixRooms)
                            {
                                if (m.roomID == roomID)
                                {
                                    //found
                                    n.Tag = m;
                                    break;
                                }
                            }
                            n.NotificationClickedEvent += NotificationClickedCallback; // todo: howto/when unsubscribe?
                            n.Show();
                        }
                    }
                }



                // show messages (in chat history) in openend room-windows
                foreach (Form form in Application.OpenForms)
                {
                    if (form is Chat)
                    {
                        Chat chat = (Chat)form;
                        Console.WriteLine(chat.MatrixRoom.roomID);


                        foreach (ChatMessage chatMessage in Businesslogic.Instance.chatMessages)
                        {
                            if (chat.MatrixRoom.roomID == chatMessage.RoomID && !chatMessage.Displayed)
                            {
                                chatMessage.Displayed = true;
                                Console.WriteLine(String.Format("displaying message from {0} for room {1}: {2}", chatMessage.Sender, chat.MatrixRoom.roomID, chatMessage.Message));
                                //unencrypted
                                chat.processIncomingChatMessage(chatMessage.Sender, chatMessage.Message);
                            }
                        }
                    }
                }
            }

            Businesslogic.Instance.sync();
        }