src/pyams_notify_ws/notify.py
changeset 25 bdb57ba75245
parent 20 03c3572a16ad
equal deleted inserted replaced
24:4f59f94ad901 25:bdb57ba75245
    53             pass
    53             pass
    54         else:
    54         else:
    55             action = message.get('action')
    55             action = message.get('action')
    56             if action == 'notify':
    56             if action == 'notify':
    57                 # dispatch notification to subscribers
    57                 # dispatch notification to subscribers
       
    58                 host = message.get('host')
    58                 source = message.get('source', {}).get('id')
    59                 source = message.get('source', {}).get('id')
    59                 target = message.get('target', {}).get('principals', ())
    60                 target = message.get('target', {}).get('principals', ())
    60                 clean_message = message.copy()
    61                 clean_message = message.copy()
    61                 clean_message.pop('target')
    62                 clean_message.pop('target')
    62                 json_message = json.dumps(clean_message)
    63                 json_message = json.dumps(clean_message)
    63                 async with users_lock:
    64                 async with users_lock:
    64                     for connection, subscription in users.items():
    65                     for connection, subscription in users.items():
       
    66                         # don't send notification to other hosts
       
    67                         if host and (host != subscription.host):
       
    68                             continue
    65                         # don't send notification to emitter
    69                         # don't send notification to emitter
    66                         if source and (source == subscription.principal['id']):
    70                         if source and (source == subscription.principal['id']):
    67                             continue
    71                             continue
    68                         if subscription.filter_target(target):
    72                         if subscription.filter_target(target):
    69                             await connection.send(json_message)
    73                             await connection.send(json_message)