From 891ff890db4cb0ec00478f135bb3de00a587f3ea Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Tue, 22 Sep 2020 19:43:34 +0800 Subject: [PATCH] Fix the problem that the synchronization session is not consistent with the skype side --- commands.go | 8 ++++---- example-config.yaml | 2 ++ portal.go | 6 +++++- user.go | 16 +++++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index 3fb85a5..6452376 100644 --- a/commands.go +++ b/commands.go @@ -484,7 +484,7 @@ func (handler *CommandHandler) CommandSync(ce *CommandEvent) { ce.Reply("Failed to contacts chat list (see logs for details)") } ce.Reply("Syncing conversations...") - err = ce.User.Conn.GetConversations("") + err = ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync) if err != nil { user.log.Errorln("Error get conversations:", err) ce.Reply("Failed to conversations list (see logs for details)") @@ -625,7 +625,7 @@ func (handler *CommandHandler) CommandList(ce *CommandEvent) { return } } else { - err = ce.User.Conn.GetConversations("") + err = ce.User.Conn.GetConversations("", handler.bridge.Config.Bridge.InitialChatSync) if err != nil { ce.Reply("Get conversations error") return @@ -669,7 +669,7 @@ func (handler *CommandHandler) CommandOpen(ce *CommandEvent) { ce.Reply("That looks like a user ID. Did you mean `pm %s`?", jid[:len(jid)-len(whatsappExt.NewUserSuffix)]) return } - ce.User.Conn.GetConversations("") + ce.User.Conn.GetConversations("", handler.bridge.Config.Bridge.InitialChatSync) fmt.Println("user.Conn.Store.Chats: ", user.Conn.Store.Chats) chat, ok := user.Conn.Store.Chats[jid] if !ok { @@ -923,7 +923,7 @@ func (handler *CommandHandler) CommandInvite(ce *CommandEvent) { fmt.Println("user.Conn.Store.Chats", user.Conn.Store.Contacts) if !ok { //user.Conn - err := ce.User.Conn.GetConversations("") + err := ce.User.Conn.GetConversations("", handler.bridge.Config.Bridge.InitialChatSync) //time.Sleep(5 * time.Second) if err != nil { fmt.Println(err) diff --git a/example-config.yaml b/example-config.yaml index e1281ba..246a70e 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -105,6 +105,8 @@ bridge: end: true # Number of chats to sync for new users. + # Since some of the obtained conversations are not the conversations that the user needs to see, + # the actual number of conversations displayed on the matrix client will be slightly less than the set value initial_chat_sync_count: 10 # Number of old messages to fill when creating new portal rooms. initial_history_fill_count: 20 diff --git a/portal.go b/portal.go index b79503f..68bf24e 100644 --- a/portal.go +++ b/portal.go @@ -620,6 +620,10 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) { } else { fmt.Println("SyncSkype ensureUserInvited", portal.MXID) portal.ensureUserInvited(user) + rep, err := portal.MainIntent().SetPowerLevel(portal.MXID, user.MXID, 100) + if err != nil { + portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep) + } } if portal.IsPrivateChat() { @@ -680,7 +684,7 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) { func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent { anyone := 0 nope := 99 - invite := 99 + invite := 50 if portal.bridge.Config.Bridge.AllowUserInvite { invite = 0 } diff --git a/user.go b/user.go index 5f9774f..23d1e27 100644 --- a/user.go +++ b/user.go @@ -399,7 +399,7 @@ func (user *User) Login(ce *CommandEvent, name string, password string) { user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix user.addToJIDMap() //user.PostLogin() - ce.User.Conn.GetConversations("") + ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync) } func loopPresence(user *User) { Loop: @@ -571,8 +571,18 @@ func (user *User) syncPortals(chatMap map[string]skype.Conversation, createAll b if chat.Properties.ConversationStatus != "Accepted" && len(chat.ThreadProperties.Lastjoinat) < 1 { continue } - // user.log.Warnfln("Non-integer last message time in %s: %s", chat.Id, t) - //continue + } + // Filter calllogs conversation + if chat.Id == "48:calllogs" { + continue + } + // Filter conversations that have not sent messages + if chat.LastMessage.Id == "" { + continue + } + // 'Lastleaveat' value means that you have left the current conversation + if len(chat.ThreadProperties.Lastleaveat) > 0 { + continue } ts := uint64(t.UnixNano()) cid, _ := chat.Id.(string)