예제 #1
0
 public ChatFullConstructor(int id, ChatParticipants participants, Photo chat_photo, PeerNotifySettings notify_settings)
 {
     this.id              = id;
     this.participants    = participants;
     this.chat_photo      = chat_photo;
     this.notify_settings = notify_settings;
 }
예제 #2
0
 public override void Read(BinaryReader reader)
 {
     this.id              = reader.ReadInt32();
     this.participants    = Tl.Parse <ChatParticipants>(reader);
     this.chat_photo      = Tl.Parse <Photo>(reader);
     this.notify_settings = Tl.Parse <PeerNotifySettings>(reader);
 }
        public static string GetChatParticipant(RestCommand command, int chatParticipantID)
        {
            ChatParticipant chatParticipant = ChatParticipants.GetChatParticipant(command.LoginUser, chatParticipantID);

            if (chatParticipant.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(chatParticipant.GetXml("ChatParticipant", true));
        }
예제 #4
0
        public async Task <ActionResult <Guid> > CreateChat([FromBody] ChatParticipants chatParticipants)
        {
            if (ModelState.ErrorCount > 0)
            {
                return(BadRequest(new Response {
                    Status = "Error!", Message = "Something went wrong"
                }));
            }
            var chatGD = await _chatManager.CreateChat(chatParticipants);

            return(Ok(chatGD));
        }
        public static string GetChatParticipants(RestCommand command)
        {
            ChatParticipants chatParticipants = new ChatParticipants(command.LoginUser);

            chatParticipants.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(chatParticipants.GetXml("ChatParticipants", "ChatParticipant", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
예제 #6
0
    public static string[] GetChatHtml(UserInfoProxy userInfo, int chatID, int lastMessageID)
    {
        LoginUser       loginUser = new LoginUser(userInfo.UserID, userInfo.OrganizationID, null);
        ChatUserSetting setting   = ChatUserSettings.GetSetting(loginUser, loginUser.UserID);

        setting.CurrentChatID = chatID;
        setting.Collection.Save();

        Chat chat = Chats.GetChat(loginUser, chatID);

        if (chat == null || chat.OrganizationID != loginUser.OrganizationID)
        {
            return(null);
        }

        ChatMessages messages = new ChatMessages(loginUser);
        int          i        = messages.GetLastMessageID(chatID);
        string       chatHtml = "";

        if (i > -1 && i != lastMessageID)
        {
            ChatParticipants.UpdateLastMessageID(loginUser, loginUser.UserID, ChatParticipantType.User, chatID, i);
            chatHtml = chat.GetHtml(true, loginUser.CultureInfo);
        }


        // load typers
        ChatParticipants participants = new ChatParticipants(loginUser);

        participants.LoadTypers(loginUser.UserID, ChatParticipantType.User, chatID, 2);
        StringBuilder typers = new StringBuilder();

        foreach (ChatParticipant item in participants)
        {
            if (typers.Length > 0)
            {
                typers.Append(", ");
            }
            typers.Append(item.FirstName);
        }

        if (typers.Length > 0)
        {
            typers.Append(" is typing a message.");
        }

        return(new string[] { chatID.ToString(), i.ToString(), chatHtml, typers.ToString() });
    }
예제 #7
0
        public async Task <Guid> CreateChat(ChatParticipants chatParticipants)
        {
            // Query to add the chat participants
            var addParticipantsQuery =
                @"
                insert into chat_participants
                values
                (
                    @_gd, @_user1_gd, @_user2_gd
                )
            ";

            // Generate chatGD
            var chatGD             = GenerateGd();
            var chatParticipantsGD = GenerateGd();

            // Execute addParticipantsQuery
            await PostQuery(addParticipantsQuery, new
            {
                _gd       = chatParticipantsGD,
                _user1_gd = chatParticipants.user1_gd,
                _user2_gd = chatParticipants.user2_gd
            });

            // Query to create the chat
            var createChatQuery =
                @"
                insert into chatroom
                values
                (
                    @_gd, @_users_gd, GETDATE()
                )
            ";

            // Execute createChatQuery
            await PostQuery(createChatQuery, new
            {
                _gd       = chatGD,
                _users_gd = chatParticipantsGD
            });

            return(chatGD);
        }
예제 #8
0
    public static string[] GetActiveChatsHtml(UserInfoProxy userInfo, bool forceUpdate, int activeChatID)
    {
        LoginUser loginUser = new LoginUser(userInfo.UserID, userInfo.OrganizationID, null);

        Chats.KickOutDisconnectedClients(loginUser, loginUser.OrganizationID);
        StringBuilder builder = new StringBuilder();

        ChatParticipants participants = new ChatParticipants(loginUser);

        participants.LoadByUserID(loginUser.UserID, loginUser.OrganizationID);

        if (!participants.IsEmpty)
        {
            int chatID = -1;

            StringBuilder names = new StringBuilder();
            foreach (ChatParticipant item in participants)
            {
                if (item.ParticipantType != ChatParticipantType.External)
                {
                    continue;
                }

                bool   isNew = (int)item.Row["LastPostedMessageID"] != (int)item.Row["MyLastMessageID"];
                string state = isNew ? "ui-state-highlight" : "chat-state-normal";
                state = activeChatID == item.ChatID ? "ui-state-default" : state;

                if (chatID != item.ChatID)
                {
                    if (names.Length > 0)
                    {
                        names.Append("</div>");
                    }
                    names.Append(string.Format("<div id=\"divChat{0}\" class=\"chat ui-corner-all ts-icon-container ui-widget ui-helper-reset {1} \">", item.ChatID.ToString(), state));
                }
                string name = item.FirstName + " " + item.LastName;
                if (!string.IsNullOrEmpty(item.CompanyName))
                {
                    name = name + " - " + item.CompanyName;
                }

                names.Append(string.Format("<span class=\"ts-icon {1}\"/><span class=\"ts-icon-text\">{0}</span>", name, item.IsOnline ? "ts-icon-online" : "ts-icon-offline"));
                chatID = item.ChatID;
            }
            names.Append("</div>");
            builder.Append(names.ToString());
        }

        string html = builder.ToString().Trim();

        if (html == "")
        {
            html = "<div class=\"chat\">There are no active chats.</div>";
        }
        if (!forceUpdate && HttpContext.Current.Session["LastChatHtml"] != null && (string)HttpContext.Current.Session["LastChatHtml"] == html)
        {
            return(null);
        }
        HttpContext.Current.Session["LastChatHtml"] = html;
        return(new string[] { html, activeChatID.ToString() });
    }
예제 #9
0
 public static void SetTyping(int chatID)
 {
     ChatParticipants.UpdateTyping(UserSession.LoginUser, UserSession.LoginUser.UserID, ChatParticipantType.User, chatID);
 }
        public void SeedData()
        {
            var users = new[]
            {
                new User()
                {
                    NickName = "NotZero_Bot", Password = "******"
                },
                new User()
                {
                    NickName = "ChinPin_Bot", Password = "******"
                },
                new User()
                {
                    NickName = "Viking_Bot", Password = "******"
                },
                new User()
                {
                    NickName = "Patriot_Bot", Password = "******"
                }
            };
            var chats = new[]
            {
                new Chat()
            };
            var chatParticipants = new[]
            {
                new ChatParticipant()
                {
                    Chatroom = chats[0], Participant = users[0]
                },
                new ChatParticipant()
                {
                    Chatroom = chats[0], Participant = users[1]
                },
                new ChatParticipant()
                {
                    Chatroom = chats[0], Participant = users[2]
                },
                new ChatParticipant()
                {
                    Chatroom = chats[0], Participant = users[3]
                }
            };
            var messages = new[]
            {
                new Message()
                {
                    Chatroom = chats[0], Body = "1 message", SendDate = DateTime.Now.AddMinutes(-10), SendingUser = users[0]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "2 message", SendDate = DateTime.Now.AddMinutes(-9), SendingUser = users[1]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "3 message", SendDate = DateTime.Now.AddMinutes(-8), SendingUser = users[2]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "4 message", SendDate = DateTime.Now.AddMinutes(-7), SendingUser = users[2]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "5 message", SendDate = DateTime.Now.AddMinutes(-6), SendingUser = users[3]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "6 message", SendDate = DateTime.Now.AddMinutes(-5), SendingUser = users[1]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "7 message", SendDate = DateTime.Now.AddMinutes(-4), SendingUser = users[0]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "8 message", SendDate = DateTime.Now.AddMinutes(-3), SendingUser = users[0]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "9 message", SendDate = DateTime.Now.AddMinutes(-2), SendingUser = users[1]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "10 message", SendDate = DateTime.Now.AddMinutes(-1), SendingUser = users[2]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "11 message", SendDate = DateTime.Now.AddMinutes(-0), SendingUser = users[0]
                },
                new Message()
                {
                    Chatroom = chats[0], Body = "11 message", SendDate = DateTime.Now.AddMinutes(-0), SendingUser = users[3]
                },
            };

            Users.AddRange(users);
            Chats.AddRange(chats);
            ChatParticipants.AddRange(chatParticipants);
            foreach (var item in messages)
            {
                Messages.Add(item);
                this.SaveChanges();
            }
        }
 public override void Read(BinaryReader reader)
 {
     this.participants = Tl.Parse <ChatParticipants>(reader);
 }
 public UpdateChatParticipantsConstructor(ChatParticipants participants)
 {
     this.participants = participants;
 }