apiAdminDeleteMudmail handles DELETE /admin/api/v1/mudmail Query params: user_id (int), date_sent_us (int64 microseconds since epoch). Deletes the first message for that user whose DateSent microsecond timestamp matches.
(r *http.Request)
| 179 | // Query params: user_id (int), date_sent_us (int64 microseconds since epoch). |
| 180 | // Deletes the first message for that user whose DateSent microsecond timestamp matches. |
| 181 | func (m *MudmailModule) apiAdminDeleteMudmail(r *http.Request) (int, bool, any) { |
| 182 | q := r.URL.Query() |
| 183 | |
| 184 | userIdStr := q.Get("user_id") |
| 185 | dateSentStr := q.Get("date_sent_us") |
| 186 | |
| 187 | if userIdStr == "" || dateSentStr == "" { |
| 188 | return http.StatusBadRequest, false, map[string]string{"error": "user_id and date_sent_us query params are required"} |
| 189 | } |
| 190 | |
| 191 | userId, err := strconv.Atoi(userIdStr) |
| 192 | if err != nil || userId <= 0 { |
| 193 | return http.StatusBadRequest, false, map[string]string{"error": "invalid user_id"} |
| 194 | } |
| 195 | |
| 196 | dateSentUs, err := strconv.ParseInt(dateSentStr, 10, 64) |
| 197 | if err != nil { |
| 198 | return http.StatusBadRequest, false, map[string]string{"error": "invalid date_sent_us"} |
| 199 | } |
| 200 | |
| 201 | isOnline := users.GetByUserId(userId) != nil |
| 202 | var inbox Inbox |
| 203 | if isOnline { |
| 204 | inbox = m.inboxes[userId] |
| 205 | } else { |
| 206 | inbox = m.load(userId) |
| 207 | } |
| 208 | |
| 209 | newInbox := make(Inbox, 0, len(inbox)) |
| 210 | deleted := false |
| 211 | for _, msg := range inbox { |
| 212 | if !deleted && msg.DateSent.UnixMicro() == dateSentUs { |
| 213 | deleted = true |
| 214 | continue |
| 215 | } |
| 216 | newInbox = append(newInbox, msg) |
| 217 | } |
| 218 | |
| 219 | if !deleted { |
| 220 | return http.StatusNotFound, false, map[string]string{"error": "message not found"} |
| 221 | } |
| 222 | |
| 223 | if isOnline { |
| 224 | m.inboxes[userId] = newInbox |
| 225 | } |
| 226 | m.save(userId, newInbox) |
| 227 | |
| 228 | return http.StatusOK, true, map[string]any{"deleted": true} |
| 229 | } |
| 230 | |
| 231 | // inboxForUser returns the username and inbox for a given userId, preferring |
| 232 | // the in-memory copy for online users and falling back to disk for offline ones. |
nothing calls this directly
no test coverage detected