diff --git a/plugin.json b/plugin.json index 8d60c56..92e1cb8 100755 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "id": "com.github.scottleedavis.mattermost-plugin-remind", "name": "Remind Bot Mattermost Plugin", "description": "Sets Reminders", - "version": "0.2.0", + "version": "0.2.1", "server": { "executables": { "linux-amd64": "server/dist/plugin-linux-amd64", diff --git a/server/http.go b/server/http.go index ff178db..7b7cc54 100755 --- a/server/http.go +++ b/server/http.go @@ -60,6 +60,11 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { if target == nil { target = T("me") } + if target != T("me") && + !strings.HasPrefix(target.(string), "@") && + !strings.HasPrefix(target.(string), "~") { + target = "@" + target.(string) + } when := T("in") + " " + T("button.snooze."+ttime.(string)) switch ttime.(string) { @@ -106,6 +111,10 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { useToString = "" } + t := "" + if len(r.Reminder.Occurrences) > 0 { + t = r.Reminder.Occurrences[0].Occurrence.In(location).Format(time.RFC3339) + } var responseParameters = map[string]interface{}{ "Target": r.Reminder.Target, "UseTo": useToString, @@ -113,7 +122,7 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { "When": p.formatWhen( r.Username, r.Reminder.When, - r.Reminder.Occurrences[0].Occurrence.In(location).Format(time.RFC3339), + t, false, ), } diff --git a/server/i18n.go b/server/i18n.go index ab47239..a545f0d 100755 --- a/server/i18n.go +++ b/server/i18n.go @@ -9,32 +9,18 @@ import ( "path/filepath" "strings" - "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils/fileutils" "github.com/nicksnyder/go-i18n/i18n" ) -var TEE i18n.TranslateFunc -var TDefault i18n.TranslateFunc var locales map[string]string = make(map[string]string) -var settings model.LocalizationSettings -// this functions loads translations from filesystem -// and assign english while loading server config func TranslationsPreInit() error { - // Set T even if we fail to load the translations. Lots of shutdown handling code will - // segfault trying to handle the error, and the untranslated IDs are strictly better. - TEE = TfuncWithFallback("en") - TDefault = TfuncWithFallback("en") - return InitTranslationsWithDir() -} - -func InitTranslationsWithDir() error { i18nDirectory, found := fileutils.FindDir("plugins/" + manifest.Id + "/server/dist/i18n/") if !found { - return fmt.Errorf("Unable to find i18n directory") + return fmt.Errorf("unable to find i18n directory") } files, _ := ioutil.ReadDir(i18nDirectory) @@ -46,7 +32,6 @@ func InitTranslationsWithDir() error { if err := i18n.LoadTranslationFile(filepath.Join(i18nDirectory, filename)); err != nil { return err } - mlog.Info("found the files?") } } @@ -62,10 +47,6 @@ func GetUserTranslations(locale string) i18n.TranslateFunc { return translations } -func GetSupportedLocales() map[string]string { - return locales -} - func TfuncWithFallback(pref string) i18n.TranslateFunc { t, _ := i18n.Tfunc(pref) return func(translationID string, args ...interface{}) string { diff --git a/server/manifest.go b/server/manifest.go index 9585bd5..c964d8e 100755 --- a/server/manifest.go +++ b/server/manifest.go @@ -5,5 +5,5 @@ var manifest = struct { Version string }{ Id: "com.github.scottleedavis.mattermost-plugin-remind", - Version: "0.2.0", + Version: "0.2.1", } diff --git a/server/occurrence.go b/server/occurrence.go index 114af0f..da4dc3d 100755 --- a/server/occurrence.go +++ b/server/occurrence.go @@ -200,8 +200,11 @@ func (p *Plugin) addOccurrences(request *ReminderRequest, occurrences []time.Tim if rErr != nil { return rErr } - - if tUser, tErr := p.API.GetUserByUsername(request.Reminder.Target[1:]); tErr != nil { + target := request.Reminder.Target + if len(target) > 0 { + target = target[1:] + } + if tUser, tErr := p.API.GetUserByUsername(target); tErr != nil { return tErr } else { if rUser.Id != tUser.Id { @@ -323,6 +326,9 @@ func (p *Plugin) inEN(when string, user *model.User) (times []time.Time, err err when = strings.Trim(when, " ") whenSplit := strings.Split(when, " ") + if len(whenSplit) < 2 { + return []time.Time{}, errors.New("empty when split") + } value := whenSplit[1] units := whenSplit[len(whenSplit)-1] if len(whenSplit) == 2 { @@ -577,6 +583,9 @@ func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err err if strings.Contains(when, T("every")) { dateTimeSplit := strings.Split(when, " "+T("every")+" ") + if len(dateTimeSplit) < 2 { + return []time.Time{}, errors.New("empty date time split") + } return p.every(T("every")+" "+dateTimeSplit[1]+" "+dateTimeSplit[0], user) } else if len(whenSplit) >= 3 && diff --git a/server/scheduler.go b/server/scheduler.go index e051e85..5b22075 100755 --- a/server/scheduler.go +++ b/server/scheduler.go @@ -53,6 +53,10 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* request.Reminder.Target = T("you") } + t := "" + if len(request.Reminder.Occurrences) > 0 { + t = request.Reminder.Occurrences[0].Occurrence.In(location).Format(time.RFC3339) + } var responseParameters = map[string]interface{}{ "Target": request.Reminder.Target, "UseTo": useToString, @@ -60,7 +64,7 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* "When": p.formatWhen( request.Username, request.Reminder.When, - request.Reminder.Occurrences[0].Occurrence.In(location).Format(time.RFC3339), + t, false, ), } diff --git a/server/utils.go b/server/utils.go index ff03ffb..ca02346 100755 --- a/server/utils.go +++ b/server/utils.go @@ -27,12 +27,15 @@ func (p *Plugin) location(user *model.User) *time.Location { if tzLoc, err := timezone.GetTimezones(tzCode); err != nil { return time.Now().Location() } else { - if l, lErr := time.LoadLocation(tzLoc[0]); lErr != nil { - return time.Now().Location() + if len(tzLoc) > 0 { + if l, lErr := time.LoadLocation(tzLoc[0]); lErr != nil { + return time.Now().Location() + } else { + return l + } } else { - return l + return time.Now().Location() } - } } else { location, _ := time.LoadLocation(tz)