Only display chats the user is currently member of in chat the "join chat" view

This commit is contained in:
mjentsch 2015-03-20 17:48:54 +01:00
parent 293c6049a6
commit a8314eb3ae
2 changed files with 39 additions and 17 deletions

View file

@ -14,27 +14,27 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe">
<rect key="frame" x="0.0" y="0.0" width="227" height="46"/>
<rect key="frame" x="0.0" y="0.0" width="267" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qUU-2Z-89E">
<rect key="frame" x="-36" y="12" width="90" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Chats:" id="Muj-XM-wKR">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vmH-Cu-psq">
<rect key="frame" x="58" y="10" width="158" height="26"/>
<rect key="frame" x="92" y="10" width="158" height="26"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="BgB-2f-ODq">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="QeB-8O-H4a"/>
</popUpButtonCell>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qUU-2Z-89E">
<rect key="frame" x="-2" y="13" width="90" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Chats:" id="Muj-XM-wKR">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<point key="canvasLocation" x="259.5" y="442"/>
<point key="canvasLocation" x="279.5" y="442"/>
</customView>
</objects>
</document>

View file

@ -1,4 +1,4 @@
/*
/*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
@ -18,6 +18,7 @@
#include "TelegramJoinChatViewController.h"
#include "telegram-purple.h"
#include "tgp-structs.h"
#include "tgp-chat.h"
#import <Adium/AIContactControllerProtocol.h>
#import <AIUtilities/AICompletingTextField.h>
@ -34,7 +35,7 @@
static void tgl_peer_iterator_cb (tgl_peer_t *peer, void *extra) {
NSMutableArray *A = (__bridge NSMutableArray *)(extra);
if (tgl_get_peer_type (peer->id) == TGL_PEER_CHAT) {
[A addObject: [[NSString alloc] initWithUTF8String:peer->print_name]];
[A addObject: [NSValue valueWithPointer: peer]];
}
}
@ -49,11 +50,32 @@ static void tgl_peer_iterator_cb (tgl_peer_t *peer, void *extra) {
[popupButton_existingChat removeAllItems];
NSMutableArray *A = [NSMutableArray new];
tgl_peer_iterator_ex (conn->TLS, tgl_peer_iterator_cb, (__bridge void *)(A));
for (NSString *name in A) {
[popupButton_existingChat addItemWithTitle:name];
NSMutableArray *a = [NSMutableArray new];
tgl_peer_iterator_ex (conn->TLS, tgl_peer_iterator_cb, (__bridge void *)(a));
NSMutableArray *chats = [NSMutableArray new];
NSMutableArray *leftChats = [NSMutableArray new];
for (NSValue *V in a) {
tgl_peer_t *P = [V pointerValue];
NSString *name = [[NSString alloc] initWithUTF8String:P->print_name];
if (chat_is_member (conn->TLS->our_id, &P->chat)) {
[chats addObject: name];
}
else {
[leftChats addObject: name];
}
}
NSArray *sortedChats = [chats sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
return [(NSString*)a
compare:b
options:NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch];
}];
[popupButton_existingChat addItemsWithTitles: sortedChats];
// TODO: Display left chats with a grey font to indicate that those are no
// longer, but still allow the user to view the history
// [popupButton_existingChat addItemsWithTitles: leftChats];
}
}