Skip to content

Commit

Permalink
Hilights: Client side hilighting for old cores
Browse files Browse the repository at this point in the history
...that don't have it server side.
  • Loading branch information
guruz committed Apr 18, 2020
1 parent f8b314d commit 15bd0dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion quassel-for-ios/quassel-for-ios/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ - (void) popToLoginAndShowError:(NSString*)errorMsg

- (void) quasselFullyConnected
{

if(self.bufferViewController) {
// Hilight flags might be changed because we got the NetworkInit data
[self.bufferViewController.tableView reloadData];
}
}

- (void) doReconnectIfNecessary
Expand Down
36 changes: 36 additions & 0 deletions quassel-for-ios/quassel-for-ios/QuasselCoreConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,30 @@ - (void) handleReceivedNetworkInit:(NSArray*)networkInit
}


// Older cores don't set the Hilight flag (hilight is client side), so we manually hilight messages
// Go through all
NSArray *bufferIdsForNetwork = [networkIdBufferIdListMap objectForKey:networkId];
for(BufferId *bufferId in bufferIdsForNetwork) {
[self postProcessHilightForBuffer:bufferId];
}

networkInitsReceived++;
if (networkInitsReceived == neworkIdList.count ) {
[delegate quasselFullyConnected];
}
}

- (void) postProcessHilightForBuffer:(BufferId*)bufferId
{
NSMutableArray *messageList = [bufferIdMessageListMap objectForKey:bufferId];
for(Message*message in messageList) {
BOOL messageHasHilight = [self messageHasHilight:message];
if (messageHasHilight) {
message.messageFlag = message.messageFlag | MessageFlagHilight;
}
}
}


- (void) sendQVariant:(QVariant*) qvariant
{
Expand Down Expand Up @@ -1121,24 +1139,28 @@ - (void) backlogMessagesReceived:(NSMutableArray*)messagesReceived
// for (int i = 0; i < messagesReceived.count; i++)
// NSLog(@"We want to add %d %@", i, [messagesReceived objectAtIndex:i]);


if (!firstMessageWeHave && !lastMessageWeHave) {
// Easy case: We have no messages yet
NSLog(@"backlogMessagesReceived Easy case, no messages yet.");
[messageList addObjectsFromArray:messagesReceived];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
[delegate quasselMessagesReceived:messagesReceived received:ReceiveStyleAppended];

} else if (lastReceivedMessage.messageId.intValue < firstMessageWeHave.messageId.intValue) {
// FIXME Case1: Is lastReceivedMessage.id < firstMessageWeGot.id
//NSLog(@"backlogMessagesReceived Would prepend %d messages", messagesReceived.count);
[messageList insertObjects:messagesReceived atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, messagesReceived.count)]];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
[delegate quasselMessagesReceived:messagesReceived received:ReceiveStylePrepended];

} else if (firstReceivedMessage.messageId.intValue > lastMessageWeHave.messageId.intValue){
// FIXME Case2: Is firstReceivedMessage.id > lastMessageWeGot.id
//NSLog(@"backlogMessagesReceived Would apppend %d messages", messagesReceived.count);
[messageList addObjectsFromArray:messagesReceived];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
[delegate quasselMessagesReceived:messagesReceived received:ReceiveStyleAppended];

Expand All @@ -1148,6 +1170,17 @@ - (void) backlogMessagesReceived:(NSMutableArray*)messagesReceived
}
}

- (BOOL) messageHasHilight:(Message*)message
{
NetworkId *networkId = message.bufferInfo.networkId;
NSString *myNick = [self.networkIdMyNickMap objectForKey:networkId];
if (!myNick || myNick.length==0)return NO;
while ([myNick hasSuffix:@"_"]) myNick = [myNick substringToIndex:myNick.length-1];
if (myNick.length<=3)return NO;

return [message.contents.lowercaseString containsString:myNick.lowercaseString];
}


- (void) messageReceived:(Message*)message
{
Expand All @@ -1162,12 +1195,14 @@ - (void) messageReceived:(Message*)message

if (!firstMessage || !previousMessage || [previousMessage.messageId intValue] < [message.messageId intValue]) {
[messageList addObject:message];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
//NSLog(@"messageReceived Appending message");
[delegate quasselMessageReceived:message received:ReceiveStyleAppended onIndex:messageList.count-1];
} else if ([firstMessage.messageId intValue] > [message.messageId intValue]) {
//NSLog(@"messageReceived Prepending message");
[messageList insertObject:message atIndex:0];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
[delegate quasselMessageReceived:message received:ReceiveStylePrepended onIndex:0];
} else {
Expand All @@ -1193,6 +1228,7 @@ - (void) messageReceived:(Message*)message
} else {
NSLog(@"messageReceived Inserting message at index %d", indexToUse);
[messageList insertObject:message atIndex:indexToUse];
[self postProcessHilightForBuffer:bufferId];
[self computeBufferActivityForBuffer:bufferId];
[delegate quasselMessageReceived:message received:ReceiveStyleBacklog onIndex:indexToUse];
}
Expand Down

0 comments on commit 15bd0dd

Please sign in to comment.