Skip to content

Commit 644bba3

Browse files
committed
Localised more alert strings.
Renamed most of the alert phrases. Fixes #3 - Default value issue with MySQL. Fixed a bug where pages would't load with HTTPS disabled.
1 parent 436c53f commit 644bba3

File tree

10 files changed

+70
-44
lines changed

10 files changed

+70
-44
lines changed

common/alerts.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func BuildAlert(asid int, event string, elementType string, actorID int, targetU
5454

5555
actor, err := Users.Get(actorID)
5656
if err != nil {
57-
return "", errors.New("Unable to find the actor")
57+
return "", errors.New(GetErrorPhrase("alerts_no_actor"))
5858
}
5959

6060
/*if elementType != "forum" {
@@ -66,7 +66,7 @@ func BuildAlert(asid int, event string, elementType string, actorID int, targetU
6666
}*/
6767

6868
if event == "friend_invite" {
69-
return buildAlertString(GetTmplPhrase("alerts_new_friend_invite"), []string{actor.Name}, actor.Link, actor.Avatar, asid), nil
69+
return buildAlertString(GetTmplPhrase("alerts.new_friend_invite"), []string{actor.Name}, actor.Link, actor.Avatar, asid), nil
7070
}
7171

7272
// Not that many events for us to handle in a forum
@@ -79,13 +79,13 @@ func BuildAlert(asid int, event string, elementType string, actorID int, targetU
7979
}
8080
// Store the forum ID in the targetUser column instead of making a new one? o.O
8181
// Add an additional column for extra information later on when we add the ability to link directly to posts. We don't need the forum data for now...
82-
return buildAlertString(GetTmplPhrase("alerts_forum_new_topic"), []string{actor.Name, topic.Title}, topic.Link, actor.Avatar, asid), nil
82+
return buildAlertString(GetTmplPhrase("alerts.forum_new_topic"), []string{actor.Name, topic.Title}, topic.Link, actor.Avatar, asid), nil
8383
}
84-
return buildAlertString(GetTmplPhrase("alerts_forum_unknown_action"), []string{actor.Name}, "", actor.Avatar, asid), nil
84+
return buildAlertString(GetTmplPhrase("alerts.forum_unknown_action"), []string{actor.Name}, "", actor.Avatar, asid), nil
8585
}
8686

8787
var url, area string
88-
var phraseName = "alerts_" + elementType
88+
var phraseName = "alerts." + elementType
8989
switch elementType {
9090
case "topic":
9191
topic, err := Topics.Get(elementID)
@@ -102,7 +102,7 @@ func BuildAlert(asid int, event string, elementType string, actorID int, targetU
102102
targetUser, err = Users.Get(elementID)
103103
if err != nil {
104104
DebugLogf("Unable to find target user %d", elementID)
105-
return "", errors.New("Unable to find the target user")
105+
return "", errors.New(GetErrorPhrase("alerts_no_target_user"))
106106
}
107107
area = targetUser.Name
108108
url = targetUser.Link
@@ -112,15 +112,15 @@ func BuildAlert(asid int, event string, elementType string, actorID int, targetU
112112
case "post":
113113
topic, err := TopicByReplyID(elementID)
114114
if err != nil {
115-
return "", errors.New("Unable to find the linked reply or parent topic")
115+
return "", errors.New(GetErrorPhrase("alerts_no_linked_topic_by_reply"))
116116
}
117117
url = topic.Link
118118
area = topic.Title
119119
if targetUserID == user.ID {
120120
phraseName += "_own"
121121
}
122122
default:
123-
return "", errors.New("Invalid elementType")
123+
return "", errors.New(GetErrorPhrase("alerts_invalid_elementtype"))
124124
}
125125

126126
switch event {
@@ -193,7 +193,6 @@ func NotifyWatchers(asid int64) error {
193193
if EnableWebsockets {
194194
go notifyWatchers(asid)
195195
}
196-
197196
return nil
198197
}
199198

common/routes_common.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) {
280280

281281
// TODO: Add a config setting to disable this header
282282
// TODO: Have this header cover more things
283-
w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests")
283+
if Site.EnableSsl {
284+
w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests")
285+
}
284286

285287
if user == &GuestUser {
286288
usercpy.LastIP = host

common/user_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewDefaultUserStore(cache UserCache) (*DefaultUserStore, error) {
5858
getByName: acc.Select("users").Columns("uid, name, group, active, is_super_admin, session, email, avatar, message, url_prefix, url_name, level, score, liked, last_ip, temp_group").Where("name = ?").Prepare(),
5959
getOffset: acc.Select("users").Columns("uid, name, group, active, is_super_admin, session, email, avatar, message, url_prefix, url_name, level, score, liked, last_ip, temp_group").Orderby("uid ASC").Limit("?,?").Prepare(),
6060
exists: acc.SimpleSelect("users", "uid", "uid = ?", "", ""),
61-
register: acc.SimpleInsert("users", "name, email, password, salt, group, is_super_admin, session, active, message, createdAt, lastActiveAt", "?,?,?,?,?,0,'',?,'',UTC_TIMESTAMP(),UTC_TIMESTAMP()"), // TODO: Implement user_count on users_groups here
61+
register: acc.Insert("users").Columns("name, email, password, salt, group, is_super_admin, session, active, message, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt").Fields("?,?,?,?,?,0,'',?,'',UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP()").Prepare(), // TODO: Implement user_count on users_groups here
6262
usernameExists: acc.SimpleSelect("users", "name", "name = ?", "", ""),
6363
userCount: acc.SimpleCount("users", "", ""),
6464
}, acc.FirstError()

install/install/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func createAdmin() error {
3737
}
3838

3939
// Build the admin user query
40-
adminUserStmt, err := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','127.0.0.1'")
40+
adminUserStmt, err := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','127.0.0.1'")
4141
if err != nil {
4242
return err
4343
}

langs/english.json

+30-24
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@
9898
"register_username_too_long_prefix":"The username is too long, max: ",
9999
"register_email_fail":"We were unable to send the email for you to confirm that this email address belongs to you. You may not have access to some functionality until you do so. Please ask an administrator for assistance.",
100100

101+
"alerts_no_actor":"Unable to find the actor",
102+
"alerts_no_target_user":"Unable to find the target user",
101103
"alerts_no_linked_topic":"Unable to find the linked topic",
104+
"alerts_no_linked_topic_by_reply":"Unable to find the linked reply or parent topic",
105+
"alerts_invalid_elementtype":"Invalid elementType",
102106

103107
"panel_groups_need_name":"The group name can't be left blank.",
104108
"panel_groups_cannot_edit_admin":"You need the EditGroupAdmin permission to edit an admin group.",
@@ -315,30 +319,32 @@
315319
"menu_login":"Login",
316320
"menu_register":"Register",
317321

318-
"alerts_forum_new_topic":"{0} created the topic {1}",
319-
"alerts_forum_unknown_action":"{0} did something in a forum",
320-
321-
"alerts_topic_own_reply":"{0} replied to your topic {1}",
322-
"alerts_topic_reply":"{0} replied to {1}",
323-
"alerts_topic_own_like":"{0} liked your topic {1}",
324-
"alerts_topic_like":"{0} liked {1}",
325-
"alerts_topic_own_mention":"{0} mentioned you in {1}",
326-
"alerts_topic_mention":"{0} mentioned you in {1}",
327-
328-
"alerts_post_own_reply":"{0} replied to your post in {1}",
329-
"alerts_post_reply":"{0} replied to {1}",
330-
"alerts_post_own_like":"{0} liked your post in {1}",
331-
"alerts_post_like":"{0} liked a post in {1}",
332-
"alerts_post_own_mention":"{0} mentioned you in {1}",
333-
"alerts_post_mention":"{0} mentioned you in {1}",
334-
335-
"alerts_user_own_reply":"{0} made a post on your profile",
336-
"alerts_user_reply":"{0} posted on {1}'s profile",
337-
"alerts_user_own_like":"{0} likes you",
338-
"alerts_user_like":"{0} likes {1}",
339-
"alerts_user_own_mention":"{0} mentioned you on your profile",
340-
"alerts_user_mention":"{0} mentioned you on {1}'s profile",
341-
"alerts_new_friend_invite":"You received a friend invite from {0}",
322+
"alerts.forum_new_topic":"{0} created the topic {1}",
323+
"alerts.forum_unknown_action":"{0} did something in a forum",
324+
325+
"alerts.topic_own_reply":"{0} replied to your topic {1}",
326+
"alerts.topic_reply":"{0} replied to {1}",
327+
"alerts.topic_own_like":"{0} liked your topic {1}",
328+
"alerts.topic_like":"{0} liked {1}",
329+
"alerts.topic_own_mention":"{0} mentioned you in {1}",
330+
"alerts.topic_mention":"{0} mentioned you in {1}",
331+
332+
"alerts.post_own_reply":"{0} replied to your post in {1}",
333+
"alerts.post_reply":"{0} replied to {1}",
334+
"alerts.post_own_like":"{0} liked your post in {1}",
335+
"alerts.post_like":"{0} liked a post in {1}",
336+
"alerts.post_own_mention":"{0} mentioned you in {1}",
337+
"alerts.post_mention":"{0} mentioned you in {1}",
338+
339+
"alerts.user_own_reply":"{0} made a post on your profile",
340+
"alerts.user_reply":"{0} posted on {1}'s profile",
341+
"alerts.user_own_like":"{0} likes you",
342+
"alerts.user_like":"{0} likes {1}",
343+
"alerts.user_own_mention":"{0} mentioned you on your profile",
344+
"alerts.user_mention":"{0} mentioned you on {1}'s profile",
345+
"alerts.new_friend_invite":"You received a friend invite from {0}",
346+
347+
"alerts.no_alerts":"You don't have any alerts",
342348

343349
"topics_click_topics_to_select":"Click the topics to select them",
344350
"topics_new_topic":"New Topic",

public/global.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function updateAlertList(menuAlerts) {
8181
j++;
8282
}
8383

84-
if(outList == "") outList = "<div class='alertItem'>You don't have any alerts</div>";
84+
if(outList == "") outList = "<div class='alertItem'>"+phraseBox["alerts"]["alerts.no_alerts"]+"</div>";
8585
alertListNode.innerHTML = outList;
8686

8787
if(alertCount != 0) {
@@ -489,7 +489,6 @@ function mainInit(){
489489
$(".submit_edit").click(function(event)
490490
{
491491
event.preventDefault();
492-
//console.log("running .submit_edit event");
493492
var outData = {isJs: "1"}
494493
var blockParent = $(this).closest('.editable_parent');
495494
blockParent.find('.editable_block').each(function() {
@@ -569,8 +568,9 @@ function mainInit(){
569568
var fileList = this.files;
570569
// Truncate the number of files to 5
571570
let files = [];
572-
for(var i = 0; i < fileList.length && i < 5; i++)
571+
for(var i = 0; i < fileList.length && i < 5; i++) {
573572
files[i] = fileList[i];
573+
}
574574

575575
// Iterate over the files
576576
let totalSize = 0;

public/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function DoNothingButPassBack(item) {
9292
}
9393

9494
function fetchPhrases() {
95-
fetch("/api/phrases/?query=status,topic_list")
95+
fetch("/api/phrases/?query=status,topic_list,alerts")
9696
.then((resp) => resp.json())
9797
.then((data) => {
9898
console.log("loaded phrase endpoint data");

query_gen/lib/mysql.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func (adapter *MysqlAdapter) parseColumn(column DBTableColumn) (col DBTableColum
141141
// Make it easier to support Cassandra in the future
142142
if column.Type == "createdAt" {
143143
column.Type = "datetime"
144+
if column.Default == "" {
145+
column.Default = "UTC_TIMESTAMP()"
146+
}
144147
} else if column.Type == "json" {
145148
column.Type = "text"
146149
}
@@ -151,7 +154,9 @@ func (adapter *MysqlAdapter) parseColumn(column DBTableColumn) (col DBTableColum
151154
// TODO: Exclude the other variants of text like mediumtext and longtext too
152155
if column.Default != "" && column.Type != "text" {
153156
end = " DEFAULT "
154-
if adapter.stringyType(column.Type) && column.Default != "''" {
157+
if column.Type == "datetime" && column.Default[len(column.Default)-1] == ')' {
158+
end += column.Default
159+
} else if adapter.stringyType(column.Type) && column.Default != "''" {
155160
end += "'" + column.Default + "'"
156161
} else {
157162
end += column.Default

query_gen/tables.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,19 @@ func createTables(adapter qgen.Adapter) error {
204204
qgen.DBTableColumn{"createdBy", "int", 0, false, false, ""}, // TODO: Make this a foreign key
205205
qgen.DBTableColumn{"is_closed", "boolean", 0, false, false, "0"},
206206
qgen.DBTableColumn{"sticky", "boolean", 0, false, false, "0"},
207+
// TODO: Add an index for this
207208
qgen.DBTableColumn{"parentID", "int", 0, false, false, "2"},
208209
qgen.DBTableColumn{"ipaddress", "varchar", 200, false, false, "0.0.0.0.0"},
209210
qgen.DBTableColumn{"postCount", "int", 0, false, false, "1"},
210211
qgen.DBTableColumn{"likeCount", "int", 0, false, false, "0"},
211212
qgen.DBTableColumn{"words", "int", 0, false, false, "0"},
212213
qgen.DBTableColumn{"views", "int", 0, false, false, "0"},
214+
//qgen.DBTableColumn{"dailyViews", "int", 0, false, false, "0"},
215+
//qgen.DBTableColumn{"weeklyViews", "int", 0, false, false, "0"},
216+
//qgen.DBTableColumn{"monthlyViews", "int", 0, false, false, "0"},
217+
// ? - A little hacky, maybe we could do something less likely to bite us with huge numbers of topics?
218+
// TODO: Add an index for this?
219+
//qgen.DBTableColumn{"lastMonth", "datetime", 0, false, false, ""},
213220
qgen.DBTableColumn{"css_class", "varchar", 100, false, false, "''"},
214221
qgen.DBTableColumn{"poll", "int", 0, false, false, "0"},
215222
qgen.DBTableColumn{"data", "varchar", 200, false, false, "''"},
@@ -435,7 +442,7 @@ func createTables(adapter qgen.Adapter) error {
435442
[]qgen.DBTableColumn{
436443
qgen.DBTableColumn{"miid", "int", 0, false, true, ""},
437444
qgen.DBTableColumn{"mid", "int", 0, false, false, ""},
438-
qgen.DBTableColumn{"name", "varchar", 200, false, false, ""},
445+
qgen.DBTableColumn{"name", "varchar", 200, false, false, "''"},
439446
qgen.DBTableColumn{"htmlID", "varchar", 200, false, false, "''"},
440447
qgen.DBTableColumn{"cssClass", "varchar", 200, false, false, "''"},
441448
qgen.DBTableColumn{"position", "varchar", 100, false, false, ""},
@@ -590,5 +597,12 @@ func createTables(adapter qgen.Adapter) error {
590597
[]qgen.DBTableKey{},
591598
)
592599

600+
/*qgen.Install.CreateTable("updates", "", "",
601+
[]qgen.DBTableColumn{
602+
qgen.DBTableColumn{"dbVersion", "int", 0, false, false, "0"},
603+
},
604+
[]qgen.DBTableKey{},
605+
)*/
606+
593607
return nil
594608
}

routes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user common.User) c
163163
phrases = make(map[string]string)
164164
for _, positive := range positives {
165165
// ! Constrain it to topic and status phrases for now
166-
if !strings.HasPrefix(positive, "topic") && !strings.HasPrefix(positive, "status") {
166+
if !strings.HasPrefix(positive, "topic") && !strings.HasPrefix(positive, "status") && !strings.HasPrefix(positive, "alerts") {
167167
return common.PreErrorJS("Not implemented!", w, r)
168168
}
169169
pPhrases, ok := common.GetTmplPhrasesByPrefix(positive)
@@ -176,7 +176,7 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user common.User) c
176176
}
177177
} else {
178178
// ! Constrain it to topic and status phrases for now
179-
if !strings.HasPrefix(positives[0], "topic") && !strings.HasPrefix(positives[0], "status") {
179+
if !strings.HasPrefix(positives[0], "topic") && !strings.HasPrefix(positives[0], "status") && !strings.HasPrefix(positives[0], "alerts") {
180180
return common.PreErrorJS("Not implemented!", w, r)
181181
}
182182
pPhrases, ok := common.GetTmplPhrasesByPrefix(positives[0])

0 commit comments

Comments
 (0)