Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlee0201 committed Oct 5, 2017
1 parent 07377e4 commit 13055af
Show file tree
Hide file tree
Showing 39 changed files with 1,272 additions and 1,664 deletions.
10 changes: 8 additions & 2 deletions MQTTDemo/IMLib/IMClient/IMService.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,49 @@

- (BOOL)deleteMessage:(long)messageId;

- (GroupInfo *)getGroupInfo:(NSString *)groupId line:(int)line refresh:(BOOL)refresh;
- (GroupInfo *)getGroupInfo:(NSString *)groupId refresh:(BOOL)refresh;
- (UserInfo *)getUserInfo:(NSString *)userId refresh:(BOOL)refresh;

- (void)registerMessageContent:(Class)contentClass;
- (MessageContent *)messageContentFromPayload:(MessagePayload *)payload;

- (void)createGroup:(NSString *)groupId
line:(int)line
name:(NSString *)groupName
portrait:(NSString *)groupPortrait
members:(NSArray *)groupMembers
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)(NSString *groupId))successBlock
error:(void(^)(int error_code))errorBlock;

- (void)addMembers:(NSArray *)members
toGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;

- (void)kickoffMembers:(NSArray *)members
fromGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;

- (void)quitGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;

- (void)dismissGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;

- (void)modifyGroupInfo:(GroupInfo *)groupInfo
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;
Expand All @@ -84,6 +89,7 @@

- (void)transferGroup:(NSString *)groupId
to:(NSString *)newOwner
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock;
Expand Down
67 changes: 56 additions & 11 deletions MQTTDemo/IMLib/IMClient/IMService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ - (void)setConversation:(Conversation *)conversation top:(BOOL)top {
mars::stn::MessageDB::Instance()->updateConversationIsTop(conversation.type, [conversation.target UTF8String], conversation.line, top);
}
- (void)createGroup:(NSString *)groupId
line:(int)line
name:(NSString *)groupName
portrait:(NSString *)groupPortrait
members:(NSArray *)groupMembers
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)(NSString *groupId))successBlock
error:(void(^)(int error_code))errorBlock {
Expand All @@ -391,11 +391,17 @@ - (void)createGroup:(NSString *)groupId
MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::createGroup(groupId == nil ? "" : [groupId UTF8String], groupName == nil ? "" : [groupName UTF8String], groupPortrait == nil ? "" : [groupPortrait UTF8String], memberList, tmsg, new IMCreateGroupCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}
mars::stn::createGroup(groupId == nil ? "" : [groupId UTF8String], groupName == nil ? "" : [groupName UTF8String], groupPortrait == nil ? "" : [groupPortrait UTF8String], memberList, lines, tmsg, new IMCreateGroupCallback(successBlock, errorBlock));
}

- (void)addMembers:(NSArray *)members
toGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {
Expand All @@ -407,11 +413,18 @@ - (void)addMembers:(NSArray *)members
MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::addMembers([groupId UTF8String], memberList, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::addMembers([groupId UTF8String], memberList, lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (void)kickoffMembers:(NSArray *)members
fromGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {
Expand All @@ -423,32 +436,53 @@ - (void)kickoffMembers:(NSArray *)members
MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::kickoffMembers([groupId UTF8String], memberList, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::kickoffMembers([groupId UTF8String], memberList, lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (void)quitGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {

MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::quitGroup([groupId UTF8String], tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::quitGroup([groupId UTF8String], lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (void)dismissGroup:(NSString *)groupId
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {

MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::dismissGroup([groupId UTF8String], tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::dismissGroup([groupId UTF8String], lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (void)modifyGroupInfo:(GroupInfo *)groupInfo
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {
Expand All @@ -470,7 +504,13 @@ - (void)modifyGroupInfo:(GroupInfo *)groupInfo
MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);
mars::stn::modifyGroupInfo([groupInfo.target UTF8String], tInfo, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));

std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::modifyGroupInfo([groupInfo.target UTF8String], tInfo, lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (void)getGroupInfo:(NSArray<NSString *> *)groupIds success:(void(^)(NSArray<GroupInfo *> *))successBlock error:(void(^)(int error_code))errorBlock {
Expand All @@ -495,14 +535,20 @@ - (void)getMyGroups:(void(^)(NSArray<NSString *> *))successBlock

- (void)transferGroup:(NSString *)groupId
to:(NSString *)newOwner
notifyLines:(NSArray<NSNumber *> *)notifyLines
notifyContent:(MessageContent *)notifyContent
success:(void(^)())successBlock
error:(void(^)(int error_code))errorBlock {
MessagePayload *payload = [notifyContent encode];
mars::stn::TMessage tmsg;
fillTMessage(tmsg, nil, payload);

mars::stn::transferGroup([groupId UTF8String], [newOwner UTF8String], tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
std::list<int> lines;
for (NSNumber *number in notifyLines) {
lines.push_back([number intValue]);
}

mars::stn::transferGroup([groupId UTF8String], [newOwner UTF8String], lines, tmsg, new IMGeneralGroupOperationCallback(successBlock, errorBlock));
}

- (MessageContent *)messageContentFromPayload:(MessagePayload *)payload {
Expand All @@ -526,13 +572,12 @@ - (BOOL)deleteMessage:(long)messageId {
return mars::stn::MessageDB::Instance()->DeleteMessage(messageId);
}

- (GroupInfo *)getGroupInfo:(NSString *)groupId line:(int)line refresh:(BOOL)refresh {
mars::stn::TGroupInfo tgi = mars::stn::MessageDB::Instance()->GetGroupInfo([groupId UTF8String], line, refresh);
- (GroupInfo *)getGroupInfo:(NSString *)groupId refresh:(BOOL)refresh {
mars::stn::TGroupInfo tgi = mars::stn::MessageDB::Instance()->GetGroupInfo([groupId UTF8String], refresh);
if (!tgi.target.empty()) {
GroupInfo *groupInfo = [[GroupInfo alloc] init];
groupInfo.type = (GroupType)tgi.type;
groupInfo.target = [NSString stringWithUTF8String:tgi.target.c_str()];
groupInfo.line = tgi.line;
groupInfo.name = [NSString stringWithUTF8String:tgi.name.c_str()];
groupInfo.extra = [NSData dataWithBytes:tgi.extra.c_str() length:tgi.extra.length()];
groupInfo.portrait = [NSString stringWithUTF8String:tgi.portrait.c_str()];
Expand Down
1 change: 0 additions & 1 deletion MQTTDemo/IMLib/MQTTClient/GroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ typedef enum : NSUInteger {
@interface GroupInfo : NSObject
@property (nonatomic, assign)GroupType type;
@property (nonatomic, strong)NSString *target;
@property (nonatomic, assign)int line;
@property (nonatomic, strong)NSString *name;
@property (nonatomic, strong)NSString *portrait;
@property (nonatomic, strong)NSString *owner;
Expand Down
2 changes: 1 addition & 1 deletion MQTTDemo/IMLib/mars.framework/Headers/stn/MessageDB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace mars {
bool FailSendingMessages();


TGroupInfo GetGroupInfo(const std::string &groupId, int line, bool refresh);
TGroupInfo GetGroupInfo(const std::string &groupId, bool refresh);
long InsertGroupInfo(const TGroupInfo &groupInfo);

TUserInfo getUserInfo(const std::string &userId, bool refresh);
Expand Down
17 changes: 8 additions & 9 deletions MQTTDemo/IMLib/mars.framework/Headers/stn/stn.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ struct TaskProfile;
struct DnsProfile;
class TGroupInfo {
public:
TGroupInfo() : type(0), line(0) {}
TGroupInfo() : target(""), type(0) {}
std::string target;
int line;
std::string name;
std::string portrait;
std::string owner;
Expand Down Expand Up @@ -541,25 +540,25 @@ extern void (*ReportDnsProfile)(const DnsProfile& _dns_profile);

extern int (*sendMessage)(TMessage &tmsg, SendMessageCallback *callback);

extern void (*createGroup)(const std::string &groupId, const std::string &groupName, const std::string &groupPortrait, const std::list<std::string> &groupMembers, TMessage &tmsg, CreateGroupCallback *callback);
extern void (*createGroup)(const std::string &groupId, const std::string &groupName, const std::string &groupPortrait, const std::list<std::string> &groupMembers, const std::list<int> &notifyLines, TMessage &tmsg, CreateGroupCallback *callback);

extern void (*addMembers)(const std::string &groupId, const std::list<std::string> &members, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*addMembers)(const std::string &groupId, const std::list<std::string> &members, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*kickoffMembers)(const std::string &groupId, const std::list<std::string> &members, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*kickoffMembers)(const std::string &groupId, const std::list<std::string> &members, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*quitGroup)(const std::string &groupId, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*quitGroup)(const std::string &groupId, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*dismissGroup)(const std::string &groupId, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*dismissGroup)(const std::string &groupId, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*getGroupInfo)(const std::list<std::pair<std::string, int64_t>> &groupIdList, GetGroupInfoCallback *callback);

extern void (*modifyGroupInfo)(const std::string &groupId, const TGroupInfo &groupInfo, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*modifyGroupInfo)(const std::string &groupId, const TGroupInfo &groupInfo, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*getGroupMembers)(const std::string &groupId, GetGroupMembersCallback *callback);

extern void (*getMyGroups)(GetMyGroupsCallback *callback);

extern void (*transferGroup)(const std::string &groupId, const std::string &newOwner, TMessage &tmsg, GeneralGroupOperationCallback *callback);
extern void (*transferGroup)(const std::string &groupId, const std::string &newOwner, const std::list<int> &notifyLines, TMessage &tmsg, GeneralGroupOperationCallback *callback);

extern void (*getUserInfo)(const std::list<std::pair<std::string, int64_t>> &userReqList, GetUserInfoCallback *callback);

Expand Down
2 changes: 1 addition & 1 deletion MQTTDemo/MQTTDemo/ConversationTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (void)setInfo:(ConversationInfo *)info {
self.targetView.text = [NSString stringWithFormat:@"user<%@>", info.conversation.target];
}
} else if (info.conversation.type == Group_Type) {
GroupInfo *groupInfo = [[IMService sharedIMService] getGroupInfo:info.conversation.target line:info.conversation.line refresh:NO];
GroupInfo *groupInfo = [[IMService sharedIMService] getGroupInfo:info.conversation.target refresh:NO];
if(groupInfo.name.length > 0) {
self.targetView.text = groupInfo.name;
} else {
Expand Down
2 changes: 1 addition & 1 deletion MQTTDemo/MQTTDemo/CreateGroupViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (IBAction)onDone:(id)sender {
notifyContent.creator = [NetworkService sharedInstance].userId;
notifyContent.groupName = self.nameField.text;

[[IMService sharedIMService] createGroup:nil line:0 name:self.nameField.text portrait:nil members:membes notifyContent:notifyContent success:^(NSString *groupId) {
[[IMService sharedIMService] createGroup:nil name:self.nameField.text portrait:nil members:membes notifyLines:@[@(0)] notifyContent:notifyContent success:^(NSString *groupId) {
NSLog(@"create group success");
} error:^(int error_code) {
NSLog(@"create group failure");
Expand Down
10 changes: 5 additions & 5 deletions MQTTDemo/MQTTDemo/GroupTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
AddGroupeMemberNotificationContent *content = [[AddGroupeMemberNotificationContent alloc] init];
content.invitor = [NetworkService sharedInstance].userId;
content.invitees = memberIds;
[[IMService sharedIMService] addMembers:memberIds toGroup:groupId notifyContent:content success:^{
[[IMService sharedIMService] addMembers:memberIds toGroup:groupId notifyLines:@[@(0)] notifyContent:content success:^{
[ws refreshList];
} error:^(int error_code) {

Expand All @@ -132,7 +132,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
KickoffGroupMemberNotificaionContent *content = [[KickoffGroupMemberNotificaionContent alloc] init];
content.operateUser = [NetworkService sharedInstance].userId;
content.kickedMembers = memberIds;
[[IMService sharedIMService] kickoffMembers:memberIds fromGroup:groupId notifyContent:content success:^{
[[IMService sharedIMService] kickoffMembers:memberIds fromGroup:groupId notifyLines:@[@(0)] notifyContent:content success:^{
[ws refreshList];
} error:^(int error_code) {

Expand All @@ -155,7 +155,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
TransferGroupOwnerNotificationContent *content = [[TransferGroupOwnerNotificationContent alloc] init];
content.operateUser = [NetworkService sharedInstance].userId;
content.owner = memberIds[0];
[[IMService sharedIMService] transferGroup:groupId to:memberIds[0] notifyContent:content success:^{
[[IMService sharedIMService] transferGroup:groupId to:memberIds[0] notifyLines:@[@(0)] notifyContent:content success:^{
[ws refreshList];
} error:^(int error_code) {

Expand All @@ -172,7 +172,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
QuitGroupNotificationContent *content = [[QuitGroupNotificationContent alloc] init];
content.quitMember = [NetworkService sharedInstance].userId;
//Todo: add animination here
[[IMService sharedIMService] quitGroup:groupId notifyContent:content success:^{
[[IMService sharedIMService] quitGroup:groupId notifyLines:@[@(0)] notifyContent:content success:^{
dispatch_async(dispatch_get_main_queue(), ^{
[ws refreshList];
});
Expand All @@ -187,7 +187,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
content.operateUser = [NetworkService sharedInstance].userId;

//Todo: add animination here
[[IMService sharedIMService] dismissGroup:groupId notifyContent:content success:^{
[[IMService sharedIMService] dismissGroup:groupId notifyLines:@[@(0)] notifyContent:content success:^{
dispatch_async(dispatch_get_main_queue(), ^{
[ws refreshList];
});
Expand Down
2 changes: 0 additions & 2 deletions mars/stn/mqtt/DB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ namespace mars {
std::list<const WCDB::ColumnDef> groupDefList = {
WCDB::ColumnDef(Column("_id"), ColumnType::Integer32).makePrimary(OrderTerm::NotSet, true),
WCDB::ColumnDef(Column("_uid"), ColumnType::Text).makeNotNull(),
WCDB::ColumnDef(Column("_line"), ColumnType::Integer32),
WCDB::ColumnDef(Column("_name"), ColumnType::Text),
WCDB::ColumnDef(Column("_portrait"), ColumnType::Text),
WCDB::ColumnDef(Column("_owner"), ColumnType::Text),
Expand All @@ -303,7 +302,6 @@ namespace mars {
std::list<const WCDB::ColumnDef> groupMemberDefList = {
WCDB::ColumnDef(Column("_id"), ColumnType::Integer32).makePrimary(OrderTerm::NotSet, true),
WCDB::ColumnDef(Column("_gid"), ColumnType::Text).makeNotNull(),
WCDB::ColumnDef(Column("_line"), ColumnType::Integer32),
WCDB::ColumnDef(Column("_mid"), ColumnType::Text).makeNotNull(),
WCDB::ColumnDef(Column("_type"), ColumnType::Text),
WCDB::ColumnDef(Column("_update_dt"), ColumnType::Integer64).makeDefault(0)
Expand Down
Loading

0 comments on commit 13055af

Please sign in to comment.