コード例 #1
0
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
    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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
    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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
    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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
    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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
    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
ファイル: control.py プロジェクト: OliverDashiell/DrawChat
 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())