Commits

Josh VanderLinden  committed 19c6675

Trying to limit the number of messages that get sent over the wire

  • Participants
  • Parent commits f904f1e

Comments (0)

Files changed (2)

 # Maintainer: Josh VanderLinden <arch@cloudlery.com>
 pkgname=zedify
-pkgver=20130222
+pkgver=20130223
 pkgrel=1
 pkgdesc="Deliver message notifications to remote machines"
 arch=('any')

File weechat/zedifier.py

 #!/usr/bin/env python2
 
+import time
+
 import zmq
 
 from weechat import buffer_get_string as get, config_get_plugin as cfg
 
 
 __author__ = 'codekoala'
-__version__ = '0.0.3'
+__version__ = '0.0.4'
 __descr__ = 'Deliver message notifications to remote machines'
 
 weechat.register('zedifier', __author__, __version__, 'GPL3',
 
     def __init__(self):
         self.configure()
+        self.last_msg = None
+        self.last_time = None
 
         self.pub = ctx.socket(zmq.PUSH)
         self.connect()
             send = True
 
         if send:
-            self.pub.send_json({
+            self.send({
                 'event': event,
                 'user': prefix,
                 'chat': chat,
 
     def typing(self, data, signal, buf):
         name = buffer_name(buf)
-        self.pub.send_json({
+        self.send({
             'event': 'typing',
             'in_buffer': name,
         })
 
     def buffer_switch(self, data, signal, buf):
         name = buffer_name(buf)
-        self.pub.send_json({
+        self.send({
             'event': 'buffer_switch',
             'to_buffer': name,
         })
 
     def window_switch(self, data, signal, win):
         name = window_name(win)
-        self.pub.send_json({
+        self.send({
             'event': 'window_switch',
             'to_window': name,
         })
 
         return OK
 
+    def send(self, obj):
+        """
+        Only send the message if it's changed or been more than 15 seconds
+        since the last message.
+        """
+
+        now = time.time()
+
+        if self.last_time is None or now - self.last_time > 15:
+            if obj != self.last_msg:
+                self.pub.send_json(obj)
+
+        self.last_msg = obj
+        self.last_time = now
+
     def close(self):
         """Clean up connections"""