/// <summary> /// 移除订阅者 /// </summary> /// <param name="subscriber">订阅者对象</param> /// <returns>结果</returns> public async Task<bool> RemoveSubscriber(Subscriber subscriber) { //判断订阅者是否位于订阅者列表中 if (!instance.SubscriberList.Contains(subscriber)) { return false; } Topic removedTopic = GetTopicByName(subscriber.TopicName); //订阅者列表更新 instance.SubscriberList.Remove(subscriber); //数据库更新 SubscriberController subscriberController = new SubscriberController(db.Subscribers); subscriberController.SetSubscriber(subscriber); subscriberController.DeleteSubscriber(); //话题列表更新 instance.TopicList.Remove(removedTopic); //数据库更新 TopicController topicController = await GetTopicController(removedTopic); topicController.DeleteTopic(); //向服务器请求删除订阅者 client.RemoveSubscriber(subscriber); return true; }
/// <summary> /// 通过订阅者位置移除订阅者 /// </summary> /// <param name="position">订阅者位置</param> /// <returns>结果</returns> public async Task<bool> RemoveSubsriberAt(int position) { if (position < 0 || position > instance.SubscriberList.Count) { return false; } Subscriber subscriber = instance.SubscriberList[position]; Topic removedTopic = GetTopicByName(subscriber.TopicName); //订阅者列表更新 instance.SubscriberList.Remove(subscriber); //数据库更新 SubscriberController subscriberController = new SubscriberController(db.Subscribers); subscriberController.SetSubscriber(subscriber); subscriberController.DeleteSubscriber(); //话题列表更新 instance.TopicList.Remove(removedTopic); //数据库更新 TopicController topicController = await GetTopicController(removedTopic); topicController.DeleteTopic(); //向服务器请求删除订阅者 client.RemoveSubscriber(subscriber); //移除成功返回真 return true; }
/// <summary> /// 移除订阅者(群组话题使用) /// </summary> /// <param name="subscriber">订阅者对象</param> /// <returns>结果</returns> public async Task <bool> RemoveSubscriber(Subscriber subscriber) { //判断订阅者是否位于订阅者列表中 if (!instance.SubsriberList.Contains(subscriber)) { //订阅者不存在返回假 return(false); } instance.SubsriberList.Remove(subscriber); //调用订阅者控制器删除订阅者 SubscriberController subscriberController = new SubscriberController(db.Subscribers); subscriberController.SetSubscriber(subscriber); subscriberController.DeleteSubscriber(); //更新话题时间戳 instance.LastUsed = ChatMessageBuilder.GetTimeStamp(); var dbContext = db.Topics.GetRepository(); await dbContext.UpsertTopic(instance); //删除成功返回真 return(true); }