Skip to content

Commit

Permalink
Remove org from user and author for chat and message
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 9, 2024
1 parent 3bd3945 commit fd553c6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
15 changes: 8 additions & 7 deletions controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *ApiController) Signout() {
c.ResponseOk()
}

func (c *ApiController) addInitialChat(userId string) (*object.Chat, error) {
func (c *ApiController) addInitialChat(organization string, userName string) (*object.Chat, error) {
store, err := object.GetDefaultStore("admin")
if err != nil {
return nil, err
Expand All @@ -89,8 +89,6 @@ func (c *ApiController) addInitialChat(userId string) (*object.Chat, error) {
return nil, fmt.Errorf("The default store is not found")
}

organization, userName := util.GetOwnerAndNameFromId(userId)

randomName := util.GetRandomName()
currentTime := util.GetCurrentTime()
chat := &object.Chat{
Expand All @@ -104,9 +102,9 @@ func (c *ApiController) addInitialChat(userId string) (*object.Chat, error) {
Category: "Default Category",
Type: "AI",
User: userName,
User1: userId,
User1: "",
User2: "",
Users: []string{userId},
Users: []string{userName},
ClientIp: c.getClientIp(),
UserAgent: c.getUserAgent(),
MessageCount: 0,
Expand Down Expand Up @@ -138,7 +136,10 @@ func (c *ApiController) addInitialChatAndMessage(user *casdoorsdk.User) error {
return nil
}

chat, err := c.addInitialChat(user.GetId())
organizationName := user.Owner
userName := user.Name

chat, err := c.addInitialChat(organizationName, userName)
if err != nil {
return err
}
Expand All @@ -148,7 +149,7 @@ func (c *ApiController) addInitialChatAndMessage(user *casdoorsdk.User) error {
Name: fmt.Sprintf("message_%s", util.GetRandomName()),
CreatedTime: util.GetCurrentTimeEx(chat.CreatedTime),
Organization: chat.Organization,
User: user.Name,
User: userName,
Chat: chat.Name,
ReplyTo: "Welcome",
Author: "AI",
Expand Down
2 changes: 1 addition & 1 deletion controllers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c *ApiController) AddMessage() {

var chat *object.Chat
if message.Chat == "" {
chat, err = c.addInitialChat(message.Author)
chat, err = c.addInitialChat(message.Organization, message.User)
if err != nil {
c.ResponseError(err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions web/src/ChatListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class ChatListPage extends React.Component {
category: i18next.t("chat:Default Category"),
type: "AI",
user: this.props.account.name,
user1: `${this.props.account.owner}/${this.props.account.name}`,
user1: "",
user2: "",
users: [`${this.props.account.owner}/${this.props.account.name}`],
users: [this.props.account.name],
messageCount: 0,
};
}
Expand Down
8 changes: 4 additions & 4 deletions web/src/ChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class ChatPage extends BaseListPage {
name: `chat_${randomName}`,
createdTime: moment().format(),
updatedTime: moment().format(),
// organization: this.props.account.owner,
organization: this.props.account.owner,
displayName: `${i18next.t("chat:New Chat")} - ${this.getNextChatIndex(chat?.displayName) ?? randomName}`,
type: "AI",
user: this.props.account.name,
category: chat !== undefined ? chat.category : i18next.t("chat:Default Category"),
user1: `${this.props.account.owner}/${this.props.account.name}`,
user1: "",
user2: "",
users: [`${this.props.account.owner}/${this.props.account.name}`],
users: [this.props.account.name],
clientIp: this.props.account.createdIp,
userAgent: this.props.account.education,
messageCount: 0,
Expand All @@ -104,7 +104,7 @@ class ChatPage extends BaseListPage {
user: this.props.account.name,
chat: this.state.chat?.name,
replyTo: "",
author: `${this.props.account.owner}/${this.props.account.name}`,
author: this.props.account.name,
text: text,
isHidden: isHidden,
fileName: fileName,
Expand Down
9 changes: 7 additions & 2 deletions web/src/MessageListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MessageListPage extends React.Component {
user: this.props.account.name,
chat: "",
replyTo: "",
author: `${this.props.account.owner}/${this.props.account.name}`,
author: this.props.account.name,
text: "",
};
}
Expand Down Expand Up @@ -188,8 +188,13 @@ class MessageListPage extends React.Component {
return text;
}

let userId = text;
if (!userId.includes("/")) {
userId = `${record.organization}/${userId}`;
}

return (
<a target="_blank" rel="noreferrer" href={Setting.getMyProfileUrl(this.props.account).replace("/account", `/users/${text}`)}>
<a target="_blank" rel="noreferrer" href={Setting.getMyProfileUrl(this.props.account).replace("/account", `/users/${userId}`)}>
{text}
</a>
);
Expand Down

0 comments on commit fd553c6

Please sign in to comment.