forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
S2U-29 5.1.3.3 Private Messages: Request a read receipt feature - mas…
…ter (sakaiproject#12193)
- Loading branch information
1 parent
5baada1
commit 4ad9372
Showing
21 changed files
with
329 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...rc/java/org/sakaiproject/api/app/messageforums/PrivateMessageUserNotificationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Copyright (c) 2003-2023 The Apereo Foundation | ||
* | ||
* Licensed under the Educational Community License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/ecl2 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.sakaiproject.api.app.messageforums; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import org.sakaiproject.api.app.messageforums.PrivateMessage; | ||
import org.sakaiproject.api.app.messageforums.ui.PrivateMessageManager; | ||
import org.sakaiproject.component.api.ServerConfigurationService; | ||
import org.sakaiproject.event.api.Event; | ||
import org.sakaiproject.exception.IdUnusedException; | ||
import org.sakaiproject.messaging.api.AbstractUserNotificationHandler; | ||
import org.sakaiproject.messaging.api.UserNotificationData; | ||
import org.sakaiproject.site.api.Site; | ||
import org.sakaiproject.site.api.SiteService; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
public class PrivateMessageUserNotificationHandler extends AbstractUserNotificationHandler{ | ||
|
||
@Resource | ||
private PrivateMessageManager privateMessageManager; | ||
|
||
@Resource | ||
private SiteService siteService; | ||
|
||
@Resource | ||
private ServerConfigurationService serverConfigurationService; | ||
|
||
@Override | ||
public List<String> getHandledEvents() { | ||
return Arrays.asList(DiscussionForumService.EVENT_MESSAGES_READ_RECEIPT); | ||
} | ||
|
||
@Override | ||
public Optional<List<UserNotificationData>> handleEvent(Event e) { | ||
|
||
String from = e.getUserId(); | ||
|
||
String ref = e.getResource(); | ||
String[] pathParts = ref.split("/"); | ||
|
||
String siteId = pathParts[3]; | ||
String pvtMessageId = pathParts[pathParts.length - 2]; | ||
|
||
try { | ||
PrivateMessage pvtMessage = privateMessageManager.getPrivateMessageByDecryptedId(pvtMessageId); | ||
switch (e.getEvent()) { | ||
case DiscussionForumService.EVENT_MESSAGES_READ_RECEIPT: | ||
return Optional.of(handleAdd(from, siteId, pvtMessage.getCreatedBy(), pvtMessage)); | ||
default: | ||
return Optional.empty(); | ||
} | ||
} catch (Exception ex) { | ||
log.error("Failed to find the privateMessage: " + pvtMessageId, ex); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
private List<UserNotificationData> handleAdd(String from, String siteId, String userId, PrivateMessage pvtMessage) { | ||
|
||
List<UserNotificationData> notificationEvents = new ArrayList<>(); | ||
|
||
Date openTime = pvtMessage.getCreated(); | ||
if (openTime == null || openTime.before(new Date()) && !pvtMessage.getDraft()) { | ||
try { | ||
Site site = siteService.getSite(siteId); | ||
String title = pvtMessage.getTitle(); | ||
if (!from.equals(userId)) { | ||
String toolId = site.getToolForCommonId(DiscussionForumService.MESSAGES_TOOL_ID).getId(); | ||
String url = serverConfigurationService.getPortalUrl() + "/site/" + siteId | ||
+ "/tool/" + toolId + "/privateMsg/pvtMsgDirectAccess?current_msg_detail=" + pvtMessage.getId(); | ||
notificationEvents.add(new UserNotificationData(from, userId, siteId, title, url)); | ||
} | ||
} catch (IdUnusedException idEx) { | ||
log.error("Failed to find the site: " + siteId, idEx); | ||
} | ||
|
||
} | ||
|
||
return notificationEvents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.