add customize contacts api
This commit is contained in:
parent
2d03904646
commit
bb9f424d44
|
@ -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
|
||||
}
|
||||
|
|
@ -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.`
|
||||
|
|
10
user.go
10
user.go
|
@ -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,12 +619,20 @@ 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)
|
||||
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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue