public static async Task <string> LoadMessageDetails(string noteHubId, string userId, string msgId) { var cntx = Cntx; var gsvc = new UserGroupServiceProxy(); var svc = new ShortMessageServiceProxy(); var rmsg = await svc.LoadEntityByKeyAsync(cntx, msgId); var msg0 = rmsg; while (rmsg.ReplyToID != null) { rmsg = await svc.LoadEntityByKeyAsync(cntx, rmsg.ReplyToID); } EntitySetType[] excludes = new EntitySetType[] { EntitySetType.UserGroup, EntitySetType.ShortMessageAudience }; EntitySetRelation[] drills = new EntitySetRelation[] { new EntitySetRelation { SetType = EntitySetType.User, RelatedSets = new EntitySetType[] { EntitySetType.UserAppMember, } } }; var msg = await svc.LoadEntityGraphRecursAsync(cntx, rmsg.ID, excludes, drills); var msgstr = GetJsonMessage(msg, userId, true, msgId); if (msg0.IsNotReceived == false) { msg0.IsNotReceived = false; await svc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg0 }); } return(msgstr); }
public static async Task <PeerShotMessage> AddUserMessage(string chatHubId, string userId, string peerId, string replyId, string message, bool record) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); var now = DateTime.UtcNow; ShortMessage msg = new ShortMessage { ID = Guid.NewGuid().ToString(), ApplicationID = AppId, TypeID = 1, GroupID = null, FromID = userId, ToID = peerId, ReplyToID = string.IsNullOrEmpty(replyId) ? null : replyId, CreatedDate = now, LastModified = now, MsgText = message }; if (record) { var r = await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); var _msg = r.ChangedEntities[0].UpdatedItem; _msg.User_FromID = u; m.msg = GetJsonMessage(_msg, userId, peer, false); } else { msg.User_FromID = u; m.msg = GetJsonMessage(msg, userId, peer, false); } UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); var utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop != null) { utop.InteractCount = utop.InteractCount == null ? 1 : utop.InteractCount + 1; utop.LastInteract = DateTime.UtcNow; await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop }); } MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); m.peer = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault(); return(m); }
public static async Task<string> LoadMessageDetails(string noteHubId, string userId, string msgId) { var cntx = Cntx; var gsvc = new UserGroupServiceProxy(); var svc = new ShortMessageServiceProxy(); var rmsg = await svc.LoadEntityByKeyAsync(cntx, msgId); var msg0 = rmsg; while (rmsg.ReplyToID != null) rmsg = await svc.LoadEntityByKeyAsync(cntx, rmsg.ReplyToID); EntitySetType[] excludes = new EntitySetType[] { EntitySetType.UserGroup, EntitySetType.ShortMessageAudience }; EntitySetRelation[] drills = new EntitySetRelation[] { new EntitySetRelation { SetType = EntitySetType.User, RelatedSets = new EntitySetType[] { EntitySetType.UserAppMember, } } }; var msg = await svc.LoadEntityGraphRecursAsync(cntx, rmsg.ID, excludes, drills); var msgstr = GetJsonMessage(msg, userId, true, msgId); if (msg0.IsNotReceived == false) { msg0.IsNotReceived = false; await svc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg0 }); } return msgstr; }
public static async Task LeaveUserMessage(string chatHubId, string userId, string peerId, string replyId, string message) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); var now = DateTime.UtcNow; ShortMessage msg = new ShortMessage { ID = Guid.NewGuid().ToString(), ApplicationID = AppId, TypeID = ApplicationContext.ChatShortMsgTypeId, GroupID = null, FromID = userId, ToID = peerId, ReplyToID = string.IsNullOrEmpty(replyId) ? null : replyId, CreatedDate = now, LastModified = now, MsgText = message, IsNotReceived = true }; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); DateTime dt = DateTime.UtcNow; List <UserAssociation> lass = new List <UserAssociation>(); UserAssociation utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop == null) { utop = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = userId, ToUserID = peerId, CreateDate = dt, AssocCount = 0, LastAssoc = dt, InteractCount = 1, Votes = 0 }; } else { utop.InteractCount++; } lass.Add(utop); if (!string.IsNullOrEmpty(replyId)) { UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId); if (ptou == null) { ptou = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = peerId, ToUserID = userId, CreateDate = dt, AssocCount = 0, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else { ptou.InteractCount++; } lass.Add(ptou); } await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), lass.ToArray()); }
public static async Task LeaveUserMessage(string chatHubId, string userId, string peerId, string replyId, string message) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); var now = DateTime.UtcNow; ShortMessage msg = new ShortMessage { ID = Guid.NewGuid().ToString(), ApplicationID = AppId, TypeID = 1, GroupID = null, FromID = userId, ToID = peerId, ReplyToID = string.IsNullOrEmpty(replyId) ? null : replyId, CreatedDate = now, LastModified = now, MsgText = message, IsNotReceived = true }; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); DateTime dt = DateTime.UtcNow; List<UserAssociation> lass = new List<UserAssociation>(); UserAssociation utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop == null) { utop = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = userId, ToUserID = peerId, CreateDate = dt, AssocCount = 0, LastAssoc = dt, InteractCount = 1, Votes = 0 }; } else utop.InteractCount++; lass.Add(utop); if (!string.IsNullOrEmpty(replyId)) { UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId); if (ptou == null) { ptou = new UserAssociation { TypeID = ApplicationContext.ChatAssocTypeId, FromUserID = peerId, ToUserID = userId, CreateDate = dt, AssocCount = 0, LastAssoc = dt, InteractCount = 0, Votes = 0 }; } else ptou.InteractCount++; lass.Add(ptou); } await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), lass.ToArray()); }
public static async Task<PeerShotMessage> UpdateUserMessage(string chatHubId, string userId, string peerId, string msgId, string message) { var cntx = Cntx; UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); PeerShotMessage m = new PeerShotMessage(); ShortMessage msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId || msg.ToID != peerId) return null; var now = DateTime.UtcNow; msg.MsgText = message; msg.LastModified = now; var r = await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); var _msg = r.ChangedEntities[0].UpdatedItem; _msg.User_FromID = u; m.msg = GetJsonMessage(_msg, userId, peer, false); UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy(); var utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId); if (utop != null) { utop.InteractCount = utop.InteractCount == null ? 1 : utop.InteractCount + 1; utop.LastInteract = DateTime.UtcNow; await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop }); } MembershipPlusServiceProxy svc = new MembershipPlusServiceProxy(); DateTime dt = DateTime.UtcNow.AddMinutes(-ApplicationContext.OnlineUserInactiveTime); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" }, new QToken { TkName = "asc" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "HubID == \"" + chatHubId + "\" && ChannelID == \"" + userId + "\" && ConnectionID is not null && IsDisconnected == false" }, new QToken { TkName = "&&" }, new QToken { TkName = "ApplicationID == \"" + AppId + "\" && UserID == \"" + peerId + "\"" }, new QToken { TkName = "&&" }, new QToken { TkName = "UserAppMemberRef.LastActivityDate > " + svc.FormatRepoDateTime(dt) } }); MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy(); m.peer = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).SingleOrDefault(); return m; }
public static async Task <ShotMessageNotice> UpdateUserMessage(string noticeHubId, string chatHubId, string userId, string groupId, string msgId, string message) { var cntx = Cntx; UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); var msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId) { return(null); } if (msg.MsgText == message) { return(null); } var now = DateTime.UtcNow; msg.MsgTitle = GetLeadText(message); msg.MsgText = message; msg.LastModified = now; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); msg.User_FromID = u; UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); var cond = new UserGroupMemberSetConstraints { UserGroupIDWrap = new ForeignKeyData <string> { KeyValue = groupId } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List <QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List <QToken>(new QToken[] { new QToken { TkName = "SubscribedTo is not null && SubscribedTo == true" } }); var gmbs = await gmsvc.ConstraintQueryAsync(cntx, new UserGroupMemberSet(), cond, qexpr); List <MemberNotification> notices = new List <MemberNotification>(); List <MemberCallback> noteCbks = new List <MemberCallback>(); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); string noticeMsg = "Group message by " + u.Username + " updated in " + g.DistinctString; MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.NewMessageNoticeTypeId); foreach (var m in gmbs) { if (m.ActivityNotification.HasValue && m.ActivityNotification.Value) { var cb = await mcbsvc.LoadEntityByKeyAsync(cntx, groupId, noticeHubId, AppId, m.UserID); if (cb.ConnectionID != null && !cb.IsDisconnected) { cb.UserAppMemberRef = await mcbsvc.MaterializeUserAppMemberRefAsync(cntx, cb); noteCbks.Add(cb); } } notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = noticeMsg, CreatedDate = now, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.NewMessageNoticeTypeId, UserID = userId }); } var peers = await ListConnectIds(chatHubId, groupId); List <ShortMessageAudience> laud = new List <ShortMessageAudience>(); foreach (var peer in peers) { if (peer.UserID != userId) { var a = new ShortMessageAudience { MsgID = msg.ID, UserID = peer.UserID, VoteCount = 0 }; laud.Add(a); } } if (laud.Count > 0) { ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), laud.ToArray()); } if (notices.Count > 0) { MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), notices.ToArray()); } return(new ShotMessageNotice { msg = GetJsonMessage(msg, userId, g, false), brief = noticeMsg, categ = ntype, peers = peers, callbacks = noteCbks }); }
public static async Task<ShotMessageNotice> UpdateUserMessage(string noticeHubId, string chatHubId, string userId, string groupId, string msgId, string message) { var cntx = Cntx; UserGroupServiceProxy gsvc = new UserGroupServiceProxy(); var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId); ShortMessageServiceProxy msvc = new ShortMessageServiceProxy(); var msg = await msvc.LoadEntityByKeyAsync(cntx, msgId); if (msg == null || msg.FromID != userId) return null; if (msg.MsgText == message) return null; var now = DateTime.UtcNow; msg.MsgTitle = GetLeadText(message); msg.MsgText = message; msg.LastModified = now; await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg }); UserServiceProxy usvc = new UserServiceProxy(); var u = await usvc.LoadEntityByKeyAsync(cntx, userId); msg.User_FromID = u; UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy(); var cond = new UserGroupMemberSetConstraints { UserGroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId } }; var qexpr = new QueryExpresion(); qexpr.OrderTks = new List<QToken>(new QToken[] { new QToken { TkName = "UserID" } }); qexpr.FilterTks = new List<QToken>(new QToken[] { new QToken { TkName = "SubscribedTo is not null && SubscribedTo == true" } }); var gmbs = await gmsvc.ConstraintQueryAsync(cntx, new UserGroupMemberSet(), cond, qexpr); List<MemberNotification> notices = new List<MemberNotification>(); List<MemberCallback> noteCbks = new List<MemberCallback>(); MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy(); string noticeMsg = "Group message by " + u.Username + " updated in " + g.DistinctString; MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy(); var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.NewMessageNoticeTypeId); foreach (var m in gmbs) { if (m.ActivityNotification.HasValue && m.ActivityNotification.Value) { var cb = await mcbsvc.LoadEntityByKeyAsync(cntx, groupId, noticeHubId, AppId, m.UserID); if (cb.ConnectionID != null && !cb.IsDisconnected) { cb.UserAppMemberRef = await mcbsvc.MaterializeUserAppMemberRefAsync(cntx, cb); noteCbks.Add(cb); } } notices.Add(new MemberNotification { ID = Guid.NewGuid().ToString(), Title = noticeMsg, CreatedDate = now, PriorityLevel = 0, ReadCount = 0, ApplicationID = AppId, TypeID = ApplicationContext.NewMessageNoticeTypeId, UserID = userId }); } var peers = await ListConnectIds(chatHubId, groupId); List<ShortMessageAudience> laud = new List<ShortMessageAudience>(); foreach (var peer in peers) { if (peer.UserID != userId) { var a = new ShortMessageAudience { MsgID = msg.ID, UserID = peer.UserID, VoteCount = 0 }; laud.Add(a); } } if (laud.Count > 0) { ShortMessageAudienceServiceProxy audsvc = new ShortMessageAudienceServiceProxy(); await audsvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageAudienceSet(), laud.ToArray()); } if (notices.Count > 0) { MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy(); await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), notices.ToArray()); } return new ShotMessageNotice { msg = GetJsonMessage(msg, userId, g, false), brief = noticeMsg, categ = ntype, peers = peers, callbacks = noteCbks }; }