Exemplo n.º 1
0
        /// <summary>
        /// Create a topic
        /// </summary>
        /// <param name="processType">Process type</param>
        /// <param name="topicHandle">Topic handle</param>
        /// <param name="title">Topic title</param>
        /// <param name="text">Topic text</param>
        /// <param name="blobType">Blob type</param>
        /// <param name="blobHandle">Blob handle</param>
        /// <param name="categories">Topic categories</param>
        /// <param name="language">Topic language</param>
        /// <param name="group">Topic group</param>
        /// <param name="deepLink">Topic deep link</param>
        /// <param name="friendlyName">Topic friendly name</param>
        /// <param name="publisherType">Publisher type</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="userVisibility">User visibility</param>
        /// <param name="createdTime">Created time</param>
        /// <param name="reviewStatus">Review status</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="requestId">Request id associated with the create topic request</param>
        /// <returns>Create topic task</returns>
        public async Task CreateTopic(
            ProcessType processType,
            string topicHandle,
            string title,
            string text,
            BlobType blobType,
            string blobHandle,
            string categories,
            string language,
            string group,
            string deepLink,
            string friendlyName,
            PublisherType publisherType,
            string userHandle,
            UserVisibilityStatus userVisibility,
            DateTime createdTime,
            ReviewStatus reviewStatus,
            string appHandle,
            string requestId)
        {
            await this.topicsStore.InsertTopic(
                StorageConsistencyMode.Strong,
                topicHandle,
                title,
                text,
                blobType,
                blobHandle,
                categories,
                language,
                group,
                deepLink,
                friendlyName,
                publisherType,
                userHandle,
                createdTime,
                reviewStatus,
                appHandle,
                requestId);

            if (publisherType == PublisherType.User)
            {
                await this.topicsStore.InsertUserTopic(StorageConsistencyMode.Strong, userHandle, appHandle, topicHandle);

                await this.topicsStore.InsertFollowingTopic(StorageConsistencyMode.Strong, userHandle, appHandle, topicHandle, userHandle);

                await this.popularTopicsManager.UpdatePopularUserTopic(processType, userHandle, appHandle, topicHandle, 0);
            }

            // TODO: should we add a popular app topic feed
            await this.topicsStore.InsertRecentTopic(StorageConsistencyMode.Strong, appHandle, topicHandle, userHandle);

            await this.popularTopicsManager.UpdatePopularTopic(processType, appHandle, topicHandle, userHandle, createdTime, 0);

            await this.searchQueue.SendSearchIndexTopicMessage(topicHandle, createdTime);

            if (publisherType == PublisherType.User)
            {
                await this.fanoutTopicsQueue.SendFanoutTopicMessage(userHandle, appHandle, topicHandle);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update user visibility
        /// </summary>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="visibility">User visibility status</param>
        /// <param name="lastUpdatedTime">Last updated bio</param>
        /// <param name="userProfileEntity">User profile entity</param>
        /// <returns>Update user visibility task</returns>
        public async Task UpdateUserVisibility(
            string userHandle,
            string appHandle,
            UserVisibilityStatus visibility,
            DateTime lastUpdatedTime,
            IUserProfileEntity userProfileEntity)
        {
            userProfileEntity.Visibility      = visibility;
            userProfileEntity.LastUpdatedTime = lastUpdatedTime;

            await this.usersStore.UpdateUserProfile(StorageConsistencyMode.Strong, userHandle, appHandle, userProfileEntity);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert user
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="identityProviderType">Identity provider type</param>
        /// <param name="accountId">Account id</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="firstName">First name</param>
        /// <param name="lastName">Last name</param>
        /// <param name="bio">User bio</param>
        /// <param name="photoHandle">Photo handle</param>
        /// <param name="visibility">User visibility</param>
        /// <param name="createdTime">Created time</param>
        /// <param name="requestId">Request Id</param>
        /// <returns>Insert user task</returns>
        public async Task InsertUser(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            IdentityProviderType identityProviderType,
            string accountId,
            string appHandle,
            string firstName,
            string lastName,
            string bio,
            string photoHandle,
            UserVisibilityStatus visibility,
            DateTime createdTime,
            string requestId)
        {
            UserProfileEntity userProfileEntity = new UserProfileEntity()
            {
                FirstName       = firstName,
                LastName        = lastName,
                Bio             = bio,
                CreatedTime     = createdTime,
                LastUpdatedTime = createdTime,
                Visibility      = visibility,
                PhotoHandle     = photoHandle,
                ReviewStatus    = ReviewStatus.Active,
                RequestId       = requestId
            };

            AppFeedEntity appFeedEntity = new AppFeedEntity()
            {
                AppHandle = appHandle
            };

            LinkedAccountFeedEntity linkedAccountFeedEntity = new LinkedAccountFeedEntity()
            {
                IdentityProviderType = identityProviderType,
                AccountId            = accountId
            };

            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Users);

            ObjectTable profilesTable = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserProfilesObject) as ObjectTable;
            FeedTable   appsTable     = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserAppsFeed) as FeedTable;
            FeedTable   accountsTable = this.tableStoreManager.GetTable(ContainerIdentifier.Users, TableIdentifier.UserLinkedAccountsFeed) as FeedTable;
            Transaction transaction   = new Transaction();

            transaction.Add(Operation.Insert(profilesTable, userHandle, appHandle, userProfileEntity));
            transaction.Add(Operation.Insert(appsTable, userHandle, this.tableStoreManager.DefaultFeedKey, appHandle, appFeedEntity));
            transaction.Add(Operation.Insert(accountsTable, userHandle, this.tableStoreManager.DefaultFeedKey, identityProviderType.ToString(), linkedAccountFeedEntity));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> PostTopic([FromBody] PostTopicRequest request)
        {
            string className  = "TopicsController";
            string methodName = "PostTopic";
            string logEntry   = $"PublisherType = {request?.PublisherType}";

            this.LogControllerStart(this.log, className, methodName, logEntry);

            var userProfileEntity = await this.usersManager.ReadUserProfile(this.UserHandle, this.AppHandle);

            if (userProfileEntity == null)
            {
                return(this.Unauthorized(ResponseStrings.UserNotFound));
            }

            UserVisibilityStatus visibility = userProfileEntity.Visibility;

            // app published topics can only be created by an administrator of that application
            if (request.PublisherType == PublisherType.App)
            {
                bool isAdmin = await this.appsManager.IsAdminUser(this.AppHandle, this.UserHandle);

                if (!isAdmin)
                {
                    return(this.Unauthorized(ResponseStrings.UserUnauthorized));
                }
            }

            // Define a locally-scoped userHandle. If App is PublisherType, we will set it to null
            string userHandle = this.UserHandle;

            if (request.PublisherType == PublisherType.App)
            {
                // for app published topics, we don't record the userHandle as the topic owner
                // this is because if the user who created the topic is later deleted, we do not want the topic to disappear
                userHandle = null;

                // app published topics are always public
                visibility = UserVisibilityStatus.Public;
            }

            string topicHandle = this.handleGenerator.GenerateShortHandle();

            await this.topicsManager.CreateTopic(
                ProcessType.Frontend,
                topicHandle,
                request.Title,
                request.Text,
                request.BlobType,
                request.BlobHandle,
                request.Categories,
                request.Language,
                request.Group,
                request.DeepLink,
                request.FriendlyName,
                request.PublisherType,
                userHandle,
                visibility,
                DateTime.UtcNow,
                ReviewStatus.Active,
                this.AppHandle,
                null);

            var response = new PostTopicResponse()
            {
                TopicHandle = topicHandle
            };

            logEntry += $", TopicHandle = {topicHandle}";
            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.Created <PostTopicResponse>(new Uri(this.RequestAbsoluteUri + "/" + topicHandle), response));
        }