Skip to content

Commit

Permalink
Add organization to chat and message
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 7, 2024
1 parent 438dc20 commit e5723ea
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
11 changes: 6 additions & 5 deletions controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *ApiController) addInitialChat(userId string) (*object.Chat, error) {
return nil, fmt.Errorf("The default store is not found")
}

_, userName := util.GetOwnerAndNameFromId(userId)
organization, userName := util.GetOwnerAndNameFromId(userId)

randomName := util.GetRandomName()
currentTime := util.GetCurrentTime()
Expand All @@ -98,6 +98,7 @@ func (c *ApiController) addInitialChat(userId string) (*object.Chat, error) {
Name: fmt.Sprintf("chat_%s", randomName),
CreatedTime: currentTime,
UpdatedTime: currentTime,
Organization: organization,
DisplayName: fmt.Sprintf("New Chat - %d", 1),
Store: store.GetId(),
Category: "Default Category",
Expand Down Expand Up @@ -143,10 +144,10 @@ func (c *ApiController) addInitialChatAndMessage(user *casdoorsdk.User) error {
}

answerMessage := &object.Message{
Owner: "admin",
Name: fmt.Sprintf("message_%s", util.GetRandomName()),
CreatedTime: util.GetCurrentTimeEx(chat.CreatedTime),
// Organization: message.Organization,
Owner: "admin",
Name: fmt.Sprintf("message_%s", util.GetRandomName()),
CreatedTime: util.GetCurrentTimeEx(chat.CreatedTime),
Organization: chat.Organization,
User: user.Name,
Chat: chat.Name,
ReplyTo: "Welcome",
Expand Down
9 changes: 5 additions & 4 deletions controllers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (c *ApiController) AddMessage() {
return
}

message.Organization = chat.Organization
message.Chat = chat.Name
} else {
chatId := util.GetId(message.Owner, message.Chat)
Expand Down Expand Up @@ -140,10 +141,10 @@ func (c *ApiController) AddMessage() {
if success {
if chat != nil && chat.Type == "AI" {
answerMessage := &object.Message{
Owner: message.Owner,
Name: fmt.Sprintf("message_%s", util.GetRandomName()),
CreatedTime: util.GetCurrentTimeEx(message.CreatedTime),
// Organization: message.Organization,
Owner: message.Owner,
Name: fmt.Sprintf("message_%s", util.GetRandomName()),
CreatedTime: util.GetCurrentTimeEx(message.CreatedTime),
Organization: message.Organization,
User: message.User,
Chat: message.Chat,
ReplyTo: message.GetId(),
Expand Down
2 changes: 1 addition & 1 deletion object/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Chat struct {
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"`

// Organization string `xorm:"varchar(100)" json:"organization"`
Organization string `xorm:"varchar(100)" json:"organization"`
DisplayName string `xorm:"varchar(100)" json:"displayName"`
Store string `xorm:"varchar(100)" json:"store"`
Category string `xorm:"varchar(100)" json:"category"`
Expand Down
1 change: 1 addition & 0 deletions web/src/ChatListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ChatListPage extends React.Component {
name: `chat_${randomName}`,
createdTime: moment().format(),
updatedTime: moment().format(),
organization: this.props.account.owner,
displayName: `${i18next.t("chat:New Chat")} - ${randomName}`,
category: i18next.t("chat:Default Category"),
type: "AI",
Expand Down
2 changes: 1 addition & 1 deletion web/src/MessageListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MessageListPage extends React.Component {
owner: "admin",
name: `message_${randomName}`,
createdTime: moment().format(),
// organization: "Message Organization - 1",
organization: this.props.account.owner,
user: this.props.account.name,
chat: "",
replyTo: "",
Expand Down

0 comments on commit e5723ea

Please sign in to comment.