@@ -120,6 +120,29 @@ def add_system_audit_log(severity: AuditSeverity, title: str, url: str, package=
120
120
return add_audit_log (severity , get_system_user (), title , url , package , description )
121
121
122
122
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
+
123
146
def post_bot_message (package : Package , title : str , message : str , session = None ):
124
147
if session is None :
125
148
session = db .session
@@ -137,16 +160,12 @@ def post_bot_message(package: Package, title: str, message: str, session=None):
137
160
session .add (thread )
138
161
session .flush ()
139
162
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 " )
145
166
146
167
add_notification (thread .watchers , system_user , NotificationType .BOT , title , thread .get_view_url (), thread .package , session )
147
168
148
- thread .replies .append (reply )
149
-
150
169
151
170
def post_to_approval_thread (package : Package , user : User , message : str , is_status_update = True , create_thread = False ):
152
171
thread = package .review_thread
@@ -163,12 +182,7 @@ def post_to_approval_thread(package: Package, user: User, message: str, is_statu
163
182
else :
164
183
return
165
184
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 )
172
186
173
187
if is_status_update :
174
188
msg = f"{ message } - { thread .title } "
@@ -177,8 +191,6 @@ def post_to_approval_thread(package: Package, user: User, message: str, is_statu
177
191
178
192
add_notification (thread .watchers , user , NotificationType .THREAD_REPLY , msg , thread .get_view_url (), package )
179
193
180
- thread .replies .append (reply )
181
-
182
194
183
195
def get_games_from_csv (session : sqlalchemy .orm .Session , csv : str ) -> List [Package ]:
184
196
return get_games_from_list (session , [name .strip () for name in csv .split ("," )])
0 commit comments