@@ -120,6 +120,29 @@ def add_system_audit_log(severity: AuditSeverity, title: str, url: str, package=
120120 return add_audit_log (severity , get_system_user (), title , url , package , description )
121121
122122
123+ def add_replies (thread : Thread , user : User , message : str , continuation : str = "(continued)\n \n " , is_status_update = False ):
124+ is_first = True
125+ while message != "" :
126+ if len (message ) > 1900 :
127+ idx = message [:1900 ].rfind ("\n " )
128+ this_reply = message [:idx ] + "\n \n …"
129+ message = message [idx :]
130+ else :
131+ this_reply = message
132+ message = ""
133+
134+ reply = ThreadReply ()
135+ reply .thread = thread
136+ reply .author = user
137+ reply .is_status_update = is_status_update
138+ if is_first :
139+ reply .comment = this_reply
140+ else :
141+ reply .comment = f"{ continuation } { this_reply } "
142+ thread .replies .append (reply )
143+ is_first = False
144+
145+
123146def post_bot_message (package : Package , title : str , message : str , session = None ):
124147 if session is None :
125148 session = db .session
@@ -137,16 +160,12 @@ def post_bot_message(package: Package, title: str, message: str, session=None):
137160 session .add (thread )
138161 session .flush ()
139162
140- reply = ThreadReply ()
141- reply .thread = thread
142- reply .author = system_user
143- reply .comment = "**{}**\n \n {}\n \n This is an automated message, but you can reply if you need help" .format (title , message )
144- session .add (reply )
163+ add_replies (thread , system_user ,
164+ f"**{ title } **\n \n { message } \n \n This is an automated message, but you can reply if you need help" ,
165+ continuation = f"(continued)\n \n **{ title } **\n \n " )
145166
146167 add_notification (thread .watchers , system_user , NotificationType .BOT , title , thread .get_view_url (), thread .package , session )
147168
148- thread .replies .append (reply )
149-
150169
151170def post_to_approval_thread (package : Package , user : User , message : str , is_status_update = True , create_thread = False ):
152171 thread = package .review_thread
@@ -163,12 +182,7 @@ def post_to_approval_thread(package: Package, user: User, message: str, is_statu
163182 else :
164183 return
165184
166- reply = ThreadReply ()
167- reply .thread = thread
168- reply .author = user
169- reply .is_status_update = is_status_update
170- reply .comment = message
171- db .session .add (reply )
185+ add_replies (thread , user , message , is_status_update = is_status_update )
172186
173187 if is_status_update :
174188 msg = f"{ message } - { thread .title } "
@@ -177,8 +191,6 @@ def post_to_approval_thread(package: Package, user: User, message: str, is_statu
177191
178192 add_notification (thread .watchers , user , NotificationType .THREAD_REPLY , msg , thread .get_view_url (), package )
179193
180- thread .replies .append (reply )
181-
182194
183195def get_games_from_csv (session : sqlalchemy .orm .Session , csv : str ) -> List [Package ]:
184196 return get_games_from_list (session , [name .strip () for name in csv .split ("," )])
0 commit comments