示例#1
0
def send_notification_before_five_mins_of_scheduled_call(arg):
    chat_ids = eval(arg) if arg else None  # arg = [1,2, 3]
    chat_from = now()
    chat_till = now() + timedelta(0, 300)
    if arg:
        chats = Chats.objects.filter(id__in=chat_ids)
    else:
        chats = Chats.objects.filter(chat_time__gte=chat_from, chat_time__lte=chat_till, chat_notified_times=0)

    for chat in chats:
        logger.info("Sending 5 min Notificaiton for chat id {}".format(chat.id))
        GCMNotificaiton().send_chat_reminder_notification(chat.id)
示例#2
0
 def setUp(self):
     self.usera, _ = Users.objects.get_or_create(fcm_token="token1",
                                                 fb_link="link1")
     self.userb, _ = Users.objects.get_or_create(fcm_token="token2",
                                                 fb_link="link2")
     self.chat = Chats(userA=self.usera, userB=self.userb, chat_time=now())
     self.chat.save()
示例#3
0
def get_current_or_next_chat_for_user(user_uuid):
    user = Users.objects.filter(user_uuid=user_uuid, active=True)
    from_time = utils.now() - timedelta(0, SECONDS)
    chats = Chats.objects.filter(Q(Q(userA=user) | Q(userB=user)),
                                 chat_time__gte=from_time)

    if not chats.exists():
        return None, None
    else:
        chat = chats.first()
        now = utils.now()
        if chat.chat_time > now:
            on_going_chat = False
        else:
            on_going_chat = True
        return chat, on_going_chat
示例#4
0
    def send_chat_scheduled_notificaiton(self, chat_id):
        chat = Chats.objects.get(id=chat_id)
        users = [chat.userA, chat.userB]

        for user in users:
            title = "Your Call has been scheduled"
            seconds = (chat.chat_time - now()).days * 24 * 60 * 60 + (
                chat.chat_time - now()).seconds
            next_time_diff = "{} hour and {} minutes".format(
                seconds / 3600, seconds / 60)
            message = "Hi {}, Congratulations! We have scheduled a call in next {}". \
                format(user.name, next_time_diff)
            data_message = {}
            self.send_notificaiton(user.fcm_token, title, message,
                                   data_message)

        chat.chat_notified_times += 1
        chat.save()
示例#5
0
文件: test_user.py 项目: ansal10/five
 def setUp(self):
     self.userA, _ = Users.objects.get_or_create(firebase_user_id='12')
     self.userB, _ = Users.objects.get_or_create(firebase_user_id='21')
     self.chat, _ = Chats.objects.get_or_create(userA=self.userA,
                                                userB=self.userB,
                                                chat_time=now(),
                                                opentok_session_id='111')
     self.client = Client()
     pass
示例#6
0
文件: test_user.py 项目: ansal10/five
 def test_generation_of_new_opentok_session_id(self, x1, x2, x3):
     user = Users()
     user.save()
     data = {"user_uuid": user.user_uuid}
     Chats(userA=user, userB=user, chat_time=now()).save()
     response = self.client.post('/fiveapp/get_session',
                                 content_type="application/json",
                                 **self.auth_headers(user.user_uuid, ''))
     assert response.status_code == 200
     res_data = json.loads(response.content)
     self.assertEqual(res_data['session']['sessionId'], 'session1')
     self.assertEqual(res_data['session']['token'], 'token1')
示例#7
0
文件: test_user.py 项目: ansal10/five
 def test_chat_time_for_user_with_expired_time(self):
     user = Users()
     user.save()
     data = {"user_uuid": user.user_uuid}
     chat_time = now() - timedelta(0, 300)
     Chats(userA=user, userB=user, chat_time=chat_time).save()
     response = self.client.post('/fiveapp/next_chat',
                                 content_type="application/json",
                                 **self.auth_headers(user.user_uuid, ''))
     assert response.status_code == 200
     res_data = json.loads(response.content)
     self.assertIsNone(res_data['chat'])
示例#8
0
文件: test_user.py 项目: ansal10/five
 def test_chat_time_for_user_with_future_time(self):
     user = Users()
     user.save()
     data = {"user_uuid": user.user_uuid}
     chat_time = now() + timedelta(0, 600)
     Chats(userA=user, userB=user, chat_time=chat_time).save()
     response = self.client.post('/fiveapp/next_chat',
                                 content_type="application/json",
                                 **self.auth_headers(user.user_uuid, ''))
     assert response.status_code == 200
     res_data = json.loads(response.content)
     self.assertIn('seconds_left_for_chat_start', res_data['chat'])
     self.assertNotIn('session_data', res_data['chat'])
示例#9
0
    def send_chat_reminder_notification(self, chat_id):
        chat = Chats.objects.get(id=chat_id)
        users = [chat.userA, chat.userB]
        for user in users:
            title = "Reminder for Your Scheduled Call in next few minutes"
            next_time_diff = "{} seconds".format(
                (chat.chat_time - now()).seconds)
            message = "Hi {}, Just a reminder that your next call is scheduled in {}". \
                format(user.name, next_time_diff)
            data_message = {}
            self.send_notificaiton(user.fcm_token, title, message,
                                   data_message)

        chat.chat_notified_times += 1
        chat.save()
示例#10
0
 def send_ringing_notification(self, fcm_token, gender, chat):
     data_message = {
         NOTIFICATION_TYPE: RINGING_NOTIFICATION,
         GENDER_KEY: gender,
         "chat_start_time": chat.chat_time.isoformat(),
         "chat_end_time":
         (chat.chat_time + timedelta(0, SECONDS)).isoformat(),
         "current_time": now().isoformat(),
         "gender": gender,
         "fcm_token": fcm_token
     }
     self.send_data_only_notification(fcm_token,
                                      "",
                                      "",
                                      data_message=data_message)
示例#11
0
文件: test_user.py 项目: ansal10/five
 def test_chat_time_for_user_with_scheduled_chat(self, x, y):
     user = Users(gender='male')
     other_user = Users(gender='female')
     other_user.save()
     user.save()
     data = {"user_uuid": user.user_uuid}
     Chats(userA=user, userB=other_user, chat_time=now()).save()
     response = self.client.post('/fiveapp/next_chat',
                                 content_type="application/json",
                                 **self.auth_headers(user.user_uuid, ''))
     assert response.status_code == 200
     res_data = json.loads(response.content)
     self.assertEqual(res_data['chat']['user']['gender'], 'female')
     self.assertIn('seconds_left_for_chat_start', res_data['chat'])
     self.assertIn('token', res_data['chat']['session_data'])
示例#12
0
 def save(self, *args, **kwargs):
     self.last_visited = now()
     super(Users, self).save(*args, **kwargs)