@@ -83,6 +83,9 @@ class QChatWidget(QgsDockWidget):
8383 qchat_client : QChatApiClient
8484 qchat_ws : QChatWebsocket
8585
86+ min_author_length : int
87+ max_author_length : int
88+
8689 def __init__ (
8790 self ,
8891 iface : QgisInterface ,
@@ -237,6 +240,16 @@ def on_widget_opened(self) -> None:
237240 # initialize QChat API client
238241 self .qchat_client = QChatApiClient (self .settings .qchat_instance_uri )
239242
243+ # fetch rules for author min/max length
244+ try :
245+ rules = self .qchat_client .get_rules ()
246+ self .min_author_length = rules ["min_author_length" ]
247+ self .max_author_length = rules ["max_author_length" ]
248+ except Exception as exc :
249+ self .iface .messageBar ().pushCritical (self .tr ("QChat error" ), str (exc ))
250+ self .min_author_length = 3
251+ self .max_author_length = 32
252+
240253 # clear rooms combobox items
241254 self .cbb_room .clear () # delete all items from comboBox
242255
@@ -346,6 +359,23 @@ def on_room_changed(self) -> None:
346359 """
347360 Action called when room index is changed in the room combobox
348361 """
362+ if (
363+ not self .min_author_length
364+ <= len (self .settings .author_nickname )
365+ <= self .max_author_length
366+ ):
367+ self .log (
368+ message = self .tr (
369+ "QChat nickname not set or too short (between {min} and {max} characters). Please open settings to fix it."
370+ ).format (min = self .min_author_length , max = self .max_author_length ),
371+ log_level = Qgis .Warning ,
372+ push = self .settings .notify_push_info ,
373+ duration = self .settings .notify_push_duration ,
374+ button = True ,
375+ button_label = self .tr ("Open Settings" ),
376+ button_connect = self .on_settings_button_clicked ,
377+ )
378+ return
349379 old_room = self .current_room
350380 new_room = self .cbb_room .currentText ()
351381 old_is_marker = old_room != MARKER_VALUE
@@ -372,6 +402,23 @@ def on_connect_button_clicked(self) -> None:
372402 if self .connected :
373403 self .disconnect_from_room ()
374404 else :
405+ if (
406+ not self .min_author_length
407+ <= len (self .settings .author_nickname )
408+ <= self .max_author_length
409+ ):
410+ self .log (
411+ message = self .tr (
412+ "QChat nickname not set or too short (between {min} and {max} characters). Please open settings to fix it."
413+ ).format (min = self .min_author_length , max = self .max_author_length ),
414+ log_level = Qgis .Warning ,
415+ push = self .settings .notify_push_info ,
416+ duration = self .settings .notify_push_duration ,
417+ button = True ,
418+ button_label = self .tr ("Open Settings" ),
419+ button_connect = self .on_settings_button_clicked ,
420+ )
421+ return
375422 room = self .cbb_room .currentText ()
376423 if room == MARKER_VALUE :
377424 return
0 commit comments