VRFS-2539 protect against error during notification load if the related session is missing / clean up the notifications of nonexistent sessions
This commit is contained in:
parent
f80b0e4f66
commit
3f2be132bd
|
|
@ -427,6 +427,7 @@ module JamRuby
|
|||
# returns one user history per user, with instruments all crammed together, and with total duration
|
||||
def unique_user_histories
|
||||
|
||||
# only get the active users if the session is in progress
|
||||
user_filter = "music_sessions_user_history.session_removed_at is null" if self.session_removed_at.nil?
|
||||
|
||||
MusicSessionUserHistory
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ module JamRuby
|
|||
# used for persisted notifications
|
||||
def formatted_msg
|
||||
# target_user, band, session, recording, invitation, join_request = nil
|
||||
source_user, band = nil
|
||||
source_user, band, session = nil
|
||||
|
||||
unless self.source_user_id.nil?
|
||||
source_user = User.find(self.source_user_id)
|
||||
|
|
@ -53,7 +53,12 @@ module JamRuby
|
|||
end
|
||||
|
||||
unless self.session_id.nil?
|
||||
session = MusicSession.find(self.session_id)
|
||||
session = MusicSession.find_by_id(self.session_id)
|
||||
|
||||
# remove all notifications related to this session if it's not found
|
||||
if session.nil?
|
||||
Notification.delete_all "(session_id = '#{session_id}')"
|
||||
end
|
||||
end
|
||||
|
||||
self.class.format_msg(self.description, {:user => source_user, :band => band, :session => session})
|
||||
|
|
|
|||
|
|
@ -207,19 +207,24 @@
|
|||
isLoading = true;
|
||||
// retrieve pending notifications for this user
|
||||
rest.getNotifications(buildParams())
|
||||
.done(function(response) {
|
||||
updateNotificationList(response);
|
||||
isLoading = false;
|
||||
})
|
||||
.fail(function() {
|
||||
isLoading = false;
|
||||
app.ajaxError();
|
||||
})
|
||||
.done(function(response) {
|
||||
updateNotificationList(response);
|
||||
isLoading = false;
|
||||
})
|
||||
.fail(function() {
|
||||
isLoading = false;
|
||||
app.ajaxError();
|
||||
})
|
||||
}
|
||||
|
||||
function updateNotificationList(response) {
|
||||
$.each(response, function(index, val) {
|
||||
|
||||
// this means the session no longer exists
|
||||
if (response.fan_access == null && response.musician_access == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(val.description == context.JK.MessageType.TEXT_MESSAGE) {
|
||||
val.formatted_msg = textMessageDialog.formatTextMessage(val.message.substring(0, 200), val.source_user_id, val.source_user.name, val.message.length > 200).html();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue