Skip to content

Commit 9ff80b9

Browse files
committed
fixes #139: Refactor: centralize logic to determine 'direction'
The concept of 'direction' of an ArchivedMessage is, to some, counter-intuitive. The mechanism that determines the direction of a particular stanza should be centralized to reduce confusion.
1 parent 52ba880 commit 9ff80b9

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

+3-11
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,9 @@ static protected ArchivedMessage asArchivedMessage(JID owner, String fromJID, St
626626
final JID from = new JID(fromJID + ( fromJIDResource == null || fromJIDResource.isEmpty() ? "" : "/" + fromJIDResource ));
627627
final JID to = new JID(toJID + ( toJIDResource == null || toJIDResource.isEmpty() ? "" : "/" + toJIDResource ));
628628

629-
final ArchivedMessage.Direction direction;
630-
final JID with;
631-
if (owner.asBareJID().equals(to.asBareJID())) {
632-
direction = Direction.from;
633-
with = from;
634-
} else {
635-
direction = Direction.to;
636-
with = to;
637-
}
638-
final ArchivedMessage archivedMessage = new ArchivedMessage(id, sentDate, direction, with, sid, body, stanza);
639-
return archivedMessage;
629+
final ArchivedMessage.Direction direction = ArchivedMessage.Direction.getDirection(owner, to);
630+
final JID with = direction == Direction.from ? from : to;
631+
return new ArchivedMessage(id, sentDate, direction, with, sid, body, stanza);
640632
}
641633

642634
private static Long dateToMillis(Date date) {

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ public enum Direction {
3232
/**
3333
* A message received by the owner.
3434
*/
35-
from
35+
from;
36+
37+
/**
38+
* Returns a direction instance for a particular stanza, based on the owner of the archive that the stanza is
39+
* in, and the addressee ('to') of the stanza.
40+
*
41+
* @param owner The owner of the archive that a message is in.
42+
* @param addressee The addressee of the stanza.
43+
* @return The direction of the stanza.
44+
*/
45+
public static Direction getDirection(@Nonnull final JID owner, @Nonnull final JID addressee) {
46+
if (owner.asBareJID().equals(addressee.asBareJID())) {
47+
return Direction.from;
48+
} else {
49+
return Direction.to;
50+
}
51+
}
3652
}
3753

3854
@Nullable

0 commit comments

Comments
 (0)