Request: Limit messages sent per user per time period

Issue #68 closed
Daniel Stanton created an issue

I think users can send as many messages as they want - unless I missed the functionality to limit this?

Comments (4)

  1. Patrick Samson repo owner

    Right, there is no limit. But you should be able to implement your own policy with some DB requests.

  2. Former user Account Deleted

    I've implemented this before. Its kind of a hack but under postman/models.py -> Class Message -> I added this method

    @classmethod
    def get_dates_of_last_two_messages_by_sender(cls,sender):
        latest_two_messages = cls.objects.filter(sender=sender).order_by('-sent_at')[:1]
        try:
            datetime1 = latest_two_messages[0].sent_at
        except IndexError:
                return
    
        time_dif = datetime.datetime.now(tz=pytz.utc) - datetime1
        if time_dif.total_seconds()<25:
                print datetime1
                print time_dif.total_seconds()
                raise ValidationError(ugettext("Please slow down sending messages."))
    

    And then under the clean function of that same class I added

    self.get_dates_of_last_two_messages_by_sender(sender=self.sender)
    
  3. Daniel Stanton reporter

    I was thinking something similar. When a user sends a message, if a rate limit is set (in seconds) in settings.py, then get the datetime of the last sent message and compare it to the current datetime. Send if they're passed the rate limit period, feed back to user if not.

    POSTMAN_RATE_LIMIT would be for users mailing other users for the first time (to reduce spam) POSTMAN_RATE_LIMIT_CONVERSATION would be for users continuing a conversation (to reduce sending duplicate messages)

    I'm suggesting it because it seems like an effective way to counter spam and repeat sending of the same email, is common in messaging implementations for other platforms, and would benefit many users, rather than just my own use case. Is it not worth adding?

  4. Log in to comment