Ejemplo n.º 1
0
        /// <summary>
        /// 新增订阅者
        /// </summary>
        /// <param name="subscriber">订阅者对象</param>
        /// <param name="isTemporary">是否临时保存</param>
        /// <returns>结果</returns>
        public async Task<bool> AddSubscriber(Subscriber subscriber, bool isTemporary = false)
        {
            //判断是否为有效订阅者
            if (instance.SubscriberList.Contains(subscriber) || subscriber.TopicName == "fnd" || subscriber.TopicName == "me")
            {
                //无效订阅者返回假
                return false;
            }

            //判断是否为临时查询
            if (isTemporary == true)
            {
                if (searchSubscriberResult.Contains(subscriber))
                {
                    return false;
                }
                searchSubscriberResult.Add(subscriber);
                return true;
            }

            //获取已存在话题或创建话题
            Topic newTopic = GetTopicByName(subscriber.TopicName);
            if (newTopic == null)
            {
                newTopic = new Topic(subscriber.TopicName);
            }

            if (newTopic == null)
            {
                newTopic = new Topic(subscriber.TopicName);
            }

            //话题列表更新
            await AddTopic(newTopic);

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

            //订阅者列表更新
            instance.SubscriberList.Add(subscriber);

            //数据库更新
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);
            subscriberController.SetSubscriber(subscriber);
            subscriberController.UpsertSubscriber();

            //服务器更新
            client.SubscribeTopic(newTopic);
            return true;
        }
Ejemplo 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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }