BlenderKit: fix asset bar update of button visibility

also make notifications check them only for users that make a search in the session, and only check once in 2 hours
This commit is contained in:
Vilem Duha 2021-11-09 11:39:50 +01:00
parent 115d251253
commit 90668547ad
3 changed files with 52 additions and 40 deletions

View File

@ -891,39 +891,41 @@ class BlenderKitAssetBarOperator(BL_UI_OT_draw_operator):
if not sr:
return
for asset_button in self.asset_buttons:
if asset_button.visible:
asset_button.asset_index = asset_button.button_index + self.scroll_offset
if asset_button.asset_index < len(sr):
asset_button.asset_index = asset_button.button_index + self.scroll_offset
# print(asset_button.asset_index, len(sr))
if asset_button.asset_index < len(sr):
asset_button.visible = True
asset_data = sr[asset_button.asset_index]
asset_data = sr[asset_button.asset_index]
iname = blenderkit.utils.previmg_name(asset_button.asset_index)
# show indices for debug purposes
# asset_button.text = str(asset_button.asset_index)
img = bpy.data.images.get(iname)
if img is None or len(img.pixels) == 0:
img_filepath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
else:
img_filepath = img.filepath
# print(asset_button.button_index, img_filepath)
asset_button.set_image(img_filepath)
self.update_validation_icon(asset_button, asset_data)
if utils.profile_is_validator() and asset_data['verificationStatus'] == 'uploaded':
over_limit = utils.is_upload_old(asset_data)
if over_limit:
redness = min(over_limit * .05, 0.7)
asset_button.red_alert.bg_color = (1, 0, 0, redness)
asset_button.red_alert.visible = True
else:
asset_button.red_alert.visible = False
elif utils.profile_is_validator():
asset_button.red_alert.visible = False
iname = blenderkit.utils.previmg_name(asset_button.asset_index)
# show indices for debug purposes
# asset_button.text = str(asset_button.asset_index)
img = bpy.data.images.get(iname)
if img is None or len(img.pixels) == 0:
img_filepath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
else:
asset_button.validation_icon.visible = False
if utils.profile_is_validator():
img_filepath = img.filepath
# print(asset_button.button_index, img_filepath)
asset_button.set_image(img_filepath)
self.update_validation_icon(asset_button, asset_data)
if utils.profile_is_validator() and asset_data['verificationStatus'] == 'uploaded':
over_limit = utils.is_upload_old(asset_data)
if over_limit:
redness = min(over_limit * .05, 0.7)
asset_button.red_alert.bg_color = (1, 0, 0, redness)
asset_button.red_alert.visible = True
else:
asset_button.red_alert.visible = False
elif utils.profile_is_validator():
asset_button.red_alert.visible = False
else:
asset_button.visible = False
asset_button.validation_icon.visible = False
if utils.profile_is_validator():
asset_button.red_alert.visible = False
def scroll_update(self):
sr = bpy.context.window_manager.get('search results')

View File

@ -50,9 +50,9 @@ def upload_comment_thread(url, comment='', api_key=None):
# try:
r = rerequests.put(url, data=data, verify=True, headers=headers)
print(r)
# print(r)
# print(dir(r))
print(r.text)
# print(r.text)
# except requests.exceptions.RequestException as e:
# print('ratings upload failed: %s' % str(e))
@ -72,7 +72,7 @@ def upload_comment_flag_thread( asset_id = '', comment_id='', flag='like', api_k
# try:
r = rerequests.post(url, data=data, verify=True, headers=headers)
print(r.text)
# print(r.text)
#here it's important we read back, so likes are updated accordingly:
get_comments(asset_id, api_key)
@ -129,7 +129,7 @@ def get_comments(asset_id, api_key):
r = rerequests.get(url, params=params, verify=True, headers=headers)
if r is None:
return
print(r.status_code)
# print(r.status_code)
if r.status_code == 200:
rj = r.json()
# store comments - send them to task queue

View File

@ -117,7 +117,7 @@ def refresh_notifications_timer():
fetch_server_data()
all_notifications_count = comments_utils.count_all_notifications()
comments_utils.get_notifications_thread(preferences.api_key, all_count = all_notifications_count)
return 300
return 7200
def update_ad(ad):
@ -197,9 +197,9 @@ def scene_load(context):
categories.load_categories()
if not bpy.app.timers.is_registered(refresh_token_timer) and not bpy.app.background:
bpy.app.timers.register(refresh_token_timer, persistent=True, first_interval=36000)
if utils.experimental_enabled() and not bpy.app.timers.is_registered(
refresh_notifications_timer) and not bpy.app.background:
bpy.app.timers.register(refresh_notifications_timer, persistent=True, first_interval=5)
# if utils.experimental_enabled() and not bpy.app.timers.is_registered(
# refresh_notifications_timer) and not bpy.app.background:
# bpy.app.timers.register(refresh_notifications_timer, persistent=True, first_interval=5)
update_assets_data()
@ -218,10 +218,11 @@ def fetch_server_data():
get_profile()
if bpy.context.window_manager.get('bkit_categories') is None:
categories.fetch_categories_thread(api_key, force=False)
all_notifications_count = comments_utils.count_all_notifications()
comments_utils.get_notifications_thread(api_key, all_count = all_notifications_count)
# all_notifications_count = comments_utils.count_all_notifications()
# comments_utils.get_notifications_thread(api_key, all_count = all_notifications_count)
first_time = True
first_search_parsing = True
last_clipboard = ''
@ -408,7 +409,7 @@ def search_timer():
all_thumbs_loaded = all_loaded
global search_threads
global search_threads, first_search_parsing
if len(search_threads) == 0:
# utils.p('end search timer')
props = utils.get_search_props()
@ -426,6 +427,15 @@ def search_timer():
# but most of the time only one is running anyway
if not thread[0].is_alive():
#check for notifications only for users that actually use the add-on
if first_search_parsing:
first_search_parsing = False
all_notifications_count = comments_utils.count_all_notifications()
comments_utils.get_notifications_thread(api_key, all_count=all_notifications_count)
if utils.experimental_enabled() and not bpy.app.timers.is_registered(
refresh_notifications_timer) and not bpy.app.background:
bpy.app.timers.register(refresh_notifications_timer, persistent=True, first_interval=5)
search_threads.remove(thread) #
icons_dir = thread[1]
scene = bpy.context.scene