mirror of https://github.com/procxx/kepka.git
Fixed duplicate of Saved Messages in touchbar when it is pinned.
- Moved updating of pinned dialogs order from PinnedDialogButton to TouchBar class.
This commit is contained in:
parent
60cf1b6490
commit
04843ebdd8
|
@ -46,6 +46,8 @@ static NSTouchBarItemIdentifier _Nullable currentPosition = [NSString stringWith
|
||||||
@property(nonatomic, assign) double duration;
|
@property(nonatomic, assign) double duration;
|
||||||
@property(nonatomic, assign) double position;
|
@property(nonatomic, assign) double position;
|
||||||
|
|
||||||
|
@property(retain) NSMutableArray * _Nullable mainPinnedButtons;
|
||||||
|
|
||||||
- (id _Nonnull) init:(NSView * _Nonnull)view;
|
- (id _Nonnull) init:(NSView * _Nonnull)view;
|
||||||
- (void)handlePropertyChange:(Media::Player::TrackState)property;
|
- (void)handlePropertyChange:(Media::Player::TrackState)property;
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,12 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||||
@property(nonatomic, assign) int number;
|
@property(nonatomic, assign) int number;
|
||||||
@property(nonatomic, assign) bool waiting;
|
@property(nonatomic, assign) bool waiting;
|
||||||
@property(nonatomic, assign) PeerData * peer;
|
@property(nonatomic, assign) PeerData * peer;
|
||||||
|
@property(nonatomic, assign) bool isDeletedFromView;
|
||||||
|
|
||||||
- (id) init:(int)num;
|
- (id) init:(int)num;
|
||||||
- (id) initSavedMessages;
|
- (id) initSavedMessages;
|
||||||
- (NSImage *) getPinImage;
|
- (NSImage *) getPinImage;
|
||||||
- (void)buttonActionPin:(NSButton *)sender;
|
- (void)buttonActionPin:(NSButton *)sender;
|
||||||
- (void)updatePeerData;
|
|
||||||
- (void)updatePinnedDialog;
|
- (void)updatePinnedDialog;
|
||||||
|
|
||||||
@end // @interface PinnedDialogButton
|
@end // @interface PinnedDialogButton
|
||||||
|
@ -74,7 +74,6 @@ auto lifetime = rpl::lifetime();
|
||||||
}
|
}
|
||||||
self.number = num;
|
self.number = num;
|
||||||
self.waiting = true;
|
self.waiting = true;
|
||||||
[self updatePeerData];
|
|
||||||
|
|
||||||
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
|
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
|
||||||
[button setBordered:NO];
|
[button setBordered:NO];
|
||||||
|
@ -83,31 +82,21 @@ auto lifetime = rpl::lifetime();
|
||||||
self.view = button;
|
self.view = button;
|
||||||
self.customizationLabel = [NSString stringWithFormat:@"Pinned Dialog %d", num];
|
self.customizationLabel = [NSString stringWithFormat:@"Pinned Dialog %d", num];
|
||||||
|
|
||||||
const auto updateImage = [self]() {
|
|
||||||
NSButton *button = self.view;
|
|
||||||
button.image = [self getPinImage];
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.peer) {
|
if (self.peer) {
|
||||||
Notify::PeerUpdateViewer(
|
Notify::PeerUpdateViewer(
|
||||||
self.peer,
|
self.peer,
|
||||||
Notify::PeerUpdate::Flag::PhotoChanged
|
Notify::PeerUpdate::Flag::PhotoChanged
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
self.waiting = true;
|
self.waiting = true;
|
||||||
updateImage();
|
|
||||||
}, lifetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth().data().pinnedDialogsOrderUpdated(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
[self updatePinnedDialog];
|
[self updatePinnedDialog];
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
base::ObservableViewer(
|
base::ObservableViewer(
|
||||||
Auth().downloaderTaskFinished()
|
Auth().downloaderTaskFinished()
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (self.waiting) {
|
if (self.waiting) {
|
||||||
updateImage();
|
[self updatePinnedDialog];
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
|
|
||||||
|
@ -115,10 +104,8 @@ auto lifetime = rpl::lifetime();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updatePinnedDialog {
|
- (void) updatePinnedDialog {
|
||||||
[self updatePeerData];
|
|
||||||
NSButton *button = self.view;
|
NSButton *button = self.view;
|
||||||
button.image = [self getPinImage];
|
button.image = [self getPinImage];
|
||||||
[button setHidden:(self.number > Auth().data().pinnedChatsOrder(nullptr).size())];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initSavedMessages {
|
- (id) initSavedMessages {
|
||||||
|
@ -155,18 +142,6 @@ auto lifetime = rpl::lifetime();
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) updatePeerData {
|
|
||||||
const auto &order = Auth().data().pinnedChatsOrder(nullptr);
|
|
||||||
if (self.number > order.size()) {
|
|
||||||
self.peer = nil;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto pinned = order.at(self.number - 1);
|
|
||||||
if (const auto history = pinned.history()) {
|
|
||||||
self.peer = history->peer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) buttonActionPin:(NSButton *)sender {
|
- (void) buttonActionPin:(NSButton *)sender {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
|
||||||
App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId
|
App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId
|
||||||
|
@ -283,9 +258,61 @@ auto lifetime = rpl::lifetime();
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
|
|
||||||
|
Auth().data().pinnedDialogsOrderUpdated(
|
||||||
|
) | rpl::start_with_next([self] {
|
||||||
|
[self updatePinnedButtons];
|
||||||
|
}, lifetime);
|
||||||
|
|
||||||
|
[self updatePinnedButtons];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) updatePinnedButtons {
|
||||||
|
const auto &order = Auth().data().pinnedChatsOrder(nullptr);
|
||||||
|
auto isSelfPeerPinned = false;
|
||||||
|
PinnedDialogButton *selfChatButton;
|
||||||
|
NSCustomTouchBarItem *item = [self.touchBarMain itemForIdentifier:pinnedPanel];
|
||||||
|
NSStackView *stack = item.view;
|
||||||
|
|
||||||
|
for (PinnedDialogButton *button in self.mainPinnedButtons) {
|
||||||
|
const auto num = button.number;
|
||||||
|
if (num <= kSavedMessagesId) {
|
||||||
|
if (num == kSavedMessagesId) {
|
||||||
|
selfChatButton = button;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto numIsTooLarge = num > order.size();
|
||||||
|
[button.view setHidden:numIsTooLarge];
|
||||||
|
if (numIsTooLarge) {
|
||||||
|
button.peer = nil;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto pinned = order.at(num - 1);
|
||||||
|
if (const auto history = pinned.history()) {
|
||||||
|
button.peer = history->peer;
|
||||||
|
[button updatePinnedDialog];
|
||||||
|
if (history->peer->id == Auth().userPeerId()) {
|
||||||
|
isSelfPeerPinned = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If self chat is pinned, delete from view saved messages button.
|
||||||
|
if (isSelfPeerPinned) {
|
||||||
|
if (!selfChatButton.isDeletedFromView) {
|
||||||
|
selfChatButton.isDeletedFromView = true;
|
||||||
|
[stack removeView:selfChatButton.view];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (selfChatButton.isDeletedFromView) {
|
||||||
|
selfChatButton.isDeletedFromView = false;
|
||||||
|
[stack insertView:selfChatButton.view atIndex:0 inGravity:NSStackViewGravityLeading];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIconSize) {
|
NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIconSize) {
|
||||||
const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
|
const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
|
||||||
auto pixmap = QPixmap::fromImage(instance);
|
auto pixmap = QPixmap::fromImage(instance);
|
||||||
|
@ -338,12 +365,15 @@ NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIcon
|
||||||
return item;
|
return item;
|
||||||
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"pinned"]) {
|
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"pinned"]) {
|
||||||
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
||||||
NSMutableArray *pins = [[NSMutableArray alloc] init];
|
self.mainPinnedButtons = [[NSMutableArray alloc] init];
|
||||||
|
NSStackView *stackView = [[NSStackView alloc] init];
|
||||||
|
|
||||||
for (auto i = kSavedMessagesId; i <= Global::PinnedDialogsCountMax(); i++) {
|
for (auto i = kSavedMessagesId; i <= Global::PinnedDialogsCountMax(); i++) {
|
||||||
[pins addObject:[[PinnedDialogButton alloc] init:i].view];
|
PinnedDialogButton *button = [[PinnedDialogButton alloc] init:i];
|
||||||
|
[self.mainPinnedButtons addObject:button];
|
||||||
|
[stackView addView:button.view inGravity:NSStackViewGravityCenter];
|
||||||
}
|
}
|
||||||
NSStackView *stackView = [NSStackView stackViewWithViews:[pins copy]];
|
|
||||||
[stackView setSpacing:-15];
|
[stackView setSpacing:-15];
|
||||||
item.view = stackView;
|
item.view = stackView;
|
||||||
[self.touchbarItems[identifier] setObject:item.view forKey:@"view"];
|
[self.touchbarItems[identifier] setObject:item.view forKey:@"view"];
|
||||||
|
|
Loading…
Reference in New Issue