Skip to content

Commit

Permalink
Fix bug not noti when user create recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
duyetpt committed Nov 29, 2015
1 parent fd3cd30 commit 40b4699
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public void run() {
try {
Notification noti = NotificationActionImp.getInstance().getNoti();
// increate notification number
CompactUserInfo toUser = UserCache.getInstance().get(noti.getTo());
toUser.increaseNumberNotificaion();
UserDAO.getInstance().increateNotificationNumber(toUser.getUserId());
if (noti.getTo() != null) {
CompactUserInfo toUser = UserCache.getInstance().get(noti.getTo());
toUser.increaseNumberNotificaion();
UserDAO.getInstance().increateNotificationNumber(toUser.getUserId());
}

List<Notification> list = null;
switch (noti.getType()) {
Expand Down Expand Up @@ -63,28 +65,31 @@ public void run() {
}
}

private List<Notification> notiNewRecipe(Notification noti) {
private List<Notification> notiNewRecipe(Notification noti) throws DAOException {
CompactUserInfo user = null;
Following follow = null;
try {
user = UserCache.getInstance().get(noti.getFrom());
follow = FollowingDAO.getInstance().get(noti.getFrom(), Following.class);
} catch (DAOException e) {
logger.error("process notiNewRecipe error", e);
Following follow = FollowingDAO.getInstance().get(noti.getFrom(), Following.class);
user = UserCache.getInstance().get(noti.getFrom());

List<Notification> notis = new ArrayList<Notification>();
if (follow == null || follow.getFollowers() == null) {
return notis;
}

List<Notification> notis = new ArrayList<Notification>();
for (String follower : follow.getFollowers()) {
Notification notiComp = new Notification();
notiComp.setFrom(noti.getFrom());
notiComp.setTo(follower);
notiComp.setRecipeId(noti.getRecipeId());
notiComp.setType(Notification.NEW_RECIPE_FROM_FOLLOWING_TYPE);
notiComp.setFromAvatar(user.getAvatarUrl());
notiComp.setFromName(user.getDisplayName());
notiComp.setRecipeTitle(noti.getRecipeTitle());

notis.add(noti);
notis.add(notiComp);

// increate noti number
CompactUserInfo toUser = UserCache.getInstance().get(follower);
toUser.increaseNumberNotificaion();
UserDAO.getInstance().increateNotificationNumber(follower);
}

return notis;
Expand Down Expand Up @@ -156,9 +161,9 @@ private List<Notification> notiFollower(Notification notification) {
notis.add(noti);
return notis;
}

private List<Notification> notiRemoveRecipe(Notification notification) {

Notification noti = new Notification();
noti.setFrom(notification.getFrom());
noti.setTo(notification.getTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
import com.vn.dailycookapp.utils.ConfigurationLoader;
import com.vn.dailycookapp.utils.lang.Language;
import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.List;
import org.dao.DAOException;
import org.dao.DeviceTokenDAO;
Expand Down

0 comments on commit 40b4699

Please sign in to comment.