public void AdminDeleteSessions(int operatorUserID, IEnumerable <int> sessionIds) { if (ValidateUtil.HasItems <int>(sessionIds)) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { List <int> ids = new List <int>(); foreach (int id in sessionIds) { ids.Add(id); } int[] t = new int[ids.Count]; ids.CopyTo(t); try { settings.PassportService.Chat_AdminDeleteSessions(operatorUserID, t); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); } } else #endif { Guid[] excludeRoleIDs = PermissionSet.GetNoPermissionTargetRoleIds(operatorUserID, PermissionTargetType.Content); ChatDao.Instance.AdminDeleteSessions(sessionIds, excludeRoleIDs); } } }
public ChatSessionCollection GetChatSessionsWithUnreadMessages(int operatorID, int topCount) { if (operatorID <= 0) { ThrowError(new NotLoginError()); return(new ChatSessionCollection()); } if (topCount <= 0) { return(new ChatSessionCollection()); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { ChatSessionProxy[] sessiongs = settings.PassportService.Chat_GetChatSessionsWithUnreadMessages(operatorID, topCount); ChatSessionCollection result = new ChatSessionCollection(); foreach (ChatSessionProxy s in sessiongs) { result.Add(GetChatSession(s)); } return(result); } else #endif { return(ChatDao.Instance.GetChatSessionsWithUnreadMessages(operatorID, topCount)); } }
/// <summary> /// 获取所有通知 /// </summary> /// <returns>返回所有通知集合</returns> public NotifyCollection GetAllNotifies(int pageSize, int pageNumber, ref int?count) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { NotifyProxy[] notifys = settings.PassportService.Notify_GetAllNotifies(pageSize, pageNumber, ref count); NotifyCollection result = new NotifyCollection(); foreach (NotifyProxy proxy in notifys) { result.Add(GetNotify(proxy)); } return(result); } else #endif { pageNumber = pageNumber <= 0 ? 1 : pageNumber; pageSize = pageSize <= 0 ? Consts.DefaultPageSize : pageSize; if (HasUnCatchedError) { return(new NotifyCollection()); } return(NotifyDao.Instance.GetNotifies(null, pageSize, pageNumber, ref count)); } }
public ChatSession GetChatSession(int operatorID, int targetUserID) { if (operatorID <= 0) { ThrowError(new NotLoginError()); return(null); } if (targetUserID <= 0) { return(null); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { ChatSessionProxy session = settings.PassportService.Chat_GetChatSessionByUserID(operatorID, targetUserID); return(GetChatSession(session)); } else #endif { return(ChatDao.Instance.GetChatSession(operatorID, targetUserID)); } }
public void SaveSettings() { MessageDisplay msgDisplay = CreateMessageDisplay(); AppConfig appConfig = (AppConfig)Globals.CurrentAppConfig.Clone(); PassportClientConfig config = appConfig.PassportClient; config.EnablePassport = _Request.Get <bool>("EnablePassport", Method.Post, false); accessKey = config.AccessKey; if (config.EnablePassport) { string passportOwnerUsername = _Request.Get("passportOwnerUsername", Method.Post); string passportOwnerPassword = _Request.Get("passportOwnerPassword", Method.Post); config.PassportRoot = _Request.Get("passportRoot", Method.Post); if (!config.TestPassportService(config.PassportRoot, 5000)) { msgDisplay.AddError("无法连接服务器“" + config.PassportRoot + "”,可能的原因:<br />1、 服务器地址不正确<br />2、 服务器未开放Passport接口<br />3、 请检查服务器和本地防火墙设置<br />4、请检查服务器和本地网站的.asmx后缀处理程序是否正确"); return; } registerClient = _Request.Get <bool>("registerClient", Method.Post, false); if (registerClient) { APIResult result = null; try { result = config.RegisterPassportClient(passportOwnerUsername, passportOwnerPassword, out newClientID); if (result.IsSuccess == false) { foreach (string s in result.Messages) { msgDisplay.AddError(s); return; } } else { config.ClientID = newClientID; } } catch (Exception ex) { msgDisplay.AddError(ex.Message); return; } } } Globals.SaveAppConfig(appConfig); //SaveSetting<PassportClientConfig>("savesetting"); if (registerClient) { HttpRuntime.UnloadAppDomain(); } }
private string GetAvatarPath(UserAvatarSize size) { if (AvatarPropFlag.Available) { string s = UserBO.Instance.GetAvatarSizeDirectoryName(size); s = this.AvatarPropFlag.PropData.Replace("{size}", s); usePropAvatar = true; return(UrlUtil.ResolveUrl(s)); // return Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar,, this.AvatarPropFlag.PropData); } usePropAvatar = false; //判断头像是否存在,如果存在直接返回头像 string avatarSrc = AvatarSrc; if (string.IsNullOrEmpty(avatarSrc) == false) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { string avatarRelativeUrl = Globals.GetRelativeUrl(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc).Remove(0, 1); return(UrlUtil.JoinUrl(settings.PassportRoot, avatarRelativeUrl)); } #endif return(Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar, UserBO.Instance.GetAvatarSizeDirectoryName(size), avatarSrc)); } //当头像和附加头像都为空时,使用默认头像 string defaultAvatarUrl; switch (size) { case UserAvatarSize.Small: defaultAvatarUrl = Consts.DefaultUserAvatar_Small; break; case UserAvatarSize.Big: defaultAvatarUrl = Consts.DefaultUserAvatar_Big; break; default: defaultAvatarUrl = Consts.DefaultUserAvatar_Default; break; } #if !Passport PassportClientConfig settings2 = Globals.PassportClient; if (settings2.EnablePassport) { return(UrlUtil.JoinUrl(settings2.PassportRoot, defaultAvatarUrl)); } #endif return(Globals.GetVirtualPath(SystemDirecotry.Root, defaultAvatarUrl)); }
/// <summary> /// 全部忽略某类型的通知 /// </summary> /// <param name="userID"></param> /// <param name="type"></param> public void DeleteNotifysByType(AuthUser operatorUser, int type) { if (operatorUser == User.Guest) { return; } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { APIResult result = null; try { result = settings.PassportService.Notify_DeleteNotifysByType(operatorUser.UserID, type); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); return; } if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); } } else #endif { if (type == 0) { int maxID = 0; foreach (SystemNotify sn in operatorUser.SystemNotifys) { if (maxID < sn.NotifyID) { maxID = sn.NotifyID; } } operatorUser.SystemNotifys.Clear(); UserBO.Instance.UpdateMaxSystemNotifyID(operatorUser, maxID); } NotifyDao.Instance.DeleteNotifysByType(operatorUser.UserID, type); RemoveCacheByType(operatorUser.UserID, type); } }
public bool IgnoreNotifies(int oparetorUserID, IEnumerable <int> notifyIDs, out UnreadNotifies unread) { unread = new UnreadNotifies(); if (!ValidateUtil.HasItems <int>(notifyIDs)) { return(true); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { List <int> ids = new List <int>(); foreach (int id in notifyIDs) { ids.Add(id); } int[] t = new int[ids.Count]; ids.CopyTo(t); UnreadNotifiesProxy proxy = settings.PassportService.Notify_IgnoreNotifies(oparetorUserID, t); unread = ProxyToUnreadNotifies(proxy); } else #endif { NotifyDao.Instance.IgnoreNotify(oparetorUserID, notifyIDs, out unread); } if (!unread.IsEmpty || unread.UserID > 0) { if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(unread); } AuthUser oparetorUser = UserBO.Instance.GetUserFromCache <AuthUser>(oparetorUserID); if (oparetorUser != null) { oparetorUser.UnreadNotify = unread; } RemoveCacheByType(oparetorUserID, 0); } return(true); }
public Notify GetNotify(int operatorID, int notifyID) { if (operatorID <= 0) { ThrowError(new NotLoginError()); return(null); } if (notifyID <= 0) { ThrowError(new InvalidParamError("notifyID")); return(null); } #if !Passport PassportClientConfig config = Globals.PassportClient; if (config.EnablePassport) { NotifyProxy notify = config.PassportService.Notify_GetNotify(operatorID, notifyID); if (notify == null) { return(null); } //if(T is friend return(GetNotify(notify)); } else #endif { Notify notify = NotifyDao.Instance.GetNotify <Notify>(null, notifyID, false); if (notify != null) { if (notify.UserID == operatorID) { return(notify); } if (ManagePermission.Can(operatorID, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID)) { return(notify); } } return(null); } }
public ChatMessageCollection GetLastChatMessages(int userID, int targetUserID, int lastMessageID, int messageCount) { if (!AllSettings.Current.ChatSettings.EnableChatFunction) { return(new ChatMessageCollection()); } messageCount = messageCount <= 0 ? 200 : messageCount; #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { ChatMessageProxy[] messages = settings.PassportService.Chat_GetLastChatMessages(userID, targetUserID, lastMessageID, messageCount); ChatMessageCollection result = new ChatMessageCollection(); foreach (ChatMessageProxy m in messages) { result.Add(GetChatMessage(m)); } return(result); } else #endif { ChatMessageCollection messages = ChatDao.Instance.GetLastChatMessages(userID, targetUserID, lastMessageID, messageCount); ProcessKeyword(messages, ProcessKeywordMode.TryUpdateKeyword); if (messages.Count > 0) { if (OnUsersMessageCountChanged != null) { AuthUser user = UserBO.Instance.GetAuthUser(userID); if (user != null) { Dictionary <int, int> counts = new Dictionary <int, int>(); counts.Add(userID, user.UnreadMessages); OnUsersMessageCountChanged(counts); } } } return(messages); } //if (OnChatUserMessageCountChanged != null) OnChatUserMessageCountChanged(userID); }
public SystemNotify GetSystemNotify(int notifyID) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { SystemNotifyProxy proxy = settings.PassportService.Notify_GetSystemNotify(notifyID); return(ProxyToSystemNotify(proxy)); } else #endif { return(NotifyDao.Instance.GetSystemNotify(notifyID)); } }
/// <summary> /// 获取指定用户指定类型的所有通知 /// </summary> /// <param name="notifyType">指定类型</param> /// <returns>指定用户指定类型的所有通知集合</returns> public NotifyCollection GetNotifiesByType(int userID, int notifyType, int pageSize, int pageNumber, ref int?count) { if (userID <= 0) { ThrowError(new NotLoginError()); return(new NotifyCollection()); } pageNumber = pageNumber <= 0 ? 1 : pageNumber; pageSize = pageSize <= 0 ? Consts.DefaultPageSize : pageSize; if (HasUnCatchedError) { return(new NotifyCollection()); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { NotifyProxy[] proxys = settings.PassportService.Notify_GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count); NotifyCollection notifies = new NotifyCollection(); foreach (NotifyProxy proxy in proxys) { notifies.Add(GetNotify(proxy)); } return(notifies); } else #endif { NotifyCollection notifys; string cacheKey = string.Format(cacheKey_pagedNotify, userID, notifyType, pageSize, pageNumber); if (!CacheUtil.TryGetValue <NotifyCollection>(cacheKey, out notifys)) { notifys = NotifyDao.Instance.GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count); CacheUtil.Set <NotifyCollection>(cacheKey, notifys); } count = notifys.TotalRecords; return(notifys); } }
public void ProcessRequest(System.Web.HttpContext context) { HttpRequest Request = context.Request; HttpResponse Response = context.Response; string cookie = Request.QueryString["authcookie"]; if (string.IsNullOrEmpty(cookie)) { context.Response.End(); return; } int userID = UserBO.Instance.GetUserID(cookie, true); AuthUser My = UserBO.Instance.GetAuthUser(userID); if (My == null || My == User.Guest) { Response.Write("error"); Response.End(); } if (string.IsNullOrEmpty(Request.QueryString["file"])) { string phyFile; Response.Write(UserBO.Instance.SaveTempAvatar(My, Request, out phyFile)); Response.End(); } else { if (Globals.PassportClient.EnablePassport) { PassportClientConfig settings = Globals.PassportClient; string passportAvatarUrl = string.Concat(settings.AvatarGeneratorUrl, "?kachashow=true&file=aaa.jpg"); KeyValuePair <string, string>[] heads = new KeyValuePair <string, string> [1]; heads[0] = new KeyValuePair <string, string>("size", Request.Headers["size"]); HttpWebResponse response = NetUtil.PostToRemoteUrl(Request, passportAvatarUrl, heads); Thread.Sleep(300); } else { UserBO.Instance.SaveAvatar(My, My.UserID, Request); } } }
/// <summary> /// 获取系统通知列表 /// </summary> /// <returns></returns> public SystemNotifyCollection GetSystemNotifys() { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { SystemNotifyProxy[] proxys = settings.PassportService.Notify_GetSystemNotifys(); SystemNotifyCollection result = new SystemNotifyCollection(); foreach (SystemNotifyProxy proxy in proxys) { result.Add(ProxyToSystemNotify(proxy)); } return(result); } else #endif { return(NotifyDao.Instance.GetSystemNotifies()); } }
protected void Page_Load(object sender, EventArgs e) { string passportRoot = _Request.Get("passportroot", Method.Post); if (string.IsNullOrEmpty(passportRoot)) { ShowError("请填写Passport服务器地址"); return; } bool success; string errMsg = string.Empty; using (ErrorScope es = new ErrorScope()) { PassportClientConfig setting = new PassportClientConfig(); success = setting.TestPassportService(passportRoot, 5000); if (es.HasUnCatchedError) { CatchError <ErrorInfo>(delegate(ErrorInfo error) { ShowError(error); return; //errMsg += error.Message; }); } } if (success) { ShowSuccess("Passport服务器通讯正常!"); } else { ShowError("无法连接" + passportRoot + "上的Passport服务!"); } }
protected void Page_Load(object sender, EventArgs e) { int userID = _Request.Get <int>("uid", Method.Get, 0); if (userID == MyUserID) { AuthUser my = My; UserBO.Instance.Logout(); #if !Passport OnlineUserPool.Instance.Remove(my); #endif } #if !Passport PassportClientConfig setting = Globals.PassportClient; if (setting.EnablePassport) { Response.Redirect(setting.LogoutUrl + "?returnurl=" + HttpUtility.UrlEncode(ReturnUrl)); return; } #endif ShowSuccess("您已经安全退出", AllSettings.Current.PassportServerSettings.EnablePassportService?ReturnUrl: IndexUrl); }
protected void Page_Load(object sender, EventArgs e) { AddNavigationItem("找回密码"); #if !Passport PassportClientConfig setting = Globals.PassportClient; if (setting.EnablePassport) { Response.Redirect(setting.RecoverPasswordUrl); return; } #endif if (_Request.IsClick("RecoverPassword")) { RecoverPassword(); } else if (_Request.IsClick("resetRecoverPassword")) { ResetRecoverPassword(); } }
/// <summary> /// 获取聊天会话,最近聊天的用户将出现在列表顶部 /// </summary> /// <param name="operatorID"></param> /// <param name="pageNumber"></param> /// <param name="pageSize"></param> /// <returns></returns> public ChatSessionCollection GetChatSessions(int operatorID, int pageNumber, int pageSize) { if (!AllSettings.Current.ChatSettings.EnableChatFunction) { return(new ChatSessionCollection()); } if (operatorID <= 0) { ThrowError(new NotLoginError()); return(new ChatSessionCollection()); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { int totalCount; ChatSessionProxy[] sessiongs = settings.PassportService.Chat_GetChatSessions(operatorID, pageNumber, pageSize, out totalCount); ChatSessionCollection result = new ChatSessionCollection(); foreach (ChatSessionProxy s in sessiongs) { result.Add(GetChatSession(s)); } result.TotalRecords = totalCount; return(result); } else #endif { ChatSessionCollection chatSessions = ChatDao.Instance.GetChatSessions(operatorID, pageNumber, pageSize); //UserBO.Instance.getsi return(chatSessions); } }
private void ProcessUploadAvatar() { #if !Passport if (Globals.PassportClient.EnablePassport) { PassportClientConfig settings = Globals.PassportClient; string passportAvatarUrl = string.Concat(settings.AvatarGeneratorUrl, "?kachashow=true&file=aaa.jpg"); KeyValuePair <string, string>[] heads = new KeyValuePair <string, string> [1]; heads[0] = new KeyValuePair <string, string>("size", Request.Headers["size"]); HttpWebResponse response = NetUtil.PostToRemoteUrl(Request, passportAvatarUrl, heads); Thread.Sleep(500); } else #endif { UserBO.Instance.SaveAvatar(My, MyUserID, Request); } }
public NotifyCollection GetTopNotifys(int userID, int count, int type) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { NotifyProxy[] notifys = new NotifyProxy[0]; try { notifys = settings.PassportService.Notify_GetTopNotify(userID, count, type); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); } NotifyCollection result = new NotifyCollection(); foreach (NotifyProxy proxy in notifys) { result.Add(GetNotify(proxy)); } return(result); } else #endif { NotifyCollection notifys; //string key = string.Format(cacheKey_UserNotifyType, userID, type, count, 1); //if (!CacheUtil.TryGetValue<NotifyCollection>(key, out notifys)) //{ notifys = NotifyDao.Instance.GetTopNotifys(userID, type, count); // CacheUtil.Set<NotifyCollection>(key, notifys); //} return(notifys); } }
protected void Page_Load(object sender, EventArgs e) { AddNavigationItem("登录"); #if !Passport PassportClientConfig setting = Globals.PassportClient; if (setting.EnablePassport) { string fromUrl = ReturnUrl; if (!fromUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { fromUrl = UrlUtil.JoinUrl(Globals.FullAppRoot, fromUrl); } Response.Redirect(setting.LoginUrl + "?returnurl=" + HttpUtility.UrlEncode(fromUrl)); return; } #endif if (_Request.IsClick("login")) { UserLogin(); } }
public ChatSessionCollection AdminGetSessions(int operatorUserID, ChatSessionFilter filter, int pageNumber) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { ChatSessionProxy[] sessons = settings.PassportService.Chat_AdminGetSessions(operatorUserID, GetChatSessionFilterProxy(filter), pageNumber); ChatSessionCollection result = new ChatSessionCollection(); foreach (ChatSessionProxy s in sessons) { result.Add(GetChatSession(s)); } return(result); } else #endif { Guid[] ExcludeRoleIds = PermissionSet.GetNoPermissionTargetRoleIds(operatorUserID, PermissionTargetType.Content); return(ChatDao.Instance.AdminGetSessions(filter, pageNumber, ExcludeRoleIds)); } }
protected void Page_Load(object sender, EventArgs e) { AddNavigationItem("注册新帐号"); #if !Passport PassportClientConfig setting = Globals.PassportClient; if (setting.EnablePassport) { Response.Redirect(setting.RegisterUrl); return; } #endif activeCode = _Request.Get("active", Method.Get); MessageDisplay msgDisplay = CreateMessageDisplay(); ValidateEmailAction activingEmailType = _Request.Get <ValidateEmailAction>("type", Method.Get, ValidateEmailAction.None); int isSent = _Request.Get("issent", Method.Get, 0); if (activingEmailType != ValidateEmailAction.None) { if (activingEmailType == ValidateEmailAction.ActivingUser) { IsActivingUser = true; } else { IsValidateEmail = true; } m_NeedActive = true; int userID = _Request.Get <int>("userid", Method.Get, 0); NeedActiveUser = UserBO.Instance.GetUser(userID); if (NeedActiveUser == null) { ShowError("该用户ID可能已经被删除,请重新注册!"); } m_email = NeedActiveUser.Email; CheckEmailLoginLink(m_email); } //判断用户是否点击了“注册”按钮 if (_Request.IsClick("register")) { Register(); } //判断用户是否点击了"重新发送邮件"按钮 else if (_Request.IsClick("sendmail")) { ResendEmail(); } //判断是否“激活帐号”操作 else if (!string.IsNullOrEmpty(activeCode)) { if (_Request.IsClick("activeme")) //这里加点击按钮判断是因为某些邮箱会抓取邮件里的链接,造成用户自动激活。 { using (ErrorScope es = new ErrorScope()) { if (UserBO.Instance.ActivingUser(activeCode)) { //用户激活成功 ShowSuccess("恭喜!您的账号" + My.Username + "已成功激活。", IndexUrl); } else { if (es.HasUnCatchedError) { es.CatchError <ErrorInfo>(delegate(ErrorInfo error) { IsOverrunLimitTimes = true; msgDisplay.AddError(error); }); } else { ShowError(new InvalidActiveCodeError("active", activeCode)); } } } } } //判断是否“重发激活邮件”的操作 else if (activingEmailType == ValidateEmailAction.ActivingUser && isSent != 1) { NeedSendMailClick = true; } //判断是否"重新发送验证邮箱的邮件" else if (activingEmailType == ValidateEmailAction.ValidateEmail && isSent != 1) { NeedSendMailClick = true; } }
public bool DeleteChatSessions(int operatorID, IEnumerable <int> targetUserIds) { if (operatorID <= 0) { ThrowError(new NotLoginError()); return(false); } //if (ValidateUtil.HasItems(targetUserIds) == false) //{ // ThrowError(new NotSelectedMessagesError("targetUserIds")); // return false; //} #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { List <int> ids = new List <int>(); foreach (int id in targetUserIds) { ids.Add(id); } int[] t = new int[ids.Count]; ids.CopyTo(t); APIResult result = null; try { result = settings.PassportService.Chat_DeleteChatSessions(operatorID, t); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); return(false); } if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } return(false); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(false); } return(true); } else #endif { bool success = ChatDao.Instance.DeleteChatSessions(operatorID, targetUserIds); if (success) { if (OnUsersMessageCountChanged != null) { AuthUser user = UserBO.Instance.GetAuthUser(operatorID); if (user != null) { Dictionary <int, int> counts = new Dictionary <int, int>(); counts.Add(operatorID, user.UnreadMessages); OnUsersMessageCountChanged(counts); } } } return(success); } }
/// <summary> /// 发送一个对话消息,并且根据指定参数决定是否需要同时返回最新消息 /// </summary> /// <param name="operatorID">发送者</param> /// <param name="targetUserID">接受者</param> /// <param name="contentWithoutEncode">未经html编码的内容</param> /// <param name="ip">发送者IP</param> /// <param name="processContent">是否处理内容</param> /// <param name="getNewMessages">是否需要同时返回最新消息</param> /// <param name="lastMessageID">如果需要返回最新消息,则传入客户端</param> /// <returns></returns> public ChatMessageCollection SendMessage(int operatorID, int targetUserID, string contentWithoutEncode, string ip, bool processContent, bool getNewMessages, int lastMessageID) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { ChatMessageProxy[] chatMessages; APIResult result = null; string content = ProcessChatContent(operatorID, contentWithoutEncode); content = content.Replace("{$root}", Globals.FullAppRoot); try { result = settings.PassportService.Chat_SendMessage(operatorID, targetUserID, content, ip, getNewMessages, lastMessageID, out chatMessages); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); return(new ChatMessageCollection()); } if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { ThrowError(new CustomError("远程服务器错误, 请稍后重试." + (result.Messages.Length > 0 ? result.Messages[0] : string.Empty))); } return(new ChatMessageCollection()); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(new ChatMessageCollection()); } ChatMessageCollection messages = new ChatMessageCollection(); foreach (ChatMessageProxy m in chatMessages) { messages.Add(GetChatMessage(m)); } return(messages); } else #endif { if (!AllSettings.Current.ChatSettings.EnableChatFunction) { return(new ChatMessageCollection()); } if (operatorID <= 0) { ThrowError(new NotLoginError()); return(new ChatMessageCollection()); } if (targetUserID <= 0) { ThrowError(new UserNotExistsError("targetUserID", targetUserID)); return(new ChatMessageCollection()); } if (operatorID == targetUserID) { ThrowError(new CustomError("targetUserID", "您不能和自己交谈")); //临时的 return(new ChatMessageCollection()); } if (string.IsNullOrEmpty(contentWithoutEncode) || (contentWithoutEncode = contentWithoutEncode.Trim()) == string.Empty) { ThrowError(new EmptyMessageContentError("contentWithoutEncode")); return(new ChatMessageCollection()); } if (contentWithoutEncode.Length > MaxContentLength) { ThrowError(new MessageContentLengthError("contentWithoutEncode", contentWithoutEncode, MaxContentLength)); return(new ChatMessageCollection()); } if (FriendBO.Instance.InMyBlacklist(targetUserID, operatorID)) { ThrowError(new InBlackListError()); return(new ChatMessageCollection()); } //if (AllSettings.Current.UserPermissionSet.Can(operatorID, UserPermissionSet.Action.UseMessage) == false) //{ // ThrowError(new NoPermissionUseMessageError()); // return false; //} string content = contentWithoutEncode; if (processContent) { content = ProcessChatContent(operatorID, content); } ContentKeywordSettings keywords = AllSettings.Current.ContentKeywordSettings; string keyword = null; if (keywords.BannedKeywords.IsMatch(content, out keyword)) { ThrowError(new ChatMessageBannedKeywordsError("content", keyword)); return(null); } ChatMessageCollection newMessages = ChatDao.Instance.SendMessage(operatorID, targetUserID, content, ip, getNewMessages, lastMessageID); AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(targetUserID); if (user != null) { user.UnreadMessages++; } if (OnUsersMessageCountChanged != null) { if (user == null) { user = UserBO.Instance.GetAuthUser(targetUserID); } if (user != null) { Dictionary <int, int> counts = new Dictionary <int, int>(); counts.Add(user.UserID, user.UnreadMessages); OnUsersMessageCountChanged(counts); } } ProcessKeyword(newMessages, ProcessKeywordMode.TryUpdateKeyword); return(newMessages); } }
/// <summary> /// 获取和某人的聊天记录,如果pageNumber为0则取最后一页 /// </summary> /// <param name="operatorID"></param> /// <param name="targetUserID"></param> /// <param name="pageNumber">0表示取最后一页</param> /// <param name="pageSize"></param> /// <returns></returns> private ChatMessageCollection GetChatMessages(int operatorID, int targetUserID, int pageNumber, int pageSize, bool processKeyword, bool updateIsReaded) { if (!AllSettings.Current.ChatSettings.EnableChatFunction) { return(new ChatMessageCollection()); } if (operatorID <= 0) { ThrowError(new NotLoginError()); return(new ChatMessageCollection()); } if (targetUserID <= 0) { return(new ChatMessageCollection()); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { int totalCount; ChatMessageProxy[] messages = settings.PassportService.Chat_GetChatMessages(operatorID, targetUserID, pageNumber, pageSize, processKeyword, updateIsReaded, out totalCount); ChatMessageCollection result = new ChatMessageCollection(); foreach (ChatMessageProxy m in messages) { result.Add(GetChatMessage(m)); } result.TotalRecords = totalCount; return(result); } else #endif { ChatMessageCollection Messages = ChatDao.Instance.GetChatMessages(operatorID, targetUserID, pageNumber, pageSize, updateIsReaded); if (updateIsReaded) { if (OnUsersMessageCountChanged != null) { AuthUser user = UserBO.Instance.GetAuthUser(operatorID); if (user != null) { Dictionary <int, int> counts = new Dictionary <int, int>(); counts.Add(operatorID, user.UnreadMessages); OnUsersMessageCountChanged(counts); } } } if (processKeyword) { ProcessKeyword(Messages, ProcessKeywordMode.TryUpdateKeyword); } else { ProcessKeyword(Messages, ProcessKeywordMode.FillOriginalText); } return(Messages); } }
/// <summary> /// 删除多个通知 /// </summary> /// <param name="notifyIDs">要删除的通知的ID集</param> public bool DeleteNotifies(int operatorUserID, IEnumerable <int> notifyIDs) { if (notifyIDs == null) { ThrowError(new NoSelectedNotifiesError("notifyIDs")); return(false); } if (!ValidateUtil.HasItems <int>(notifyIDs)) { return(true); } #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { List <int> ids = new List <int>(); foreach (int id in notifyIDs) { ids.Add(id); } int[] t = new int[ids.Count]; ids.CopyTo(t); APIResult result = null; try { result = settings.PassportService.Notify_DeleteNotifies(operatorUserID, t); } catch (Exception ex) { ThrowError(new APIError(ex.Message)); return(false); } if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } return(false); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(false); } return(true); } else #endif { List <int> deleteNotifyIds = new List <int>(); NotifyCollection notifies = NotifyDao.Instance.GetNotifies(notifyIDs); ///如果集合里没有数据, 会出现没有权限的误报, 因此直接返回 if (notifies.Count == 0) { return(true); } foreach (Notify notify in notifies) { if (notify.UserID == operatorUserID || ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID)) { deleteNotifyIds.Add(notify.NotifyID); } } if (deleteNotifyIds.Count == 0) { ThrowError(new NoPermissionDeleteNotifyError()); return(false); } UnreadNotifyCollection unread; NotifyDao.Instance.DeleteNotifies(null, deleteNotifyIds, out unread); foreach (UnreadNotifies un in unread) { RemoveCacheByType(un.UserID, 0); if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(un); } AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(un.UserID); if (user != null) { user.UnreadNotify = un; } } return(true); } }
public bool AddNotify(AuthUser oprateUser, Notify notify) { #region 基础参数检查 if (notify == null) { return(false); } if (notify.UserID <= 0) { return(false); } if (notify.UserID == oprateUser.UserID) { return(true); } #endregion UnreadNotifies UnreadNotifies = null; #if !Passport PassportClientConfig setting = Globals.PassportClient; if (setting.EnablePassport) { NotifyType type = AllNotifyTypes[notify.TypeID]; NotifyActionProxy[] proxys = new NotifyActionProxy[notify.Actions.Count]; int i = 0; foreach (NotifyAction action in notify.Actions) { NotifyActionProxy nap = new NotifyActionProxy(); nap.Url = "{clienturl}" + action.Url; nap.Title = action.Title; nap.IsDialog = action.IsDialog; proxys[i] = nap; i++; } ThreadPool.QueueUserWorkItem(delegate(object a) { try { setting.PassportService.Notify_Send(notify.UserID, type.TypeName, notify.Content, notify.DataTable.ToString(), proxys, notify.Keyword); } catch { } }); } else #endif { NotifyState SysState = AllSettings.Current.NotifySettings.GetNotifySystemState(notify.TypeID); SystemNotifyProvider.Update(); //判断系统设置 switch (SysState) { case NotifyState.AlwaysClose: return(false); case NotifyState.DefaultClose: case NotifyState.DefaultOpen: //判断用户设置 UserNotifySetting userSetting = UserBO.Instance.GetNotifySetting(notify.UserID); if (userSetting != null && userSetting.GetNotifyState(notify.TypeID) == NotifyState.DefaultClose) { return(false); } break; } StringTable actions = new StringTable(); if (notify.Actions != null) { foreach (NotifyAction na in notify.Actions) { actions.Add(na.Title, (na.IsDialog ? "*" : "") + na.Url); } } NotifyDao.Instance.AddNotify(notify.UserID, notify.TypeID, notify.Content, notify.Keyword, notify.DataTable.ToString(), 0, actions.ToString(), out UnreadNotifies); AuthUser user; user = UserBO.Instance.GetUserFromCache <AuthUser>(notify.UserID); if (user != null) { user.UnreadNotify = UnreadNotifies; } if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(UnreadNotifies); } RemoveCacheByType(notify.UserID, 0); return(true); } return(true); }
/// <summary> /// 删除通知 /// </summary> /// <param name="messageID">要删除的通知的ID</param> public bool DeleteNotify(AuthUser operatorUser, int notifyID) { #if !Passport PassportClientConfig settings = Globals.PassportClient; if (settings.EnablePassport) { APIResult result = settings.PassportService.Notify_DeleteNotify(operatorUser.UserID, notifyID); if (result.ErrorCode == Consts.ExceptionCode) { if (result.Messages.Length > 0) { throw new Exception(result.Messages[0]); } return(false); } else if (result.IsSuccess == false) { ThrowError <CustomError>(new CustomError("", result.Messages[0])); return(false); } return(true); } else #endif { Notify notify = NotifyDao.Instance.GetNotify <Notify>(null, notifyID, false); if (notify != null) { if (notify.UserID != operatorUser.UserID && ManagePermission.Can(operatorUser, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID) == false) { ThrowError(new NoPermissionDeleteNotifyError()); return(false); } if (HasUnCatchedError) { return(false); } UnreadNotifies unread; NotifyDao.Instance.DeleteNotify(null, notifyID, out unread); if (unread != null) { if (OnUserNotifyCountChanged != null) { OnUserNotifyCountChanged(unread); } AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(unread.UserID); if (user != null) { user.UnreadNotify = unread; } RemoveCacheByType(unread.UserID, 0); } } //bool isDeleted = NotifyDao.Instance.DeleteNotify(userID, notifyID); //if (isDeleted) //{ // UserBO.Instance.RemoveUserDataCache(notify.UserID); //} return(true); } }