Add delegate presence (callback)

Set Consolidated presence of core when app enter in background or foreground
This commit is contained in:
Benoit Martins 2023-04-14 17:25:30 +02:00
parent 595ce13409
commit 15481cf227
5 changed files with 78 additions and 9 deletions

View file

@ -53,6 +53,24 @@
self.tableView.accessibilityIdentifier = @"Chat list";
[self loadData];
_chatRooms = NULL;
NSDictionary* userInfo;
[NSNotificationCenter.defaultCenter addObserver:self
selector: @selector(receiveTestNotification:)
name: @"LinphoneFriendPresenceUpdate"
object: userInfo];
}
-(void) receiveTestNotification:(NSNotification*)notification
{
if ([notification.name isEqualToString:@"LinphoneFriendPresenceUpdate"])
{
NSDictionary* userInfo = notification.userInfo;
NSString* friend = (NSString*)userInfo[@"friend"];
BOOL friendIsOnline = (BOOL)userInfo[@"isOnline"];
//NSLog(@"Successfully received test notification! %@ %d", friend, friendIsOnline);
}
}
- (void)viewDidAppear:(BOOL)animated {

View file

@ -75,6 +75,9 @@
// To avoid crash
[PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];
}
linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceBusy);
[CallManager.instance stopLinphoneCore];
}
[SwiftUtil resetCachedAsset];
@ -86,6 +89,8 @@
[LinphoneManager.instance startLinphoneCore];
[LinphoneManager.instance.fastAddressBook reloadFriends];
linphone_core_set_consolidated_presence(LC, LinphoneConsolidatedPresenceOnline);
[NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:nil];
}

View file

@ -114,7 +114,30 @@ class Avatar : UIView {
let contactAddress = Address.getSwiftObject(cObject: address).contact()
var iconPresenceView = UIImageView()
if contactAddress != nil {
iconPresenceView = updatePresenceImage(contact: Address.getSwiftObject(cObject: address).contact()!)
iconPresenceView = updatePresenceImage(contact: contactAddress!)
let friend = Friend.getSwiftObject(cObject: (contactAddress?.friend)!)
let friendDelegate = FriendDelegateStub(
onPresenceReceived: { (linphoneFriend: Friend) -> Void in
let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!)
print("Successfully received test notification linphoneFriend \(linphoneFriend.address?.displayName)")
print("Successfully received test notification friend \(friend.address?.displayName)")
print("Successfully received test notification consolidatedPresence \(presenceModel!.consolidatedPresence)")
print("Successfully received test notification consolidatedPresence \(friend.consolidatedPresence)")
print("Successfully received test notification isOnline \(presenceModel!.isOnline)")
print("Successfully received test notification friend \(friend.isPresenceReceived)")
NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly(), "isOnline": presenceModel!.isOnline])
}
)
friend.addDelegate(delegate: friendDelegate)
}
avatarWithPresence.addSubview(avatarImageWihtoutPresence)
@ -124,8 +147,7 @@ class Avatar : UIView {
return avatarWithPresence.toImage()
}
@objc static func imageForInitials(contact:Contact) -> UIImage? {
let displayName: String = contact.displayName
@objc static func imageForInitials(contact:Contact, displayName:String) -> UIImage? {
if (shared == nil) {
prepareIt()
}
@ -139,6 +161,30 @@ class Avatar : UIView {
let avatarWithPresence = UIView(frame: CGRect(x: 0, y: 0, width: size, height: size))
let avatarImageWihtoutPresence = UIImageView(image: shared?.toImage())
let iconPresenceView = updatePresenceImage(contact: contact)
let friend = Friend.getSwiftObject(cObject: contact.friend)
let friendDelegate = FriendDelegateStub(
onPresenceReceived: { (linphoneFriend: Friend) -> Void in
let presenceModel = linphoneFriend.getPresenceModelForUriOrTel(uriOrTel: (linphoneFriend.address?.asStringUriOnly())!)
print("Successfully received test notification linphoneFriend displayName \(linphoneFriend.address?.displayName)")
print("Successfully received test notification friend displayName \(friend.address?.displayName)")
print("Successfully received test notification presenceModel consolidatedPresence \(presenceModel!.consolidatedPresence)")
print("Successfully received test notification friend consolidatedPresence \(friend.consolidatedPresence)")
print("Successfully received test notification presenceModel isOnline \(presenceModel!.isOnline)")
print("Successfully received test notification friend isPresenceReceived \(friend.isPresenceReceived)")
NotificationCenter.default.post(name: Notification.Name("LinphoneFriendPresenceUpdate"), object: nil, userInfo: ["friend": linphoneFriend.address?.asStringUriOnly(), "isOnline": presenceModel!.isOnline])
}
)
friend.addDelegate(delegate: friendDelegate)
avatarWithPresence.addSubview(avatarImageWihtoutPresence)
avatarWithPresence.addSubview(iconPresenceView)
@ -166,7 +212,7 @@ class Avatar : UIView {
} else {
imageName = "led_inprogress";
}
return UIImageView(image: UIImage(named:imageName))
}
}

View file

@ -36,7 +36,7 @@
if (retImage == nil) {
retImage = contact.friend && linphone_friend_get_addresses(contact.friend) ?
[AvatarBridge imageForAddressWithAddress:linphone_friend_get_addresses(contact.friend)->data] :
[AvatarBridge imageForInitialsWithContact:contact];
[AvatarBridge imageForInitialsWithContact:contact displayName:[contact displayName]];
}
if (retImage.size.width != retImage.size.height) {
retImage = [retImage squareCrop];

View file

@ -606,7 +606,7 @@
63E27A321C4FECD000D332AE /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 63E27A311C4FECD000D332AE /* LaunchScreen.xib */; };
63E27A521C50EDB000D332AE /* hold.mkv in Resources */ = {isa = PBXBuildFile; fileRef = 63E27A511C50EB2700D332AE /* hold.mkv */; };
63E59A3F1ADE70D900646FB3 /* InAppProductsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E59A3E1ADE70D900646FB3 /* InAppProductsManager.m */; };
63E802DB1C625AEF000D5509 /* BuildFile in Resources */ = {isa = PBXBuildFile; };
63E802DB1C625AEF000D5509 /* (null) in Resources */ = {isa = PBXBuildFile; };
63EC8D391D7438660066547B /* AssistantLinkView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 63EC8D3B1D7438660066547B /* AssistantLinkView.xib */; };
63F1DF441BCE618E00EDED90 /* UIAddressTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 63F1DF431BCE618E00EDED90 /* UIAddressTextField.m */; };
63FB30351A680E73008CA393 /* UIRoundedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 63FB30341A680E73008CA393 /* UIRoundedImageView.m */; };
@ -2551,7 +2551,7 @@
path = LinphoneUI;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA = {
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
8C23BCB71D82AAC3005F19BB /* linphone.entitlements */,
@ -3975,7 +3975,7 @@
fr,
hu,
);
mainGroup = 29B97314FDCFA39411CA2CEA;
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */;
projectDirPath = "";
projectRoot = "";
@ -4046,7 +4046,7 @@
633FEEE01D3CD55A0014B822 /* numpad_8_over~ipad@2x.png in Resources */,
633FEDDC1D3CD5590014B822 /* call_start_body_disabled~ipad.png in Resources */,
C63F72FF285A31DA0066163B /* Roboto-Bold.ttf in Resources */,
63E802DB1C625AEF000D5509 /* BuildFile in Resources */,
63E802DB1C625AEF000D5509 /* (null) in Resources */,
633FEE2E1D3CD5590014B822 /* color_F.png in Resources */,
633FEDC51D3CD5590014B822 /* call_hangup_disabled@2x.png in Resources */,
633FEEDF1D3CD55A0014B822 /* numpad_8_over~ipad.png in Resources */,