public Reply PostReply(string user, string[] atUser, string msgContent, string richMessage, string[] attachmentID, DateTime timestamp, //string originMessageUser, string originMessageID) { if (_accManager.FindUser(user) == null) { throw new UserNotFoundException(user); } //merge toUser list and @somebody in the message content List <String> validToUsers = new List <String>(); HashSet <string> ToUserIDs = new HashSet <string>(); ToUserIDs.UnionWith(Utils.GetAtUserid(msgContent)); if (atUser != null) { ToUserIDs.UnionWith(atUser); } foreach (string uid in ToUserIDs) { var temp = _accManager.FindUser(uid); if (temp != null) { validToUsers.Add(temp.Userid); } } atUser = validToUsers.ToArray(); TableOperation retreiveOperation = MessageManager.RetrieveUserlineMsgByID <UserLineEntity>(originMessageID); TableResult retreiveResult = _userline.Execute(retreiveOperation); UserLineEntity originMsg = ((UserLineEntity)retreiveResult.Result); if (originMsg == null) { throw new MessageNotFoundException(); } //Insert Rich Message string richMessageID = null; if (!string.IsNullOrEmpty(richMessage)) { richMessageID = _richMsgManager.PostRichMessage(user, timestamp, richMessage); } //Reply reply = new Reply(user, atUser, msgContent, timestamp, originMessageUser, originMessageID); Reply reply = new Reply(user, originMsg.Group, msgContent, timestamp, null, originMessageID, atUser, richMessageID, attachmentID); //insert reply ReplyEntity replyEntity = new ReplyEntity(reply); TableOperation insertOperation = TableOperation.Insert(replyEntity); _reply.Execute(insertOperation); //update reply count originMsg.ReplyCount++; TableOperation updateOperation = TableOperation.Replace(originMsg); _userline.Execute(updateOperation); foreach (string userid in atUser) { if (_accManager.FindUser(userid) == null) { continue; } //notif user ReplyNotificationEntifity notifEntity = new ReplyNotificationEntifity(userid, reply); insertOperation = TableOperation.Insert(notifEntity); _replyNotification.Execute(insertOperation); _replyArchive.Execute(insertOperation); _notifManager.incrementReplyNotifCount(userid); } return(reply); }
public Message PostMessage(string userid, string groupID, string eventID, string schemaID, string[] owner, string[] atUser, string[] topicName, string message, string richMessage, string[] attachmentID, int importance, DateTime timestamp) { if ("none".Equals(message)) { message = ""; } if (message.Length > 2048) { throw new MessageTooLongException(); } UserProfile user = _accManager.FindUser(userid); if (user == null) { throw new UserNotFoundException(userid); } if (!_schemaManager.Contain(schemaID)) { throw new SchemaNotFoundException(); } //merge userid from argument as well as message HashSet <string> validAtUsers = new HashSet <string>(); HashSet <string> atUserids = new HashSet <string>(); atUserids.UnionWith(Utils.GetAtUserid(message)); if (atUser != null) { atUserids.UnionWith(atUser); } foreach (string uid in atUserids) { try { Membership member = _groupManager.CheckMembership(groupID, userid); validAtUsers.Add(member.MemberID); } catch { } } //merge topic from argument as well as message HashSet <string> topic = new HashSet <string>(); topic.UnionWith(Utils.GetTopicNames(message)); if (topicName != null) { topic.UnionWith(topicName); } //Insert Rich Message string richMessageID = null; if (!string.IsNullOrEmpty(richMessage)) { richMessageID = _richMsgManager.PostRichMessage(userid, timestamp, richMessage); } // create message Message msg = new Message(userid, groupID, message, timestamp, eventID, schemaID, owner, validAtUsers.ToArray(), topic.ToArray(), richMessageID, attachmentID, importance); //insert into Userline TableOperation insertOperation = TableOperation.InsertOrReplace(new UserLineEntity(msg)); _userline.Execute(insertOperation); //insert into poster's homeline insertOperation = TableOperation.InsertOrReplace(new HomeLineEntity(msg.User, msg)); _homeline.Execute(insertOperation); //insert into QueueMessage //QueueMessage queueMessage = new QueueMessage(QueueMessage.TypeMessage, msg.ToJsonString()); _queue.AddMessage(msg.toAzureCloudQueueMessage()); _spiderqueue.AddMessage(msg.toAzureCloudQueueMessage()); _mailMessageQueue.AddMessage(msg.toAzureCloudQueueMessage()); user.MessageCount++; _accManager.UpdateUser(user); return(msg); }