(m api.DeviceMessage)
| 96 | } |
| 97 | |
| 98 | func (t *KeyChangeConsumer) onDeviceKeyMessage(m api.DeviceMessage) bool { |
| 99 | if m.DeviceKeys == nil { |
| 100 | return true |
| 101 | } |
| 102 | logger := logrus.WithField("user_id", m.UserID) |
| 103 | |
| 104 | // only send key change events which originated from us |
| 105 | _, originServerName, err := gomatrixserverlib.SplitID('@', m.UserID) |
| 106 | if err != nil { |
| 107 | logger.WithError(err).Error("Failed to extract domain from key change event") |
| 108 | return true |
| 109 | } |
| 110 | if originServerName != t.serverName { |
| 111 | return true |
| 112 | } |
| 113 | |
| 114 | var queryRes roomserverAPI.QueryRoomsForUserResponse |
| 115 | err = t.rsAPI.QueryRoomsForUser(t.ctx, &roomserverAPI.QueryRoomsForUserRequest{ |
| 116 | UserID: m.UserID, |
| 117 | WantMembership: "join", |
| 118 | }, &queryRes) |
| 119 | if err != nil { |
| 120 | logger.WithError(err).Error("failed to calculate joined rooms for user") |
| 121 | return true |
| 122 | } |
| 123 | |
| 124 | // send this key change to all servers who share rooms with this user. |
| 125 | destinations, err := t.db.GetJoinedHostsForRooms(t.ctx, queryRes.RoomIDs, true) |
| 126 | if err != nil { |
| 127 | logger.WithError(err).Error("failed to calculate joined hosts for rooms user is in") |
| 128 | return true |
| 129 | } |
| 130 | |
| 131 | if len(destinations) == 0 { |
| 132 | return true |
| 133 | } |
| 134 | // Pack the EDU and marshal it |
| 135 | edu := &gomatrixserverlib.EDU{ |
| 136 | Type: gomatrixserverlib.MDeviceListUpdate, |
| 137 | Origin: string(t.serverName), |
| 138 | } |
| 139 | event := gomatrixserverlib.DeviceListUpdateEvent{ |
| 140 | UserID: m.UserID, |
| 141 | DeviceID: m.DeviceID, |
| 142 | DeviceDisplayName: m.DisplayName, |
| 143 | StreamID: m.StreamID, |
| 144 | PrevID: prevID(m.StreamID), |
| 145 | Deleted: len(m.KeyJSON) == 0, |
| 146 | Keys: m.KeyJSON, |
| 147 | } |
| 148 | if edu.Content, err = json.Marshal(event); err != nil { |
| 149 | logger.WithError(err).Error("failed to marshal EDU JSON") |
| 150 | return true |
| 151 | } |
| 152 | |
| 153 | logger.Debugf("Sending device list update message to %q", destinations) |
| 154 | err = t.queues.SendEDU(edu, t.serverName, destinations) |
| 155 | return err == nil |
no test coverage detected