Skip to content

Commit 05bb1f5

Browse files
committed
fixes igniterealtime#139: refactoring: reduce complexity by making ArchivedMessage (almost) immutable
No functional changes intended.
1 parent b674247 commit 05bb1f5

File tree

4 files changed

+16
-48
lines changed

4 files changed

+16
-48
lines changed

src/java/com/reucon/openfire/plugin/archive/ArchiveFactory.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public static ArchivedMessage createArchivedMessage(Session session,
2222
final String sid = StanzaIDUtil.findFirstUniqueAndStableStanzaID( message, owner.toBareJID() );
2323
final ArchivedMessage archivedMessage;
2424

25-
archivedMessage = new ArchivedMessage(new Date(), direction, message.getType().toString(), with, sid);
26-
archivedMessage.setSubject(message.getSubject());
27-
archivedMessage.setBody(message.getBody());
25+
// Use a 'null' value for the numeric database ID, as the resulting object has not yet been stored in the database.
26+
final Long id = null;
27+
28+
archivedMessage = new ArchivedMessage(id, new Date(), direction, message.getType().toString(), with, sid, message.getBody(), message.toXML());
2829

2930
return archivedMessage;
3031
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,7 @@ static protected ArchivedMessage asArchivedMessage(JID owner, String fromJID, St
880880
direction = Direction.to;
881881
with = to;
882882
}
883-
final ArchivedMessage archivedMessage = new ArchivedMessage(sentDate, direction, type == null ? null : type.toString(), with, sid);
884-
archivedMessage.setStanza(stanza);
885-
archivedMessage.setBody(body);
886-
archivedMessage.setId(id);
883+
final ArchivedMessage archivedMessage = new ArchivedMessage(id, sentDate, direction, type == null ? null : type.toString(), with, sid, body, stanza);
887884
return archivedMessage;
888885
}
889886

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ static protected ArchivedMessage asArchivedMessage(JID roomJID, String senderJID
297297
sid = null;
298298
}
299299

300-
final ArchivedMessage archivedMessage = new ArchivedMessage(sentDate, ArchivedMessage.Direction.from, null, null, sid);
301-
archivedMessage.setStanza(stanza);
302-
archivedMessage.setId(id);
300+
final ArchivedMessage archivedMessage = new ArchivedMessage(id, sentDate, ArchivedMessage.Direction.from, null, null, sid, body, stanza);
303301
return archivedMessage;
304302
}
305303

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

+10-38
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,31 @@ public enum Direction {
2323
from
2424
}
2525

26-
private Long id;
26+
private final Long id;
2727
private final Date time;
2828
private final Direction direction;
2929
private final String type;
30-
private String subject;
31-
private String body;
30+
private final String body;
3231
private Conversation conversation;
33-
private JID with;
34-
private String stanza;
35-
private String stableId;
32+
private final JID with;
33+
private final String stanza;
34+
private final String stableId;
3635

37-
public ArchivedMessage( Date time, Direction direction, String type, JID with, String stableId ) {
36+
public ArchivedMessage( Long id, Date time, Direction direction, String type, JID with, String stableId, String body, String stanza) {
37+
this.id = id;
3838
this.time = time;
3939
this.direction = direction;
4040
this.type = type;
4141
this.with = with;
4242
this.stableId = stableId;
43+
this.body = body;
44+
this.stanza = stanza;
4345
}
4446

4547
public Long getId() {
4648
return id;
4749
}
4850

49-
public void setId(Long id) {
50-
this.id = id;
51-
}
52-
5351
public Date getTime() {
5452
return time;
5553
}
@@ -62,30 +60,14 @@ public String getType() {
6260
return type;
6361
}
6462

65-
public String getSubject() {
66-
return subject;
67-
}
68-
69-
public void setSubject(String subject) {
70-
this.subject = subject;
71-
}
72-
7363
public String getBody() {
7464
return body;
7565
}
7666

77-
public void setBody(String body) {
78-
this.body = body;
79-
}
80-
8167
public String getStanza() {
8268
return stanza;
8369
}
8470

85-
public void setStanza(String stanza) {
86-
this.stanza = stanza;
87-
}
88-
8971
public Conversation getConversation() {
9072
return conversation;
9173
}
@@ -101,7 +83,7 @@ public void setConversation(Conversation conversation) {
10183
* otherwise.
10284
*/
10385
public boolean isEmpty() {
104-
return subject == null && body == null;
86+
return body == null;
10587
}
10688

10789
public JID getWith() {
@@ -113,16 +95,6 @@ public String getStableId()
11395
return stableId;
11496
}
11597

116-
public void setStableId( final UUID stableId )
117-
{
118-
this.stableId = stableId.toString();
119-
}
120-
121-
public void setStableId( final String stableId )
122-
{
123-
this.stableId = stableId;
124-
}
125-
12698
public String toString() {
12799
StringBuilder sb = new StringBuilder();
128100

0 commit comments

Comments
 (0)