Esempio n. 1
0
        /// <summary>
        /// 上传照片-普通上传(页面)
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadNormal(long albumId = 0, string spaceKey = null)
        {
            var    user     = UserContext.CurrentUser;
            string photoIds = Request.QueryString["photoIds"];

            if (user == null)
            {
                return(Redirect(SiteUrls.Instance().Login(true)));
            }
            if (user.UserName == spaceKey || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                //相册下拉框
                albumId = TempData.Get <long>("albumId", 0);
                GetAlbumList(albumId);
                pageResourceManager.InsertTitlePart("上传照片");
                ViewData["photoIds"] = photoIds;
                return(View());
            }
            else
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有创建或编辑照片的权限",
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 空间首页瀑布流局部页(相册首页)
        /// </summary>
        public ActionResult _HomeWaterFall(string spaceKey, int pageIndex = 1)
        {
            IUser user = userService.GetUser(spaceKey);

            if (user == null)
            {
                return(HttpNotFound());
            }

            var currentuser = UserContext.CurrentUser;

            if (currentuser == null)
            {
                return(Redirect(SiteUrls.Instance().Login(true)));
            }

            if (currentuser.UserName == spaceKey || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                PagingDataSet <Photo> photos = photoService.GetPhotosOfFollowedUsers(user.UserId, pageSize, pageIndex);
                return(View(photos));
            }
            else
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有查看首页照片的权限",
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 照片圈人通知
        /// </summary>
        /// <param name="photoLabel"></param>
        /// <param name="eventArgs"></param>
        public void PhotoLabelNotice_After(PhotoLabel photoLabel, CommonEventArgs eventArgs)
        {
            if (photoLabel.Photo == null)
            {
                return;
            }
            //圈人的操作人
            IUser user = DIContainer.Resolve <UserService>().GetUser(photoLabel.UserId);

            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                //排除掉照片主人自己
                if (photoLabel.UserId == photoLabel.Photo.UserId)
                {
                    return;
                }
                //通知照片作者
                Notice notice = Notice.New();
                notice.UserId             = photoLabel.Photo.UserId;
                notice.ApplicationId      = PhotoConfig.Instance().ApplicationId;
                notice.TypeId             = NoticeTypeIds.Instance().Hint();
                notice.LeadingActor       = user.DisplayName;
                notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().Home(user.UserName));
                notice.RelativeObjectName = photoLabel.Photo.Description;
                notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(photoLabel.Photo.PhotoId));
                notice.TemplateName       = NoticeTemplateNames.Instance().PhotoLabelNotice();
                noticeService.Create(notice);
            }
        }
Esempio n. 4
0
        public ActionResult AlbumDetailList(string spaceKey, long albumId, int pageSize = 20, int pageIndex = 1)
        {
            IUser user = userService.GetUser(spaceKey);

            if (user == null)
            {
                return(HttpNotFound());
            }

            Album album = photoService.GetAlbum(albumId);

            if (album == null)
            {
                return(HttpNotFound());
            }

            //验证是否通过审核
            long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey);

            if (!authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId) && album.UserId != currentSpaceUserId &&
                (int)album.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(PhotoConfig.Instance().ApplicationId)))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "尚未通过审核",
                    Body = "由于当前问题尚未通过审核,您无法浏览当前内容。",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }

            IUser currentUser           = UserContext.CurrentUser;
            bool  ignoreAuditAndPrivacy = false;

            if (currentUser != null && currentUser.UserId == album.UserId)
            {
                ignoreAuditAndPrivacy = true;
            }

            if (!authorizer.Album_View(album))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有查看该相册的权限",
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }

            PagingDataSet <Photo> photos = photoService.GetPhotosOfAlbum(TenantTypeIds.Instance().User(), albumId, ignoreAuditAndPrivacy, pageSize: pageSize, pageIndex: pageIndex);

            ViewData["album"] = album;

            pageResourceManager.InsertTitlePart(album.AlbumName);

            return(View(photos));
        }
        public async Task StopProposalsAsync()
        {
            var photoBot = Service.PhotoBot;

            var winnerProposal = photoBot.Config.Proposals
                                 .OrderBy(element => Guid.NewGuid())
                                 .ThenByDescending(element => element.Score)
                                 .First();

            var proposalsChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentProposalsChannelId);
            var winnersChannel   = photoBot.SocketGuild.GetTextChannel(photoBot.Config.WinnerChannelId);

            using var client = new WebClient();
            await client.DownloadFileTaskAsync(new Uri(winnerProposal.ImageUrl), "winner_proposal.png");

            try
            {
                await winnersChannel.SendFileAsync("winner_proposal.png", $"Thema: {winnerProposal.Topic}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            var users = photoBot.Config.PhotoUserIds;

            photoBot.Config.UserIdToPhotoChannelId = new Dictionary <ulong, ulong>();

            foreach (var userId in users)
            {
                var user         = photoBot.SocketGuild.GetUser(userId);
                var photoChannel = await ChannelCreator.CreateChannelAsync($"photo-{user.Username}", photoBot.Config.PhotoCategoryId);

                var denyAllPermissions = new Overwrite(photoBot.Config.EveryoneRoleId, PermissionTarget.Role,
                                                       OverwritePermissions.DenyAll(photoChannel));

                var allowUserPermissions = new Overwrite(userId, PermissionTarget.User,
                                                         OverwritePermissions.AllowAll(photoChannel));

                var permissions = new List <Overwrite> {
                    denyAllPermissions, allowUserPermissions
                };

                await photoChannel.ModifyAsync(prop => prop.PermissionOverwrites = permissions);

                photoBot.Config.UserIdToPhotoChannelId.Add(userId, photoChannel.Id);
            }

            await Archiver.ArchiveChannelAsync(proposalsChannel);

            await PhotoConfig.SaveAsync();
        }
        public async Task StartBattleAsync()
        {
            var photoBot = Service.PhotoBot;

            await ReplyAsync("Starting new photoshop battle.");

            var proposalsChannel = await ChannelCreator.CreateChannelAsync("proposals", photoBot.Config.PhotoCategoryId);

            if (photoBot.Config.CurrentProposalsChannelId != 0)
            {
                var oldProposalsChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentProposalsChannelId);
                await Archiver.ArchiveChannelAsync(oldProposalsChannel);
            }

            if (photoBot.Config.CurrentVotingChannelId != 0)
            {
                var oldVotingChannel = photoBot.SocketGuild.GetTextChannel(photoBot.Config.CurrentVotingChannelId);
                await Archiver.ArchiveChannelAsync(oldVotingChannel);
            }

            if (photoBot.Config.UserIdToPhotoChannelId != null)
            {
                foreach (var(_, value) in photoBot.Config.UserIdToPhotoChannelId)
                {
                    if (value == 0)
                    {
                        continue;
                    }
                    var channel = photoBot.SocketGuild.GetTextChannel(value);
                    if (channel != null)
                    {
                        await channel.DeleteAsync();
                    }
                }
            }

            photoBot.Config.CurrentProposalsChannelId = proposalsChannel.Id;

            await photoBot.GetPhotoUsersAsync();

            photoBot.Config.Proposals = new List <PhotoMessage>();
            photoBot.Config.Photos    = new List <PhotoMessage>();
            photoBot.Config.UserIdToPhotoChannelId = new Dictionary <ulong, ulong>();

            await PhotoConfig.SaveAsync();
        }
Esempio n. 7
0
        public ActionResult _SetEssential(long photoId, bool isEssential = true)
        {
            Photo photo = photoService.GetPhoto(photoId);

            if (photo == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "没有找到照片")));
            }

            if (!authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId))
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您可能没有权限给此照片加精")));
            }

            photoService.SetEssential(photo, isEssential);
            return(Json(new StatusMessageData(StatusMessageType.Success, isEssential ? "加精成功" : "取消精华成功")));
        }
Esempio n. 8
0
        /// <summary>
        /// 动态处理程序
        /// </summary>
        private void PhotoActivityModule_After(Album album, AuditEventArgs eventArgs)
        {
            //生成动态
            ActivityService activityService = new ActivityService();
            AuditService    auditService    = new AuditService();

            bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);

            if (auditDirection == true)
            {
                //如果是新上传了照片,则更新最后修改时间
                if (activityService.UpdateLastModified(TenantTypeIds.Instance().Album(), album.AlbumId))
                {
                    return;
                }
                //初始化Owner为用户的动态
                Activity activity = Activity.New();
                activity.ActivityItemKey       = ActivityItemKeys.Instance().CreatePhoto();
                activity.ApplicationId         = PhotoConfig.Instance().ApplicationId;
                activity.HasImage              = true;
                activity.HasMusic              = false;
                activity.HasVideo              = false;
                activity.IsOriginalThread      = true;
                activity.IsPrivate             = album.PrivacyStatus == PrivacyStatus.Private ? true : false;
                activity.UserId                = album.UserId;
                activity.ReferenceId           = 0;
                activity.ReferenceTenantTypeId = string.Empty;
                activity.SourceId              = album.AlbumId;
                activity.TenantTypeId          = TenantTypeIds.Instance().Album();
                activity.OwnerId               = album.UserId;
                activity.OwnerName             = album.Author;
                activity.OwnerType             = ActivityOwnerTypes.Instance().User();
                //是否是公开的(用于是否推送站点动态)
                bool isPublic = album.PrivacyStatus == PrivacyStatus.Public ? true : false;

                activityService.Generate(activity, true, isPublic);
            }
            else if (auditDirection == false) //删除动态
            {
                activityService.DeleteSource(TenantTypeIds.Instance().Album(), album.AlbumId);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 评论动态处理
        /// </summary>
        /// <param name="comment"></param>
        /// <param name="eventArgs"></param>
        private void CommentActivityEventModule_After(Comment comment, AuditEventArgs eventArgs)
        {
            bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus);
            Photo photo          = null;

            if (comment.TenantTypeId == TenantTypeIds.Instance().Photo() && comment.UserId != comment.ToUserId)
            {
                if (auditDirection == true)
                {
                    photo = photoService.GetPhoto(comment.CommentedObjectId);
                    Activity activityOfFollower = Activity.New();
                    activityOfFollower.ActivityItemKey       = ActivityItemKeys.Instance().CommentPhoto();
                    activityOfFollower.ApplicationId         = PhotoConfig.Instance().ApplicationId;
                    activityOfFollower.HasImage              = false;
                    activityOfFollower.HasMusic              = false;
                    activityOfFollower.HasVideo              = false;
                    activityOfFollower.IsOriginalThread      = true;
                    activityOfFollower.IsPrivate             = photo.PrivacyStatus == PrivacyStatus.Private ? true : false;
                    activityOfFollower.UserId                = comment.UserId;
                    activityOfFollower.ReferenceId           = photo.PhotoId;
                    activityOfFollower.ReferenceTenantTypeId = TenantTypeIds.Instance().Photo();
                    activityOfFollower.SourceId              = comment.Id;
                    activityOfFollower.TenantTypeId          = TenantTypeIds.Instance().Comment();
                    activityOfFollower.OwnerId               = comment.UserId;
                    activityOfFollower.OwnerName             = comment.Author;
                    activityOfFollower.OwnerType             = ActivityOwnerTypes.Instance().User();

                    //是否是公开的(用于是否推送站点动态)
                    bool isPublic = photo.PrivacyStatus == PrivacyStatus.Public ? true : false;

                    activityService.Generate(activityOfFollower, true, isPublic);
                }
                else
                {
                    activityService.DeleteSource(TenantTypeIds.Instance().Comment(), comment.Id);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 照片操作日志事件处理
        /// </summary>
        private void PhotoOperationLogEventModule_After(Photo senders, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() ||
                eventArgs.EventOperationType == EventOperationType.Instance().Approved() ||
                eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() ||
                eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() ||
                eventArgs.EventOperationType == EventOperationType.Instance().SetSticky() ||
                eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential() ||
                eventArgs.EventOperationType == EventOperationType.Instance().CancelSticky())
            {
                OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo);

                entry.ApplicationId       = entry.ApplicationId;
                entry.Source              = PhotoConfig.Instance().ApplicationName;
                entry.OperationType       = eventArgs.EventOperationType;
                entry.OperationObjectName = string.IsNullOrEmpty(senders.Description) ? "照片" : senders.Description;
                entry.OperationObjectId   = senders.PhotoId;
                entry.Description         = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "照片", entry.OperationObjectName);

                OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>();
                logService.Create(entry);
            }
        }
        public async Task StartVotingAsync()
        {
            var photoBot           = Service.PhotoBot;
            var photoVotingChannel = await ChannelCreator.CreateChannelAsync("photo-voting", photoBot.Config.PhotoCategoryId);

            photoBot.Config.CurrentVotingChannelId = photoVotingChannel.Id;

            photoBot.Config.Photos = photoBot.Config.Photos.OrderBy(element => Guid.NewGuid()).ToList();
            foreach (var photo in photoBot.Config.Photos)
            {
                using var webClient = new WebClient();
                await webClient.DownloadFileTaskAsync(photo.ImageUrl, "photo.png");

                var photoMessage = await photoVotingChannel.SendFileAsync("photo.png", "");

                await photoMessage.AddReactionAsync(new Emoji("✅"));

                await photoMessage.AddReactionAsync(new Emoji("❌"));

                photo.MessageId = photoMessage.Id;
            }

            foreach (var(_, value) in photoBot.Config.UserIdToPhotoChannelId)
            {
                if (value == 0)
                {
                    continue;
                }
                var channel = photoBot.SocketGuild.GetTextChannel(value);
                if (channel != null)
                {
                    await channel.DeleteAsync();
                }
            }

            await PhotoConfig.SaveAsync();
        }
Esempio n. 12
0
        /// <summary>
        /// 圈人动态处理
        /// </summary>
        private void LabelPhotoActivityModule_After(PhotoLabel photoLabel, CommonEventArgs eventArgs)
        {
            Photo photo = photoService.GetPhoto(photoLabel.PhotoId);

            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                //初始化Owner为用户的动态
                Activity activity = Activity.New();
                activity.ActivityItemKey       = ActivityItemKeys.Instance().LabelPhoto();
                activity.ApplicationId         = PhotoConfig.Instance().ApplicationId;
                activity.HasImage              = true;
                activity.HasMusic              = false;
                activity.HasVideo              = false;
                activity.IsOriginalThread      = true;
                activity.IsPrivate             = photoLabel.Photo.PrivacyStatus == PrivacyStatus.Private ? true : false;
                activity.UserId                = photo.UserId;
                activity.ReferenceId           = photoLabel.PhotoId;
                activity.ReferenceTenantTypeId = TenantTypeIds.Instance().Photo();
                activity.SourceId              = photoLabel.LabelId;
                activity.TenantTypeId          = TenantTypeIds.Instance().PhotoLabel();
                activity.OwnerId               = photo.UserId;
                activity.OwnerName             = photo.Author;
                activity.OwnerType             = ActivityOwnerTypes.Instance().User();

                //是否是公开的(用于是否推送站点动态)
                bool isPublic = photoLabel.Photo.PrivacyStatus == PrivacyStatus.Public ? true : false;

                activityService.Generate(activity, true, isPublic);

                //再为被圈用户生成动态
                new ActivityRepository().InsertUserInboxs(activity.ActivityId, new long[] { photoLabel.ObjetId });
            }
            else
            {
                activityService.DeleteSource(TenantTypeIds.Instance().PhotoLabel(), photoLabel.LabelId);
            }
        }