Exemplo n.º 1
0
def send_notification(sid, notification_data):
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(notification_data['to_user_id'])
        n = Notification(to_user_id=usr.id, notification_type=notification_data['notification_type'],
                         notification_data=notification_data, content=notification_data['content'])

        n.save()
        notification = Notification.get(n.id)
        data_to_send = {
            'new_notification': notification.client_message(),
            'unread': get_unread(usr.id, [])}

        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send, sid_for_recipient)
Exemplo n.º 2
0
def read_notification(sid, notification_id):
    with controlled_execution():
        notification = Notification.get(notification_id)
        if notification.read_tm is None:
            print("SELECT notification_set_read(ARRAY ['%s']);" % (notification.id,))
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" % (notification.id,))
            unread = get_unread(notification.to_user_id)
            for sid_for_receiver in connected_user_id_sids[notification.to_user_id]:
                sio.emit('general_notification', {'unread': unread}, sid_for_receiver)
Exemplo n.º 3
0
def send_notification(sid, notification_data):
    log('send_notification', sid, notification_data)
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(notification_data['to_user_id'])
        n = Notification(
            to_user_id=usr.id,
            notification_type=notification_data['notification_type'],
            notification_data=notification_data,
            content=notification_data['content'])

        n.save()
        notification = Notification.get(n.id)
        data_to_send = {
            'new_notification': notification.client_message(),
            'unread': get_unread(usr.id, [])
        }

        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send,
                         sid_for_recipient)
Exemplo n.º 4
0
def read_notification(sid, notification_id):
    log('read_notification', sid, notification_id)
    with controlled_execution():
        notification = Notification.get(notification_id)
        if notification.read_tm is None:
            log("SELECT notification_set_read(ARRAY ['%s']);" %
                (notification.id, ))
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" %
                           (notification.id, ))
            unread = get_unread(notification.to_user_id)
            for sid_for_receiver in connected_user_id_sids[
                    notification.to_user_id]:
                sio.emit('general_notification', {'unread': unread},
                         sid_for_receiver)
Exemplo n.º 5
0
def load_notifications(sid, event_data):
    with controlled_execution():
        print('load_notifications', event_data)
        user_id = connected_sid_user_id[sid]

        older = event_data.get('older', False)
        ret = Notification.get_notifications(50, user_id, older, event_data.get('first_id' if older else 'last_id', None))
        print(ret)

        read_ids = [n.id for n in ret['items'] if not n.read_tm]
        if len(read_ids):
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" % ("', '".join(read_ids)))
            unread = get_unread(user_id)
            for sid_for_receiver in connected_user_id_sids[user_id]:
                sio.emit('general_notification', {
                    'unread': unread
                }, sid_for_receiver)

        ret['items'] = [n.client_message() for n in ret['items']]
        return ret
Exemplo n.º 6
0
def load_notifications(sid, event_data):
    log('load_notifications', sid, event_data)
    with controlled_execution():
        user_id = connected_sid_user_id[sid]

        older = event_data.get('older', False)
        ret = Notification.get_notifications(
            50, user_id, older,
            event_data.get('first_id' if older else 'last_id', None))
        log(ret)

        read_ids = [n.id for n in ret['items'] if not n.read_tm]
        if len(read_ids):
            g.db().execute("SELECT notification_set_read(ARRAY ['%s']);" %
                           ("', '".join(read_ids)))
            unread = get_unread(user_id)
            for sid_for_receiver in connected_user_id_sids[user_id]:
                sio.emit('general_notification', {'unread': unread},
                         sid_for_receiver)

        ret['items'] = [n.client_message() for n in ret['items']]
        return ret