Other chat features

Mute user/Group#

If you want to mute the notifications for the chat of a user or a group, you can utilise the below method.

ChatManager.shared.updateChatMuteStatus(jid: jid, muteStatus: muteStatus)
ArgumentTypeDescription
JIDStringjid of the chat user/ group
MUTE_STATUSBooltrue, if you want to mute notifications for the chat

Get Recent Chat#

To get the recent chat of a user or a group.

let recentChat = ChatManager.shared.getRecentChatOf(jid:jid)

Refer this doc to know more about RecentChat Class

ArgumentsTypeDescription
JIDStringjid of the user/group
caution

Will return a null object if a user never made a conversation with that user/group.

Get Recent Chat list#

To get the recent chat of a user or a group.

Mark a conversation as read#

By marking a converstaion as read the unread count will be reset and it is considered the message inside the conversation were read by you.

let recentChatList = ChatManager.shared.getRecentChatList()
or
ChatManager.shared.getRecentChatList { (isSuccess, flyError, resultDict) in
if (isSuccess) {
var recentChatList = resultDict
//update the UI
} else {
//Fetching recent chat list failed
}
}
ArgumentTypeDescription
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler
info

The method with callback runs on background thread and the one without callback didn't run on background thread

Get Recent Chat list with archived chats#

To get the recent chat list including the arhived chat conversation call the below method.

let recentChatList = ChatManager.shared.getRecentChatListIncludingArchived()

Archive a recent chat conversation#

Archiving a chat conversation makes the chat not appear in recent chat list, mostly used on chats which are inactive for a long time.

ChatManager.shared.archiveChatConversation(jidsToArchive:jids)
ArgumentTypeDescription
JIDS_TO_ARCHIVE[String]jids of the user/group

Unarchive a archived recent chat conversation#

Unarchiving a archived recent chat conversation makes the chat conversation appear in recent chat list again.

ChatManager.shared.unarchiveChatConversation(jidsToUnarchive:jids)
ChatManager.markConversationAsRead(JID_LIST);
ArgumentTypeDescription
JIDS_TO_UNARCHIVE[String]jids of the user/group

Note : Archiving and Unarchiving a chat conversation persist in local only not across login or reinstalls.

Get List of archived recent chat conversation#

An archived chat won't be listed in recent chat list. To get the list of archived chats call the below method.

ChatManager.shared.getArchivedChatList { (isSuccess, flyError, resultDict) in
if isSuccess {
var flydata = resultDict
print(flydata.getData())
}else{
//Getting users blocked me list failed
}
}
ArgumentTypeDescription
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Mark a conversation as unread#

By marking a converstaion as unread it is considered the message inside the conversation were in unread state.

ChatManager.shared.getArchivedChatList { (isSuccess, flyError, resultDict) in
if isSuccess {
var flydata = resultDict
print(flydata.getData())
}else{
//Getting users blocked me list failed
}
}
ArgumentTypeDescription
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Delete a Recent Chat#

To delete a recent chat of a user or a group call the method.

ChatManager.shared.deleteRecentChat(jid: jid)

We can delete a archived recent chat using this method too.

ArgumentsTypeDescription
JIDStringjid of the user/group
caution

Deleting a recent chat will delete the all the conversation for that user/group including favorite messages.

Pin a Recent Chat#

To pin a recent chat which makes a particular recent chat to appear at the top of the recent chat list.

ChatManager.shared.updateRecentChatPinStatus(jid: jid, pinRecentChat: pinRecentChat)
ArgumentsTypeDescription
JIDStringjid of the user/group
PIN_RECENT_CHATbooleanif true chat will be pinned else the chat will be unpinned

Recent Chat Pinned Count#

To get the pinned count on recent chat list call the below method.

let recentPinCount = ChatManager.shared.recentChatPinnedCount()

Clear chat messages#

Clear chat messages is a feature which allows users to delete the chat messages to reduce the storage usage. if you want to clear the messages for the entire chat, or multiple chats then you can utilise the below methods. it will also delete the downloaded media files from your local storage.

Clear chat#

You can clear the messages for any chat by using the below method. The messages will not be deleted to the receipient.

ChatManager.shared.clearChat(toJID: toJid, chatType: chatType, clearChatExceptStarred: clearChatExceptStarred) { (isSuccess, flyerror, resultDict) in
}
ArgumentTypeDescription
TO_JIDStringjid of the chat user
CHAT_TYPEChatTypeEnumChatTypeEnum.chat for single chat, ChatTypeEnum.groupchat for group chat, ChatTypeEnum.broadcast for broadcast
CLEAR_EXCEPT_STARREDbooleanif true, delete all the messages except the favourite messages
CALLBACKFlyCompletionHandlerFlyCompletionHandler used as completion Handler

Handling Banned User/Group#

Banning a user or group is a feature. A user or group can be blocked or unblocked from console. This is applicable to logged in user, contacts of logged in user and groups

Note: Xmpp must be connected

Current / Logged in user#

To get blocking/unblocking event of current/logged in user, confirm viewcontroller or Appdelegate to below protocol.

AdminBlockCurrentUserDelegate

FlyDefaults.isBlockedByAdmin
// This will return true or false to check current user is blocked or unblocked.
// It can be used, while coming from background or opening the app or wherever
let adminEmail = "mirroflyadminsupport@gmail.com"
// support email is defined in StringConstants File.

In Appdelegate#

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ChatManager.shared.adminBlockCurrentUserDelegate = self
retrun true
}
extension AppDelegate : AdminBlockCurrentUserDelegate {
func didBlockOrUnblockCurrentUser(userJid: String, isBlocked: Bool) {
if isBlocked {
// if logged in user is being blocked this coditon will execute
// do your UI stuffs here
} else {
// if logged in user is unblocked this coditon will execute
// do your UI stuffs here
}
}
}

In ViewController#

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
ChatManager.shared.adminBlockCurrentUserDelegate = self
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
ChatManager.shared.adminBlockCurrentUserDelegate = nil
}
extension <View Controller Name> : AdminBlockCurrentUserDelegate {
func didBlockOrUnblockCurrentUser(userJid: String, isBlocked: Bool) {
if isBlocked {
// if logged in user is being blocked this coditon will execute
// do your UI stuff here
} else {
// if logged in user is unblocked this coditon will execute
// do your UI stuff here
}
}
}
ArgumentTypeDescription
userJidStringjid of the current user
isBlockedBooltrue, if current user is being blocked. false, if current user is unblocked

Contacts of current user and group#

To get blocking/unblocking event of Contacts of current user and group, confirm viewcontroller to below protocol.

AdminBlockDelegate

In ViewController#

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
ChatManager.shared.adminBlockDelegate = self
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
ChatManager.shared.adminBlockDelegate = nil
}
extension <ViewController Name> : AdminBlockDelegate {
func didBlockOrUnblockContact(userJid: String, isBlocked: Bool) {
// If a contact is blocked/unblocked, this function will be triggered
// do your UI stuff here
}
func didBlockOrUnblockSelf(userJid: String, isBlocked: Bool) {
// If a current user is blocked/unblocked, this function will be triggered
// do your UI stuff here
}
func didBlockOrUnblockGroup(groupJid: String, isBlocked: Bool) {
// If a group is blocked/unblocked, this function will be triggered
// do your UI stuff here
}
}
ArgumentTypeDescription
userJidStringjid of the user
isBlockedBooltrue, if user is being blocked. false, if user is unblocked
groupJidStringjid of the group