dms kind work

This commit is contained in:
Karmanyaah Malhotra
2021-04-30 17:21:13 -04:00
parent e2daccc250
commit 23c5e89c4f
5 changed files with 46 additions and 9 deletions

View File

@ -17,6 +17,9 @@
package database
import (
"strconv"
"strings"
"gorm.io/gorm"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/id"
@ -31,6 +34,25 @@ type PortalKey struct {
Receiver types.GroupMeID `gorm:"primaryKey"`
}
func ParsePortalKey(inp types.GroupMeID) *PortalKey {
parts := strings.Split(inp, "+")
if len(parts) != 2 {
return nil
}
if i, err := strconv.Atoi(parts[0]); i == 0 || err != nil {
return nil
}
if i, err := strconv.Atoi(parts[1]); i == 0 || err != nil {
return nil
}
return &PortalKey{
JID: parts[0],
Receiver: parts[1],
}
}
func GroupPortalKey(jid types.GroupMeID) PortalKey {
return PortalKey{
JID: jid,
@ -49,7 +71,7 @@ func (key PortalKey) String() string {
if key.Receiver == key.JID {
return key.JID
}
return key.JID + "-" + key.Receiver
return key.JID + "+" + key.Receiver
}
func (key PortalKey) IsPrivate() bool {

View File

@ -150,7 +150,10 @@ func (store *SQLStateStore) TryGetMember(roomID id.RoomID, userID id.UserID) (*e
}
func (store *SQLStateStore) TryGetMemberRaw(roomID id.RoomID, userID id.UserID) (user MxUserProfile, err bool) {
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
user.RoomID = roomID.String()
user.UserID = userID.String()
ans := store.db.Limit(1).Find(&user)
if ans.Error == gorm.ErrRecordNotFound {
err = true