Skip to content

Commit 0eabde7

Browse files
committed
fixes #139: refactoring: repurposing 'with' in MUC context
When processing an archived message in MAM context, using the 'with' attribute (that would otherwise go unused) to reflect the nickname of the sender of the message allows us to avoid unneeded stanza parsing.
1 parent d01f621 commit 0eabde7

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/java/com/reucon/openfire/plugin/archive/impl/MucMamPersistenceManager.java

+8-16
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,13 @@ public static ArchivedMessage getArchivedMessage( long messageId, MUCRoom room )
226226
}
227227

228228
static protected ArchivedMessage asArchivedMessage(JID roomJID, String senderJID, String nickname, Date sentDate, String subject, String body, String stanza, long id) throws DocumentException {
229-
if (stanza == null) {
230-
Message message = new Message();
231-
message.setType(Message.Type.groupchat);
232-
message.setSubject(subject);
233-
message.setBody(body);
234-
// Set the sender of the message
235-
if (nickname != null && nickname.trim().length() > 0) {
236-
// Recreate the sender address based on the nickname and room's JID
237-
message.setFrom(new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true));
238-
}
239-
else {
240-
// Set the room as the sender of the message
241-
message.setFrom(roomJID);
242-
}
243-
stanza = message.toString();
229+
final JID with;
230+
if (nickname != null && nickname.trim().length() > 0) {
231+
// Recreate the sender address based on the nickname and room's JID
232+
with = new JID(roomJID.getNode(), roomJID.getDomain(), nickname, true);
233+
}
234+
else {
235+
with = roomJID;
244236
}
245237

246238
String sid;
@@ -257,7 +249,7 @@ static protected ArchivedMessage asArchivedMessage(JID roomJID, String senderJID
257249
sid = null;
258250
}
259251

260-
final ArchivedMessage archivedMessage = new ArchivedMessage(id, sentDate, ArchivedMessage.Direction.from, null, sid, body, stanza);
252+
final ArchivedMessage archivedMessage = new ArchivedMessage(id, sentDate, ArchivedMessage.Direction.from, with, sid, body, stanza);
261253
return archivedMessage;
262254
}
263255

src/java/com/reucon/openfire/plugin/archive/model/ArchivedMessage.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static Direction getDirection(@Nonnull final JID owner, @Nonnull final JI
6363
@Nullable
6464
private final String body;
6565

66-
@Nullable
66+
@Nonnull
6767
private final JID with;
6868

6969
@Nullable
@@ -72,7 +72,7 @@ public static Direction getDirection(@Nonnull final JID owner, @Nonnull final JI
7272
@Nullable
7373
private final String stableId;
7474

75-
public ArchivedMessage(@Nullable final Long id, @Nonnull final Date time, @Nonnull final Direction direction, @Nullable final JID with, @Nullable final String stableId, @Nullable final String body, @Nullable final String stanza) throws DocumentException {
75+
public ArchivedMessage(@Nullable final Long id, @Nonnull final Date time, @Nonnull final Direction direction, @Nonnull final JID with, @Nullable final String stableId, @Nullable final String body, @Nullable final String stanza) throws DocumentException {
7676
this.id = id;
7777
this.time = time;
7878
this.direction = direction;
@@ -154,12 +154,12 @@ public Message getStanza() {
154154
* The message peer (the 'other side' of the conversation), in respect to the owner of the archive that this message
155155
* is part of.
156156
*
157-
* This value will only have meaning when the original message was sent in a one-to-one conversation. When the
158-
* archived message was originally shared in a group chat, this value can be null.
157+
* When the archived message was originally shared in a group chat, this value will reference the in-room address
158+
* of the participant that sent the message (eg: room@service/nickname).
159159
*
160160
* @return The conversation peer.
161161
*/
162-
@Nullable
162+
@Nonnull
163163
public JID getWith() {
164164
return with;
165165
}
@@ -224,8 +224,8 @@ public static Message recreateStanza( @Nonnull final ArchivedMessage archivedMes
224224
from = archivedMessage.getWith();
225225
}
226226

227-
final boolean isMuc = (to != null && XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService( to ) != null)
228-
|| (from != null && XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService( from ) != null);
227+
final boolean isMuc = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService( to ) != null
228+
|| XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService( from ) != null;
229229

230230
final Message result = new Message();
231231
result.setFrom(from);

src/java/com/reucon/openfire/plugin/archive/xep0136/IQRetrieveHandler.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ private Element addMessageElement(Element parentElement,
122122
messageElement = parentElement.addElement(message.getDirection()
123123
.toString());
124124
messageElement.addAttribute("secs", Long.toString(secs));
125-
if (message.getWith() != null) {
126-
messageElement.addAttribute("jid", message.getWith().toBareJID());
127-
}
125+
messageElement.addAttribute("jid", message.getWith().toBareJID());
128126
messageElement.addElement("body").setText(message.getBody());
129127

130128
return messageElement;

0 commit comments

Comments
 (0)