Example #1
0
class MessageListResource(WigoDbListResource):
    model = Message

    def get(self):
        raise NotImplementedError()

    @api.expect(Message.to_doc_list_model(api))
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def post(self):
        return super(MessageListResource, self).post()
Example #2
0
class ConversationWithUserResource(WigoResource):
    model = Message

    @user_token_required
    @check_last_modified('user', 'last_message_change')
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def get(self, with_user_id, headers):
        with_user = User.find(with_user_id)
        count, page, instances = self.select().user(
            g.user).to_user(with_user).execute()
        return self.serialize_list(self.model, instances, count,
                                   page), 200, headers

    @user_token_required
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def delete(self, with_user_id):
        Message.delete_conversation(g.user, User.find(with_user_id))
        return {'success': True}
Example #3
0
class ConversationsResource(WigoResource):
    model = Message

    @user_token_required
    @check_last_modified('user', 'last_message_change')
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def get(self, headers):
        count, page, instances = self.select().user(g.user).execute()
        return self.serialize_list(self.model, instances, count,
                                   page), 200, headers
Example #4
0
class MessageResource(WigoDbResource):
    model = Message

    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def get(self, model_id):
        return super(MessageResource, self).get(model_id)

    def check_get(self, message):
        super(MessageResource, self).check_get(message)
        if message.user_id != g.user.id:
            abort(403, message='Can only view your own messages')

    @api.expect(Message.to_doc_list_model(api))
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def post(self, model_id):
        return super(MessageResource, self).post(model_id)

    def delete(self, model_id):
        abort(501, message='Not implemented')
Example #5
0
class NotificationsResource(WigoResource):
    model = Notification

    @user_token_required
    @check_last_modified('user', 'last_notification')
    @api.response(200, 'Success', model=Message.to_doc_list_model(api))
    def get(self, user_id, headers):
        user = g.user
        group = g.group

        query = self.select().user(user)
        query = query.min(epoch(group.get_day_end() - timedelta(days=15)))
        query = query.max(time())
        count, page, instances = query.execute()

        return self.serialize_list(self.model, instances, count,
                                   page), 200, headers
Example #6
0
    def __get_conversation(self):
        if self._to_user:
            return self.__get_page(
                skey(self._user, 'conversation', self._to_user.id))
        else:
            query = User.select().key(skey(self._user, 'conversations')).limit(
                self._limit).page(self._page).order(self._order)

            count, page, users = query.execute()

            message_ids = []
            for user in users:
                last_message_id = self.db.get(
                    skey(self._user, 'conversation', user.id, 'last_message'))
                message_ids.append(last_message_id)

            return count, page, Message.find(message_ids)
Example #7
0
def notify_on_message(message_id):
    message = Message.find(message_id)
    user = message.to_user
    from_user = message.user

    message_text = message.message
    if message_text and len(message_text) > 1000:
        message_text = message_text[0:1000]

    data = {
        'message_id': message_id,
        'navigate': '/messages/{}'.format(from_user.id),
        'sound': 'chord',
        'badge': 1,
        'alert': {
            'body': '{}: {}'.format(from_user.full_name.encode('utf-8'), message_text.encode('utf-8')),
        }
    }

    where = {
        'wigo_id': user.id,
        'deviceType': 'ios',
        'api_version_num': {
            '$gte': 2
        }
    }

    if user.is_ios_push_enabled():
        push.alert(data=data, where=dict(where, **{
            'deviceType': 'ios'
        }), enterprise=user.enterprise)

    if user.is_android_push_enabled():
        push.alert(data=dict(data, **{
            'action': 'com.whoisgoingout.wigo.ACTION_MESSAGE'
        }), where=dict(where, **{
            'deviceType': 'android'
        }), enterprise=user.enterprise)
Example #8
0
 def delete(self, with_user_id):
     Message.delete_conversation(g.user, User.find(with_user_id))
     return {'success': True}