mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
matrix user id on user profiles
This commit is contained in:
parent
71d66905bd
commit
7966a91334
8 changed files with 50 additions and 1 deletions
|
@ -181,6 +181,8 @@ def user_profile(actor):
|
||||||
"mediaType": "text/markdown"
|
"mediaType": "text/markdown"
|
||||||
}
|
}
|
||||||
actor_data['summary'] = markdown_to_html(user.about)
|
actor_data['summary'] = markdown_to_html(user.about)
|
||||||
|
if user.matrix_user_id:
|
||||||
|
actor_data['matrixUserId'] = user.matrix_user_id
|
||||||
resp = jsonify(actor_data)
|
resp = jsonify(actor_data)
|
||||||
resp.content_type = 'application/activity+json'
|
resp.content_type = 'application/activity+json'
|
||||||
return resp
|
return resp
|
||||||
|
|
|
@ -304,6 +304,7 @@ def actor_json_to_model(activity_json, address, server):
|
||||||
user = User(user_name=activity_json['preferredUsername'],
|
user = User(user_name=activity_json['preferredUsername'],
|
||||||
email=f"{address}@{server}",
|
email=f"{address}@{server}",
|
||||||
about_html=parse_summary(activity_json),
|
about_html=parse_summary(activity_json),
|
||||||
|
matrix_user_id=activity_json['matrixUserId'] if 'matrixUserId' in activity_json else '',
|
||||||
created=activity_json['published'] if 'published' in activity_json else utcnow(),
|
created=activity_json['published'] if 'published' in activity_json else utcnow(),
|
||||||
ap_id=f"{address}@{server}",
|
ap_id=f"{address}@{server}",
|
||||||
ap_public_url=activity_json['id'],
|
ap_public_url=activity_json['id'],
|
||||||
|
|
|
@ -239,6 +239,7 @@ class User(UserMixin, db.Model):
|
||||||
about = db.Column(db.Text) # markdown
|
about = db.Column(db.Text) # markdown
|
||||||
about_html = db.Column(db.Text) # html
|
about_html = db.Column(db.Text) # html
|
||||||
keywords = db.Column(db.String(256))
|
keywords = db.Column(db.String(256))
|
||||||
|
matrix_user_id = db.Column(db.String(256))
|
||||||
show_nsfw = db.Column(db.Boolean, default=False)
|
show_nsfw = db.Column(db.Boolean, default=False)
|
||||||
show_nsfl = db.Column(db.Boolean, default=False)
|
show_nsfl = db.Column(db.Boolean, default=False)
|
||||||
created = db.Column(db.DateTime, default=utcnow)
|
created = db.Column(db.DateTime, default=utcnow)
|
||||||
|
|
|
@ -298,7 +298,7 @@ def comment_vote(comment_id, vote_direction):
|
||||||
|
|
||||||
current_user.last_seen = utcnow()
|
current_user.last_seen = utcnow()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
current_user.recalculate_attitude(vote_direction)
|
current_user.recalculate_attitude()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
comment.post.flush_cache()
|
comment.post.flush_cache()
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
{{ render_field(form.password_field) }}
|
{{ render_field(form.password_field) }}
|
||||||
<hr />
|
<hr />
|
||||||
{{ render_field(form.about) }}
|
{{ render_field(form.about) }}
|
||||||
|
{{ render_field(form.matrix_user_id) }}
|
||||||
|
<small class="field_hint">e.g. @something:matrix.org. Include leading @ and use : before server</small>
|
||||||
{{ render_field(form.profile_file) }}
|
{{ render_field(form.profile_file) }}
|
||||||
<small class="field_hint">Provide a square image that looks good when small.</small>
|
<small class="field_hint">Provide a square image that looks good when small.</small>
|
||||||
{{ render_field(form.banner_file) }}
|
{{ render_field(form.banner_file) }}
|
||||||
|
|
|
@ -11,6 +11,7 @@ class ProfileForm(FlaskForm):
|
||||||
password_field = PasswordField(_l('Set new password'), validators=[Optional(), Length(min=1, max=50)],
|
password_field = PasswordField(_l('Set new password'), validators=[Optional(), Length(min=1, max=50)],
|
||||||
render_kw={"autocomplete": 'Off'})
|
render_kw={"autocomplete": 'Off'})
|
||||||
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)])
|
about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)])
|
||||||
|
matrix_user_id = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)])
|
||||||
profile_file = FileField(_('Avatar image'))
|
profile_file = FileField(_('Avatar image'))
|
||||||
banner_file = FileField(_('Top banner image'))
|
banner_file = FileField(_('Top banner image'))
|
||||||
bot = BooleanField(_l('This profile is a bot'))
|
bot = BooleanField(_l('This profile is a bot'))
|
||||||
|
|
|
@ -69,6 +69,7 @@ def edit_profile(actor):
|
||||||
current_user.set_password(form.password_field.data)
|
current_user.set_password(form.password_field.data)
|
||||||
current_user.about = form.about.data
|
current_user.about = form.about.data
|
||||||
current_user.about_html = markdown_to_html(form.about.data)
|
current_user.about_html = markdown_to_html(form.about.data)
|
||||||
|
current_user.matrix_user_id = form.matrix_user_id.data
|
||||||
current_user.bot = form.bot.data
|
current_user.bot = form.bot.data
|
||||||
profile_file = request.files['profile_file']
|
profile_file = request.files['profile_file']
|
||||||
if profile_file and profile_file.filename != '':
|
if profile_file and profile_file.filename != '':
|
||||||
|
@ -89,6 +90,7 @@ def edit_profile(actor):
|
||||||
elif request.method == 'GET':
|
elif request.method == 'GET':
|
||||||
form.email.data = current_user.email
|
form.email.data = current_user.email
|
||||||
form.about.data = current_user.about
|
form.about.data = current_user.about
|
||||||
|
form.matrix_user_id.data = current_user.matrix_user_id
|
||||||
form.password_field.data = ''
|
form.password_field.data = ''
|
||||||
|
|
||||||
return render_template('user/edit_profile.html', title=_('Edit profile'), form=form, user=current_user)
|
return render_template('user/edit_profile.html', title=_('Edit profile'), form=form, user=current_user)
|
||||||
|
|
40
migrations/versions/88d210da7f2b_user_matrix_id.py
Normal file
40
migrations/versions/88d210da7f2b_user_matrix_id.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
"""user matrix id
|
||||||
|
|
||||||
|
Revision ID: 88d210da7f2b
|
||||||
|
Revises: e8113bc01e3a
|
||||||
|
Create Date: 2023-12-28 20:51:08.605373
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '88d210da7f2b'
|
||||||
|
down_revision = 'e8113bc01e3a'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('report', schema=None) as batch_op:
|
||||||
|
batch_op.drop_constraint('report_suspect_reply_id_fkey', type_='foreignkey')
|
||||||
|
batch_op.drop_column('suspect_reply_id')
|
||||||
|
|
||||||
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('matrix_user_id', sa.String(length=256), nullable=True))
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('matrix_user_id')
|
||||||
|
|
||||||
|
with op.batch_alter_table('report', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('suspect_reply_id', sa.INTEGER(), autoincrement=False, nullable=True))
|
||||||
|
batch_op.create_foreign_key('report_suspect_reply_id_fkey', 'post_reply', ['suspect_reply_id'], ['id'])
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in a new issue