Kinda work dms
This commit is contained in:
@ -57,7 +57,7 @@ func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
||||
}
|
||||
|
||||
gdb, err := gorm.Open(conn, &gorm.Config{
|
||||
//Logger: logger.Default.LogMode(logger.Info),
|
||||
// Logger: logger.Default.LogMode(logger.Info),
|
||||
// Logger: baseLog,
|
||||
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
|
@ -24,6 +24,8 @@ import (
|
||||
"github.com/karmanyaahm/matrix-groupme-go/types"
|
||||
)
|
||||
|
||||
// JID is the puppet or the group
|
||||
// Receiver is the "Other Person" in a DM or the group itself in a group
|
||||
type PortalKey struct {
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
Receiver types.GroupMeID `gorm:"primaryKey"`
|
||||
@ -50,6 +52,11 @@ func (key PortalKey) String() string {
|
||||
return key.JID + "-" + key.Receiver
|
||||
}
|
||||
|
||||
func (key PortalKey) IsPrivate() bool {
|
||||
//also see FindPrivateChats
|
||||
return key.JID != key.Receiver
|
||||
}
|
||||
|
||||
type PortalQuery struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
@ -82,8 +89,8 @@ func (pq *PortalQuery) GetAllByJID(jid types.GroupMeID) []*Portal {
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) FindPrivateChats(receiver types.GroupMeID) []*Portal {
|
||||
print("aaaaaaaaaaaaaaaaaa wrong portal stuff")
|
||||
return pq.getAll(pq.db.DB.Where("receiver = ? AND jid LIKE '%@s.whatsapp.net'", receiver))
|
||||
//also see IsPrivate
|
||||
return pq.getAll(pq.db.DB.Where("receiver = ? AND receiver <> jid", receiver))
|
||||
|
||||
}
|
||||
|
||||
|
@ -178,8 +178,8 @@ type UserPortal struct {
|
||||
|
||||
func (user *User) SetPortalKeys(newKeys []PortalKeyWithMeta) error {
|
||||
tx := user.db.Begin()
|
||||
ans := tx.Where("user_jid = ?", *user.jidPtr()).Delete(&UserPortal{})
|
||||
print("make sure all are deletede")
|
||||
ans := tx.Where("user_jid = ?", *user.jidPtr()).Delete(UserPortal{})
|
||||
|
||||
if ans.Error != nil {
|
||||
_ = tx.Rollback()
|
||||
return ans.Error
|
||||
|
Reference in New Issue
Block a user