/// <summary> /// 删除回复 /// </summary> /// <returns></returns> public string DeleteReplies() { if (Signature != GetParam("sig").ToString()) { ErrorCode = (int)ErrorType.API_EC_SIGNATURE; return ""; } //如果是桌面程序则需要验证用户身份 if (this.App.ApplicationType == (int)ApplicationType.DESKTOP) { if (Uid < 1) { ErrorCode = (int)ErrorType.API_EC_SESSIONKEY; return ""; } } if (CallId <= LastCallId) { ErrorCode = (int)ErrorType.API_EC_CALLID; return string.Empty; } if (!CheckRequiredParams("post_ids,tid")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return string.Empty; } string successfulIds = string.Empty; int tid = GetIntParam("tid"); //如果是桌面程序则需要验证用户身份 if (this.App.ApplicationType == (int)ApplicationType.DESKTOP) { ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(Uid); TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid); if (!Discuz.Forum.Moderators.IsModer(userInfo.Adminid, Uid, topicInfo.Fid)) { ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED; return ""; } } int i = 0; string postTableId = Discuz.Forum.Posts.GetPostTableId(tid); Posts.RemoveShowTopicCache(tid.ToString()); foreach (string s in GetParam("post_ids").ToString().Split(',')) { int pid = TypeConverter.StrToInt(s); if (pid < 1) continue; if (Discuz.Forum.Posts.DeletePost(postTableId, pid, false, true) > 0) { successfulIds += (pid + ","); i++; } if (i >= 20) { break; } } if (successfulIds.Length > 0) successfulIds = successfulIds.Remove(successfulIds.Length - 1); if (Format == FormatType.JSON) return string.Format("\"{0}\"", successfulIds); TopicDeleteRepliesResponse tdrr = new TopicDeleteRepliesResponse(); tdrr.Result = successfulIds; return SerializationHelper.Serialize(tdrr); }
public override bool Run(CommandParameter commandParam, ref string result) { if (!commandParam.CheckRequiredParams("post_ids,tid")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } string successfulIds = string.Empty; int tid = commandParam.GetIntParam("tid"); //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(commandParam.LocalUid); TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid); if (!Discuz.Forum.Moderators.IsModer(userInfo.Adminid, commandParam.LocalUid, topicInfo.Fid)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return false; } } int i = 0; string postTableId = Discuz.Forum.Posts.GetPostTableId(tid); foreach (string s in commandParam.GetDNTParam("post_ids").ToString().Split(',')) { int pid = TypeConverter.StrToInt(s); if (pid < 1) continue; if (Discuz.Forum.Posts.DeletePost(postTableId, pid, false, true) > 0) successfulIds += (pid + ","); if (++i >= 20) break; } if (successfulIds.Length > 0) successfulIds = successfulIds.Remove(successfulIds.Length - 1); if (commandParam.Format == FormatType.JSON) result = string.Format("\"{0}\"", successfulIds); else { TopicDeleteRepliesResponse tdrr = new TopicDeleteRepliesResponse(); tdrr.Result = successfulIds; result = SerializationHelper.Serialize(tdrr); } return true; }