progress
This commit is contained in:
parent
0ff534c2df
commit
e2daccc250
@ -867,10 +867,10 @@ func (handler *CommandHandler) CommandOpen(ce *CommandEvent) {
|
||||
handler.log.Debugln("Importing", jid, "for", user.MXID)
|
||||
portal := user.bridge.GetPortalByJID(database.GroupPortalKey(jid))
|
||||
if len(portal.MXID) > 0 {
|
||||
portal.Sync(user, contact)
|
||||
portal.Sync(user, &contact)
|
||||
ce.Reply("Portal room synced.")
|
||||
} else {
|
||||
portal.Sync(user, contact)
|
||||
portal.Sync(user, &contact)
|
||||
ce.Reply("Portal room created.")
|
||||
}
|
||||
_, _ = portal.MainIntent().InviteUser(portal.MXID, &mautrix.ReqInviteUser{UserID: user.MXID})
|
||||
|
@ -135,7 +135,7 @@ func (store *SQLStateStore) GetMember(roomID id.RoomID, userID id.UserID) *event
|
||||
|
||||
func (store *SQLStateStore) TryGetMember(roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, bool) {
|
||||
var user MxUserProfile
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Take(&user)
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
||||
|
||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
||||
@ -150,13 +150,12 @@ 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).Take(&user)
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
||||
|
||||
if ans.Error == gorm.ErrRecordNotFound {
|
||||
err = true
|
||||
return
|
||||
}
|
||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
||||
} else if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
||||
err = true
|
||||
return
|
||||
|
@ -25,6 +25,10 @@ func (c Client) IndexAllGroups() ([]*groupme.Group, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c Client) IndexAllRelations() ([]*groupme.User, error) {
|
||||
return c.IndexRelations(context.TODO(), &groupme.IndexChatsQuery{})
|
||||
}
|
||||
|
||||
func (c Client) IndexAllChats() ([]*groupme.Chat, error) {
|
||||
return c.IndexChats(context.TODO(), &groupme.IndexChatsQuery{
|
||||
PerPage: 100, //TODO?
|
||||
|
25
portal.go
25
portal.go
@ -540,7 +540,7 @@ func (portal *Portal) ensureUserInvited(user *User) {
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) Sync(user *User, group groupme.Group) {
|
||||
func (portal *Portal) Sync(user *User, group *groupme.Group) {
|
||||
portal.log.Infoln("Syncing portal for", user.MXID)
|
||||
|
||||
if user.IsRelaybot {
|
||||
@ -548,12 +548,11 @@ func (portal *Portal) Sync(user *User, group groupme.Group) {
|
||||
portal.hasRelaybot = &yes
|
||||
}
|
||||
|
||||
var err error
|
||||
sub := user.Conn.SubscribeToGroup
|
||||
if portal.IsPrivateChat() {
|
||||
err = user.Conn.SubscribeToUser(context.TODO(), groupme.ID(portal.Key.JID), user.Token)
|
||||
} else {
|
||||
err = user.Conn.SubscribeToGroup(context.TODO(), groupme.ID(portal.Key.JID), user.Token)
|
||||
sub = user.Conn.SubscribeToDM
|
||||
}
|
||||
err := sub(context.TODO(), groupme.ID(portal.Key.Receiver), user.Token)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Subscribing failed, live metadata updates won't work", err)
|
||||
}
|
||||
@ -944,15 +943,21 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||
var metadata *groupme.Group
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := portal.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
m, _ := portal.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
||||
meta, err := portal.bridge.StateStore.TryGetMemberRaw("", puppet.MXID)
|
||||
if err {
|
||||
println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
||||
return errors.New("Cannot find user information")
|
||||
}
|
||||
|
||||
//m, _ := portal.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||
portal.Name = m.DisplayName
|
||||
portal.AvatarURL = types.ContentURI{id.MustParseContentURI(m.AvatarURL)}
|
||||
portal.Avatar = m.Avatar
|
||||
portal.Name = meta.DisplayName
|
||||
portal.AvatarURL = types.ContentURI{id.MustParseContentURI(meta.AvatarURL)}
|
||||
portal.Avatar = meta.Avatar
|
||||
} else {
|
||||
portal.Name = ""
|
||||
}
|
||||
portal.Topic = "WhatsApp private chat"
|
||||
portal.Topic = "GroupMe private chat"
|
||||
// } else if portal.IsStatusBroadcastRoom() {
|
||||
// portal.Name = "WhatsApp Status Broadcast"
|
||||
// portal.Topic = "WhatsApp status updates from your contacts"
|
||||
|
@ -248,8 +248,8 @@ func (puppet *Puppet) UpdateName(source *User, portalMXID id.RoomID, contact gro
|
||||
if err == nil {
|
||||
memberRaw.DisplayName = newName
|
||||
// puppet.NameQuality[portalMXID] = quality
|
||||
puppet.bridge.StateStore.SetMemberRaw(&memberRaw) //TODO handle; maybe .Update() ?
|
||||
go puppet.updatePortalName()
|
||||
puppet.Update()
|
||||
} else {
|
||||
puppet.log.Warnln("Failed to set display name:", err)
|
||||
}
|
||||
|
24
user.go
24
user.go
@ -58,8 +58,9 @@ type User struct {
|
||||
ConnectionErrors int
|
||||
CommunityID string
|
||||
|
||||
ChatList map[types.GroupMeID]groupme.Chat
|
||||
GroupList map[types.GroupMeID]groupme.Group
|
||||
ChatList map[types.GroupMeID]groupme.Chat
|
||||
GroupList map[types.GroupMeID]groupme.Group
|
||||
RelationList map[types.GroupMeID]groupme.User
|
||||
|
||||
cleanDisconnection bool
|
||||
batteryWarningsSent int
|
||||
@ -561,6 +562,23 @@ func (user *User) HandleChatList() {
|
||||
}
|
||||
user.ChatList = dmMap
|
||||
|
||||
userMap := make(map[string]groupme.User)
|
||||
users, err := user.Client.IndexAllRelations()
|
||||
if err != nil {
|
||||
user.log.Errorln("Error syncing user list, continuing sync", err)
|
||||
}
|
||||
for _, u := range users {
|
||||
puppet := user.bridge.GetPuppetByJID(u.ID.String())
|
||||
// "" for overall user not related to one group
|
||||
puppet.Sync(nil, "", groupme.Member{
|
||||
UserID: u.ID,
|
||||
Nickname: u.Name,
|
||||
ImageURL: u.AvatarURL,
|
||||
})
|
||||
userMap[u.ID.String()] = *u
|
||||
}
|
||||
user.RelationList = userMap
|
||||
|
||||
user.log.Infoln("Chat list received")
|
||||
user.chatListReceived <- struct{}{}
|
||||
go user.syncPortals(false)
|
||||
@ -627,7 +645,7 @@ func (user *User) syncPortals(createAll bool) {
|
||||
go func(chat Chat) {
|
||||
create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
|
||||
if len(chat.Portal.MXID) > 0 || create || createAll {
|
||||
chat.Portal.Sync(user, *chat.Group)
|
||||
chat.Portal.Sync(user, chat.Group)
|
||||
err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
|
||||
if err != nil {
|
||||
chat.Portal.log.Errorln("Error backfilling history:", err)
|
||||
|
Loading…
Reference in New Issue
Block a user