예제 #1
0
        /// <summary>
        /// Queues notifications to people from comment text based on @ symbols
        /// </summary>
        private async Task ParseMentionsAsync(IDbConnection connection, Comment comment, UserProfile userProfile)
        {
            // for now, can do mentions only on work item comments because EventLog.WorkItemId is required
            if (comment.ObjectType != ObjectType.WorkItem)
            {
                return;
            }

            var names = Regex.Matches(comment.TextBody, "@([a-zA-Z][a-zA-Z0-9_]*)").OfType <Match>();

            if (!names.Any())
            {
                return;
            }

            string senderName = await OrganizationUser.GetUserDisplayNameAsync(connection, comment.OrganizationId, userProfile.UserId, userProfile);

            foreach (var name in names)
            {
                var users = await new OrgUserByName()
                {
                    OrgId = comment.OrganizationId, Name = name.Value.Substring(1)
                }.ExecuteAsync(connection);
                if (users.Any())
                {
                    var    mentionedUser = users.First();
                    string mentionName   = mentionedUser.DisplayName ?? mentionedUser.Email;
                    await ReplaceMentionNameAsync(connection, comment, name.Value, mentionedUser);

                    int eventLogId = await CreateEventLogFromMentionAsync(connection, comment, senderName, mentionName);

                    await Notification.CreateFromMentionAsync(connection, eventLogId, comment, senderName, mentionedUser);
                }
            }
        }
예제 #2
0
        public override async Task AfterSaveAsync(IDbConnection connection, SaveAction action, IUser user)
        {
            if (action == SaveAction.Insert)
            {
                var workItem = await connection.FindAsync <WorkItem>(WorkItemId);

                var label = await connection.FindAsync <Label>(LabelId);

                string displayUser = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, user.UserName);

                string text = $"{displayUser} added label {label.Name} to work item {workItem.Number}";
                string html = $"{displayUser} added label <strong>{label.Name}</strong> to work item {workItem.Number}";

                int eventLogId = await EventLog.WriteAsync(connection, new EventLog()
                {
                    OrganizationId = workItem.OrganizationId,
                    TeamId         = workItem.TeamId,
                    ApplicationId  = workItem.ApplicationId,
                    WorkItemId     = workItem.Id,
                    EventId        = SystemEvent.LabelAdded,
                    IconClass      = IconClass,
                    IconColor      = IconColor,
                    HtmlBody       = html,
                    TextBody       = text,
                    SourceId       = Id,
                    SourceTable    = nameof(WorkItemLabel)
                }, user);

                await Notification.CreateFromLabelSubscriptions(connection, eventLogId);
            }
        }
예제 #3
0
        public override async Task AfterSaveAsync(IDbConnection connection, SaveAction action, IUser user)
        {
            if (action == SaveAction.Insert)
            {
                var workItem = await connection.FindAsync <WorkItem>(WorkItemId);

                workItem.ActivityId    = ToActivityId;
                workItem.LastHandOffId = Id;
                await connection.SaveAsync(workItem, user);

                var toActivity = await connection.FindAsync <Activity>(ToActivityId);

                var fromActivity = await connection.FindAsync <Activity>(FromActivityId);

                string displayUser = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, FromUserId, user);

                string text = $"{displayUser} handed off work item {workItem.Number} from {fromActivity.Name} to {toActivity.Name}";

                int eventLogId = await EventLog.WriteAsync(connection, new EventLog(WorkItemId, user)
                {
                    EventId     = (IsForward) ? SystemEvent.HandOffForward : SystemEvent.HandOffBackward,
                    IconClass   = GetIconClass(IsForward),
                    IconColor   = GetColor(IsForward),
                    HtmlBody    = text,
                    TextBody    = text,
                    SourceId    = Id,
                    SourceTable = "HandOff"
                });

                await Notification.CreateFromActivitySubscriptions(connection, eventLogId);
            }
        }
예제 #4
0
        public override async Task AfterSaveAsync(IDbConnection connection, SaveAction action, IUser user)
        {
            if (action == SaveAction.Insert)
            {
                var workItem = await connection.FindAsync <WorkItem>(WorkItemId);

                workItem.ActivityId    = ToActivityId;
                workItem.LastHandOffId = Id;

                if (ToUserId.HasValue)
                {
                    var activity = await connection.FindAsync <Activity>(ToActivityId);

                    Responsibility.SetWorkItemUserActions[activity.ResponsibilityId].Invoke(workItem, ToUserId.Value);
                }

                await connection.SaveAsync(workItem, user);

                var toActivity = await connection.FindAsync <Activity>(ToActivityId);

                var fromActivity = await connection.FindAsync <Activity>(FromActivityId);

                string displayUser = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, FromUserId, user);

                string text = $"{displayUser} handed off work item {workItem.Number} from {fromActivity.Name} to {toActivity.Name}";

                if (ToUserId.HasValue)
                {
                    var assignedToUser = await connection.FindAsync <UserProfile>(ToUserId.Value);

                    string assignedToName = await OrganizationUser.GetUserDisplayNameAsync(connection, workItem.OrganizationId, ToUserId.Value, assignedToUser);

                    text += $", assigned to {assignedToName}";
                }

                int eventLogId = await EventLog.WriteAsync(connection, new EventLog(WorkItemId, user)
                {
                    TeamId      = workItem.TeamId,
                    EventId     = (IsForward) ? SystemEvent.HandOffForward : SystemEvent.HandOffBackward,
                    IconClass   = GetIconClass(IsForward),
                    IconColor   = GetColor(IsForward),
                    HtmlBody    = text,
                    TextBody    = text,
                    SourceId    = Id,
                    SourceTable = nameof(HandOff)
                });

                await Notification.CreateFromActivitySubscriptions(connection, eventLogId);
            }
        }