summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-01-20 13:36:16 -0600
committerCorey Hulen <corey@hulen.com>2016-01-20 13:36:16 -0600
commitaefbb541d0d5bdd9919fef44fbf1a1fbfeaeb58b (patch)
treed87809ff2a306e5428b0ab6973d05509baa21abd /api/channel.go
parent0b1aff3b24b4ac2df8e963c83d6e52b127c603f9 (diff)
downloadchat-aefbb541d0d5bdd9919fef44fbf1a1fbfeaeb58b.tar.gz
chat-aefbb541d0d5bdd9919fef44fbf1a1fbfeaeb58b.tar.bz2
chat-aefbb541d0d5bdd9919fef44fbf1a1fbfeaeb58b.zip
Revert " PLT-7 adding loc for db calls"
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go132
1 files changed, 65 insertions, 67 deletions
diff --git a/api/channel.go b/api/channel.go
index 476c20909..706baa004 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -5,14 +5,12 @@ package api
import (
"fmt"
- "net/http"
- "strconv"
- "strings"
-
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
- goi18n "github.com/nicksnyder/go-i18n/i18n"
+ "net/http"
+ "strconv"
+ "strings"
)
const (
@@ -78,7 +76,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
- if result := <-Srv.Store.Channel().Save(c.T, channel); result.Err != nil {
+ if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
return nil, result.Err
} else {
sc := result.Data.(*model.Channel)
@@ -87,7 +85,7 @@ func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.C
cm := &model.ChannelMember{ChannelId: sc.Id, UserId: c.Session.UserId,
Roles: model.CHANNEL_ROLE_ADMIN, NotifyProps: model.GetDefaultChannelNotifyProps()}
- if cmresult := <-Srv.Store.Channel().SaveMember(c.T, cm); cmresult.Err != nil {
+ if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
return nil, cmresult.Err
}
}
@@ -125,7 +123,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
}
- uc := Srv.Store.User().Get(c.T, otherUserId)
+ uc := Srv.Store.User().Get(otherUserId)
channel := new(model.Channel)
@@ -151,7 +149,7 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
NotifyProps: model.GetDefaultChannelNotifyProps(),
}
- if result := <-Srv.Store.Channel().SaveDirectChannel(c.T, channel, cm1, cm2); result.Err != nil {
+ if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.Channel), nil
@@ -184,8 +182,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(c.T, channel.Id)
- cmc := Srv.Store.Channel().GetMember(c.T, channel.Id, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(channel.Id)
+ cmc := Srv.Store.Channel().GetMember(channel.Id, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -235,7 +233,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type
}
- if ucresult := <-Srv.Store.Channel().Update(c.T, oldChannel); ucresult.Err != nil {
+ if ucresult := <-Srv.Store.Channel().Update(oldChannel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -260,8 +258,8 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(c.T, channelId)
- cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(channelId)
+ cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -279,7 +277,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header
channel.Header = channelHeader
- if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
+ if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -292,7 +290,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
go func() {
- uc := Srv.Store.User().Get(c.T, c.Session.UserId)
+ uc := Srv.Store.User().Get(c.Session.UserId)
if uresult := <-uc; uresult.Err != nil {
l4g.Error("Failed to retrieve user while trying to save update channel header message %v", uresult.Err)
@@ -335,8 +333,8 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(c.T, channelId)
- cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(channelId)
+ cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -354,7 +352,7 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
channel.Purpose = channelPurpose
- if ucresult := <-Srv.Store.Channel().Update(c.T, channel); ucresult.Err != nil {
+ if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -368,10 +366,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
- if result := <-Srv.Store.Channel().GetChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
if result.Err.Message == "No channels were found" {
// lets make sure the user is valid
- if result := <-Srv.Store.User().Get(c.T, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
c.Err = result.Err
c.RemoveSessionCookie(w, r)
l4g.Error("Error in getting users profile for id=%v forcing logout", c.Session.UserId)
@@ -393,7 +391,7 @@ func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
- if result := <-Srv.Store.Channel().GetMoreChannels(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetMoreChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else if HandleEtag(result.Data.(*model.ChannelList).Etag(), w, r) {
@@ -409,7 +407,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
- if result := <-Srv.Store.Channel().GetChannelCounts(c.T, c.Session.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetChannelCounts(c.Session.TeamId, c.Session.UserId); result.Err != nil {
c.Err = model.NewAppError("getChannelCounts", "Unable to get channel counts from the database", result.Err.Message)
return
} else if HandleEtag(result.Data.(*model.ChannelCounts).Etag(), w, r) {
@@ -439,8 +437,8 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
func JoinChannel(c *Context, channelId string, role string) {
- sc := Srv.Store.Channel().Get(c.T, channelId)
- uc := Srv.Store.User().Get(c.T, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(channelId)
+ uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -457,7 +455,7 @@ func JoinChannel(c *Context, channelId string, role string) {
}
if channel.Type == model.CHANNEL_OPEN {
- if _, err := AddUserToChannel(c.T, user, channel); err != nil {
+ if _, err := AddUserToChannel(user, channel); err != nil {
c.Err = err
return
}
@@ -483,7 +481,7 @@ func PostUserAddRemoveMessageAndForget(c *Context, channelId string, message str
}()
}
-func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
+func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
if channel.DeleteAt > 0 {
return nil, model.NewAppError("AddUserToChannel", "The channel has been archived or deleted", "")
}
@@ -493,7 +491,7 @@ func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.C
}
newMember := &model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
- if cmresult := <-Srv.Store.Channel().SaveMember(T, newMember); cmresult.Err != nil {
+ if cmresult := <-Srv.Store.Channel().SaveMember(newMember); cmresult.Err != nil {
l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, cmresult.Err)
return nil, model.NewAppError("AddUserToChannel", "Failed to add user to channel", "")
}
@@ -508,29 +506,29 @@ func AddUserToChannel(T goi18n.TranslateFunc, user *model.User, channel *model.C
return newMember, nil
}
-func JoinDefaultChannels(T goi18n.TranslateFunc, user *model.User, channelRole string) *model.AppError {
+func JoinDefaultChannels(user *model.User, channelRole string) *model.AppError {
// We don't call JoinChannel here since c.Session is not populated on user creation
var err *model.AppError = nil
- if result := <-Srv.Store.Channel().GetByName(T, user.TeamId, "town-square"); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetByName(user.TeamId, "town-square"); result.Err != nil {
err = result.Err
} else {
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
- if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
+ if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
}
- if result := <-Srv.Store.Channel().GetByName(T, user.TeamId, "off-topic"); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetByName(user.TeamId, "off-topic"); result.Err != nil {
err = result.Err
} else {
cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
- if cmResult := <-Srv.Store.Channel().SaveMember(T, cm); cmResult.Err != nil {
+ if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
}
@@ -543,8 +541,8 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
- sc := Srv.Store.Channel().Get(c.T, id)
- uc := Srv.Store.User().Get(c.T, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(id)
+ uc := Srv.Store.User().Get(c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -572,12 +570,12 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if cmresult := <-Srv.Store.Channel().RemoveMember(c.T, channel.Id, c.Session.UserId); cmresult.Err != nil {
+ if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, c.Session.UserId); cmresult.Err != nil {
c.Err = cmresult.Err
return
}
- RemoveUserFromChannel(c.T, c.Session.UserId, c.Session.UserId, channel)
+ RemoveUserFromChannel(c.Session.UserId, c.Session.UserId, channel)
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v has left the channel.`, user.Username))
@@ -592,11 +590,11 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
- sc := Srv.Store.Channel().Get(c.T, id)
- scm := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
- uc := Srv.Store.User().Get(c.T, c.Session.UserId)
- ihc := Srv.Store.Webhook().GetIncomingByChannel(c.T, id)
- ohc := Srv.Store.Webhook().GetOutgoingByChannel(c.T, id)
+ sc := Srv.Store.Channel().Get(id)
+ scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
+ uc := Srv.Store.User().Get(c.Session.UserId)
+ ihc := Srv.Store.Webhook().GetIncomingByChannel(id)
+ ohc := Srv.Store.Webhook().GetOutgoingByChannel(id)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -645,7 +643,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
now := model.GetMillis()
for _, hook := range incomingHooks {
go func() {
- if result := <-Srv.Store.Webhook().DeleteIncoming(c.T, hook.Id, now); result.Err != nil {
+ if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting incoming webhook, id=" + hook.Id)
}
}()
@@ -653,13 +651,13 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
for _, hook := range outgoingHooks {
go func() {
- if result := <-Srv.Store.Webhook().DeleteOutgoing(c.T, hook.Id, now); result.Err != nil {
+ if result := <-Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting outgoing webhook, id=" + hook.Id)
}
}()
}
- if dresult := <-Srv.Store.Channel().Delete(c.T, channel.Id, model.GetMillis()); dresult.Err != nil {
+ if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return
}
@@ -685,7 +683,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["id"]
- Srv.Store.Channel().UpdateLastViewedAt(c.T, id, c.Session.UserId)
+ Srv.Store.Channel().UpdateLastViewedAt(id, c.Session.UserId)
preference := model.Preference{
UserId: c.Session.UserId,
@@ -694,7 +692,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
Value: id,
}
- Srv.Store.Preference().Save(c.T, &model.Preferences{preference})
+ Srv.Store.Preference().Save(&model.Preferences{preference})
message := model.NewMessage(c.Session.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
message.Add("channel_id", id)
@@ -711,8 +709,8 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
id := params["id"]
//pchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
- cchan := Srv.Store.Channel().Get(c.T, id)
- cmchan := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
+ cchan := Srv.Store.Channel().Get(id)
+ cmchan := Srv.Store.Channel().GetMember(id, c.Session.UserId)
if cresult := <-cchan; cresult.Err != nil {
c.Err = cresult.Err
@@ -751,7 +749,7 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
memberLimit = int(memberLimitInt64)
}
- sc := Srv.Store.Channel().Get(c.T, id)
+ sc := Srv.Store.Channel().Get(id)
var channel *model.Channel
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -765,9 +763,9 @@ func getChannelExtraInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- scm := Srv.Store.Channel().GetMember(c.T, id, c.Session.UserId)
- ecm := Srv.Store.Channel().GetExtraMembers(c.T, id, memberLimit)
- ccm := Srv.Store.Channel().GetMemberCount(c.T, id)
+ scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
+ ecm := Srv.Store.Channel().GetExtraMembers(id, memberLimit)
+ ccm := Srv.Store.Channel().GetMemberCount(id)
if cmresult := <-scm; cmresult.Err != nil {
c.Err = cmresult.Err
@@ -816,10 +814,10 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
- sc := Srv.Store.Channel().Get(c.T, id)
- ouc := Srv.Store.User().Get(c.T, c.Session.UserId)
- nuc := Srv.Store.User().Get(c.T, userId)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(id)
+ ouc := Srv.Store.User().Get(c.Session.UserId)
+ nuc := Srv.Store.User().Get(userId)
// Only need to be a member of the channel to add a new member
if !c.HasPermissionsToChannel(cchan, "addMember") {
@@ -842,7 +840,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
oUser := oresult.Data.(*model.User)
- cm, err := AddUserToChannel(c.T, nUser, channel)
+ cm, err := AddUserToChannel(nUser, channel)
if err != nil {
c.Err = err
return
@@ -852,7 +850,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v added to the channel by %v`, nUser.Username, oUser.Username))
- <-Srv.Store.Channel().UpdateLastViewedAt(c.T, id, oUser.Id)
+ <-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
w.Write([]byte(cm.ToJson()))
}
}
@@ -870,8 +868,8 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(c.T, channelId)
- cmc := Srv.Store.Channel().GetMember(c.T, channelId, c.Session.UserId)
+ sc := Srv.Store.Channel().Get(channelId)
+ cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -893,7 +891,7 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := RemoveUserFromChannel(c.T, userIdToRemove, c.Session.UserId, channel); err != nil {
+ if err := RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil {
c.Err = model.NewAppError("updateChannel", "Unable to remove user.", err.Message)
return
}
@@ -908,12 +906,12 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
-func RemoveUserFromChannel(T goi18n.TranslateFunc, userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
+func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
if channel.DeleteAt > 0 {
return model.NewAppError("updateChannel", "The channel has been archived or deleted", "")
}
- if cmresult := <-Srv.Store.Channel().RemoveMember(T, channel.Id, userIdToRemove); cmresult.Err != nil {
+ if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); cmresult.Err != nil {
return cmresult.Err
}
@@ -941,7 +939,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
if !c.HasPermissionsToUser(userId, "updateNotifyLevel") {
return
@@ -951,7 +949,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- result := <-Srv.Store.Channel().GetMember(c.T, channelId, userId)
+ result := <-Srv.Store.Channel().GetMember(channelId, userId)
if result.Err != nil {
c.Err = result.Err
return
@@ -968,7 +966,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
member.NotifyProps["desktop"] = desktop
}
- if result := <-Srv.Store.Channel().UpdateMember(c.T, &member); result.Err != nil {
+ if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
c.Err = result.Err
return
} else {