hotfixes: migration logs, recipients online status

This commit is contained in:
tonyrewin 2023-01-25 09:32:59 +03:00
parent 82c6236a7f
commit 608901a260
4 changed files with 41 additions and 21 deletions

View File

@ -47,18 +47,27 @@ def create_author_from_app(app):
if not user: if not user:
print('[migration] creating user...') print('[migration] creating user...')
name = app.get('name') name = app.get('name')
slug = translit(name, "ru", reversed=True).lower() if name:
slug = re.sub('[^0-9a-zA-Z]+', '-', slug) slug = translit(name, "ru", reversed=True).lower()
# check if nameslug is used slug = re.sub('[^0-9a-zA-Z]+', '-', slug)
user = session.query(User).where(User.slug == slug).first() # check if slug is used
# get slug from email if slug:
if user: user = session.query(User).where(User.slug == slug).first()
slug = app['email'].split('@')[0]
user = session.query(User).where(User.slug == slug).first() # get slug from email
# one more try if user:
if user: slug = app['email'].split('@')[0]
slug += '-author' user = session.query(User).where(User.slug == slug).first()
user = session.query(User).where(User.slug == slug).first() # one more try
if user:
slug += '-author'
user = session.query(User).where(User.slug == slug).first()
else:
print(f'[migration] author @{slug} is found by email')
else:
print(f'[migration] author @{slug} is found')
# create user with application data # create user with application data
if not user: if not user:
@ -84,7 +93,7 @@ def create_author_from_app(app):
async def create_shout(shout_dict): async def create_shout(shout_dict):
s = Shout.create(**shout_dict) s = Shout.create(**shout_dict)
author = shout_dict['authors'][0] author = s.authors[0]
with local_session() as session: with local_session() as session:
srf = session.query(ShoutReactionsFollower).where( srf = session.query(ShoutReactionsFollower).where(
ShoutReactionsFollower.shout == s.id ShoutReactionsFollower.shout == s.id
@ -109,8 +118,9 @@ async def get_user(entry, storage):
userdata = anondict userdata = anondict
# cleanup slug # cleanup slug
slug = userdata.get("slug", "") slug = userdata.get("slug", "")
slug = re.sub('[^0-9a-zA-Z]+', '-', slug) if slug:
userdata["slug"] = slug slug = re.sub('[^0-9a-zA-Z]+', '-', slug)
userdata["slug"] = slug
user = await process_user(userdata, storage, user_oid) user = await process_user(userdata, storage, user_oid)
return user, user_oid return user, user_oid

View File

@ -11,7 +11,7 @@ class ReactionKind(Enumeration):
DISAGREE = 2 # -1 DISAGREE = 2 # -1
PROOF = 3 # +1 PROOF = 3 # +1
DISPROOF = 4 # -1 DISPROOF = 4 # -1
ASK = 5 # +0 bookmark ASK = 5 # +0
PROPOSE = 6 # +0 PROPOSE = 6 # +0
QUOTE = 7 # +0 bookmark QUOTE = 7 # +0 bookmark
COMMENT = 8 # +0 COMMENT = 8 # +0
@ -19,8 +19,8 @@ class ReactionKind(Enumeration):
REJECT = 0 # -1 REJECT = 0 # -1
LIKE = 11 # +1 LIKE = 11 # +1
DISLIKE = 12 # -1 DISLIKE = 12 # -1
REMARK = 13 REMARK = 13 # 0
FOOTNOTE = 14 FOOTNOTE = 14 # 0
# TYPE = <reaction index> # rating diff # TYPE = <reaction index> # rating diff

View File

@ -75,7 +75,7 @@ async def create_chat(_, info, title="", members=[]):
if chat: if chat:
chat = json.loads(chat) chat = json.loads(chat)
if chat['title'] == "": if chat['title'] == "":
print('[inbox] craeteChat found old chat') print('[inbox] createChat found old chat')
print(chat) print(chat)
break break
if chat: if chat:

View File

@ -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): async def load_recipients(_, info, limit=50, offset=0):
chat_users = [] chat_users = []
auth: AuthCredentials = info.context["request"].auth auth: AuthCredentials = info.context["request"].auth
try: try:
onliners = await redis.execute("SMEMBERS", "users-online")
chat_users += await followed_authors(auth.user_id) chat_users += await followed_authors(auth.user_id)
limit = limit - len(chat_users) limit = limit - len(chat_users)
except Exception: except Exception:
pass pass
with local_session() as session: with local_session() as session:
chat_users += session.query(User).where(User.emailConfirmed).limit(limit).offset(offset) 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 { return {
"members": chat_users, "members": members,
"error": None "error": None
} }