示例#1
0
 @Override
 public void setMessagesReadden(String userId, String tagId, UserTags tags) {
   Query<UnreaddenMessage> q =
       ds.createQuery(UnreaddenMessage.class).field("userId").equal(userId);
   if (!tagId.equals(UserTags.ALL_TAGS)) {
     SocioTag tag = tags.getTag(tagId);
     List<String> tagsIds = new ArrayList<String>();
     List<SocioTag> leaves = tag.getLeaves();
     for (SocioTag leaf : leaves) {
       tagsIds.add(leaf.getUniqueId());
     }
     q.field("tagId").hasAnyOf(tagsIds);
   }
   List<UnreaddenMessage> unreadMessages = q.asList();
   List<GeneralMessage> messages = new ArrayList<GeneralMessage>();
   List<ReaddenMessage> readdenMessages = new ArrayList<ReaddenMessage>();
   for (UnreaddenMessage unreaddenMessage : unreadMessages) {
     GeneralMessage message = unreaddenMessage.getMessage();
     messages.add(message);
     ReaddenMessage readdenMessage = new ReaddenMessage();
     readdenMessage.setUserId(userId);
     readdenMessage.setMessageUniqueId(message.getUniqueFieldValue().toString());
     readdenMessages.add(readdenMessage);
   }
   ds.save(readdenMessages);
   ds.delete(q);
   for (GeneralMessage message : messages) {
     // TODO Next lines are just to save space in unpaid mongoDB on CloudBees
     Query<UnreaddenMessage> isMore =
         ds.createQuery(UnreaddenMessage.class).field("message").equal(message);
     if (isMore.countAll() <= 0) {
       ds.delete(message);
     }
   }
 }
示例#2
0
 @Override
 public void setMessageReadden(String userId, String messageId) {
   Query<UnreaddenMessage> q =
       ds.createQuery(UnreaddenMessage.class)
           .field("message")
           .equal(new Key<GeneralMessage>(GeneralMessage.class, new ObjectId(messageId)))
           .field("userId")
           .equal(userId);
   ds.delete(q);
   ReaddenMessage readdenMessage = new ReaddenMessage();
   readdenMessage.setUserId(userId);
   readdenMessage.setMessageUniqueId(
       ds.get(GeneralMessage.class, new ObjectId(messageId)).getUniqueFieldValue().toString());
   ds.save(readdenMessage);
   // TODO Next lines are just to save space in unpaid mongoDB on CloudBees
   Query<UnreaddenMessage> isMore =
       ds.createQuery(UnreaddenMessage.class)
           .field("message")
           .equal(new Key<GeneralMessage>(GeneralMessage.class, new ObjectId(messageId)));
   if (isMore.countAll() <= 0) {
     ds.delete(GeneralMessage.class, new ObjectId(messageId));
   }
 }