| @@ -201,7 +201,17 @@ fn room_cmp<T: RoomLikeItem>( |
| 201 | 201 | }, |
| 202 | 202 | SortFieldRoom::Invite => { |
| 203 | 203 | // sort invites before other rooms. |
| 204 | | b.is_invite().cmp(&a.is_invite()) |
| 204 | let a = a.membership() == MatrixRoomState::Invited; |
| 205 | let b = b.membership() == MatrixRoomState::Invited; |
| 206 | |
| 207 | b.cmp(&a) |
| 208 | }, |
| 209 | SortFieldRoom::Joined => { |
| 210 | // sort joined rooms before other rooms. |
| 211 | let a = a.membership() == MatrixRoomState::Joined; |
| 212 | let b = b.membership() == MatrixRoomState::Joined; |
| 213 | |
| 214 | b.cmp(&a) |
| 205 | 215 | }, |
| 206 | 216 | } |
| 207 | 217 | } |
| @@ -282,7 +292,7 @@ trait RoomLikeItem { |
| 282 | 292 | fn recent_ts(&self) -> Option<&MessageTimeStamp>; |
| 283 | 293 | fn alias(&self) -> Option<&RoomAliasId>; |
| 284 | 294 | fn name(&self) -> &str; |
| 285 | | fn is_invite(&self) -> bool; |
| 295 | fn membership(&self) -> MatrixRoomState; |
| 286 | 296 | fn has_mention(&self) -> bool; |
| 287 | 297 | } |
| 288 | 298 | |
| @@ -714,7 +724,7 @@ impl WindowOps<IambInfo> for IambWindow { |
| 714 | 724 | .iter() |
| 715 | 725 | .chain(sync_info.dms.iter()) |
| 716 | 726 | .map(|room| GenericRoomItem::new(room, rooms, aliases)) |
| 717 | | .filter(RoomLikeItem::is_invite) |
| 727 | .filter(|item| item.membership() == MatrixRoomState::Invited) |
| 718 | 728 | .collect::<Vec<_>>(); |
| 719 | 729 | |
| 720 | 730 | let fields = &settings.tunables.sort.chats; |
| @@ -1197,8 +1207,8 @@ impl RoomLikeItem for GenericRoomItem { |
| 1197 | 1207 | &self.name |
| 1198 | 1208 | } |
| 1199 | 1209 | |
| 1200 | | fn is_invite(&self) -> bool { |
| 1201 | | self.membership == MatrixRoomState::Invited |
| 1210 | fn membership(&self) -> MatrixRoomState { |
| 1211 | self.membership |
| 1202 | 1212 | } |
| 1203 | 1213 | |
| 1204 | 1214 | fn has_mention(&self) -> bool { |
| @@ -1525,7 +1535,7 @@ mod tests { |
| 1525 | 1535 | alias: Option<OwnedRoomAliasId>, |
| 1526 | 1536 | name: &'static str, |
| 1527 | 1537 | unread: UnreadInfo, |
| 1528 | | invite: bool, |
| 1538 | membership: MatrixRoomState, |
| 1529 | 1539 | } |
| 1530 | 1540 | |
| 1531 | 1541 | impl RoomLikeItem for &TestRoomItem { |
| @@ -1553,8 +1563,8 @@ mod tests { |
| 1553 | 1563 | self.unread.is_unread() |
| 1554 | 1564 | } |
| 1555 | 1565 | |
| 1556 | | fn is_invite(&self) -> bool { |
| 1557 | | self.invite |
| 1566 | fn membership(&self) -> MatrixRoomState { |
| 1567 | self.membership |
| 1558 | 1568 | } |
| 1559 | 1569 | |
| 1560 | 1570 | fn has_mention(&self) -> bool { |
| @@ -1592,7 +1602,7 @@ mod tests { |
| 1592 | 1602 | alias: Some(room_alias_id!("#room1:example.com").to_owned()), |
| 1593 | 1603 | name: "Z", |
| 1594 | 1604 | unread: UnreadInfo::default(), |
| 1595 | | invite: false, |
| 1605 | membership: MatrixRoomState::Joined, |
| 1596 | 1606 | }; |
| 1597 | 1607 | |
| 1598 | 1608 | let room2 = TestRoomItem { |
| @@ -1601,7 +1611,7 @@ mod tests { |
| 1601 | 1611 | alias: Some(room_alias_id!("#a:example.com").to_owned()), |
| 1602 | 1612 | name: "Unnamed Room", |
| 1603 | 1613 | unread: UnreadInfo::default(), |
| 1604 | | invite: false, |
| 1614 | membership: MatrixRoomState::Joined, |
| 1605 | 1615 | }; |
| 1606 | 1616 | |
| 1607 | 1617 | let room3 = TestRoomItem { |
| @@ -1610,7 +1620,7 @@ mod tests { |
| 1610 | 1620 | alias: None, |
| 1611 | 1621 | name: "Cool Room", |
| 1612 | 1622 | unread: UnreadInfo::default(), |
| 1613 | | invite: false, |
| 1623 | membership: MatrixRoomState::Joined, |
| 1614 | 1624 | }; |
| 1615 | 1625 | |
| 1616 | 1626 | // Sort by Name ascending. |
| @@ -1664,7 +1674,7 @@ mod tests { |
| 1664 | 1674 | unread_notifications: 0, |
| 1665 | 1675 | unread_mentions: 0, |
| 1666 | 1676 | }, |
| 1667 | | invite: false, |
| 1677 | membership: MatrixRoomState::Joined, |
| 1668 | 1678 | }; |
| 1669 | 1679 | |
| 1670 | 1680 | let room2 = TestRoomItem { |
| @@ -1679,7 +1689,7 @@ mod tests { |
| 1679 | 1689 | unread_notifications: 0, |
| 1680 | 1690 | unread_mentions: 0, |
| 1681 | 1691 | }, |
| 1682 | | invite: false, |
| 1692 | membership: MatrixRoomState::Joined, |
| 1683 | 1693 | }; |
| 1684 | 1694 | |
| 1685 | 1695 | let room3 = TestRoomItem { |
| @@ -1694,7 +1704,7 @@ mod tests { |
| 1694 | 1704 | unread_notifications: 0, |
| 1695 | 1705 | unread_mentions: 0, |
| 1696 | 1706 | }, |
| 1697 | | invite: false, |
| 1707 | membership: MatrixRoomState::Joined, |
| 1698 | 1708 | }; |
| 1699 | 1709 | |
| 1700 | 1710 | // Sort by Recent ascending. |
| @@ -1722,7 +1732,7 @@ mod tests { |
| 1722 | 1732 | alias: None, |
| 1723 | 1733 | name: "Old room 1", |
| 1724 | 1734 | unread: UnreadInfo::default(), |
| 1725 | | invite: false, |
| 1735 | membership: MatrixRoomState::Joined, |
| 1726 | 1736 | }; |
| 1727 | 1737 | |
| 1728 | 1738 | let room2 = TestRoomItem { |
| @@ -1731,7 +1741,7 @@ mod tests { |
| 1731 | 1741 | alias: None, |
| 1732 | 1742 | name: "Old room 2", |
| 1733 | 1743 | unread: UnreadInfo::default(), |
| 1734 | | invite: false, |
| 1744 | membership: MatrixRoomState::Joined, |
| 1735 | 1745 | }; |
| 1736 | 1746 | |
| 1737 | 1747 | let room3 = TestRoomItem { |
| @@ -1740,7 +1750,7 @@ mod tests { |
| 1740 | 1750 | alias: None, |
| 1741 | 1751 | name: "New Fancy Room", |
| 1742 | 1752 | unread: UnreadInfo::default(), |
| 1743 | | invite: true, |
| 1753 | membership: MatrixRoomState::Invited, |
| 1744 | 1754 | }; |
| 1745 | 1755 | |
| 1746 | 1756 | // Sort invites first |
| @@ -1776,7 +1786,7 @@ mod tests { |
| 1776 | 1786 | alias: None, |
| 1777 | 1787 | name: "Room E", |
| 1778 | 1788 | unread: UnreadInfo::default(), |
| 1779 | | invite: false, |
| 1789 | membership: MatrixRoomState::Joined, |
| 1780 | 1790 | }; |
| 1781 | 1791 | |
| 1782 | 1792 | // Alias and V1 room ID agree: |
| @@ -1786,7 +1796,7 @@ mod tests { |
| 1786 | 1796 | alias: Some(room_alias_id!("#name:a.com").to_owned()), |
| 1787 | 1797 | name: "Room D", |
| 1788 | 1798 | unread: UnreadInfo::default(), |
| 1789 | | invite: false, |
| 1799 | membership: MatrixRoomState::Joined, |
| 1790 | 1800 | }; |
| 1791 | 1801 | |
| 1792 | 1802 | // Alias, V2 room id: |
| @@ -1796,7 +1806,7 @@ mod tests { |
| 1796 | 1806 | alias: Some(room_alias_id!("#alias:b.com").to_owned()), |
| 1797 | 1807 | name: "Room C", |
| 1798 | 1808 | unread: UnreadInfo::default(), |
| 1799 | | invite: true, |
| 1809 | membership: MatrixRoomState::Invited, |
| 1800 | 1810 | }; |
| 1801 | 1811 | |
| 1802 | 1812 | // Alias and V2 room ID disagree, alias is used: |
| @@ -1806,7 +1816,7 @@ mod tests { |
| 1806 | 1816 | alias: Some(room_alias_id!("#alias:a.com").to_owned()), |
| 1807 | 1817 | name: "Room B", |
| 1808 | 1818 | unread: UnreadInfo::default(), |
| 1809 | | invite: true, |
| 1819 | membership: MatrixRoomState::Invited, |
| 1810 | 1820 | }; |
| 1811 | 1821 | |
| 1812 | 1822 | // No alias and V2 room ID: |
| @@ -1816,7 +1826,7 @@ mod tests { |
| 1816 | 1826 | alias: None, |
| 1817 | 1827 | name: "Room A", |
| 1818 | 1828 | unread: UnreadInfo::default(), |
| 1819 | | invite: true, |
| 1829 | membership: MatrixRoomState::Invited, |
| 1820 | 1830 | }; |
| 1821 | 1831 | |
| 1822 | 1832 | // Sort servers first ascending, name tie breaks: |