예제 #1
0
        public static void SendToGroup(Group group, string text, MessageType type, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members, Guid? authorId = null, DateTime? date = null)
        {
            if (!date.HasValue)
                date = DateTime.Now;

            var messageInfo = new MessageStruct
            {
                AuthorId = authorId,
                Text = text,
                Type = (byte)type,
                Date = date.Value
            };

            Current.SendToGroup(group, messageInfo, recipientType);
        }
예제 #2
0
        public void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType)
        {
            var recipientIdList = new List <Guid>();

            if (recipientType.HasFlag(GroupMessageRecipientType.Members))
            {
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                                             x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Approved).Select(uig => uig.UserId)
                                         .ToList());
            }

            if (recipientType.HasFlag(GroupMessageRecipientType.Moderators))
            {
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                                             x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Moderator).Select(uig => uig.UserId)
                                         .ToList());
            }

            if (recipientType.HasFlag(GroupMessageRecipientType.NotApprovedUsers))
            {
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                                             x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.NotApproved).Select(uig => uig.UserId)
                                         .ToList());
            }

            recipientIdList = recipientIdList.Distinct().ToList();

            if (recipientIdList.Count > 0)
            {
                foreach (var userId in recipientIdList)
                {
                    var message = new MessageStruct
                    {
                        AuthorId    = messageInfo.AuthorId,
                        RecipientId = userId,
                        Text        = messageInfo.Text,
                        Type        = messageInfo.Type,
                        Date        = messageInfo.Date
                    };

                    Send(message);
                }

                DataService.PerThread.SaveChanges();
            }

            UserContextService.GroupMembersAbandon(group.Id);
        }
예제 #3
0
        public static void SendToGroup(Group group, string text, MessageType type, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members, Guid?authorId = null, DateTime?date = null)
        {
            if (!date.HasValue)
            {
                date = DateTime.Now;
            }

            var messageInfo = new MessageStruct
            {
                AuthorId = authorId,
                Text     = text,
                Type     = (byte)type,
                Date     = date.Value
            };

            Current.SendToGroup(group, messageInfo, recipientType);
        }
예제 #4
0
 public static void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members)
 {
     Current.SendToGroup(group, messageInfo, recipientType);
 }
예제 #5
0
 public static void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType = GroupMessageRecipientType.Members)
 {
     Current.SendToGroup(group, messageInfo, recipientType);
 }
예제 #6
0
        public void SendToGroup(Group group, MessageStruct messageInfo, GroupMessageRecipientType recipientType)
        {
            var recipientIdList = new List<Guid>();

            if (recipientType.HasFlag(GroupMessageRecipientType.Members))
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                    x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Approved).Select(uig => uig.UserId)
                                             .ToList());

            if (recipientType.HasFlag(GroupMessageRecipientType.Moderators))
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                    x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.Moderator).Select(uig => uig.UserId)
                                             .ToList());

            if (recipientType.HasFlag(GroupMessageRecipientType.NotApprovedUsers))
                recipientIdList.AddRange(DataService.PerThread.GroupMemberSet.Where(
                    x => x.GroupId == group.Id && x.State == (byte)GroupMemberState.NotApproved).Select(uig => uig.UserId)
                                             .ToList());

            recipientIdList = recipientIdList.Distinct().ToList();

            if (recipientIdList.Count > 0)
            {
                foreach (var userId in recipientIdList)
                {
                    var message = new MessageStruct
                    {
                        AuthorId = messageInfo.AuthorId,
                        RecipientId = userId,
                        Text = messageInfo.Text,
                        Type = messageInfo.Type,
                        Date = messageInfo.Date
                    };

                    Send(message);
                }

                DataService.PerThread.SaveChanges();
            }

            UserContextService.GroupMembersAbandon(group.Id);
        }