def unsubscribe(self, id): loggedInUser = helper.getLoggedInUser() if user.isSubscribed(id): stream.unsubscribe(id, loggedInUser["_id"]) return ack else: return error("You are not subscribed to that stream.", NotSubscribedError)
def subscribe(self, id): loggedInUser = helper.getLoggedInUser() if stream.canSubscribe(id, loggedInUser["_id"]): if user.isSubscribed(loggedInUser["_id"], id): return error("You are already subscribed to that stream.", AlreadySubscribedError) else: stream.subscribe(id, loggedInUser["_id"]) return ack else: return error("Operation not permitted. You don't have permission to subscribe to this stream.", PermissionError)
def add(self, id, userName): loggedInUser = helper.getLoggedInUser() if stream.canAdmin(id, loggedInUser["_id"]): otherId = user.idForName(userName) if user.isSubscribed(otherId, id): return error("User %s is already subscribed to that stream." % userName, AlreadySubscribedError) else: stream.invite(id, loggedInUser["_id"], otherId) return ack else: return error("Operation not permitted. You don't have permission to subscribe to this stream.", PermissionError)