Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
340 commits
Select commit Hold shift + click to select a range
c88aa99
API - get followers/following count for remote user from remote instance
SamR1 Jan 23, 2022
a8241dc
API - fixes and changes on users
SamR1 Feb 20, 2022
d97621a
Client - search a remote user
SamR1 Jan 23, 2022
ab6945e
Client - init following a remote user (WIP)
SamR1 Jan 23, 2022
3b83aa2
API - return profile link for remote user
SamR1 Jan 26, 2022
96d48a7
API - refactoring remote user creation/refresh + fix getting user
SamR1 Jan 26, 2022
e01378c
Client - update remote user display
SamR1 Jan 26, 2022
de3ce0e
Client - remove unused style attributes
SamR1 Jan 30, 2022
90d03e4
Client - add confirmation before logging out
SamR1 Jan 30, 2022
e6c81ba
Client - fix authenticated user type
SamR1 Jan 30, 2022
6a0c502
Client - refacto and fix
SamR1 Jan 30, 2022
67a7026
Client - add button to get back to profile on relationships list
SamR1 Jan 30, 2022
6da5fb0
API - does not raise error when refresh on a existing remote user fails
SamR1 Jan 30, 2022
2b3726e
Client - fix tabs display in user profile
SamR1 Jan 30, 2022
8e2ed7b
API & Client - display follow requests to check
SamR1 Jan 30, 2022
352cba1
API - minor fix
SamR1 Jan 31, 2022
d6dec5e
API - add privacy levels on workouts (WIP)
SamR1 Feb 20, 2022
5af40fd
API - add workouts with privacy levels
SamR1 Feb 2, 2022
7229123
API - update workout visibility
SamR1 Feb 20, 2022
dfab3ed
API - minor refacto
SamR1 Feb 20, 2022
4fc6b0b
Client - add visibility on workout (WIP)
SamR1 Feb 2, 2022
76a6be2
API - return visibility preferences only for authenticated user
SamR1 Feb 2, 2022
eb5edc9
API - return user with workout
SamR1 Feb 20, 2022
9eed417
API - return visibility only for workout owner
SamR1 Feb 2, 2022
2fe0968
API - only workout owner can edit or delete a workout
SamR1 Feb 20, 2022
e24eee0
Client - display workout depending on visibility (WIP)
SamR1 Feb 3, 2022
90c1d67
Client - minor style fix
SamR1 Feb 3, 2022
9748e6b
API - init timeline route
SamR1 Feb 4, 2022
997725b
Client - init timeline display on dashboard
SamR1 Feb 4, 2022
6601176
Client - dashboard minor changes
SamR1 Feb 4, 2022
631fd5c
Merge branch 'dev' into add-social-features
SamR1 Apr 8, 2022
43629a8
Merge branch 'dev' into add-social-features
SamR1 Apr 9, 2022
b04d430
Merge branch 'dev' into add-social-features
SamR1 Apr 23, 2022
a436387
Merge branch 'dev' into add-social-features
SamR1 Apr 24, 2022
8a3a2c6
API - minor test refacto
SamR1 Apr 24, 2022
a9d5734
API - display workouts on timelime depending on visibility
SamR1 Apr 24, 2022
3b89dd6
API - fix User and Workouts models
SamR1 Apr 24, 2022
55b840d
API - store remote instance software name and version
SamR1 Apr 24, 2022
ff8d93a
API - minor refacto
SamR1 May 7, 2022
2e3a182
API - federation activities refacto
SamR1 May 7, 2022
35a6dba
API - init workouts activity objects
SamR1 May 7, 2022
b4eb8c3
Merge branch 'dev' into add-social-features
SamR1 May 8, 2022
9f0c063
API - update workout activities
SamR1 May 11, 2022
8afcee5
API - minor refacto
SamR1 May 11, 2022
29a6434
API - init shared inbox
SamR1 May 11, 2022
cfdac06
API - get followers shared inbox
SamR1 May 11, 2022
40e82b1
API - inbox minor refacto
SamR1 May 11, 2022
5769540
API - minor tests refacto
SamR1 May 11, 2022
1a53958
API - init remote workout creation (WIP)
SamR1 May 11, 2022
d987081
API - send activities for workouts w/o gpx to remote instance inboxes
SamR1 May 11, 2022
11ef21e
Merge branch 'dev' into add-social-features
SamR1 May 29, 2022
efb7791
API - fix workout creation on remote fittrackee instances (WIP)
SamR1 Jun 5, 2022
716618d
API - store remote url if workout from remote fittrackee instances
SamR1 Jun 5, 2022
0d1c811
API - return workout visibility
SamR1 Jun 6, 2022
9d3d970
API - only create records for local workouts for now
SamR1 Jun 6, 2022
bb92748
Client - update workout display (WIP)
SamR1 Jun 6, 2022
1a267da
Merge branch 'dev' into add-social-features
SamR1 Jun 12, 2022
a34dbba
Merge branch 'dev' into add-social-features
SamR1 Jun 22, 2022
7cd75a0
Merge branch 'dev' into add-social-features
SamR1 Jul 3, 2022
708c44b
Merge branch 'dev' into add-social-features
SamR1 Jul 13, 2022
807c94f
Merge branch 'dev' into add-social-features
SamR1 Jul 30, 2022
a4d0836
Merge branch 'dev' into add-social-features
SamR1 Sep 19, 2022
283c25c
API - refacto
SamR1 Sep 20, 2022
7b6868b
API - add `follow` scope for relationship-related endpoints
SamR1 Sep 20, 2022
5c8e814
Merge branch 'dev' into add-social-features
SamR1 Sep 21, 2022
a12634e
Merge branch 'dev' into add-social-features
SamR1 Sep 21, 2022
9caa5a2
Merge branch 'dev' into add-social-features
SamR1 Nov 2, 2022
74c5d9d
Client - fix after merging dev
SamR1 Nov 2, 2022
73ccc30
API - fix remote user creation
SamR1 Nov 2, 2022
53cea69
Merge branch 'dev' into add-social-features
SamR1 Nov 5, 2022
5f1c2c1
Merge branch 'dev' into add-social-features
SamR1 Nov 9, 2022
2bf0343
Merge branch 'dev' into add-social-features
SamR1 Nov 19, 2022
e771659
Merge branch 'dev' into add-social-features
SamR1 Nov 20, 2022
4720f33
API - update privacy level in order to share to local followers only
SamR1 Nov 20, 2022
53b2b84
API - send activities for workouts w/ gpx to remote instances (WIP)
SamR1 Nov 20, 2022
bd42876
API - only send the last workouts when zip archive is imported
SamR1 Nov 20, 2022
92d5180
Merge branch 'dev' into add-social-features
SamR1 Nov 27, 2022
082f4a1
Merge branch 'dev' into add-social-features
SamR1 Nov 30, 2022
0b8ec5b
API - update visibility utils with remote followers
SamR1 Nov 30, 2022
074a185
API - update Workout model with remote followers
SamR1 Nov 30, 2022
6f22274
API - update timeline api with remote followers
SamR1 Nov 30, 2022
d2bfe58
Client - add local and remote followers privacy level (WIP)
SamR1 Dec 1, 2022
350ea1f
API - segments are not returned when user can not see map data
SamR1 Dec 1, 2022
b232de0
API - minor refacto
SamR1 Dec 2, 2022
b709f02
API - rename activity object method
SamR1 Dec 2, 2022
2b9f338
API - update Create activity for workout
SamR1 Dec 2, 2022
87f2929
Merge branch 'dev' into add-social-features
SamR1 Dec 11, 2022
57148a6
Merge branch 'dev' into add-social-features
SamR1 Dec 21, 2022
63a5c79
API - fix migration
SamR1 Dec 21, 2022
95d6e0d
API - add remote object id in workout model
SamR1 Dec 21, 2022
7b1a91a
API - init Delete activity for workouts (WIP)
SamR1 Dec 21, 2022
c250195
Merge branch 'dev' into add-social-features
SamR1 Jan 1, 2023
9ef379c
API - check actor on Delete activity
SamR1 Jan 1, 2023
5bf4765
API - init Update activity for Workouts
SamR1 Jan 4, 2023
f194a1c
API - send activity to remote instances on workout update
SamR1 Jan 4, 2023
3efd7ce
API - init workout comment model
SamR1 Jan 4, 2023
9389d3d
API - update testing config
SamR1 Jan 4, 2023
8d01f46
API - add visibity to comments
SamR1 Jan 7, 2023
0f1c12d
API - init route to add comment to a workout (WIP)
SamR1 Jan 7, 2023
51c41cc
API - init route to get workout comment (WIP)
SamR1 Jan 8, 2023
ab33524
API - init Create activity for workout comment (Note) + refacto
SamR1 Jan 8, 2023
c4d2420
API - fix visibility check
SamR1 Jan 8, 2023
4b6e30c
API - refacto (get workout visibility from 'to' and 'cc' fields)
SamR1 Jan 11, 2023
13d27ac
API - send Create activity when posting a comment on a workout
SamR1 Jan 11, 2023
50aeeb3
API - init comment creation from activity (WIP)
SamR1 Jan 11, 2023
7186613
API - add route to get workout comments
SamR1 Jan 15, 2023
8e93a4f
Client - fix access to User profile when unauthenticated
SamR1 Jan 15, 2023
4929755
API - get sports when unauthenticated
SamR1 Jan 15, 2023
6fafc1c
Client - display public workout when unauthenticated
SamR1 Jan 15, 2023
dbe0f1c
Client - refacto
SamR1 Jan 15, 2023
0bed7e4
Client - update ESLint config
SamR1 Jan 15, 2023
b0ef5f1
Client - add comments in workout detail (WIP)
SamR1 Jan 15, 2023
41b574e
API - lint fix
SamR1 Jan 15, 2023
ccf24a0
Client - update button on User profile
SamR1 Jan 15, 2023
102b1d7
Client - display user fullname on comment if user is from remote inst…
SamR1 Jan 15, 2023
9bf9f18
Client - sanitize comments
SamR1 Jan 18, 2023
8de79df
Client - update comments style
SamR1 Jan 18, 2023
a03b7f7
API - fix comment serializer
SamR1 Jan 18, 2023
382b931
API - add route to delete comment
SamR1 Jan 18, 2023
095e767
Client - delete a comment (WIP)
SamR1 Jan 18, 2023
a92e8a6
API - add route to update a comment
SamR1 Jan 20, 2023
e791946
Client - update a comment
SamR1 Jan 20, 2023
c25551c
API - fix migration
SamR1 Jan 20, 2023
2e9a7eb
API - refacto workouts and comments routes
SamR1 Jan 20, 2023
b3c838b
API - init comment reply
SamR1 Jan 20, 2023
ff8c096
API - create remote comment reply
SamR1 Jan 20, 2023
fe35a7c
API - get comment replies (WIP)
SamR1 Jan 25, 2023
ecd1912
Client - display comment replies (WIP)
SamR1 Jan 25, 2023
67d8219
API - delete comment having replies
SamR1 Jan 29, 2023
0ee244d
API - delete remote comment
SamR1 Jan 29, 2023
add3466
API - fix workout deletion
SamR1 Jan 29, 2023
7632f37
API & Client - remove pagination on comments for now
SamR1 Jan 29, 2023
105710c
Client - display comment input only for authenticated user
SamR1 Feb 1, 2023
941c0cc
Client - minor style update on workout detail
SamR1 Feb 1, 2023
2675e09
Client - refacto
SamR1 Feb 1, 2023
f75bcc7
API - fix user profile url
SamR1 Feb 1, 2023
931fd41
API - update tests config
SamR1 Feb 5, 2023
1e818e0
API - refacto comments
SamR1 Feb 5, 2023
63644c4
API - add mentions users in comment text and when sending activity (WIP)
SamR1 Feb 5, 2023
576a8da
Client - update comment display
SamR1 Feb 5, 2023
1e7bd90
Client - comment visibility depends on workout visibility
SamR1 Feb 5, 2023
14f0b00
API - minor refactoring
SamR1 Feb 8, 2023
662dd52
API - store mentioned users in database
SamR1 Feb 8, 2023
ad26288
API - handle visibility for mentioned users
SamR1 Feb 11, 2023
487181b
API - update comment-related activity models (WIP)
SamR1 Feb 12, 2023
e0abde5
API - handle activities related to comment with mentions
SamR1 Feb 15, 2023
f722c3e
API & Client - refacto
SamR1 Feb 15, 2023
c1d5e3f
API - create comment even a related workout does not exist
SamR1 Feb 15, 2023
6df8f36
Client - update visibility labels for comments
SamR1 Feb 16, 2023
534b1e0
Merge branch 'dev' into add-social-features
SamR1 Feb 16, 2023
8fbd348
API - fix test
SamR1 Feb 16, 2023
15a5bc5
API & Client - move federation activation in a environment variable
SamR1 Feb 16, 2023
ab46fa2
API - minor fix
SamR1 Feb 16, 2023
27b0609
Merge branch 'dev' into add-social-features
SamR1 Feb 20, 2023
46ca3b8
API - fix mentions on remote comment
SamR1 Feb 20, 2023
9158fdb
API - skip errored users when handling mentions
SamR1 Feb 20, 2023
dd656f9
Client - avoid non existing user fullname to be linkified as mailto URL
SamR1 Feb 20, 2023
ec17716
Client - add loader to comments
SamR1 Feb 20, 2023
ae38f34
API & Client - exclude inactive users for counts and users list
SamR1 Feb 21, 2023
2b23c2a
Client - minor refacto
SamR1 Feb 21, 2023
c8e6fd1
API - fix migration
SamR1 Feb 21, 2023
26dc4ff
API - init likes
SamR1 Feb 22, 2023
a83c2e1
API - handle like activities
SamR1 Feb 22, 2023
cf62277
API - add likes count
SamR1 Feb 22, 2023
e828368
Client - display likes on workouts and comments
SamR1 Feb 22, 2023
040fe0e
Merge branch 'dev' into add-social-features
SamR1 Mar 8, 2023
34af30c
Merge branch 'dev' into add-social-features
SamR1 Mar 8, 2023
5150d44
Merge branch 'dev' into add-social-features
SamR1 Apr 8, 2023
571dd3d
Merge branch 'dev' into add-social-features
SamR1 Apr 13, 2023
d889f6b
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Apr 13, 2023
b9bd581
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jun 4, 2023
8996b7f
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jun 25, 2023
6c666bb
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jul 15, 2023
b1213e0
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jul 23, 2023
1cb6c24
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jul 30, 2023
6baf866
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Aug 23, 2023
cf6edc5
API - fix workouts order when uploading a zip archive
SamR1 Aug 26, 2023
6a0b8cf
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Sep 14, 2023
c7993af
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Oct 4, 2023
f02ef4a
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Oct 8, 2023
34eef9c
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jan 3, 2024
492021e
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jan 6, 2024
d49a03b
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Feb 4, 2024
4f9507e
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Feb 10, 2024
f19ad23
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Mar 10, 2024
0428fd7
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Apr 13, 2024
3c2aab3
API - rename migration
SamR1 Apr 13, 2024
2e30c47
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Apr 21, 2024
15a682d
API - rename migration
SamR1 Apr 21, 2024
bf36bd2
Merge branch 'add-social-features' into add-social-features_ap
SamR1 May 1, 2024
8e69b5e
Merge branch 'add-social-features' into add-social-features_ap
SamR1 May 8, 2024
0226766
Merge branch 'add-social-features' into add-social-features_ap
SamR1 May 9, 2024
2685466
Merge branch 'add-social-features' into add-social-features_ap
SamR1 May 22, 2024
9fb390f
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Jun 29, 2024
4ec9368
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Aug 3, 2024
fd4add7
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Aug 25, 2024
87411a3
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Sep 1, 2024
94da2ad
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Sep 21, 2024
cd9a0b1
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Oct 9, 2024
4b30db1
fix poetry.lock
SamR1 Oct 9, 2024
fc2b9e8
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Oct 30, 2024
670d9fa
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Nov 20, 2024
11f6d18
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 4, 2024
6cf2668
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 7, 2024
ca57377
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 7, 2024
5dd72ce
API & Client - restore comment replies
SamR1 Dec 7, 2024
2a37b2e
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 8, 2024
a5c39e5
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 8, 2024
8f8d372
Client - revert "remove code about reply"
SamR1 Dec 8, 2024
899f101
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 11, 2024
6d8bd22
Merge branch 'add-social-features' into add-social-features_ap
SamR1 Dec 14, 2024
d952a31
Merge branch 'v0.9.x' into add-social-features_ap
SamR1 Dec 29, 2024
d796927
Merge branch 'v0.9.x' into add-social-features_ap
SamR1 Jan 5, 2025
4b6e5d2
Merge branch 'dev' into federation
SamR1 Jan 18, 2025
7db1287
Merge branch 'dev' into federation
SamR1 Jan 25, 2025
c6cecc2
API - fix missing db.DateTime
SamR1 Jan 26, 2025
9654ad8
Merge branch 'update-sql-alchemy' into federation
SamR1 Jan 29, 2025
6caa15c
API - fix after SQLAlchemy update
SamR1 Feb 1, 2025
0ef20f3
Merge branch 'dev' into federation
SamR1 Feb 1, 2025
a5ac924
Merge branch 'dev' into federation
SamR1 Feb 2, 2025
bbf9e01
Client - fixes after merge
SamR1 Feb 2, 2025
53425ba
Merge branch 'dev' into federation
SamR1 Feb 15, 2025
24594e3
Merge branch 'dev' into federation
SamR1 Mar 15, 2025
1ea39f1
Merge branch 'dev' into federation
SamR1 Mar 26, 2025
2b3d3c7
Merge branch 'dev' into federation
SamR1 Apr 6, 2025
cb2d6a3
Merge branch 'dev' into federation
SamR1 Apr 16, 2025
7a51902
Merge branch 'dev' into federation
SamR1 Apr 20, 2025
3e08cb3
Merge branch 'dev' into federation
SamR1 Apr 27, 2025
85ea07c
Merge branch 'dev' into federation
SamR1 May 3, 2025
f31e6f6
Merge branch 'dev' into federation
SamR1 May 11, 2025
8a4d0cc
Merge branch 'dev' into federation
SamR1 May 18, 2025
b20672b
Merge branch 'dev' into federation
SamR1 May 29, 2025
30d92cd
Merge branch 'dev' into federation
SamR1 May 30, 2025
a6c4931
Merge branch 'dev' into federation
SamR1 May 31, 2025
c674e89
Merge branch 'dev' into federation
SamR1 Jun 18, 2025
607a6b5
Merge branch 'dev' into federation
SamR1 Jul 23, 2025
ff25a27
Merge branch 'dev' into federation
SamR1 Jul 30, 2025
4867674
Merge branch 'dev' into federation
SamR1 Aug 13, 2025
5d02c39
Merge branch 'dev' into federation
SamR1 Aug 31, 2025
0fd24ca
Merge branch 'dev' into federation
SamR1 Sep 3, 2025
f383d2f
Merge branch 'dev' into federation
SamR1 Sep 7, 2025
760bbca
Merge branch 'dev' into federation
SamR1 Oct 5, 2025
d069826
Merge branch 'dev' into federation
SamR1 Oct 22, 2025
227d178
Merge branch 'dev' into federation
SamR1 Nov 1, 2025
576d07a
Merge branch 'dev' into federation
SamR1 Nov 5, 2025
b65f786
Merge branch 'dev' into federation
SamR1 Dec 14, 2025
ea18094
Merge branch 'dev' into federation
SamR1 Dec 27, 2025
1d84934
Merge branch 'dev' into federation
SamR1 Jan 4, 2026
8f349ae
Merge branch 'dev' into federation
SamR1 Jan 25, 2026
1453a0b
Merge branch 'dev' into federation
SamR1 Feb 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.docker.dev
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ export SENDER_EMAIL=fittrackee@example.com
# Weather
# available weather API providers: visualcrossing
# export WEATHER_API_PROVIDER=
# export WEATHER_API_KEY=
# export WEATHER_API_KEY=

# Federation
# export FEDERATION_ENABLED=False
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ export SENDER_EMAIL=
# available weather API providers: visualcrossing
# export WEATHER_API_PROVIDER=
# export WEATHER_API_KEY=

# Federation
# export FEDERATION_ENABLED=False
9 changes: 9 additions & 0 deletions fittrackee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def create_app(init_email: bool = True) -> Flask:
app.register_blueprint(feeds_blueprint, url_prefix="")
app.register_blueprint(geocode_blueprint, url_prefix="/api")

# ActivityPub federation
from .federation.federation import ap_federation_blueprint
from .federation.nodeinfo import ap_nodeinfo_blueprint
from .federation.webfinger import ap_webfinger_blueprint

app.register_blueprint(ap_federation_blueprint, url_prefix="/federation")
app.register_blueprint(ap_nodeinfo_blueprint)
app.register_blueprint(ap_webfinger_blueprint, url_prefix="/.well-known")

if app.debug:
logging.getLogger("sqlalchemy").setLevel(logging.WARNING)
logging.getLogger("sqlalchemy").handlers = logging.getLogger(
Expand Down
2 changes: 2 additions & 0 deletions fittrackee/application/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_application_config() -> Union[Dict, HttpResponse]:
"open_elevation": false,
"valhalla": false
},
"federation_enabled": false,
"file_sync_limit_import": 10,
"file_limit_import": 10,
"global_map_workouts_limit": 10000,
Expand Down Expand Up @@ -115,6 +116,7 @@ def update_application_config(auth_user: User) -> Union[Dict, HttpResponse]:
"open_elevation": false,
"valhalla": false
},
"federation_enabled": true,
"file_sync_limit_import": 10,
"file_limit_import": 10,
"global_map_workouts_limit": 10000,
Expand Down
5 changes: 4 additions & 1 deletion fittrackee/application/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class AppConfig(BaseModel):

@property
def is_registration_enabled(self) -> bool:
result = db.session.execute(text("SELECT COUNT(*) FROM users;"))
result = db.session.execute(
text("SELECT COUNT(*) FROM users WHERE users.is_remote IS FALSE;")
)
nb_users = result.one()[0]
return self.max_users == 0 or nb_users < self.max_users

Expand All @@ -71,6 +73,7 @@ def serialize(self) -> Dict:
"about": self.about,
"admin_contact": self.admin_contact,
"elevation_services": self.elevation_services,
"federation_enabled": current_app.config["FEDERATION_ENABLED"],
"file_limit_import": self.file_limit_import,
"file_sync_limit_import": self.file_sync_limit_import,
"is_email_sending_enabled": current_app.config["CAN_SEND_EMAILS"],
Expand Down
140 changes: 134 additions & 6 deletions fittrackee/comments/comments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from datetime import datetime, timezone
from typing import Dict, Optional, Tuple, Union
from typing import Dict, List, Optional, Set, Tuple, Union

from flask import Blueprint, request
from flask import Blueprint, current_app, request
from sqlalchemy import exc

from fittrackee import db
from fittrackee.exceptions import InvalidVisibilityException
from fittrackee.federation.tasks.inbox import send_to_remote_inbox
from fittrackee.oauth2.server import require_auth
from fittrackee.reports.models import ReportActionAppeal
from fittrackee.responses import (
Expand All @@ -14,8 +16,8 @@
handle_error_and_return_response,
)
from fittrackee.users.models import User
from fittrackee.utils import clean_input
from fittrackee.visibility_levels import VisibilityLevel
from fittrackee.utils import clean_input, decode_short_id
from fittrackee.visibility_levels import VisibilityLevel, can_view
from fittrackee.workouts.decorators import check_workout
from fittrackee.workouts.models import Workout

Expand All @@ -27,6 +29,39 @@
DEFAULT_COMMENT_LIKES_PER_PAGE = 10


def get_all_recipients(
user: User,
comment: Comment,
deleted_mentioned_users: Optional[Set] = None,
) -> List[str]:
recipients = user.get_followers_shared_inboxes_as_list()
mentions = [
user.actor.shared_inbox_url for user in comment.remote_mentions.all()
]
if deleted_mentioned_users is None:
deleted_mentioned_users = set()
deleted_mentions = [
user.actor.shared_inbox_url for user in deleted_mentioned_users
]
return list(set(recipients + mentions + deleted_mentions))


def sending_comment_activities_allowed(
comment: Comment, deleted_mentioned_users: Optional[Set] = None
) -> bool:
if deleted_mentioned_users is None:
deleted_mentioned_users = set()
return current_app.config["FEDERATION_ENABLED"] and (
comment.has_remote_mentions
or len(deleted_mentioned_users) > 0
or comment.text_visibility
in (
VisibilityLevel.PUBLIC,
VisibilityLevel.FOLLOWERS_AND_REMOTE,
)
)


@comments_blueprint.route(
"/workouts/<string:workout_short_id>/comments", methods=["POST"]
)
Expand Down Expand Up @@ -62,6 +97,8 @@ def post_workout_comment(
"likes_count": 0,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Great!",
"text_html": "Great!",
Expand All @@ -86,12 +123,15 @@ def post_workout_comment(
:<json string text: comment content
:<json string text_visibility: visibility level (``public``,
``followers_only``, ``private``)
:<json string reply_to: id of the comment being replied to
(to be provided only for a reply)

:reqheader Authorization: OAuth 2.0 Bearer Token

:statuscode 201: ``created``
:statuscode 400:
- ``invalid payload``
- ``'reply_to' is invalid``
:statuscode 401:
- ``provide a valid auth token``
- ``signature expired, please log in again``
Expand All @@ -109,15 +149,49 @@ def post_workout_comment(
):
return InvalidPayloadErrorResponse()
try:
reply_to = comment_data.get("reply_to")
comment = None
if reply_to:
comment = Comment.query.filter(
Comment.uuid == decode_short_id(reply_to),
Comment.user_id.not_in(auth_user.get_blocked_by_user_ids()),
).first()
if (
not comment
or comment.suspended_at
or not can_view(comment, "text_visibility", auth_user)
):
return InvalidPayloadErrorResponse("'reply_to' is invalid")

new_comment = Comment(
user_id=auth_user.id,
workout_id=workout.id,
text=clean_input(comment_data["text"]),
text_visibility=VisibilityLevel(comment_data["text_visibility"]),
reply_to=comment.id if comment else None,
)
db.session.add(new_comment)
db.session.flush()
new_comment.create_mentions()
if sending_comment_activities_allowed(new_comment):
new_comment.ap_id = (
f"{auth_user.actor.activitypub_id}/"
f"workouts/{workout.short_id}/"
f"comments/{new_comment.short_id}"
)
new_comment.remote_url = (
f"https://{auth_user.actor.domain.name}/"
f"workouts/{workout.short_id}/"
f"comments/{new_comment.short_id}"
)
note_activity = new_comment.get_activity(activity_type="Create")
recipients = get_all_recipients(auth_user, new_comment)
if recipients:
send_to_remote_inbox.send(
sender_id=auth_user.actor.id,
activity=note_activity,
recipients=recipients,
)
db.session.commit()

return (
Expand All @@ -127,6 +201,8 @@ def post_workout_comment(
},
201,
)
except InvalidVisibilityException as e:
return InvalidPayloadErrorResponse(message=str(e))
except (exc.IntegrityError, ValueError) as e:
return handle_error_and_return_response(
error=e,
Expand Down Expand Up @@ -171,6 +247,8 @@ def get_workout_comment(
"likes_count": 0,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Nice!",
"text_html": "Nice!",
Expand Down Expand Up @@ -207,7 +285,7 @@ def get_workout_comment(
return (
{
"status": "success",
"comment": comment.serialize(auth_user),
"comment": comment.serialize(auth_user, get_parent_comment=True),
},
200,
)
Expand Down Expand Up @@ -253,6 +331,8 @@ def get_workout_comments(
"likes_count": 0,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Great!",
"text_html": "Great!",
Expand Down Expand Up @@ -349,6 +429,16 @@ def delete_workout_comment(
:statuscode 500: ``error, please try again or contact the administrator``
"""
try:
if sending_comment_activities_allowed(comment):
note_activity = comment.get_activity(activity_type="Delete")
recipients = get_all_recipients(auth_user, comment)
if recipients:
send_to_remote_inbox.send(
sender_id=auth_user.actor.id,
activity=note_activity,
recipients=recipients,
)

db.session.delete(comment)
db.session.commit()
return {"status": "no content"}, 204
Expand Down Expand Up @@ -396,6 +486,8 @@ def update_workout_comment(
"likes_count": 0,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Great!",
"text_html": "Great!",
Expand Down Expand Up @@ -441,8 +533,23 @@ def update_workout_comment(
try:
comment.text = clean_input(comment_data["text"])
comment.modification_date = datetime.now(timezone.utc)
comment.update_mentions()
deleted_mentioned_users = comment.update_mentions()
db.session.commit()

if sending_comment_activities_allowed(
comment, deleted_mentioned_users
):
recipients = get_all_recipients(
auth_user, comment, deleted_mentioned_users
)
if recipients:
note_activity = comment.get_activity(activity_type="Update")
send_to_remote_inbox.send(
sender_id=auth_user.actor.id,
activity=note_activity,
recipients=recipients,
)

return {
"status": "success",
"comment": comment.serialize(auth_user),
Expand Down Expand Up @@ -487,6 +594,8 @@ def like_comment(
"likes_count": 1,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Great!",
"text_html": "Great!",
Expand Down Expand Up @@ -526,6 +635,14 @@ def like_comment(
like = CommentLike(user_id=auth_user.id, comment_id=comment.id)
db.session.add(like)
db.session.commit()

if current_app.config["FEDERATION_ENABLED"] and comment.user.is_remote:
like_activity = like.get_activity()
send_to_remote_inbox.send(
sender_id=auth_user.actor.id,
activity=like_activity,
recipients=[comment.user.actor.shared_inbox_url],
)
except exc.IntegrityError:
db.session.rollback()
return {
Expand Down Expand Up @@ -570,6 +687,8 @@ def undo_comment_like(
"likes_count": 0,
"mentions": [],
"modification_date": null,
"replies": [],
"reply_to": null,
"suspended_at": null,
"text": "Great!",
"text_html": "Great!",
Expand Down Expand Up @@ -609,6 +728,15 @@ def undo_comment_like(
if like:
db.session.delete(like)
db.session.commit()

if current_app.config["FEDERATION_ENABLED"] and comment.user.is_remote:
undo_activity = like.get_activity(is_undo=True)
send_to_remote_inbox.send(
sender_id=auth_user.actor.id,
activity=undo_activity,
recipients=[comment.user.actor.shared_inbox_url],
)

return {
"status": "success",
"comment": comment.serialize(auth_user),
Expand Down
Loading