hotfix: proposals, chatmembers, footnotes, etc
This commit is contained in:
@@ -75,7 +75,7 @@ async def create_chat(_, info, title="", members=[]):
|
||||
if chat:
|
||||
chat = json.loads(chat)
|
||||
if chat['title'] == "":
|
||||
print('[inbox] craeteChat found old chat')
|
||||
print('[inbox] createChat found old chat')
|
||||
print(chat)
|
||||
break
|
||||
if chat:
|
||||
|
@@ -124,15 +124,25 @@ async def load_messages_by(_, info, by, limit: int = 10, offset: int = 0):
|
||||
async def load_recipients(_, info, limit=50, offset=0):
|
||||
chat_users = []
|
||||
auth: AuthCredentials = info.context["request"].auth
|
||||
|
||||
try:
|
||||
onliners = await redis.execute("SMEMBERS", "users-online")
|
||||
chat_users += await followed_authors(auth.user_id)
|
||||
limit = limit - len(chat_users)
|
||||
except Exception:
|
||||
pass
|
||||
with local_session() as session:
|
||||
chat_users += session.query(User).where(User.emailConfirmed).limit(limit).offset(offset)
|
||||
members = []
|
||||
for a in chat_users:
|
||||
members.append({
|
||||
"id": a.id,
|
||||
"slug": a.slug,
|
||||
"userpic": a.userpic,
|
||||
"name": a.name,
|
||||
"lastSeen": a.lastSeen,
|
||||
"online": a.id in onliners
|
||||
})
|
||||
return {
|
||||
"members": chat_users,
|
||||
"members": members,
|
||||
"error": None
|
||||
}
|
||||
|
@@ -157,6 +157,23 @@ async def create_reaction(_, info, reaction={}):
|
||||
reaction['createdBy'] = auth.user_id
|
||||
with local_session() as session:
|
||||
r = Reaction.create(**reaction)
|
||||
shout = session.query(Shout).where(Shout.id == r.shout).one()
|
||||
|
||||
# Proposal accepting logix
|
||||
if r.replyTo is not None and \
|
||||
r.kind == ReactionKind.ACCEPT and \
|
||||
user_id in shout.dict()['authors']:
|
||||
replied_reaction = session.query(Reaction).when(Reaction.id == r.replyTo).first()
|
||||
if replied_reaction and replied_reaction.kind == ReactionKind.PROPOSE:
|
||||
if replied_reaction.range:
|
||||
old_body = shout.body
|
||||
start, end = replied_reaction.range.split(':')
|
||||
start = int(start)
|
||||
end = int(end)
|
||||
new_body = old_body[:start] + replied_reaction.body + old_body[end:]
|
||||
shout.body = new_body
|
||||
# TODO: update git version control
|
||||
|
||||
session.add(r)
|
||||
session.commit()
|
||||
|
||||
@@ -230,9 +247,9 @@ async def delete_reaction(_, info, reaction=None):
|
||||
return {"error": "access denied"}
|
||||
r.deletedAt = datetime.now(tz=timezone.utc)
|
||||
session.commit()
|
||||
return {
|
||||
"reaction": r
|
||||
}
|
||||
return {
|
||||
"reaction": r
|
||||
}
|
||||
|
||||
|
||||
@query.field("loadReactionsBy")
|
||||
|
@@ -1,48 +0,0 @@
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from sqlalchemy.orm import joinedload, aliased
|
||||
from sqlalchemy.sql.expression import desc, asc, select, func
|
||||
from base.orm import local_session
|
||||
from base.resolvers import query, mutation
|
||||
from base.exceptions import ObjectNotExist
|
||||
from orm.remark import Remark
|
||||
|
||||
|
||||
@mutation.field("createRemark")
|
||||
@login_required
|
||||
async def create_remark(_, info, slug, body):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
tt = Remark.create(slug=slug, body=body)
|
||||
session.commit()
|
||||
return
|
||||
|
||||
@mutation.field("updateRemark")
|
||||
@login_required
|
||||
async def update_remark(_, info, slug, body = ''):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
rmrk = session.query(Remark).where(Remark.slug == slug).one()
|
||||
if body:
|
||||
tt.body = body
|
||||
session.add(rmrk)
|
||||
session.commit()
|
||||
return
|
||||
|
||||
@mutation.field("deleteRemark")
|
||||
@login_required
|
||||
async def delete_remark(_, info, slug):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
rmrk = session.query(Remark).where(Remark.slug == slug).one()
|
||||
rmrk.remove()
|
||||
session.commit()
|
||||
return
|
||||
|
||||
@query.field("loadRemark")
|
||||
@login_required
|
||||
async def load_remark(_, info, slug):
|
||||
pass
|
Reference in New Issue
Block a user