create-msg-update
This commit is contained in:
parent
ec7f82c72f
commit
6d9ac5f272
|
@ -10,18 +10,18 @@ from services.inbox import ChatFollowing, MessageResult, MessagesStorage
|
|||
|
||||
@mutation.field("createMessage")
|
||||
@login_required
|
||||
async def create_message(_, info, chat_id: str, body: str, replyTo=None):
|
||||
async def create_message(_, info, chat: str, body: str, replyTo=None):
|
||||
""" create message with :body for :chat_id replying to :replyTo optionally """
|
||||
user = info.context["request"].user
|
||||
chat = await redis.execute("GET", f"chats/{chat_id}")
|
||||
chat = await redis.execute("GET", f"chats/{chat}")
|
||||
if not chat:
|
||||
return {
|
||||
"error": "chat not exist"
|
||||
}
|
||||
message_id = await redis.execute("GET", f"chats/{chat_id}/next_message_id")
|
||||
message_id = await redis.execute("GET", f"chats/{chat.id}/next_message_id")
|
||||
message_id = int(message_id)
|
||||
new_message = {
|
||||
"chatId": chat_id,
|
||||
"chatId": chat.id,
|
||||
"id": message_id,
|
||||
"author": user.slug,
|
||||
"body": body,
|
||||
|
@ -29,16 +29,16 @@ async def create_message(_, info, chat_id: str, body: str, replyTo=None):
|
|||
"createdAt": int(datetime.now().timestamp()),
|
||||
}
|
||||
await redis.execute(
|
||||
"SET", f"chats/{chat_id}/messages/{message_id}", json.dumps(new_message)
|
||||
"SET", f"chats/{chat.id}/messages/{message_id}", json.dumps(new_message)
|
||||
)
|
||||
await redis.execute("LPUSH", f"chats/{chat_id}/message_ids", str(message_id))
|
||||
await redis.execute("SET", f"chats/{chat_id}/next_message_id", str(message_id + 1))
|
||||
await redis.execute("LPUSH", f"chats/{chat.id}/message_ids", str(message_id))
|
||||
await redis.execute("SET", f"chats/{chat.id}/next_message_id", str(message_id + 1))
|
||||
|
||||
chat = json.loads(chat)
|
||||
users = chat["users"]
|
||||
for user_slug in users:
|
||||
await redis.execute(
|
||||
"LPUSH", f"chats/{chat_id}/unread/{user_slug}", str(message_id)
|
||||
"LPUSH", f"chats/{chat.id}/unread/{user_slug}", str(message_id)
|
||||
)
|
||||
|
||||
result = MessageResult("NEW", new_message)
|
||||
|
@ -157,6 +157,7 @@ async def message_generator(obj, info):
|
|||
|
||||
while True:
|
||||
msg = await asyncio.gather(*tasks)
|
||||
print('[inbox] %d new messages' % len(tasks))
|
||||
yield msg
|
||||
finally:
|
||||
await MessagesStorage.remove_chat(following_chat)
|
||||
|
|
|
@ -150,7 +150,7 @@ type Mutation {
|
|||
deleteChat(chatId: String!): Result!
|
||||
inviteChat(chatId: String!, userslug: String!): Result!
|
||||
|
||||
createMessage(chatId: String!, body: String!, replyTo: String): Result!
|
||||
createMessage(chat: String!, body: String!, replyTo: String): Result!
|
||||
updateMessage(chatId: String!, id: Int!, body: String!): Result!
|
||||
deleteMessage(chatId: String!, id: Int!): Result!
|
||||
markAsRead(chatId: String!, ids: [Int]!): Result!
|
||||
|
|
|
@ -40,7 +40,7 @@ class ViewStat:
|
|||
lock = asyncio.Lock()
|
||||
by_slugs = {}
|
||||
by_topics = {}
|
||||
period = 30 * 60 # 30 minutes
|
||||
period = 5 * 60 # 5 minutes
|
||||
transport = AIOHTTPTransport(url="https://ackee.discours.io/")
|
||||
client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user