protected void set_messages_as_seen(Guid?threadId, ref string responseText) { //Privacy Check: OK if (!paramsContainer.GBEdit) { return; } if (!threadId.HasValue || !MSGController.has_message(paramsContainer.Tenant.Id, null, paramsContainer.CurrentUserID.Value, threadId, null)) { responseText = "{\"ErrorText\":\"" + Messages.AccessDenied + "\"}"; return; } int msgCount = 0, sentCount = 0, notSeenCount = 0; bool result = MSGController.set_messages_as_seen(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value, threadId.Value); if (result) { MSGController.get_thread_info(paramsContainer.Tenant.Id, threadId.Value, paramsContainer.CurrentUserID.Value, ref msgCount, ref sentCount, ref notSeenCount); } responseText = !result ? "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}" : "{\"Succeed\":\"" + Messages.OperationCompletedSuccessfully + "\"" + ",\"ThreadInfo\":" + _get_thread_info_json(msgCount, sentCount, notSeenCount) + "}"; }
protected void send_message(Guid?forwardedFrom, string title, string messageText, bool?isGroup, List <Guid> receiverUserIds, Guid?threadId, List <DocFileInfo> attachedFiles, Guid?groupId, string _ref, ref string responseText) { //GroupID will not be stored in the database and is just used for chat //Privacy Check: OK if (!paramsContainer.GBEdit) { return; } if (!string.IsNullOrEmpty(title) && title.Length > 490) { responseText = "{\"ErrorText\":\"" + Messages.MaxAllowedInputLengthExceeded + "\"}"; return; } else if (!PublicMethods.is_secure_title(title)) { responseText = "{\"ErrorText\":\"" + Messages.TheTextIsFormattedBadly + "\"}"; return; } if (!isGroup.HasValue) { isGroup = false; } Guid messageId = Guid.NewGuid(); isGroup = receiverUserIds.Count == 1 ? false : isGroup; bool selfChat = !isGroup.Value && ( (receiverUserIds.Count == 1 && receiverUserIds.First() == paramsContainer.CurrentUserID.Value) || (threadId == paramsContainer.CurrentUserID) ); if (!threadId.HasValue && ((isGroup.Value && receiverUserIds.Count > 1) || (!isGroup.Value && receiverUserIds.Count == 1))) { threadId = isGroup.Value ? Guid.NewGuid() : (receiverUserIds.Count == 1 ? receiverUserIds.First() : threadId); } if (attachedFiles != null) { attachedFiles.ForEach(f => f.move(paramsContainer.Tenant.Id, FolderNames.TemporaryFiles, FolderNames.Attachments)); } long result = MSGController.send_message(paramsContainer.Tenant.Id, messageId, forwardedFrom, paramsContainer.CurrentUserID.Value, title, messageText, isGroup.Value, receiverUserIds, threadId, attachedFiles); if (result <= 0 && attachedFiles != null) { attachedFiles.ForEach(f => f.move(paramsContainer.Tenant.Id, FolderNames.Attachments, FolderNames.TemporaryFiles)); } List <User> receiverUsers; User senderUser = UsersController.get_user(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value); responseText = result <= 0 ? "{\"ErrorText\":\"" + Messages.OperationFailed + "\"}" : "{\"Succeed\":\"" + Messages.OperationCompletedSuccessfully + "\""; bool sendForMany = !isGroup.Value && receiverUserIds.Count > 1; if (result > 0 && !sendForMany) { int msgCount = 0, sentCount = 0, notSeenCount = 0; MSGController.get_thread_info(paramsContainer.Tenant.Id, paramsContainer.CurrentUserID.Value, threadId.Value, ref msgCount, ref sentCount, ref notSeenCount); receiverUsers = UsersController.get_users(paramsContainer.Tenant.Id, receiverUserIds); responseText += ",\"Thread\":{" + "\"ThreadID\":\"" + threadId.ToString() + "\"" + ",\"IsGroup\":" + isGroup.ToString().ToLower() + ",\"UsersCount\":" + receiverUserIds.Count.ToString().ToLower() + ",\"MessagesCount\":" + msgCount.ToString() + ",\"SentCount\":" + sentCount.ToString() + ",\"NotSeenCount\":" + notSeenCount.ToString() + ",\"Users\":[" + ProviderUtil.list_to_string <string>(receiverUsers.Select( u => "{\"UserID\":\"" + u.UserID.ToString() + "\"" + ",\"UserName\":\"" + Base64.encode(u.UserName) + "\"" + ",\"FirstName\":\"" + Base64.encode(u.FirstName) + "\"" + ",\"LastName\":\"" + Base64.encode(u.LastName) + "\"" + ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address( paramsContainer.Tenant.Id, u.UserID.Value) + "\"" + "}").ToList()) + "]" + "}"; if (threadId == senderUser.UserID || (receiverUserIds != null && receiverUserIds.Contains(senderUser.UserID.Value))) { responseText += ",\"SenderIsReceiver\":" + true.ToString().ToLower(); } for (int i = 0; i < attachedFiles.Count; ++i) { attachedFiles[i].OwnerID = messageId; } responseText += ",\"Message\":{" + "\"ID\":" + result.ToString() + ",\"ReceiverID\":" + (result + 1).ToString() + ",\"MessageID\":\"" + messageId.ToString() + "\"" + ",\"ThreadID\":\"" + threadId.Value.ToString() + "\"" + ",\"ForwardedFrom\":\"" + (!forwardedFrom.HasValue ? "" : forwardedFrom.ToString()) + "\"" + ",\"IsGroup\":" + isGroup.ToString().ToLower() + ",\"GroupID\":\"" + (groupId.HasValue && groupId.HasValue ? groupId.Value : Guid.NewGuid()).ToString() + "\"" + ",\"SelfChat\":" + selfChat.ToString().ToLower() + ",\"IsSender\":" + true.ToString().ToLower() + ",\"Seen\":" + true.ToString().ToLower() + ",\"Title\":\"" + string.Empty + "\"" + ",\"MessageText\":\"" + Base64.encode(messageText) + "\"" + ",\"SendDate\":\"" + PublicMethods.get_local_date(DateTime.Now, true) + "\"" + ",\"SenderUserID\":\"" + senderUser.UserID.ToString() + "\"" + ",\"SenderUserName\":\"" + Base64.encode(senderUser.UserName) + "\"" + ",\"SenderFirstName\":\"" + Base64.encode(senderUser.FirstName) + "\"" + ",\"SenderLastName\":\"" + Base64.encode(senderUser.LastName) + "\"" + ",\"ProfileImageURL\":\"" + DocumentUtilities.get_personal_image_address( paramsContainer.Tenant.Id, senderUser.UserID.Value) + "\"" + ",\"AttachedFiles\":" + DocumentUtilities.get_files_json(paramsContainer.Tenant.Id, attachedFiles, true) + ",\"Ref\":\"" + (string.IsNullOrEmpty(_ref) ? string.Empty : _ref) + "\"" + "}"; } responseText += "}"; //Send RealTime Data if (result > 0 && RaaiVanSettings.RealTime(paramsContainer.Tenant.Id) && !sendForMany) { List <Guid> userIds = new List <Guid>(); if (!isGroup.Value) { userIds = new List <Guid>() { threadId.Value, senderUser.UserID.Value } } ; else { userIds = receiverUserIds.Count > 0 ? receiverUserIds : MSGController.get_thread_users(paramsContainer.Tenant.Id, threadId.Value, paramsContainer.CurrentUserID.Value, 1000, null).Select(u => u.UserID.Value).ToList(); if (receiverUserIds.Count > 0) { userIds.Add(senderUser.UserID.Value); } } if (userIds.Count > 0) { RaaiVanHub.SendData(paramsContainer.Tenant.Id, userIds, RaaiVanHub.RealTimeAction.NewMessage, responseText); } } //end of Send RealTime Data }