diff --git a/migration/tables/comments.py b/migration/tables/comments.py index 89003324..febe4c85 100644 --- a/migration/tables/comments.py +++ b/migration/tables/comments.py @@ -45,7 +45,7 @@ def migrate(entry): with local_session() as session: shout = session.query(Shout).filter(Shout.old_id == entry['_id']).first() if not shout: shout = session.query(Shout).first() - author = session.query(User).filter(User.old_id == entry['_id']).first() + author = session.query(User).filter(User.old_id == entry['_id']).first() # FIXME comment_dict = { 'old_id': entry['_id'], 'author': author.id if author else 0, diff --git a/orm/message.py b/orm/message.py index f2ef48e0..e9b8a714 100644 --- a/orm/message.py +++ b/orm/message.py @@ -10,7 +10,8 @@ from orm.base import Base class Message(Base): __tablename__ = 'message' - author: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender") + fromUser: int = Column(ForeignKey("user.id"), nullable=False, comment="Sender") + chatRoom: int = Column(Integer, nullable=false, comment="Chatroom") body: str = Column(String, nullable=False, comment="Body") createdAt = Column(DateTime, nullable=False, default = datetime.now, comment="Created at") updatedAt = Column(DateTime, nullable=True, comment="Updated at") diff --git a/resolvers/zine.py b/resolvers/zine.py index 449ae380..3794a9ae 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -14,7 +14,6 @@ from datetime import datetime, timedelta from pathlib import Path from sqlalchemy import select, func, desc, and_ from sqlalchemy.orm import selectinload -import pprint class GitTask: @@ -353,7 +352,7 @@ async def view_shout(_, info, shout_id): @query.field("getShoutBySlug") async def get_shout_by_slug(_, info, slug): all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections] - pprint(all_fields) + print(all_fields) selected_fields = set(["authors", "comments", "topics"]).intersection(all_fields) select_options = [selectinload(getattr(Shout, field)) for field in selected_fields] diff --git a/schema.graphql b/schema.graphql index b4b339d8..8b3885bf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -68,10 +68,16 @@ type MessageWithStatus { message: Message! } +type ChatRoomResult { + messages: [Message]! + room: ChatRoom! +} + ################################### Mutation type Mutation { # message + getRoom(chatRoom: Int!): ChatRoomResult! # TODO: private rooms protection createMessage(body: String!, replyTo: Int): MessageResult! updateMessage(id: Int!, body: String!): MessageResult! deleteMessage(messageId: Int!): Result! @@ -162,7 +168,7 @@ type Query { type Subscription { messageChanged: MessageWithStatus! - + chatUpdated: ChatRoomResult! onlineUpdated: [User!]! shoutUpdated: Shout! userUpdated: User! @@ -237,6 +243,7 @@ type User { type Message { author: Int! + chatRoom: Int! body: String! createdAt: DateTime! id: Int! @@ -245,6 +252,13 @@ type Message { visibleForUsers: [Int]! } +type ChatRoom { + id: Int! + createdAt: DateTime! + updatedAt: DateTime! + notes: String +} + type Comment { id: Int! author: User!