Skip to content

Commit

Permalink
S2U-29 5.1.3.3 Private Messages: Request a read receipt feature - mas…
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavid102 authored Dec 14, 2023
1 parent 5baada1 commit 4ad9372
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 22 deletions.
4 changes: 4 additions & 0 deletions msgcntr/messageforums-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
<build>
<resources />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,3 +987,11 @@ cdfm_faq_forum_title=FAQ Forum
cdfm_faq_forum_description=Forum for frequently asked questions
cdfm_faq_topic_title=FAQ Topic
cdfm_faq_topic_description=Topic for frequently asked questions

#S2U-29
pvt_read_receipt_label=Read Receipt
pvt_read_receipt_text=Receive a notification when the message is opened by the recipient

pvt_read_receipt_email={0}({1}) has read the message with the subject: `{2}` on {3}. \n\nTo see this message, click in this url and see the message of the site: {4}
pvt_email_href=<a href="{0}">{1}<\a>
pvt_read_receipt_email_subject={0} has been read
Original file line number Diff line number Diff line change
Expand Up @@ -981,3 +981,10 @@ cdfm_faq_forum_title=F\u00f2rum Preguntes Freq\u00fcents
cdfm_faq_forum_description=F\u00f2rum per Preguntes Freq\u00fcents
cdfm_faq_topic_title=Tema Preguntes Freq\u00fcents
cdfm_faq_topic_description=Tema per a Preguntes Freq\u00fcents

#S2U-29
pvt_read_receipt_label=Acusament de rebut
pvt_read_receipt_text=Rebre una notificaci\u00f3 quan el missatge sigui obert pel destinatari

pvt_read_receipt_email={0}({1}) ha llegit el missatge amb l`assumpte `{2}` el {3}. \n\nPer veure aquest missatge, feu clic en aquest URL i vegeu el missatge del lloc: {4}
pvt_read_receipt_email_subject={0} ha estat llegit
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,10 @@ cdfm_faq_forum_title=Foro preguntas frecuentes
cdfm_faq_forum_description=Foro para preguntas frecuentes
cdfm_faq_topic_title=Preguntas frecuentes
cdfm_faq_topic_description=Tema para las preguntas m\u00e1s frecuentes

#S2U-29
pvt_read_receipt_label=Acuse de recibo
pvt_read_receipt_text=Recibir una notificaci\u00f3n cuando el mensaje sea abierto por el destinatario

pvt_read_receipt_email={0}({1}) ha le\u00eddo el mensaje con asunto `{2}` el {3}. \n\nPara ver el mensaje que envi\u00f3, haga clic en este enlace y acceda al mensaje del sitio: {4}
pvt_read_receipt_email_subject={0} ha sido le\u00eddo
Original file line number Diff line number Diff line change
Expand Up @@ -983,3 +983,10 @@ cdfm_faq_forum_title=FAQ foroa
cdfm_faq_forum_description=Galdera ohikoentzako foroa
cdfm_faq_topic_title=FAQ gaia
cdfm_faq_topic_description=Galdera ohikoentzako gaia

#S2U-29
pvt_read_receipt_label=Jaso izanaren akta
pvt_read_receipt_text=Jaso jakinarazpen bat hartzaileak mezua irekitzen duenean

pvt_read_receipt_email={0}({1})-ek `{2}` mezua irakurri du {3}an. \n\nMezu hau ikusteko, egin klik url honetan eta ikusi gunearen mezua: {4}
pvt_read_receipt_email_subject={0} irakurri da
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface DiscussionForumService extends EntityProducer
public static final String EVENT_MESSAGES_RESPONSE = "messages.reply";

public static final String EVENT_MESSAGES_FORWARD = "messages.forward";

public static final String EVENT_MESSAGES_READ_RECEIPT = "message.read.receipt";

// Events for the (Discussion) Forums tool
public static final String EVENT_FORUMS_ADD = "forums.new";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ public interface PrivateMessageRecipient

public void setReplied(Boolean replied);

public Boolean getReadReceipt();

public void setReadReceipt(Boolean readReceipt);

}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ public List getMessagesByTypeByContext(final String typeUuid, final String conte
* @param message
* @param recipients
* @param asEmail
* @param readReceipt
*/
public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipients, boolean asEmail);
public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipients, boolean asEmail, List<MembershipItem> draftRecipients, List<MembershipItem> draftBccRecipients);
public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipients, boolean asEmail, boolean readReceipt);
public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipients, boolean asEmail, List<MembershipItem> draftRecipients, List<MembershipItem> draftBccRecipients, boolean readReceipt);


/**
Expand Down Expand Up @@ -263,5 +264,7 @@ public List getMessagesByTypeByContext(final String typeUuid, final String conte
boolean isAllowToFieldMyGroups(User user, String contextId);

boolean isAllowToFieldMyGroupMembers(User user, String contextId);

public PrivateMessage getPrivateMessageByDecryptedId(String id) throws MessagingException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ public class PrivateMessagesTool {
private String composeSendAsPvtMsg=SET_AS_YES; // currently set as Default as change by user is allowed
@Setter
private boolean booleanEmailOut = ServerConfigurationService.getBoolean("mc.messages.ccEmailDefault", false);
@Getter @Setter
private boolean booleanReadReceipt;
@Getter
private String composeSubject;
@Getter
Expand Down Expand Up @@ -1719,6 +1721,7 @@ public void resetComposeContents()
this.setBooleanSchedulerSend(false);
this.setOpenDate("");
this.setSchedulerSendDateString("");
this.setBooleanReadReceipt(false);
}

public String processPvtMsgPreview(){
Expand Down Expand Up @@ -1814,7 +1817,7 @@ public String processPvtMsgSend() {
return processPvtMsgComposeCancel();
} else {
PrivateMessageSchedulerService.removeScheduledReminder(pMsg.getId());
prtMsgManager.sendPrivateMessage(pMsg, recipients, isSendEmail);
prtMsgManager.sendPrivateMessage(pMsg, recipients, isSendEmail, booleanReadReceipt);
}
// if you are sending a reply
Message replying = pMsg.getInReplyTo();
Expand Down Expand Up @@ -1948,7 +1951,7 @@ public String processPvtMsgSaveDraft() {
List<MembershipItem> draftRecipients = drDelegate.getDraftRecipients(getSelectedComposeToList(), courseMemberMap);
List<MembershipItem> draftBccRecipients = drDelegate.getDraftRecipients(getSelectedComposeBccList(), courseMemberMap);

prtMsgManager.sendPrivateMessage(dMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients);
prtMsgManager.sendPrivateMessage(dMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients, booleanReadReceipt);

//reset contents
resetComposeContents();
Expand Down Expand Up @@ -2441,9 +2444,9 @@ private String processPvtMsgReplySentAction(PrivateMessage rrepMsg){
List<MembershipItem> draftRecipients = drDelegate.getDraftRecipients(getSelectedComposeToList(), courseMemberMap);
List<MembershipItem> draftBccRecipients = drDelegate.getDraftRecipients(getSelectedComposeBccList(), courseMemberMap);

prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients);
prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients, booleanReadReceipt);
} else {
prtMsgManager.sendPrivateMessage(rrepMsg, recipients, isSendEmail());
prtMsgManager.sendPrivateMessage(rrepMsg, recipients, isSendEmail(), booleanReadReceipt);
}

if(!rrepMsg.getDraft()){
Expand Down Expand Up @@ -2829,9 +2832,9 @@ private void processPvtMsgForwardSendHelper(PrivateMessage rrepMsg){
List<MembershipItem> draftRecipients = drDelegate.getDraftRecipients(getSelectedComposeToList(), courseMemberMap);
List<MembershipItem> draftBccRecipients = drDelegate.getDraftRecipients(getSelectedComposeBccList(), courseMemberMap);

prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients);
prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients, booleanReadReceipt);
} else {
prtMsgManager.sendPrivateMessage(rrepMsg, recipients, isSendEmail());
prtMsgManager.sendPrivateMessage(rrepMsg, recipients, isSendEmail(), booleanReadReceipt);
}

if(!rrepMsg.getDraft()){
Expand Down Expand Up @@ -3121,9 +3124,9 @@ private PrivateMessage processPvtMsgReplyAllSendHelper(boolean preview, Boolean
List<MembershipItem> draftRecipients = drDelegate.getDraftRecipients(getSelectedComposeToList(), courseMemberMap);
List<MembershipItem> draftBccRecipients = drDelegate.getDraftRecipients(getSelectedComposeBccList(), courseMemberMap);

prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients);
prtMsgManager.sendPrivateMessage(rrepMsg, getRecipients(), isSendEmail(), draftRecipients, draftBccRecipients, booleanReadReceipt);
} else {
prtMsgManager.sendPrivateMessage(rrepMsg, returnSet, isSendEmail());
prtMsgManager.sendPrivateMessage(rrepMsg, returnSet, isSendEmail(), booleanReadReceipt);
}

if(!rrepMsg.getDraft()){
Expand Down
17 changes: 17 additions & 0 deletions msgcntr/messageforums-app/src/webapp/jsp/compose.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@
</div>
<div class="row d-flex">
<div class="col-xs-12 col-sm-2 form-control-label">
<h:panelGroup styleClass="shorttext">
<h:outputLabel>
<h:outputText styleClass="pvt_read_receipt" value="#{msgs.pvt_read_receipt_label}"/>
</h:outputLabel>
</h:panelGroup>
</div>
<div class="col-xs-12 col-sm-10">
<h:panelGroup>
<h:selectBooleanCheckbox value="#{PrivateMessagesTool.booleanReadReceipt}" id="read_receipt" ></h:selectBooleanCheckbox>
<h:outputLabel for="read_receipt">
<h:outputText value="#{msgs.pvt_read_receipt_text}"/>
</h:outputLabel>
</h:panelGroup>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2">
<h:outputLabel for="viewlist">
<h:outputText value="#{msgs.pvt_label}" />
</h:outputLabel>
Expand Down
17 changes: 17 additions & 0 deletions msgcntr/messageforums-app/src/webapp/jsp/pvtMsgForward.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@
</div>
</div>
<div class="row d-flex">
<div class="col-xs-12 col-sm-2 form-control-label">
<h:panelGroup styleClass="shorttext">
<h:outputLabel>
<h:outputText styleClass="pvt_read_receipt" value="#{msgs.pvt_read_receipt_label}"/>
</h:outputLabel>
</h:panelGroup>
</div>
<div class="col-xs-12 col-sm-10">
<h:panelGroup>
<h:selectBooleanCheckbox value="#{PrivateMessagesTool.booleanReadReceipt}" id="read_receipt" ></h:selectBooleanCheckbox>
<h:outputLabel for="read_receipt">
<h:outputText value="#{msgs.pvt_read_receipt_text}"/>
</h:outputLabel>
</h:panelGroup>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2">
<h:panelGroup styleClass="shorttext form-control-label">
<h:outputLabel for="viewlist">
Expand Down
17 changes: 17 additions & 0 deletions msgcntr/messageforums-app/src/webapp/jsp/pvtMsgReply.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@
</div>
</div>
<div class="row d-flex">
<div class="col-xs-12 col-sm-2 form-control-label">
<h:panelGroup styleClass="shorttext">
<h:outputLabel>
<h:outputText styleClass="pvt_read_receipt" value="#{msgs.pvt_read_receipt_label}"/>
</h:outputLabel>
</h:panelGroup>
</div>
<div class="col-xs-12 col-sm-10">
<h:panelGroup>
<h:selectBooleanCheckbox value="#{PrivateMessagesTool.booleanReadReceipt}" id="read_receipt" ></h:selectBooleanCheckbox>
<h:outputLabel for="read_receipt">
<h:outputText value="#{msgs.pvt_read_receipt_text}"/>
</h:outputLabel>
</h:panelGroup>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2">
<h:panelGroup styleClass="shorttext form-control-label">
<h:outputLabel for="viewlist">
Expand Down
17 changes: 17 additions & 0 deletions msgcntr/messageforums-app/src/webapp/jsp/pvtMsgReplyAll.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@
</div>
</div>
<div class="row d-flex">
<div class="col-xs-12 col-sm-2 form-control-label">
<h:panelGroup styleClass="shorttext">
<h:outputLabel>
<h:outputText styleClass="pvt_read_receipt" value="#{msgs.pvt_read_receipt_label}"/>
</h:outputLabel>
</h:panelGroup>
</div>
<div class="col-xs-12 col-sm-10">
<h:panelGroup>
<h:selectBooleanCheckbox value="#{PrivateMessagesTool.booleanReadReceipt}" id="read_receipt" ></h:selectBooleanCheckbox>
<h:outputLabel for="read_receipt">
<h:outputText value="#{msgs.pvt_read_receipt_text}"/>
</h:outputLabel>
</h:panelGroup>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2">
<h:panelGroup styleClass="shorttext form-control-label">
<h:outputLabel for="viewlist" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void execute(String opaqueContext) {
pvtMsg.setScheduler(false);
pvtMsg.setDraft(false);

prtMsgManager.sendPrivateMessage(pvtMsg, recipients, false);
prtMsgManager.sendPrivateMessage(pvtMsg, recipients, false, false);

// if you are sending a reply
Message replying = pvtMsg.getInReplyTo();
Expand Down
Loading

0 comments on commit 4ad9372

Please sign in to comment.