2024-09-30 23:30:39 +02:00
|
|
|
import { Store, UIEventSource } from "../../../Logic/UIEventSource"
|
2022-01-08 14:08:04 +01:00
|
|
|
|
2024-09-30 23:30:39 +02:00
|
|
|
export default class NoteCommentElement {
|
2024-06-22 18:50:46 +02:00
|
|
|
/**
|
|
|
|
* Adds the comment to the _visualisation_ of the given note; doesn't _actually_ upload
|
|
|
|
* @param txt
|
|
|
|
* @param tags
|
|
|
|
* @param state
|
|
|
|
*/
|
2022-01-26 21:40:38 +01:00
|
|
|
public static addCommentTo(
|
|
|
|
txt: string,
|
2025-04-07 02:53:21 +02:00
|
|
|
tags: UIEventSource<Record<string, string>>,
|
2024-06-24 13:11:35 +02:00
|
|
|
state: { osmConnection: { userDetails: Store<{ name: string; uid: number }> } }
|
2022-01-26 21:40:38 +01:00
|
|
|
) {
|
2022-01-08 14:08:04 +01:00
|
|
|
const comments: any[] = JSON.parse(tags.data["comments"])
|
|
|
|
const username = state.osmConnection.userDetails.data.name
|
|
|
|
|
2024-04-12 15:37:10 +02:00
|
|
|
const urlRegex = /(https?:\/\/[^\s]+)/g
|
2022-01-26 21:40:38 +01:00
|
|
|
const html = txt.replace(urlRegex, function (url) {
|
2022-01-08 14:08:04 +01:00
|
|
|
return '<a href="' + url + '">' + url + "</a>"
|
|
|
|
})
|
2022-01-26 21:40:38 +01:00
|
|
|
|
2022-01-08 14:08:04 +01:00
|
|
|
comments.push({
|
|
|
|
date: new Date().toISOString(),
|
|
|
|
uid: state.osmConnection.userDetails.data.uid,
|
|
|
|
user: username,
|
|
|
|
user_url: "https://www.openstreetmap.org/user/" + username,
|
|
|
|
action: "commented",
|
|
|
|
text: txt,
|
|
|
|
html: html,
|
2023-12-26 22:30:27 +01:00
|
|
|
highlighted: true,
|
2022-01-08 14:08:04 +01:00
|
|
|
})
|
|
|
|
tags.data["comments"] = JSON.stringify(comments)
|
|
|
|
tags.ping()
|
|
|
|
}
|
|
|
|
}
|