Added helper methods to send ephemeral messages to specific users
Этот коммит содержится в:
54
api/post.go
54
api/post.go
@@ -747,34 +747,27 @@ func checkForOutOfChannelMentions(c *Context, post *model.Post, channel *model.C
|
|||||||
}
|
}
|
||||||
sort.Strings(usernames)
|
sort.Strings(usernames)
|
||||||
|
|
||||||
var messageText string
|
var message string
|
||||||
if len(usernames) == 1 {
|
if len(usernames) == 1 {
|
||||||
messageText = c.T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
|
message = c.T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
|
||||||
"Username": usernames[0],
|
"Username": usernames[0],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
messageText = c.T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
|
message = c.T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
|
||||||
"Usernames": strings.Join(usernames[:len(usernames)-1], ", "),
|
"Usernames": strings.Join(usernames[:len(usernames)-1], ", "),
|
||||||
"LastUsername": usernames[len(usernames)-1],
|
"LastUsername": usernames[len(usernames)-1],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// create an ephemeral post that will be sent only to the sender of this original post and not stored in the DB
|
SendEphemeralPost(
|
||||||
warningPost := model.Post{
|
c.Session.TeamId,
|
||||||
Id: model.NewId(),
|
post.UserId,
|
||||||
ChannelId: post.ChannelId,
|
&model.Post{
|
||||||
Message: messageText,
|
ChannelId: post.ChannelId,
|
||||||
Type: model.POST_EPHEMERAL,
|
Message: message,
|
||||||
CreateAt: post.CreateAt + 1,
|
CreateAt: post.CreateAt + 1,
|
||||||
Props: model.StringInterface{},
|
},
|
||||||
Filenames: []string{},
|
)
|
||||||
}
|
|
||||||
|
|
||||||
message := model.NewMessage(c.Session.TeamId, channel.Id, post.UserId, model.ACTION_EPHEMERAL_MESSAGE)
|
|
||||||
message.Add("post", warningPost.ToJson())
|
|
||||||
message.Add("channel_type", channel.Type)
|
|
||||||
|
|
||||||
PublishAndForget(message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a list of users that were mentioned in a given post that aren't in the channel that the post was made in
|
// Gets a list of users that were mentioned in a given post that aren't in the channel that the post was made in
|
||||||
@@ -803,6 +796,29 @@ func getOutOfChannelMentions(post *model.Post, allProfiles map[string]*model.Use
|
|||||||
return mentioned
|
return mentioned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SendEphemeralPost(teamId, userId string, post *model.Post) {
|
||||||
|
post.Type = model.POST_EPHEMERAL
|
||||||
|
|
||||||
|
// fill in fields which haven't been specified which have sensible defaults
|
||||||
|
if post.Id == "" {
|
||||||
|
post.Id = model.NewId()
|
||||||
|
}
|
||||||
|
if post.CreateAt == 0 {
|
||||||
|
post.CreateAt = model.GetMillis()
|
||||||
|
}
|
||||||
|
if post.Props == nil {
|
||||||
|
post.Props = model.StringInterface{}
|
||||||
|
}
|
||||||
|
if post.Filenames == nil {
|
||||||
|
post.Filenames = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
|
||||||
|
message.Add("post", post.ToJson())
|
||||||
|
|
||||||
|
PublishAndForget(message)
|
||||||
|
}
|
||||||
|
|
||||||
func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
post := model.PostFromJson(r.Body)
|
post := model.PostFromJson(r.Body)
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import Constants from '../utils/constants.jsx';
|
|||||||
const ActionTypes = Constants.ActionTypes;
|
const ActionTypes = Constants.ActionTypes;
|
||||||
import * as AsyncClient from '../utils/async_client.jsx';
|
import * as AsyncClient from '../utils/async_client.jsx';
|
||||||
import * as Client from '../utils/client.jsx';
|
import * as Client from '../utils/client.jsx';
|
||||||
|
import * as Utils from '../utils/utils.jsx';
|
||||||
|
|
||||||
export function emitChannelClickEvent(channel) {
|
export function emitChannelClickEvent(channel) {
|
||||||
AsyncClient.getChannels(true);
|
AsyncClient.getChannels(true);
|
||||||
@@ -187,3 +188,20 @@ export function emitRemovePost(post) {
|
|||||||
post
|
post
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sendEphemeralPost(message, channelId) {
|
||||||
|
const timestamp = Utils.getTimestamp();
|
||||||
|
const post = {
|
||||||
|
id: Utils.generateId(),
|
||||||
|
user_id: '0',
|
||||||
|
channel_id: channelId || ChannelStore.getCurrentId(),
|
||||||
|
message,
|
||||||
|
type: Constants.POST_TYPE_EPHEMERAL,
|
||||||
|
create_at: timestamp,
|
||||||
|
update_at: timestamp,
|
||||||
|
filenames: [],
|
||||||
|
props: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
emitPostRecievedEvent(post);
|
||||||
|
}
|
||||||
|
|||||||
@@ -180,7 +180,6 @@ function handleNewPostEvent(msg, translations) {
|
|||||||
mentions = JSON.parse(msg.props.mentions);
|
mentions = JSON.parse(msg.props.mentions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelType = msgProps.channel_type;
|
|
||||||
const channel = ChannelStore.get(msg.channel_id);
|
const channel = ChannelStore.get(msg.channel_id);
|
||||||
const user = UserStore.getCurrentUser();
|
const user = UserStore.getCurrentUser();
|
||||||
const member = ChannelStore.getMember(msg.channel_id);
|
const member = ChannelStore.getMember(msg.channel_id);
|
||||||
@@ -192,7 +191,7 @@ function handleNewPostEvent(msg, translations) {
|
|||||||
|
|
||||||
if (notifyLevel === 'none') {
|
if (notifyLevel === 'none') {
|
||||||
return;
|
return;
|
||||||
} else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channelType !== Constants.DM_CHANNEL) {
|
} else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== Constants.DM_CHANNEL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user