public Message GetMessage(string msgID) { TableOperation retreiveOperation = RetrieveUserlineMsgByID <UserLineEntity>(msgID); TableResult retreiveResult = _userline.ExecuteRetriveOperation(retreiveOperation); UserLineEntity entity = ((UserLineEntity)retreiveResult.Result); if (entity == null) { return(null); } //var msg = JsonConvert.DeserializeObject<Message>(entity.Content); return(entity.ToMessage()); }
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); }