|  | @@ -854,62 +854,65 @@ class ContentApi(object):
 | 
	
		
			
			| 854 | 854 |  
 | 
	
		
			
			| 855 | 855 |          return active_contents
 | 
	
		
			
			| 856 | 856 |  
 | 
	
		
			
			| 857 |  | -    def get_last_unread(self, parent_id: typing.Optional[int], content_type: str,
 | 
	
		
			
			| 858 |  | -                        workspace: Workspace=None, limit=10) -> typing.List[Content]:
 | 
	
		
			
			| 859 |  | -        assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
 | 
	
		
			
			| 860 |  | -        assert content_type is not None# DYN_REMOVE
 | 
	
		
			
			| 861 |  | -        assert isinstance(content_type, str) # DYN_REMOVE
 | 
	
		
			
			| 862 |  | -
 | 
	
		
			
			| 863 |  | -        read_revision_ids = self._session.query(RevisionReadStatus.revision_id) \
 | 
	
		
			
			| 864 |  | -            .filter(RevisionReadStatus.user_id==self._user_id)
 | 
	
		
			
			| 865 |  | -
 | 
	
		
			
			| 866 |  | -        not_read_revisions = self._revisions_base_query(workspace) \
 | 
	
		
			
			| 867 |  | -            .filter(~ContentRevisionRO.revision_id.in_(read_revision_ids)) \
 | 
	
		
			
			| 868 |  | -            .filter(ContentRevisionRO.workspace_id == Workspace.workspace_id) \
 | 
	
		
			
			| 869 |  | -            .filter(Workspace.is_deleted.is_(False)) \
 | 
	
		
			
			| 870 |  | -            .subquery()
 | 
	
		
			
			| 871 |  | -
 | 
	
		
			
			| 872 |  | -        not_read_content_ids_query = self._session.query(
 | 
	
		
			
			| 873 |  | -            distinct(not_read_revisions.c.content_id)
 | 
	
		
			
			| 874 |  | -        )
 | 
	
		
			
			| 875 |  | -        not_read_content_ids = list(map(
 | 
	
		
			
			| 876 |  | -            itemgetter(0),
 | 
	
		
			
			| 877 |  | -            not_read_content_ids_query,
 | 
	
		
			
			| 878 |  | -        ))
 | 
	
		
			
			| 879 |  | -
 | 
	
		
			
			| 880 |  | -        not_read_contents = self._base_query(workspace) \
 | 
	
		
			
			| 881 |  | -            .filter(Content.content_id.in_(not_read_content_ids)) \
 | 
	
		
			
			| 882 |  | -            .order_by(desc(Content.updated))
 | 
	
		
			
			| 883 |  | -
 | 
	
		
			
			| 884 |  | -        if content_type != ContentType.Any:
 | 
	
		
			
			| 885 |  | -            not_read_contents = not_read_contents.filter(
 | 
	
		
			
			| 886 |  | -                Content.type==content_type)
 | 
	
		
			
			| 887 |  | -        else:
 | 
	
		
			
			| 888 |  | -            not_read_contents = not_read_contents.filter(
 | 
	
		
			
			| 889 |  | -                Content.type!=ContentType.Folder)
 | 
	
		
			
			| 890 |  | -
 | 
	
		
			
			| 891 |  | -        if parent_id:
 | 
	
		
			
			| 892 |  | -            not_read_contents = not_read_contents.filter(
 | 
	
		
			
			| 893 |  | -                Content.parent_id==parent_id)
 | 
	
		
			
			| 894 |  | -
 | 
	
		
			
			| 895 |  | -        result = []
 | 
	
		
			
			| 896 |  | -        for item in not_read_contents:
 | 
	
		
			
			| 897 |  | -            new_item = None
 | 
	
		
			
			| 898 |  | -            if ContentType.Comment == item.type:
 | 
	
		
			
			| 899 |  | -                new_item = item.parent
 | 
	
		
			
			| 900 |  | -            else:
 | 
	
		
			
			| 901 |  | -                new_item = item
 | 
	
		
			
			| 902 |  | -
 | 
	
		
			
			| 903 |  | -            # INFO - D.A. - 2015-05-20
 | 
	
		
			
			| 904 |  | -            # We do not want to show only one item if the last 10 items are
 | 
	
		
			
			| 905 |  | -            # comments about one thread for example
 | 
	
		
			
			| 906 |  | -            if new_item not in result:
 | 
	
		
			
			| 907 |  | -                result.append(new_item)
 | 
	
		
			
			| 908 |  | -
 | 
	
		
			
			| 909 |  | -            if len(result) >= limit:
 | 
	
		
			
			| 910 |  | -                break
 | 
	
		
			
			| 911 |  | -
 | 
	
		
			
			| 912 |  | -        return result
 | 
	
		
			
			|  | 857 | +    # TODO - G.M - 2018-07-19 - Find a way to update this method to something
 | 
	
		
			
			|  | 858 | +    # usable and efficient for tracim v2 to get content with read/unread status
 | 
	
		
			
			|  | 859 | +    # instead of relying on has_new_information_for()
 | 
	
		
			
			|  | 860 | +    # def get_last_unread(self, parent_id: typing.Optional[int], content_type: str,
 | 
	
		
			
			|  | 861 | +    #                     workspace: Workspace=None, limit=10) -> typing.List[Content]:
 | 
	
		
			
			|  | 862 | +    #     assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
 | 
	
		
			
			|  | 863 | +    #     assert content_type is not None# DYN_REMOVE
 | 
	
		
			
			|  | 864 | +    #     assert isinstance(content_type, str) # DYN_REMOVE
 | 
	
		
			
			|  | 865 | +    #
 | 
	
		
			
			|  | 866 | +    #     read_revision_ids = self._session.query(RevisionReadStatus.revision_id) \
 | 
	
		
			
			|  | 867 | +    #         .filter(RevisionReadStatus.user_id==self._user_id)
 | 
	
		
			
			|  | 868 | +    #
 | 
	
		
			
			|  | 869 | +    #     not_read_revisions = self._revisions_base_query(workspace) \
 | 
	
		
			
			|  | 870 | +    #         .filter(~ContentRevisionRO.revision_id.in_(read_revision_ids)) \
 | 
	
		
			
			|  | 871 | +    #         .filter(ContentRevisionRO.workspace_id == Workspace.workspace_id) \
 | 
	
		
			
			|  | 872 | +    #         .filter(Workspace.is_deleted.is_(False)) \
 | 
	
		
			
			|  | 873 | +    #         .subquery()
 | 
	
		
			
			|  | 874 | +    #
 | 
	
		
			
			|  | 875 | +    #     not_read_content_ids_query = self._session.query(
 | 
	
		
			
			|  | 876 | +    #         distinct(not_read_revisions.c.content_id)
 | 
	
		
			
			|  | 877 | +    #     )
 | 
	
		
			
			|  | 878 | +    #     not_read_content_ids = list(map(
 | 
	
		
			
			|  | 879 | +    #         itemgetter(0),
 | 
	
		
			
			|  | 880 | +    #         not_read_content_ids_query,
 | 
	
		
			
			|  | 881 | +    #     ))
 | 
	
		
			
			|  | 882 | +    #
 | 
	
		
			
			|  | 883 | +    #     not_read_contents = self._base_query(workspace) \
 | 
	
		
			
			|  | 884 | +    #         .filter(Content.content_id.in_(not_read_content_ids)) \
 | 
	
		
			
			|  | 885 | +    #         .order_by(desc(Content.updated))
 | 
	
		
			
			|  | 886 | +    #
 | 
	
		
			
			|  | 887 | +    #     if content_type != ContentType.Any:
 | 
	
		
			
			|  | 888 | +    #         not_read_contents = not_read_contents.filter(
 | 
	
		
			
			|  | 889 | +    #             Content.type==content_type)
 | 
	
		
			
			|  | 890 | +    #     else:
 | 
	
		
			
			|  | 891 | +    #         not_read_contents = not_read_contents.filter(
 | 
	
		
			
			|  | 892 | +    #             Content.type!=ContentType.Folder)
 | 
	
		
			
			|  | 893 | +    #
 | 
	
		
			
			|  | 894 | +    #     if parent_id:
 | 
	
		
			
			|  | 895 | +    #         not_read_contents = not_read_contents.filter(
 | 
	
		
			
			|  | 896 | +    #             Content.parent_id==parent_id)
 | 
	
		
			
			|  | 897 | +    #
 | 
	
		
			
			|  | 898 | +    #     result = []
 | 
	
		
			
			|  | 899 | +    #     for item in not_read_contents:
 | 
	
		
			
			|  | 900 | +    #         new_item = None
 | 
	
		
			
			|  | 901 | +    #         if ContentType.Comment == item.type:
 | 
	
		
			
			|  | 902 | +    #             new_item = item.parent
 | 
	
		
			
			|  | 903 | +    #         else:
 | 
	
		
			
			|  | 904 | +    #             new_item = item
 | 
	
		
			
			|  | 905 | +    #
 | 
	
		
			
			|  | 906 | +    #         # INFO - D.A. - 2015-05-20
 | 
	
		
			
			|  | 907 | +    #         # We do not want to show only one item if the last 10 items are
 | 
	
		
			
			|  | 908 | +    #         # comments about one thread for example
 | 
	
		
			
			|  | 909 | +    #         if new_item not in result:
 | 
	
		
			
			|  | 910 | +    #             result.append(new_item)
 | 
	
		
			
			|  | 911 | +    #
 | 
	
		
			
			|  | 912 | +    #         if len(result) >= limit:
 | 
	
		
			
			|  | 913 | +    #             break
 | 
	
		
			
			|  | 914 | +    #
 | 
	
		
			
			|  | 915 | +    #     return result
 | 
	
		
			
			| 913 | 916 |  
 | 
	
		
			
			| 914 | 917 |      def set_allowed_content(self, folder: Content, allowed_content_dict:dict):
 | 
	
		
			
			| 915 | 918 |          """
 | 
	
	
		
			
			|  | @@ -1088,11 +1091,7 @@ class ContentApi(object):
 | 
	
		
			
			| 1088 | 1091 |                         do_flush: bool=True,
 | 
	
		
			
			| 1089 | 1092 |                         recursive: bool=True
 | 
	
		
			
			| 1090 | 1093 |                         ):
 | 
	
		
			
			| 1091 |  | -
 | 
	
		
			
			| 1092 |  | -        itemset = self.get_last_unread(None, ContentType.Any)
 | 
	
		
			
			| 1093 |  | -
 | 
	
		
			
			| 1094 |  | -        for item in itemset:
 | 
	
		
			
			| 1095 |  | -            self.mark_read(item, read_datetime, do_flush, recursive)
 | 
	
		
			
			|  | 1094 | +        return self.mark_read__workspace(None, read_datetime, do_flush, recursive) # nopep8
 | 
	
		
			
			| 1096 | 1095 |  
 | 
	
		
			
			| 1097 | 1096 |      def mark_read__workspace(self,
 | 
	
		
			
			| 1098 | 1097 |                         workspace : Workspace,
 | 
	
	
		
			
			|  | @@ -1100,11 +1099,10 @@ class ContentApi(object):
 | 
	
		
			
			| 1100 | 1099 |                         do_flush: bool=True,
 | 
	
		
			
			| 1101 | 1100 |                         recursive: bool=True
 | 
	
		
			
			| 1102 | 1101 |                         ):
 | 
	
		
			
			| 1103 |  | -
 | 
	
		
			
			| 1104 |  | -        itemset = self.get_last_unread(None, ContentType.Any, workspace)
 | 
	
		
			
			| 1105 |  | -
 | 
	
		
			
			|  | 1102 | +        itemset = self.get_last_active(workspace)
 | 
	
		
			
			| 1106 | 1103 |          for item in itemset:
 | 
	
		
			
			| 1107 |  | -            self.mark_read(item, read_datetime, do_flush, recursive)
 | 
	
		
			
			|  | 1104 | +            if item.type != ContentType.Folder and item.has_new_information_for(self._user):
 | 
	
		
			
			|  | 1105 | +                self.mark_read(item, read_datetime, do_flush, recursive)
 | 
	
		
			
			| 1108 | 1106 |  
 | 
	
		
			
			| 1109 | 1107 |      def mark_read(self, content: Content,
 | 
	
		
			
			| 1110 | 1108 |                    read_datetime: datetime=None,
 |