Skip to content

Commit

Permalink
various messaging improvements. close #2183 close #2184
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 7, 2023
1 parent c398144 commit 0a36469
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@
import com.jdimension.jlawyer.client.events.DocumentAddedEvent;
import com.jdimension.jlawyer.client.events.Event;
import com.jdimension.jlawyer.client.events.EventBroker;
import com.jdimension.jlawyer.client.events.InstantMessageDeletedEvent;
import com.jdimension.jlawyer.client.events.NewInstantMessagesEvent;
import com.jdimension.jlawyer.client.events.ReviewAddedEvent;
import com.jdimension.jlawyer.client.launcher.CaseDocumentStore;
import com.jdimension.jlawyer.client.launcher.CustomLauncher;
Expand Down Expand Up @@ -989,6 +991,8 @@ public ArchiveFilePanel() {
EventBroker b = EventBroker.getInstance();
b.subscribeConsumer(this, Event.TYPE_DOCUMENTADDED);
b.subscribeConsumer(this, Event.TYPE_REVIEWADDED);
b.subscribeConsumer(this, Event.TYPE_INSTANTMESSAGING_MESSAGEDELETED);
b.subscribeConsumer(this, Event.TYPE_INSTANTMESSAGING_NEWMESSAGES);

}

Expand Down Expand Up @@ -3715,6 +3719,17 @@ public void showDocumentsPopup(MouseEvent evt) {
}

public void addMessageToView(InstantMessage msg) {
// check if message has already been added
for(Component c: this.pnlMessages.getComponents()) {
if(c instanceof MessagePanel) {
InstantMessage existingMessage=((MessagePanel)c).getMessage();
if(existingMessage.getId().equals(msg.getId())) {
return;
}
}
}


MessagePanel mp1 = new MessagePanel(UserSettings.getInstance().getLoginEnabledUsers(), UserSettings.getInstance().getCurrentUser().getPrincipalId(), UserSettings.getInstance().getCurrentUser().getPrincipalId().equalsIgnoreCase(msg.getSender()), msg);
mp1.setAlignmentX(JPanel.LEFT_ALIGNMENT);
mp1.setContextForeground(DefaultColorTheme.COLOR_DARK_GREY);
Expand Down Expand Up @@ -5917,9 +5932,10 @@ private void mnuSendMessageForDocumentActionPerformed(java.awt.event.ActionEvent
if(selectedDocs.isEmpty())
return;

SendInstantMessageDialog dlg=new SendInstantMessageDialog(EditorsRegistry.getInstance().getMainWindow(), true, this.dto, selectedDocs, this);
SendInstantMessageDialog dlg=new SendInstantMessageDialog(EditorsRegistry.getInstance().getMainWindow(), true, this.dto, selectedDocs);
FrameUtils.centerDialog(dlg, EditorsRegistry.getInstance().getMainWindow());
dlg.setVisible(true);


}//GEN-LAST:event_mnuSendMessageForDocumentActionPerformed

Expand Down Expand Up @@ -6169,6 +6185,36 @@ public void onEvent(Event e) {
}
}
}
} else if (e instanceof InstantMessageDeletedEvent) {

boolean removed = false;
for (int i = 0; i < this.pnlMessages.getComponentCount(); i++) {
if (this.pnlMessages.getComponent(i) instanceof MessagePanel) {
if (((MessagePanel) this.pnlMessages.getComponent(i)).getMessage().getId().equals(((InstantMessageDeletedEvent)e).getMessageId())) {
this.pnlMessages.remove(this.pnlMessages.getComponent(i));
removed = true;
break;
}
}
}
if (removed) {
this.pnlMessages.revalidate();
}



} else if (e instanceof NewInstantMessagesEvent) {
SwingUtilities.invokeLater(() -> {
if (((NewInstantMessagesEvent) e).getNewMessages() != null) {
for (InstantMessage msg : ((NewInstantMessagesEvent) e).getNewMessages()) {
if(msg.getCaseContext() != null && this.dto!=null) {
if (msg.getCaseContext().getId().equals(this.dto.getId())) {
this.addMessageToView(msg);
}
}
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,6 @@ public class MessagePollingTimerTask extends java.util.TimerTask {
private long lastMessageTimestamp=-1;
private long lastMentionStatusChangedTimestamp=-1;

protected static long unseenByUser=0;

/**
* Creates a new instance of MessagePollingTimerTask
* @param latestMessage
Expand Down Expand Up @@ -740,18 +738,4 @@ public void run() {
}
}

/**
* @return the unseenByUser
*/
public static synchronized long getUnseenByUser() {
return unseenByUser;
}

/**
* @param aUnseenByUser the unseenByUser to set
*/
public static synchronized void setUnseenByUser(long aUnseenByUser) {
unseenByUser = aUnseenByUser;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@
<Container class="javax.swing.JTabbedPane" name="tabsPane">
<Properties>
<Property name="tabLayoutPolicy" type="int" value="1"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="tabsPane" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
</Properties>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@
import com.jdimension.jlawyer.client.settings.ServerSettings;
import com.jdimension.jlawyer.client.settings.UserSettings;
import com.jdimension.jlawyer.client.utils.FrameUtils;
import com.jdimension.jlawyer.client.utils.StringUtils;
import com.jdimension.jlawyer.persistence.ArchiveFileBean;
import com.jdimension.jlawyer.persistence.InstantMessage;
import com.jdimension.jlawyer.persistence.InstantMessageMention;
import com.jdimension.jlawyer.services.JLawyerServiceLocator;
Expand Down Expand Up @@ -713,6 +715,7 @@ public class MessagingCenterPanel extends javax.swing.JPanel implements Themeabl
private static final Logger log = Logger.getLogger(MessagingCenterPanel.class.getName());

private static final int SCROLLPANE_VERTICAL_INCREMENT = 16;
private static final String CLIENTPROPERTY_CASECONTEXT="tab.casecontext";

private Image backgroundImage = null;

Expand All @@ -732,6 +735,8 @@ public MessagingCenterPanel() {
this.initializing = true;

initComponents();

this.tabsPane.putClientProperty("JTabbedPane.maximumTabWidth", 200);

this.jScrollPane1.getViewport().setOpaque(false);
this.jScrollPane1.getVerticalScrollBar().setUnitIncrement(SCROLLPANE_VERTICAL_INCREMENT);
Expand Down Expand Up @@ -916,6 +921,7 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jScrollPane1.setViewportView(lstHashtags);

tabsPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
tabsPane.setFont(tabsPane.getFont());

jScrollPane3.setBorder(null);
jScrollPane3.setOpaque(false);
Expand Down Expand Up @@ -1015,7 +1021,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
.add(cmbDownloadInstantMessages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jScrollPane1)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
.add(lblClearHashtagSelection, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
Expand Down Expand Up @@ -1232,9 +1238,12 @@ private void addToTabIfRequired(InstantMessage msg) {

int existingTab = -1;
for (int i = 0; i < this.tabsPane.getTabCount(); i++) {
if (tabsPane.getTitleAt(i).equals(msg.getCaseContext().getFileNumber())) {
existingTab = i;
break;
Object caseContext=((JScrollPane)tabsPane.getComponentAt(i)).getClientProperty(CLIENTPROPERTY_CASECONTEXT);
if(caseContext!=null && caseContext instanceof ArchiveFileBean) {
if(((ArchiveFileBean)caseContext).getId().equals(msg.getCaseContext().getId())) {
existingTab = i;
break;
}
}
}

Expand All @@ -1253,7 +1262,9 @@ private void addToTabIfRequired(InstantMessage msg) {
targetScroll.getViewport().setOpaque(false);
targetScroll.setBorder(null);
targetScroll.setOpaque(false);
tabsPane.addTab(msg.getCaseContext().getFileNumber(), targetScroll);
targetScroll.putClientProperty(CLIENTPROPERTY_CASECONTEXT, msg.getCaseContext());
tabsPane.addTab(getTabTitleForMessage(msg), targetScroll);
tabsPane.setToolTipTextAt(tabsPane.getTabCount()-1, this.getTooltipForTab(msg.getCaseContext()));
existingTab = tabsPane.getTabCount() - 1;

} else {
Expand All @@ -1272,7 +1283,7 @@ private void addToTabIfRequired(InstantMessage msg) {
if (msg.getSent().getTime() > tab4latest.getTime()) {
// move tab to the left
tabsPane.removeTabAt(existingTab);
tabsPane.insertTab(msg.getCaseContext().getFileNumber(), null, targetScroll, null, 3);
tabsPane.insertTab(getTabTitleForMessage(msg), null, targetScroll, null, 3);
}
}
}
Expand All @@ -1290,6 +1301,23 @@ private void addToTabIfRequired(InstantMessage msg) {
}

}

private String getTabTitleForMessage(InstantMessage m) {
StringBuilder sb=new StringBuilder();
String name=m.getCaseContext().getName();
name=StringUtils.cutoff(name,20);
sb.append("<html><b>").append(m.getCaseContext().getFileNumber()).append("</b><br/>").append(name).append("</html>");
return sb.toString();
}

private String getTooltipForTab(ArchiveFileBean caseContext) {
if(caseContext==null)
return null;
StringBuilder sb=new StringBuilder();
//sb.append("<html><b>").append(caseContext.getFileNumber()).append("</b><br/>").append(caseContext.getName()).append("<br/>").append(caseContext.getReason()).append("</html>");
sb.append(caseContext.getFileNumber()).append(System.lineSeparator()).append(caseContext.getName()).append(System.lineSeparator()).append(caseContext.getReason());
return sb.toString();
}

private void addToMentioningTabsIfRequired(InstantMessage msg) {

Expand Down Expand Up @@ -1349,14 +1377,11 @@ public void newMessageForSubmission(InstantMessage msg) {
JScrollPane sp = (JScrollPane) this.tabsPane.getComponentAt(tabIndex);
JPanel messagesInTab = (JPanel) sp.getViewport().getComponent(0);

for (int i = 0; i < messagesInTab.getComponentCount(); i++) {
if (messagesInTab.getComponent(i) instanceof MessagePanel) {
if (((MessagePanel) messagesInTab.getComponent(i)).getMessage().getCaseContext()!=null) {
msg.setCaseContext(((MessagePanel) messagesInTab.getComponent(i)).getMessage().getCaseContext());
break;
}
}
Object caseContext=sp.getClientProperty(CLIENTPROPERTY_CASECONTEXT);
if(caseContext!=null) {
msg.setCaseContext((ArchiveFileBean)caseContext);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@
import com.jdimension.jlawyer.client.events.EventBroker;
import com.jdimension.jlawyer.client.events.OpenMentionsEvent;
import com.jdimension.jlawyer.client.settings.ClientSettings;
import com.jdimension.jlawyer.client.settings.UserSettings;
import com.jdimension.jlawyer.services.JLawyerServiceLocator;
import org.apache.log4j.Logger;

Expand All @@ -691,7 +692,7 @@ public void run() {
try {
ClientSettings settings = ClientSettings.getInstance();
JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties());
int openMentions = locator.lookupMessagingServiceRemote().getNumberOfOpenMentions();
int openMentions = locator.lookupMessagingServiceRemote().getNumberOfOpenMentions(UserSettings.getInstance().getCurrentUser().getPrincipalId());

EventBroker eb = EventBroker.getInstance();
eb.publishEvent(new OpenMentionsEvent(openMentions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ public class SendInstantMessageDialog extends javax.swing.JDialog implements New
private ArrayList<ArchiveFileDocumentsBean> documentContexts = null;
private ArchiveFileBean caseContext=null;


/**
* Creates new form SendInstantMessageDialog
*
Expand Down Expand Up @@ -846,4 +845,5 @@ public void newMessageForSubmission(InstantMessage msg) {
this.setVisible(false);
this.dispose();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ public static String nonNull(String s) {
s="";
return s;
}

public static String cutoff(String name, int maxLength) {
if(name.length()>maxLength)
name=name.substring(0,maxLength-1) + "...";
return name;
}

static class SortIgnoreCase implements Comparator<Object> {
public int compare(Object o1, Object o2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ public interface MessagingServiceRemote {
InstantMessage getMessage(String id) throws Exception;

int getNumberOfOpenMentions() throws Exception;
int getNumberOfOpenMentions(String principalId) throws Exception;

List<InstantMessageMention> getUpdatedMentionsSince(Date since) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
@NamedQuery(name = "InstantMessageMention.findSince", query = "SELECT a FROM InstantMessageMention a WHERE a.statusChanged > :since order by a.statusChanged asc"),
@NamedQuery(name = "InstantMessageMention.findById", query = "SELECT a FROM InstantMessageMention a WHERE a.id = :id"),
@NamedQuery(name = "InstantMessageMention.findOpen", query = "SELECT a FROM InstantMessageMention a WHERE a.done = 0"),
@NamedQuery(name = "InstantMessageMention.findOpenByPrincipal", query = "SELECT a FROM InstantMessageMention a WHERE a.done = 0 and a.principal = :principal"),
@NamedQuery(name = "InstantMessageMention.findByMessage", query = "SELECT a FROM InstantMessageMention a WHERE a.message = :message")})
public class InstantMessageMention implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@ public List<InstantMessageMention> findOpen() {

}

@Override
public List<InstantMessageMention> findOpen(String principalId) {

return (List<InstantMessageMention>) em.createNamedQuery("InstantMessageMention.findOpenByPrincipal").setParameter("principal", principalId).getResultList();

}

@Override
public List<InstantMessageMention> findSince(Date since) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ public interface InstantMessageMentionFacadeLocal {
List<InstantMessageMention> findRange(int[] range);

List<InstantMessageMention> findOpen();
List<InstantMessageMention> findOpen(String principalId);

int count();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ public List<InstantMessage> getMessagesSince(Date since) throws Exception {
} else {
this.singleton.setLatestInstantMessageReceived(since.getTime());
}
return messages;

return filterForRelevantMessages(messages, this.context.getCallerPrincipal().getName());
} else if(since.getTime()<this.singleton.getLatestInstantMessageReceived()) {
// new message have been received
List<InstantMessage> messages=this.messageFacade.findSince(since);
Expand All @@ -809,11 +810,41 @@ public List<InstantMessage> getMessagesSince(Date since) throws Exception {
} else {
this.singleton.setLatestInstantMessageReceived(since.getTime());
}
return messages;
return filterForRelevantMessages(messages, this.context.getCallerPrincipal().getName());
} else {
return null;
}
}

private List<InstantMessage> filterForRelevantMessages(List<InstantMessage> unfiltered, String principalId) {
ArrayList<InstantMessage> filtered=new ArrayList<>();
for(InstantMessage m: unfiltered) {
if(messageRelevantForUser(m, principalId))
filtered.add(m);
}
return filtered;
}

private boolean messageRelevantForUser(InstantMessage m, String principalId) {
// message sent in a case context
if(m.getCaseContext()!=null)
return true;

// message sent by the user
if(m.getSender()!=null && m.getSender().equals(principalId))
return true;

// user has been mentioned
if(m.getMentionFor(principalId)!=null)
return true;

// no case context, sent to all
if(m.getCaseContext()==null && !m.hasMentions())
return true;

return false;

}

@Override
@RolesAllowed({"loginRole"})
Expand Down Expand Up @@ -862,6 +893,17 @@ public int getNumberOfOpenMentions() throws Exception {
}
return openCount;
}

@Override
@RolesAllowed({"loginRole"})
public int getNumberOfOpenMentions(String principalId) throws Exception {
List<InstantMessageMention> open=this.mentionFacade.findOpen(principalId);
int openCount=0;
if(open!=null) {
openCount=open.size();
}
return openCount;
}

@Override
@RolesAllowed({"loginRole"})
Expand Down

0 comments on commit 0a36469

Please sign in to comment.