Пример #1
0
        public async Task InitSessionGroups()
        {
            var teamVM            = ServiceLocator.Current.GetInstance <TeamViewModel>();
            var conversationQuery = new AVQuery <AVObject>("_Conversation")
                                    .WhereEqualTo("team", teamVM.SelectdTeam).Limit(200);

            var conversations = (await conversationQuery.FindAsync())
                                .Select(x => AVIMConversation.CreateWithData(x, client));

            foreach (var conversation in conversations)
            {
                var session = new ConversationSessionViewModel(conversation);
                if (conversation.ContainsKey("category"))
                {
                    var category = conversation.Get <int>("category");
                    if (conversation.MemberIds.Contains(client.ClientId))
                    {
                        var group = this.SessionGroups.First(g => g.Category == category);
                        if (group != null)
                        {
                            group.Sessions.Add(session);
                        }
                    }
                    else
                    {
                        var group = this.SessionGroups.First(g => g.Category == -1);
                        if (group != null)
                        {
                            group.Sessions.Add(session);
                        }
                    }
                }
            }
        }
Пример #2
0
        public async Task CreateConversationExecuteAsync(UserSelectViewModel selected)
        {
            var members = selected.SelectedUsers
                          .Where(x => x.IsSelected)
                          .Select(u => u.UserInfo.Name)
                          .Concat(new string[] { client.ClientId });

            // 群聊 :0
            // 私聊:1
            var category = members.Count() > 3 ? 0 : 1;
            var options  = new Dictionary <string, object>();
            var name     = string.Join(",", members) + " 的群聊";

            if (category == 1)
            {
                name = string.Join("和", members) + " 的私聊";
            }
            var teamVM = ServiceLocator.Current.GetInstance <TeamViewModel>();

            options.Add("team", teamVM.SelectdTeam);
            options.Add("category", category);
            var newConversation = await client.CreateConversationAsync(members : members, name : name, options : options);

            var newSession = new ConversationSessionViewModel()
            {
                ConversationInSession = newConversation,
            };
            await newSession.LoadUsersInConversationAsync();

            var group = this.SessionGroups.First(x => x.Category == 0);

            group.Sessions.Add(newSession);
        }
Пример #3
0
        public async Task OpenConversationExecuteAsync(ConversationSessionViewModel selected)
        {
            if (this.SelectedSession.Equals(selected))
            {
                return;
            }
            this.SelectedSession = selected;

            await this.SelectedSession.LoadHistoryAsync(init : true, limit : 20);

            await this.SelectedSession.LoadUsersInConversationAsync(init : true);
        }
Пример #4
0
        public void CategoryClassify(ConversationSessionViewModel conversationVM)
        {
            var newHere = true;

            foreach (var sg in SessionGroups)
            {
                foreach (var session in sg.Sessions)
                {
                    if (session.Equals(conversationVM))
                    {
                        if (conversationVM.Category == session.Category)
                        {
                            return;
                        }
                        else
                        {
                            newHere = false;
                        }
                    }
                }
            }
            if (conversationVM.ConversationInSession.ContainsKey("category"))
            {
                var category = conversationVM.ConversationInSession.Get <int>("category");
                if (conversationVM.ConversationInSession.MemberIds.Contains(client.ClientId))
                {
                    var group = this.SessionGroups.First(g => g.Category == category);
                    if (group != null)
                    {
                        group.Sessions.Add(conversationVM);
                    }
                }
                else
                {
                    var group = this.SessionGroups.First(g => g.Category == -1);
                    if (group != null)
                    {
                        group.Sessions.Add(conversationVM);
                    }
                }
            }
        }