commit 059a89f9c637593046b517679401c6b2e8647d65
parent 7e823a19734cc569fe5d5d67381624b9e5cb4dde
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 2 Jun 2023 21:09:59 -0700
improve format
Diffstat:
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/pkg/web/handlers/api/v1/msgInterceptor.go b/pkg/web/handlers/api/v1/msgInterceptor.go
@@ -97,7 +97,7 @@ func ProcessRawMessage(db *database.DkfDB, in, roomKey string, authUserID databa
html = convertMarkdown(html)
html = convertBangShortcuts(html)
html = convertArchiveLinks(db, html, roomID, authUserID)
- html = convertLinks(html, db.GetUserByUsername, db.GetLinkByShorthand, db.GetChatMessageByUUID)
+ html = convertLinks(html, roomID, db.GetUserByUsername, db.GetLinkByShorthand, db.GetChatMessageByUUID)
html = linkDefaultRooms(html)
html, taggedUsersIDsMap := colorifyTaggedUsers(html, db.GetUsersByUsername)
html = linkRoomTags(db, html)
diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go
@@ -815,7 +815,7 @@ func convertLinksWithoutScheme(in string) string {
var linkRgxStr = `(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#\(\)]*[\w\-\@?^=%&/~\+#\(\)])?`
var profileRgxStr = `/u/\w{3,20}`
var linkShorthandRgxStr = `/l/\w{3,20}`
-var dkfArchiveRgx = regexp.MustCompile(`/chat/[^/]+/archive\?uuid=([\w-]{36})#[\w-]{36}`)
+var dkfArchiveRgx = regexp.MustCompile(`/chat/([\w_]{3,50})/archive\?uuid=([\w-]{36})#[\w-]{36}`)
var linkOrProfileRgx = regexp.MustCompile(`(` + linkRgxStr + `|` + profileRgxStr + `|` + linkShorthandRgxStr + `)`)
var userProfileLinkRgx = regexp.MustCompile(`^` + profileRgxStr + `$`)
var linkShorthandPageLinkRgx = regexp.MustCompile(`^` + linkShorthandRgxStr + `$`)
@@ -844,6 +844,7 @@ func splitQuote(in string) (string, string) {
}
func convertLinks(in string,
+ roomID database.RoomID,
getUserByUsername func(database.Username) (database.User, error),
getLinkByShorthand func(string) (database.Link, error),
getChatMessageByUUID func(string) (database.ChatMessage, error)) string {
@@ -1042,9 +1043,13 @@ func convertLinks(in string,
label = link
href = trimmed
}
- if m := dkfArchiveRgx.FindStringSubmatch(label); len(m) == 2 {
- if msg, err := getChatMessageByUUID(m[1]); err == nil {
- label = msg.CreatedAt.Format("[Jan 02 03:04:05]")
+ if m := dkfArchiveRgx.FindStringSubmatch(label); len(m) == 3 {
+ if msg, err := getChatMessageByUUID(m[2]); err == nil {
+ if roomID == msg.RoomID {
+ label = msg.CreatedAt.Format("[Jan 02 03:04:05]")
+ } else {
+ label = msg.CreatedAt.Format("[#" + m[1] + " Jan 02 03:04:05]")
+ }
}
}
// Allows to have messages such as: "my profile is /u/username :)"