Пример #1
0
        public static async Task <dynamic> Unsubscribe(string userId, string groupId)
        {
            var cntx = Cntx;
            UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
            var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);

            if (uig != null && (!uig.SubscribedTo.HasValue || !uig.SubscribedTo.Value))
            {
                return new { ok = false, msg = ResourceUtils.GetString("735f81aa93cc3430592d2cc2a57b1cd7", "You are not a subscriber yet!") }
            }
            ;
            if (uig == null)
            {
                uig = new UserGroupMember
                {
                    UserID               = userId,
                    UserGroupID          = groupId,
                    SubscribedTo         = false,
                    ActivityNotification = false
                };
            }
            else
            {
                uig.SubscribedTo = false;
            }
            await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });

            return(new { ok = true, msg = "" });
        }
 public static async Task<string[]> UserGroupChatMembers(string userId)
 {
     var svc = new UserGroupMemberServiceProxy();
     var qexpr = new QueryExpresion();
     qexpr.FilterTks = new List<QToken>(new QToken[] {
         new QToken { TkName = "UserID == \"" + userId + "\" && UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID }
     });
     var gl = await svc.QueryDatabaseAsync(Cntx, new UserGroupMemberSet(), qexpr);
     return gl == null ? null : (from d in gl select d.UserGroupID).ToArray();
 }
Пример #3
0
        public static async Task <ChatContextVM> ListChatRooms(string uId)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var            m           = new ChatContextVM();
            var            cntx        = Cntx;
            QueryExpresion qexpr       = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "GroupName"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && ParentID is null"
                }
            });
            m.TopRooms = new List <EntityAbs <UserGroup> >();
            var roots = await gsvc.QueryDatabaseAsync(cntx, new UserGroupSet(), qexpr);

            foreach (var r in roots)
            {
                var top = await gsvc.LoadEntityFullHierarchyRecursAsync(cntx, r);

                if (top != null)
                {
                    m.TopRooms.Add(top);
                }
            }
            UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();

            qexpr          = new QueryExpresion();
            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UserID"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserID == \"" + uId + "\""
                }
            });
            var recs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);

            if (recs.Count() > 0)
            {
                m.MemberIds = (from d in recs select d.UserGroupID).ToArray();
            }
            else
            {
                m.MemberIds = new string[] { }
            };
            return(m);
        }
Пример #4
0
        public static async Task <dynamic> Subscribe(string userId, string groupId)
        {
            var cntx = Cntx;
            UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
            var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);

            if (uig != null && uig.SubscribedTo.HasValue && uig.SubscribedTo.Value)
            {
                return new { ok = false, msg = ResourceUtils.GetString("73cca337310dc88725934ac22120ffaf", "You are already a subscriber!") }
            }
            ;
            QueryExpresion qexpr = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>();
            qexpr.OrderTks.Add(new QToken {
                TkName = "UserGroupID"
            });
            qexpr.FilterTks = new List <QToken>();
            qexpr.FilterTks.Add(new QToken
            {
                TkName = "UserID == \"" + userId + "\" && SubscribedTo is not null && SubscribedTo == true"
            });
            var uigs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);

            if (uigs.Count() >= MaxSubscriptions)
            {
                return(new
                {
                    ok = false,
                    msg = ResourceUtils.GetString("06200770094b57284bc7b16e0c7ea274", "You number of subscriptions exeeds the allowed limit, please unsubscribe from some of the existing ones first.")
                });
            }
            if (uig == null)
            {
                uig = new UserGroupMember
                {
                    UserID               = userId,
                    UserGroupID          = groupId,
                    SubscribedTo         = true,
                    ActivityNotification = false
                };
            }
            else
            {
                uig.SubscribedTo = true;
            }
            await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });

            return(new { ok = true, msg = "" });
        }
Пример #5
0
        public static async Task <string[]> UserGroupChatMembers(string userId)
        {
            var svc   = new UserGroupMemberServiceProxy();
            var qexpr = new QueryExpresion();

            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UserID == \"" + userId + "\" && UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID
                }
            });
            var gl = await svc.QueryDatabaseAsync(Cntx, new UserGroupMemberSet(), qexpr);

            return(gl == null ? null : (from d in gl select d.UserGroupID).ToArray());
        }
Пример #6
0
        public static async Task <dynamic> ChangeNotification(string userId, string groupId)
        {
            var cntx = Cntx;
            UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
            var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);

            if (!uig.ActivityNotification.HasValue)
            {
                uig.ActivityNotification = true;
            }
            else
            {
                uig.ActivityNotification = !uig.ActivityNotification.Value;
            }
            await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });

            return(new { ok = true, msg = "" });
        }
Пример #7
0
        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
            });
        }
Пример #8
0
        public static async Task <ChatRoomVM> LoadChatRoom(string hubId, string groupId, string userId, int maxMessages, bool dialog = false)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var        cntx            = Cntx;
            ChatRoomVM m = new ChatRoomVM()
            {
                RoomExists = false, DialogMode = dialog
            };

            if (!string.IsNullOrEmpty(groupId))
            {
                var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);

                if (g != null)
                {
                    m.RoomExists = true;
                    m.ID         = groupId;
                    m.RoomPath   = g.DistinctString.Split('/');
                    m.RoomInfo   = await gsvc.LoadEntityGroupDescriptionAsync(cntx, g.ID);

                    UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy();
                    UserGroupMember             uig   = await gmsvc.LoadEntityByKeyAsync(cntx, groupId, userId);

                    if (uig == null)
                    {
                        uig = new UserGroupMember
                        {
                            UserID               = userId,
                            UserGroupID          = groupId,
                            SubscribedTo         = false,
                            ActivityNotification = false
                        };
                        await gmsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
                    }
                    cntx.DirectDataAccess = true;
                    MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy();
                    var           qexpr             = getConnectedGroupMemberFilter(hubId, g.ID);
                    var           peers             = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray();
                    List <string> jsonPeers         = new List <string>();
                    if (peers.Length > 0)
                    {
                        for (int i = 0; i < peers.Length; i++)
                        {
                            // retrieve the related entity graph
                            peers[i] = await cbsv.LoadEntityGraphRecursAsync(cntx, groupId, hubId, AppId, peers[i].UserID, null, null);

                            jsonPeers.Add(GetJsonPeer(peers[i]));
                        }
                    }
                    m.ActivePeers         = jsonPeers.ToArray();
                    cntx.DirectDataAccess = false;
                    ShortMessageServiceProxy msgsvc = new ShortMessageServiceProxy();
                    var cond = new ShortMessageSetConstraints
                    {
                        ApplicationIDWrap = new ForeignKeyData <string> {
                            KeyValue = AppId
                        },
                        TypeIDWrap = new ForeignKeyData <int> {
                            KeyValue = ApplicationContext.ChatShortMsgTypeId
                        },
                        GroupIDWrap = new ForeignKeyData <string> {
                            KeyValue = groupId
                        }
                    };
                    UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
                    qexpr          = new QueryExpresion();
                    qexpr.OrderTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "UserID"
                        }
                    });
                    qexpr.FilterTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "UserGroupID == \"" + g.ID + "\" && SubscribedTo is not null && SubscribedTo == true"
                        }
                    });
                    m.Subscribers = (int)(await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr));
                    var      svc = new MembershipPlusServiceProxy();
                    DateTime dt  = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow);
                    qexpr          = new QueryExpresion();
                    qexpr.OrderTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "CreatedDate"
                        },
                        new QToken {
                            TkName = "desc"
                        }
                    });
                    qexpr.FilterTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "ToID is null && CreatedDate > " + svc.FormatRepoDateTime(dt)
                        }
                    });
                    if (dialog)
                    {
                        qexpr.FilterTks.Add(new QToken {
                            TkName = " && ReplyToID is null"
                        });
                    }
                    var           msgs     = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray();
                    List <string> jsonMsgs = new List <string>();
                    if (msgs.Length > 0)
                    {
                        for (int i = msgs.Length - 1; i >= 0; i--)
                        {
                            EntitySetType[] excludes;
                            if (dialog)
                            {
                                excludes = new EntitySetType[]
                                {
                                    EntitySetType.UserGroup,
                                    //EntitySetType.ShortMessageAudience,
                                    EntitySetType.ShortMessageAttachment
                                };
                            }
                            else
                            {
                                excludes = new EntitySetType[]
                                {
                                    EntitySetType.UserGroup,
                                    //EntitySetType.ShortMessageAudience,
                                    EntitySetType.ShortMessageAttachment,
                                    EntitySetType.ShortMessage
                                };
                            }
                            msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null);

                            jsonMsgs.Add(GetJsonMessage(msgs[i], userId, g, dialog));
                        }
                    }
                    m.RecentMsgs = jsonMsgs.ToArray();
                }
            }
            return(m);
        }
 public static async Task<ChatRoomVM> LoadChatRoom(string hubId, string groupId, string userId, int maxMessages, bool dialog = false)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var cntx = Cntx;
     ChatRoomVM m = new ChatRoomVM() { RoomExists = false, DialogMode = dialog };
     if (!string.IsNullOrEmpty(groupId))
     {
         var g = await gsvc.LoadEntityByKeyAsync(cntx, groupId);
         if (g != null)
         {
             m.RoomExists = true;
             m.ID = groupId;
             m.RoomPath = g.DistinctString.Split('/');
             m.RoomInfo = await gsvc.LoadEntityGroupDescriptionAsync(cntx, g.ID);
             UserGroupMemberServiceProxy gmsvc = new UserGroupMemberServiceProxy();
             UserGroupMember uig = await gmsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
             if (uig == null)
             {
                 uig = new UserGroupMember
                 {
                     UserID = userId,
                     UserGroupID = groupId,
                     SubscribedTo = false,
                     ActivityNotification = false
                 };
                 await gmsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
             }
             cntx.DirectDataAccess = true;
             MemberCallbackServiceProxy cbsv = new MemberCallbackServiceProxy();
             var qexpr = getConnectedGroupMemberFilter(hubId, g.ID);
             var peers = (await cbsv.QueryDatabaseAsync(cntx, new MemberCallbackSet(), qexpr)).ToArray();
             List<string> jsonPeers = new List<string>();
             if (peers.Length > 0)
             {
                 for (int i = 0; i < peers.Length; i++)
                 {
                     // retrieve the related entity graph
                     peers[i] = await cbsv.LoadEntityGraphRecursAsync(cntx, groupId, hubId, AppId, peers[i].UserID, null, null);
                     jsonPeers.Add(GetJsonPeer(peers[i]));
                 }
             }
             m.ActivePeers = jsonPeers.ToArray();
             cntx.DirectDataAccess = false;
             ShortMessageServiceProxy msgsvc = new ShortMessageServiceProxy();
             var cond = new ShortMessageSetConstraints
             {
                 ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = AppId },
                 TypeIDWrap = new ForeignKeyData<int> { KeyValue = ApplicationContext.ChatShortMsgTypeId },
                 GroupIDWrap = new ForeignKeyData<string> { KeyValue = groupId }
             };
             UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserID" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserGroupID == \"" + g.ID + "\" && SubscribedTo is not null && SubscribedTo == true"  }
             });
             m.Subscribers = (int)(await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr));
             var svc = new MembershipPlusServiceProxy();
             DateTime dt = DateTime.UtcNow.AddMinutes(-InitMsgTimeWindow);
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "CreatedDate" },
                 new QToken { TkName = "desc" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] {
                 new QToken { TkName = "ToID is null && CreatedDate > " + svc.FormatRepoDateTime(dt) }
             });
             if (dialog)
             {
                 qexpr.FilterTks.Add(new QToken { TkName = " && ReplyToID is null" });
             }
             var msgs = (await msgsvc.ConstraintQueryLimitedAsync(cntx, new ShortMessageSet(), cond, qexpr, maxMessages)).ToArray();
             List<string> jsonMsgs = new List<string>();
             if (msgs.Length > 0)
             {
                 for (int i = msgs.Length - 1; i >= 0; i--)
                 {
                     EntitySetType[] excludes;
                     if (dialog)
                     {
                         excludes = new EntitySetType[]
                         {
                             EntitySetType.UserGroup,
                             //EntitySetType.ShortMessageAudience,
                             EntitySetType.ShortMessageAttachment
                         };
                     }
                     else
                     {
                         excludes = new EntitySetType[]
                         {
                             EntitySetType.UserGroup,
                             //EntitySetType.ShortMessageAudience,
                             EntitySetType.ShortMessageAttachment,
                             EntitySetType.ShortMessage
                         };
                     }
                     msgs[i] = await msgsvc.LoadEntityGraphRecursAsync(cntx, msgs[i].ID, excludes, null);
                     jsonMsgs.Add(GetJsonMessage(msgs[i], userId, g, dialog));
                 }
             }
             m.RecentMsgs = jsonMsgs.ToArray();
         }
     }
     return m;
 }
Пример #10
0
        public static async Task <bool> IsUserAMember(string groupId, string userId)
        {
            var svc = new UserGroupMemberServiceProxy();

            return((await svc.LoadEntityByKeyAsync(Cntx, groupId, userId)) != null);
        }
 public static async Task<ChatContextVM> ListChatRooms(string uId)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var m = new ChatContextVM();
     var cntx = Cntx;
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "GroupName" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && ParentID is null" }
     });
     m.TopRooms = new List<EntityAbs<UserGroup>>();
     var roots = await gsvc.QueryDatabaseAsync(cntx, new UserGroupSet(), qexpr);
     foreach (var r in roots)
     {
         var top = await gsvc.LoadEntityFullHierarchyRecursAsync(cntx, r);
         if (top != null)
             m.TopRooms.Add(top);
     }
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UserID" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UserGroupRef.GroupTypeID == " + ApplicationContext.ChatGroupTypeID + " && UserID == \"" + uId + "\""  }
     });
     var recs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);
     if (recs.Count() > 0)
         m.MemberIds = (from d in recs select d.UserGroupID).ToArray();
     else
         m.MemberIds = new string[] { };
     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<dynamic> ChangeNotification(string userId, string groupId)
 {
     var cntx = Cntx;
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
     if (!uig.ActivityNotification.HasValue)
         uig.ActivityNotification = true;
     else
         uig.ActivityNotification = !uig.ActivityNotification.Value;
     await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
     return new { ok = true, msg = "" };
 }
 public static async Task<dynamic> Unsubscribe(string userId, string groupId)
 {
     var cntx = Cntx;
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
     if (uig != null && (!uig.SubscribedTo.HasValue || !uig.SubscribedTo.Value))
         return new { ok = false, msg = ResourceUtils.GetString("735f81aa93cc3430592d2cc2a57b1cd7", "You are not a subscriber yet!") };
     if (uig == null)
     {
         uig = new UserGroupMember
         {
             UserID = userId,
             UserGroupID = groupId,
             SubscribedTo = false,
             ActivityNotification = false
         };
     }
     else
         uig.SubscribedTo = false;
     await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
     return new { ok = true, msg = "" };
 }
 public static async Task<dynamic> Subscribe(string userId, string groupId)
 {
     var cntx = Cntx;
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     var uig = await uigsvc.LoadEntityByKeyAsync(cntx, groupId, userId);
     if (uig != null && uig.SubscribedTo.HasValue && uig.SubscribedTo.Value)
         return new { ok = false, msg = ResourceUtils.GetString("73cca337310dc88725934ac22120ffaf", "You are already a subscriber!") };
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>();
     qexpr.OrderTks.Add(new QToken { TkName = "UserGroupID" });
     qexpr.FilterTks = new List<QToken>();
     qexpr.FilterTks.Add(new QToken
     {
         TkName = "UserID == \"" + userId + "\" && SubscribedTo is not null && SubscribedTo == true"
     });
     var uigs = await uigsvc.QueryDatabaseAsync(cntx, new UserGroupMemberSet(), qexpr);
     if (uigs.Count() >= MaxSubscriptions)
     {
         return new
         {
             ok = false,
             msg = ResourceUtils.GetString("06200770094b57284bc7b16e0c7ea274", "You number of subscriptions exeeds the allowed limit, please unsubscribe from some of the existing ones first.")
         };
     }
     if (uig == null)
     {
         uig = new UserGroupMember
         {
             UserID = userId,
             UserGroupID = groupId,
             SubscribedTo = true,
             ActivityNotification = false
         };
     }
     else
         uig.SubscribedTo = true;
     await uigsvc.AddOrUpdateEntitiesAsync(cntx, new UserGroupMemberSet(), new UserGroupMember[] { uig });
     return new { ok = true, msg = "" };
 }
 public static async Task<bool> IsUserAMember(string groupId, string userId)
 {
     var svc = new UserGroupMemberServiceProxy();
     return (await svc.LoadEntityByKeyAsync(Cntx, groupId, userId)) != null;
 }
Пример #17
0
        public static async Task <dynamic> LoadRoomSummary(string hubId, string id)
        {
            UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
            var    cntx  = Cntx;
            string descr = await gsvc.LoadEntityGroupDescriptionAsync(cntx, id);

            MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy();
            var  qexpr = getConnectedGroupMemberFilter(hubId, id);
            long cnt   = await mcbsvc.QueryEntityCountAsync(cntx, new MemberCallbackSet(), qexpr);

            UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();

            qexpr          = new QueryExpresion();
            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UserID"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UserGroupID == \"" + id + "\" && SubscribedTo is not null && SubscribedTo == true"
                }
            });
            long scnt = await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr);

            qexpr          = new QueryExpresion();
            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "Username"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "UsersInRole_UserID.RoleRef.UserGroupAdminRole.GroupID == \"" + id + "\""
                }
            });
            UserServiceProxy usvc = new UserServiceProxy();
            var admins            = await usvc.QueryDatabaseAsync(cntx, new UserSet(), qexpr);

            List <dynamic> ladms = new List <dynamic>();

            if (admins.Count() > 0)
            {
                RoleServiceProxy rsvc = new RoleServiceProxy();
                foreach (var u in admins)
                {
                    qexpr          = new QueryExpresion();
                    qexpr.OrderTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "ID"
                        }
                    });
                    qexpr.FilterTks = new List <QToken>(new QToken[] {
                        new QToken {
                            TkName = "UserGroupAdminRole.GroupID == \"" + id + "\" && UsersInRole.UserID == \"" + u.ID + "\""
                        }
                    });
                    var role = (await rsvc.QueryDatabaseAsync(cntx, new RoleSet(), qexpr)).First();
                    ladms.Add(new { id = u.ID, name = u.Username, role = role.DisplayName });
                }
            }
            dynamic r = new { descr = descr, active = cnt, subscribers = scnt, admins = ladms };

            return(r);
        }
 public static async Task<dynamic> LoadRoomSummary(string hubId, string id)
 {
     UserGroupServiceProxy gsvc = new UserGroupServiceProxy();
     var cntx = Cntx;
     string descr = await gsvc.LoadEntityGroupDescriptionAsync(cntx, id);
     MemberCallbackServiceProxy mcbsvc = new MemberCallbackServiceProxy();
     var qexpr = getConnectedGroupMemberFilter(hubId, id);
     long cnt = await mcbsvc.QueryEntityCountAsync(cntx, new MemberCallbackSet(), qexpr);
     UserGroupMemberServiceProxy uigsvc = new UserGroupMemberServiceProxy();
     qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UserID" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UserGroupID == \"" + id + "\" && SubscribedTo is not null && SubscribedTo == true"  }
     });
     long scnt = await uigsvc.QueryEntityCountAsync(cntx, new UserGroupMemberSet(), qexpr);
     qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "Username" }
     });
     qexpr.FilterTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "UsersInRole_UserID.RoleRef.UserGroupAdminRole.GroupID == \"" + id + "\"" }
     });
     UserServiceProxy usvc = new UserServiceProxy();
     var admins = await usvc.QueryDatabaseAsync(cntx, new UserSet(), qexpr);
     List<dynamic> ladms = new List<dynamic>();
     if (admins.Count() > 0)
     {
         RoleServiceProxy rsvc = new RoleServiceProxy();
         foreach (var u in admins)
         {
             qexpr = new QueryExpresion();
             qexpr.OrderTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "ID" }
             });
             qexpr.FilterTks = new List<QToken>(new QToken[] { 
                 new QToken { TkName = "UserGroupAdminRole.GroupID == \"" + id + "\" && UsersInRole.UserID == \"" + u.ID + "\"" }
             });
             var role = (await rsvc.QueryDatabaseAsync(cntx, new RoleSet(), qexpr)).First();
             ladms.Add(new { id = u.ID, name = u.Username, role = role.DisplayName });
         }
     }
     dynamic r = new { descr = descr, active = cnt, subscribers = scnt, admins = ladms };
     return r;
 }