add customize contacts api

This commit is contained in:
zhaoYangguang 2022-03-07 19:49:03 +08:00
parent 2d03904646
commit bb9f424d44
3 changed files with 35 additions and 4 deletions

22
api-special.go Normal file
View File

@ -0,0 +1,22 @@
package main
func (puppet *Puppet) SetMatrixContacts(conatcts []string) (err error) {
puppet.log.Debugf("SetMatrixContacts with %+v matrix ids", conatcts)
if (len(conatcts) > 0) {
client := puppet.CustomIntent().Client
if (client != nil) {
urlPath := client.BuildURL("account", "account_contacts")
s := struct {
ContactsType string `json:"contacts_type"`
ContactsIds []string `json:"contacts_ids"`
BridgeId string `json:"bridge_id"`
}{"skype", conatcts, string(puppet.MXID)}
_, err = client.MakeRequest("POST", urlPath, &s, nil)
}
}
return
}

View File

@ -393,7 +393,7 @@ func (handler *CommandHandler) CommandSync(ce *CommandEvent) {
func syncAll(user *User, create bool) {
//ce.Reply("Syncing contacts...")
user.syncPuppets(nil)
user.syncPuppets(nil, false)
//ce.Reply("Syncing chats...")
user.syncPortals(nil, create)
//sync information from non-contacts in the conversation
@ -407,7 +407,8 @@ func syncNonContactInfo(user *User) {
nonContacts[personId] = contact
}
}
user.syncPuppets(nonContacts)
user.syncPuppets(nonContacts, false)
user.syncPuppets(nil, true)
}
const cmdDeletePortalHelp = `delete-portal - Delete the current portal. If the portal is used by other people, this is limited to bridge admins.`

12
user.go
View File

@ -598,7 +598,7 @@ func (user *User) syncPortals(chatMap map[string]skype.Conversation, createAll b
// // go user.syncPuppets(contactMap)
//}
func (user *User) syncPuppets(contacts map[string]skype.Contact) {
func (user *User) syncPuppets(contacts map[string]skype.Contact, toHomeserver bool) {
if contacts == nil {
contacts = user.Conn.Store.Contacts
}
@ -619,13 +619,21 @@ func (user *User) syncPuppets(contacts map[string]skype.Contact) {
DisplayName: username,
PersonId: user.Conn.UserProfile.Username,
}
matrixContacts := []string{}
for personId, contact := range contacts {
user.log.Infoln("Syncing puppet info from contacts", personId, skypeExt.NewUserSuffix)
if strings.HasSuffix(personId, skypeExt.NewUserSuffix) {
puppet := user.bridge.GetPuppetByJID(personId)
puppet.Sync(user, contact)
if (!toHomeserver) {
puppet.Sync(user, contact)
}
matrixContacts = append(matrixContacts, string(puppet.MXID))
}
}
customPuppet := user.bridge.GetPuppetByCustomMXID(user.MXID)
if customPuppet != nil && customPuppet.CustomIntent() != nil {
customPuppet.SetMatrixContacts(matrixContacts)
}
user.log.Infoln("Finished syncing puppet info from contacts")
}