Compare commits

..

No commits in common. "093fef024563cf0cba0fa52ddcd981841b7a841f" and "1f85577fed0543656c601aad34cc813c77cbd6b4" have entirely different histories.

3 changed files with 2 additions and 43 deletions

View File

@ -176,21 +176,3 @@ func FindFriend(from_user_id, to_user_id int) []Friend {
DB.Debug().Where("user_id = ? and friend_id = ?", from_user_id, to_user_id).Find(&friends)
return friends
}
type FriendRet struct {
ID int `json:"id"` //用户id
Username string `json:"username"` //用户名
Avatar string `json:"avatar"` //头像
}
func FindFriends(user_id int) []FriendRet {
var friends []FriendRet
DB.Debug().Raw("select users.id, users.username, users.avatar from users join friends on users.id = friends.friend_id where friends.user_id = ?", user_id).Scan(&friends)
return friends
}
func FindGroups(user_id int) []Group {
var groups []Group
DB.Debug().Raw("select groups.* from groups join group_users on groups.id = group_users.group_id where group_users.user_id = ?", user_id).Scan(&groups)
return groups
}

View File

@ -66,7 +66,6 @@ func SetUpIMGroup(router *gin.Engine) {
imGroup.POST("/accept_invite", AcceptInvite)
imGroup.POST("/create_group", CreateGroup)
imGroup.GET("/sse_msg", ServerSendMsg)
imGroup.POST("/get_friend_list", GetFriendList) //获取好友列表,包括群聊
}
func generateRandomHexString(length int) (string, error) {
bytes := make([]byte, length/2) // 16字节的字符串需要32个十六进制字符即16个字节
@ -75,13 +74,6 @@ func generateRandomHexString(length int) (string, error) {
}
return hex.EncodeToString(bytes), nil
}
func GetFriendList(c *gin.Context) {
id, _ := c.Get("id")
user_id := int(id.(float64))
data := service.GetFriendList(user_id)
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": data, "message": "success"})
}
func GetMessage(c *gin.Context) {
var req Message
user_id, _ := c.Get("id")

View File

@ -34,8 +34,8 @@ func CreateGeneralMessageService(from_id, to_id, msg_type int, content string) (
case 4:
res, _ := dao.GetMsgUserByIndex(from_id, to_id, 4, 1, 0)
if len(res) > 0 {
// 已经有会话记录,返回会话id
return nil, res[0].ID
// 已经有会话记录
return errors.New("already have a conversation"), 0
}
err, id = dao.CreateGeneralMessage(from_id, to_id, msg_type, 0, 0, content)
case 5:
@ -108,18 +108,3 @@ func CreateGroup(groupName, groupInfo, groupType, groupIcon string, user_id int)
err, id := dao.CreateGroup(groupName, groupInfo, groupType, groupIcon, user_id)
return err, id
}
type FGRet struct {
Friends []dao.FriendRet `json:"friends"`
Groups []dao.Group `json:"groups"`
}
func GetFriendList(user_id int) FGRet {
//获取好友id和群id
friends := dao.FindFriends(user_id)
groups := dao.FindGroups(user_id)
var fg FGRet
fg.Friends = friends
fg.Groups = groups
return fg
}