matrix-js-sdk
matrix-js-sdk copied to clipboard
Fix relations getRelationsForEvent create relation
The problem
Currently, when calling getRelationsForEvent on a timeline set it will return undefined when no relation event exists.
In our app, we have the following logic:
Message component:
const Message = (props) => {
...
useEffect(() => {
const client = RNMWrapper.getClient();
const relation = client
.getRoom(matrixEvent.getRoomId())
?.getLiveTimeline()
.getTimelineSet()
.getRelationsForEvent(matrixEvent.getId(), "m.moment.seen", "m.reaction");
relation?.addListener("Relations.add", (e) => {
// process newly added relation on message
});
}, [matrixEvent]);
When a relation is added for matrixEvent we won't know it, as relation is undefined.
The change
I implemented (and wrote tests) that when getRelationsForEvent a new relation will be created if none exists. I think this behaviour is fine because we can then do relation.getRelations() which will return an empty array, which is more descriptive than just returning undefined.
However, I am not sure whether this change would be breaking?
Happy to discuss this change with you ✌️
Here's what your changelog entry will look like:
🐛 Bug Fixes
- Fix relations getRelationsForEvent create relation (#1717). Contributed by @hannojg.