Skip to content

Commit 66ae189

Browse files
committed
Make the process faster using the ActivityService (thanks Mike Peterson), fix a truncate error, and fix an incorrect timestamp.
1 parent 27e9ddf commit 66ae189

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

SendGrid/RockWeb/Webhooks/SendGrid.ashx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ public class SendGrid : IHttpHandler
3232
string postedData = GetDocumentContents(_request);
3333

3434
var rockContext = new Rock.Data.RockContext();
35-
var timeZoneInfo = RockDateTime.OrgTimeZoneInfo;
35+
3636
var communicationRecipientService = new CommunicationRecipientService(rockContext);
37+
var communicationRecipientActivityService = new CommunicationRecipientActivityService();
3738

39+
var timeZoneInfo = RockDateTime.OrgTimeZoneInfo;
3840
var parser = new Sendgrid.Webhooks.Service.WebhookParser();
3941
var events = parser.ParseEvents(postedData);
4042

@@ -98,17 +100,22 @@ public class SendGrid : IHttpHandler
98100
"Unknown";
99101
var openActivity = new CommunicationRecipientActivity
100102
{
103+
CommunicationRecipientId = communicationRecipient.Id,
101104
ActivityType = "Opened",
102-
ActivityDateTime = openEvent.TimeStamp,
105+
ActivityDateTime = item.TimeStamp,
103106
ActivityDetail =
104107
string.Format("Opened from {0} ({1})", openEvent.UserAgent ?? "unknown",
105108
openEvent.Ip).Truncate(2200)
106109
};
107-
communicationRecipient.Activities.Add(openActivity);
110+
communicationRecipientActivityService.Add(openActivity);
108111
}
109112
break;
110113
case WebhookEventType.Click:
111-
var clickActivity = new CommunicationRecipientActivity { ActivityType = "Click" };
114+
var clickActivity = new CommunicationRecipientActivity
115+
{
116+
CommunicationRecipientId = communicationRecipient.Id,
117+
ActivityType = "Click"
118+
};
112119
var clickEvent = item as ClickEvent;
113120
clickActivity.ActivityDateTime = item.TimeStamp;
114121
if (clickEvent != null)
@@ -117,7 +124,7 @@ public class SendGrid : IHttpHandler
117124
string.Format("Clicked the address {0} from {1} using {2}", clickEvent.Url,
118125
clickEvent.Ip, clickEvent.UserAgent).Truncate(2200);
119126
}
120-
communicationRecipient.Activities.Add(clickActivity);
127+
CommunicationRecipientActivityService.Add(clickActivity);
121128
break;
122129
case WebhookEventType.Dropped:
123130
var dropEvent = item as DroppedEvent;
@@ -177,7 +184,7 @@ public class SendGrid : IHttpHandler
177184
}
178185
if (!string.IsNullOrEmpty(item.Email))
179186
{
180-
Rock.Communication.Email.ProcessBounce(item.Email, Rock.Communication.BounceType.HardBounce, failDescription.Truncate(250), item.TimeStamp);
187+
Rock.Communication.Email.ProcessBounce(item.Email, Rock.Communication.BounceType.HardBounce, failDescription.Truncate(200), item.TimeStamp);
181188
}
182189
}
183190
}

0 commit comments

Comments
 (0)