Documentation ¶
Index ¶
- Constants
- func ChangeGroupOwner(db *gorm.DB, execID int64, chatID int64, userID int64) error
- func CheckIfInChat(db *gorm.DB, chatID int64, userID int64) bool
- func CheckIfUserInChats(db *gorm.DB, userID int64, chatIDs []int64) bool
- func CheckIsWithdrawn(db *gorm.DB, chatID int64, messageID int64) bool
- func DeleteChat(db *gorm.DB, execID int64, chatID int64) error
- func DeleteChatMember(db *gorm.DB, execID int64, chatID int64, userID int64) error
- func GetAllChatsLatestMessageID(db *gorm.DB, userID int64) ([]struct{ ... }, error)
- func ModifyChatMemberAlias(db *gorm.DB, chatID int64, userID int64, alias string) error
- func ModifyChatMemberPermission(db *gorm.DB, execID int64, chatID int64, userID int64, ...) error
- type Chat
- func CreateGroupChat(db *gorm.DB, name string, ownerID int64, members mapset.Set) (*Chat, error)
- func CreatePrivateChat(db *gorm.DB, user1 int64, user2 int64) (*Chat, error)
- func GetAllChats(db *gorm.DB, userID int64) ([]Chat, error)
- func GetChat(db *gorm.DB, chatID int64) (*Chat, error)
- func GetPrivateChat(db *gorm.DB, user1 int64, user2 int64) (*Chat, error)
- type ChatType
- type ChatUser
- type MemberPermission
- type Message
- func CreateMessage(db *gorm.DB, chatID int64, senderID int64, typ MsgType, message string) (*Message, error)
- func GetLatestMessages(db *gorm.DB, userID int64, chatIDs []int64) ([]Message, error)
- func GetMessage(db *gorm.DB, chatID int64, userID int64, messageID int64) (*Message, error)
- func GetMessages(db *gorm.DB, chatID int64, userID int64, fromID int64, toID int64) ([]Message, error)
- func WithdrawMessage(db *gorm.DB, chatID int64, userID int64, messageID int64) (*Message, error)
- type MsgType
Constants ¶
View Source
const ( // ChatTypePrivate 私聊 ChatTypePrivate = iota // ChatTypeGroup 群聊 ChatTypeGroup )
View Source
const ( // PermNormal 狗群员 PermNormal = iota // PermAdmin 狗管理 PermAdmin // PermOwner 狗群主 PermOwner )
View Source
const ( // MsgTypeText 纯文本消息种类 MsgTypeText = 0 // MsgTypeImage 图片消息 MsgTypeImage = 1 // MsgTypeAudio 音频消息 MsgTypeAudio = 2 // MsgTypeVideo 视频消息 MsgTypeVideo = 3 // MsgTypeGeo 位置消息 MsgTypeGeo = 4 // MsgTypeWithdraw 撤回消息 MsgTypeWithdraw = 100 )
Variables ¶
This section is empty.
Functions ¶
func ChangeGroupOwner ¶
ChangeGroupOwner 禅让群主
func CheckIfInChat ¶
CheckIfInChat 判断用户是否在属于某个聊天
func CheckIsWithdrawn ¶
CheckIsWithdrawn 判断消息是否被撤回
func DeleteChat ¶
DeleteChat 删除聊天,execID 表示删除的发起人,会检查权限
func DeleteChatMember ¶
DeleteChatMember 通过用户 UserID 和聊天 UserID 删除成员,execID 为执行者的 UserID,会查询权限。可以删除自身.
func GetAllChatsLatestMessageID ¶
func GetAllChatsLatestMessageID(db *gorm.DB, userID int64) ([]struct { ChatID int64 `json:"chat_id"` MaxMessageID int64 `json:"max_message_id"` }, error)
GetAllChatsLatestMessageID 获得某个用户所有的聊天的最新消息 id
func ModifyChatMemberAlias ¶
ModifyChatMemberAlias 修改成员名片
func ModifyChatMemberPermission ¶
func ModifyChatMemberPermission(db *gorm.DB, execID int64, chatID int64, userID int64, newPerm MemberPermission) error
ModifyChatMemberPermission 修改成员权限
Types ¶
type Chat ¶
type Chat struct { ID int64 `gorm:"primarykey" json:"id"` Type ChatType `gorm:"type:smallint not null;check:type >= 0 and type <= 1" json:"type"` Name string `gorm:"type:varChar(127) not null" json:"name"` Avatar string `gorm:"type:varChar(255) not null" json:"avatar"` Members []user.User `gorm:"many2many:chat_users;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"` Messages []Message `gorm:"foreignKey:ChatID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt soft_delete.DeletedAt `gorm:"index" json:"deleted_at"` }
Chat 聊天列表项的 dao
func CreateGroupChat ¶
CreateGroupChat 创建群聊,members 为成员 UserID 的集合,允许为空
func CreatePrivateChat ¶
CreatePrivateChat 创建私人聊天,若已经存在私聊,则返回此私聊
func GetAllChats ¶
GetAllChats 获得一个人加入的所有聊天
func GetPrivateChat ¶
GetPrivateChat 获得私聊
type ChatUser ¶
type ChatUser struct { ID int64 `gorm:"primaryKey" json:"-"` ChatID int64 `gorm:"uniqueIndex:idx_chat_user_delete" json:"chat_id"` UserID int64 `gorm:"uniqueIndex:idx_chat_user_delete" json:"user_id"` // Alias 群内备注 Alias string `gorm:"type:varChar(127) not null" json:"alias"` // 群内权限 Permission MemberPermission `gorm:"type:smallint not null;check:permission >= 0;default:0;" json:"permission"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"-"` DeletedAt soft_delete.DeletedAt `gorm:"uniqueIndex:idx_chat_user_delete" json:"deleted_at"` }
func AddChatMember ¶
AddChatMember 通过用户 UserID 和聊天 UserID 加入新成员
func GetChatMember ¶
GetChatMember 获得某个群成员表项
type MemberPermission ¶
type MemberPermission int64
type Message ¶
type Message struct { ID int64 `gorm:"primaryKey" json:"-"` // ChatID 消息所属的聊天 ChatID int64 `gorm:"uniqueIndex:idx_chat_message_delete" json:"chat_id"` // MessageID 单个聊天中,MessageID 从 0 开始计数且独立 MessageID int64 `gorm:"uniqueIndex:idx_chat_message_delete" json:"message_id"` Type MsgType `gorm:"type:smallint not null;check:type >= 0" json:"type"` Message string `gorm:"text not null" json:"message"` // SenderID 消息所属的用户,外键 SenderID int64 `gorm:"type:bigint not null" json:"sender_id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt soft_delete.DeletedAt `gorm:"uniqueIndex:idx_chat_message_delete" json:"-"` }
func CreateMessage ¶
func CreateMessage(db *gorm.DB, chatID int64, senderID int64, typ MsgType, message string) (*Message, error)
CreateMessage 创建一条新的信息,每个 chat 中都有自己独立的一套从 1 开始的 message_id
func GetLatestMessages ¶
GetLatestMessages 获得某个用户给定某些聊天的最新消息
func GetMessage ¶
GetMessage 使用 userID 的身份,获取从 chat 中某条消息.
Click to show internal directories.
Click to hide internal directories.