zephyr_mirror: Handle syncing subs with invite-only streams.
(imported from commit ec8d0c0d13ff0a81fa4a5e1225e94e6dad997356)
This commit is contained in:
parent
9d55822cfb
commit
7f626d2bba
|
@ -675,18 +675,31 @@ def add_zulip_subscriptions(verbose):
|
||||||
zephyr_subscriptions.add(cls)
|
zephyr_subscriptions.add(cls)
|
||||||
|
|
||||||
if len(zephyr_subscriptions) != 0:
|
if len(zephyr_subscriptions) != 0:
|
||||||
res = zulip_client.add_subscriptions(list({"name": stream} for stream in zephyr_subscriptions))
|
res = zulip_client.add_subscriptions(list({"name": stream} for stream in zephyr_subscriptions),
|
||||||
|
authorization_errors_fatal=False)
|
||||||
if res.get("result") != "success":
|
if res.get("result") != "success":
|
||||||
logger.error("Error subscribing to streams:\n%s" % (res["msg"],))
|
logger.error("Error subscribing to streams:\n%s" % (res["msg"],))
|
||||||
return
|
return
|
||||||
|
|
||||||
already = res.get("already_subscribed")
|
already = res.get("already_subscribed")
|
||||||
new = res.get("subscribed")
|
new = res.get("subscribed")
|
||||||
|
unauthorized = res.get("unauthorized")
|
||||||
if verbose:
|
if verbose:
|
||||||
if already is not None and len(already) > 0:
|
if already is not None and len(already) > 0:
|
||||||
logger.info("\nAlready subscribed to: %s" % (", ".join(already.values()[0]),))
|
logger.info("\nAlready subscribed to: %s" % (", ".join(already.values()[0]),))
|
||||||
if new is not None and len(new) > 0:
|
if new is not None and len(new) > 0:
|
||||||
logger.info("\nSuccessfully subscribed to: %s" % (", ".join(new.values()[0]),))
|
logger.info("\nSuccessfully subscribed to: %s" % (", ".join(new.values()[0]),))
|
||||||
|
if unauthorized is not None and len(unauthorized) > 0:
|
||||||
|
logger.info("\n" + "\n".join(textwrap.wrap("""\
|
||||||
|
The following streams you have NOT been subscribed to,
|
||||||
|
because they have been configured in Zulip as invitation-only streams.
|
||||||
|
This was done at the request of users of these Zephyr classes, usually
|
||||||
|
because traffic to those streams is sent within the Zephyr world encrypted
|
||||||
|
via zcrypt (in Zulip, we achieve the same privacy goals through invitation-only streams).
|
||||||
|
If you wish to read these streams in Zulip, you need to contact the people who are
|
||||||
|
on these streams and already use Zulip. They can subscribe you to them via the
|
||||||
|
"streams" page in the Zulip web interface:
|
||||||
|
""")) + "\n\n %s" % (", ".join(unauthorized),))
|
||||||
|
|
||||||
if len(skipped) > 0:
|
if len(skipped) > 0:
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -273,8 +273,10 @@ class Client(object):
|
||||||
|
|
||||||
self.call_on_each_event(event_callback, ['message'])
|
self.call_on_each_event(event_callback, ['message'])
|
||||||
|
|
||||||
def _mk_subs(streams):
|
def _mk_subs(streams, **kwargs):
|
||||||
return {'subscriptions': streams}
|
result = kwargs
|
||||||
|
result['subscriptions'] = streams
|
||||||
|
return result
|
||||||
|
|
||||||
def _mk_rm_subs(streams):
|
def _mk_rm_subs(streams):
|
||||||
return {'delete': streams}
|
return {'delete': streams}
|
||||||
|
@ -293,6 +295,6 @@ Client._register('get_profile', method='GET', url='users/me')
|
||||||
Client._register('get_public_streams', method='GET', url='streams')
|
Client._register('get_public_streams', method='GET', url='streams')
|
||||||
Client._register('get_members', method='GET', url='users')
|
Client._register('get_members', method='GET', url='users')
|
||||||
Client._register('list_subscriptions', method='GET', url='users/me/subscriptions')
|
Client._register('list_subscriptions', method='GET', url='users/me/subscriptions')
|
||||||
Client._register('add_subscriptions', url='users/me/subscriptions', make_request=_mk_subs)
|
Client._register('add_subscriptions', url='users/me/subscriptions', make_request=_mk_subs)
|
||||||
Client._register('remove_subscriptions', method='PATCH', url='users/me/subscriptions', make_request=_mk_rm_subs)
|
Client._register('remove_subscriptions', method='PATCH', url='users/me/subscriptions', make_request=_mk_rm_subs)
|
||||||
Client._register('render_message', method='GET', url='messages/render')
|
Client._register('render_message', method='GET', url='messages/render')
|
||||||
|
|
Loading…
Reference in a new issue