/
Tweak.xm
executable file
·99 lines (75 loc) · 2.61 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
BOOL soDoWeOrNot;
unsigned int whatDidWeSelect;
NSDictionary *prefs;
NSDate *oldDate;
NSDate *lastDisplayed;
static void LoadSettings() {
prefs = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.gabriobarbieri.SMSTimestamps.plist"];
soDoWeOrNot = (BOOL)[[prefs objectForKey:@"SwitchCell5"] boolValue];
whatDidWeSelect = [[prefs objectForKey:@"LinkListCell7"] intValue];
[prefs release];
}
static void SettingsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
LoadSettings();
}
static BOOL CheckForDifference(NSDate *date, int lapse){
if(oldDate == nil){//should happen upon the first table load.
oldDate = date;
lastDisplayed = date;
return YES;
}else{//means this is not the first one, do our thang.
NSDate *thisMsg = date;
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *components = [gregorianCalendar components:unitFlags
fromDate:lastDisplayed
toDate:thisMsg
options:0];
int c = [components minute];
[gregorianCalendar release];
oldDate = date;
if(c >=lapse){
lastDisplayed = date;
return YES;
}else{
return NO;}
}
}
%hook CKTranscriptBubbleData
- (BOOL)_shouldShowTimestampForDate:(id)arg1{
LoadSettings();
if(!soDoWeOrNot) {
return %orig(arg1);
}
switch (whatDidWeSelect) {
case 1:
return YES;
case 2:
return CheckForDifference(arg1, 1);
case 3:
return CheckForDifference(arg1, 5);
case 4:
return CheckForDifference(arg1, 10);
default:
return YES;
}
}
%end
%hook CKTranscriptController
- (void)viewWillDisappear:(BOOL)arg1{
oldDate = nil;
%orig(arg1);
}
- (void)viewDidDisappear:(BOOL)arg1{
oldDate = nil;
%orig(arg1);
}
%end
%ctor
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
%init;
LoadSettings();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, SettingsChanged, CFSTR("com.gabriobarbieri.SMSTimestamps-preferencesChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
[pool drain];
}