Ejemplo n.º 1
0
        private static GroupViewModel Map(
            ChatGroup group,
            IEnumerable <ChatGroupParticipant> chatParticipants,
            Contact contact)
        {
            var isTemporaryRoom = group.Type == GroupType.Temporary;
            var isInitiator     = group.InitiatorContactId == contact.Id;

            return(new GroupViewModel
            {
                Id = group.Id,
                Title = group.FormatGroupTitle(chatParticipants, contact.Id),
                AvatarImageId = group.FormatGroupAvatar(chatParticipants, contact.Id),
                Participants = chatParticipants
                               .Where(x => group.Type == GroupType.Regular || x.ContactId == contact.Id)
                               .Select(x => x.Map())
                               .ToList(),
                IsOneToOne = group.IsOneToOne,
                Type = group.Type,
                AccessRight = isTemporaryRoom ?
                              new AccessRights(!isInitiator, isInitiator, isInitiator, isInitiator, isInitiator, isInitiator) :
                              new AccessRights(!isInitiator && !group.IsOneToOne, isInitiator || group.IsOneToOne),
                InitiatorContactId = group.InitiatorContactId,
                LastUpdatedDate = group.UpdatedOn
            });
        }