Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more work on the user-filter support for UserStreams

  • Loading branch information...
commit 61736f6f6760a691d3317887f535399465ee8f78 1 parent da84a98
@mindcrime mindcrime authored
View
64 grails-app/controllers/org/fogbeam/quoddy/UserStreamController.groovy
@@ -56,7 +56,7 @@ class UserStreamController
createWizardOne {
on("stage2") {
- println "transitioning to stage2";
+ println "stage2";
UserStream streamToCreate = new UserStream();
streamToCreate.name = params.streamName;
@@ -76,7 +76,7 @@ class UserStreamController
createWizardTwo {
on("stage3"){
- println "finishing Wizard";
+ println "stage3";
println "params: ${params}";
UserStream streamToCreate = flow.streamToCreate;
// eventTypes:[219, 218]
@@ -91,11 +91,13 @@ class UserStreamController
}
/* load user list */
- List<User> allusers = userService.findAllUsers();
+ // List<User> allusers = userService.findAllUsers();
+ println "getting eligible users: ";
+ List<User> eligibleUsers = userService.findEligibleUsersForUser( session.user );
+ println "Found ${eligibleUsers.size()} users\n";
- println "Found ${allusers.size()} users\n";
-
- [users:allusers, selectedUsers:streamToCreate.userUuidsIncluded];
+ println ("returning eligible users:");
+ [users:eligibleUsers, selectedUsers:streamToCreate.userUuidsIncluded];
}.to("createWizardThree")
}
@@ -106,21 +108,41 @@ class UserStreamController
println "params: ${params}";
UserStream streamToCreate = flow.streamToCreate;
- // save users
- String[] userUuids = request.getParameterValues( 'users' );
- streamToCreate.userUuidsIncluded?.clear();
+ String userFilter = params.userFilter;
- for( String userUuid : userUuids )
+ if( userFilter.equals( "all_users" ))
{
- User userToInclude = userService.findUserByUuid( userUuid );
- if( userToInclude == null ) {
- println "Failed to locate User for uuid ${userUuid}";
- continue;
- }
+ streamToCreate.includeAllUsers = true;
- streamToCreate.addToUserUuidsIncluded( userUuid );
}
-
+ else if( userFilter.equals( "no_users" ))
+ {
+ streamToCreate.includeSelfOnly = true;
+
+ }
+ else if( userFilter.equals( "select_list" ))
+ {
+ // save users
+ String[] userUuids = request.getParameterValues( 'users' );
+ streamToCreate.userUuidsIncluded?.clear();
+
+ for( String userUuid : userUuids )
+ {
+ User userToInclude = userService.findUserByUuid( userUuid );
+ if( userToInclude == null ) {
+ println "Failed to locate User for uuid ${userUuid}";
+ continue;
+ }
+
+ streamToCreate.addToUserUuidsIncluded( userUuid );
+ }
+
+ }
+ else
+ {
+ // this isn't supposed to happen
+ }
+
/* load userList list */
List<UserList> userLists = userListService.getListsForUser( session.user );
@@ -303,11 +325,13 @@ class UserStreamController
}
/* load user list */
- List<User> allusers = userService.findAllUsers();
+ // List<User> allusers = userService.findAllUsers();
+ List<User> eligibleUsers = userService.findEligibleUsersForUser( session.user );
- println "Found ${allusers.size()} users\n";
+ println "Found ${eligibleUsers.size()} users\n";
- [users:allusers, selectedUsers:streamToEdit.userUuidsIncluded];
+ [users:allusers, eligibleUsers:streamToEdit.userUuidsIncluded];
+
}.to("editWizardThree")
}
View
2  grails-app/domain/org/fogbeam/quoddy/FriendCollection.groovy
@@ -1,6 +1,6 @@
package org.fogbeam.quoddy
-class FriendCollection
+class FriendCollection implements Serializable
{
String ownerUuid;
Date dateCreated;
View
2  grails-app/domain/org/fogbeam/quoddy/IFollowCollection.groovy
@@ -1,6 +1,6 @@
package org.fogbeam.quoddy;
-public class IFollowCollection
+public class IFollowCollection implements Serializable
{
String ownerUuid;
Date dateCreated;
View
26 grails-app/domain/org/fogbeam/quoddy/UserStream.groovy
@@ -38,26 +38,24 @@ class UserStream implements Serializable
// include:
- // users
- Boolean includeAllUsers = true;
- // Set<String> userUuidsIncluded = new HashSet<String>();
+ // users
+ Boolean includeSelfOnly = false;
+ Boolean includeAllUsers = false;
- // user lists
- Boolean includeAllLists = true;
- // Set<String> userListUuidsIncluded = new HashSet<String>();
+ // user lists
+ Boolean includeAllLists = false;
- // groups
- Boolean includeAllGroups = true;
- // Set<String> userGroupUuidsIncluded = new HashSet<String>();
+ // groups
+ Boolean includeAllGroups = false;
+
- // subscriptions
- Boolean includeAllSubscriptions = true;
- // Set<String> subscriptionUuidsIncluded = new HashSet<String>();
+ // subscriptions
+ Boolean includeAllSubscriptions = false;
- // event types
+ // event types
Boolean includeAllEventTypes = false;
- // Set<String> eventTypesIncluded = new HashSet<String>();
+
// exclude (filters)
View
16 grails-app/services/org/fogbeam/quoddy/EventStreamService.groovy
@@ -37,7 +37,7 @@ class EventStreamService {
// working that way, we can revisit what to do about queued messages.
Calendar cal = Calendar.getInstance();
- cal.add(Calendar.HOUR_OF_DAY, -600 );
+ cal.add(Calendar.HOUR_OF_DAY, -2160 );
Date cutoffDate = cal.getTime();
List<EventBase> recentEvents = new ArrayList<EventBase>();
@@ -60,7 +60,7 @@ class EventStreamService {
println "query now: ${query}";
- if( !userStream.includeAllUsers )
+ if( !userStream.includeAllUsers && !userStream.includeSelfOnly )
{
println "filtering by user";
query = query + ", stream ";
@@ -73,7 +73,7 @@ class EventStreamService {
println "query now: ${query}";
- if( !userStream.includeAllUsers )
+ if( !userStream.includeAllUsers && !userStream.includeSelfOnly )
{
println "filtering by user";
query = query + ", UserStream as stream ";
@@ -132,6 +132,14 @@ class EventStreamService {
{
// nothing to do, default query will return hits from all eligible users
}
+ else if( userStream.includeSelfOnly )
+ {
+ // left alone, the existing default query would return posts from any
+ // user in the friends list. We should rework the entire base query
+ // but - for now - we can cheat and just add an extra and clause to
+ // filter down to the user id of our user
+ query = query + " and event.owner = :owner";
+ }
else
{
query = query + " and event.owner.uuid in elements( stream.userUuidsIncluded ) and stream.id = :streamId ) ";
@@ -165,7 +173,7 @@ class EventStreamService {
'friendIds':friendIds,
'targetUuid':streamPublic.uuid, 'owner': user]
- if( !userStream.includeAllUsers )
+ if( !userStream.includeAllUsers && !userStream.includeSelfOnly )
{
parameters << ['streamId':userStream.id]
}
View
5 grails-app/services/org/fogbeam/quoddy/LocalFriendService.groovy
@@ -72,6 +72,7 @@ class LocalFriendService
friends.add( friend );
}
+ friendsCollection = null;
println "returning friends: ${friends}";
return friends;
}
@@ -92,6 +93,7 @@ class LocalFriendService
User follower = User.findByUuid( collection.ownerUuid );
followers.add( follower );
}
+ iFollowCollections = null;
return followers;
}
@@ -109,7 +111,8 @@ class LocalFriendService
User iFollow = User.findByUuid( iFollowUuid );
peopleIFollow.add( iFollow );
}
-
+
+ iFollowCollection = null;
return peopleIFollow;
}
View
26 grails-app/services/org/fogbeam/quoddy/UserService.groovy
@@ -52,6 +52,7 @@ class UserService {
defaultStream.definedBy = UserStream.DEFINED_SYSTEM;
defaultStream.owner = user;
defaultStream.includeAllEventTypes = true;
+ defaultStream.includeAllUsers = true;
if( !defaultStream.save())
@@ -124,6 +125,31 @@ class UserService {
return users;
}
+ public List<User> findEligibleUsersForUser( final User user )
+ {
+ List<User> eligibleUsers = new ArrayList<User>();
+ Set<User> tempUsers = new TreeSet<User>();
+
+ List<User> friends = friendService.listFriends( user );
+ List<User> iFollow = friendService.listIFollow( user );
+
+ tempUsers.addAll( friends );
+ tempUsers.addAll( iFollow );
+
+ friends.clear();
+ friends = null;
+ iFollow.clear();
+ iFollow = null;
+
+ eligibleUsers.addAll( tempUsers );
+
+ tempUsers.clear();
+ tempUsers = null;
+
+ println "returning eligibleUsers from findEligibleUsersForUser";
+ return eligibleUsers;
+ }
+
public List<User> listFriends( User user )
{
List<User> friends = new ArrayList<User>();
View
19 grails-app/views/userStream/create.gsp
@@ -1,19 +0,0 @@
-<html>
-
- <head>
- <title>Quoddy: Create STREAM</title>
- <meta name="layout" content="main" />
- <nav:resources />
- </head>
-
- <body>
-
- <h3>Create STREAM</h3>
- <p />
- <g:form controller="userStream" action="save" method="POST">
- <label for="streamName">Name:</label> <g:textField name="streamName" value=""/>
- <br />
- <g:submitButton name="Create" />
- </g:form>
- </body>
-</html>
View
18 grails-app/views/userStream/createWizard/createWizardThree.gsp
@@ -4,17 +4,33 @@
<title>Quoddy: Edit User Stream</title>
<meta name="layout" content="main" />
<nav:resources />
+ <style type="text/css">
+ #userFilterSelections li {
+ list-style-type:none;
+ }
+ </style>
</head>
<body>
<div class="hero-unit span6">
<h2>Select users to include in this stream.</h2>
<g:form controller="userStream" action="createWizard" method="POST">
+ <ul id="userFilterSelections">
+ <li>
+ <g:radio name="userFilter" value="no_users" checked="true" />&nbsp;Include Nobody (self posts only)
+ </li>
+ <li>
+ <g:radio name="userFilter" value="all_users" checked="true" />&nbsp;Include Everbody (friends & people I follow)
+ </li>
+ <li>
+ <g:radio name="userFilter" value="select_list" checked="true" />&nbsp;Included only selected users
+ </li>
+ </ul>
<g:select optionKey="uuid" optionValue="fullName"
name="users"
from="${users}"
value="${selectedUsers}"
- multiple="true" />
+ multiple="true" />
<g:submitButton name="stage4" value="Next" class="btn" />
</g:form>
</div>
View
20 grails-app/views/userStream/edit.gsp
@@ -1,20 +0,0 @@
-<html>
-
- <head>
- <title>Quoddy: Edit STREAM</title>
- <meta name="layout" content="main" />
- <nav:resources />
- </head>
-
- <body>
-
- <h3>Edit STREAM</h3>
- <p />
- <g:form controller="userStream" action="update" method="POST">
- <g:hiddenField name="streamId" value="${streamToEdit.id}" />
- <label for="streamName">Name:</label> <g:textField name="streamName" value="${streamToEdit.name}"/>
- <br />
- <g:submitButton name="Save" />
- </g:form>
- </body>
-</html>
Please sign in to comment.
Something went wrong with that request. Please try again.