mirror of https://github.com/zulip/zulip.git
Add UserProfile callback for pointer updates
(imported from commit bfa9c15d82f092a1810cfcee1a88e1e292bc4cb8)
This commit is contained in:
parent
2a4c3b5bff
commit
66d7678423
|
@ -59,7 +59,8 @@ def get_log_recipient(recipient):
|
|||
|
||||
class Callbacks:
|
||||
TYPE_RECEIVE = 0
|
||||
TYPE_MAX = 1
|
||||
TYPE_POINTER_UPDATE = 1
|
||||
TYPE_MAX = 2
|
||||
|
||||
def __init__(self):
|
||||
self.table = {}
|
||||
|
@ -125,10 +126,22 @@ class UserProfile(models.Model):
|
|||
|
||||
callbacks_table.clear(self.user.id, Callbacks.TYPE_RECEIVE)
|
||||
|
||||
def update_pointer(self, new_pointer):
|
||||
global callbacks_table
|
||||
|
||||
for cb in callbacks_table.get(self.user.id, Callbacks.TYPE_POINTER_UPDATE):
|
||||
cb(new_pointer=new_pointer)
|
||||
|
||||
callbacks_table.clear(self.user.id, Callbacks.TYPE_POINTER_UPDATE)
|
||||
|
||||
def add_receive_callback(self, cb):
|
||||
global callbacks_table
|
||||
callbacks_table.add(self.user.id, Callbacks.TYPE_RECEIVE, cb)
|
||||
|
||||
def add_pointer_update_callback(self, cb):
|
||||
global callbacks_table
|
||||
callbacks_table.add(self.user.id, Callbacks.TYPE_POINTER_UPDATE, cb)
|
||||
|
||||
def __repr__(self):
|
||||
return "<UserProfile: %s %s>" % (self.user.email, self.realm)
|
||||
def __str__(self):
|
||||
|
|
|
@ -225,6 +225,8 @@ def update_pointer_backend(request, user_profile):
|
|||
user_profile.pointer = pointer
|
||||
user_profile.last_pointer_updater = request.session.session_key
|
||||
user_profile.save()
|
||||
|
||||
user_profile.update_pointer(pointer)
|
||||
return json_success()
|
||||
|
||||
def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False,
|
||||
|
|
Loading…
Reference in New Issue