diff --git a/api-special.go b/api-special.go new file mode 100644 index 0000000..43e74c7 --- /dev/null +++ b/api-special.go @@ -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 +} + diff --git a/commands.go b/commands.go index 974fb8a..262c40a 100644 --- a/commands.go +++ b/commands.go @@ -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.` diff --git a/user.go b/user.go index f9db40d..bce9f16 100644 --- a/user.go +++ b/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,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") }