Move the Place activity to the location field (instead of a tag)
This commit is contained in:
@@ -453,7 +453,7 @@ def api_new_note() -> _Response:
|
|||||||
|
|
||||||
source = None
|
source = None
|
||||||
summary = None
|
summary = None
|
||||||
place_tags = []
|
location = None
|
||||||
|
|
||||||
# Basic Micropub (https://www.w3.org/TR/micropub/) "create" support
|
# Basic Micropub (https://www.w3.org/TR/micropub/) "create" support
|
||||||
is_micropub = False
|
is_micropub = False
|
||||||
@@ -472,15 +472,11 @@ def api_new_note() -> _Response:
|
|||||||
location = _user_api_arg("location", default="")
|
location = _user_api_arg("location", default="")
|
||||||
if location.startswith("geo:"):
|
if location.startswith("geo:"):
|
||||||
slat, slng, *_ = location[4:].split(",")
|
slat, slng, *_ = location[4:].split(",")
|
||||||
place_tags.append(
|
location = {
|
||||||
{
|
"type": ap.ActivityType.PLACE.value,
|
||||||
"type": ap.ActivityType.PLACE.value,
|
"latitude": float(slat),
|
||||||
"url": "",
|
"longitude": float(slng),
|
||||||
"name": "",
|
}
|
||||||
"latitude": float(slat),
|
|
||||||
"longitude": float(slng),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Handle JSON microformats2 data
|
# Handle JSON microformats2 data
|
||||||
if _user_api_arg("type", default=None):
|
if _user_api_arg("type", default=None):
|
||||||
@@ -513,20 +509,17 @@ def api_new_note() -> _Response:
|
|||||||
if summary is None:
|
if summary is None:
|
||||||
summary = _user_api_arg("summary", default="")
|
summary = _user_api_arg("summary", default="")
|
||||||
|
|
||||||
if not place_tags:
|
if not location:
|
||||||
if _user_api_arg("location_lat", default=None):
|
if _user_api_arg("location_lat", default=None):
|
||||||
lat = float(_user_api_arg("location_lat"))
|
lat = float(_user_api_arg("location_lat"))
|
||||||
lng = float(_user_api_arg("location_lng"))
|
lng = float(_user_api_arg("location_lng"))
|
||||||
loc_name = _user_api_arg("location_name", default="")
|
loc_name = _user_api_arg("location_name", default="")
|
||||||
place_tags.append(
|
location = {
|
||||||
{
|
"type": ap.ActivityType.PLACE.value,
|
||||||
"type": ap.ActivityType.PLACE.value,
|
"name": loc_name,
|
||||||
"url": "",
|
"latitude": lat,
|
||||||
"name": loc_name,
|
"longitude": lng,
|
||||||
"latitude": lat,
|
}
|
||||||
"longitude": lng,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# All the following fields are specific to the API (i.e. not Micropub related)
|
# All the following fields are specific to the API (i.e. not Micropub related)
|
||||||
_reply, reply = None, None
|
_reply, reply = None, None
|
||||||
@@ -542,7 +535,7 @@ def api_new_note() -> _Response:
|
|||||||
content, tags = parse_markdown(source)
|
content, tags = parse_markdown(source)
|
||||||
|
|
||||||
# Check for custom emojis
|
# Check for custom emojis
|
||||||
tags = tags + emojis.tags(content) + place_tags
|
tags = tags + emojis.tags(content)
|
||||||
|
|
||||||
to: List[str] = []
|
to: List[str] = []
|
||||||
cc: List[str] = []
|
cc: List[str] = []
|
||||||
@@ -582,6 +575,9 @@ def api_new_note() -> _Response:
|
|||||||
context=context,
|
context=context,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if location:
|
||||||
|
raw_note["location"] = location
|
||||||
|
|
||||||
if request.files:
|
if request.files:
|
||||||
for f in request.files.keys():
|
for f in request.files.keys():
|
||||||
if not request.files[f].filename:
|
if not request.files[f].filename:
|
||||||
|
@@ -361,3 +361,18 @@ class _20191020_ManuallyApprovesFollowerSupportMigrationn(Migration):
|
|||||||
},
|
},
|
||||||
{"$set": {"meta.follow_status": "accepted"}},
|
{"$set": {"meta.follow_status": "accepted"}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class _20191106_PlaceTagToLocation(Migration):
|
||||||
|
def migrate(self) -> None:
|
||||||
|
for data in find_activities({"activity.object.tag.type": "Place"}):
|
||||||
|
for tag in data["activity"]["object"]["tag"]:
|
||||||
|
if tag["type"] == "Place":
|
||||||
|
break
|
||||||
|
DB.activities.update_one(
|
||||||
|
{"_id": data["_id"]},
|
||||||
|
{
|
||||||
|
"$pull": {"activity.object.tag": {"type": "Place"}},
|
||||||
|
"$set": {"activity.object.location": tag},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@@ -254,31 +254,30 @@ def get_actor(url):
|
|||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
def has_place(note):
|
def has_place(note):
|
||||||
for tag in note.get("tag", []):
|
if note.get("location") and note["location"].get("type") == "Place":
|
||||||
if tag.get("type") == "Place":
|
return True
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
def get_place(note):
|
def get_place(note):
|
||||||
for tag in note.get("tag", []):
|
if note.get("location") and note["location"].get("type") == "Place":
|
||||||
if tag.get("type") == "Place":
|
tag = note["location"]
|
||||||
lat = tag["latitude"]
|
lat = tag["latitude"]
|
||||||
lng = tag["longitude"]
|
lng = tag["longitude"]
|
||||||
out = ""
|
out = ""
|
||||||
if tag.get("name"):
|
if tag.get("name"):
|
||||||
out += f"{tag['name']} "
|
out += f"{tag['name']} "
|
||||||
|
|
||||||
out += (
|
out += (
|
||||||
'<span class="h-geo">'
|
'<span class="h-geo">'
|
||||||
f'<data class="p-latitude" value="{lat}"></data>'
|
f'<data class="p-latitude" value="{lat}"></data>'
|
||||||
f'<data class="p-longitude" value="{lng}"></data>'
|
f'<data class="p-longitude" value="{lng}"></data>'
|
||||||
f'<a href="https://www.openstreetmap.org/?mlat={lat}&mlon={lng}#map=16/{lat}/{lng}">{lat},{lng}</a>'
|
f'<a href="https://www.openstreetmap.org/?mlat={lat}&mlon={lng}#map=16/{lat}/{lng}">{lat},{lng}</a>'
|
||||||
"</span>"
|
"</span>"
|
||||||
)
|
)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user