예제 #1
0
 def draw_chat_object(self, user_id, session_id, type_, **kwargs):
     with self._session_ as session:
         user = session.query(model.User).get(user_id)
         chat_session = session.query(model.Session).get(session_id)
         
         if user not in chat_session.users:
             raise Exception("You cannot add to this session")
         
         if type_ == "Text":
             result = model.Text(**kwargs)
         elif type_ == "Line":
             result = model.Line(**kwargs)
         elif type_ == "Shape":
             result = model.Shape(**kwargs)
         else:
             raise Exception("unknown type: {}".format(type_))
         
         result.owner = user
         chat_session.chat_objects.append(result)
         session.add(result)
         session.commit()
         
         msg = Protocol.chat_session_protocol(chat_session)
         
         for user in chat_session.users:
             self.broadcast_user(user.id, "drawn_chat_object", msg)
         
         return True
예제 #2
0
    def draw_chat_object(self, user_id, session_id, type_, **kwargs):
        with self._session_ as session:
            user = session.query(model.User).get(user_id)
            chat_session = session.query(model.Session).get(session_id)

            if user not in chat_session.users:
                raise Exception("You cannot add to this session")

            if type_ == "Text":
                result = model.Text(**kwargs)
            elif type_ == "Line":
                result = model.Line(**kwargs)
            elif type_ == "Shape":
                result = model.Shape(**kwargs)
            else:
                raise Exception("unknown type: {}".format(type_))

            result.owner = user
            chat_session.chat_objects.append(result)
            session.add(result)
            session.commit()

            msg = Protocol.chat_session_protocol(chat_session)

            for user in chat_session.users:
                self.broadcast_user(user.id, "drawn_chat_object", msg)

            return True
예제 #3
0
 def session_start(self, user_id):
     with self._session_ as session:
         chat_session = model.Session()
         session.add(chat_session)
         chat_session.users.append(session.query(model.User).get(user_id))
         session.commit()
         return Protocol.chat_session_protocol(chat_session)
예제 #4
0
 def login(self, username, password):
     with self._session_ as session:
         user = session.query(model.User).filter_by(username=username, password=password).first()
         if user is None:
             raise Exception("No such user or password!")
         self._set_user_(user)
         return Protocol.user_protocol(user)
예제 #5
0
 def session_start(self, user_id):
     with self._session_ as session:
         chat_session = model.Session()
         session.add(chat_session)
         chat_session.users.append(session.query(model.User).get(user_id))
         session.commit()
         return Protocol.chat_session_protocol(chat_session)
예제 #6
0
 def login(self, username, password):
     with self._session_ as session:
         user = session.query(model.User).filter_by(
             username=username, password=password).first()
         if user is None:
             raise Exception("No such user or password!")
         self._set_user_(user)
         return Protocol.user_protocol(user)
예제 #7
0
    def get_chat_session(self, user_id, session_id):
        with self._session_ as session:
            user = session.query(model.User).get(user_id)
            chat_session = session.query(model.Session).get(session_id)

            if user not in chat_session.users:
                raise Exception("You cannot view this session")

            return Protocol.chat_session_protocol(chat_session)
예제 #8
0
 def get_chat_session(self, user_id, session_id):
     with self._session_ as session:
         user = session.query(model.User).get(user_id)
         chat_session = session.query(model.Session).get(session_id)
         
         if user not in chat_session.users:
             raise Exception("You cannot view this session")
         
         return Protocol.chat_session_protocol(chat_session)
예제 #9
0
 def register(self, username, password):
     with self._session_ as session:
         user = model.User(username=username, password=password)
         session.add(user)
         try:
             session.commit()
             self._set_user_(user)
         except IntegrityError:
             raise Exception("username already exists")
         return Protocol.user_protocol(user)
예제 #10
0
 def register(self, username, password):
     with self._session_ as session:
         user = model.User(username=username, password=password)
         session.add(user)
         try:
             session.commit()
             self._set_user_(user)
         except IntegrityError:
             raise Exception("username already exists")
         return Protocol.user_protocol(user)
예제 #11
0
    def delete_chat_object(self, user_id, chat_object_id):
        with self._session_ as session:
            user = session.query(model.User).get(user_id)
            chat_object = session.query(model.ChatObject).get(chat_object_id)

            if user not in chat_object.chat_session.users:
                raise Exception("You cannot add to this session")

            chat_session = chat_object.chat_session

            session.delete(chat_object)
            session.commit()

            msg = Protocol.chat_session_protocol(chat_session)

            for user in chat_session.users:
                self.broadcast_user(user.id, "deleted_chat_object", msg)

            return True
예제 #12
0
    def add_user_to_session(self, user_id, session_id, friend_id):
        with self._session_ as session:
            user = session.query(model.User).get(user_id)
            friend = session.query(model.User).get(friend_id)
            chat_session = session.query(model.Session).get(session_id)

            session_users = list(chat_session.users)
            assert user in session_users
            assert friend not in session_users

            chat_session.users.append(friend)
            session.commit()

            msg = Protocol.chat_session_protocol(chat_session)

            for user in chat_session.users:
                self.broadcast_user(user.id, "drawn_chat_object", msg)

            return True
예제 #13
0
 def delete_chat_object(self, user_id, chat_object_id):
     with self._session_ as session:
         user = session.query(model.User).get(user_id)
         chat_object = session.query(model.ChatObject).get(chat_object_id)
         
         if user not in chat_object.chat_session.users:
             raise Exception("You cannot add to this session")
         
         chat_session = chat_object.chat_session
         
         session.delete(chat_object)
         session.commit()
         
         msg = Protocol.chat_session_protocol(chat_session)
         
         for user in chat_session.users:
             self.broadcast_user(user.id, "deleted_chat_object", msg)
         
         return True
예제 #14
0
 def add_user_to_session(self, user_id, session_id, friend_id):
     with self._session_ as session:
         user = session.query(model.User).get(user_id)
         friend = session.query(model.User).get(friend_id)
         chat_session = session.query(model.Session).get(session_id)
         
         session_users = list(chat_session.users)
         assert user in session_users
         assert friend not in session_users
         
         chat_session.users.append(friend)
         session.commit()
         
         msg = Protocol.chat_session_protocol(chat_session)
         
         for user in chat_session.users:
             self.broadcast_user(user.id, "drawn_chat_object", msg)
         
         return True
예제 #15
0
 def _set_user_(self, user):
     if self._current_client_:
         self._current_client_.user_id = user.id if user else None
     if user:
         self._online[user.id] = Protocol.friend_protocol(user)
         self.broadcast("online", self._online.values())
예제 #16
0
 def get_friend_by_id(self, user_id, friend_id):
     with self._session_ as session:
         friend = session.query(model.User).get(friend_id)
         
         return Protocol.friend_protocol(friend);
예제 #17
0
 def session_end(self, user_id, session_id):
     with self._session_ as session:
         chat_session = session.query(model.Session).get(session_id)
         chat_session.ended = True
         session.commit()
         return Protocol.chat_session_protocol(chat_session)
예제 #18
0
 def session_end(self, user_id, session_id):
     with self._session_ as session:
         chat_session = session.query(model.Session).get(session_id)
         chat_session.ended = True
         session.commit()
         return Protocol.chat_session_protocol(chat_session)
예제 #19
0
    def get_friend_by_id(self, user_id, friend_id):
        with self._session_ as session:
            friend = session.query(model.User).get(friend_id)

            return Protocol.friend_protocol(friend)
예제 #20
0
 def _set_user_(self, user):
     if self._current_client_:
         self._current_client_.user_id = user.id if user else None
     if user:
         self._online[user.id] = Protocol.friend_protocol(user) 
         self.broadcast("online", self._online.values())