def set_ready(self, client_upload_id, storage_id, author, album, duration, now): self.set_processing(client_upload_id, storage_id, author, album, now) video = Video.objects.get(storage_id=storage_id) if video.status == Video.STATUS_PROCESSING: video.status = Video.STATUS_READY video.duration = duration video.save(update_fields=['status', 'duration']) album.save_revision(now,True) photo = video.get_photo() # Send push notifications to the album members about just added photos membership_query = AlbumMember.objects.filter(album=album).only('user__id') device_push.broadcast_videos_added_to_album( album_id=album.id, author_id=photo.author.id, album_name=album.name, author_name=photo.author.nickname, author_avatar_url=photo.author.get_avatar_url(), num_photos=1, user_ids=[membership.user.id for membership in membership_query], album_photo=photo.photo_id) device_push.broadcast_album_sync([photo.author.id], photo.album.id) #device_push.broadcast_video_added_to_album(photo.album.id,[photo.author.id], photo.album.name, photo.author.creator.name, photo.author.get_avatar_url(),) #(, author_avatar_url, num_photos, user//_ids,album_photo elif video.status != Video.STATUS_READY: raise RuntimeError('Invalid transition from status: ' + video.status)
def send_push_on_photos_added_to_album(sender, **kwargs): """When new photos added to the album then send push notifications to all album members""" photos = kwargs.get('photos') user = kwargs.get('by_user') album = kwargs.get('to_album') photo = photos[0] # Send push notifications to the album members about just added photos membership_query = AlbumMember.objects.filter(album=album).only('user__id') device_push.broadcast_photos_added_to_album( album_id=album.id, author_id=user.id, album_name=album.name, author_name=user.nickname, author_avatar_url=user.get_avatar_url(), num_photos=len(photos), user_ids=[membership.user.id for membership in membership_query], album_photo=photo) # #70 3) device_push.broadcast_album_sync(user.id, album.id)
def send_push_on_photo_removed_from_album(sender, **kwargs): photos = kwargs.get('photos') user = kwargs.get('by_user') album = kwargs.get('from_album') users = album.get_member_users() user_ids = [user.id for user in users] # #70 3) device_push.broadcast_album_sync(user_ids, album.id)
def set_photo_user_glance_score_delta(self, user, photo, score_delta): changed = PhotoGlanceScoreDelta.objects.set_photo_user_glance_score_delta(user, photo, score_delta, self.current_date) if changed: if photo.author.id != user.id: photo.author.increment_user_glance_score(3 * score_delta) user_ids = [photo.author.id] device_push.broadcast_photo_glance_score_delta(user_ids, user.nickname, user.get_avatar_url(), photo.album.id, photo.photo_id, photo.album.name, score_delta) album_users = self.album.get_member_users() user_ids = [u.id for u in album_users if u.id != photo.author.id and u.id != user.id] device_push.broadcast_album_sync(user_ids, self.album.id)