mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			Set number of preview posts on profile screen
							parent
							
								
									01ca986483
								
							
						
					
					
						commit
						cc318218e0
					
				
							
								
								
									
										17
									
								
								daemon.py
								
								
								
								
							
							
						
						
									
										17
									
								
								daemon.py
								
								
								
								
							| 
						 | 
				
			
			@ -83,6 +83,8 @@ from person import remove_account
 | 
			
		|||
from person import can_remove_post
 | 
			
		||||
from person import person_snooze
 | 
			
		||||
from person import person_unsnooze
 | 
			
		||||
from posts import get_max_profile_posts
 | 
			
		||||
from posts import set_max_profile_posts
 | 
			
		||||
from posts import get_post_expiry_keep_dms
 | 
			
		||||
from posts import set_post_expiry_keep_dms
 | 
			
		||||
from posts import get_post_expiry_days
 | 
			
		||||
| 
						 | 
				
			
			@ -6513,6 +6515,21 @@ class PubServer(BaseHTTPRequestHandler):
 | 
			
		|||
                            set_post_expiry_days(base_dir, nickname, domain, 0)
 | 
			
		||||
                            actor_changed = True
 | 
			
		||||
 | 
			
		||||
                    # set maximum preview posts on profile screen
 | 
			
		||||
                    max_profile_posts = \
 | 
			
		||||
                        get_max_profile_posts(base_dir, nickname, domain,
 | 
			
		||||
                                              self.server.max_recent_posts)
 | 
			
		||||
                    if fields.get('maxRecentProfilePosts'):
 | 
			
		||||
                        if fields['maxRecentProfilePosts'] != \
 | 
			
		||||
                           str(max_profile_posts):
 | 
			
		||||
                            max_profile_posts = \
 | 
			
		||||
                                fields['maxRecentProfilePosts']
 | 
			
		||||
                            set_max_profile_posts(base_dir, nickname, domain,
 | 
			
		||||
                                                  max_profile_posts)
 | 
			
		||||
                    else:
 | 
			
		||||
                        set_max_profile_posts(base_dir, nickname, domain,
 | 
			
		||||
                                              self.server.max_recent_posts)
 | 
			
		||||
 | 
			
		||||
                    # change tox address
 | 
			
		||||
                    current_tox_address = get_tox_address(actor_json)
 | 
			
		||||
                    if fields.get('toxAddress'):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										43
									
								
								posts.py
								
								
								
								
							
							
						
						
									
										43
									
								
								posts.py
								
								
								
								
							| 
						 | 
				
			
			@ -5971,3 +5971,46 @@ def get_original_post_from_announce_url(announce_url: str, base_dir: str,
 | 
			
		|||
                url = orig_post_id
 | 
			
		||||
 | 
			
		||||
    return actor, url, orig_filename
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_max_profile_posts(base_dir: str, nickname: str, domain: str,
 | 
			
		||||
                          max_recent_posts: int) -> int:
 | 
			
		||||
    """Returns the maximum number of posts to show on the profile screen
 | 
			
		||||
    """
 | 
			
		||||
    max_posts_filename = \
 | 
			
		||||
        acct_dir(base_dir, nickname, domain) + '/max_profile_posts.txt'
 | 
			
		||||
    if not os.path.isfile(max_posts_filename):
 | 
			
		||||
        return max_recent_posts
 | 
			
		||||
    max_profile_posts = max_recent_posts
 | 
			
		||||
    try:
 | 
			
		||||
        with open(max_posts_filename, 'r', encoding='utf-8') as fp_posts:
 | 
			
		||||
            max_posts_str = fp_posts.read()
 | 
			
		||||
            if max_posts_str:
 | 
			
		||||
                if max_posts_str.isdigit():
 | 
			
		||||
                    max_profile_posts = int(max_posts_str)
 | 
			
		||||
    except OSError:
 | 
			
		||||
        print('EX: unable to read maximum profile posts ' +
 | 
			
		||||
              max_posts_filename)
 | 
			
		||||
    if max_profile_posts < 1:
 | 
			
		||||
        max_profile_posts = 1
 | 
			
		||||
    if max_profile_posts > 20:
 | 
			
		||||
        max_profile_posts = 20
 | 
			
		||||
    return max_profile_posts
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def set_max_profile_posts(base_dir: str, nickname: str, domain: str,
 | 
			
		||||
                          max_recent_posts: int) -> bool:
 | 
			
		||||
    """Sets the maximum number of posts to show on the profile screen
 | 
			
		||||
    """
 | 
			
		||||
    max_posts_filename = \
 | 
			
		||||
        acct_dir(base_dir, nickname, domain) + '/max_profile_posts.txt'
 | 
			
		||||
    max_recent_posts_str = str(max_recent_posts)
 | 
			
		||||
    try:
 | 
			
		||||
        with open(max_posts_filename, 'w+',
 | 
			
		||||
                  encoding='utf-8') as fp_posts:
 | 
			
		||||
            fp_posts.write(max_recent_posts_str)
 | 
			
		||||
    except OSError:
 | 
			
		||||
        print('EX: unable to save maximum profile posts ' +
 | 
			
		||||
              max_posts_filename)
 | 
			
		||||
        return False
 | 
			
		||||
    return True
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,6 +44,7 @@ from posts import get_person_box
 | 
			
		|||
from posts import is_moderator
 | 
			
		||||
from posts import parse_user_feed
 | 
			
		||||
from posts import is_create_inside_announce
 | 
			
		||||
from posts import get_max_profile_posts
 | 
			
		||||
from donate import get_donation_url
 | 
			
		||||
from donate import get_website
 | 
			
		||||
from donate import get_gemini_link
 | 
			
		||||
| 
						 | 
				
			
			@ -611,31 +612,6 @@ def _get_profile_header_after_search(nickname: str, default_timeline: str,
 | 
			
		|||
    return html_str
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _get_max_profile_posts(base_dir: str, nickname: str, domain: str,
 | 
			
		||||
                           max_recent_posts: int) -> int:
 | 
			
		||||
    """Returns the maximum number of posts to show on the profile screen
 | 
			
		||||
    """
 | 
			
		||||
    max_posts_filename = \
 | 
			
		||||
        acct_dir(base_dir, nickname, domain) + '/max_profile_posts.txt'
 | 
			
		||||
    if not os.path.isfile(max_posts_filename):
 | 
			
		||||
        return max_recent_posts
 | 
			
		||||
    max_profile_posts = max_recent_posts
 | 
			
		||||
    try:
 | 
			
		||||
        with open(max_posts_filename, 'r', encoding='utf-8') as fp_posts:
 | 
			
		||||
            max_posts_str = fp_posts.read()
 | 
			
		||||
            if max_posts_str:
 | 
			
		||||
                if max_posts_str.isdigit():
 | 
			
		||||
                    max_profile_posts = int(max_posts_str)
 | 
			
		||||
    except OSError:
 | 
			
		||||
        print('EX: unable to read maximum profile posts ' +
 | 
			
		||||
              max_posts_filename)
 | 
			
		||||
    if max_profile_posts < 1:
 | 
			
		||||
        max_profile_posts = 1
 | 
			
		||||
    if max_profile_posts > 20:
 | 
			
		||||
        max_profile_posts = 20
 | 
			
		||||
    return max_profile_posts
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def html_profile(signing_priv_key_pem: str,
 | 
			
		||||
                 rss_icon_at_top: bool,
 | 
			
		||||
                 icons_as_buttons: bool,
 | 
			
		||||
| 
						 | 
				
			
			@ -1096,8 +1072,8 @@ def html_profile(signing_priv_key_pem: str,
 | 
			
		|||
        translate['Get the source code'] + '" src="/icons/agpl.png" /></a>'
 | 
			
		||||
 | 
			
		||||
    if selected == 'posts':
 | 
			
		||||
        max_profile_posts = _get_max_profile_posts(base_dir, nickname, domain,
 | 
			
		||||
                                                   max_recent_posts)
 | 
			
		||||
        max_profile_posts = get_max_profile_posts(base_dir, nickname, domain,
 | 
			
		||||
                                                  max_recent_posts)
 | 
			
		||||
        min_images_for_accounts = []
 | 
			
		||||
        profile_str += \
 | 
			
		||||
            _html_profile_posts(recent_posts_cache, max_profile_posts,
 | 
			
		||||
| 
						 | 
				
			
			@ -2335,7 +2311,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, bio_str: str,
 | 
			
		|||
                       'expiryKeepDMs', keep_dms)
 | 
			
		||||
 | 
			
		||||
    max_profile_posts = \
 | 
			
		||||
        _get_max_profile_posts(base_dir, nickname, domain, max_recent_posts)
 | 
			
		||||
        get_max_profile_posts(base_dir, nickname, domain, max_recent_posts)
 | 
			
		||||
    edit_profile_form += \
 | 
			
		||||
        edit_number_field(translate['Preview posts on profile screen'],
 | 
			
		||||
                          'maxRecentProfilePosts', max_profile_posts,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue