def _userdata(self, _conversation, _member_list): _redis = self._redis _conversation_uuid = _conversation["uuid"] _user_uuid = _conversation["user_uuid"] _conversation_name = _conversation.get("conversation_name") _conversation_icon = _conversation.get("conversation_icon") _conversation_type = _conversation.get("conversation_type") if _conversation_type == CONVERSATION_TYPE.P2S: # i is service users for _i in _member_list: self._datarow(_i, None, _conversation_type, _conversation_uuid, _conversation_name, _conversation_icon) # only one member it is a portal user if len(_member_list) == 1: _user_key = DeviceUser.__tablename__ + ".uuid." + _member_list[0] _conversation_icon = _redis.hget(_user_key, "user_icon") _conversation_name = _redis.hget(_user_key, "user_fullname") # multiple service users may come from a group or whole app team if len(_member_list) > 1: _group_users = copy.deepcopy(_member_list) _group_users.append(_user_uuid) _conversation_icon = create_group_icon(_redis, _group_users) if self._group_uuid != None: _group_key = OrgGroup.__tablename__ + ".uuid." + self._group_uuid _conversation_name = _redis.hget(_group_key, "group_name") else: _app_key = AppInfo.__tablename__ + ".uuid." + self._app_uuid _conversation_name = _redis.hget(_app_key, "app_name") self._datarow(_user_uuid, None, _conversation_type, _conversation_uuid, _conversation_name, _conversation_icon) self._return_name = _conversation_name self._return_icon = _conversation_icon return if _conversation_type == CONVERSATION_TYPE.S2S: # ONE TO ONE if len(_member_list) == 1: _key = DeviceUser.__tablename__ + ".uuid." + _member_list[0] _other = _redis.hmget(_key, ["user_icon", "user_fullname"]) _other_icon = _other[0] _other_fullname = _other[1] self._datarow(_user_uuid, self._user_fullname, _conversation_type, _conversation_uuid, _other_fullname, _other_icon) self._datarow(_member_list[0], _other_fullname, _conversation_type, _conversation_uuid, self._user_fullname, self._user_icon) self._return_name = _other_fullname self._return_icon = _other_icon return # GROUP if len(_member_list) > 1: _member_list.append(_user_uuid) for _i in _member_list: self._datarow(_i, None, _conversation_type, _conversation_uuid, _conversation_name, _conversation_icon) return return
def _create_conversation(self, _request, _rule, _target_services): _rule_uuid = None if _rule != None: _rule_uuid = _rule.get("uuid") _app_uuid = _request.get("app_uuid") _user_uuid = _request.get("user_uuid") _key = DeviceUser.__tablename__ + ".uuid." + _user_uuid _portal_user_name = self.redis.hget(_key, "user_fullname") _portal_user_icon = self.redis.hget(_key, "user_icon") _group_icon = create_group_icon(self.redis, _target_services) _assigned_uuid = None if len(_target_services) == 1: _assigned_uuid = _target_services[0] _conversation_uuid = str(uuid.uuid1()) _row = ConversationInfo(uuid=_conversation_uuid, app_uuid=_app_uuid, user_uuid=_user_uuid, assigned_uuid=_assigned_uuid, rule_uuid=_rule_uuid, status=CONVERSATION_STATUS.NEW, conversation_type=CONVERSATION_TYPE.P2S) _row.async_add(self.redis) _row.create_redis_keys(self.redis) _conversation_name = [] for _user in _target_services: _key = DeviceUser.__tablename__ + ".uuid." + _user _conversation_name.append(self.redis.hget(_key, "user_fullname")) _conversation_name = ",".join(_conversation_name) _row = ConversationUserData( uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user_uuid, conversation_uuid=_conversation_uuid, conversation_name=_conversation_name, conversation_icon=_group_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) for _user in _target_services: _row = ConversationUserData( uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user, conversation_uuid=_conversation_uuid, conversation_name=_portal_user_name, conversation_icon=_portal_user_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) return
def _create_conversation(self, _request, _rule, _target_services): _rule_uuid = None if _rule != None: _rule_uuid = _rule.get("uuid") _app_uuid = _request.get("app_uuid") _user_uuid = _request.get("user_uuid") _key = DeviceUser.__tablename__ + ".uuid." + _user_uuid _portal_user_name = self.redis.hget(_key, "user_fullname") _portal_user_icon = self.redis.hget(_key, "user_icon") _group_icon = create_group_icon(self.redis, _target_services) _assigned_uuid = None if len(_target_services) == 1: _assigned_uuid = _target_services[0] _conversation_uuid = str(uuid.uuid1()) _row = ConversationInfo(uuid=_conversation_uuid, app_uuid=_app_uuid, user_uuid=_user_uuid, assigned_uuid=_assigned_uuid, rule_uuid=_rule_uuid, status=CONVERSATION_STATUS.NEW, conversation_type=CONVERSATION_TYPE.P2S) _row.async_add(self.redis) _row.create_redis_keys(self.redis) _conversation_name = [] for _user in _target_services: _key = DeviceUser.__tablename__ + ".uuid." + _user _conversation_name.append(self.redis.hget(_key, "user_fullname")) _conversation_name = ",".join(_conversation_name) _row = ConversationUserData(uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user_uuid, conversation_uuid=_conversation_uuid, conversation_name=_conversation_name, conversation_icon=_group_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) for _user in _target_services: _row = ConversationUserData(uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user, conversation_uuid=_conversation_uuid, conversation_name=_portal_user_name, conversation_icon=_portal_user_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) return
def _all(self, _request): _app_uuid = _request.get("app_uuid") _user_uuid = _request.get("user_uuid") _key = AppUserData.__tablename__ + ".app_uuid." + _app_uuid + ".is_service_user.True" _allocated_users = self.redis.smembers(_key) if _allocated_users == None or len(_allocated_users) == 0: self._ack_error(_device_uuid, DIS_ERR.CONVERSATION_NO_USER) return _key = DeviceUser.__tablename__ + ".uuid." + _user_uuid _portal_user_name = self.redis.hget(_key, "user_fullname") _portal_user_icon = self.redis.hget(_key, "user_icon") _group_icon = create_group_icon(self.redis, _allocated_users) _assigned_uuid = None if len(_allocated_users) == 1: _assigned_uuid = list(_allocated_users)[0] _conversation_uuid = str(uuid.uuid1()) _row = ConversationInfo(uuid=_conversation_uuid, app_uuid=_app_uuid, user_uuid=_user_uuid, assigned_uuid=_assigned_uuid, status=CONVERSATION_STATUS.NEW, conversation_type=CONVERSATION_TYPE.P2S) _row.async_add(self.redis) _row.create_redis_keys(self.redis) _conversation_name = [] for _user in _allocated_users: _key = DeviceUser.__tablename__ + ".uuid." + _user _conversation_name.append(self.redis.hget(_key, "user_fullname")) _conversation_name = ",".join(_conversation_name) _row = ConversationUserData(uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user_uuid, conversation_uuid=_conversation_uuid, conversation_name=_conversation_name, conversation_icon=_group_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) for _user in _allocated_users: _row = ConversationUserData(uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user, conversation_uuid=_conversation_uuid, conversation_name=_portal_user_name, conversation_icon=_portal_user_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add(self.redis) _row.create_redis_keys(self.redis) return
def _all(self, _app_uuid, _user_uuid, _device_uuid): _key = AppUserData.__tablename__ + ".app_uuid." + _app_uuid + \ ".is_service_user.True" _allocated_users = self.redis.smembers(_key) if _allocated_users == None or len(_allocated_users) == 0: self._ack_error(_device_uuid) return _key = DeviceUser.__tablename__ + ".uuid." + _user_uuid _portal_user_name = self.redis.hget(_key, "user_fullname") _portal_user_icon = self.redis.hget(_key, "user_icon") _group_icon = create_group_icon(self.redis, _allocated_users) _conversation_uuid = str(uuid.uuid1()) _row = CoversationInfo(uuid=_conversation_uuid, app_uuid=_app_uuid, user_uuid=_user_uuid, status=CONVESATION_STATUS.NEW, conversation_type=CONVERSATION_TYPE.P2S) _row.async_add() _row.create_redis_keys(self.redis) _conversation_name = [] for _user in _allocated_users: _key = DeviceUser.__tablename__ + ".uuid." + _user _conversation_name.append(self.redis.hget(_key, "user_fullname")) _conversation_name = ",".join(_conversation_name) _row = ConversationUserData( uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user_uuid, conversation_uuid=_conversation_uuid, conversation_name=_conversation_name, conversation_icon=_group_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add() _row.create_redis_keys(self.redis) for _user in _allocated_users: _row = ConversationUserData( uuid=str(uuid.uuid1()), app_uuid=_app_uuid, user_uuid=_user, conversation_uuid=_conversation_uuid, conversation_name=_portal_user_name, conversation_icon=_portal_user_icon, conversation_status=CONVERSATION_STATUS.NEW) _row.async_add() _row.create_redis_keys(self.redis) self._ack_success(_device_uuid, _conversation_uuid) return
def update_group_icon(_redis, _group_uuid): _key = OrgUserGroupData.__tablename__ + ".group_uuid." + _group_uuid _users = _redis.smembers(_key) _group_icon = None if len(_users) == 0: _group_icon = create_user_icon(_group_uuid) else: _group_icon = create_group_icon(_redis, _users) _row = OrgGroup(uuid=_group_uuid, group_icon=_group_icon) _row.update_redis_keys(_redis) _row.async_update() return
def _create(self): _key = DeviceUser.__tablename__ + ".uuid." + self._user_uuid _user = self._redis.hmget(_key, ["user_icon", "user_fullname"]) self._user_icon = _user[0] self._user_fullname = _user[1] _conv_icon = self._user_icon if self._conv_type != CONVERSATION_TYPE.P2S and len( self._member_list) > 1: _group_users = copy.deepcopy(self._member_list) _group_users.append(self._user_uuid) _conv_icon = create_group_icon(self._redis, _group_users) self._return_icon = _conv_icon self._return_name = self._conv_name _list = self._member_list if self._conv_type == CONVERSATION_TYPE.P2S: if _list == None or len(_list) == 0: _list = self._get_conversation_user_list() if _list == None or len(_list) == 0: self._handler.setErrorCode(API_ERR.NO_CONVERSATION_MEMBER) return None _assigned_uuid = None if len(_list) == 1: _assigned_uuid = _list[0] _conv_uuid = str(uuid.uuid1()) _values = { "uuid": _conv_uuid, "user_uuid": self._user_uuid, "assigned_uuid": _assigned_uuid, "app_uuid": self._app_uuid, "group_uuid": self._group_uuid, "conversation_name": self._conv_name, "conversation_icon": _conv_icon, "conversation_type": self._conv_type, "status": CONVERSATION_STATUS.NEW, } # create it _row = ConversationInfo(**_values) _row.async_add() _row.create_redis_keys(self._redis) self._userdata(_values, copy.deepcopy(_list)) return self._result_data(_values, _list)
def _create(self): _key = DeviceUser.__tablename__ + ".uuid." + self._user_uuid _user = self._redis.hmget(_key, ["user_icon", "user_fullname"]) self._user_icon = _user[0] self._user_fullname = _user[1] _conv_icon = self._user_icon if self._conv_type != CONVERSATION_TYPE.P2S and len(self._member_list) > 1: _group_users = copy.deepcopy(self._member_list) _group_users.append(self._user_uuid) _conv_icon = create_group_icon(self._redis, _group_users) self._return_icon = _conv_icon self._return_name = self._conv_name _list = self._member_list if self._conv_type == CONVERSATION_TYPE.P2S: if _list == None or len(_list) == 0: _list = self._get_conversation_user_list() if _list == None or len(_list) == 0: self._handler.setErrorCode(API_ERR.NO_CONVERSATION_MEMBER) return None _assigned_uuid = None if len(_list) == 1: _assigned_uuid = _list[0] _conv_uuid = str(uuid.uuid1()) _values = { "uuid": _conv_uuid, "user_uuid": self._user_uuid, "assigned_uuid": _assigned_uuid, "app_uuid": self._app_uuid, "group_uuid": self._group_uuid, "conversation_name": self._conv_name, "conversation_icon": _conv_icon, "conversation_type": self._conv_type, "status": CONVERSATION_STATUS.NEW, } # create it _row = ConversationInfo(**_values) _row.async_add(self._redis) _row.create_redis_keys(self._redis) self._userdata(_values, copy.deepcopy(_list)) return self._result_data(_values, _list)