• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang utils.GetUserTranslations函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/mattermost/platform/utils.GetUserTranslations函数的典型用法代码示例。如果您正苦于以下问题:Golang GetUserTranslations函数的具体用法?Golang GetUserTranslations怎么用?Golang GetUserTranslations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetUserTranslations函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: sendPushNotification

func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, wasMentioned bool) {
	sessions := getMobileAppSessions(user.Id)

	if sessions == nil {
		return
	}

	var channelName string

	if channel.Type == model.CHANNEL_DIRECT {
		channelName = senderName
	} else {
		channelName = channel.DisplayName
	}

	userLocale := utils.GetUserTranslations(user.Locale)

	msg := model.PushNotification{}
	if badge := <-Srv.Store.User().GetUnreadCount(user.Id); badge.Err != nil {
		msg.Badge = 1
		l4g.Error(utils.T("store.sql_user.get_unread_count.app_error"), user.Id, badge.Err)
	} else {
		msg.Badge = int(badge.Data.(int64))
	}
	msg.Type = model.PUSH_TYPE_MESSAGE
	msg.ChannelId = channel.Id
	msg.ChannelName = channel.Name

	if *utils.Cfg.EmailSettings.PushNotificationContents == model.FULL_NOTIFICATION {
		if channel.Type == model.CHANNEL_DIRECT {
			msg.Category = model.CATEGORY_DM
			msg.Message = "@" + senderName + ": " + model.ClearMentionTags(post.Message)
		} else {
			msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_in") + channelName + ": " + model.ClearMentionTags(post.Message)
		}
	} else {
		if channel.Type == model.CHANNEL_DIRECT {
			msg.Category = model.CATEGORY_DM
			msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
		} else if wasMentioned {
			msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention") + channelName
		} else {
			msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_non_mention") + channelName
		}
	}

	l4g.Debug(utils.T("api.post.send_notifications_and_forget.push_notification.debug"), msg.DeviceId, msg.Message)

	for _, session := range sessions {
		tmpMessage := *model.PushNotificationFromJson(strings.NewReader(msg.ToJson()))
		tmpMessage.SetDeviceIdAndPlatform(session.DeviceId)
		sendToPushProxy(tmpMessage)
	}
}
开发者ID:boreys,项目名称:platform,代码行数:54,代码来源:post.go


示例2: Render

func (me *ServerTemplatePage) Render() string {
	var text bytes.Buffer

	T := utils.GetUserTranslations(me.Locale)
	me.Props["Footer"] = T("api.templates.email_footer")
	me.Html["EmailInfo"] = template.HTML(T("api.templates.email_info",
		map[string]interface{}{"SupportEmail": me.ClientCfg["SupportEmail"], "SiteName": me.ClientCfg["SiteName"]}))

	if err := ServerTemplates.ExecuteTemplate(&text, me.TemplateName, me); err != nil {
		l4g.Error(utils.T("api.api.render.error"), me.TemplateName, err)
	}

	return text.String()
}
开发者ID:kidhero,项目名称:platform,代码行数:14,代码来源:api.go


示例3: sendBatchedEmailNotification

func sendBatchedEmailNotification(userId string, notifications []*batchedNotification) {
	uchan := Srv.Store.User().Get(userId)
	pchan := Srv.Store.Preference().Get(userId, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_DISPLAY_NAME_FORMAT)

	var user *model.User
	if result := <-uchan; result.Err != nil {
		l4g.Warn("api.email_batching.send_batched_email_notification.user.app_error")
		return
	} else {
		user = result.Data.(*model.User)
	}

	translateFunc := utils.GetUserTranslations(user.Locale)

	var displayNameFormat string
	if result := <-pchan; result.Err != nil && result.Err.DetailedError != sql.ErrNoRows.Error() {
		l4g.Warn("api.email_batching.send_batched_email_notification.preferences.app_error")
		return
	} else if result.Err != nil {
		// no display name format saved, so fall back to default
		displayNameFormat = model.PREFERENCE_DEFAULT_DISPLAY_NAME_FORMAT
	} else {
		displayNameFormat = result.Data.(model.Preference).Value
	}

	var contents string
	for _, notification := range notifications {
		template := utils.NewHTMLTemplate("post_batched_post", user.Locale)

		contents += renderBatchedPost(template, notification.post, notification.teamName, displayNameFormat, translateFunc)
	}

	tm := time.Unix(notifications[0].post.CreateAt/1000, 0)

	subject := translateFunc("api.email_batching.send_batched_email_notification.subject", len(notifications), map[string]interface{}{
		"SiteName": utils.Cfg.TeamSettings.SiteName,
		"Year":     tm.Year(),
		"Month":    translateFunc(tm.Month().String()),
		"Day":      tm.Day(),
	})

	body := utils.NewHTMLTemplate("post_batched_body", user.Locale)
	body.Props["SiteURL"] = *utils.Cfg.ServiceSettings.SiteURL
	body.Props["Posts"] = template.HTML(contents)
	body.Props["BodyText"] = translateFunc("api.email_batching.send_batched_email_notification.body_text", len(notifications))

	if err := utils.SendMail(user.Email, subject, body.Render()); err != nil {
		l4g.Warn(utils.T("api.email_batchings.send_batched_email_notification.send.app_error"), user.Email, err)
	}
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:50,代码来源:email_batching.go


示例4: TestGetMessageForNotification

func TestGetMessageForNotification(t *testing.T) {
	Setup()
	translateFunc := utils.GetUserTranslations("en")

	post := &model.Post{
		Message:   "test",
		Filenames: model.StringArray{},
	}

	if getMessageForNotification(post, translateFunc) != "test" {
		t.Fatal("should've returned message text")
	}

	post.Filenames = model.StringArray{"test1.png"}
	if getMessageForNotification(post, translateFunc) != "test" {
		t.Fatal("should've returned message text, even with attachments")
	}

	post.Message = ""
	if message := getMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" {
		t.Fatal("should've returned number of images:", message)
	}

	post.Filenames = model.StringArray{"test1.png", "test2.jpg"}
	if message := getMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" {
		t.Fatal("should've returned number of images:", message)
	}

	post.Filenames = model.StringArray{"test1.go"}
	if message := getMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" {
		t.Fatal("should've returned number of files:", message)
	}

	post.Filenames = model.StringArray{"test1.go", "test2.jpg"}
	if message := getMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test2.jpg" {
		t.Fatal("should've returned number of mixed files:", message)
	}
}
开发者ID:cloudron-io,项目名称:mattermost,代码行数:38,代码来源:post_test.go


示例5: sendOutOfChannelMentions

func sendOutOfChannelMentions(post *model.Post, teamId string, profiles map[string]*model.User) *model.AppError {
	if len(profiles) == 0 {
		return nil
	}

	var usernames []string
	for _, user := range profiles {
		usernames = append(usernames, user.Username)
	}
	sort.Strings(usernames)

	T := utils.GetUserTranslations(profiles[post.UserId].Locale)

	var message string
	if len(usernames) == 1 {
		message = T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
			"Username": usernames[0],
		})
	} else {
		message = T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
			"Usernames":    strings.Join(usernames[:len(usernames)-1], ", "),
			"LastUsername": usernames[len(usernames)-1],
		})
	}

	SendEphemeralPost(
		teamId,
		post.UserId,
		&model.Post{
			ChannelId: post.ChannelId,
			Message:   message,
			CreateAt:  post.CreateAt + 1,
		},
	)

	return nil
}
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:37,代码来源:notification.go


示例6: sendNotifications


//.........这里部分代码省略.........
				} else {
					toEmailMap[userId] = false
				}
			}
		}

		for id := range toEmailMap {
			updateMentionCountAndForget(post.ChannelId, id)
		}
	}

	if len(toEmailMap) != 0 {
		mentionedUsers = make([]string, 0, len(toEmailMap))
		for k := range toEmailMap {
			mentionedUsers = append(mentionedUsers, k)
		}

		teamURL := c.GetSiteURL() + "/" + team.Name

		// Build and send the emails
		tm := time.Unix(post.CreateAt/1000, 0)

		for id, doSend := range toEmailMap {

			if !doSend {
				continue
			}

			// skip if inactive
			if profileMap[id].DeleteAt > 0 {
				continue
			}

			userLocale := utils.GetUserTranslations(profileMap[id].Locale)

			if channel.Type == model.CHANNEL_DIRECT {
				bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
				subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")
			} else {
				bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
				subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
				channelName = channel.DisplayName
			}

			month := userLocale(tm.Month().String())
			day := fmt.Sprintf("%d", tm.Day())
			year := fmt.Sprintf("%d", tm.Year())
			zone, _ := tm.Zone()

			subjectPage := utils.NewHTMLTemplate("post_subject", profileMap[id].Locale)
			subjectPage.Props["Subject"] = userLocale("api.templates.post_subject",
				map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
					"Month": month[:3], "Day": day, "Year": year})
			subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName

			bodyPage := utils.NewHTMLTemplate("post_body", profileMap[id].Locale)
			bodyPage.Props["SiteURL"] = c.GetSiteURL()
			bodyPage.Props["PostMessage"] = model.ClearMentionTags(post.Message)
			bodyPage.Props["TeamLink"] = teamURL + "/channels/" + channel.Name
			bodyPage.Props["BodyText"] = bodyText
			bodyPage.Props["Button"] = userLocale("api.templates.post_body.button")
			bodyPage.Html["Info"] = template.HTML(userLocale("api.templates.post_body.info",
				map[string]interface{}{"ChannelName": channelName, "SenderName": senderName,
					"Hour": fmt.Sprintf("%02d", tm.Hour()), "Minute": fmt.Sprintf("%02d", tm.Minute()),
					"TimeZone": zone, "Month": month, "Day": day}))
开发者ID:carriercomm,项目名称:platform,代码行数:66,代码来源:post.go


示例7: TestGetMessageForNotification

func TestGetMessageForNotification(t *testing.T) {
	Setup().InitBasic()

	testPng := store.Must(Srv.Store.FileInfo().Save(&model.FileInfo{
		CreatorId: model.NewId(),
		Path:      "test1.png",
		Name:      "test1.png",
		MimeType:  "image/png",
	})).(*model.FileInfo)

	testJpg1 := store.Must(Srv.Store.FileInfo().Save(&model.FileInfo{
		CreatorId: model.NewId(),
		Path:      "test2.jpg",
		Name:      "test2.jpg",
		MimeType:  "image/jpeg",
	})).(*model.FileInfo)

	testFile := store.Must(Srv.Store.FileInfo().Save(&model.FileInfo{
		CreatorId: model.NewId(),
		Path:      "test1.go",
		Name:      "test1.go",
		MimeType:  "text/plain",
	})).(*model.FileInfo)

	testJpg2 := store.Must(Srv.Store.FileInfo().Save(&model.FileInfo{
		CreatorId: model.NewId(),
		Path:      "test3.jpg",
		Name:      "test3.jpg",
		MimeType:  "image/jpeg",
	})).(*model.FileInfo)

	translateFunc := utils.GetUserTranslations("en")

	post := &model.Post{
		Id:      model.NewId(),
		Message: "test",
	}

	if getMessageForNotification(post, translateFunc) != "test" {
		t.Fatal("should've returned message text")
	}

	post.FileIds = model.StringArray{testPng.Id}
	store.Must(Srv.Store.FileInfo().AttachToPost(testPng.Id, post.Id))
	if getMessageForNotification(post, translateFunc) != "test" {
		t.Fatal("should've returned message text, even with attachments")
	}

	post.Message = ""
	if message := getMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" {
		t.Fatal("should've returned number of images:", message)
	}

	post.FileIds = model.StringArray{testPng.Id, testJpg1.Id}
	store.Must(Srv.Store.FileInfo().AttachToPost(testJpg1.Id, post.Id))
	if message := getMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" && message != "2 images sent: test2.jpg, test1.png" {
		t.Fatal("should've returned number of images:", message)
	}

	post.Id = model.NewId()
	post.FileIds = model.StringArray{testFile.Id}
	store.Must(Srv.Store.FileInfo().AttachToPost(testFile.Id, post.Id))
	if message := getMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" {
		t.Fatal("should've returned number of files:", message)
	}

	store.Must(Srv.Store.FileInfo().AttachToPost(testJpg2.Id, post.Id))
	post.FileIds = model.StringArray{testFile.Id, testJpg2.Id}
	if message := getMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test3.jpg" && message != "2 files sent: test3.jpg, test1.go" {
		t.Fatal("should've returned number of mixed files:", message)
	}
}
开发者ID:Rudloff,项目名称:platform,代码行数:72,代码来源:post_test.go


示例8: sendNotificationEmail

func sendNotificationEmail(c *Context, post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string, sender *model.User) {
	// skip if inactive
	if user.DeleteAt > 0 {
		return
	}

	if channel.Type == model.CHANNEL_DIRECT && channel.TeamId != team.Id {
		// this message is a cross-team DM so it we need to find a team that the recipient is on to use in the link
		if result := <-Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil {
			l4g.Error(utils.T("api.post.send_notifications_and_forget.get_teams.error"), user.Id, result.Err)
			return
		} else {
			// if the recipient isn't in the current user's team, just pick one
			teams := result.Data.([]*model.Team)
			found := false

			for i := range teams {
				if teams[i].Id == team.Id {
					found = true
					break
				}
			}

			if !found {
				team = teams[0]
			}
		}
	}

	if *utils.Cfg.EmailSettings.EnableEmailBatching {
		var sendBatched bool

		if result := <-Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); result.Err != nil {
			// if the call fails, assume it hasn't been set and use the default
			sendBatched = false
		} else {
			// default to not using batching if the setting is set to immediate
			sendBatched = result.Data.(model.Preference).Value != model.PREFERENCE_DEFAULT_EMAIL_INTERVAL
		}

		if sendBatched {
			if err := AddNotificationEmailToBatch(user, post, team); err == nil {
				return
			}
		}

		// fall back to sending a single email if we can't batch it for some reason
	}

	var channelName string
	var bodyText string
	var subjectText string
	var mailTemplate string
	var mailParameters map[string]interface{}

	teamURL := c.GetSiteURL() + "/" + team.Name
	tm := time.Unix(post.CreateAt/1000, 0)

	userLocale := utils.GetUserTranslations(user.Locale)
	month := userLocale(tm.Month().String())
	day := fmt.Sprintf("%d", tm.Day())
	year := fmt.Sprintf("%d", tm.Year())
	zone, _ := tm.Zone()

	if channel.Type == model.CHANNEL_DIRECT {
		bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")

		senderDisplayName := senderName
		if sender != nil {
			if result := <-Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format"); result.Err != nil {
				// Show default sender's name if user doesn't set display settings.
				senderDisplayName = senderName
			} else {
				senderDisplayName = sender.GetDisplayNameForPreference(result.Data.(model.Preference).Value)
			}
		}

		mailTemplate = "api.templates.post_subject_in_direct_message"
		mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
			"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
	} else {
		bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
		channelName = channel.DisplayName
		mailTemplate = "api.templates.post_subject_in_channel"
		mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
			"ChannelName": channelName, "Month": month, "Day": day, "Year": year}
	}

	subjectPage := utils.NewHTMLTemplate("post_subject", user.Locale)
	subjectPage.Props["Subject"] = userLocale(mailTemplate, mailParameters)
	subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName

	bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
	bodyPage.Props["SiteURL"] = c.GetSiteURL()
	bodyPage.Props["PostMessage"] = getMessageForNotification(post, userLocale)
	bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
	bodyPage.Props["BodyText"] = bodyText
	bodyPage.Props["Button"] = userLocale("api.templates.post_body.button")
//.........这里部分代码省略.........
开发者ID:boreys,项目名称:platform,代码行数:101,代码来源:post.go


示例9: sendPushNotification

func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, wasMentioned bool) {
	var sessions []*model.Session
	if result := <-Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
		l4g.Error(utils.T("api.post.send_notifications_and_forget.sessions.error"), user.Id, result.Err)
		return
	} else {
		sessions = result.Data.([]*model.Session)
	}

	var channelName string

	if channel.Type == model.CHANNEL_DIRECT {
		channelName = senderName
	} else {
		channelName = channel.DisplayName
	}

	userLocale := utils.GetUserTranslations(user.Locale)

	for _, session := range sessions {
		if len(session.DeviceId) > 0 &&
			(strings.HasPrefix(session.DeviceId, model.PUSH_NOTIFY_APPLE+":") || strings.HasPrefix(session.DeviceId, model.PUSH_NOTIFY_ANDROID+":")) {

			msg := model.PushNotification{}
			if badge := <-Srv.Store.User().GetUnreadCount(user.Id); badge.Err != nil {
				msg.Badge = 1
				l4g.Error(utils.T("store.sql_user.get_unread_count.app_error"), user.Id, badge.Err)
			} else {
				msg.Badge = int(badge.Data.(int64))
			}
			msg.ServerId = utils.CfgDiagnosticId
			msg.ChannelId = channel.Id
			msg.ChannelName = channel.Name

			if strings.HasPrefix(session.DeviceId, model.PUSH_NOTIFY_APPLE+":") {
				msg.Platform = model.PUSH_NOTIFY_APPLE
				msg.DeviceId = strings.TrimPrefix(session.DeviceId, model.PUSH_NOTIFY_APPLE+":")
			} else if strings.HasPrefix(session.DeviceId, model.PUSH_NOTIFY_ANDROID+":") {
				msg.Platform = model.PUSH_NOTIFY_ANDROID
				msg.DeviceId = strings.TrimPrefix(session.DeviceId, model.PUSH_NOTIFY_ANDROID+":")
			}

			if *utils.Cfg.EmailSettings.PushNotificationContents == model.FULL_NOTIFICATION {
				if channel.Type == model.CHANNEL_DIRECT {
					msg.Category = model.CATEGORY_DM
					msg.Message = "@" + senderName + ": " + model.ClearMentionTags(post.Message)
				} else {
					msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_in") + channelName + ": " + model.ClearMentionTags(post.Message)
				}
			} else {
				if channel.Type == model.CHANNEL_DIRECT {
					msg.Category = model.CATEGORY_DM
					msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
				} else if wasMentioned {
					msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention") + channelName
				} else {
					msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_non_mention") + channelName
				}
			}

			tr := &http.Transport{
				TLSClientConfig: &tls.Config{InsecureSkipVerify: *utils.Cfg.ServiceSettings.EnableInsecureOutgoingConnections},
			}
			httpClient := &http.Client{Transport: tr}
			request, _ := http.NewRequest("POST", *utils.Cfg.EmailSettings.PushNotificationServer+model.API_URL_SUFFIX_V1+"/send_push", strings.NewReader(msg.ToJson()))

			l4g.Debug(utils.T("api.post.send_notifications_and_forget.push_notification.debug"), msg.DeviceId, msg.Message)
			if _, err := httpClient.Do(request); err != nil {
				l4g.Error(utils.T("api.post.send_notifications_and_forget.push_notification.error"), user.Id, err)
			}

			// notification sent, don't need to check other sessions
			break
		}
	}
}
开发者ID:42wim,项目名称:platform,代码行数:76,代码来源:post.go


示例10: sendNotificationEmail

func sendNotificationEmail(c *Context, post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string) {
	// skip if inactive
	if user.DeleteAt > 0 {
		return
	}

	var channelName string
	var bodyText string
	var subjectText string

	teamURL := c.GetSiteURL() + "/" + team.Name
	tm := time.Unix(post.CreateAt/1000, 0)

	userLocale := utils.GetUserTranslations(user.Locale)

	if channel.Type == model.CHANNEL_DIRECT {
		bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")
		channelName = senderName
	} else {
		bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
		channelName = channel.DisplayName
	}

	month := userLocale(tm.Month().String())
	day := fmt.Sprintf("%d", tm.Day())
	year := fmt.Sprintf("%d", tm.Year())
	zone, _ := tm.Zone()

	subjectPage := utils.NewHTMLTemplate("post_subject", user.Locale)
	subjectPage.Props["Subject"] = userLocale("api.templates.post_subject",
		map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
			"Month": month[:3], "Day": day, "Year": year})
	subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName

	bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
	bodyPage.Props["SiteURL"] = c.GetSiteURL()
	bodyPage.Props["PostMessage"] = model.ClearMentionTags(post.Message)
	bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
	bodyPage.Props["BodyText"] = bodyText
	bodyPage.Props["Button"] = userLocale("api.templates.post_body.button")
	bodyPage.Html["Info"] = template.HTML(userLocale("api.templates.post_body.info",
		map[string]interface{}{"ChannelName": channelName, "SenderName": senderName,
			"Hour": fmt.Sprintf("%02d", tm.Hour()), "Minute": fmt.Sprintf("%02d", tm.Minute()),
			"TimeZone": zone, "Month": month, "Day": day}))

	// attempt to fill in a message body if the post doesn't have any text
	if len(strings.TrimSpace(bodyPage.Props["PostMessage"])) == 0 && len(post.Filenames) > 0 {
		// extract the filenames from their paths and determine what type of files are attached
		filenames := make([]string, len(post.Filenames))
		onlyImages := true
		for i, filename := range post.Filenames {
			var err error
			if filenames[i], err = url.QueryUnescape(filepath.Base(filename)); err != nil {
				// this should never error since filepath was escaped using url.QueryEscape
				filenames[i] = filepath.Base(filename)
			}

			ext := filepath.Ext(filename)
			onlyImages = onlyImages && model.IsFileExtImage(ext)
		}
		filenamesString := strings.Join(filenames, ", ")

		var attachmentPrefix string
		if onlyImages {
			attachmentPrefix = "Image"
		} else {
			attachmentPrefix = "File"
		}
		if len(post.Filenames) > 1 {
			attachmentPrefix += "s"
		}

		bodyPage.Props["PostMessage"] = userLocale("api.post.send_notifications_and_forget.sent",
			map[string]interface{}{"Prefix": attachmentPrefix, "Filenames": filenamesString})
	}

	if err := utils.SendMail(user.Email, subjectPage.Render(), bodyPage.Render()); err != nil {
		l4g.Error(utils.T("api.post.send_notifications_and_forget.send.error"), user.Email, err)
	}
}
开发者ID:42wim,项目名称:platform,代码行数:82,代码来源:post.go


示例11: sendNotificationEmail

func sendNotificationEmail(c *Context, post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string, sender *model.User) {
	// skip if inactive
	if user.DeleteAt > 0 {
		return
	}

	if *utils.Cfg.EmailSettings.EnableEmailBatching {
		if err := AddNotificationEmailToBatch(user, post, team); err == nil {
			return
		}

		// fall back to sending a single email if we can't batch it for some reason
	}

	var channelName string
	var bodyText string
	var subjectText string
	var mailTemplate string
	var mailParameters map[string]interface{}

	teamURL := c.GetSiteURL() + "/" + team.Name
	tm := time.Unix(post.CreateAt/1000, 0)

	userLocale := utils.GetUserTranslations(user.Locale)
	month := userLocale(tm.Month().String())
	day := fmt.Sprintf("%d", tm.Day())
	year := fmt.Sprintf("%d", tm.Year())
	zone, _ := tm.Zone()

	if channel.Type == model.CHANNEL_DIRECT {
		bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")

		senderDisplayName := senderName
		if sender != nil {
			if result := <-Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format"); result.Err != nil {
				// Show default sender's name if user doesn't set display settings.
				senderDisplayName = senderName
			} else {
				senderDisplayName = sender.GetDisplayNameForPreference(result.Data.(model.Preference).Value)
			}
		}

		mailTemplate = "api.templates.post_subject_in_direct_message"
		mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
			"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
	} else {
		bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
		subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
		channelName = channel.DisplayName
		mailTemplate = "api.templates.post_subject_in_channel"
		mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
			"ChannelName": channelName, "Month": month, "Day": day, "Year": year}
	}

	subjectPage := utils.NewHTMLTemplate("post_subject", user.Locale)
	subjectPage.Props["Subject"] = userLocale(mailTemplate, mailParameters)
	subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName

	bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
	bodyPage.Props["SiteURL"] = c.GetSiteURL()
	bodyPage.Props["PostMessage"] = getMessageForNotification(post, userLocale)
	bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
	bodyPage.Props["BodyText"] = bodyText
	bodyPage.Props["Button"] = userLocale("api.templates.post_body.button")
	bodyPage.Html["Info"] = template.HTML(userLocale("api.templates.post_body.info",
		map[string]interface{}{"ChannelName": channelName, "SenderName": senderName,
			"Hour": fmt.Sprintf("%02d", tm.Hour()), "Minute": fmt.Sprintf("%02d", tm.Minute()),
			"TimeZone": zone, "Month": month, "Day": day}))

	if err := utils.SendMail(user.Email, subjectPage.Render(), bodyPage.Render()); err != nil {
		l4g.Error(utils.T("api.post.send_notifications_and_forget.send.error"), user.Email, err)
	}
}
开发者ID:TribeMedia,项目名称:platform,代码行数:74,代码来源:post.go


示例12: SendNotifications


//.........这里部分代码省略.........
			sender = profile
		}
	}

	var senderUsername string
	if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" {
		senderUsername = value.(string)
	} else {
		senderUsername = profileMap[post.UserId].Username
	}

	if utils.Cfg.EmailSettings.SendEmailNotifications {
		for _, id := range mentionedUsersList {
			userAllowsEmails := profileMap[id].NotifyProps["email"] != "false"

			var status *model.Status
			var err *model.AppError
			if status, err = GetStatus(id); err != nil {
				status = &model.Status{
					UserId:         id,
					Status:         model.STATUS_OFFLINE,
					Manual:         false,
					LastActivityAt: 0,
					ActiveChannel:  "",
				}
			}

			if userAllowsEmails && status.Status != model.STATUS_ONLINE && profileMap[id].DeleteAt == 0 {
				sendNotificationEmail(post, profileMap[id], channel, team, senderName[id], sender)
			}
		}
	}

	T := utils.GetUserTranslations(profileMap[post.UserId].Locale)

	// If the channel has more than 1K users then @here is disabled
	if hereNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
		hereNotification = false
		SendEphemeralPost(
			team.Id,
			post.UserId,
			&model.Post{
				ChannelId: post.ChannelId,
				Message:   T("api.post.disabled_here", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
				CreateAt:  post.CreateAt + 1,
			},
		)
	}

	// If the channel has more than 1K users then @channel is disabled
	if channelNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
		SendEphemeralPost(
			team.Id,
			post.UserId,
			&model.Post{
				ChannelId: post.ChannelId,
				Message:   T("api.post.disabled_channel", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
				CreateAt:  post.CreateAt + 1,
			},
		)
	}

	// If the channel has more than 1K users then @all is disabled
	if allNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
		SendEphemeralPost(
			team.Id,
开发者ID:ZJvandeWeg,项目名称:platform,代码行数:67,代码来源:notification.go


示例13: sendNotificationsAndForget


//.........这里部分代码省略.........
						} else {
							toEmailMap[userId] = false
						}
					}
				}

				for id := range toEmailMap {
					updateMentionCountAndForget(post.ChannelId, id)
				}
			}

			if len(toEmailMap) != 0 {
				mentionedUsers = make([]string, 0, len(toEmailMap))
				for k := range toEmailMap {
					mentionedUsers = append(mentionedUsers, k)
				}

				teamURL := c.GetSiteURL() + "/" + team.Name

				// Build and send the emails
				tm := time.Unix(post.CreateAt/1000, 0)

				for id, doSend := range toEmailMap {

					if !doSend {
						continue
					}

					// skip if inactive
					if profileMap[id].DeleteAt > 0 {
						continue
					}

					userLocale := utils.GetUserTranslations(profileMap[id].Locale)

					if channel.Type == model.CHANNEL_DIRECT {
						bodyText = userLocale("api.post.send_notifications_and_forget.message_body")
						subjectText = userLocale("api.post.send_notifications_and_forget.message_subject")
					} else {
						bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
						subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
						channelName = channel.DisplayName
					}

					subjectPage := NewServerTemplatePage("post_subject")
					subjectPage.Props["SiteURL"] = c.GetSiteURL()
					subjectPage.Props["TeamDisplayName"] = team.DisplayName
					subjectPage.Props["SubjectText"] = subjectText
					subjectPage.Props["Month"] = tm.Month().String()[:3]
					subjectPage.Props["Day"] = fmt.Sprintf("%d", tm.Day())
					subjectPage.Props["Year"] = fmt.Sprintf("%d", tm.Year())

					bodyPage := NewServerTemplatePage("post_body")
					bodyPage.Props["SiteURL"] = c.GetSiteURL()
					bodyPage.Props["Nickname"] = profileMap[id].FirstName
					bodyPage.Props["TeamDisplayName"] = team.DisplayName
					bodyPage.Props["ChannelName"] = channelName
					bodyPage.Props["BodyText"] = bodyText
					bodyPage.Props["SenderName"] = senderName
					bodyPage.Props["Hour"] = fmt.Sprintf("%02d", tm.Hour())
					bodyPage.Props["Minute"] = fmt.Sprintf("%02d", tm.Minute())
					bodyPage.Props["Month"] = tm.Month().String()[:3]
					bodyPage.Props["Day"] = fmt.Sprintf("%d", tm.Day())
					bodyPage.Props["TimeZone"], _ = tm.Zone()
					bodyPage.Props["PostMessage"] = model.ClearMentionTags(post.Message)
					bodyPage.Props["TeamLink"] = teamURL + "/channels/" + channel.Name
开发者ID:bitbackofen,项目名称:platform,代码行数:67,代码来源:post.go



注:本文中的github.com/mattermost/platform/utils.GetUserTranslations函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang utils.InitHTML函数代码示例发布时间:2022-05-23
下一篇:
Golang utils.GetTranslationsAndLocale函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap