Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 11, 2013
1 parent ffe870b commit cbb64d2
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 48 deletions.
1 change: 1 addition & 0 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Without this configuration present, some functionality in the IDE may be limited
<word>markdowns</word>
<word>permalink</word>
<word>servlet</word>
<word>Unfollows</word>
<word>whitelist</word>
</spellchecker-wordlist>
</project-shared-configuration>
51 changes: 40 additions & 11 deletions src/main/java/org/b3log/symphony/event/ArticleNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
*/
package org.b3log.symphony.event;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import org.b3log.latke.Keys;
import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventException;
import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User;
import org.b3log.latke.urlfetch.URLFetchService;
import org.b3log.latke.urlfetch.URLFetchServiceFactory;
import org.b3log.symphony.model.Article;
import org.b3log.symphony.model.Follow;
import org.b3log.symphony.model.Notification;
import org.b3log.symphony.service.FollowQueryService;
import org.b3log.symphony.service.NotificationMgmtService;
import org.b3log.symphony.service.UserQueryService;
import org.json.JSONObject;
Expand All @@ -39,7 +41,7 @@
* Sends an article notification to the user who be &#64;username in the article content.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Sep 6, 2013
* @version 1.0.0.4, Nov 11, 2013
* @since 0.2.0
*/
@Named
Expand All @@ -61,15 +63,23 @@ public class ArticleNotifier extends AbstractEventListener<JSONObject> {
@Inject
private NotificationMgmtService notificationMgmtService;

/**
* Follow query service.
*/
@Inject
private FollowQueryService followQueryService;

/**
* User query service.
*/
@Inject
private UserQueryService userQueryService;

@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject data = event.getData();
LOGGER.log(Level.DEBUG, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), data, ArticleNotifier.class.getName()});


final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final UserQueryService userQueryService = beanManager.getReference(UserQueryService.class);
new Object[]{event.getType(), data, ArticleNotifier.class.getName()});

try {
final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE);
Expand All @@ -86,6 +96,8 @@ public void action(final Event<JSONObject> event) throws EventException {
return;
}

final Set<String> atedUserIds = new HashSet<String>();

// 'At' Notification
for (final String userName : atUserNames) {
final JSONObject user = userQueryService.getUserByName(userName);
Expand All @@ -97,12 +109,30 @@ public void action(final Event<JSONObject> event) throws EventException {
}

final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Notification.NOTIFICATION_USER_ID, user.optString(Keys.OBJECT_ID));
final String atedUserId = user.optString(Keys.OBJECT_ID);
requestJSONObject.put(Notification.NOTIFICATION_USER_ID, atedUserId);
requestJSONObject.put(Notification.NOTIFICATION_DATA_ID, originalArticle.optString(Keys.OBJECT_ID));

notificationMgmtService.addAtNotification(requestJSONObject);

atedUserIds.add(atedUserId);
}

// 'Article' Notification
final List<JSONObject> followerUsers = followQueryService.getFollowerUsers(articleAuthorId, 1, Integer.MAX_VALUE);
for (final JSONObject followerUser : followerUsers) {
final JSONObject requestJSONObject = new JSONObject();
final String followerUserId = followerUser.optString(Follow.FOLLOWER_ID);

if (atedUserIds.contains(followerUserId)) {
continue;
}

requestJSONObject.put(Notification.NOTIFICATION_USER_ID, followerUserId);
requestJSONObject.put(Notification.NOTIFICATION_DATA_ID, originalArticle.optString(Keys.OBJECT_ID));

notificationMgmtService.addFollowingUserNotification(requestJSONObject);
}

// final Set<String> qqSet = new HashSet<String>();
// for (final String userName : atUserNames) {
Expand All @@ -116,7 +146,6 @@ public void action(final Event<JSONObject> event) throws EventException {
// if (qqSet.isEmpty()) {
// return;
// }

// /*
// * {
// * "key": "",
Expand Down Expand Up @@ -153,7 +182,7 @@ public void action(final Event<JSONObject> event) throws EventException {

/**
* Gets the event type {@linkplain EventTypes#ADD_ARTICLE}.
*
*
* @return event type
*/
@Override
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/b3log/symphony/model/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* This class defines all common model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.8, Oct 11, 2013
* @version 1.0.1.9, Nov 11, 2013
* @since 0.2.0
*/
public final class Common {
Expand Down Expand Up @@ -103,6 +103,11 @@ public final class Common {
* Key of latest comment articles.
*/
public static final String LATEST_CMT_ARTICLES = "latestCmtArticles";

/**
* Key of user id.
*/
public static final String USER_ID = "userId";

/**
* Key of user home articles.
Expand Down Expand Up @@ -134,6 +139,16 @@ public final class Common {
*/
public static final String UNREAD_AT_NOTIFICATION_CNT = "unreadAtNotificationCnt";

/**
* Key of 'followingUser' notifications.
*/
public static final String FOLLOWING_USER_NOTIFICATIONS = "followingUserNotifications";

/**
* Key of unread 'followingUser' notifications count.
*/
public static final String UNREAD_FOLLOWING_USER_NOTIFICATION_CNT = "unreadFollowingUserNotificationCnt";

/**
* Key of author name.
*/
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/b3log/symphony/model/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* This class defines all notification model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Sep 2, 2013
* @version 1.0.0.2, Nov 11, 2013
* @since 0.2.5
*/
public final class Notification {
Expand Down Expand Up @@ -74,7 +74,12 @@ public final class Notification {
* Data type - commented.
*/
public static final int DATA_TYPE_C_COMMENTED = 3;


/**
* Data type - followingUser.
*/
public static final int DATA_TYPE_C_FOLLOWING_USER = 4;

//// Transient ////
/**
* Key of unread notification count.
Expand Down
Loading

0 comments on commit cbb64d2

Please sign in to comment.