Esempio n. 1
0
        /// <summary>
        /// 订阅话题
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns>结果</returns>
        public async Task<bool> AddTopic(Topic topic)
        {
            if (instance.TopicList.Contains(topic) || topic.Name.Equals("me") || topic.Name.Equals("fnd"))
            {
                return false;
            }

            //话题列表更新
            instance.TopicList.Add(topic);

            //数据库更新
            TopicController topicController = await GetTopicController(topic);
            topicController.UpsertTopic();

            return true;
        }
Esempio n. 2
0
        /// <summary>
        /// 取消置顶话题
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns>结果</returns>
        public async Task<bool> UnpinTopic(Topic topic)
        {
            if (!instance.TopicList.Contains(topic) || topic.Weight == 0)
            {
                return false;
            }

            //权重置为0
            topic.Weight = 0;

            //数据库更新
            TopicController topicController = await GetTopicController(topic);
            topicController.UpsertTopic();

            return true;
        }
Esempio n. 3
0
        /// <summary>
        /// 移动话题
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns></returns>
        public async Task<bool> MoveTopic(Topic topic)
        {
            if (!instance.TopicList.Contains(topic))
            {
                return false;
            }

            //话题列表更新
            int oldPosition = instance.TopicList.IndexOf(topic);
            instance.TopicList.RemoveAt(oldPosition);
            instance.TopicList.Insert(0, topic);

            //数据库更新
            TopicController topicController = await GetTopicController(topic);
            topicController.UpsertTopic();

            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// 通过话题获取话题控制器
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns>话题控制器</returns>
        public async Task<TopicController> GetTopicController(Topic topic)
        {
            if (topic == null)
            {
                return null;
            }

            //获取或创建控制器
            TopicController topicController;
            if (topicControllerDictionary.TryGetValue(topic.Name, out topicController) == false)
            {
                client.SubscribeTopic(topic);
                topicController = new TopicController(db);
                await topicController.SetTopic(topic);
                topicControllerDictionary.TryAdd(topic.Name, topicController);
            }

            return topicController;
        }
Esempio n. 5
0
        /// <summary>
        /// 通过话题名获取话题控制器
        /// </summary>
        /// <param name="name">话题名</param>
        /// <returns>话题控制器</returns>
        public async Task<TopicController> GetTopicControllerByName(string name)
        {
            int index = instance.TopicList.IndexOf(new Topic(name));
            if (index == -1)
            {
                return null;
            }
            
            //获取或创建控制器
            TopicController topicController;
            if (topicControllerDictionary.TryGetValue(name, out topicController) == false)
            {
                client.SubscribeTopic(instance.TopicList[index]);
                topicController = new TopicController(db);
                await topicController.SetTopic(instance.TopicList[index]);
                topicControllerDictionary.TryAdd(name, topicController);
            }

            return topicController;
        }
Esempio n. 6
0
        /// <summary>
        /// 移除话题
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns>结果</returns>
        public async Task<bool> RemoveTopic(Topic topic)
        {
            if (!instance.TopicList.Contains(topic))
            {
                return false;
            }

            instance.TopicList.Remove(topic);
            topic.IsArchived = true;

            //数据库更新
            TopicController topicController = await GetTopicController(topic);
            topicController.UpsertTopic();

            //话题列表更新
            instance.TopicList.Remove(topic);

            //服务器更新
            client.RemoveTopic(topic);


            return true;
        }
Esempio n. 7
0
        /// <summary>
        /// 通过话题位置移除话题
        /// </summary>
        /// <param name="position">话题位置</param>
        /// <returns>结果</returns>
        public async Task<bool> RemoveTopicAt(int position)
        {
            if (position < 0 || position > instance.TopicList.Count)
            {
                return false;
            }

            Topic topic = instance.TopicList[position];
            topic.IsArchived = true;

            //数据库更新
            TopicController topicController = await GetTopicController(topic);
            topicController.DeleteTopic();

            //话题列表更新
            instance.TopicList.Remove(topic);


            //服务器更新
            client.RemoveTopic(topic);

            return true;
        }
Esempio n. 8
0
 /// <summary>
 /// 获取话题控制器
 /// </summary>
 /// <returns>订阅者控制器</returns>
 public TopicController GetTopicController()
 {
     TopicController topicController = new TopicController(db);
     return topicController;
 }