@@ -72,15 +72,15 @@ export default class DMRoomMap {
72
72
73
73
_onAccountData ( ev ) {
74
74
if ( ev . getType ( ) == 'm.direct' ) {
75
- let userToRooms = this . matrixClient . getAccountData ( 'm.direct' ) . getContent ( ) ;
75
+ const userToRooms = this . matrixClient . getAccountData ( 'm.direct' ) . getContent ( ) || { } ;
76
76
const myUserId = this . matrixClient . getUserId ( ) ;
77
77
const selfDMs = userToRooms [ myUserId ] ;
78
78
if ( selfDMs && selfDMs . length ) {
79
- this . _patchUpSelfDMs ( userToRooms ) ;
79
+ const neededPatching = this . _patchUpSelfDMs ( userToRooms ) ;
80
80
// to avoid multiple devices fighting to correct
81
81
// the account data, only try to send the corrected
82
82
// version once.
83
- if ( ! this . _hasSentOutPatchDirectAccountDataPatch ) {
83
+ if ( neededPatching && ! this . _hasSentOutPatchDirectAccountDataPatch ) {
84
84
this . _hasSentOutPatchDirectAccountDataPatch = true ;
85
85
this . matrixClient . setAccountData ( 'm.direct' , userToRooms ) ;
86
86
}
@@ -98,25 +98,40 @@ export default class DMRoomMap {
98
98
const myUserId = this . matrixClient . getUserId ( ) ;
99
99
const selfRoomIds = userToRooms [ myUserId ] ;
100
100
if ( selfRoomIds ) {
101
- const guessedUserIds = selfRoomIds . map ( ( roomId ) => {
101
+ // any self-chats that should not be self-chats?
102
+ const guessedUserIdsThatChanged = selfRoomIds . map ( ( roomId ) => {
102
103
const room = this . matrixClient . getRoom ( roomId ) ;
103
- return room && room . guessDMUserId ( ) ;
104
+ if ( room ) {
105
+ const userId = room . guessDMUserId ( ) ;
106
+ if ( userId && userId !== myUserId ) {
107
+ return { userId, roomId} ;
108
+ }
109
+ }
110
+ } ) . filter ( ( ids ) => ! ! ids ) ; //filter out
111
+ // these are actually all legit self-chats
112
+ // bail out
113
+ if ( ! guessedUserIdsThatChanged . length ) {
114
+ return false ;
115
+ }
116
+ userToRooms [ myUserId ] = selfRoomIds . filter ( ( roomId ) => {
117
+ return guessedUserIdsThatChanged
118
+ . some ( ( ids ) => ids . roomId === roomId ) ;
104
119
} ) ;
105
- delete userToRooms [ myUserId ] ;
106
- guessedUserIds . forEach ( ( userId , i ) => {
120
+
121
+ guessedUserIdsThatChanged . forEach ( ( { userId, roomId } ) => {
107
122
if ( ! userId ) {
108
123
// if not able to guess the other user (unlikely)
109
124
// still put it in the map so the room stays marked
110
125
// as a DM, we just wont be able to show an avatar.
111
126
userId = "" ;
112
127
}
113
- const roomId = selfRoomIds [ i ] ;
114
128
let roomIds = userToRooms [ userId ] ;
115
129
if ( ! roomIds ) {
116
130
roomIds = userToRooms [ userId ] = [ ] ;
117
131
}
118
132
roomIds . push ( roomId ) ;
119
133
} ) ;
134
+ return true ;
120
135
}
121
136
}
122
137
0 commit comments