Skip to content

Commit

Permalink
added relationship.source.can_dm support
Browse files Browse the repository at this point in the history
  • Loading branch information
takke committed Oct 26, 2013
1 parent fed8697 commit e6db014
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Expand Up @@ -149,6 +149,16 @@ public boolean isTargetFollowedBySource() {
}


/**
* Checks if source user can send dm to target user
*
* @return true if source user can send dm to target user
*/
public boolean canSourceDm() {
return getTarget().canSourceDm();
}


/**
* Checks if the source user has enabled notifications for updates of the target user
*
Expand Down
7 changes: 7 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/Relationship.java
Expand Up @@ -90,6 +90,13 @@ public interface Relationship extends TwitterResponse, java.io.Serializable {
*/
boolean isTargetFollowedBySource();

/**
* Checks if source user can send dm to target user
*
* @return true if source user can send dm to target user
*/
boolean canSourceDm();

/**
* Checks if the source user has enabled notifications for updates of the target user
*
Expand Down
Expand Up @@ -43,6 +43,7 @@
private final boolean sourceNotificationsEnabled;
private final boolean sourceFollowingTarget;
private final boolean sourceFollowedByTarget;
private final boolean sourceCanDm;
private final long sourceUserId;
private final String sourceUserScreenName;
private boolean wantRetweets;
Expand Down Expand Up @@ -72,6 +73,7 @@
sourceBlockingTarget = getBoolean("blocking", sourceJson);
sourceFollowingTarget = getBoolean("following", sourceJson);
sourceFollowedByTarget = getBoolean("followed_by", sourceJson);
sourceCanDm = getBoolean("can_dm", sourceJson);
sourceNotificationsEnabled = getBoolean("notifications_enabled", sourceJson);
wantRetweets = getBoolean("want_retweets", sourceJson);
} catch (JSONException jsone) {
Expand Down Expand Up @@ -180,6 +182,14 @@ public boolean isTargetFollowedBySource() {
return sourceFollowingTarget;
}

/**
* {@inheritDoc}
*/
@Override
public boolean canSourceDm() {
return sourceCanDm;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -221,6 +231,7 @@ public int hashCode() {
result = 31 * result + (sourceNotificationsEnabled ? 1 : 0);
result = 31 * result + (sourceFollowingTarget ? 1 : 0);
result = 31 * result + (sourceFollowedByTarget ? 1 : 0);
result = 31 * result + (sourceCanDm ? 1 : 0);
result = 31 * result + (int) (sourceUserId ^ (sourceUserId >>> 32));
result = 31 * result + (sourceUserScreenName != null ? sourceUserScreenName.hashCode() : 0);
return result;
Expand All @@ -235,6 +246,7 @@ public String toString() {
", targetUserScreenName='" + targetUserScreenName + '\'' +
", sourceFollowingTarget=" + sourceFollowingTarget +
", sourceFollowedByTarget=" + sourceFollowedByTarget +
", sourceCanDm=" + sourceCanDm +
", sourceNotificationsEnabled=" + sourceNotificationsEnabled +
'}';
}
Expand Down
Expand Up @@ -181,6 +181,16 @@ public void testRelationship() throws Exception {
assertFalse(rel1.isSourceFollowingTarget());
assertTrue(rel1.isTargetFollowingSource());
assertFalse(rel1.isTargetFollowedBySource());
assertTrue(rel1.canSourceDm());

// reverse precondition
Relationship rel1r = twitter1.showFriendship(followsOneWay, id1.screenName);
assertNotNull(rel1r);
assertFalse(rel1r.isSourceFollowedByTarget());
assertTrue(rel1r.isSourceFollowingTarget());
assertFalse(rel1r.isTargetFollowingSource());
assertTrue(rel1r.isTargetFollowedBySource());
assertFalse(rel1r.canSourceDm());

// 2) best_friend1 is following and followed by best_friend2
Relationship rel2 = twitter1.showFriendship(bestFriend1.screenName, bestFriend2.screenName);
Expand Down
Expand Up @@ -44,6 +44,7 @@ public static void main(String[] args) {
System.out.println("isSourceFollowedByTarget: " + relationship.isSourceFollowedByTarget());
System.out.println("isSourceFollowingByTarget: " + relationship.isSourceFollowingTarget());
System.out.println("isSourceNotificationsEnabled: " + relationship.isSourceNotificationsEnabled());
System.out.println("canSourceDm: " + relationship.canSourceDm());
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
Expand Down

0 comments on commit e6db014

Please sign in to comment.