Esempio n. 1
0
def handle_new_pic(pic_ref):
    message_title = "Shared pics"
    message_body = str(
        pic_ref.sharer_ref.user_id) + " added a pic to group " + str(
            pic_ref.group_ref.name)
    registration_ids = []
    for member in pic_ref.group_ref.members:
        registration_ids.append(member.token)
    response = []
    for pic in pic_ref.group_ref.shared_pics:
        sharer = pic.sharer
        pic_url = "http://13.127.52.161:8080/get_pic/" + pic.picture
        thumb_url = "http://13.127.52.161:8080/get_pic/" + pic.thumb
        response.append({
            "pic_id": pic.id,
            "pic_url": pic_url,
            "thumb_url": thumb_url,
            "sharer": sharer
        })
    namespace = '/pics/' + str(pic_ref.group_ref.id)
    socketio.emit('uploaded', response, namespace=namespace)
    result = push_service.notify_multiple_devices(
        registration_ids=registration_ids,
        message_title=message_title,
        message_body=message_body)
    print(result)
Esempio n. 2
0
def handle_group_deleted(admin, members, name):
    message_title = "Shared Groups"
    message_body = str(admin) + " removed you from group " + str(name)
    registration_ids = []
    for member in members:
        # user=User.query.get(member.id)
        # groups=user.groups
        registration_ids.append(member.token)
        group_obj = []
        for group in member.groups:
            group_obj.append({"id": group.id, "name": group.name})
            '''
            members=[]
            for member1 in group.members:
                members.append({"name":member1.name})
            group_obj.append({"id":group.id,"name":group.name,"members": members })
            '''
        namespace = '/groups/' + member.id
        print(namespace)
        socketio.emit('my response', group_obj, namespace=namespace)
    result = push_service.notify_multiple_devices(
        registration_ids=registration_ids,
        message_title=message_title,
        message_body=message_body)
    print(result)
Esempio n. 3
0
def handle_group_full_delete(members):
    for member in members:
        group_obj = []
        for group in member.groups:
            group_obj.append({"id": group.id, "name": group.name})
            '''
            members=[]
            for member1 in group.members:
                members.append({"name":member1.name})
            group_obj.append({"id":group.id,"name":group.name,"members": members })
            '''
        namespace = '/groups/' + member.id
        print(namespace)
        socketio.emit('my response', group_obj, namespace=namespace)
Esempio n. 4
0
def handle_delete_pic(group_ref):
    response = []
    for pic in group_ref.shared_pics:
        sharer = pic.sharer
        pic_url = "http://13.127.52.161:8080/get_pic/" + pic.picture
        thumb_url = "http://13.127.52.161:8080/get_pic/" + pic.thumb
        response.append({
            "pic_id": pic.id,
            "pic_url": pic_url,
            "thumb_url": thumb_url,
            "sharer": sharer
        })
    namespace = '/pics/' + str(group_ref.id)
    socketio.emit('uploaded', response, namespace=namespace)
Esempio n. 5
0
def handle_group_listen(group):
    members = []
    for member in group.members:
        members.append({
            "name": member.name,
            "id": member.id,
            "email": member.email
        })
    group_obj = ({
        "id": group.id,
        "name": group.name,
        "members": members,
        "admin": group.admin
    })
    #for member in group.members:
    namespace = '/groups/' + str(group.id)
    socketio.emit('my response3', group_obj, namespace=namespace)
Esempio n. 6
0
def handle_neary_users(users):
    if (len(users) > 0):
        for user in users:

            user_arr = []
            users_new = User.query.filter(
                (User.latitude >= (float(user.latitude) - .002))
                & (User.latitude <= (float(user.latitude) + .002))
                & (User.longitude <= (float(user.longitude) + .002))
                & (User.longitude >= (float(user.longitude) - .002))
                & (User.id != user.id)).all()
            for user_new in users_new:
                user_arr.append({
                    "user_id": user_new.id,
                    "user_name": user_new.name,
                    "user_email": user_new.email,
                    "last_seen": user_new.last_seen
                })
            namespace = '/nearby/' + user.id
            socketio.emit('my response2', user_arr, namespace=namespace)
Esempio n. 7
0
def handle_group_admin_delete(members, admin_ref, name):
    message_title = "Shared Groups"
    message_body = "You are the new admin of group " + str(name)
    registration_id = admin_ref.token
    result = push_service.notify_single_device(registration_id=registration_id,
                                               message_title=message_title,
                                               message_body=message_body)
    print(result)
    for member in members:
        group_obj = []
        for group in member.groups:
            group_obj.append({"id": group.id, "name": group.name})
            '''
            members=[]
            for member1 in group.members:
                members.append({"name":member1.name})
            group_obj.append({"id":group.id,"name":group.name,"members": members })
            '''
        namespace = '/groups/' + member.id
        print(namespace)
        socketio.emit('my response', group_obj, namespace=namespace)
Esempio n. 8
0
def handle_group_created(admin, members, name, admin_id):
    message_title = "Added to group"
    message_body = str(admin) + " added you to group " + str(name)
    registration_ids = []
    for member in members:
        if (member.id != admin_id):
            registration_ids.append(member.token)
        group_obj = []
        for group in member.groups:
            group_obj.append({"id": group.id, "name": group.name})
            '''
            members=[]
            for member1 in group.members:
                members.append({"name":member1.name})
            group_obj.append({"id":group.id,"name":group.name,"members": members })
            '''
        namespace = '/groups/' + member.id
        print(namespace)
        socketio.emit('my response', group_obj, namespace=namespace)
    result = push_service.notify_multiple_devices(
        registration_ids=registration_ids,
        message_title=message_title,
        message_body=message_body)
    print(result)