/// <summary>
        /// Update notifications status
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="readActivityHandle">Read activity handle</param>
        /// <param name="readNotificationsStatusEntity">Read notifications status entity</param>
        /// <returns>Update notifications status task</returns>
        public async Task UpdateNotificationsStatus(
            StorageConsistencyMode storageConsistencyMode,
            string userHandle,
            string appHandle,
            string readActivityHandle,
            INotificationsStatusEntity readNotificationsStatusEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.Notifications);

            ObjectTable statusTable = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsStatus) as ObjectTable;
            CountTable  countTable  = this.tableStoreManager.GetTable(ContainerIdentifier.Notifications, TableIdentifier.NotificationsCount) as CountTable;

            Transaction transaction = new Transaction();

            if (readNotificationsStatusEntity == null)
            {
                NotificationsStatusEntity notificationsStatusEntity = new NotificationsStatusEntity()
                {
                    ReadActivityHandle = readActivityHandle
                };

                transaction.Add(Operation.Insert(statusTable, userHandle, appHandle, notificationsStatusEntity));
            }
            else
            {
                readNotificationsStatusEntity.ReadActivityHandle = readActivityHandle;
                transaction.Add(Operation.Replace(statusTable, userHandle, appHandle, readNotificationsStatusEntity as NotificationsStatusEntity));
            }

            transaction.Add(Operation.InsertOrReplace(countTable, userHandle, appHandle, 0));
            await store.ExecuteTransactionAsync(transaction, storageConsistencyMode.ToConsistencyMode());
        }
示例#2
0
 /// <summary>
 /// Update notifications status.
 /// This records the most recent notification that the user has read (or seen).
 /// </summary>
 /// <param name="userHandle">User handle</param>
 /// <param name="appHandle">App handle</param>
 /// <param name="readActivityHandle">Read activity handle</param>
 /// <param name="notificationsStatusEntity">Notifications status entity</param>
 /// <returns>Update notifications status task</returns>
 public async Task UpdateNotificationsStatus(
     string userHandle,
     string appHandle,
     string readActivityHandle,
     INotificationsStatusEntity notificationsStatusEntity)
 {
     await this.notificationsStore.UpdateNotificationsStatus(
         StorageConsistencyMode.Strong,
         userHandle,
         appHandle,
         readActivityHandle,
         notificationsStatusEntity);
 }
示例#3
0
        /// <summary>
        /// Create a notification
        /// </summary>
        /// <param name="processType">Process type</param>
        /// <param name="userHandle">User handle</param>
        /// <param name="appHandle">App handle</param>
        /// <param name="activityHandle">Activity handle</param>
        /// <param name="activityType">Activity type</param>
        /// <param name="actorUserHandle">Actor user handle</param>
        /// <param name="actedOnUserHandle">Acted on user handle</param>
        /// <param name="actedOnContentType">Acted on content type</param>
        /// <param name="actedOnContentHandle">Acted on content handle</param>
        /// <param name="createdTime">Created time</param>
        /// <returns>Create notification task</returns>
        public async Task CreateNotification(
            ProcessType processType,
            string userHandle,
            string appHandle,
            string activityHandle,
            ActivityType activityType,
            string actorUserHandle,
            string actedOnUserHandle,
            ContentType actedOnContentType,
            string actedOnContentHandle,
            DateTime createdTime)
        {
            await this.notificationsStore.InsertNotification(
                StorageConsistencyMode.Strong,
                userHandle,
                appHandle,
                activityHandle,
                activityType,
                actorUserHandle,
                actedOnUserHandle,
                actedOnContentType,
                actedOnContentHandle,
                createdTime);

            // check if the user has already seen this activity in the app
            INotificationsStatusEntity notificationsStatusEntity = await this.ReadNotificationsStatus(userHandle, appHandle);

            // Send a push notification if the user hasn't already seen this notification in the app UI.
            // This is a similar comparison to what is done in GetActivityView
            if (notificationsStatusEntity == null ||
                string.CompareOrdinal(activityHandle, notificationsStatusEntity.ReadActivityHandle) <= 0)
            {
                // send a push notification
                await this.pushNotificationsManager.SendNotification(
                    userHandle,
                    appHandle,
                    activityHandle,
                    activityType,
                    actorUserHandle,
                    actedOnUserHandle,
                    actedOnContentType,
                    actedOnContentHandle,
                    createdTime);
            }
        }
        public async Task <IHttpActionResult> PutNotificationsStatus([FromBody] PutNotificationsStatusRequest request)
        {
            string className  = "MyNotificationsController";
            string methodName = "PutNotificationsStatus";
            string logEntry   = $"ActivityHandle = {request?.ReadActivityHandle}";

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

            INotificationsStatusEntity notificationsStatusEntity = await this.notificationsManager.ReadNotificationsStatus(this.UserHandle, this.AppHandle);

            if (notificationsStatusEntity != null)
            {
                if (string.CompareOrdinal(request.ReadActivityHandle, notificationsStatusEntity.ReadActivityHandle) > 0)
                {
                    return(this.Conflict(ResponseStrings.NewerItemExists));
                }
            }

            await this.notificationsManager.UpdateNotificationsStatus(this.UserHandle, this.AppHandle, request.ReadActivityHandle, notificationsStatusEntity);

            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.NoContent());
        }