/** * 添加封禁聊天室成员方法 * * @param chatroom:聊天室信息,memberIds(必传支持多个最多20个),minute:封禁时长,以分钟为单位,最大值为43200分钟。(必传) * * @return ResponseResult **/ public async Task <ResponseResult> Add(ChatroomModel chatroom) { string message = CommonUtil.CheckFiled(chatroom, PATH, CheckMethod.ADD); if (null != message) { return(RongJsonUtil.JsonStringToObj <ResponseResult>(message)); } StringBuilder sb = new StringBuilder(); ChatroomMember[] members = chatroom.Members; foreach (var member in members) { sb.Append("&userId=").Append(HttpUtility.UrlEncode(member.Id, UTF8)); } sb.Append("&chatroomId=").Append(HttpUtility.UrlEncode(chatroom.Id, UTF8)); sb.Append("&minute=").Append(HttpUtility.UrlEncode(chatroom.Minute.ToString(), UTF8)); string body = sb.ToString(); if (body.IndexOf("&", StringComparison.OrdinalIgnoreCase) == 0) { body = body.Substring(1, body.Length - 1); } string result = await RongHttpClient.ExecutePost(AppKey, AppSecret, body, RongCloud.ApiHostType.Type + "/chatroom/user/block/add.json", "application/x-www-form-urlencoded"); return(RongJsonUtil.JsonStringToObj <ResponseResult>( CommonUtil.GetResponseByCode(PATH, CheckMethod.ADD, result))); }
/** * 添加聊天室白名单成员方法 * * @param chatroom:聊天室.Id,memberIds 聊天室中白名单成员最多不超过 5 个。(必传) * * @return ResponseResult **/ public async Task <ResponseResult> Remove(ChatroomModel chatroom) { if (chatroom == null) { return(new ResponseResult(1002, "Paramer 'chatroom' is required")); } string message = CommonUtil.CheckFiled(chatroom, PATH, CheckMethod.REMOVE); if (null != message) { return(RongJsonUtil.JsonStringToObj <ResponseResult>(message)); } StringBuilder sb = new StringBuilder(); sb.Append("&chatroomId=").Append(HttpUtility.UrlEncode(chatroom.Id, UTF8)); ChatroomMember[] members = chatroom.Members; foreach (var member in members) { sb.Append("&userId=").Append(HttpUtility.UrlEncode(member.Id, UTF8)); } string body = sb.ToString(); if (body.IndexOf("&") == 0) { body = body.Substring(1, body.Length - 1); } string result = await RongHttpClient.ExecutePost(AppKey, AppSecret, body, RongCloud.ApiHostType.Type + "/chatroom/user/whitelist/remove.json", "application/x-www-form-urlencoded"); return(RongJsonUtil.JsonStringToObj <ResponseResult>(CommonUtil.GetResponseByCode(PATH, CheckMethod.REMOVE, result))); }
/** * 删除聊天室保活方法 * * @param chatroom: 聊天室信息,id(必传) * * @return ResponseResult **/ public async Task <ResponseResult> Remove(ChatroomModel chatroom) { string message = CommonUtil.CheckFiled(chatroom, PATH, CheckMethod.REMOVE); if (null != message) { return(RongJsonUtil.JsonStringToObj <ResponseResult>(message)); } StringBuilder sb = new StringBuilder(); sb.Append("&chatroomId=").Append(HttpUtility.UrlEncode(chatroom.Id, UTF8)); string body = sb.ToString(); if (body.IndexOf("&", StringComparison.OrdinalIgnoreCase) == 0) { body = body.Substring(1, body.Length - 1); } string result = await RongHttpClient.ExecutePost(AppKey, AppSecret, body, RongCloud.ApiHostType.Type + "/chatroom/keepalive/remove.json", "application/x-www-form-urlencoded"); return(RongJsonUtil.JsonStringToObj <ResponseResult>( CommonUtil.GetResponseByCode(PATH, CheckMethod.REMOVE, result))); }
static void Main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Distribute distribute = rongCloud.Chatroom.distribute; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/distribute.html#stop * * 聊天室消息停止分发 * */ ChatroomModel chatroomModel = new ChatroomModel() { Id = "d7ec7a8b8d8546c98b0973417209a548" }; ResponseResult result = distribute.Stop(chatroomModel); Console.WriteLine("stopDistributionMessage: " + result.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/distribute.html#resume * * 聊天室消息恢复分发方法(每秒钟限 100 次) */ ResponseResult resumeResult = distribute.Resume(chatroomModel); Console.WriteLine("resumeDistributionMessage: " + resumeResult.ToString()); Console.ReadLine(); }
public async Task <IActionResult> Join([FromBody] ChatroomModel chatroom) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); var result = await _databaseProvider.Join(user, chatroom.Id); return(Ok(result)); }
public async Task <IActionResult> PostAsync([FromBody] ChatroomModel model) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); var chatroom = await _databaseProvider.CreateChatroom(user.Id, model.Name); return(Ok(chatroom)); }
static async Task Main(string[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Ban ban = rongCloud.Chatroom.ban; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/ban.html#add * 添加聊天室全局禁言 * */ ChatroomMember[] members = { new ChatroomMember() { Id = "qawr34h" }, new ChatroomMember() { Id = "qawr35h" } }; ChatroomModel chatroom = new ChatroomModel() { Members = members, Minute = 5 }; ResponseResult result = await ban.Add(chatroom); Console.WriteLine("addGagUser: "******"ListGagUser: "******"removeBanUser: " + removeResult); Console.ReadLine(); }
static void main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Whitelist whitelist = rongCloud.Chatroom.whiteList; /** * API: 文档http://www.rongcloud.cn/docs/server_sdk_api/chatroom/whitelist/user.html#add * 添加聊天室用户白名单 * */ ChatroomMember[] members = { new ChatroomMember() { Id = "qawr34h" }, new ChatroomMember() { Id = "qawr35h" } }; ChatroomModel chatroom = new ChatroomModel() { Id = "d7ec7a8b8d8546c98b0973417209a548", Members = members }; ResponseResult addResult = whitelist.User.Add(chatroom); Console.WriteLine("add whitelist: " + addResult.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/whitelist/user.html#getList * 获取聊天室用户白名单 * */ WhiteListResult getResult = whitelist.User.GetList(chatroom); Console.WriteLine("get whitelist: " + getResult.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/whitelist/user.html#remove * 删除聊天室用户白名单 * */ ResponseResult removeResult = whitelist.User.Remove(chatroom); Console.WriteLine("remove whitelist: " + removeResult.ToString()); Console.ReadLine(); }
public ActionResult Chat(ChatRequestModel request) { var response = new PartialViewModel(); var user = UserService.GetUser(request.User.Id); if (user == null || user.Role == Models.User_Model.RoleLevel.Blocked) { response.Logout = true; return(Json(response)); } int chatroomId = 0; if (request.RawChatroomIdValue != null) { chatroomId = request.RawChatroomIdValue.GetHashCode(); } int parentChatroomId = chatroomId; //temporary during initial testing string chatroomName = request.ChatroomName; if (!ChatroomService.DoesChatroomExist(chatroomId)) { ChatroomService.CreateChatroom(chatroomId, chatroomName); } var joinErrors = SecurityService.CanUserJoinChatroom(request); response.Errors.AddRange(joinErrors); if (joinErrors.Count == 0) { if (!ChatroomService.AddUserToChatroom(chatroomId, parentChatroomId, request.User.Id, request.UserHandle)) { response.AddError("Error adding user into chatroom."); } } var chatroomModel = new ChatroomModel() { ChatroomId = chatroomId, ChatroomName = chatroomName, ParentChatroomId = parentChatroomId, UserHandle = request.UserHandle, UserId = request.User.Id }; //response.Data = PartialView("~/Views/Chatroom/_Chat.cshtml", chatroomModel); response.Data = RenderPartialViewToString(this.ControllerContext, "~/Views/Chatroom/_Chat.cshtml", chatroomModel); return(Json(response)); }
public async Task <ChatroomModel> CreateRoomAsync(string userId, ChatroomModel model) { var entity = _chatroomFactory.Map(model); entity.CreatedById = userId; await _dbContext.Chatrooms.AddAsync(entity); await _dbContext.SaveChangesAsync(); return(_chatroomFactory.Map(entity)); }
//Helper method for creating a chatroom since MVC uses controller contexts to route the user to the chat partial view page/ //We don't need that routing here, all we need is the logic or 99% above that line so just replicate it here and //This will create a chatroom and add the user to it //The chatrrom only exists in memory while the tests are run. Each new build refreshes public ChatResponseTestModel createChatroomAndAddUser(ChatRequestModel request) { var response = new ChatResponseTestModel(); int chatroomId = 0; if (request.RawChatroomIdValue != null) { chatroomId = request.RawChatroomIdValue.GetHashCode(); } int parentChatroomId = chatroomId; //temporary during initial testing string chatroomName = request.ChatroomName; if (!ChatroomService.DoesChatroomExist(chatroomId)) { ChatroomService.CreateChatroom(chatroomId, chatroomName); } var joinErrors = SecurityService.CanUserJoinChatroom(request); response.Errors.AddRange(joinErrors); if (joinErrors.Count == 0) { if (!ChatroomService.AddUserToChatroom(chatroomId, parentChatroomId, request.User.Id, request.UserHandle)) { response.AddError("Error adding user into chatroom."); } } var chatroomModel = new ChatroomModel() { ChatroomId = chatroomId, ChatroomName = chatroomName, ParentChatroomId = parentChatroomId, UserHandle = request.UserHandle, UserId = request.User.Id }; response.ChatroomModel = chatroomModel; return(response); }
static void Main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Keepalive keepalive = rongCloud.chatroom.keepalive; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/keepalive.html#add * * 添加保活聊天室 * **/ ChatroomModel chatroom = new ChatroomModel() { Id = "d7ec7a8b8d8546c98b0973417209a548" }; ResponseResult addResult = keepalive.Add(chatroom); Console.WriteLine("add keepalive result" + addResult.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/keepalive.html#remove * * 删除保活聊天室 * **/ ResponseResult removeResult = keepalive.Remove(chatroom); Console.WriteLine("keepalive remove" + removeResult.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/keepalive.html#getList * * 获取保活聊天室 * **/ ChatroomKeepaliveResult result = keepalive.GetList(); Console.WriteLine("keepalive getList" + result.ToString()); Console.ReadLine(); }
static void main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Gag gag = rongCloud.Chatroom.gag; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/gag.html#add * 添加禁言聊天室成员方法想(在 App 中如果不让某一用户在聊天室中发言时,可将此用户在聊天室中禁言, * 被禁言用户可以接收查看聊天室中用户聊天信息,但不能发送消息.)获取某用户的黑名单列表方法(每秒钟限 100 次) */ ChatroomMember[] members = { new ChatroomMember() { Id = "qawr34h" }, new ChatroomMember() { Id = "qawr35h" } }; ChatroomModel chatroom = new ChatroomModel() { Id = "hjhf07kk", Members = members, Minute = 5 }; ResponseResult result = gag.Add(chatroom); Console.WriteLine("addGagUser: "******"hjhf07kk" }; ListGagChatroomUserResult chatroomListGagUserResult = gag.GetList(chatroom); Console.WriteLine("ListGagUser: "******"hjhf07kk", Members = members }; ResponseResult removeResult = gag.Remove(chatroom); Console.WriteLine("rollbackGagUser: " + result.ToString()); Console.ReadLine(); }
static async Task Main(string[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Block block = rongCloud.Chatroom.block; ChatroomMember[] members = { new ChatroomMember() { Id = "qawr34h" }, new ChatroomMember() { Id = "qawr35h" } }; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/block.html#add * * 添加封禁聊天室成员方法 */ ChatroomModel chatroom = new ChatroomModel() { Id = "d7ec7a8b8d8546c98b0973417209a548", Members = members, Minute = 5 }; ResponseResult result = await block.Add(chatroom); Console.WriteLine("addBlockUser: "******"d7ec7a8b8d8546c98b0973417209a548", Members = members }; //ResponseResult removeResult = block.remove(chatroom); //Console.WriteLine("removeResult: " + removeResult.ToString()); /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/block.html#getList * * 查询被封禁聊天室成员方法 */ ListBlockChatroomUserResult getResult = await block.GetList("d7ec7a8b8d8546c98b0973417209a548"); Console.WriteLine("getListBlockUser: " + getResult); Console.ReadLine(); }
static void Main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api地址方式 //RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Chatroom chatroom = rongCloud.Chatroom; /** * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/chatroom.html#create * * 创建聊天室 * * */ ChatroomModel[] chatrooms = { new ChatroomModel() { Id = "OIBbeKlkx", Name = "chatroomName1" }, new ChatroomModel() { Id = "chatroomId2", Name = "chatroomName2" } }; ResponseResult result = chatroom.Create(chatrooms); Console.WriteLine("create: " + result.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/chatroom.html#destory * 销毁聊天室 * * */ ChatroomModel chatroomModel = new ChatroomModel() { Id = "chatroomId2" }; //ResponseResult chatroomDestroyResult = chatroom.Destroy(chatroomModel); //Console.WriteLine("destroy: " + chatroomDestroyResult.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/chatroom/chatroom.html#getMembers * 查询聊天室成员demo * * */ chatroomModel = new ChatroomModel() { Id = "OIBbeKlkx", Count = 10, Order = 1 }; ChatroomUserQueryResult chatroomQueryUserResult = chatroom.Get(chatroomModel); Console.WriteLine("queryUser: "******"e5ZnCtyfE", ChatroomId = "OIBbeKlkx" }; CheckChatRoomUserResult checkMemberResult = chatroom.IsExist(member); Console.WriteLine("checkChatroomUserResult: " + checkMemberResult.IsInChrm); Console.ReadLine(); }
public async Task <IActionResult> CreateRoom(ChatroomModel model) { var chatroom = await _chatroomsLogic.CreateRoomAsync(User.GetUserId(), model); return(CreatedAtAction(nameof(GetRoom), new { id = chatroom.Id }, chatroom)); }
public Chatroom Map(ChatroomModel chatroom) => new Chatroom { Id = chatroom.Id, Name = chatroom.Name, CreatedById = chatroom.CreatedById };